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

Generated by: LCOV version 1.13