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     // FIXME: Make this a namespace, probably just move all the Register*
00547     // functions into Target (currently they all just set members on the Target
00548     // anyway, and Target friends this class so those functions can...
00549     // function).
00550     TargetRegistry() = delete;
00551 
00552     class iterator
00553         : public std::iterator<std::forward_iterator_tag, Target, ptrdiff_t> {
00554       const Target *Current;
00555       explicit iterator(Target *T) : Current(T) {}
00556       friend struct TargetRegistry;
00557     public:
00558       iterator() : Current(nullptr) {}
00559 
00560       bool operator==(const iterator &x) const {
00561         return Current == x.Current;
00562       }
00563       bool operator!=(const iterator &x) const {
00564         return !operator==(x);
00565       }
00566 
00567       // Iterator traversal: forward iteration only
00568       iterator &operator++() {          // Preincrement
00569         assert(Current && "Cannot increment end iterator!");
00570         Current = Current->getNext();
00571         return *this;
00572       }
00573       iterator operator++(int) {        // Postincrement
00574         iterator tmp = *this;
00575         ++*this;
00576         return tmp;
00577       }
00578 
00579       const Target &operator*() const {
00580         assert(Current && "Cannot dereference end iterator!");
00581         return *Current;
00582       }
00583 
00584       const Target *operator->() const {
00585         return &operator*();
00586       }
00587     };
00588 
00589     /// printRegisteredTargetsForVersion - Print the registered targets
00590     /// appropriately for inclusion in a tool's version output.
00591     static void printRegisteredTargetsForVersion();
00592 
00593     /// @name Registry Access
00594     /// @{
00595 
00596     static iterator_range<iterator> targets();
00597 
00598     /// lookupTarget - Lookup a target based on a target triple.
00599     ///
00600     /// \param Triple - The triple to use for finding a target.
00601     /// \param Error - On failure, an error string describing why no target was
00602     /// found.
00603     static const Target *lookupTarget(const std::string &Triple,
00604                                       std::string &Error);
00605 
00606     /// lookupTarget - Lookup a target based on an architecture name
00607     /// and a target triple.  If the architecture name is non-empty,
00608     /// then the lookup is done by architecture.  Otherwise, the target
00609     /// triple is used.
00610     ///
00611     /// \param ArchName - The architecture to use for finding a target.
00612     /// \param TheTriple - The triple to use for finding a target.  The
00613     /// triple is updated with canonical architecture name if a lookup
00614     /// by architecture is done.
00615     /// \param Error - On failure, an error string describing why no target was
00616     /// found.
00617     static const Target *lookupTarget(const std::string &ArchName,
00618                                       Triple &TheTriple,
00619                                       std::string &Error);
00620 
00621     /// @}
00622     /// @name Target Registration
00623     /// @{
00624 
00625     /// RegisterTarget - Register the given target. Attempts to register a
00626     /// target which has already been registered will be ignored.
00627     ///
00628     /// Clients are responsible for ensuring that registration doesn't occur
00629     /// while another thread is attempting to access the registry. Typically
00630     /// this is done by initializing all targets at program startup.
00631     ///
00632     /// @param T - The target being registered.
00633     /// @param Name - The target name. This should be a static string.
00634     /// @param ShortDesc - A short target description. This should be a static
00635     /// string.
00636     /// @param ArchMatchFn - The arch match checking function for this target.
00637     /// @param HasJIT - Whether the target supports JIT code
00638     /// generation.
00639     static void RegisterTarget(Target &T,
00640                                const char *Name,
00641                                const char *ShortDesc,
00642                                Target::ArchMatchFnTy ArchMatchFn,
00643                                bool HasJIT = false);
00644 
00645     /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
00646     /// given target.
00647     ///
00648     /// Clients are responsible for ensuring that registration doesn't occur
00649     /// while another thread is attempting to access the registry. Typically
00650     /// this is done by initializing all targets at program startup.
00651     ///
00652     /// @param T - The target being registered.
00653     /// @param Fn - A function to construct a MCAsmInfo for the target.
00654     static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
00655       T.MCAsmInfoCtorFn = Fn;
00656     }
00657 
00658     /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
00659     /// given target.
00660     ///
00661     /// Clients are responsible for ensuring that registration doesn't occur
00662     /// while another thread is attempting to access the registry. Typically
00663     /// this is done by initializing all targets at program startup.
00664     ///
00665     /// @param T - The target being registered.
00666     /// @param Fn - A function to construct a MCCodeGenInfo for the target.
00667     static void RegisterMCCodeGenInfo(Target &T,
00668                                      Target::MCCodeGenInfoCtorFnTy Fn) {
00669       T.MCCodeGenInfoCtorFn = Fn;
00670     }
00671 
00672     /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
00673     /// given target.
00674     ///
00675     /// Clients are responsible for ensuring that registration doesn't occur
00676     /// while another thread is attempting to access the registry. Typically
00677     /// this is done by initializing all targets at program startup.
00678     ///
00679     /// @param T - The target being registered.
00680     /// @param Fn - A function to construct a MCInstrInfo for the target.
00681     static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
00682       T.MCInstrInfoCtorFn = Fn;
00683     }
00684 
00685     /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
00686     /// the given target.
00687     static void RegisterMCInstrAnalysis(Target &T,
00688                                         Target::MCInstrAnalysisCtorFnTy Fn) {
00689       T.MCInstrAnalysisCtorFn = Fn;
00690     }
00691 
00692     /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
00693     /// given target.
00694     ///
00695     /// Clients are responsible for ensuring that registration doesn't occur
00696     /// while another thread is attempting to access the registry. Typically
00697     /// this is done by initializing all targets at program startup.
00698     ///
00699     /// @param T - The target being registered.
00700     /// @param Fn - A function to construct a MCRegisterInfo for the target.
00701     static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
00702       T.MCRegInfoCtorFn = Fn;
00703     }
00704 
00705     /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
00706     /// the given target.
00707     ///
00708     /// Clients are responsible for ensuring that registration doesn't occur
00709     /// while another thread is attempting to access the registry. Typically
00710     /// this is done by initializing all targets at program startup.
00711     ///
00712     /// @param T - The target being registered.
00713     /// @param Fn - A function to construct a MCSubtargetInfo for the target.
00714     static void RegisterMCSubtargetInfo(Target &T,
00715                                         Target::MCSubtargetInfoCtorFnTy Fn) {
00716       T.MCSubtargetInfoCtorFn = Fn;
00717     }
00718 
00719     /// RegisterTargetMachine - Register a TargetMachine implementation for the
00720     /// given target.
00721     ///
00722     /// Clients are responsible for ensuring that registration doesn't occur
00723     /// while another thread is attempting to access the registry. Typically
00724     /// this is done by initializing all targets at program startup.
00725     ///
00726     /// @param T - The target being registered.
00727     /// @param Fn - A function to construct a TargetMachine for the target.
00728     static void RegisterTargetMachine(Target &T,
00729                                       Target::TargetMachineCtorTy Fn) {
00730       T.TargetMachineCtorFn = Fn;
00731     }
00732 
00733     /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
00734     /// given target.
00735     ///
00736     /// Clients are responsible for ensuring that registration doesn't occur
00737     /// while another thread is attempting to access the registry. Typically
00738     /// this is done by initializing all targets at program startup.
00739     ///
00740     /// @param T - The target being registered.
00741     /// @param Fn - A function to construct an AsmBackend for the target.
00742     static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
00743       T.MCAsmBackendCtorFn = Fn;
00744     }
00745 
00746     /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
00747     /// the given target.
00748     ///
00749     /// Clients are responsible for ensuring that registration doesn't occur
00750     /// while another thread is attempting to access the registry. Typically
00751     /// this is done by initializing all targets at program startup.
00752     ///
00753     /// @param T - The target being registered.
00754     /// @param Fn - A function to construct an MCTargetAsmParser for the target.
00755     static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
00756       T.MCAsmParserCtorFn = Fn;
00757     }
00758 
00759     /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
00760     /// target.
00761     ///
00762     /// Clients are responsible for ensuring that registration doesn't occur
00763     /// while another thread is attempting to access the registry. Typically
00764     /// this is done by initializing all targets at program startup.
00765     ///
00766     /// @param T - The target being registered.
00767     /// @param Fn - A function to construct an AsmPrinter for the target.
00768     static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
00769       T.AsmPrinterCtorFn = Fn;
00770     }
00771 
00772     /// RegisterMCDisassembler - Register a MCDisassembler implementation for
00773     /// the given target.
00774     ///
00775     /// Clients are responsible for ensuring that registration doesn't occur
00776     /// while another thread is attempting to access the registry. Typically
00777     /// this is done by initializing all targets at program startup.
00778     ///
00779     /// @param T - The target being registered.
00780     /// @param Fn - A function to construct an MCDisassembler for the target.
00781     static void RegisterMCDisassembler(Target &T,
00782                                        Target::MCDisassemblerCtorTy Fn) {
00783       T.MCDisassemblerCtorFn = Fn;
00784     }
00785 
00786     /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
00787     /// given target.
00788     ///
00789     /// Clients are responsible for ensuring that registration doesn't occur
00790     /// while another thread is attempting to access the registry. Typically
00791     /// this is done by initializing all targets at program startup.
00792     ///
00793     /// @param T - The target being registered.
00794     /// @param Fn - A function to construct an MCInstPrinter for the target.
00795     static void RegisterMCInstPrinter(Target &T,
00796                                       Target::MCInstPrinterCtorTy Fn) {
00797       T.MCInstPrinterCtorFn = Fn;
00798     }
00799 
00800     /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
00801     /// given target.
00802     ///
00803     /// Clients are responsible for ensuring that registration doesn't occur
00804     /// while another thread is attempting to access the registry. Typically
00805     /// this is done by initializing all targets at program startup.
00806     ///
00807     /// @param T - The target being registered.
00808     /// @param Fn - A function to construct an MCCodeEmitter for the target.
00809     static void RegisterMCCodeEmitter(Target &T,
00810                                       Target::MCCodeEmitterCtorTy Fn) {
00811       T.MCCodeEmitterCtorFn = Fn;
00812     }
00813 
00814     static void RegisterCOFFStreamer(Target &T, Target::COFFStreamerCtorTy Fn) {
00815       T.COFFStreamerCtorFn = Fn;
00816     }
00817 
00818     static void RegisterMachOStreamer(Target &T,
00819                                       Target::MachOStreamerCtorTy Fn) {
00820       T.MachOStreamerCtorFn = Fn;
00821     }
00822 
00823     static void RegisterELFStreamer(Target &T, Target::ELFStreamerCtorTy Fn) {
00824       T.ELFStreamerCtorFn = Fn;
00825     }
00826 
00827     static void
00828     RegisterNullTargetStreamer(Target &T, Target::NullTargetStreamerCtorTy Fn) {
00829       T.NullTargetStreamerCtorFn = Fn;
00830     }
00831 
00832     static void RegisterAsmTargetStreamer(Target &T,
00833                                           Target::AsmTargetStreamerCtorTy Fn) {
00834       T.AsmTargetStreamerCtorFn = Fn;
00835     }
00836 
00837     static void
00838     RegisterObjectTargetStreamer(Target &T,
00839                                  Target::ObjectTargetStreamerCtorTy Fn) {
00840       T.ObjectTargetStreamerCtorFn = Fn;
00841     }
00842 
00843     /// RegisterMCRelocationInfo - Register an MCRelocationInfo
00844     /// implementation for the given target.
00845     ///
00846     /// Clients are responsible for ensuring that registration doesn't occur
00847     /// while another thread is attempting to access the registry. Typically
00848     /// this is done by initializing all targets at program startup.
00849     ///
00850     /// @param T - The target being registered.
00851     /// @param Fn - A function to construct an MCRelocationInfo for the target.
00852     static void RegisterMCRelocationInfo(Target &T,
00853                                          Target::MCRelocationInfoCtorTy Fn) {
00854       T.MCRelocationInfoCtorFn = Fn;
00855     }
00856 
00857     /// RegisterMCSymbolizer - Register an MCSymbolizer
00858     /// implementation for the given target.
00859     ///
00860     /// Clients are responsible for ensuring that registration doesn't occur
00861     /// while another thread is attempting to access the registry. Typically
00862     /// this is done by initializing all targets at program startup.
00863     ///
00864     /// @param T - The target being registered.
00865     /// @param Fn - A function to construct an MCSymbolizer for the target.
00866     static void RegisterMCSymbolizer(Target &T,
00867                                      Target::MCSymbolizerCtorTy Fn) {
00868       T.MCSymbolizerCtorFn = Fn;
00869     }
00870 
00871     /// @}
00872   };
00873 
00874 
00875   //===--------------------------------------------------------------------===//
00876 
00877   /// RegisterTarget - Helper template for registering a target, for use in the
00878   /// target's initialization function. Usage:
00879   ///
00880   ///
00881   /// Target TheFooTarget; // The global target instance.
00882   ///
00883   /// extern "C" void LLVMInitializeFooTargetInfo() {
00884   ///   RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
00885   /// }
00886   template<Triple::ArchType TargetArchType = Triple::UnknownArch,
00887            bool HasJIT = false>
00888   struct RegisterTarget {
00889     RegisterTarget(Target &T, const char *Name, const char *Desc) {
00890       TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch, HasJIT);
00891     }
00892 
00893     static bool getArchMatch(Triple::ArchType Arch) {
00894       return Arch == TargetArchType;
00895     }
00896   };
00897 
00898   /// RegisterMCAsmInfo - Helper template for registering a target assembly info
00899   /// implementation.  This invokes the static "Create" method on the class to
00900   /// actually do the construction.  Usage:
00901   ///
00902   /// extern "C" void LLVMInitializeFooTarget() {
00903   ///   extern Target TheFooTarget;
00904   ///   RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
00905   /// }
00906   template<class MCAsmInfoImpl>
00907   struct RegisterMCAsmInfo {
00908     RegisterMCAsmInfo(Target &T) {
00909       TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
00910     }
00911   private:
00912     static MCAsmInfo *Allocator(const MCRegisterInfo &/*MRI*/, StringRef TT) {
00913       return new MCAsmInfoImpl(TT);
00914     }
00915 
00916   };
00917 
00918   /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
00919   /// implementation.  This invokes the specified function to do the
00920   /// construction.  Usage:
00921   ///
00922   /// extern "C" void LLVMInitializeFooTarget() {
00923   ///   extern Target TheFooTarget;
00924   ///   RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
00925   /// }
00926   struct RegisterMCAsmInfoFn {
00927     RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
00928       TargetRegistry::RegisterMCAsmInfo(T, Fn);
00929     }
00930   };
00931 
00932   /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
00933   /// implementation.  This invokes the static "Create" method on the class
00934   /// to actually do the construction.  Usage:
00935   ///
00936   /// extern "C" void LLVMInitializeFooTarget() {
00937   ///   extern Target TheFooTarget;
00938   ///   RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
00939   /// }
00940   template<class MCCodeGenInfoImpl>
00941   struct RegisterMCCodeGenInfo {
00942     RegisterMCCodeGenInfo(Target &T) {
00943       TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
00944     }
00945   private:
00946     static MCCodeGenInfo *Allocator(StringRef /*TT*/, Reloc::Model /*RM*/,
00947                                     CodeModel::Model /*CM*/,
00948                                     CodeGenOpt::Level /*OL*/) {
00949       return new MCCodeGenInfoImpl();
00950     }
00951   };
00952 
00953   /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
00954   /// info implementation.  This invokes the specified function to do the
00955   /// construction.  Usage:
00956   ///
00957   /// extern "C" void LLVMInitializeFooTarget() {
00958   ///   extern Target TheFooTarget;
00959   ///   RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
00960   /// }
00961   struct RegisterMCCodeGenInfoFn {
00962     RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
00963       TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
00964     }
00965   };
00966 
00967   /// RegisterMCInstrInfo - Helper template for registering a target instruction
00968   /// info implementation.  This invokes the static "Create" method on the class
00969   /// to actually do the construction.  Usage:
00970   ///
00971   /// extern "C" void LLVMInitializeFooTarget() {
00972   ///   extern Target TheFooTarget;
00973   ///   RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
00974   /// }
00975   template<class MCInstrInfoImpl>
00976   struct RegisterMCInstrInfo {
00977     RegisterMCInstrInfo(Target &T) {
00978       TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
00979     }
00980   private:
00981     static MCInstrInfo *Allocator() {
00982       return new MCInstrInfoImpl();
00983     }
00984   };
00985 
00986   /// RegisterMCInstrInfoFn - Helper template for registering a target
00987   /// instruction info implementation.  This invokes the specified function to
00988   /// do the construction.  Usage:
00989   ///
00990   /// extern "C" void LLVMInitializeFooTarget() {
00991   ///   extern Target TheFooTarget;
00992   ///   RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
00993   /// }
00994   struct RegisterMCInstrInfoFn {
00995     RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
00996       TargetRegistry::RegisterMCInstrInfo(T, Fn);
00997     }
00998   };
00999 
01000   /// RegisterMCInstrAnalysis - Helper template for registering a target
01001   /// instruction analyzer implementation.  This invokes the static "Create"
01002   /// method on the class to actually do the construction.  Usage:
01003   ///
01004   /// extern "C" void LLVMInitializeFooTarget() {
01005   ///   extern Target TheFooTarget;
01006   ///   RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
01007   /// }
01008   template<class MCInstrAnalysisImpl>
01009   struct RegisterMCInstrAnalysis {
01010     RegisterMCInstrAnalysis(Target &T) {
01011       TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
01012     }
01013   private:
01014     static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
01015       return new MCInstrAnalysisImpl(Info);
01016     }
01017   };
01018 
01019   /// RegisterMCInstrAnalysisFn - Helper template for registering a target
01020   /// instruction analyzer implementation.  This invokes the specified function
01021   /// to do the construction.  Usage:
01022   ///
01023   /// extern "C" void LLVMInitializeFooTarget() {
01024   ///   extern Target TheFooTarget;
01025   ///   RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
01026   /// }
01027   struct RegisterMCInstrAnalysisFn {
01028     RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
01029       TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
01030     }
01031   };
01032 
01033   /// RegisterMCRegInfo - Helper template for registering a target register info
01034   /// implementation.  This invokes the static "Create" method on the class to
01035   /// actually do the construction.  Usage:
01036   ///
01037   /// extern "C" void LLVMInitializeFooTarget() {
01038   ///   extern Target TheFooTarget;
01039   ///   RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
01040   /// }
01041   template<class MCRegisterInfoImpl>
01042   struct RegisterMCRegInfo {
01043     RegisterMCRegInfo(Target &T) {
01044       TargetRegistry::RegisterMCRegInfo(T, &Allocator);
01045     }
01046   private:
01047     static MCRegisterInfo *Allocator(StringRef /*TT*/) {
01048       return new MCRegisterInfoImpl();
01049     }
01050   };
01051 
01052   /// RegisterMCRegInfoFn - Helper template for registering a target register
01053   /// info implementation.  This invokes the specified function to do the
01054   /// construction.  Usage:
01055   ///
01056   /// extern "C" void LLVMInitializeFooTarget() {
01057   ///   extern Target TheFooTarget;
01058   ///   RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
01059   /// }
01060   struct RegisterMCRegInfoFn {
01061     RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
01062       TargetRegistry::RegisterMCRegInfo(T, Fn);
01063     }
01064   };
01065 
01066   /// RegisterMCSubtargetInfo - Helper template for registering a target
01067   /// subtarget info implementation.  This invokes the static "Create" method
01068   /// on the class to actually do the construction.  Usage:
01069   ///
01070   /// extern "C" void LLVMInitializeFooTarget() {
01071   ///   extern Target TheFooTarget;
01072   ///   RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
01073   /// }
01074   template<class MCSubtargetInfoImpl>
01075   struct RegisterMCSubtargetInfo {
01076     RegisterMCSubtargetInfo(Target &T) {
01077       TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
01078     }
01079   private:
01080     static MCSubtargetInfo *Allocator(StringRef /*TT*/, StringRef /*CPU*/,
01081                                       StringRef /*FS*/) {
01082       return new MCSubtargetInfoImpl();
01083     }
01084   };
01085 
01086   /// RegisterMCSubtargetInfoFn - Helper template for registering a target
01087   /// subtarget info implementation.  This invokes the specified function to
01088   /// do the construction.  Usage:
01089   ///
01090   /// extern "C" void LLVMInitializeFooTarget() {
01091   ///   extern Target TheFooTarget;
01092   ///   RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
01093   /// }
01094   struct RegisterMCSubtargetInfoFn {
01095     RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
01096       TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
01097     }
01098   };
01099 
01100   /// RegisterTargetMachine - Helper template for registering a target machine
01101   /// implementation, for use in the target machine initialization
01102   /// function. Usage:
01103   ///
01104   /// extern "C" void LLVMInitializeFooTarget() {
01105   ///   extern Target TheFooTarget;
01106   ///   RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
01107   /// }
01108   template<class TargetMachineImpl>
01109   struct RegisterTargetMachine {
01110     RegisterTargetMachine(Target &T) {
01111       TargetRegistry::RegisterTargetMachine(T, &Allocator);
01112     }
01113 
01114   private:
01115     static TargetMachine *Allocator(const Target &T, StringRef TT,
01116                                     StringRef CPU, StringRef FS,
01117                                     const TargetOptions &Options,
01118                                     Reloc::Model RM,
01119                                     CodeModel::Model CM,
01120                                     CodeGenOpt::Level OL) {
01121       return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
01122     }
01123   };
01124 
01125   /// RegisterMCAsmBackend - Helper template for registering a target specific
01126   /// assembler backend. Usage:
01127   ///
01128   /// extern "C" void LLVMInitializeFooMCAsmBackend() {
01129   ///   extern Target TheFooTarget;
01130   ///   RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
01131   /// }
01132   template<class MCAsmBackendImpl>
01133   struct RegisterMCAsmBackend {
01134     RegisterMCAsmBackend(Target &T) {
01135       TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
01136     }
01137 
01138   private:
01139     static MCAsmBackend *Allocator(const Target &T,
01140                                    const MCRegisterInfo &MRI,
01141                                    StringRef Triple, StringRef CPU) {
01142       return new MCAsmBackendImpl(T, MRI, Triple, CPU);
01143     }
01144   };
01145 
01146   /// RegisterMCAsmParser - Helper template for registering a target specific
01147   /// assembly parser, for use in the target machine initialization
01148   /// function. Usage:
01149   ///
01150   /// extern "C" void LLVMInitializeFooMCAsmParser() {
01151   ///   extern Target TheFooTarget;
01152   ///   RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
01153   /// }
01154   template<class MCAsmParserImpl>
01155   struct RegisterMCAsmParser {
01156     RegisterMCAsmParser(Target &T) {
01157       TargetRegistry::RegisterMCAsmParser(T, &Allocator);
01158     }
01159 
01160   private:
01161     static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P,
01162                                         const MCInstrInfo &MII,
01163                                         const MCTargetOptions &Options) {
01164       return new MCAsmParserImpl(STI, P, MII, Options);
01165     }
01166   };
01167 
01168   /// RegisterAsmPrinter - Helper template for registering a target specific
01169   /// assembly printer, for use in the target machine initialization
01170   /// function. Usage:
01171   ///
01172   /// extern "C" void LLVMInitializeFooAsmPrinter() {
01173   ///   extern Target TheFooTarget;
01174   ///   RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
01175   /// }
01176   template<class AsmPrinterImpl>
01177   struct RegisterAsmPrinter {
01178     RegisterAsmPrinter(Target &T) {
01179       TargetRegistry::RegisterAsmPrinter(T, &Allocator);
01180     }
01181 
01182   private:
01183     static AsmPrinter *Allocator(TargetMachine &TM,
01184                                  std::unique_ptr<MCStreamer> &&Streamer) {
01185       return new AsmPrinterImpl(TM, std::move(Streamer));
01186     }
01187   };
01188 
01189   /// RegisterMCCodeEmitter - Helper template for registering a target specific
01190   /// machine code emitter, for use in the target initialization
01191   /// function. Usage:
01192   ///
01193   /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
01194   ///   extern Target TheFooTarget;
01195   ///   RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
01196   /// }
01197   template<class MCCodeEmitterImpl>
01198   struct RegisterMCCodeEmitter {
01199     RegisterMCCodeEmitter(Target &T) {
01200       TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
01201     }
01202 
01203   private:
01204     static MCCodeEmitter *Allocator(const MCInstrInfo & /*II*/,
01205                                     const MCRegisterInfo & /*MRI*/,
01206                                     MCContext & /*Ctx*/) {
01207       return new MCCodeEmitterImpl();
01208     }
01209   };
01210 
01211 }
01212 
01213 #endif