LCOV - code coverage report
Current view: top level - include/llvm/Support - TargetRegistry.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 96 104 92.3 %
Date: 2018-05-20 00:06:23 Functions: 146 146 100.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.13