LLVM  mainline
TargetRegistry.h
Go to the documentation of this file.
00001 //===-- Support/TargetRegistry.h - Target Registration ----------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file exposes the TargetRegistry interface, which tools can use to access
00011 // the appropriate target specific classes (TargetMachine, AsmPrinter, etc.)
00012 // which have been registered.
00013 //
00014 // Target specific class implementations should register themselves using the
00015 // appropriate TargetRegistry interfaces.
00016 //
00017 //===----------------------------------------------------------------------===//
00018 
00019 #ifndef LLVM_SUPPORT_TARGETREGISTRY_H
00020 #define LLVM_SUPPORT_TARGETREGISTRY_H
00021 
00022 #include "llvm-c/Disassembler.h"
00023 #include "llvm/ADT/Triple.h"
00024 #include "llvm/Support/CodeGen.h"
00025 #include "llvm/Support/FormattedStream.h"
00026 #include <cassert>
00027 #include <memory>
00028 #include <string>
00029 
00030 namespace llvm {
00031   class AsmPrinter;
00032   class MCAsmBackend;
00033   class MCAsmInfo;
00034   class MCAsmParser;
00035   class MCCodeEmitter;
00036   class MCCodeGenInfo;
00037   class MCContext;
00038   class MCDisassembler;
00039   class MCInstrAnalysis;
00040   class MCInstPrinter;
00041   class MCInstrInfo;
00042   class MCRegisterInfo;
00043   class MCStreamer;
00044   class MCSubtargetInfo;
00045   class MCSymbolizer;
00046   class MCRelocationInfo;
00047   class MCTargetAsmParser;
00048   class MCTargetOptions;
00049   class MCTargetStreamer;
00050   class TargetMachine;
00051   class TargetOptions;
00052   class raw_ostream;
00053   class raw_pwrite_stream;
00054   class formatted_raw_ostream;
00055 
00056   MCStreamer *createNullStreamer(MCContext &Ctx);
00057   MCStreamer *createAsmStreamer(MCContext &Ctx,
00058                                 std::unique_ptr<formatted_raw_ostream> OS,
00059                                 bool isVerboseAsm, bool useDwarfDirectory,
00060                                 MCInstPrinter *InstPrint, MCCodeEmitter *CE,
00061                                 MCAsmBackend *TAB, bool ShowInst);
00062 
00063   /// Takes ownership of \p TAB and \p CE.
00064   MCStreamer *createELFStreamer(MCContext &Ctx, MCAsmBackend &TAB,
00065                                 raw_pwrite_stream &OS, MCCodeEmitter *CE,
00066                                 bool RelaxAll);
00067   MCStreamer *createMachOStreamer(MCContext &Ctx, MCAsmBackend &TAB,
00068                                   raw_pwrite_stream &OS, MCCodeEmitter *CE,
00069                                   bool RelaxAll, bool DWARFMustBeAtTheEnd,
00070                                   bool LabelSections = false);
00071 
00072   MCRelocationInfo *createMCRelocationInfo(StringRef TT, MCContext &Ctx);
00073 
00074   MCSymbolizer *createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
00075                                    LLVMSymbolLookupCallback SymbolLookUp,
00076                                    void *DisInfo, MCContext *Ctx,
00077                                    std::unique_ptr<MCRelocationInfo> &&RelInfo);
00078 
00079   /// Target - Wrapper for Target specific information.
00080   ///
00081   /// For registration purposes, this is a POD type so that targets can be
00082   /// registered without the use of static constructors.
00083   ///
00084   /// Targets should implement a single global instance of this class (which
00085   /// will be zero initialized), and pass that instance to the TargetRegistry as
00086   /// part of their initialization.
00087   class Target {
00088   public:
00089     friend struct TargetRegistry;
00090 
00091     typedef bool (*ArchMatchFnTy)(Triple::ArchType Arch);
00092 
00093     typedef MCAsmInfo *(*MCAsmInfoCtorFnTy)(const MCRegisterInfo &MRI,
00094                                             StringRef TT);
00095     typedef MCCodeGenInfo *(*MCCodeGenInfoCtorFnTy)(StringRef TT,
00096                                                     Reloc::Model RM,
00097                                                     CodeModel::Model CM,
00098                                                     CodeGenOpt::Level OL);
00099     typedef MCInstrInfo *(*MCInstrInfoCtorFnTy)(void);
00100     typedef MCInstrAnalysis *(*MCInstrAnalysisCtorFnTy)(const MCInstrInfo*Info);
00101     typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(StringRef TT);
00102     typedef MCSubtargetInfo *(*MCSubtargetInfoCtorFnTy)(StringRef TT,
00103                                                         StringRef CPU,
00104                                                         StringRef Features);
00105     typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T,
00106                                                   StringRef TT,
00107                                                   StringRef CPU,
00108                                                   StringRef Features,
00109                                                   const TargetOptions &Options,
00110                                                   Reloc::Model RM,
00111                                                   CodeModel::Model CM,
00112                                                   CodeGenOpt::Level OL);
00113     // If it weren't for layering issues (this header is in llvm/Support, but
00114     // depends on MC?) this should take the Streamer by value rather than rvalue
00115     // reference.
00116     typedef AsmPrinter *(*AsmPrinterCtorTy)(
00117         TargetMachine &TM, std::unique_ptr<MCStreamer> &&Streamer);
00118     typedef MCAsmBackend *(*MCAsmBackendCtorTy)(const Target &T,
00119                                                 const MCRegisterInfo &MRI,
00120                                                 StringRef TT,
00121                                                 StringRef CPU);
00122     typedef MCTargetAsmParser *(*MCAsmParserCtorTy)(
00123         MCSubtargetInfo &STI,
00124         MCAsmParser &P,
00125         const MCInstrInfo &MII,
00126         const MCTargetOptions &Options);
00127     typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T,
00128                                                     const MCSubtargetInfo &STI,
00129                                                     MCContext &Ctx);
00130     typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Triple &T,
00131                                                   unsigned SyntaxVariant,
00132                                                   const MCAsmInfo &MAI,
00133                                                   const MCInstrInfo &MII,
00134                                                   const MCRegisterInfo &MRI);
00135     typedef MCCodeEmitter *(*MCCodeEmitterCtorTy)(const MCInstrInfo &II,
00136                                                   const MCRegisterInfo &MRI,
00137                                                   MCContext &Ctx);
00138     typedef MCStreamer *(*ELFStreamerCtorTy)(const Triple &T, MCContext &Ctx,
00139                                              MCAsmBackend &TAB,
00140                                              raw_pwrite_stream &OS,
00141                                              MCCodeEmitter *Emitter,
00142                                              bool RelaxAll);
00143     typedef MCStreamer *(*MachOStreamerCtorTy)(
00144         MCContext &Ctx, MCAsmBackend &TAB, raw_pwrite_stream &OS,
00145         MCCodeEmitter *Emitter, bool RelaxAll, bool DWARFMustBeAtTheEnd);
00146     typedef MCStreamer *(*COFFStreamerCtorTy)(MCContext &Ctx, MCAsmBackend &TAB,
00147                                               raw_pwrite_stream &OS,
00148                                               MCCodeEmitter *Emitter,
00149                                               bool RelaxAll);
00150     typedef MCTargetStreamer *(*NullTargetStreamerCtorTy)(MCStreamer &S);
00151     typedef MCTargetStreamer *(*AsmTargetStreamerCtorTy)(
00152         MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *InstPrint,
00153         bool IsVerboseAsm);
00154     typedef MCTargetStreamer *(*ObjectTargetStreamerCtorTy)(
00155         MCStreamer &S, const MCSubtargetInfo &STI);
00156     typedef MCRelocationInfo *(*MCRelocationInfoCtorTy)(StringRef TT,
00157                                                         MCContext &Ctx);
00158     typedef MCSymbolizer *(*MCSymbolizerCtorTy)(
00159         StringRef TT, LLVMOpInfoCallback GetOpInfo,
00160         LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo, MCContext *Ctx,
00161         std::unique_ptr<MCRelocationInfo> &&RelInfo);
00162 
00163   private:
00164     /// Next - The next registered target in the linked list, maintained by the
00165     /// TargetRegistry.
00166     Target *Next;
00167 
00168     /// The target function for checking if an architecture is supported.
00169     ArchMatchFnTy ArchMatchFn;
00170 
00171     /// Name - The target name.
00172     const char *Name;
00173 
00174     /// ShortDesc - A short description of the target.
00175     const char *ShortDesc;
00176 
00177     /// HasJIT - Whether this target supports the JIT.
00178     bool HasJIT;
00179 
00180     /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
00181     /// registered.
00182     MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
00183 
00184     /// MCCodeGenInfoCtorFn - Constructor function for this target's
00185     /// MCCodeGenInfo, if registered.
00186     MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn;
00187 
00188     /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
00189     /// if registered.
00190     MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
00191 
00192     /// MCInstrAnalysisCtorFn - Constructor function for this target's
00193     /// MCInstrAnalysis, if registered.
00194     MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
00195 
00196     /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
00197     /// if registered.
00198     MCRegInfoCtorFnTy MCRegInfoCtorFn;
00199 
00200     /// MCSubtargetInfoCtorFn - Constructor function for this target's
00201     /// MCSubtargetInfo, if registered.
00202     MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
00203 
00204     /// TargetMachineCtorFn - Construction function for this target's
00205     /// TargetMachine, if registered.
00206     TargetMachineCtorTy TargetMachineCtorFn;
00207 
00208     /// MCAsmBackendCtorFn - Construction function for this target's
00209     /// MCAsmBackend, if registered.
00210     MCAsmBackendCtorTy MCAsmBackendCtorFn;
00211 
00212     /// MCAsmParserCtorFn - Construction function for this target's
00213     /// MCTargetAsmParser, if registered.
00214     MCAsmParserCtorTy MCAsmParserCtorFn;
00215 
00216     /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
00217     /// if registered.
00218     AsmPrinterCtorTy AsmPrinterCtorFn;
00219 
00220     /// MCDisassemblerCtorFn - Construction function for this target's
00221     /// MCDisassembler, if registered.
00222     MCDisassemblerCtorTy MCDisassemblerCtorFn;
00223 
00224     /// MCInstPrinterCtorFn - Construction function for this target's
00225     /// MCInstPrinter, if registered.
00226     MCInstPrinterCtorTy MCInstPrinterCtorFn;
00227 
00228     /// MCCodeEmitterCtorFn - Construction function for this target's
00229     /// CodeEmitter, if registered.
00230     MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
00231 
00232     // Construction functions for the various object formats, if registered.
00233     COFFStreamerCtorTy COFFStreamerCtorFn;
00234     MachOStreamerCtorTy MachOStreamerCtorFn;
00235     ELFStreamerCtorTy ELFStreamerCtorFn;
00236 
00237     /// Construction function for this target's null TargetStreamer, if
00238     /// registered (default = nullptr).
00239     NullTargetStreamerCtorTy NullTargetStreamerCtorFn;
00240 
00241     /// Construction function for this target's asm TargetStreamer, if
00242     /// registered (default = nullptr).
00243     AsmTargetStreamerCtorTy AsmTargetStreamerCtorFn;
00244 
00245     /// Construction function for this target's obj TargetStreamer, if
00246     /// registered (default = nullptr).
00247     ObjectTargetStreamerCtorTy ObjectTargetStreamerCtorFn;
00248 
00249     /// MCRelocationInfoCtorFn - Construction function for this target's
00250     /// MCRelocationInfo, if registered (default = llvm::createMCRelocationInfo)
00251     MCRelocationInfoCtorTy MCRelocationInfoCtorFn;
00252 
00253     /// MCSymbolizerCtorFn - Construction function for this target's
00254     /// MCSymbolizer, if registered (default = llvm::createMCSymbolizer)
00255     MCSymbolizerCtorTy MCSymbolizerCtorFn;
00256 
00257   public:
00258     Target()
00259         : COFFStreamerCtorFn(nullptr), MachOStreamerCtorFn(nullptr),
00260           ELFStreamerCtorFn(nullptr), NullTargetStreamerCtorFn(nullptr),
00261           AsmTargetStreamerCtorFn(nullptr), ObjectTargetStreamerCtorFn(nullptr),
00262           MCRelocationInfoCtorFn(nullptr), MCSymbolizerCtorFn(nullptr) {}
00263 
00264     /// @name Target Information
00265     /// @{
00266 
00267     // getNext - Return the next registered target.
00268     const Target *getNext() const { return Next; }
00269 
00270     /// getName - Get the target name.
00271     const char *getName() const { return Name; }
00272 
00273     /// getShortDescription - Get a short description of the target.
00274     const char *getShortDescription() const { return ShortDesc; }
00275 
00276     /// @}
00277     /// @name Feature Predicates
00278     /// @{
00279 
00280     /// hasJIT - Check if this targets supports the just-in-time compilation.
00281     bool hasJIT() const { return HasJIT; }
00282 
00283     /// hasTargetMachine - Check if this target supports code generation.
00284     bool hasTargetMachine() const { return TargetMachineCtorFn != nullptr; }
00285 
00286     /// hasMCAsmBackend - Check if this target supports .o generation.
00287     bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != nullptr; }
00288 
00289     /// @}
00290     /// @name Feature Constructors
00291     /// @{
00292 
00293     /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
00294     /// target triple.
00295     ///
00296     /// \param Triple This argument is used to determine the target machine
00297     /// feature set; it should always be provided. Generally this should be
00298     /// either the target triple from the module, or the target triple of the
00299     /// host if that does not exist.
00300     MCAsmInfo *createMCAsmInfo(const MCRegisterInfo &MRI,
00301                                StringRef Triple) const {
00302       if (!MCAsmInfoCtorFn)
00303         return nullptr;
00304       return MCAsmInfoCtorFn(MRI, Triple);
00305     }
00306 
00307     /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
00308     ///
00309     MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model RM,
00310                                        CodeModel::Model CM,
00311                                        CodeGenOpt::Level OL) const {
00312       if (!MCCodeGenInfoCtorFn)
00313         return nullptr;
00314       return MCCodeGenInfoCtorFn(Triple, RM, CM, OL);
00315     }
00316 
00317     /// createMCInstrInfo - Create a MCInstrInfo implementation.
00318     ///
00319     MCInstrInfo *createMCInstrInfo() const {
00320       if (!MCInstrInfoCtorFn)
00321         return nullptr;
00322       return MCInstrInfoCtorFn();
00323     }
00324 
00325     /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
00326     ///
00327     MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
00328       if (!MCInstrAnalysisCtorFn)
00329         return nullptr;
00330       return MCInstrAnalysisCtorFn(Info);
00331     }
00332 
00333     /// createMCRegInfo - Create a MCRegisterInfo implementation.
00334     ///
00335     MCRegisterInfo *createMCRegInfo(StringRef Triple) const {
00336       if (!MCRegInfoCtorFn)
00337         return nullptr;
00338       return MCRegInfoCtorFn(Triple);
00339     }
00340 
00341     /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
00342     ///
00343     /// \param Triple This argument is used to determine the target machine
00344     /// feature set; it should always be provided. Generally this should be
00345     /// either the target triple from the module, or the target triple of the
00346     /// host if that does not exist.
00347     /// \param CPU This specifies the name of the target CPU.
00348     /// \param Features This specifies the string representation of the
00349     /// additional target features.
00350     MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU,
00351                                            StringRef Features) const {
00352       if (!MCSubtargetInfoCtorFn)
00353         return nullptr;
00354       return MCSubtargetInfoCtorFn(Triple, CPU, Features);
00355     }
00356 
00357     /// createTargetMachine - Create a target specific machine implementation
00358     /// for the specified \p Triple.
00359     ///
00360     /// \param Triple This argument is used to determine the target machine
00361     /// feature set; it should always be provided. Generally this should be
00362     /// either the target triple from the module, or the target triple of the
00363     /// host if that does not exist.
00364     TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU,
00365                              StringRef Features, const TargetOptions &Options,
00366                              Reloc::Model RM = Reloc::Default,
00367                              CodeModel::Model CM = CodeModel::Default,
00368                              CodeGenOpt::Level OL = CodeGenOpt::Default) const {
00369       if (!TargetMachineCtorFn)
00370         return nullptr;
00371       return TargetMachineCtorFn(*this, Triple, CPU, Features, Options,
00372                                  RM, CM, OL);
00373     }
00374 
00375     /// createMCAsmBackend - Create a target specific assembly parser.
00376     ///
00377     /// \param Triple The target triple string.
00378     MCAsmBackend *createMCAsmBackend(const MCRegisterInfo &MRI,
00379                                      StringRef Triple, StringRef CPU) const {
00380       if (!MCAsmBackendCtorFn)
00381         return nullptr;
00382       return MCAsmBackendCtorFn(*this, MRI, Triple, CPU);
00383     }
00384 
00385     /// createMCAsmParser - Create a target specific assembly parser.
00386     ///
00387     /// \param Parser The target independent parser implementation to use for
00388     /// parsing and lexing.
00389     MCTargetAsmParser *createMCAsmParser(
00390         MCSubtargetInfo &STI,
00391         MCAsmParser &Parser,
00392         const MCInstrInfo &MII,
00393         const MCTargetOptions &Options) const {
00394       if (!MCAsmParserCtorFn)
00395         return nullptr;
00396       return MCAsmParserCtorFn(STI, Parser, MII, Options);
00397     }
00398 
00399     /// createAsmPrinter - Create a target specific assembly printer pass.  This
00400     /// takes ownership of the MCStreamer object.
00401     AsmPrinter *createAsmPrinter(TargetMachine &TM,
00402                                  std::unique_ptr<MCStreamer> &&Streamer) const {
00403       if (!AsmPrinterCtorFn)
00404         return nullptr;
00405       return AsmPrinterCtorFn(TM, std::move(Streamer));
00406     }
00407 
00408     MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI,
00409                                          MCContext &Ctx) const {
00410       if (!MCDisassemblerCtorFn)
00411         return nullptr;
00412       return MCDisassemblerCtorFn(*this, STI, Ctx);
00413     }
00414 
00415     MCInstPrinter *createMCInstPrinter(const Triple &T, unsigned SyntaxVariant,
00416                                        const MCAsmInfo &MAI,
00417                                        const MCInstrInfo &MII,
00418                                        const MCRegisterInfo &MRI) const {
00419       if (!MCInstPrinterCtorFn)
00420         return nullptr;
00421       return MCInstPrinterCtorFn(T, SyntaxVariant, MAI, MII, MRI);
00422     }
00423 
00424 
00425     /// createMCCodeEmitter - Create a target specific code emitter.
00426     MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
00427                                        const MCRegisterInfo &MRI,
00428                                        MCContext &Ctx) const {
00429       if (!MCCodeEmitterCtorFn)
00430         return nullptr;
00431       return MCCodeEmitterCtorFn(II, MRI, Ctx);
00432     }
00433 
00434     /// Create a target specific MCStreamer.
00435     ///
00436     /// \param T The target triple.
00437     /// \param Ctx The target context.
00438     /// \param TAB The target assembler backend object. Takes ownership.
00439     /// \param OS The stream object.
00440     /// \param Emitter The target independent assembler object.Takes ownership.
00441     /// \param RelaxAll Relax all fixups?
00442     MCStreamer *createMCObjectStreamer(const Triple &T, MCContext &Ctx,
00443                                        MCAsmBackend &TAB, raw_pwrite_stream &OS,
00444                                        MCCodeEmitter *Emitter,
00445                                        const MCSubtargetInfo &STI,
00446                                        bool RelaxAll,
00447                                        bool DWARFMustBeAtTheEnd) const {
00448       MCStreamer *S;
00449       switch (T.getObjectFormat()) {
00450       default:
00451         llvm_unreachable("Unknown object format");
00452       case Triple::COFF:
00453         assert(T.isOSWindows() && "only Windows COFF is supported");
00454         S = COFFStreamerCtorFn(Ctx, TAB, OS, Emitter, RelaxAll);
00455         break;
00456       case Triple::MachO:
00457         if (MachOStreamerCtorFn)
00458           S = MachOStreamerCtorFn(Ctx, TAB, OS, Emitter, RelaxAll,
00459                                   DWARFMustBeAtTheEnd);
00460         else
00461           S = createMachOStreamer(Ctx, TAB, OS, Emitter, RelaxAll,
00462                                   DWARFMustBeAtTheEnd);
00463         break;
00464       case Triple::ELF:
00465         if (ELFStreamerCtorFn)
00466           S = ELFStreamerCtorFn(T, Ctx, TAB, OS, Emitter, RelaxAll);
00467         else
00468           S = createELFStreamer(Ctx, TAB, OS, Emitter, RelaxAll);
00469         break;
00470       }
00471       if (ObjectTargetStreamerCtorFn)
00472         ObjectTargetStreamerCtorFn(*S, STI);
00473       return S;
00474     }
00475 
00476     MCStreamer *createAsmStreamer(MCContext &Ctx,
00477                                   std::unique_ptr<formatted_raw_ostream> OS,
00478                                   bool IsVerboseAsm, bool UseDwarfDirectory,
00479                                   MCInstPrinter *InstPrint, MCCodeEmitter *CE,
00480                                   MCAsmBackend *TAB, bool ShowInst) const {
00481       formatted_raw_ostream &OSRef = *OS;
00482       MCStreamer *S = llvm::createAsmStreamer(Ctx, std::move(OS), IsVerboseAsm,
00483                                               UseDwarfDirectory, InstPrint, CE,
00484                                               TAB, ShowInst);
00485       createAsmTargetStreamer(*S, OSRef, InstPrint, IsVerboseAsm);
00486       return S;
00487     }
00488 
00489     MCTargetStreamer *createAsmTargetStreamer(MCStreamer &S,
00490                                               formatted_raw_ostream &OS,
00491                                               MCInstPrinter *InstPrint,
00492                                               bool IsVerboseAsm) const {
00493       if (AsmTargetStreamerCtorFn)
00494         return AsmTargetStreamerCtorFn(S, OS, InstPrint, IsVerboseAsm);
00495       return nullptr;
00496     }
00497 
00498     MCStreamer *createNullStreamer(MCContext &Ctx) const {
00499       MCStreamer *S = llvm::createNullStreamer(Ctx);
00500       createNullTargetStreamer(*S);
00501       return S;
00502     }
00503 
00504     MCTargetStreamer *createNullTargetStreamer(MCStreamer &S) const {
00505       if (NullTargetStreamerCtorFn)
00506         return NullTargetStreamerCtorFn(S);
00507       return nullptr;
00508     }
00509 
00510     /// createMCRelocationInfo - Create a target specific MCRelocationInfo.
00511     ///
00512     /// \param TT The target triple.
00513     /// \param Ctx The target context.
00514     MCRelocationInfo *
00515       createMCRelocationInfo(StringRef TT, MCContext &Ctx) const {
00516       MCRelocationInfoCtorTy Fn = MCRelocationInfoCtorFn
00517                                       ? MCRelocationInfoCtorFn
00518                                       : llvm::createMCRelocationInfo;
00519       return Fn(TT, Ctx);
00520     }
00521 
00522     /// createMCSymbolizer - Create a target specific MCSymbolizer.
00523     ///
00524     /// \param TT The target triple.
00525     /// \param GetOpInfo The function to get the symbolic information for operands.
00526     /// \param SymbolLookUp The function to lookup a symbol name.
00527     /// \param DisInfo The pointer to the block of symbolic information for above call
00528     /// back.
00529     /// \param Ctx The target context.
00530     /// \param RelInfo The relocation information for this target. Takes ownership.
00531     MCSymbolizer *
00532     createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
00533                        LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo,
00534                        MCContext *Ctx,
00535                        std::unique_ptr<MCRelocationInfo> &&RelInfo) const {
00536       MCSymbolizerCtorTy Fn =
00537           MCSymbolizerCtorFn ? MCSymbolizerCtorFn : llvm::createMCSymbolizer;
00538       return Fn(TT, GetOpInfo, SymbolLookUp, DisInfo, Ctx, std::move(RelInfo));
00539     }
00540 
00541     /// @}
00542   };
00543 
00544   /// TargetRegistry - Generic interface to target specific features.
00545   struct TargetRegistry {
00546     class iterator {
00547       const Target *Current;
00548       explicit iterator(Target *T) : Current(T) {}
00549       friend struct TargetRegistry;
00550     public:
00551       iterator() : Current(nullptr) {}
00552 
00553       bool operator==(const iterator &x) const {
00554         return Current == x.Current;
00555       }
00556       bool operator!=(const iterator &x) const {
00557         return !operator==(x);
00558       }
00559 
00560       // Iterator traversal: forward iteration only
00561       iterator &operator++() {          // Preincrement
00562         assert(Current && "Cannot increment end iterator!");
00563         Current = Current->getNext();
00564         return *this;
00565       }
00566       iterator operator++(int) {        // Postincrement
00567         iterator tmp = *this;
00568         ++*this;
00569         return tmp;
00570       }
00571 
00572       const Target &operator*() const {
00573         assert(Current && "Cannot dereference end iterator!");
00574         return *Current;
00575       }
00576 
00577       const Target *operator->() const {
00578         return &operator*();
00579       }
00580     };
00581 
00582     /// printRegisteredTargetsForVersion - Print the registered targets
00583     /// appropriately for inclusion in a tool's version output.
00584     static void printRegisteredTargetsForVersion();
00585 
00586     /// @name Registry Access
00587     /// @{
00588 
00589     static iterator begin();
00590 
00591     static iterator end() { return iterator(); }
00592 
00593     /// lookupTarget - Lookup a target based on a target triple.
00594     ///
00595     /// \param Triple - The triple to use for finding a target.
00596     /// \param Error - On failure, an error string describing why no target was
00597     /// found.
00598     static const Target *lookupTarget(const std::string &Triple,
00599                                       std::string &Error);
00600 
00601     /// lookupTarget - Lookup a target based on an architecture name
00602     /// and a target triple.  If the architecture name is non-empty,
00603     /// then the lookup is done by architecture.  Otherwise, the target
00604     /// triple is used.
00605     ///
00606     /// \param ArchName - The architecture to use for finding a target.
00607     /// \param TheTriple - The triple to use for finding a target.  The
00608     /// triple is updated with canonical architecture name if a lookup
00609     /// by architecture is done.
00610     /// \param Error - On failure, an error string describing why no target was
00611     /// found.
00612     static const Target *lookupTarget(const std::string &ArchName,
00613                                       Triple &TheTriple,
00614                                       std::string &Error);
00615 
00616     /// @}
00617     /// @name Target Registration
00618     /// @{
00619 
00620     /// RegisterTarget - Register the given target. Attempts to register a
00621     /// target which has already been registered will be ignored.
00622     ///
00623     /// Clients are responsible for ensuring that registration doesn't occur
00624     /// while another thread is attempting to access the registry. Typically
00625     /// this is done by initializing all targets at program startup.
00626     ///
00627     /// @param T - The target being registered.
00628     /// @param Name - The target name. This should be a static string.
00629     /// @param ShortDesc - A short target description. This should be a static
00630     /// string.
00631     /// @param ArchMatchFn - The arch match checking function for this target.
00632     /// @param HasJIT - Whether the target supports JIT code
00633     /// generation.
00634     static void RegisterTarget(Target &T,
00635                                const char *Name,
00636                                const char *ShortDesc,
00637                                Target::ArchMatchFnTy ArchMatchFn,
00638                                bool HasJIT = false);
00639 
00640     /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
00641     /// given target.
00642     ///
00643     /// Clients are responsible for ensuring that registration doesn't occur
00644     /// while another thread is attempting to access the registry. Typically
00645     /// this is done by initializing all targets at program startup.
00646     ///
00647     /// @param T - The target being registered.
00648     /// @param Fn - A function to construct a MCAsmInfo for the target.
00649     static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
00650       T.MCAsmInfoCtorFn = Fn;
00651     }
00652 
00653     /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
00654     /// given target.
00655     ///
00656     /// Clients are responsible for ensuring that registration doesn't occur
00657     /// while another thread is attempting to access the registry. Typically
00658     /// this is done by initializing all targets at program startup.
00659     ///
00660     /// @param T - The target being registered.
00661     /// @param Fn - A function to construct a MCCodeGenInfo for the target.
00662     static void RegisterMCCodeGenInfo(Target &T,
00663                                      Target::MCCodeGenInfoCtorFnTy Fn) {
00664       T.MCCodeGenInfoCtorFn = Fn;
00665     }
00666 
00667     /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
00668     /// given target.
00669     ///
00670     /// Clients are responsible for ensuring that registration doesn't occur
00671     /// while another thread is attempting to access the registry. Typically
00672     /// this is done by initializing all targets at program startup.
00673     ///
00674     /// @param T - The target being registered.
00675     /// @param Fn - A function to construct a MCInstrInfo for the target.
00676     static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
00677       T.MCInstrInfoCtorFn = Fn;
00678     }
00679 
00680     /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
00681     /// the given target.
00682     static void RegisterMCInstrAnalysis(Target &T,
00683                                         Target::MCInstrAnalysisCtorFnTy Fn) {
00684       T.MCInstrAnalysisCtorFn = Fn;
00685     }
00686 
00687     /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
00688     /// given target.
00689     ///
00690     /// Clients are responsible for ensuring that registration doesn't occur
00691     /// while another thread is attempting to access the registry. Typically
00692     /// this is done by initializing all targets at program startup.
00693     ///
00694     /// @param T - The target being registered.
00695     /// @param Fn - A function to construct a MCRegisterInfo for the target.
00696     static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
00697       T.MCRegInfoCtorFn = Fn;
00698     }
00699 
00700     /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
00701     /// the given target.
00702     ///
00703     /// Clients are responsible for ensuring that registration doesn't occur
00704     /// while another thread is attempting to access the registry. Typically
00705     /// this is done by initializing all targets at program startup.
00706     ///
00707     /// @param T - The target being registered.
00708     /// @param Fn - A function to construct a MCSubtargetInfo for the target.
00709     static void RegisterMCSubtargetInfo(Target &T,
00710                                         Target::MCSubtargetInfoCtorFnTy Fn) {
00711       T.MCSubtargetInfoCtorFn = Fn;
00712     }
00713 
00714     /// RegisterTargetMachine - Register a TargetMachine implementation for the
00715     /// given target.
00716     ///
00717     /// Clients are responsible for ensuring that registration doesn't occur
00718     /// while another thread is attempting to access the registry. Typically
00719     /// this is done by initializing all targets at program startup.
00720     ///
00721     /// @param T - The target being registered.
00722     /// @param Fn - A function to construct a TargetMachine for the target.
00723     static void RegisterTargetMachine(Target &T,
00724                                       Target::TargetMachineCtorTy Fn) {
00725       T.TargetMachineCtorFn = Fn;
00726     }
00727 
00728     /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
00729     /// given target.
00730     ///
00731     /// Clients are responsible for ensuring that registration doesn't occur
00732     /// while another thread is attempting to access the registry. Typically
00733     /// this is done by initializing all targets at program startup.
00734     ///
00735     /// @param T - The target being registered.
00736     /// @param Fn - A function to construct an AsmBackend for the target.
00737     static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
00738       T.MCAsmBackendCtorFn = Fn;
00739     }
00740 
00741     /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
00742     /// the given target.
00743     ///
00744     /// Clients are responsible for ensuring that registration doesn't occur
00745     /// while another thread is attempting to access the registry. Typically
00746     /// this is done by initializing all targets at program startup.
00747     ///
00748     /// @param T - The target being registered.
00749     /// @param Fn - A function to construct an MCTargetAsmParser for the target.
00750     static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
00751       T.MCAsmParserCtorFn = Fn;
00752     }
00753 
00754     /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
00755     /// target.
00756     ///
00757     /// Clients are responsible for ensuring that registration doesn't occur
00758     /// while another thread is attempting to access the registry. Typically
00759     /// this is done by initializing all targets at program startup.
00760     ///
00761     /// @param T - The target being registered.
00762     /// @param Fn - A function to construct an AsmPrinter for the target.
00763     static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
00764       T.AsmPrinterCtorFn = Fn;
00765     }
00766 
00767     /// RegisterMCDisassembler - Register a MCDisassembler implementation for
00768     /// the given target.
00769     ///
00770     /// Clients are responsible for ensuring that registration doesn't occur
00771     /// while another thread is attempting to access the registry. Typically
00772     /// this is done by initializing all targets at program startup.
00773     ///
00774     /// @param T - The target being registered.
00775     /// @param Fn - A function to construct an MCDisassembler for the target.
00776     static void RegisterMCDisassembler(Target &T,
00777                                        Target::MCDisassemblerCtorTy Fn) {
00778       T.MCDisassemblerCtorFn = Fn;
00779     }
00780 
00781     /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
00782     /// given target.
00783     ///
00784     /// Clients are responsible for ensuring that registration doesn't occur
00785     /// while another thread is attempting to access the registry. Typically
00786     /// this is done by initializing all targets at program startup.
00787     ///
00788     /// @param T - The target being registered.
00789     /// @param Fn - A function to construct an MCInstPrinter for the target.
00790     static void RegisterMCInstPrinter(Target &T,
00791                                       Target::MCInstPrinterCtorTy Fn) {
00792       T.MCInstPrinterCtorFn = Fn;
00793     }
00794 
00795     /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
00796     /// given target.
00797     ///
00798     /// Clients are responsible for ensuring that registration doesn't occur
00799     /// while another thread is attempting to access the registry. Typically
00800     /// this is done by initializing all targets at program startup.
00801     ///
00802     /// @param T - The target being registered.
00803     /// @param Fn - A function to construct an MCCodeEmitter for the target.
00804     static void RegisterMCCodeEmitter(Target &T,
00805                                       Target::MCCodeEmitterCtorTy Fn) {
00806       T.MCCodeEmitterCtorFn = Fn;
00807     }
00808 
00809     static void RegisterCOFFStreamer(Target &T, Target::COFFStreamerCtorTy Fn) {
00810       T.COFFStreamerCtorFn = Fn;
00811     }
00812 
00813     static void RegisterMachOStreamer(Target &T,
00814                                       Target::MachOStreamerCtorTy Fn) {
00815       T.MachOStreamerCtorFn = Fn;
00816     }
00817 
00818     static void RegisterELFStreamer(Target &T, Target::ELFStreamerCtorTy Fn) {
00819       T.ELFStreamerCtorFn = Fn;
00820     }
00821 
00822     static void
00823     RegisterNullTargetStreamer(Target &T, Target::NullTargetStreamerCtorTy Fn) {
00824       T.NullTargetStreamerCtorFn = Fn;
00825     }
00826 
00827     static void RegisterAsmTargetStreamer(Target &T,
00828                                           Target::AsmTargetStreamerCtorTy Fn) {
00829       T.AsmTargetStreamerCtorFn = Fn;
00830     }
00831 
00832     static void
00833     RegisterObjectTargetStreamer(Target &T,
00834                                  Target::ObjectTargetStreamerCtorTy Fn) {
00835       T.ObjectTargetStreamerCtorFn = Fn;
00836     }
00837 
00838     /// RegisterMCRelocationInfo - Register an MCRelocationInfo
00839     /// implementation for the given target.
00840     ///
00841     /// Clients are responsible for ensuring that registration doesn't occur
00842     /// while another thread is attempting to access the registry. Typically
00843     /// this is done by initializing all targets at program startup.
00844     ///
00845     /// @param T - The target being registered.
00846     /// @param Fn - A function to construct an MCRelocationInfo for the target.
00847     static void RegisterMCRelocationInfo(Target &T,
00848                                          Target::MCRelocationInfoCtorTy Fn) {
00849       T.MCRelocationInfoCtorFn = Fn;
00850     }
00851 
00852     /// RegisterMCSymbolizer - Register an MCSymbolizer
00853     /// implementation for the given target.
00854     ///
00855     /// Clients are responsible for ensuring that registration doesn't occur
00856     /// while another thread is attempting to access the registry. Typically
00857     /// this is done by initializing all targets at program startup.
00858     ///
00859     /// @param T - The target being registered.
00860     /// @param Fn - A function to construct an MCSymbolizer for the target.
00861     static void RegisterMCSymbolizer(Target &T,
00862                                      Target::MCSymbolizerCtorTy Fn) {
00863       T.MCSymbolizerCtorFn = Fn;
00864     }
00865 
00866     /// @}
00867   };
00868 
00869 
00870   //===--------------------------------------------------------------------===//
00871 
00872   /// RegisterTarget - Helper template for registering a target, for use in the
00873   /// target's initialization function. Usage:
00874   ///
00875   ///
00876   /// Target TheFooTarget; // The global target instance.
00877   ///
00878   /// extern "C" void LLVMInitializeFooTargetInfo() {
00879   ///   RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
00880   /// }
00881   template<Triple::ArchType TargetArchType = Triple::UnknownArch,
00882            bool HasJIT = false>
00883   struct RegisterTarget {
00884     RegisterTarget(Target &T, const char *Name, const char *Desc) {
00885       TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch, HasJIT);
00886     }
00887 
00888     static bool getArchMatch(Triple::ArchType Arch) {
00889       return Arch == TargetArchType;
00890     }
00891   };
00892 
00893   /// RegisterMCAsmInfo - Helper template for registering a target assembly info
00894   /// implementation.  This invokes the static "Create" method on the class to
00895   /// actually do the construction.  Usage:
00896   ///
00897   /// extern "C" void LLVMInitializeFooTarget() {
00898   ///   extern Target TheFooTarget;
00899   ///   RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
00900   /// }
00901   template<class MCAsmInfoImpl>
00902   struct RegisterMCAsmInfo {
00903     RegisterMCAsmInfo(Target &T) {
00904       TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
00905     }
00906   private:
00907     static MCAsmInfo *Allocator(const MCRegisterInfo &/*MRI*/, StringRef TT) {
00908       return new MCAsmInfoImpl(TT);
00909     }
00910 
00911   };
00912 
00913   /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
00914   /// implementation.  This invokes the specified function to do the
00915   /// construction.  Usage:
00916   ///
00917   /// extern "C" void LLVMInitializeFooTarget() {
00918   ///   extern Target TheFooTarget;
00919   ///   RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
00920   /// }
00921   struct RegisterMCAsmInfoFn {
00922     RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
00923       TargetRegistry::RegisterMCAsmInfo(T, Fn);
00924     }
00925   };
00926 
00927   /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
00928   /// implementation.  This invokes the static "Create" method on the class
00929   /// to actually do the construction.  Usage:
00930   ///
00931   /// extern "C" void LLVMInitializeFooTarget() {
00932   ///   extern Target TheFooTarget;
00933   ///   RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
00934   /// }
00935   template<class MCCodeGenInfoImpl>
00936   struct RegisterMCCodeGenInfo {
00937     RegisterMCCodeGenInfo(Target &T) {
00938       TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
00939     }
00940   private:
00941     static MCCodeGenInfo *Allocator(StringRef /*TT*/, Reloc::Model /*RM*/,
00942                                     CodeModel::Model /*CM*/,
00943                                     CodeGenOpt::Level /*OL*/) {
00944       return new MCCodeGenInfoImpl();
00945     }
00946   };
00947 
00948   /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
00949   /// info implementation.  This invokes the specified function to do the
00950   /// construction.  Usage:
00951   ///
00952   /// extern "C" void LLVMInitializeFooTarget() {
00953   ///   extern Target TheFooTarget;
00954   ///   RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
00955   /// }
00956   struct RegisterMCCodeGenInfoFn {
00957     RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
00958       TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
00959     }
00960   };
00961 
00962   /// RegisterMCInstrInfo - Helper template for registering a target instruction
00963   /// info implementation.  This invokes the static "Create" method on the class
00964   /// to actually do the construction.  Usage:
00965   ///
00966   /// extern "C" void LLVMInitializeFooTarget() {
00967   ///   extern Target TheFooTarget;
00968   ///   RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
00969   /// }
00970   template<class MCInstrInfoImpl>
00971   struct RegisterMCInstrInfo {
00972     RegisterMCInstrInfo(Target &T) {
00973       TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
00974     }
00975   private:
00976     static MCInstrInfo *Allocator() {
00977       return new MCInstrInfoImpl();
00978     }
00979   };
00980 
00981   /// RegisterMCInstrInfoFn - Helper template for registering a target
00982   /// instruction info implementation.  This invokes the specified function to
00983   /// do the construction.  Usage:
00984   ///
00985   /// extern "C" void LLVMInitializeFooTarget() {
00986   ///   extern Target TheFooTarget;
00987   ///   RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
00988   /// }
00989   struct RegisterMCInstrInfoFn {
00990     RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
00991       TargetRegistry::RegisterMCInstrInfo(T, Fn);
00992     }
00993   };
00994 
00995   /// RegisterMCInstrAnalysis - Helper template for registering a target
00996   /// instruction analyzer implementation.  This invokes the static "Create"
00997   /// method on the class to actually do the construction.  Usage:
00998   ///
00999   /// extern "C" void LLVMInitializeFooTarget() {
01000   ///   extern Target TheFooTarget;
01001   ///   RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
01002   /// }
01003   template<class MCInstrAnalysisImpl>
01004   struct RegisterMCInstrAnalysis {
01005     RegisterMCInstrAnalysis(Target &T) {
01006       TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
01007     }
01008   private:
01009     static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
01010       return new MCInstrAnalysisImpl(Info);
01011     }
01012   };
01013 
01014   /// RegisterMCInstrAnalysisFn - Helper template for registering a target
01015   /// instruction analyzer implementation.  This invokes the specified function
01016   /// to do the construction.  Usage:
01017   ///
01018   /// extern "C" void LLVMInitializeFooTarget() {
01019   ///   extern Target TheFooTarget;
01020   ///   RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
01021   /// }
01022   struct RegisterMCInstrAnalysisFn {
01023     RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
01024       TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
01025     }
01026   };
01027 
01028   /// RegisterMCRegInfo - Helper template for registering a target register info
01029   /// implementation.  This invokes the static "Create" method on the class to
01030   /// actually do the construction.  Usage:
01031   ///
01032   /// extern "C" void LLVMInitializeFooTarget() {
01033   ///   extern Target TheFooTarget;
01034   ///   RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
01035   /// }
01036   template<class MCRegisterInfoImpl>
01037   struct RegisterMCRegInfo {
01038     RegisterMCRegInfo(Target &T) {
01039       TargetRegistry::RegisterMCRegInfo(T, &Allocator);
01040     }
01041   private:
01042     static MCRegisterInfo *Allocator(StringRef /*TT*/) {
01043       return new MCRegisterInfoImpl();
01044     }
01045   };
01046 
01047   /// RegisterMCRegInfoFn - Helper template for registering a target register
01048   /// info implementation.  This invokes the specified function to do the
01049   /// construction.  Usage:
01050   ///
01051   /// extern "C" void LLVMInitializeFooTarget() {
01052   ///   extern Target TheFooTarget;
01053   ///   RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
01054   /// }
01055   struct RegisterMCRegInfoFn {
01056     RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
01057       TargetRegistry::RegisterMCRegInfo(T, Fn);
01058     }
01059   };
01060 
01061   /// RegisterMCSubtargetInfo - Helper template for registering a target
01062   /// subtarget info implementation.  This invokes the static "Create" method
01063   /// on the class to actually do the construction.  Usage:
01064   ///
01065   /// extern "C" void LLVMInitializeFooTarget() {
01066   ///   extern Target TheFooTarget;
01067   ///   RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
01068   /// }
01069   template<class MCSubtargetInfoImpl>
01070   struct RegisterMCSubtargetInfo {
01071     RegisterMCSubtargetInfo(Target &T) {
01072       TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
01073     }
01074   private:
01075     static MCSubtargetInfo *Allocator(StringRef /*TT*/, StringRef /*CPU*/,
01076                                       StringRef /*FS*/) {
01077       return new MCSubtargetInfoImpl();
01078     }
01079   };
01080 
01081   /// RegisterMCSubtargetInfoFn - Helper template for registering a target
01082   /// subtarget info implementation.  This invokes the specified function to
01083   /// do the construction.  Usage:
01084   ///
01085   /// extern "C" void LLVMInitializeFooTarget() {
01086   ///   extern Target TheFooTarget;
01087   ///   RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
01088   /// }
01089   struct RegisterMCSubtargetInfoFn {
01090     RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
01091       TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
01092     }
01093   };
01094 
01095   /// RegisterTargetMachine - Helper template for registering a target machine
01096   /// implementation, for use in the target machine initialization
01097   /// function. Usage:
01098   ///
01099   /// extern "C" void LLVMInitializeFooTarget() {
01100   ///   extern Target TheFooTarget;
01101   ///   RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
01102   /// }
01103   template<class TargetMachineImpl>
01104   struct RegisterTargetMachine {
01105     RegisterTargetMachine(Target &T) {
01106       TargetRegistry::RegisterTargetMachine(T, &Allocator);
01107     }
01108 
01109   private:
01110     static TargetMachine *Allocator(const Target &T, StringRef TT,
01111                                     StringRef CPU, StringRef FS,
01112                                     const TargetOptions &Options,
01113                                     Reloc::Model RM,
01114                                     CodeModel::Model CM,
01115                                     CodeGenOpt::Level OL) {
01116       return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
01117     }
01118   };
01119 
01120   /// RegisterMCAsmBackend - Helper template for registering a target specific
01121   /// assembler backend. Usage:
01122   ///
01123   /// extern "C" void LLVMInitializeFooMCAsmBackend() {
01124   ///   extern Target TheFooTarget;
01125   ///   RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
01126   /// }
01127   template<class MCAsmBackendImpl>
01128   struct RegisterMCAsmBackend {
01129     RegisterMCAsmBackend(Target &T) {
01130       TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
01131     }
01132 
01133   private:
01134     static MCAsmBackend *Allocator(const Target &T,
01135                                    const MCRegisterInfo &MRI,
01136                                    StringRef Triple, StringRef CPU) {
01137       return new MCAsmBackendImpl(T, MRI, Triple, CPU);
01138     }
01139   };
01140 
01141   /// RegisterMCAsmParser - Helper template for registering a target specific
01142   /// assembly parser, for use in the target machine initialization
01143   /// function. Usage:
01144   ///
01145   /// extern "C" void LLVMInitializeFooMCAsmParser() {
01146   ///   extern Target TheFooTarget;
01147   ///   RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
01148   /// }
01149   template<class MCAsmParserImpl>
01150   struct RegisterMCAsmParser {
01151     RegisterMCAsmParser(Target &T) {
01152       TargetRegistry::RegisterMCAsmParser(T, &Allocator);
01153     }
01154 
01155   private:
01156     static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P,
01157                                         const MCInstrInfo &MII,
01158                                         const MCTargetOptions &Options) {
01159       return new MCAsmParserImpl(STI, P, MII, Options);
01160     }
01161   };
01162 
01163   /// RegisterAsmPrinter - Helper template for registering a target specific
01164   /// assembly printer, for use in the target machine initialization
01165   /// function. Usage:
01166   ///
01167   /// extern "C" void LLVMInitializeFooAsmPrinter() {
01168   ///   extern Target TheFooTarget;
01169   ///   RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
01170   /// }
01171   template<class AsmPrinterImpl>
01172   struct RegisterAsmPrinter {
01173     RegisterAsmPrinter(Target &T) {
01174       TargetRegistry::RegisterAsmPrinter(T, &Allocator);
01175     }
01176 
01177   private:
01178     static AsmPrinter *Allocator(TargetMachine &TM,
01179                                  std::unique_ptr<MCStreamer> &&Streamer) {
01180       return new AsmPrinterImpl(TM, std::move(Streamer));
01181     }
01182   };
01183 
01184   /// RegisterMCCodeEmitter - Helper template for registering a target specific
01185   /// machine code emitter, for use in the target initialization
01186   /// function. Usage:
01187   ///
01188   /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
01189   ///   extern Target TheFooTarget;
01190   ///   RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
01191   /// }
01192   template<class MCCodeEmitterImpl>
01193   struct RegisterMCCodeEmitter {
01194     RegisterMCCodeEmitter(Target &T) {
01195       TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
01196     }
01197 
01198   private:
01199     static MCCodeEmitter *Allocator(const MCInstrInfo & /*II*/,
01200                                     const MCRegisterInfo & /*MRI*/,
01201                                     MCContext & /*Ctx*/) {
01202       return new MCCodeEmitterImpl();
01203     }
01204   };
01205 
01206 }
01207 
01208 #endif