From d6b06b1f3696b1bf4b334c14faebefad6be45015 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Sun, 26 Jul 2009 05:41:39 +0000 Subject: [PATCH] Update target registration description in Writing An LLVM Backend, and add a mention in release notes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77128 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/ReleaseNotes-2.6.html | 11 +++++++-- docs/WritingAnLLVMBackend.html | 54 +++++++++++++++++++++++++++++++++++++----- 2 files changed, 57 insertions(+), 8 deletions(-) diff --git a/docs/ReleaseNotes-2.6.html b/docs/ReleaseNotes-2.6.html index 8cc833105e5..86d8e4f9e22 100644 --- a/docs/ReleaseNotes-2.6.html +++ b/docs/ReleaseNotes-2.6.html @@ -491,8 +491,15 @@ clients should be unaffected by this transition, unless they are used to Val
  • The registration interfaces for backend Targets has changed (what was -previously TargetMachineRegistry). FIXME: Complete this section, explain client -changes, point to documentation on new backend interface.
  • +previously TargetMachineRegistry). For backend authors, see the Writing An LLVM Backend guide. For clients, the notable API changes are: + +
  • llvm-dis now fails if output file exists, instead of dumping to stdout. FIXME: describe any other tool changes due to the raw_fd_ostream change. FIXME: diff --git a/docs/WritingAnLLVMBackend.html b/docs/WritingAnLLVMBackend.html index b430d4dd3f4..388e706046d 100644 --- a/docs/WritingAnLLVMBackend.html +++ b/docs/WritingAnLLVMBackend.html @@ -22,6 +22,7 @@
  • Preliminaries
  • Target Machine
  • +
  • Target Registration
  • Register Set and Register Classes
    • Defining a Register
    • @@ -422,21 +423,62 @@ SparcTargetMachine::SparcTargetMachine(const Module &M, const std::string &a alignment, and then ABI preferred alignment.
    + + + + + + +
    + +

    +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.

    + +

    +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: +

    + +
    +
    +Target llvm::TheSparcTarget;
    +
    +extern "C" void LLVMInitializeSparcTargetInfo() { 
    +  RegisterTarget 
    +    X(TheSparcTarget, "sparc", "Sparc");
    +}
    +
    +
    +

    -You must also register your target using the RegisterTarget -template. (See the TargetMachineRegistry class.) For example, -in SparcTargetMachine.cpp, the target is registered with: +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:

    -namespace {
    -  // Register the target.
    -  RegisterTarget<SparcTargetMachine>X("sparc", "SPARC");
    +extern "C" void LLVMInitializeSparcAsmPrinter() { 
    +  RegisterAsmPrinter X(TheSparcTarget);
     }
     
    +

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

    +
    -- 2.11.0