Home | History | Annotate | Download | only in Support
      1 //===-- Support/TargetRegistry.h - Target Registration ----------*- C++ -*-===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 // This file exposes the TargetRegistry interface, which tools can use to access
     11 // the appropriate target specific classes (TargetMachine, AsmPrinter, etc.)
     12 // which have been registered.
     13 //
     14 // Target specific class implementations should register themselves using the
     15 // appropriate TargetRegistry interfaces.
     16 //
     17 //===----------------------------------------------------------------------===//
     18 
     19 #ifndef LLVM_SUPPORT_TARGETREGISTRY_H
     20 #define LLVM_SUPPORT_TARGETREGISTRY_H
     21 
     22 #include "llvm/ADT/Triple.h"
     23 #include "llvm/Support/CodeGen.h"
     24 #include "llvm-c/Disassembler.h"
     25 #include <cassert>
     26 #include <string>
     27 
     28 namespace llvm {
     29   class AsmPrinter;
     30   class Module;
     31   class MCAssembler;
     32   class MCAsmBackend;
     33   class MCAsmInfo;
     34   class MCAsmParser;
     35   class MCCodeEmitter;
     36   class MCCodeGenInfo;
     37   class MCContext;
     38   class MCDisassembler;
     39   class MCInstrAnalysis;
     40   class MCInstPrinter;
     41   class MCInstrInfo;
     42   class MCRegisterInfo;
     43   class MCStreamer;
     44   class MCSubtargetInfo;
     45   class MCSymbolizer;
     46   class MCRelocationInfo;
     47   class MCTargetAsmParser;
     48   class TargetMachine;
     49   class TargetOptions;
     50   class raw_ostream;
     51   class formatted_raw_ostream;
     52 
     53   MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
     54                                 bool isVerboseAsm,
     55                                 bool useLoc, bool useCFI,
     56                                 bool useDwarfDirectory,
     57                                 MCInstPrinter *InstPrint,
     58                                 MCCodeEmitter *CE,
     59                                 MCAsmBackend *TAB,
     60                                 bool ShowInst);
     61 
     62   MCRelocationInfo *createMCRelocationInfo(StringRef TT, MCContext &Ctx);
     63 
     64   MCSymbolizer *createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
     65                                    LLVMSymbolLookupCallback SymbolLookUp,
     66                                    void *DisInfo,
     67                                    MCContext *Ctx,
     68                                    MCRelocationInfo *RelInfo);
     69 
     70   /// Target - Wrapper for Target specific information.
     71   ///
     72   /// For registration purposes, this is a POD type so that targets can be
     73   /// registered without the use of static constructors.
     74   ///
     75   /// Targets should implement a single global instance of this class (which
     76   /// will be zero initialized), and pass that instance to the TargetRegistry as
     77   /// part of their initialization.
     78   class Target {
     79   public:
     80     friend struct TargetRegistry;
     81 
     82     typedef unsigned (*TripleMatchQualityFnTy)(const std::string &TT);
     83 
     84     typedef MCAsmInfo *(*MCAsmInfoCtorFnTy)(const MCRegisterInfo &MRI,
     85                                             StringRef TT);
     86     typedef MCCodeGenInfo *(*MCCodeGenInfoCtorFnTy)(StringRef TT,
     87                                                     Reloc::Model RM,
     88                                                     CodeModel::Model CM,
     89                                                     CodeGenOpt::Level OL);
     90     typedef MCInstrInfo *(*MCInstrInfoCtorFnTy)(void);
     91     typedef MCInstrAnalysis *(*MCInstrAnalysisCtorFnTy)(const MCInstrInfo*Info);
     92     typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(StringRef TT);
     93     typedef MCSubtargetInfo *(*MCSubtargetInfoCtorFnTy)(StringRef TT,
     94                                                         StringRef CPU,
     95                                                         StringRef Features);
     96     typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T,
     97                                                   StringRef TT,
     98                                                   StringRef CPU,
     99                                                   StringRef Features,
    100                                                   const TargetOptions &Options,
    101                                                   Reloc::Model RM,
    102                                                   CodeModel::Model CM,
    103                                                   CodeGenOpt::Level OL);
    104     typedef AsmPrinter *(*AsmPrinterCtorTy)(TargetMachine &TM,
    105                                             MCStreamer &Streamer);
    106     typedef MCAsmBackend *(*MCAsmBackendCtorTy)(const Target &T,
    107                                                 StringRef TT,
    108                                                 StringRef CPU);
    109     typedef MCTargetAsmParser *(*MCAsmParserCtorTy)(MCSubtargetInfo &STI,
    110                                                     MCAsmParser &P);
    111     typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T,
    112                                                     const MCSubtargetInfo &STI);
    113     typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
    114                                                   unsigned SyntaxVariant,
    115                                                   const MCAsmInfo &MAI,
    116                                                   const MCInstrInfo &MII,
    117                                                   const MCRegisterInfo &MRI,
    118                                                   const MCSubtargetInfo &STI);
    119     typedef MCCodeEmitter *(*MCCodeEmitterCtorTy)(const MCInstrInfo &II,
    120                                                   const MCRegisterInfo &MRI,
    121                                                   const MCSubtargetInfo &STI,
    122                                                   MCContext &Ctx);
    123     typedef MCStreamer *(*MCObjectStreamerCtorTy)(const Target &T,
    124                                                   StringRef TT,
    125                                                   MCContext &Ctx,
    126                                                   MCAsmBackend &TAB,
    127                                                   raw_ostream &_OS,
    128                                                   MCCodeEmitter *_Emitter,
    129                                                   bool RelaxAll,
    130                                                   bool NoExecStack);
    131     typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx,
    132                                              formatted_raw_ostream &OS,
    133                                              bool isVerboseAsm,
    134                                              bool useLoc,
    135                                              bool useCFI,
    136                                              bool useDwarfDirectory,
    137                                              MCInstPrinter *InstPrint,
    138                                              MCCodeEmitter *CE,
    139                                              MCAsmBackend *TAB,
    140                                              bool ShowInst);
    141     typedef MCRelocationInfo *(*MCRelocationInfoCtorTy)(StringRef TT,
    142                                                         MCContext &Ctx);
    143     typedef MCSymbolizer *(*MCSymbolizerCtorTy)(StringRef TT,
    144                                    LLVMOpInfoCallback GetOpInfo,
    145                                    LLVMSymbolLookupCallback SymbolLookUp,
    146                                    void *DisInfo,
    147                                    MCContext *Ctx,
    148                                    MCRelocationInfo *RelInfo);
    149 
    150   private:
    151     /// Next - The next registered target in the linked list, maintained by the
    152     /// TargetRegistry.
    153     Target *Next;
    154 
    155     /// TripleMatchQualityFn - The target function for rating the match quality
    156     /// of a triple.
    157     TripleMatchQualityFnTy TripleMatchQualityFn;
    158 
    159     /// Name - The target name.
    160     const char *Name;
    161 
    162     /// ShortDesc - A short description of the target.
    163     const char *ShortDesc;
    164 
    165     /// HasJIT - Whether this target supports the JIT.
    166     bool HasJIT;
    167 
    168     /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
    169     /// registered.
    170     MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
    171 
    172     /// MCCodeGenInfoCtorFn - Constructor function for this target's
    173     /// MCCodeGenInfo, if registered.
    174     MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn;
    175 
    176     /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
    177     /// if registered.
    178     MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
    179 
    180     /// MCInstrAnalysisCtorFn - Constructor function for this target's
    181     /// MCInstrAnalysis, if registered.
    182     MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
    183 
    184     /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
    185     /// if registered.
    186     MCRegInfoCtorFnTy MCRegInfoCtorFn;
    187 
    188     /// MCSubtargetInfoCtorFn - Constructor function for this target's
    189     /// MCSubtargetInfo, if registered.
    190     MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
    191 
    192     /// TargetMachineCtorFn - Construction function for this target's
    193     /// TargetMachine, if registered.
    194     TargetMachineCtorTy TargetMachineCtorFn;
    195 
    196     /// MCAsmBackendCtorFn - Construction function for this target's
    197     /// MCAsmBackend, if registered.
    198     MCAsmBackendCtorTy MCAsmBackendCtorFn;
    199 
    200     /// MCAsmParserCtorFn - Construction function for this target's
    201     /// MCTargetAsmParser, if registered.
    202     MCAsmParserCtorTy MCAsmParserCtorFn;
    203 
    204     /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
    205     /// if registered.
    206     AsmPrinterCtorTy AsmPrinterCtorFn;
    207 
    208     /// MCDisassemblerCtorFn - Construction function for this target's
    209     /// MCDisassembler, if registered.
    210     MCDisassemblerCtorTy MCDisassemblerCtorFn;
    211 
    212     /// MCInstPrinterCtorFn - Construction function for this target's
    213     /// MCInstPrinter, if registered.
    214     MCInstPrinterCtorTy MCInstPrinterCtorFn;
    215 
    216     /// MCCodeEmitterCtorFn - Construction function for this target's
    217     /// CodeEmitter, if registered.
    218     MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
    219 
    220     /// MCObjectStreamerCtorFn - Construction function for this target's
    221     /// MCObjectStreamer, if registered.
    222     MCObjectStreamerCtorTy MCObjectStreamerCtorFn;
    223 
    224     /// AsmStreamerCtorFn - Construction function for this target's
    225     /// AsmStreamer, if registered (default = llvm::createAsmStreamer).
    226     AsmStreamerCtorTy AsmStreamerCtorFn;
    227 
    228     /// MCRelocationInfoCtorFn - Construction function for this target's
    229     /// MCRelocationInfo, if registered (default = llvm::createMCRelocationInfo)
    230     MCRelocationInfoCtorTy MCRelocationInfoCtorFn;
    231 
    232     /// MCSymbolizerCtorFn - Construction function for this target's
    233     /// MCSymbolizer, if registered (default = llvm::createMCSymbolizer)
    234     MCSymbolizerCtorTy MCSymbolizerCtorFn;
    235 
    236   public:
    237     Target() : AsmStreamerCtorFn(llvm::createAsmStreamer),
    238                MCRelocationInfoCtorFn(llvm::createMCRelocationInfo),
    239                MCSymbolizerCtorFn(llvm::createMCSymbolizer) {}
    240 
    241     /// @name Target Information
    242     /// @{
    243 
    244     // getNext - Return the next registered target.
    245     const Target *getNext() const { return Next; }
    246 
    247     /// getName - Get the target name.
    248     const char *getName() const { return Name; }
    249 
    250     /// getShortDescription - Get a short description of the target.
    251     const char *getShortDescription() const { return ShortDesc; }
    252 
    253     /// @}
    254     /// @name Feature Predicates
    255     /// @{
    256 
    257     /// hasJIT - Check if this targets supports the just-in-time compilation.
    258     bool hasJIT() const { return HasJIT; }
    259 
    260     /// hasTargetMachine - Check if this target supports code generation.
    261     bool hasTargetMachine() const { return TargetMachineCtorFn != 0; }
    262 
    263     /// hasMCAsmBackend - Check if this target supports .o generation.
    264     bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != 0; }
    265 
    266     /// hasAsmParser - Check if this target supports .s parsing.
    267     bool hasMCAsmParser() const { return MCAsmParserCtorFn != 0; }
    268 
    269     /// hasAsmPrinter - Check if this target supports .s printing.
    270     bool hasAsmPrinter() const { return AsmPrinterCtorFn != 0; }
    271 
    272     /// hasMCDisassembler - Check if this target has a disassembler.
    273     bool hasMCDisassembler() const { return MCDisassemblerCtorFn != 0; }
    274 
    275     /// hasMCInstPrinter - Check if this target has an instruction printer.
    276     bool hasMCInstPrinter() const { return MCInstPrinterCtorFn != 0; }
    277 
    278     /// hasMCCodeEmitter - Check if this target supports instruction encoding.
    279     bool hasMCCodeEmitter() const { return MCCodeEmitterCtorFn != 0; }
    280 
    281     /// hasMCObjectStreamer - Check if this target supports streaming to files.
    282     bool hasMCObjectStreamer() const { return MCObjectStreamerCtorFn != 0; }
    283 
    284     /// hasAsmStreamer - Check if this target supports streaming to files.
    285     bool hasAsmStreamer() const { return AsmStreamerCtorFn != 0; }
    286 
    287     /// @}
    288     /// @name Feature Constructors
    289     /// @{
    290 
    291     /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
    292     /// target triple.
    293     ///
    294     /// \param Triple This argument is used to determine the target machine
    295     /// feature set; it should always be provided. Generally this should be
    296     /// either the target triple from the module, or the target triple of the
    297     /// host if that does not exist.
    298     MCAsmInfo *createMCAsmInfo(const MCRegisterInfo &MRI,
    299                                StringRef Triple) const {
    300       if (!MCAsmInfoCtorFn)
    301         return 0;
    302       return MCAsmInfoCtorFn(MRI, Triple);
    303     }
    304 
    305     /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
    306     ///
    307     MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model RM,
    308                                        CodeModel::Model CM,
    309                                        CodeGenOpt::Level OL) const {
    310       if (!MCCodeGenInfoCtorFn)
    311         return 0;
    312       return MCCodeGenInfoCtorFn(Triple, RM, CM, OL);
    313     }
    314 
    315     /// createMCInstrInfo - Create a MCInstrInfo implementation.
    316     ///
    317     MCInstrInfo *createMCInstrInfo() const {
    318       if (!MCInstrInfoCtorFn)
    319         return 0;
    320       return MCInstrInfoCtorFn();
    321     }
    322 
    323     /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
    324     ///
    325     MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
    326       if (!MCInstrAnalysisCtorFn)
    327         return 0;
    328       return MCInstrAnalysisCtorFn(Info);
    329     }
    330 
    331     /// createMCRegInfo - Create a MCRegisterInfo implementation.
    332     ///
    333     MCRegisterInfo *createMCRegInfo(StringRef Triple) const {
    334       if (!MCRegInfoCtorFn)
    335         return 0;
    336       return MCRegInfoCtorFn(Triple);
    337     }
    338 
    339     /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
    340     ///
    341     /// \param Triple This argument is used to determine the target machine
    342     /// feature set; it should always be provided. Generally this should be
    343     /// either the target triple from the module, or the target triple of the
    344     /// host if that does not exist.
    345     /// \param CPU This specifies the name of the target CPU.
    346     /// \param Features This specifies the string representation of the
    347     /// additional target features.
    348     MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU,
    349                                            StringRef Features) const {
    350       if (!MCSubtargetInfoCtorFn)
    351         return 0;
    352       return MCSubtargetInfoCtorFn(Triple, CPU, Features);
    353     }
    354 
    355     /// createTargetMachine - Create a target specific machine implementation
    356     /// for the specified \p Triple.
    357     ///
    358     /// \param Triple This argument is used to determine the target machine
    359     /// feature set; it should always be provided. Generally this should be
    360     /// either the target triple from the module, or the target triple of the
    361     /// host if that does not exist.
    362     TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU,
    363                              StringRef Features, const TargetOptions &Options,
    364                              Reloc::Model RM = Reloc::Default,
    365                              CodeModel::Model CM = CodeModel::Default,
    366                              CodeGenOpt::Level OL = CodeGenOpt::Default) const {
    367       if (!TargetMachineCtorFn)
    368         return 0;
    369       return TargetMachineCtorFn(*this, Triple, CPU, Features, Options,
    370                                  RM, CM, OL);
    371     }
    372 
    373     /// createMCAsmBackend - Create a target specific assembly parser.
    374     ///
    375     /// \param Triple The target triple string.
    376     MCAsmBackend *createMCAsmBackend(StringRef Triple, StringRef CPU) const {
    377       if (!MCAsmBackendCtorFn)
    378         return 0;
    379       return MCAsmBackendCtorFn(*this, Triple, CPU);
    380     }
    381 
    382     /// createMCAsmParser - Create a target specific assembly parser.
    383     ///
    384     /// \param Parser The target independent parser implementation to use for
    385     /// parsing and lexing.
    386     MCTargetAsmParser *createMCAsmParser(MCSubtargetInfo &STI,
    387                                          MCAsmParser &Parser) const {
    388       if (!MCAsmParserCtorFn)
    389         return 0;
    390       return MCAsmParserCtorFn(STI, Parser);
    391     }
    392 
    393     /// createAsmPrinter - Create a target specific assembly printer pass.  This
    394     /// takes ownership of the MCStreamer object.
    395     AsmPrinter *createAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) const{
    396       if (!AsmPrinterCtorFn)
    397         return 0;
    398       return AsmPrinterCtorFn(TM, Streamer);
    399     }
    400 
    401     MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI) const {
    402       if (!MCDisassemblerCtorFn)
    403         return 0;
    404       return MCDisassemblerCtorFn(*this, STI);
    405     }
    406 
    407     MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
    408                                        const MCAsmInfo &MAI,
    409                                        const MCInstrInfo &MII,
    410                                        const MCRegisterInfo &MRI,
    411                                        const MCSubtargetInfo &STI) const {
    412       if (!MCInstPrinterCtorFn)
    413         return 0;
    414       return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, MII, MRI, STI);
    415     }
    416 
    417 
    418     /// createMCCodeEmitter - Create a target specific code emitter.
    419     MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
    420                                        const MCRegisterInfo &MRI,
    421                                        const MCSubtargetInfo &STI,
    422                                        MCContext &Ctx) const {
    423       if (!MCCodeEmitterCtorFn)
    424         return 0;
    425       return MCCodeEmitterCtorFn(II, MRI, STI, Ctx);
    426     }
    427 
    428     /// createMCObjectStreamer - Create a target specific MCStreamer.
    429     ///
    430     /// \param TT The target triple.
    431     /// \param Ctx The target context.
    432     /// \param TAB The target assembler backend object. Takes ownership.
    433     /// \param _OS The stream object.
    434     /// \param _Emitter The target independent assembler object.Takes ownership.
    435     /// \param RelaxAll Relax all fixups?
    436     /// \param NoExecStack Mark file as not needing a executable stack.
    437     MCStreamer *createMCObjectStreamer(StringRef TT, MCContext &Ctx,
    438                                        MCAsmBackend &TAB,
    439                                        raw_ostream &_OS,
    440                                        MCCodeEmitter *_Emitter,
    441                                        bool RelaxAll,
    442                                        bool NoExecStack) const {
    443       if (!MCObjectStreamerCtorFn)
    444         return 0;
    445       return MCObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter,
    446                                     RelaxAll, NoExecStack);
    447     }
    448 
    449     /// createAsmStreamer - Create a target specific MCStreamer.
    450     MCStreamer *createAsmStreamer(MCContext &Ctx,
    451                                   formatted_raw_ostream &OS,
    452                                   bool isVerboseAsm,
    453                                   bool useLoc,
    454                                   bool useCFI,
    455                                   bool useDwarfDirectory,
    456                                   MCInstPrinter *InstPrint,
    457                                   MCCodeEmitter *CE,
    458                                   MCAsmBackend *TAB,
    459                                   bool ShowInst) const {
    460       // AsmStreamerCtorFn is default to llvm::createAsmStreamer
    461       return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useLoc, useCFI,
    462                                useDwarfDirectory, InstPrint, CE, TAB, ShowInst);
    463     }
    464 
    465     /// createMCRelocationInfo - Create a target specific MCRelocationInfo.
    466     ///
    467     /// \param TT The target triple.
    468     /// \param Ctx The target context.
    469     MCRelocationInfo *
    470       createMCRelocationInfo(StringRef TT, MCContext &Ctx) const {
    471       return MCRelocationInfoCtorFn(TT, Ctx);
    472     }
    473 
    474     /// createMCSymbolizer - Create a target specific MCSymbolizer.
    475     ///
    476     /// \param TT The target triple.
    477     /// \param GetOpInfo The function to get the symbolic information for operands.
    478     /// \param SymbolLookUp The function to lookup a symbol name.
    479     /// \param DisInfo The pointer to the block of symbolic information for above call
    480     /// back.
    481     /// \param Ctx The target context.
    482     /// \param RelInfo The relocation information for this target. Takes ownership.
    483     MCSymbolizer *
    484     createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
    485                        LLVMSymbolLookupCallback SymbolLookUp,
    486                        void *DisInfo,
    487                        MCContext *Ctx, MCRelocationInfo *RelInfo) const {
    488       return MCSymbolizerCtorFn(TT, GetOpInfo, SymbolLookUp, DisInfo,
    489                                 Ctx, RelInfo);
    490     }
    491 
    492     /// @}
    493   };
    494 
    495   /// TargetRegistry - Generic interface to target specific features.
    496   struct TargetRegistry {
    497     class iterator {
    498       const Target *Current;
    499       explicit iterator(Target *T) : Current(T) {}
    500       friend struct TargetRegistry;
    501     public:
    502       iterator(const iterator &I) : Current(I.Current) {}
    503       iterator() : Current(0) {}
    504 
    505       bool operator==(const iterator &x) const {
    506         return Current == x.Current;
    507       }
    508       bool operator!=(const iterator &x) const {
    509         return !operator==(x);
    510       }
    511 
    512       // Iterator traversal: forward iteration only
    513       iterator &operator++() {          // Preincrement
    514         assert(Current && "Cannot increment end iterator!");
    515         Current = Current->getNext();
    516         return *this;
    517       }
    518       iterator operator++(int) {        // Postincrement
    519         iterator tmp = *this;
    520         ++*this;
    521         return tmp;
    522       }
    523 
    524       const Target &operator*() const {
    525         assert(Current && "Cannot dereference end iterator!");
    526         return *Current;
    527       }
    528 
    529       const Target *operator->() const {
    530         return &operator*();
    531       }
    532     };
    533 
    534     /// printRegisteredTargetsForVersion - Print the registered targets
    535     /// appropriately for inclusion in a tool's version output.
    536     static void printRegisteredTargetsForVersion();
    537 
    538     /// @name Registry Access
    539     /// @{
    540 
    541     static iterator begin();
    542 
    543     static iterator end() { return iterator(); }
    544 
    545     /// lookupTarget - Lookup a target based on a target triple.
    546     ///
    547     /// \param Triple - The triple to use for finding a target.
    548     /// \param Error - On failure, an error string describing why no target was
    549     /// found.
    550     static const Target *lookupTarget(const std::string &Triple,
    551                                       std::string &Error);
    552 
    553     /// lookupTarget - Lookup a target based on an architecture name
    554     /// and a target triple.  If the architecture name is non-empty,
    555     /// then the lookup is done by architecture.  Otherwise, the target
    556     /// triple is used.
    557     ///
    558     /// \param ArchName - The architecture to use for finding a target.
    559     /// \param TheTriple - The triple to use for finding a target.  The
    560     /// triple is updated with canonical architecture name if a lookup
    561     /// by architecture is done.
    562     /// \param Error - On failure, an error string describing why no target was
    563     /// found.
    564     static const Target *lookupTarget(const std::string &ArchName,
    565                                       Triple &TheTriple,
    566                                       std::string &Error);
    567 
    568     /// getClosestTargetForJIT - Pick the best target that is compatible with
    569     /// the current host.  If no close target can be found, this returns null
    570     /// and sets the Error string to a reason.
    571     ///
    572     /// Maintained for compatibility through 2.6.
    573     static const Target *getClosestTargetForJIT(std::string &Error);
    574 
    575     /// @}
    576     /// @name Target Registration
    577     /// @{
    578 
    579     /// RegisterTarget - Register the given target. Attempts to register a
    580     /// target which has already been registered will be ignored.
    581     ///
    582     /// Clients are responsible for ensuring that registration doesn't occur
    583     /// while another thread is attempting to access the registry. Typically
    584     /// this is done by initializing all targets at program startup.
    585     ///
    586     /// @param T - The target being registered.
    587     /// @param Name - The target name. This should be a static string.
    588     /// @param ShortDesc - A short target description. This should be a static
    589     /// string.
    590     /// @param TQualityFn - The triple match quality computation function for
    591     /// this target.
    592     /// @param HasJIT - Whether the target supports JIT code
    593     /// generation.
    594     static void RegisterTarget(Target &T,
    595                                const char *Name,
    596                                const char *ShortDesc,
    597                                Target::TripleMatchQualityFnTy TQualityFn,
    598                                bool HasJIT = false);
    599 
    600     /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
    601     /// given target.
    602     ///
    603     /// Clients are responsible for ensuring that registration doesn't occur
    604     /// while another thread is attempting to access the registry. Typically
    605     /// this is done by initializing all targets at program startup.
    606     ///
    607     /// @param T - The target being registered.
    608     /// @param Fn - A function to construct a MCAsmInfo for the target.
    609     static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
    610       // Ignore duplicate registration.
    611       if (!T.MCAsmInfoCtorFn)
    612         T.MCAsmInfoCtorFn = Fn;
    613     }
    614 
    615     /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
    616     /// given target.
    617     ///
    618     /// Clients are responsible for ensuring that registration doesn't occur
    619     /// while another thread is attempting to access the registry. Typically
    620     /// this is done by initializing all targets at program startup.
    621     ///
    622     /// @param T - The target being registered.
    623     /// @param Fn - A function to construct a MCCodeGenInfo for the target.
    624     static void RegisterMCCodeGenInfo(Target &T,
    625                                      Target::MCCodeGenInfoCtorFnTy Fn) {
    626       // Ignore duplicate registration.
    627       if (!T.MCCodeGenInfoCtorFn)
    628         T.MCCodeGenInfoCtorFn = Fn;
    629     }
    630 
    631     /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
    632     /// given target.
    633     ///
    634     /// Clients are responsible for ensuring that registration doesn't occur
    635     /// while another thread is attempting to access the registry. Typically
    636     /// this is done by initializing all targets at program startup.
    637     ///
    638     /// @param T - The target being registered.
    639     /// @param Fn - A function to construct a MCInstrInfo for the target.
    640     static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
    641       // Ignore duplicate registration.
    642       if (!T.MCInstrInfoCtorFn)
    643         T.MCInstrInfoCtorFn = Fn;
    644     }
    645 
    646     /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
    647     /// the given target.
    648     static void RegisterMCInstrAnalysis(Target &T,
    649                                         Target::MCInstrAnalysisCtorFnTy Fn) {
    650       // Ignore duplicate registration.
    651       if (!T.MCInstrAnalysisCtorFn)
    652         T.MCInstrAnalysisCtorFn = Fn;
    653     }
    654 
    655     /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
    656     /// given target.
    657     ///
    658     /// Clients are responsible for ensuring that registration doesn't occur
    659     /// while another thread is attempting to access the registry. Typically
    660     /// this is done by initializing all targets at program startup.
    661     ///
    662     /// @param T - The target being registered.
    663     /// @param Fn - A function to construct a MCRegisterInfo for the target.
    664     static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
    665       // Ignore duplicate registration.
    666       if (!T.MCRegInfoCtorFn)
    667         T.MCRegInfoCtorFn = Fn;
    668     }
    669 
    670     /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
    671     /// the given target.
    672     ///
    673     /// Clients are responsible for ensuring that registration doesn't occur
    674     /// while another thread is attempting to access the registry. Typically
    675     /// this is done by initializing all targets at program startup.
    676     ///
    677     /// @param T - The target being registered.
    678     /// @param Fn - A function to construct a MCSubtargetInfo for the target.
    679     static void RegisterMCSubtargetInfo(Target &T,
    680                                         Target::MCSubtargetInfoCtorFnTy Fn) {
    681       // Ignore duplicate registration.
    682       if (!T.MCSubtargetInfoCtorFn)
    683         T.MCSubtargetInfoCtorFn = Fn;
    684     }
    685 
    686     /// RegisterTargetMachine - Register a TargetMachine implementation for the
    687     /// given target.
    688     ///
    689     /// Clients are responsible for ensuring that registration doesn't occur
    690     /// while another thread is attempting to access the registry. Typically
    691     /// this is done by initializing all targets at program startup.
    692     ///
    693     /// @param T - The target being registered.
    694     /// @param Fn - A function to construct a TargetMachine for the target.
    695     static void RegisterTargetMachine(Target &T,
    696                                       Target::TargetMachineCtorTy Fn) {
    697       // Ignore duplicate registration.
    698       if (!T.TargetMachineCtorFn)
    699         T.TargetMachineCtorFn = Fn;
    700     }
    701 
    702     /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
    703     /// given target.
    704     ///
    705     /// Clients are responsible for ensuring that registration doesn't occur
    706     /// while another thread is attempting to access the registry. Typically
    707     /// this is done by initializing all targets at program startup.
    708     ///
    709     /// @param T - The target being registered.
    710     /// @param Fn - A function to construct an AsmBackend for the target.
    711     static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
    712       if (!T.MCAsmBackendCtorFn)
    713         T.MCAsmBackendCtorFn = Fn;
    714     }
    715 
    716     /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
    717     /// the given target.
    718     ///
    719     /// Clients are responsible for ensuring that registration doesn't occur
    720     /// while another thread is attempting to access the registry. Typically
    721     /// this is done by initializing all targets at program startup.
    722     ///
    723     /// @param T - The target being registered.
    724     /// @param Fn - A function to construct an MCTargetAsmParser for the target.
    725     static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
    726       if (!T.MCAsmParserCtorFn)
    727         T.MCAsmParserCtorFn = Fn;
    728     }
    729 
    730     /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
    731     /// target.
    732     ///
    733     /// Clients are responsible for ensuring that registration doesn't occur
    734     /// while another thread is attempting to access the registry. Typically
    735     /// this is done by initializing all targets at program startup.
    736     ///
    737     /// @param T - The target being registered.
    738     /// @param Fn - A function to construct an AsmPrinter for the target.
    739     static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
    740       // Ignore duplicate registration.
    741       if (!T.AsmPrinterCtorFn)
    742         T.AsmPrinterCtorFn = Fn;
    743     }
    744 
    745     /// RegisterMCDisassembler - Register a MCDisassembler implementation for
    746     /// the given target.
    747     ///
    748     /// Clients are responsible for ensuring that registration doesn't occur
    749     /// while another thread is attempting to access the registry. Typically
    750     /// this is done by initializing all targets at program startup.
    751     ///
    752     /// @param T - The target being registered.
    753     /// @param Fn - A function to construct an MCDisassembler for the target.
    754     static void RegisterMCDisassembler(Target &T,
    755                                        Target::MCDisassemblerCtorTy Fn) {
    756       if (!T.MCDisassemblerCtorFn)
    757         T.MCDisassemblerCtorFn = Fn;
    758     }
    759 
    760     /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
    761     /// given target.
    762     ///
    763     /// Clients are responsible for ensuring that registration doesn't occur
    764     /// while another thread is attempting to access the registry. Typically
    765     /// this is done by initializing all targets at program startup.
    766     ///
    767     /// @param T - The target being registered.
    768     /// @param Fn - A function to construct an MCInstPrinter for the target.
    769     static void RegisterMCInstPrinter(Target &T,
    770                                       Target::MCInstPrinterCtorTy Fn) {
    771       if (!T.MCInstPrinterCtorFn)
    772         T.MCInstPrinterCtorFn = Fn;
    773     }
    774 
    775     /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
    776     /// given target.
    777     ///
    778     /// Clients are responsible for ensuring that registration doesn't occur
    779     /// while another thread is attempting to access the registry. Typically
    780     /// this is done by initializing all targets at program startup.
    781     ///
    782     /// @param T - The target being registered.
    783     /// @param Fn - A function to construct an MCCodeEmitter for the target.
    784     static void RegisterMCCodeEmitter(Target &T,
    785                                       Target::MCCodeEmitterCtorTy Fn) {
    786       if (!T.MCCodeEmitterCtorFn)
    787         T.MCCodeEmitterCtorFn = Fn;
    788     }
    789 
    790     /// RegisterMCObjectStreamer - Register a object code MCStreamer
    791     /// implementation for the given target.
    792     ///
    793     /// Clients are responsible for ensuring that registration doesn't occur
    794     /// while another thread is attempting to access the registry. Typically
    795     /// this is done by initializing all targets at program startup.
    796     ///
    797     /// @param T - The target being registered.
    798     /// @param Fn - A function to construct an MCStreamer for the target.
    799     static void RegisterMCObjectStreamer(Target &T,
    800                                          Target::MCObjectStreamerCtorTy Fn) {
    801       if (!T.MCObjectStreamerCtorFn)
    802         T.MCObjectStreamerCtorFn = Fn;
    803     }
    804 
    805     /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
    806     /// for the given target.
    807     ///
    808     /// Clients are responsible for ensuring that registration doesn't occur
    809     /// while another thread is attempting to access the registry. Typically
    810     /// this is done by initializing all targets at program startup.
    811     ///
    812     /// @param T - The target being registered.
    813     /// @param Fn - A function to construct an MCStreamer for the target.
    814     static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
    815       if (T.AsmStreamerCtorFn == createAsmStreamer)
    816         T.AsmStreamerCtorFn = Fn;
    817     }
    818 
    819     /// RegisterMCRelocationInfo - Register an MCRelocationInfo
    820     /// implementation for the given target.
    821     ///
    822     /// Clients are responsible for ensuring that registration doesn't occur
    823     /// while another thread is attempting to access the registry. Typically
    824     /// this is done by initializing all targets at program startup.
    825     ///
    826     /// @param T - The target being registered.
    827     /// @param Fn - A function to construct an MCRelocationInfo for the target.
    828     static void RegisterMCRelocationInfo(Target &T,
    829                                          Target::MCRelocationInfoCtorTy Fn) {
    830       if (T.MCRelocationInfoCtorFn == llvm::createMCRelocationInfo)
    831         T.MCRelocationInfoCtorFn = Fn;
    832     }
    833 
    834     /// RegisterMCSymbolizer - Register an MCSymbolizer
    835     /// implementation for the given target.
    836     ///
    837     /// Clients are responsible for ensuring that registration doesn't occur
    838     /// while another thread is attempting to access the registry. Typically
    839     /// this is done by initializing all targets at program startup.
    840     ///
    841     /// @param T - The target being registered.
    842     /// @param Fn - A function to construct an MCSymbolizer for the target.
    843     static void RegisterMCSymbolizer(Target &T,
    844                                      Target::MCSymbolizerCtorTy Fn) {
    845       if (T.MCSymbolizerCtorFn == llvm::createMCSymbolizer)
    846         T.MCSymbolizerCtorFn = Fn;
    847     }
    848 
    849     /// @}
    850   };
    851 
    852 
    853   //===--------------------------------------------------------------------===//
    854 
    855   /// RegisterTarget - Helper template for registering a target, for use in the
    856   /// target's initialization function. Usage:
    857   ///
    858   ///
    859   /// Target TheFooTarget; // The global target instance.
    860   ///
    861   /// extern "C" void LLVMInitializeFooTargetInfo() {
    862   ///   RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
    863   /// }
    864   template<Triple::ArchType TargetArchType = Triple::UnknownArch,
    865            bool HasJIT = false>
    866   struct RegisterTarget {
    867     RegisterTarget(Target &T, const char *Name, const char *Desc) {
    868       TargetRegistry::RegisterTarget(T, Name, Desc,
    869                                      &getTripleMatchQuality,
    870                                      HasJIT);
    871     }
    872 
    873     static unsigned getTripleMatchQuality(const std::string &TT) {
    874       if (Triple(TT).getArch() == TargetArchType)
    875         return 20;
    876       return 0;
    877     }
    878   };
    879 
    880   /// RegisterMCAsmInfo - Helper template for registering a target assembly info
    881   /// implementation.  This invokes the static "Create" method on the class to
    882   /// actually do the construction.  Usage:
    883   ///
    884   /// extern "C" void LLVMInitializeFooTarget() {
    885   ///   extern Target TheFooTarget;
    886   ///   RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
    887   /// }
    888   template<class MCAsmInfoImpl>
    889   struct RegisterMCAsmInfo {
    890     RegisterMCAsmInfo(Target &T) {
    891       TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
    892     }
    893   private:
    894     static MCAsmInfo *Allocator(const MCRegisterInfo &/*MRI*/, StringRef TT) {
    895       return new MCAsmInfoImpl(TT);
    896     }
    897 
    898   };
    899 
    900   /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
    901   /// implementation.  This invokes the specified function to do the
    902   /// construction.  Usage:
    903   ///
    904   /// extern "C" void LLVMInitializeFooTarget() {
    905   ///   extern Target TheFooTarget;
    906   ///   RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
    907   /// }
    908   struct RegisterMCAsmInfoFn {
    909     RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
    910       TargetRegistry::RegisterMCAsmInfo(T, Fn);
    911     }
    912   };
    913 
    914   /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
    915   /// implementation.  This invokes the static "Create" method on the class
    916   /// to actually do the construction.  Usage:
    917   ///
    918   /// extern "C" void LLVMInitializeFooTarget() {
    919   ///   extern Target TheFooTarget;
    920   ///   RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
    921   /// }
    922   template<class MCCodeGenInfoImpl>
    923   struct RegisterMCCodeGenInfo {
    924     RegisterMCCodeGenInfo(Target &T) {
    925       TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
    926     }
    927   private:
    928     static MCCodeGenInfo *Allocator(StringRef /*TT*/, Reloc::Model /*RM*/,
    929                                     CodeModel::Model /*CM*/,
    930                                     CodeGenOpt::Level /*OL*/) {
    931       return new MCCodeGenInfoImpl();
    932     }
    933   };
    934 
    935   /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
    936   /// info implementation.  This invokes the specified function to do the
    937   /// construction.  Usage:
    938   ///
    939   /// extern "C" void LLVMInitializeFooTarget() {
    940   ///   extern Target TheFooTarget;
    941   ///   RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
    942   /// }
    943   struct RegisterMCCodeGenInfoFn {
    944     RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
    945       TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
    946     }
    947   };
    948 
    949   /// RegisterMCInstrInfo - Helper template for registering a target instruction
    950   /// info implementation.  This invokes the static "Create" method on the class
    951   /// to actually do the construction.  Usage:
    952   ///
    953   /// extern "C" void LLVMInitializeFooTarget() {
    954   ///   extern Target TheFooTarget;
    955   ///   RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
    956   /// }
    957   template<class MCInstrInfoImpl>
    958   struct RegisterMCInstrInfo {
    959     RegisterMCInstrInfo(Target &T) {
    960       TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
    961     }
    962   private:
    963     static MCInstrInfo *Allocator() {
    964       return new MCInstrInfoImpl();
    965     }
    966   };
    967 
    968   /// RegisterMCInstrInfoFn - Helper template for registering a target
    969   /// instruction info implementation.  This invokes the specified function to
    970   /// do the construction.  Usage:
    971   ///
    972   /// extern "C" void LLVMInitializeFooTarget() {
    973   ///   extern Target TheFooTarget;
    974   ///   RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
    975   /// }
    976   struct RegisterMCInstrInfoFn {
    977     RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
    978       TargetRegistry::RegisterMCInstrInfo(T, Fn);
    979     }
    980   };
    981 
    982   /// RegisterMCInstrAnalysis - Helper template for registering a target
    983   /// instruction analyzer implementation.  This invokes the static "Create"
    984   /// method on the class to actually do the construction.  Usage:
    985   ///
    986   /// extern "C" void LLVMInitializeFooTarget() {
    987   ///   extern Target TheFooTarget;
    988   ///   RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
    989   /// }
    990   template<class MCInstrAnalysisImpl>
    991   struct RegisterMCInstrAnalysis {
    992     RegisterMCInstrAnalysis(Target &T) {
    993       TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
    994     }
    995   private:
    996     static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
    997       return new MCInstrAnalysisImpl(Info);
    998     }
    999   };
   1000 
   1001   /// RegisterMCInstrAnalysisFn - Helper template for registering a target
   1002   /// instruction analyzer implementation.  This invokes the specified function
   1003   /// to do the construction.  Usage:
   1004   ///
   1005   /// extern "C" void LLVMInitializeFooTarget() {
   1006   ///   extern Target TheFooTarget;
   1007   ///   RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
   1008   /// }
   1009   struct RegisterMCInstrAnalysisFn {
   1010     RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
   1011       TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
   1012     }
   1013   };
   1014 
   1015   /// RegisterMCRegInfo - Helper template for registering a target register info
   1016   /// implementation.  This invokes the static "Create" method on the class to
   1017   /// actually do the construction.  Usage:
   1018   ///
   1019   /// extern "C" void LLVMInitializeFooTarget() {
   1020   ///   extern Target TheFooTarget;
   1021   ///   RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
   1022   /// }
   1023   template<class MCRegisterInfoImpl>
   1024   struct RegisterMCRegInfo {
   1025     RegisterMCRegInfo(Target &T) {
   1026       TargetRegistry::RegisterMCRegInfo(T, &Allocator);
   1027     }
   1028   private:
   1029     static MCRegisterInfo *Allocator(StringRef /*TT*/) {
   1030       return new MCRegisterInfoImpl();
   1031     }
   1032   };
   1033 
   1034   /// RegisterMCRegInfoFn - Helper template for registering a target register
   1035   /// info implementation.  This invokes the specified function to do the
   1036   /// construction.  Usage:
   1037   ///
   1038   /// extern "C" void LLVMInitializeFooTarget() {
   1039   ///   extern Target TheFooTarget;
   1040   ///   RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
   1041   /// }
   1042   struct RegisterMCRegInfoFn {
   1043     RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
   1044       TargetRegistry::RegisterMCRegInfo(T, Fn);
   1045     }
   1046   };
   1047 
   1048   /// RegisterMCSubtargetInfo - Helper template for registering a target
   1049   /// subtarget info implementation.  This invokes the static "Create" method
   1050   /// on the class to actually do the construction.  Usage:
   1051   ///
   1052   /// extern "C" void LLVMInitializeFooTarget() {
   1053   ///   extern Target TheFooTarget;
   1054   ///   RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
   1055   /// }
   1056   template<class MCSubtargetInfoImpl>
   1057   struct RegisterMCSubtargetInfo {
   1058     RegisterMCSubtargetInfo(Target &T) {
   1059       TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
   1060     }
   1061   private:
   1062     static MCSubtargetInfo *Allocator(StringRef /*TT*/, StringRef /*CPU*/,
   1063                                       StringRef /*FS*/) {
   1064       return new MCSubtargetInfoImpl();
   1065     }
   1066   };
   1067 
   1068   /// RegisterMCSubtargetInfoFn - Helper template for registering a target
   1069   /// subtarget info implementation.  This invokes the specified function to
   1070   /// do the construction.  Usage:
   1071   ///
   1072   /// extern "C" void LLVMInitializeFooTarget() {
   1073   ///   extern Target TheFooTarget;
   1074   ///   RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
   1075   /// }
   1076   struct RegisterMCSubtargetInfoFn {
   1077     RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
   1078       TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
   1079     }
   1080   };
   1081 
   1082   /// RegisterTargetMachine - Helper template for registering a target machine
   1083   /// implementation, for use in the target machine initialization
   1084   /// function. Usage:
   1085   ///
   1086   /// extern "C" void LLVMInitializeFooTarget() {
   1087   ///   extern Target TheFooTarget;
   1088   ///   RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
   1089   /// }
   1090   template<class TargetMachineImpl>
   1091   struct RegisterTargetMachine {
   1092     RegisterTargetMachine(Target &T) {
   1093       TargetRegistry::RegisterTargetMachine(T, &Allocator);
   1094     }
   1095 
   1096   private:
   1097     static TargetMachine *Allocator(const Target &T, StringRef TT,
   1098                                     StringRef CPU, StringRef FS,
   1099                                     const TargetOptions &Options,
   1100                                     Reloc::Model RM,
   1101                                     CodeModel::Model CM,
   1102                                     CodeGenOpt::Level OL) {
   1103       return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
   1104     }
   1105   };
   1106 
   1107   /// RegisterMCAsmBackend - Helper template for registering a target specific
   1108   /// assembler backend. Usage:
   1109   ///
   1110   /// extern "C" void LLVMInitializeFooMCAsmBackend() {
   1111   ///   extern Target TheFooTarget;
   1112   ///   RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
   1113   /// }
   1114   template<class MCAsmBackendImpl>
   1115   struct RegisterMCAsmBackend {
   1116     RegisterMCAsmBackend(Target &T) {
   1117       TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
   1118     }
   1119 
   1120   private:
   1121     static MCAsmBackend *Allocator(const Target &T, StringRef Triple,
   1122                                    StringRef CPU) {
   1123       return new MCAsmBackendImpl(T, Triple, CPU);
   1124     }
   1125   };
   1126 
   1127   /// RegisterMCAsmParser - Helper template for registering a target specific
   1128   /// assembly parser, for use in the target machine initialization
   1129   /// function. Usage:
   1130   ///
   1131   /// extern "C" void LLVMInitializeFooMCAsmParser() {
   1132   ///   extern Target TheFooTarget;
   1133   ///   RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
   1134   /// }
   1135   template<class MCAsmParserImpl>
   1136   struct RegisterMCAsmParser {
   1137     RegisterMCAsmParser(Target &T) {
   1138       TargetRegistry::RegisterMCAsmParser(T, &Allocator);
   1139     }
   1140 
   1141   private:
   1142     static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P) {
   1143       return new MCAsmParserImpl(STI, P);
   1144     }
   1145   };
   1146 
   1147   /// RegisterAsmPrinter - Helper template for registering a target specific
   1148   /// assembly printer, for use in the target machine initialization
   1149   /// function. Usage:
   1150   ///
   1151   /// extern "C" void LLVMInitializeFooAsmPrinter() {
   1152   ///   extern Target TheFooTarget;
   1153   ///   RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
   1154   /// }
   1155   template<class AsmPrinterImpl>
   1156   struct RegisterAsmPrinter {
   1157     RegisterAsmPrinter(Target &T) {
   1158       TargetRegistry::RegisterAsmPrinter(T, &Allocator);
   1159     }
   1160 
   1161   private:
   1162     static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) {
   1163       return new AsmPrinterImpl(TM, Streamer);
   1164     }
   1165   };
   1166 
   1167   /// RegisterMCCodeEmitter - Helper template for registering a target specific
   1168   /// machine code emitter, for use in the target initialization
   1169   /// function. Usage:
   1170   ///
   1171   /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
   1172   ///   extern Target TheFooTarget;
   1173   ///   RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
   1174   /// }
   1175   template<class MCCodeEmitterImpl>
   1176   struct RegisterMCCodeEmitter {
   1177     RegisterMCCodeEmitter(Target &T) {
   1178       TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
   1179     }
   1180 
   1181   private:
   1182     static MCCodeEmitter *Allocator(const MCInstrInfo &/*II*/,
   1183                                     const MCRegisterInfo &/*MRI*/,
   1184                                     const MCSubtargetInfo &/*STI*/,
   1185                                     MCContext &/*Ctx*/) {
   1186       return new MCCodeEmitterImpl();
   1187     }
   1188   };
   1189 
   1190 }
   1191 
   1192 #endif
   1193