TBD

Automatically generating ASIP toolchains from 'To Be Done'

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:

  1. llvm-5.0.1.src/include/llvm/ADT/Triple.h
  2. llvm-5.0.1.src/lib/Support/Triple.cpp

lib/Target/TBD directory

  1. add the directory
  2. 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:

  1. add the lib/Target/TBD/TargetInfo/ directory
  2. add the lib/Target/TBD/TargetInfo/TBDTargetInfo.cpp.
    1. Implement the Target & getTheTBDTarget() function
    2. Implement the extern “C” void LLVMInitializeTBDTargetInfo() function
  3. 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:

  1. add the lib/Target/TBD/MCTargetDesc/ directory
  2. add the lib/Target/TBD/MCTargetDesc/TBDMCTargetDesc.cpp and TBDMCTargetDesc.h.
    1. Implement the extern “C” void LLVMInitializeTBDMCTargetDesc() function
  3. 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:

  1. add the lib/Target/TBD/TBDTargetMachine.cpp and TBDTargetMachine.h
  2. 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