Book Image

LLVM Cookbook

Book Image

LLVM Cookbook

Overview of this book

Table of Contents (16 chapters)
LLVM Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Selecting an instruction


An IR instruction in DAG needs to be lowered to a target-specific instruction. The SDAG node contains IR, which needs to be mapped on machine-specific DAG nodes. The outcome of the selection phase is ready for scheduling.

Getting ready

  1. For selecting a machine-specific instruction, a separate class, TOYDAGToDAGISel, needs to be defined. To compile the file containing this class definition, add the filename to the CMakeLists.txt file in the TOY folder:

    $ vi CMakeLists .txt
    add_llvm_target(...
    ...
    TOYISelDAGToDAG.cpp
    ...
    )
  2. A pass entry needs to be added in the TOYTargetMachine.h and TOYTargetMachine.cpp files:

    $ vi TOYTargetMachine.h
    const TOYInstrInfo *getInstrInfo() const override {
    return getSubtargetImpl()->getInstrInfo();
    }
  3. The following code in TOYTargetMachine.cpp will create a pass in the instruction selection stage:

    class TOYPassConfig : public TargetPassConfig {
    public:
    ...
    virtual bool addInstSelector();
    };
    ...
    bool TOYPassConfig::addInstSelector() {
    addPass...