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
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 theCMakeLists.txt
file in theTOY
folder:$ vi CMakeLists .txt add_llvm_target(... ... TOYISelDAGToDAG.cpp ... )
A pass entry needs to be added in the
TOYTargetMachine.h
andTOYTargetMachine.cpp
files:$ vi TOYTargetMachine.h const TOYInstrInfo *getInstrInfo() const override { return getSubtargetImpl()->getInstrInfo(); }
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...