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