v0.0.1: Added the LLVM target ‘tbd’
In this version, we added an target called ‘tbd’ in LLVM. It can compile and be shown in the ‘supported targe’, as following:
[xiesl@mapu-opencl bin]$ ./llvm-mc --version
LLVM (http://llvm.org/):
LLVM version 5.0.1
DEBUG build with assertions.
Default target: x86_64-unknown-linux-gnu
Host CPU: ivybridge
Registered Targets:
tbd - TBD Generator
x86 - 32-bit X86: Pentium-Pro and above
x86-64 - 64-bit X86: EM64T and AMD64
Anywhere, it can not do anything, because we only resigered the target, but we didn’t actually created any asm parser or asm printers.
To added an fresh new target in LLVM, following class should be implemented and regsitered:
| class | information | Initilization function |
|---|---|---|
| TargetInfo | ??? | LLVMInitializeTBDTargetInfo() |
| MCTargetDesc | The MC layer | LLVMInitializeTBDMCTargetDesc() |
| TargetMachine | ??? | LLVMInitializeTBDTargetMachine() |
We need to do following steps to make the LLVM recognize our ‘tbd’ target:
the target triple
Check out the difference in following files:
lib/Target/TBD directory
- add the directory
- add the directory in llvm-5.0.1.src/lib/Target/LLVMBuild.txt
the <TBD>TargetInfo
the TargetInfo implements the “LLVMInitializeTBDTargetInfo()” which will be called by the llvm tools:
- add the lib/Target/TBD/TargetInfo/ directory
- add the lib/Target/TBD/TargetInfo/TBDTargetInfo.cpp.
- Implement the Target & getTheTBDTarget() function
- Implement the extern “C” void LLVMInitializeTBDTargetInfo() function
- add the LLVMBuild.txt and the CMakeList.txt
the <TBD>MCTargetDesc
the MCTargetDesc implements the “extern “C” void LLVMInitializeTBDTargetMC()” which will be called by the llvm tools:
- add the lib/Target/TBD/MCTargetDesc/ directory
- add the lib/Target/TBD/MCTargetDesc/TBDMCTargetDesc.cpp and TBDMCTargetDesc.h.
- Implement the extern “C” void LLVMInitializeTBDMCTargetDesc() function
- add the LLVMBuild.txt and the CMakeList.txt
the <TBD>TargetMachine
For each new Target, we need an new class inherit from TargetMachine. and aslo implement “extern “C” void LLVMInitializeTBDTarget()” which will be called by the llvm tools:
- add the lib/Target/TBD/TBDTargetMachine.cpp and TBDTargetMachine.h
- add the LLVMBuild.txt and the CMakeList.txt
- In the LLVMBuild.txt, we should set following variables to zero, because we didn’t implement that yet.
has_asmprinter = 0 has_asmparser = 0 has_disassembler = 0
- In the LLVMBuild.txt, we should set following variables to zero, because we didn’t implement that yet.