Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:16

0001 //===- MC/TargetRegistry.h - Target Registration ----------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file exposes the TargetRegistry interface, which tools can use to access
0010 // the appropriate target specific classes (TargetMachine, AsmPrinter, etc.)
0011 // which have been registered.
0012 //
0013 // Target specific class implementations should register themselves using the
0014 // appropriate TargetRegistry interfaces.
0015 //
0016 //===----------------------------------------------------------------------===//
0017 
0018 #ifndef LLVM_MC_TARGETREGISTRY_H
0019 #define LLVM_MC_TARGETREGISTRY_H
0020 
0021 #include "llvm-c/DisassemblerTypes.h"
0022 #include "llvm/ADT/StringRef.h"
0023 #include "llvm/ADT/iterator_range.h"
0024 #include "llvm/MC/MCObjectFileInfo.h"
0025 #include "llvm/Support/CodeGen.h"
0026 #include "llvm/Support/Compiler.h"
0027 #include "llvm/Support/ErrorHandling.h"
0028 #include "llvm/Support/FormattedStream.h"
0029 #include "llvm/TargetParser/Triple.h"
0030 #include <cassert>
0031 #include <cstddef>
0032 #include <iterator>
0033 #include <memory>
0034 #include <optional>
0035 #include <string>
0036 
0037 namespace llvm {
0038 
0039 class AsmPrinter;
0040 class MCAsmBackend;
0041 class MCAsmInfo;
0042 class MCAsmParser;
0043 class MCCodeEmitter;
0044 class MCContext;
0045 class MCDisassembler;
0046 class MCInstPrinter;
0047 class MCInstrAnalysis;
0048 class MCInstrInfo;
0049 class MCObjectWriter;
0050 class MCRegisterInfo;
0051 class MCRelocationInfo;
0052 class MCStreamer;
0053 class MCSubtargetInfo;
0054 class MCSymbolizer;
0055 class MCTargetAsmParser;
0056 class MCTargetOptions;
0057 class MCTargetStreamer;
0058 class raw_ostream;
0059 class TargetMachine;
0060 class TargetOptions;
0061 namespace mca {
0062 class CustomBehaviour;
0063 class InstrPostProcess;
0064 class InstrumentManager;
0065 struct SourceMgr;
0066 } // namespace mca
0067 
0068 MCStreamer *createNullStreamer(MCContext &Ctx);
0069 // Takes ownership of \p TAB and \p CE.
0070 
0071 /// Create a machine code streamer which will print out assembly for the native
0072 /// target, suitable for compiling with a native assembler.
0073 ///
0074 /// \param InstPrint - If given, the instruction printer to use. If not given
0075 /// the MCInst representation will be printed.  This method takes ownership of
0076 /// InstPrint.
0077 ///
0078 /// \param CE - If given, a code emitter to use to show the instruction
0079 /// encoding inline with the assembly. This method takes ownership of \p CE.
0080 ///
0081 /// \param TAB - If given, a target asm backend to use to show the fixup
0082 /// information in conjunction with encoding information. This method takes
0083 /// ownership of \p TAB.
0084 ///
0085 /// \param ShowInst - Whether to show the MCInst representation inline with
0086 /// the assembly.
0087 MCStreamer *
0088 createAsmStreamer(MCContext &Ctx, std::unique_ptr<formatted_raw_ostream> OS,
0089                   MCInstPrinter *InstPrint, std::unique_ptr<MCCodeEmitter> &&CE,
0090                   std::unique_ptr<MCAsmBackend> &&TAB);
0091 
0092 MCStreamer *createELFStreamer(MCContext &Ctx,
0093                               std::unique_ptr<MCAsmBackend> &&TAB,
0094                               std::unique_ptr<MCObjectWriter> &&OW,
0095                               std::unique_ptr<MCCodeEmitter> &&CE);
0096 MCStreamer *createGOFFStreamer(MCContext &Ctx,
0097                                std::unique_ptr<MCAsmBackend> &&TAB,
0098                                std::unique_ptr<MCObjectWriter> &&OW,
0099                                std::unique_ptr<MCCodeEmitter> &&CE);
0100 MCStreamer *createMachOStreamer(MCContext &Ctx,
0101                                 std::unique_ptr<MCAsmBackend> &&TAB,
0102                                 std::unique_ptr<MCObjectWriter> &&OW,
0103                                 std::unique_ptr<MCCodeEmitter> &&CE,
0104                                 bool DWARFMustBeAtTheEnd,
0105                                 bool LabelSections = false);
0106 MCStreamer *createWasmStreamer(MCContext &Ctx,
0107                                std::unique_ptr<MCAsmBackend> &&TAB,
0108                                std::unique_ptr<MCObjectWriter> &&OW,
0109                                std::unique_ptr<MCCodeEmitter> &&CE);
0110 MCStreamer *createSPIRVStreamer(MCContext &Ctx,
0111                                 std::unique_ptr<MCAsmBackend> &&TAB,
0112                                 std::unique_ptr<MCObjectWriter> &&OW,
0113                                 std::unique_ptr<MCCodeEmitter> &&CE);
0114 MCStreamer *createDXContainerStreamer(MCContext &Ctx,
0115                                       std::unique_ptr<MCAsmBackend> &&TAB,
0116                                       std::unique_ptr<MCObjectWriter> &&OW,
0117                                       std::unique_ptr<MCCodeEmitter> &&CE);
0118 
0119 MCRelocationInfo *createMCRelocationInfo(const Triple &TT, MCContext &Ctx);
0120 
0121 MCSymbolizer *createMCSymbolizer(const Triple &TT, LLVMOpInfoCallback GetOpInfo,
0122                                  LLVMSymbolLookupCallback SymbolLookUp,
0123                                  void *DisInfo, MCContext *Ctx,
0124                                  std::unique_ptr<MCRelocationInfo> &&RelInfo);
0125 
0126 mca::CustomBehaviour *createCustomBehaviour(const MCSubtargetInfo &STI,
0127                                             const mca::SourceMgr &SrcMgr,
0128                                             const MCInstrInfo &MCII);
0129 
0130 mca::InstrPostProcess *createInstrPostProcess(const MCSubtargetInfo &STI,
0131                                               const MCInstrInfo &MCII);
0132 
0133 mca::InstrumentManager *createInstrumentManager(const MCSubtargetInfo &STI,
0134                                                 const MCInstrInfo &MCII);
0135 
0136 /// Target - Wrapper for Target specific information.
0137 ///
0138 /// For registration purposes, this is a POD type so that targets can be
0139 /// registered without the use of static constructors.
0140 ///
0141 /// Targets should implement a single global instance of this class (which
0142 /// will be zero initialized), and pass that instance to the TargetRegistry as
0143 /// part of their initialization.
0144 class Target {
0145 public:
0146   friend struct TargetRegistry;
0147 
0148   using ArchMatchFnTy = bool (*)(Triple::ArchType Arch);
0149 
0150   using MCAsmInfoCtorFnTy = MCAsmInfo *(*)(const MCRegisterInfo &MRI,
0151                                            const Triple &TT,
0152                                            const MCTargetOptions &Options);
0153   using MCObjectFileInfoCtorFnTy = MCObjectFileInfo *(*)(MCContext &Ctx,
0154                                                          bool PIC,
0155                                                          bool LargeCodeModel);
0156   using MCInstrInfoCtorFnTy = MCInstrInfo *(*)();
0157   using MCInstrAnalysisCtorFnTy = MCInstrAnalysis *(*)(const MCInstrInfo *Info);
0158   using MCRegInfoCtorFnTy = MCRegisterInfo *(*)(const Triple &TT);
0159   using MCSubtargetInfoCtorFnTy = MCSubtargetInfo *(*)(const Triple &TT,
0160                                                        StringRef CPU,
0161                                                        StringRef Features);
0162   using TargetMachineCtorTy = TargetMachine
0163       *(*)(const Target &T, const Triple &TT, StringRef CPU, StringRef Features,
0164            const TargetOptions &Options, std::optional<Reloc::Model> RM,
0165            std::optional<CodeModel::Model> CM, CodeGenOptLevel OL, bool JIT);
0166   // If it weren't for layering issues (this header is in llvm/Support, but
0167   // depends on MC?) this should take the Streamer by value rather than rvalue
0168   // reference.
0169   using AsmPrinterCtorTy = AsmPrinter *(*)(
0170       TargetMachine &TM, std::unique_ptr<MCStreamer> &&Streamer);
0171   using MCAsmBackendCtorTy = MCAsmBackend *(*)(const Target &T,
0172                                                const MCSubtargetInfo &STI,
0173                                                const MCRegisterInfo &MRI,
0174                                                const MCTargetOptions &Options);
0175   using MCAsmParserCtorTy = MCTargetAsmParser *(*)(
0176       const MCSubtargetInfo &STI, MCAsmParser &P, const MCInstrInfo &MII,
0177       const MCTargetOptions &Options);
0178   using MCDisassemblerCtorTy = MCDisassembler *(*)(const Target &T,
0179                                                    const MCSubtargetInfo &STI,
0180                                                    MCContext &Ctx);
0181   using MCInstPrinterCtorTy = MCInstPrinter *(*)(const Triple &T,
0182                                                  unsigned SyntaxVariant,
0183                                                  const MCAsmInfo &MAI,
0184                                                  const MCInstrInfo &MII,
0185                                                  const MCRegisterInfo &MRI);
0186   using MCCodeEmitterCtorTy = MCCodeEmitter *(*)(const MCInstrInfo &II,
0187                                                  MCContext &Ctx);
0188   using ELFStreamerCtorTy =
0189       MCStreamer *(*)(const Triple &T, MCContext &Ctx,
0190                       std::unique_ptr<MCAsmBackend> &&TAB,
0191                       std::unique_ptr<MCObjectWriter> &&OW,
0192                       std::unique_ptr<MCCodeEmitter> &&Emitter);
0193   using MachOStreamerCtorTy =
0194       MCStreamer *(*)(MCContext &Ctx, std::unique_ptr<MCAsmBackend> &&TAB,
0195                       std::unique_ptr<MCObjectWriter> &&OW,
0196                       std::unique_ptr<MCCodeEmitter> &&Emitter);
0197   using COFFStreamerCtorTy =
0198       MCStreamer *(*)(MCContext &Ctx, std::unique_ptr<MCAsmBackend> &&TAB,
0199                       std::unique_ptr<MCObjectWriter> &&OW,
0200                       std::unique_ptr<MCCodeEmitter> &&Emitter);
0201   using XCOFFStreamerCtorTy =
0202       MCStreamer *(*)(const Triple &T, MCContext &Ctx,
0203                       std::unique_ptr<MCAsmBackend> &&TAB,
0204                       std::unique_ptr<MCObjectWriter> &&OW,
0205                       std::unique_ptr<MCCodeEmitter> &&Emitter);
0206 
0207   using NullTargetStreamerCtorTy = MCTargetStreamer *(*)(MCStreamer &S);
0208   using AsmTargetStreamerCtorTy =
0209       MCTargetStreamer *(*)(MCStreamer &S, formatted_raw_ostream &OS,
0210                             MCInstPrinter *InstPrint);
0211   using ObjectTargetStreamerCtorTy = MCTargetStreamer *(*)(
0212       MCStreamer &S, const MCSubtargetInfo &STI);
0213   using MCRelocationInfoCtorTy = MCRelocationInfo *(*)(const Triple &TT,
0214                                                        MCContext &Ctx);
0215   using MCSymbolizerCtorTy = MCSymbolizer *(*)(
0216       const Triple &TT, LLVMOpInfoCallback GetOpInfo,
0217       LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo, MCContext *Ctx,
0218       std::unique_ptr<MCRelocationInfo> &&RelInfo);
0219 
0220   using CustomBehaviourCtorTy =
0221       mca::CustomBehaviour *(*)(const MCSubtargetInfo &STI,
0222                                 const mca::SourceMgr &SrcMgr,
0223                                 const MCInstrInfo &MCII);
0224 
0225   using InstrPostProcessCtorTy =
0226       mca::InstrPostProcess *(*)(const MCSubtargetInfo &STI,
0227                                  const MCInstrInfo &MCII);
0228 
0229   using InstrumentManagerCtorTy =
0230       mca::InstrumentManager *(*)(const MCSubtargetInfo &STI,
0231                                   const MCInstrInfo &MCII);
0232 
0233 private:
0234   /// Next - The next registered target in the linked list, maintained by the
0235   /// TargetRegistry.
0236   Target *Next;
0237 
0238   /// The target function for checking if an architecture is supported.
0239   ArchMatchFnTy ArchMatchFn;
0240 
0241   /// Name - The target name.
0242   const char *Name;
0243 
0244   /// ShortDesc - A short description of the target.
0245   const char *ShortDesc;
0246 
0247   /// BackendName - The name of the backend implementation. This must match the
0248   /// name of the 'def X : Target ...' in TableGen.
0249   const char *BackendName;
0250 
0251   /// HasJIT - Whether this target supports the JIT.
0252   bool HasJIT;
0253 
0254   /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
0255   /// registered.
0256   MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
0257 
0258   /// Constructor function for this target's MCObjectFileInfo, if registered.
0259   MCObjectFileInfoCtorFnTy MCObjectFileInfoCtorFn;
0260 
0261   /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
0262   /// if registered.
0263   MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
0264 
0265   /// MCInstrAnalysisCtorFn - Constructor function for this target's
0266   /// MCInstrAnalysis, if registered.
0267   MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
0268 
0269   /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
0270   /// if registered.
0271   MCRegInfoCtorFnTy MCRegInfoCtorFn;
0272 
0273   /// MCSubtargetInfoCtorFn - Constructor function for this target's
0274   /// MCSubtargetInfo, if registered.
0275   MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
0276 
0277   /// TargetMachineCtorFn - Construction function for this target's
0278   /// TargetMachine, if registered.
0279   TargetMachineCtorTy TargetMachineCtorFn;
0280 
0281   /// MCAsmBackendCtorFn - Construction function for this target's
0282   /// MCAsmBackend, if registered.
0283   MCAsmBackendCtorTy MCAsmBackendCtorFn;
0284 
0285   /// MCAsmParserCtorFn - Construction function for this target's
0286   /// MCTargetAsmParser, if registered.
0287   MCAsmParserCtorTy MCAsmParserCtorFn;
0288 
0289   /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
0290   /// if registered.
0291   AsmPrinterCtorTy AsmPrinterCtorFn;
0292 
0293   /// MCDisassemblerCtorFn - Construction function for this target's
0294   /// MCDisassembler, if registered.
0295   MCDisassemblerCtorTy MCDisassemblerCtorFn;
0296 
0297   /// MCInstPrinterCtorFn - Construction function for this target's
0298   /// MCInstPrinter, if registered.
0299   MCInstPrinterCtorTy MCInstPrinterCtorFn;
0300 
0301   /// MCCodeEmitterCtorFn - Construction function for this target's
0302   /// CodeEmitter, if registered.
0303   MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
0304 
0305   // Construction functions for the various object formats, if registered.
0306   COFFStreamerCtorTy COFFStreamerCtorFn = nullptr;
0307   MachOStreamerCtorTy MachOStreamerCtorFn = nullptr;
0308   ELFStreamerCtorTy ELFStreamerCtorFn = nullptr;
0309   XCOFFStreamerCtorTy XCOFFStreamerCtorFn = nullptr;
0310 
0311   /// Construction function for this target's null TargetStreamer, if
0312   /// registered (default = nullptr).
0313   NullTargetStreamerCtorTy NullTargetStreamerCtorFn = nullptr;
0314 
0315   /// Construction function for this target's asm TargetStreamer, if
0316   /// registered (default = nullptr).
0317   AsmTargetStreamerCtorTy AsmTargetStreamerCtorFn = nullptr;
0318 
0319   /// Construction function for this target's obj TargetStreamer, if
0320   /// registered (default = nullptr).
0321   ObjectTargetStreamerCtorTy ObjectTargetStreamerCtorFn = nullptr;
0322 
0323   /// MCRelocationInfoCtorFn - Construction function for this target's
0324   /// MCRelocationInfo, if registered (default = llvm::createMCRelocationInfo)
0325   MCRelocationInfoCtorTy MCRelocationInfoCtorFn = nullptr;
0326 
0327   /// MCSymbolizerCtorFn - Construction function for this target's
0328   /// MCSymbolizer, if registered (default = llvm::createMCSymbolizer)
0329   MCSymbolizerCtorTy MCSymbolizerCtorFn = nullptr;
0330 
0331   /// CustomBehaviourCtorFn - Construction function for this target's
0332   /// CustomBehaviour, if registered (default = nullptr).
0333   CustomBehaviourCtorTy CustomBehaviourCtorFn = nullptr;
0334 
0335   /// InstrPostProcessCtorFn - Construction function for this target's
0336   /// InstrPostProcess, if registered (default = nullptr).
0337   InstrPostProcessCtorTy InstrPostProcessCtorFn = nullptr;
0338 
0339   /// InstrumentManagerCtorFn - Construction function for this target's
0340   /// InstrumentManager, if registered (default = nullptr).
0341   InstrumentManagerCtorTy InstrumentManagerCtorFn = nullptr;
0342 
0343 public:
0344   Target() = default;
0345 
0346   /// @name Target Information
0347   /// @{
0348 
0349   // getNext - Return the next registered target.
0350   const Target *getNext() const { return Next; }
0351 
0352   /// getName - Get the target name.
0353   const char *getName() const { return Name; }
0354 
0355   /// getShortDescription - Get a short description of the target.
0356   const char *getShortDescription() const { return ShortDesc; }
0357 
0358   /// getBackendName - Get the backend name.
0359   const char *getBackendName() const { return BackendName; }
0360 
0361   /// @}
0362   /// @name Feature Predicates
0363   /// @{
0364 
0365   /// hasJIT - Check if this targets supports the just-in-time compilation.
0366   bool hasJIT() const { return HasJIT; }
0367 
0368   /// hasTargetMachine - Check if this target supports code generation.
0369   bool hasTargetMachine() const { return TargetMachineCtorFn != nullptr; }
0370 
0371   /// hasMCAsmBackend - Check if this target supports .o generation.
0372   bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != nullptr; }
0373 
0374   /// hasMCAsmParser - Check if this target supports assembly parsing.
0375   bool hasMCAsmParser() const { return MCAsmParserCtorFn != nullptr; }
0376 
0377   /// @}
0378   /// @name Feature Constructors
0379   /// @{
0380 
0381   /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
0382   /// target triple.
0383   ///
0384   /// \param TheTriple This argument is used to determine the target machine
0385   /// feature set; it should always be provided. Generally this should be
0386   /// either the target triple from the module, or the target triple of the
0387   /// host if that does not exist.
0388   MCAsmInfo *createMCAsmInfo(const MCRegisterInfo &MRI, StringRef TheTriple,
0389                              const MCTargetOptions &Options) const {
0390     if (!MCAsmInfoCtorFn)
0391       return nullptr;
0392     return MCAsmInfoCtorFn(MRI, Triple(TheTriple), Options);
0393   }
0394 
0395   /// Create a MCObjectFileInfo implementation for the specified target
0396   /// triple.
0397   ///
0398   MCObjectFileInfo *createMCObjectFileInfo(MCContext &Ctx, bool PIC,
0399                                            bool LargeCodeModel = false) const {
0400     if (!MCObjectFileInfoCtorFn) {
0401       MCObjectFileInfo *MOFI = new MCObjectFileInfo();
0402       MOFI->initMCObjectFileInfo(Ctx, PIC, LargeCodeModel);
0403       return MOFI;
0404     }
0405     return MCObjectFileInfoCtorFn(Ctx, PIC, LargeCodeModel);
0406   }
0407 
0408   /// createMCInstrInfo - Create a MCInstrInfo implementation.
0409   ///
0410   MCInstrInfo *createMCInstrInfo() const {
0411     if (!MCInstrInfoCtorFn)
0412       return nullptr;
0413     return MCInstrInfoCtorFn();
0414   }
0415 
0416   /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
0417   ///
0418   MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
0419     if (!MCInstrAnalysisCtorFn)
0420       return nullptr;
0421     return MCInstrAnalysisCtorFn(Info);
0422   }
0423 
0424   /// createMCRegInfo - Create a MCRegisterInfo implementation.
0425   ///
0426   MCRegisterInfo *createMCRegInfo(StringRef TT) const {
0427     if (!MCRegInfoCtorFn)
0428       return nullptr;
0429     return MCRegInfoCtorFn(Triple(TT));
0430   }
0431 
0432   /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
0433   ///
0434   /// \param TheTriple This argument is used to determine the target machine
0435   /// feature set; it should always be provided. Generally this should be
0436   /// either the target triple from the module, or the target triple of the
0437   /// host if that does not exist.
0438   /// \param CPU This specifies the name of the target CPU.
0439   /// \param Features This specifies the string representation of the
0440   /// additional target features.
0441   MCSubtargetInfo *createMCSubtargetInfo(StringRef TheTriple, StringRef CPU,
0442                                          StringRef Features) const {
0443     if (!MCSubtargetInfoCtorFn)
0444       return nullptr;
0445     return MCSubtargetInfoCtorFn(Triple(TheTriple), CPU, Features);
0446   }
0447 
0448   /// createTargetMachine - Create a target specific machine implementation
0449   /// for the specified \p Triple.
0450   ///
0451   /// \param TT This argument is used to determine the target machine
0452   /// feature set; it should always be provided. Generally this should be
0453   /// either the target triple from the module, or the target triple of the
0454   /// host if that does not exist.
0455   TargetMachine *createTargetMachine(
0456       StringRef TT, StringRef CPU, StringRef Features,
0457       const TargetOptions &Options, std::optional<Reloc::Model> RM,
0458       std::optional<CodeModel::Model> CM = std::nullopt,
0459       CodeGenOptLevel OL = CodeGenOptLevel::Default, bool JIT = false) const {
0460     if (!TargetMachineCtorFn)
0461       return nullptr;
0462     return TargetMachineCtorFn(*this, Triple(TT), CPU, Features, Options, RM,
0463                                CM, OL, JIT);
0464   }
0465 
0466   /// createMCAsmBackend - Create a target specific assembly parser.
0467   MCAsmBackend *createMCAsmBackend(const MCSubtargetInfo &STI,
0468                                    const MCRegisterInfo &MRI,
0469                                    const MCTargetOptions &Options) const {
0470     if (!MCAsmBackendCtorFn)
0471       return nullptr;
0472     return MCAsmBackendCtorFn(*this, STI, MRI, Options);
0473   }
0474 
0475   /// createMCAsmParser - Create a target specific assembly parser.
0476   ///
0477   /// \param Parser The target independent parser implementation to use for
0478   /// parsing and lexing.
0479   MCTargetAsmParser *createMCAsmParser(const MCSubtargetInfo &STI,
0480                                        MCAsmParser &Parser,
0481                                        const MCInstrInfo &MII,
0482                                        const MCTargetOptions &Options) const {
0483     if (!MCAsmParserCtorFn)
0484       return nullptr;
0485     return MCAsmParserCtorFn(STI, Parser, MII, Options);
0486   }
0487 
0488   /// createAsmPrinter - Create a target specific assembly printer pass.  This
0489   /// takes ownership of the MCStreamer object.
0490   AsmPrinter *createAsmPrinter(TargetMachine &TM,
0491                                std::unique_ptr<MCStreamer> &&Streamer) const {
0492     if (!AsmPrinterCtorFn)
0493       return nullptr;
0494     return AsmPrinterCtorFn(TM, std::move(Streamer));
0495   }
0496 
0497   MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI,
0498                                        MCContext &Ctx) const {
0499     if (!MCDisassemblerCtorFn)
0500       return nullptr;
0501     return MCDisassemblerCtorFn(*this, STI, Ctx);
0502   }
0503 
0504   MCInstPrinter *createMCInstPrinter(const Triple &T, unsigned SyntaxVariant,
0505                                      const MCAsmInfo &MAI,
0506                                      const MCInstrInfo &MII,
0507                                      const MCRegisterInfo &MRI) const {
0508     if (!MCInstPrinterCtorFn)
0509       return nullptr;
0510     return MCInstPrinterCtorFn(T, SyntaxVariant, MAI, MII, MRI);
0511   }
0512 
0513   /// createMCCodeEmitter - Create a target specific code emitter.
0514   MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
0515                                      MCContext &Ctx) const {
0516     if (!MCCodeEmitterCtorFn)
0517       return nullptr;
0518     return MCCodeEmitterCtorFn(II, Ctx);
0519   }
0520 
0521   /// Create a target specific MCStreamer.
0522   ///
0523   /// \param T The target triple.
0524   /// \param Ctx The target context.
0525   /// \param TAB The target assembler backend object. Takes ownership.
0526   /// \param OW The stream object.
0527   /// \param Emitter The target independent assembler object.Takes ownership.
0528   MCStreamer *createMCObjectStreamer(const Triple &T, MCContext &Ctx,
0529                                      std::unique_ptr<MCAsmBackend> TAB,
0530                                      std::unique_ptr<MCObjectWriter> OW,
0531                                      std::unique_ptr<MCCodeEmitter> Emitter,
0532                                      const MCSubtargetInfo &STI) const;
0533   LLVM_DEPRECATED("Use the overload without the 3 trailing bool", "")
0534   MCStreamer *createMCObjectStreamer(const Triple &T, MCContext &Ctx,
0535                                      std::unique_ptr<MCAsmBackend> &&TAB,
0536                                      std::unique_ptr<MCObjectWriter> &&OW,
0537                                      std::unique_ptr<MCCodeEmitter> &&Emitter,
0538                                      const MCSubtargetInfo &STI, bool, bool,
0539                                      bool) const;
0540 
0541   MCStreamer *createAsmStreamer(MCContext &Ctx,
0542                                 std::unique_ptr<formatted_raw_ostream> OS,
0543                                 MCInstPrinter *IP,
0544                                 std::unique_ptr<MCCodeEmitter> CE,
0545                                 std::unique_ptr<MCAsmBackend> TAB) const;
0546   LLVM_DEPRECATED("Use the overload without the 3 unused bool", "")
0547   MCStreamer *
0548   createAsmStreamer(MCContext &Ctx, std::unique_ptr<formatted_raw_ostream> OS,
0549                     bool IsVerboseAsm, bool UseDwarfDirectory,
0550                     MCInstPrinter *IP, std::unique_ptr<MCCodeEmitter> &&CE,
0551                     std::unique_ptr<MCAsmBackend> &&TAB, bool ShowInst) const;
0552 
0553   MCTargetStreamer *createAsmTargetStreamer(MCStreamer &S,
0554                                             formatted_raw_ostream &OS,
0555                                             MCInstPrinter *InstPrint) const {
0556     if (AsmTargetStreamerCtorFn)
0557       return AsmTargetStreamerCtorFn(S, OS, InstPrint);
0558     return nullptr;
0559   }
0560 
0561   MCStreamer *createNullStreamer(MCContext &Ctx) const {
0562     MCStreamer *S = llvm::createNullStreamer(Ctx);
0563     createNullTargetStreamer(*S);
0564     return S;
0565   }
0566 
0567   MCTargetStreamer *createNullTargetStreamer(MCStreamer &S) const {
0568     if (NullTargetStreamerCtorFn)
0569       return NullTargetStreamerCtorFn(S);
0570     return nullptr;
0571   }
0572 
0573   /// createMCRelocationInfo - Create a target specific MCRelocationInfo.
0574   ///
0575   /// \param TT The target triple.
0576   /// \param Ctx The target context.
0577   MCRelocationInfo *createMCRelocationInfo(StringRef TT, MCContext &Ctx) const {
0578     MCRelocationInfoCtorTy Fn = MCRelocationInfoCtorFn
0579                                     ? MCRelocationInfoCtorFn
0580                                     : llvm::createMCRelocationInfo;
0581     return Fn(Triple(TT), Ctx);
0582   }
0583 
0584   /// createMCSymbolizer - Create a target specific MCSymbolizer.
0585   ///
0586   /// \param TT The target triple.
0587   /// \param GetOpInfo The function to get the symbolic information for
0588   /// operands.
0589   /// \param SymbolLookUp The function to lookup a symbol name.
0590   /// \param DisInfo The pointer to the block of symbolic information for above
0591   /// call
0592   /// back.
0593   /// \param Ctx The target context.
0594   /// \param RelInfo The relocation information for this target. Takes
0595   /// ownership.
0596   MCSymbolizer *
0597   createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
0598                      LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo,
0599                      MCContext *Ctx,
0600                      std::unique_ptr<MCRelocationInfo> &&RelInfo) const {
0601     MCSymbolizerCtorTy Fn =
0602         MCSymbolizerCtorFn ? MCSymbolizerCtorFn : llvm::createMCSymbolizer;
0603     return Fn(Triple(TT), GetOpInfo, SymbolLookUp, DisInfo, Ctx,
0604               std::move(RelInfo));
0605   }
0606 
0607   /// createCustomBehaviour - Create a target specific CustomBehaviour.
0608   /// This class is used by llvm-mca and requires backend functionality.
0609   mca::CustomBehaviour *createCustomBehaviour(const MCSubtargetInfo &STI,
0610                                               const mca::SourceMgr &SrcMgr,
0611                                               const MCInstrInfo &MCII) const {
0612     if (CustomBehaviourCtorFn)
0613       return CustomBehaviourCtorFn(STI, SrcMgr, MCII);
0614     return nullptr;
0615   }
0616 
0617   /// createInstrPostProcess - Create a target specific InstrPostProcess.
0618   /// This class is used by llvm-mca and requires backend functionality.
0619   mca::InstrPostProcess *createInstrPostProcess(const MCSubtargetInfo &STI,
0620                                                 const MCInstrInfo &MCII) const {
0621     if (InstrPostProcessCtorFn)
0622       return InstrPostProcessCtorFn(STI, MCII);
0623     return nullptr;
0624   }
0625 
0626   /// createInstrumentManager - Create a target specific
0627   /// InstrumentManager. This class is used by llvm-mca and requires
0628   /// backend functionality.
0629   mca::InstrumentManager *
0630   createInstrumentManager(const MCSubtargetInfo &STI,
0631                           const MCInstrInfo &MCII) const {
0632     if (InstrumentManagerCtorFn)
0633       return InstrumentManagerCtorFn(STI, MCII);
0634     return nullptr;
0635   }
0636 
0637   /// @}
0638 };
0639 
0640 /// TargetRegistry - Generic interface to target specific features.
0641 struct TargetRegistry {
0642   // FIXME: Make this a namespace, probably just move all the Register*
0643   // functions into Target (currently they all just set members on the Target
0644   // anyway, and Target friends this class so those functions can...
0645   // function).
0646   TargetRegistry() = delete;
0647 
0648   class iterator {
0649     friend struct TargetRegistry;
0650 
0651     const Target *Current = nullptr;
0652 
0653     explicit iterator(Target *T) : Current(T) {}
0654 
0655   public:
0656     using iterator_category = std::forward_iterator_tag;
0657     using value_type = Target;
0658     using difference_type = std::ptrdiff_t;
0659     using pointer = value_type *;
0660     using reference = value_type &;
0661 
0662     iterator() = default;
0663 
0664     bool operator==(const iterator &x) const { return Current == x.Current; }
0665     bool operator!=(const iterator &x) const { return !operator==(x); }
0666 
0667     // Iterator traversal: forward iteration only
0668     iterator &operator++() { // Preincrement
0669       assert(Current && "Cannot increment end iterator!");
0670       Current = Current->getNext();
0671       return *this;
0672     }
0673     iterator operator++(int) { // Postincrement
0674       iterator tmp = *this;
0675       ++*this;
0676       return tmp;
0677     }
0678 
0679     const Target &operator*() const {
0680       assert(Current && "Cannot dereference end iterator!");
0681       return *Current;
0682     }
0683 
0684     const Target *operator->() const { return &operator*(); }
0685   };
0686 
0687   /// printRegisteredTargetsForVersion - Print the registered targets
0688   /// appropriately for inclusion in a tool's version output.
0689   static void printRegisteredTargetsForVersion(raw_ostream &OS);
0690 
0691   /// @name Registry Access
0692   /// @{
0693 
0694   static iterator_range<iterator> targets();
0695 
0696   /// lookupTarget - Lookup a target based on a target triple.
0697   ///
0698   /// \param Triple - The triple to use for finding a target.
0699   /// \param Error - On failure, an error string describing why no target was
0700   /// found.
0701   static const Target *lookupTarget(StringRef Triple, std::string &Error);
0702 
0703   /// lookupTarget - Lookup a target based on an architecture name
0704   /// and a target triple.  If the architecture name is non-empty,
0705   /// then the lookup is done by architecture.  Otherwise, the target
0706   /// triple is used.
0707   ///
0708   /// \param ArchName - The architecture to use for finding a target.
0709   /// \param TheTriple - The triple to use for finding a target.  The
0710   /// triple is updated with canonical architecture name if a lookup
0711   /// by architecture is done.
0712   /// \param Error - On failure, an error string describing why no target was
0713   /// found.
0714   static const Target *lookupTarget(StringRef ArchName, Triple &TheTriple,
0715                                     std::string &Error);
0716 
0717   /// @}
0718   /// @name Target Registration
0719   /// @{
0720 
0721   /// RegisterTarget - Register the given target. Attempts to register a
0722   /// target which has already been registered will be ignored.
0723   ///
0724   /// Clients are responsible for ensuring that registration doesn't occur
0725   /// while another thread is attempting to access the registry. Typically
0726   /// this is done by initializing all targets at program startup.
0727   ///
0728   /// @param T - The target being registered.
0729   /// @param Name - The target name. This should be a static string.
0730   /// @param ShortDesc - A short target description. This should be a static
0731   /// string.
0732   /// @param BackendName - The name of the backend. This should be a static
0733   /// string that is the same for all targets that share a backend
0734   /// implementation and must match the name used in the 'def X : Target ...' in
0735   /// TableGen.
0736   /// @param ArchMatchFn - The arch match checking function for this target.
0737   /// @param HasJIT - Whether the target supports JIT code
0738   /// generation.
0739   static void RegisterTarget(Target &T, const char *Name, const char *ShortDesc,
0740                              const char *BackendName,
0741                              Target::ArchMatchFnTy ArchMatchFn,
0742                              bool HasJIT = false);
0743 
0744   /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
0745   /// given target.
0746   ///
0747   /// Clients are responsible for ensuring that registration doesn't occur
0748   /// while another thread is attempting to access the registry. Typically
0749   /// this is done by initializing all targets at program startup.
0750   ///
0751   /// @param T - The target being registered.
0752   /// @param Fn - A function to construct a MCAsmInfo for the target.
0753   static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
0754     T.MCAsmInfoCtorFn = Fn;
0755   }
0756 
0757   /// Register a MCObjectFileInfo implementation for the given target.
0758   ///
0759   /// Clients are responsible for ensuring that registration doesn't occur
0760   /// while another thread is attempting to access the registry. Typically
0761   /// this is done by initializing all targets at program startup.
0762   ///
0763   /// @param T - The target being registered.
0764   /// @param Fn - A function to construct a MCObjectFileInfo for the target.
0765   static void RegisterMCObjectFileInfo(Target &T,
0766                                        Target::MCObjectFileInfoCtorFnTy Fn) {
0767     T.MCObjectFileInfoCtorFn = Fn;
0768   }
0769 
0770   /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
0771   /// given target.
0772   ///
0773   /// Clients are responsible for ensuring that registration doesn't occur
0774   /// while another thread is attempting to access the registry. Typically
0775   /// this is done by initializing all targets at program startup.
0776   ///
0777   /// @param T - The target being registered.
0778   /// @param Fn - A function to construct a MCInstrInfo for the target.
0779   static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
0780     T.MCInstrInfoCtorFn = Fn;
0781   }
0782 
0783   /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
0784   /// the given target.
0785   static void RegisterMCInstrAnalysis(Target &T,
0786                                       Target::MCInstrAnalysisCtorFnTy Fn) {
0787     T.MCInstrAnalysisCtorFn = Fn;
0788   }
0789 
0790   /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
0791   /// given target.
0792   ///
0793   /// Clients are responsible for ensuring that registration doesn't occur
0794   /// while another thread is attempting to access the registry. Typically
0795   /// this is done by initializing all targets at program startup.
0796   ///
0797   /// @param T - The target being registered.
0798   /// @param Fn - A function to construct a MCRegisterInfo for the target.
0799   static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
0800     T.MCRegInfoCtorFn = Fn;
0801   }
0802 
0803   /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
0804   /// the given target.
0805   ///
0806   /// Clients are responsible for ensuring that registration doesn't occur
0807   /// while another thread is attempting to access the registry. Typically
0808   /// this is done by initializing all targets at program startup.
0809   ///
0810   /// @param T - The target being registered.
0811   /// @param Fn - A function to construct a MCSubtargetInfo for the target.
0812   static void RegisterMCSubtargetInfo(Target &T,
0813                                       Target::MCSubtargetInfoCtorFnTy Fn) {
0814     T.MCSubtargetInfoCtorFn = Fn;
0815   }
0816 
0817   /// RegisterTargetMachine - Register a TargetMachine implementation for the
0818   /// given target.
0819   ///
0820   /// Clients are responsible for ensuring that registration doesn't occur
0821   /// while another thread is attempting to access the registry. Typically
0822   /// this is done by initializing all targets at program startup.
0823   ///
0824   /// @param T - The target being registered.
0825   /// @param Fn - A function to construct a TargetMachine for the target.
0826   static void RegisterTargetMachine(Target &T, Target::TargetMachineCtorTy Fn) {
0827     T.TargetMachineCtorFn = Fn;
0828   }
0829 
0830   /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
0831   /// given target.
0832   ///
0833   /// Clients are responsible for ensuring that registration doesn't occur
0834   /// while another thread is attempting to access the registry. Typically
0835   /// this is done by initializing all targets at program startup.
0836   ///
0837   /// @param T - The target being registered.
0838   /// @param Fn - A function to construct an AsmBackend for the target.
0839   static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
0840     T.MCAsmBackendCtorFn = Fn;
0841   }
0842 
0843   /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
0844   /// the given target.
0845   ///
0846   /// Clients are responsible for ensuring that registration doesn't occur
0847   /// while another thread is attempting to access the registry. Typically
0848   /// this is done by initializing all targets at program startup.
0849   ///
0850   /// @param T - The target being registered.
0851   /// @param Fn - A function to construct an MCTargetAsmParser for the target.
0852   static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
0853     T.MCAsmParserCtorFn = Fn;
0854   }
0855 
0856   /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
0857   /// target.
0858   ///
0859   /// Clients are responsible for ensuring that registration doesn't occur
0860   /// while another thread is attempting to access the registry. Typically
0861   /// this is done by initializing all targets at program startup.
0862   ///
0863   /// @param T - The target being registered.
0864   /// @param Fn - A function to construct an AsmPrinter for the target.
0865   static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
0866     T.AsmPrinterCtorFn = Fn;
0867   }
0868 
0869   /// RegisterMCDisassembler - Register a MCDisassembler implementation for
0870   /// the given target.
0871   ///
0872   /// Clients are responsible for ensuring that registration doesn't occur
0873   /// while another thread is attempting to access the registry. Typically
0874   /// this is done by initializing all targets at program startup.
0875   ///
0876   /// @param T - The target being registered.
0877   /// @param Fn - A function to construct an MCDisassembler for the target.
0878   static void RegisterMCDisassembler(Target &T,
0879                                      Target::MCDisassemblerCtorTy Fn) {
0880     T.MCDisassemblerCtorFn = Fn;
0881   }
0882 
0883   /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
0884   /// given target.
0885   ///
0886   /// Clients are responsible for ensuring that registration doesn't occur
0887   /// while another thread is attempting to access the registry. Typically
0888   /// this is done by initializing all targets at program startup.
0889   ///
0890   /// @param T - The target being registered.
0891   /// @param Fn - A function to construct an MCInstPrinter for the target.
0892   static void RegisterMCInstPrinter(Target &T, Target::MCInstPrinterCtorTy Fn) {
0893     T.MCInstPrinterCtorFn = Fn;
0894   }
0895 
0896   /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
0897   /// given target.
0898   ///
0899   /// Clients are responsible for ensuring that registration doesn't occur
0900   /// while another thread is attempting to access the registry. Typically
0901   /// this is done by initializing all targets at program startup.
0902   ///
0903   /// @param T - The target being registered.
0904   /// @param Fn - A function to construct an MCCodeEmitter for the target.
0905   static void RegisterMCCodeEmitter(Target &T, Target::MCCodeEmitterCtorTy Fn) {
0906     T.MCCodeEmitterCtorFn = Fn;
0907   }
0908 
0909   static void RegisterCOFFStreamer(Target &T, Target::COFFStreamerCtorTy Fn) {
0910     T.COFFStreamerCtorFn = Fn;
0911   }
0912 
0913   static void RegisterMachOStreamer(Target &T, Target::MachOStreamerCtorTy Fn) {
0914     T.MachOStreamerCtorFn = Fn;
0915   }
0916 
0917   static void RegisterELFStreamer(Target &T, Target::ELFStreamerCtorTy Fn) {
0918     T.ELFStreamerCtorFn = Fn;
0919   }
0920 
0921   static void RegisterXCOFFStreamer(Target &T, Target::XCOFFStreamerCtorTy Fn) {
0922     T.XCOFFStreamerCtorFn = Fn;
0923   }
0924 
0925   static void RegisterNullTargetStreamer(Target &T,
0926                                          Target::NullTargetStreamerCtorTy Fn) {
0927     T.NullTargetStreamerCtorFn = Fn;
0928   }
0929 
0930   static void RegisterAsmTargetStreamer(Target &T,
0931                                         Target::AsmTargetStreamerCtorTy Fn) {
0932     T.AsmTargetStreamerCtorFn = Fn;
0933   }
0934 
0935   static void
0936   RegisterObjectTargetStreamer(Target &T,
0937                                Target::ObjectTargetStreamerCtorTy Fn) {
0938     T.ObjectTargetStreamerCtorFn = Fn;
0939   }
0940 
0941   /// RegisterMCRelocationInfo - Register an MCRelocationInfo
0942   /// implementation for the given target.
0943   ///
0944   /// Clients are responsible for ensuring that registration doesn't occur
0945   /// while another thread is attempting to access the registry. Typically
0946   /// this is done by initializing all targets at program startup.
0947   ///
0948   /// @param T - The target being registered.
0949   /// @param Fn - A function to construct an MCRelocationInfo for the target.
0950   static void RegisterMCRelocationInfo(Target &T,
0951                                        Target::MCRelocationInfoCtorTy Fn) {
0952     T.MCRelocationInfoCtorFn = Fn;
0953   }
0954 
0955   /// RegisterMCSymbolizer - Register an MCSymbolizer
0956   /// implementation for the given target.
0957   ///
0958   /// Clients are responsible for ensuring that registration doesn't occur
0959   /// while another thread is attempting to access the registry. Typically
0960   /// this is done by initializing all targets at program startup.
0961   ///
0962   /// @param T - The target being registered.
0963   /// @param Fn - A function to construct an MCSymbolizer for the target.
0964   static void RegisterMCSymbolizer(Target &T, Target::MCSymbolizerCtorTy Fn) {
0965     T.MCSymbolizerCtorFn = Fn;
0966   }
0967 
0968   /// RegisterCustomBehaviour - Register a CustomBehaviour
0969   /// implementation for the given target.
0970   ///
0971   /// Clients are responsible for ensuring that registration doesn't occur
0972   /// while another thread is attempting to access the registry. Typically
0973   /// this is done by initializing all targets at program startup.
0974   ///
0975   /// @param T - The target being registered.
0976   /// @param Fn - A function to construct a CustomBehaviour for the target.
0977   static void RegisterCustomBehaviour(Target &T,
0978                                       Target::CustomBehaviourCtorTy Fn) {
0979     T.CustomBehaviourCtorFn = Fn;
0980   }
0981 
0982   /// RegisterInstrPostProcess - Register an InstrPostProcess
0983   /// implementation for the given target.
0984   ///
0985   /// Clients are responsible for ensuring that registration doesn't occur
0986   /// while another thread is attempting to access the registry. Typically
0987   /// this is done by initializing all targets at program startup.
0988   ///
0989   /// @param T - The target being registered.
0990   /// @param Fn - A function to construct an InstrPostProcess for the target.
0991   static void RegisterInstrPostProcess(Target &T,
0992                                        Target::InstrPostProcessCtorTy Fn) {
0993     T.InstrPostProcessCtorFn = Fn;
0994   }
0995 
0996   /// RegisterInstrumentManager - Register an InstrumentManager
0997   /// implementation for the given target.
0998   ///
0999   /// Clients are responsible for ensuring that registration doesn't occur
1000   /// while another thread is attempting to access the registry. Typically
1001   /// this is done by initializing all targets at program startup.
1002   ///
1003   /// @param T - The target being registered.
1004   /// @param Fn - A function to construct an InstrumentManager for the
1005   /// target.
1006   static void RegisterInstrumentManager(Target &T,
1007                                         Target::InstrumentManagerCtorTy Fn) {
1008     T.InstrumentManagerCtorFn = Fn;
1009   }
1010 
1011   /// @}
1012 };
1013 
1014 //===--------------------------------------------------------------------===//
1015 
1016 /// RegisterTarget - Helper template for registering a target, for use in the
1017 /// target's initialization function. Usage:
1018 ///
1019 ///
1020 /// Target &getTheFooTarget() { // The global target instance.
1021 ///   static Target TheFooTarget;
1022 ///   return TheFooTarget;
1023 /// }
1024 /// extern "C" void LLVMInitializeFooTargetInfo() {
1025 ///   RegisterTarget<Triple::foo> X(getTheFooTarget(), "foo", "Foo
1026 ///   description", "Foo" /* Backend Name */);
1027 /// }
1028 template <Triple::ArchType TargetArchType = Triple::UnknownArch,
1029           bool HasJIT = false>
1030 struct RegisterTarget {
1031   RegisterTarget(Target &T, const char *Name, const char *Desc,
1032                  const char *BackendName) {
1033     TargetRegistry::RegisterTarget(T, Name, Desc, BackendName, &getArchMatch,
1034                                    HasJIT);
1035   }
1036 
1037   static bool getArchMatch(Triple::ArchType Arch) {
1038     return Arch == TargetArchType;
1039   }
1040 };
1041 
1042 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
1043 /// implementation.  This invokes the static "Create" method on the class to
1044 /// actually do the construction.  Usage:
1045 ///
1046 /// extern "C" void LLVMInitializeFooTarget() {
1047 ///   extern Target TheFooTarget;
1048 ///   RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
1049 /// }
1050 template <class MCAsmInfoImpl> struct RegisterMCAsmInfo {
1051   RegisterMCAsmInfo(Target &T) {
1052     TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
1053   }
1054 
1055 private:
1056   static MCAsmInfo *Allocator(const MCRegisterInfo & /*MRI*/, const Triple &TT,
1057                               const MCTargetOptions &Options) {
1058     return new MCAsmInfoImpl(TT, Options);
1059   }
1060 };
1061 
1062 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
1063 /// implementation.  This invokes the specified function to do the
1064 /// construction.  Usage:
1065 ///
1066 /// extern "C" void LLVMInitializeFooTarget() {
1067 ///   extern Target TheFooTarget;
1068 ///   RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
1069 /// }
1070 struct RegisterMCAsmInfoFn {
1071   RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
1072     TargetRegistry::RegisterMCAsmInfo(T, Fn);
1073   }
1074 };
1075 
1076 /// Helper template for registering a target object file info implementation.
1077 /// This invokes the static "Create" method on the class to actually do the
1078 /// construction.  Usage:
1079 ///
1080 /// extern "C" void LLVMInitializeFooTarget() {
1081 ///   extern Target TheFooTarget;
1082 ///   RegisterMCObjectFileInfo<FooMCObjectFileInfo> X(TheFooTarget);
1083 /// }
1084 template <class MCObjectFileInfoImpl> struct RegisterMCObjectFileInfo {
1085   RegisterMCObjectFileInfo(Target &T) {
1086     TargetRegistry::RegisterMCObjectFileInfo(T, &Allocator);
1087   }
1088 
1089 private:
1090   static MCObjectFileInfo *Allocator(MCContext &Ctx, bool PIC,
1091                                      bool LargeCodeModel = false) {
1092     return new MCObjectFileInfoImpl(Ctx, PIC, LargeCodeModel);
1093   }
1094 };
1095 
1096 /// Helper template for registering a target object file info implementation.
1097 /// This invokes the specified function to do the construction.  Usage:
1098 ///
1099 /// extern "C" void LLVMInitializeFooTarget() {
1100 ///   extern Target TheFooTarget;
1101 ///   RegisterMCObjectFileInfoFn X(TheFooTarget, TheFunction);
1102 /// }
1103 struct RegisterMCObjectFileInfoFn {
1104   RegisterMCObjectFileInfoFn(Target &T, Target::MCObjectFileInfoCtorFnTy Fn) {
1105     TargetRegistry::RegisterMCObjectFileInfo(T, Fn);
1106   }
1107 };
1108 
1109 /// RegisterMCInstrInfo - Helper template for registering a target instruction
1110 /// info implementation.  This invokes the static "Create" method on the class
1111 /// to actually do the construction.  Usage:
1112 ///
1113 /// extern "C" void LLVMInitializeFooTarget() {
1114 ///   extern Target TheFooTarget;
1115 ///   RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
1116 /// }
1117 template <class MCInstrInfoImpl> struct RegisterMCInstrInfo {
1118   RegisterMCInstrInfo(Target &T) {
1119     TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
1120   }
1121 
1122 private:
1123   static MCInstrInfo *Allocator() { return new MCInstrInfoImpl(); }
1124 };
1125 
1126 /// RegisterMCInstrInfoFn - Helper template for registering a target
1127 /// instruction info implementation.  This invokes the specified function to
1128 /// do the construction.  Usage:
1129 ///
1130 /// extern "C" void LLVMInitializeFooTarget() {
1131 ///   extern Target TheFooTarget;
1132 ///   RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
1133 /// }
1134 struct RegisterMCInstrInfoFn {
1135   RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
1136     TargetRegistry::RegisterMCInstrInfo(T, Fn);
1137   }
1138 };
1139 
1140 /// RegisterMCInstrAnalysis - Helper template for registering a target
1141 /// instruction analyzer implementation.  This invokes the static "Create"
1142 /// method on the class to actually do the construction.  Usage:
1143 ///
1144 /// extern "C" void LLVMInitializeFooTarget() {
1145 ///   extern Target TheFooTarget;
1146 ///   RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
1147 /// }
1148 template <class MCInstrAnalysisImpl> struct RegisterMCInstrAnalysis {
1149   RegisterMCInstrAnalysis(Target &T) {
1150     TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
1151   }
1152 
1153 private:
1154   static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
1155     return new MCInstrAnalysisImpl(Info);
1156   }
1157 };
1158 
1159 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
1160 /// instruction analyzer implementation.  This invokes the specified function
1161 /// to do the construction.  Usage:
1162 ///
1163 /// extern "C" void LLVMInitializeFooTarget() {
1164 ///   extern Target TheFooTarget;
1165 ///   RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
1166 /// }
1167 struct RegisterMCInstrAnalysisFn {
1168   RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
1169     TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
1170   }
1171 };
1172 
1173 /// RegisterMCRegInfo - Helper template for registering a target register info
1174 /// implementation.  This invokes the static "Create" method on the class to
1175 /// actually do the construction.  Usage:
1176 ///
1177 /// extern "C" void LLVMInitializeFooTarget() {
1178 ///   extern Target TheFooTarget;
1179 ///   RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
1180 /// }
1181 template <class MCRegisterInfoImpl> struct RegisterMCRegInfo {
1182   RegisterMCRegInfo(Target &T) {
1183     TargetRegistry::RegisterMCRegInfo(T, &Allocator);
1184   }
1185 
1186 private:
1187   static MCRegisterInfo *Allocator(const Triple & /*TT*/) {
1188     return new MCRegisterInfoImpl();
1189   }
1190 };
1191 
1192 /// RegisterMCRegInfoFn - Helper template for registering a target register
1193 /// info implementation.  This invokes the specified function to do the
1194 /// construction.  Usage:
1195 ///
1196 /// extern "C" void LLVMInitializeFooTarget() {
1197 ///   extern Target TheFooTarget;
1198 ///   RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
1199 /// }
1200 struct RegisterMCRegInfoFn {
1201   RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
1202     TargetRegistry::RegisterMCRegInfo(T, Fn);
1203   }
1204 };
1205 
1206 /// RegisterMCSubtargetInfo - Helper template for registering a target
1207 /// subtarget info implementation.  This invokes the static "Create" method
1208 /// on the class to actually do the construction.  Usage:
1209 ///
1210 /// extern "C" void LLVMInitializeFooTarget() {
1211 ///   extern Target TheFooTarget;
1212 ///   RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
1213 /// }
1214 template <class MCSubtargetInfoImpl> struct RegisterMCSubtargetInfo {
1215   RegisterMCSubtargetInfo(Target &T) {
1216     TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
1217   }
1218 
1219 private:
1220   static MCSubtargetInfo *Allocator(const Triple & /*TT*/, StringRef /*CPU*/,
1221                                     StringRef /*FS*/) {
1222     return new MCSubtargetInfoImpl();
1223   }
1224 };
1225 
1226 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
1227 /// subtarget info implementation.  This invokes the specified function to
1228 /// do the construction.  Usage:
1229 ///
1230 /// extern "C" void LLVMInitializeFooTarget() {
1231 ///   extern Target TheFooTarget;
1232 ///   RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1233 /// }
1234 struct RegisterMCSubtargetInfoFn {
1235   RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
1236     TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
1237   }
1238 };
1239 
1240 /// RegisterTargetMachine - Helper template for registering a target machine
1241 /// implementation, for use in the target machine initialization
1242 /// function. Usage:
1243 ///
1244 /// extern "C" void LLVMInitializeFooTarget() {
1245 ///   extern Target TheFooTarget;
1246 ///   RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1247 /// }
1248 template <class TargetMachineImpl> struct RegisterTargetMachine {
1249   RegisterTargetMachine(Target &T) {
1250     TargetRegistry::RegisterTargetMachine(T, &Allocator);
1251   }
1252 
1253 private:
1254   static TargetMachine *
1255   Allocator(const Target &T, const Triple &TT, StringRef CPU, StringRef FS,
1256             const TargetOptions &Options, std::optional<Reloc::Model> RM,
1257             std::optional<CodeModel::Model> CM, CodeGenOptLevel OL, bool JIT) {
1258     return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL, JIT);
1259   }
1260 };
1261 
1262 /// RegisterMCAsmBackend - Helper template for registering a target specific
1263 /// assembler backend. Usage:
1264 ///
1265 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1266 ///   extern Target TheFooTarget;
1267 ///   RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1268 /// }
1269 template <class MCAsmBackendImpl> struct RegisterMCAsmBackend {
1270   RegisterMCAsmBackend(Target &T) {
1271     TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1272   }
1273 
1274 private:
1275   static MCAsmBackend *Allocator(const Target &T, const MCSubtargetInfo &STI,
1276                                  const MCRegisterInfo &MRI,
1277                                  const MCTargetOptions &Options) {
1278     return new MCAsmBackendImpl(T, STI, MRI);
1279   }
1280 };
1281 
1282 /// RegisterMCAsmParser - Helper template for registering a target specific
1283 /// assembly parser, for use in the target machine initialization
1284 /// function. Usage:
1285 ///
1286 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1287 ///   extern Target TheFooTarget;
1288 ///   RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1289 /// }
1290 template <class MCAsmParserImpl> struct RegisterMCAsmParser {
1291   RegisterMCAsmParser(Target &T) {
1292     TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1293   }
1294 
1295 private:
1296   static MCTargetAsmParser *Allocator(const MCSubtargetInfo &STI,
1297                                       MCAsmParser &P, const MCInstrInfo &MII,
1298                                       const MCTargetOptions &Options) {
1299     return new MCAsmParserImpl(STI, P, MII, Options);
1300   }
1301 };
1302 
1303 /// RegisterAsmPrinter - Helper template for registering a target specific
1304 /// assembly printer, for use in the target machine initialization
1305 /// function. Usage:
1306 ///
1307 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1308 ///   extern Target TheFooTarget;
1309 ///   RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1310 /// }
1311 template <class AsmPrinterImpl> struct RegisterAsmPrinter {
1312   RegisterAsmPrinter(Target &T) {
1313     TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1314   }
1315 
1316 private:
1317   static AsmPrinter *Allocator(TargetMachine &TM,
1318                                std::unique_ptr<MCStreamer> &&Streamer) {
1319     return new AsmPrinterImpl(TM, std::move(Streamer));
1320   }
1321 };
1322 
1323 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1324 /// machine code emitter, for use in the target initialization
1325 /// function. Usage:
1326 ///
1327 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1328 ///   extern Target TheFooTarget;
1329 ///   RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1330 /// }
1331 template <class MCCodeEmitterImpl> struct RegisterMCCodeEmitter {
1332   RegisterMCCodeEmitter(Target &T) {
1333     TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1334   }
1335 
1336 private:
1337   static MCCodeEmitter *Allocator(const MCInstrInfo & /*II*/,
1338                                   MCContext & /*Ctx*/) {
1339     return new MCCodeEmitterImpl();
1340   }
1341 };
1342 
1343 } // end namespace llvm
1344 
1345 #endif // LLVM_MC_TARGETREGISTRY_H