X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=docs%2FWritingAnLLVMBackend.html;h=43766b510174f9fc94cc4727fb70fc35ca9f74d8;hb=1940dd10dd6b79e3332f384756c268b85d0ad400;hp=a7512c2cc5190bc1c2304c7a6123de4eaad7dcc0;hpb=e9e6fd9155bad00da806b226e794db0c07537100;p=oota-llvm.git diff --git a/docs/WritingAnLLVMBackend.html b/docs/WritingAnLLVMBackend.html index a7512c2cc51..43766b51017 100644 --- a/docs/WritingAnLLVMBackend.html +++ b/docs/WritingAnLLVMBackend.html @@ -2,6 +2,7 @@ "http://www.w3.org/TR/html4/strict.dtd"> + Writing an LLVM Compiler Backend @@ -21,6 +22,7 @@
  • Preliminaries
  • Target Machine
  • +
  • Target Registration
  • Register Set and Register Classes + + + +
    + Target Registration +
    + + +
    + +

    +You must also register your target with the TargetRegistry, which is +what other LLVM tools use to be able to lookup and use your target at +runtime. The TargetRegistry can be used directly, but for most targets +there are helper templates which should take care of the work for you.

    +

    -You must also register your target using the RegisterTarget -template. (See the TargetMachineRegistry class.) For example, -in SparcTargetMachine.cpp, the target is registered with: +All targets should declare a global Target object which is used to +represent the target during registration. Then, in the target's TargetInfo +library, the target should define that object and use +the RegisterTarget template to register the target. For example, the Sparc registration code looks like this:

    -namespace {
    -  // Register the target.
    -  RegisterTarget<SparcTargetMachine>X("sparc", "SPARC");
    +Target llvm::TheSparcTarget;
    +
    +extern "C" void LLVMInitializeSparcTargetInfo() { 
    +  RegisterTarget<Triple::sparc, /*HasJIT=*/false>
    +    X(TheSparcTarget, "sparc", "Sparc");
     }
     
    +

    +This allows the TargetRegistry to look up the target by name or by +target triple. In addition, most targets will also register additional features +which are available in separate libraries. These registration steps are +separate, because some clients may wish to only link in some parts of the target +-- the JIT code generator does not require the use of the assembler printer, for +example. Here is an example of registering the Sparc assembly printer: +

    + +
    +
    +extern "C" void LLVMInitializeSparcAsmPrinter() { 
    +  RegisterAsmPrinter<SparcAsmPrinter> X(TheSparcTarget);
    +}
    +
    +
    + +

    +For more information, see +"llvm/Target/TargetRegistry.h". +

    +
    @@ -2037,8 +2078,8 @@ SparcTargetAsmInfo::SparcTargetAsmInfo(const SparcTargetMachine &TM) {

    The X86 assembly printer implementation (X86TargetAsmInfo) is an -example where the target specific TargetAsmInfo class uses overridden -methods: ExpandInlineAsm and PreferredEHDataFormat. +example where the target specific TargetAsmInfo class uses an +overridden methods: ExpandInlineAsm.

    @@ -2109,21 +2150,13 @@ in XXXGenAsmWriter.inc contains an implementation of the

  • printImplicitDef
  • printInlineAsm
  • - -
  • printLabel
  • - -
  • printPICJumpTableEntry
  • - -
  • printPICJumpTableSetLabel
  • The implementations of printDeclare, printImplicitDef, printInlineAsm, and printLabel in AsmPrinter.cpp are generally adequate for printing assembly and do not need to be -overridden. (printBasicBlockLabel is another method that is implemented -in AsmPrinter.cpp that may be directly used in an implementation of -XXXAsmPrinter.) +overridden.