123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464 |
- #pragma once
- #ifdef __GNUC__
- #pragma GCC diagnostic push
- #pragma GCC diagnostic ignored "-Wunused-parameter"
- #endif
- //===- MC/TargetRegistry.h - Target Registration ----------------*- C++ -*-===//
- //
- // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
- // See https://llvm.org/LICENSE.txt for license information.
- // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
- //
- //===----------------------------------------------------------------------===//
- //
- // This file exposes the TargetRegistry interface, which tools can use to access
- // the appropriate target specific classes (TargetMachine, AsmPrinter, etc.)
- // which have been registered.
- //
- // Target specific class implementations should register themselves using the
- // appropriate TargetRegistry interfaces.
- //
- //===----------------------------------------------------------------------===//
- #ifndef LLVM_MC_TARGETREGISTRY_H
- #define LLVM_MC_TARGETREGISTRY_H
- #include "llvm-c/DisassemblerTypes.h"
- #include "llvm/ADT/StringRef.h"
- #include "llvm/ADT/Triple.h"
- #include "llvm/ADT/iterator_range.h"
- #include "llvm/MC/MCObjectFileInfo.h"
- #include "llvm/Support/CodeGen.h"
- #include "llvm/Support/ErrorHandling.h"
- #include "llvm/Support/FormattedStream.h"
- #include <cassert>
- #include <cstddef>
- #include <iterator>
- #include <memory>
- #include <optional>
- #include <string>
- namespace llvm {
- class AsmPrinter;
- class MCAsmBackend;
- class MCAsmInfo;
- class MCAsmParser;
- class MCCodeEmitter;
- class MCContext;
- class MCDisassembler;
- class MCInstPrinter;
- class MCInstrAnalysis;
- class MCInstrInfo;
- class MCObjectWriter;
- class MCRegisterInfo;
- class MCRelocationInfo;
- class MCStreamer;
- class MCSubtargetInfo;
- class MCSymbolizer;
- class MCTargetAsmParser;
- class MCTargetOptions;
- class MCTargetStreamer;
- class raw_ostream;
- class TargetMachine;
- class TargetOptions;
- namespace mca {
- class CustomBehaviour;
- class InstrPostProcess;
- class InstrumentManager;
- struct SourceMgr;
- } // namespace mca
- MCStreamer *createNullStreamer(MCContext &Ctx);
- // Takes ownership of \p TAB and \p CE.
- /// Create a machine code streamer which will print out assembly for the native
- /// target, suitable for compiling with a native assembler.
- ///
- /// \param InstPrint - If given, the instruction printer to use. If not given
- /// the MCInst representation will be printed. This method takes ownership of
- /// InstPrint.
- ///
- /// \param CE - If given, a code emitter to use to show the instruction
- /// encoding inline with the assembly. This method takes ownership of \p CE.
- ///
- /// \param TAB - If given, a target asm backend to use to show the fixup
- /// information in conjunction with encoding information. This method takes
- /// ownership of \p TAB.
- ///
- /// \param ShowInst - Whether to show the MCInst representation inline with
- /// the assembly.
- MCStreamer *
- createAsmStreamer(MCContext &Ctx, std::unique_ptr<formatted_raw_ostream> OS,
- bool isVerboseAsm, bool useDwarfDirectory,
- MCInstPrinter *InstPrint, std::unique_ptr<MCCodeEmitter> &&CE,
- std::unique_ptr<MCAsmBackend> &&TAB, bool ShowInst);
- MCStreamer *createELFStreamer(MCContext &Ctx,
- std::unique_ptr<MCAsmBackend> &&TAB,
- std::unique_ptr<MCObjectWriter> &&OW,
- std::unique_ptr<MCCodeEmitter> &&CE,
- bool RelaxAll);
- MCStreamer *createMachOStreamer(MCContext &Ctx,
- std::unique_ptr<MCAsmBackend> &&TAB,
- std::unique_ptr<MCObjectWriter> &&OW,
- std::unique_ptr<MCCodeEmitter> &&CE,
- bool RelaxAll, bool DWARFMustBeAtTheEnd,
- bool LabelSections = false);
- MCStreamer *createWasmStreamer(MCContext &Ctx,
- std::unique_ptr<MCAsmBackend> &&TAB,
- std::unique_ptr<MCObjectWriter> &&OW,
- std::unique_ptr<MCCodeEmitter> &&CE,
- bool RelaxAll);
- MCStreamer *createXCOFFStreamer(MCContext &Ctx,
- std::unique_ptr<MCAsmBackend> &&TAB,
- std::unique_ptr<MCObjectWriter> &&OW,
- std::unique_ptr<MCCodeEmitter> &&CE,
- bool RelaxAll);
- MCStreamer *createSPIRVStreamer(MCContext &Ctx,
- std::unique_ptr<MCAsmBackend> &&TAB,
- std::unique_ptr<MCObjectWriter> &&OW,
- std::unique_ptr<MCCodeEmitter> &&CE,
- bool RelaxAll);
- MCStreamer *createDXContainerStreamer(MCContext &Ctx,
- std::unique_ptr<MCAsmBackend> &&TAB,
- std::unique_ptr<MCObjectWriter> &&OW,
- std::unique_ptr<MCCodeEmitter> &&CE,
- bool RelaxAll);
- MCRelocationInfo *createMCRelocationInfo(const Triple &TT, MCContext &Ctx);
- MCSymbolizer *createMCSymbolizer(const Triple &TT, LLVMOpInfoCallback GetOpInfo,
- LLVMSymbolLookupCallback SymbolLookUp,
- void *DisInfo, MCContext *Ctx,
- std::unique_ptr<MCRelocationInfo> &&RelInfo);
- mca::CustomBehaviour *createCustomBehaviour(const MCSubtargetInfo &STI,
- const mca::SourceMgr &SrcMgr,
- const MCInstrInfo &MCII);
- mca::InstrPostProcess *createInstrPostProcess(const MCSubtargetInfo &STI,
- const MCInstrInfo &MCII);
- mca::InstrumentManager *createInstrumentManager(const MCSubtargetInfo &STI,
- const MCInstrInfo &MCII);
- /// Target - Wrapper for Target specific information.
- ///
- /// For registration purposes, this is a POD type so that targets can be
- /// registered without the use of static constructors.
- ///
- /// Targets should implement a single global instance of this class (which
- /// will be zero initialized), and pass that instance to the TargetRegistry as
- /// part of their initialization.
- class Target {
- public:
- friend struct TargetRegistry;
- using ArchMatchFnTy = bool (*)(Triple::ArchType Arch);
- using MCAsmInfoCtorFnTy = MCAsmInfo *(*)(const MCRegisterInfo &MRI,
- const Triple &TT,
- const MCTargetOptions &Options);
- using MCObjectFileInfoCtorFnTy = MCObjectFileInfo *(*)(MCContext &Ctx,
- bool PIC,
- bool LargeCodeModel);
- using MCInstrInfoCtorFnTy = MCInstrInfo *(*)();
- using MCInstrAnalysisCtorFnTy = MCInstrAnalysis *(*)(const MCInstrInfo *Info);
- using MCRegInfoCtorFnTy = MCRegisterInfo *(*)(const Triple &TT);
- using MCSubtargetInfoCtorFnTy = MCSubtargetInfo *(*)(const Triple &TT,
- StringRef CPU,
- StringRef Features);
- using TargetMachineCtorTy = TargetMachine
- *(*)(const Target &T, const Triple &TT, StringRef CPU, StringRef Features,
- const TargetOptions &Options, std::optional<Reloc::Model> RM,
- std::optional<CodeModel::Model> CM, CodeGenOpt::Level OL, bool JIT);
- // If it weren't for layering issues (this header is in llvm/Support, but
- // depends on MC?) this should take the Streamer by value rather than rvalue
- // reference.
- using AsmPrinterCtorTy = AsmPrinter *(*)(
- TargetMachine &TM, std::unique_ptr<MCStreamer> &&Streamer);
- using MCAsmBackendCtorTy = MCAsmBackend *(*)(const Target &T,
- const MCSubtargetInfo &STI,
- const MCRegisterInfo &MRI,
- const MCTargetOptions &Options);
- using MCAsmParserCtorTy = MCTargetAsmParser *(*)(
- const MCSubtargetInfo &STI, MCAsmParser &P, const MCInstrInfo &MII,
- const MCTargetOptions &Options);
- using MCDisassemblerCtorTy = MCDisassembler *(*)(const Target &T,
- const MCSubtargetInfo &STI,
- MCContext &Ctx);
- using MCInstPrinterCtorTy = MCInstPrinter *(*)(const Triple &T,
- unsigned SyntaxVariant,
- const MCAsmInfo &MAI,
- const MCInstrInfo &MII,
- const MCRegisterInfo &MRI);
- using MCCodeEmitterCtorTy = MCCodeEmitter *(*)(const MCInstrInfo &II,
- MCContext &Ctx);
- using ELFStreamerCtorTy =
- MCStreamer *(*)(const Triple &T, MCContext &Ctx,
- std::unique_ptr<MCAsmBackend> &&TAB,
- std::unique_ptr<MCObjectWriter> &&OW,
- std::unique_ptr<MCCodeEmitter> &&Emitter, bool RelaxAll);
- using MachOStreamerCtorTy =
- MCStreamer *(*)(MCContext &Ctx, std::unique_ptr<MCAsmBackend> &&TAB,
- std::unique_ptr<MCObjectWriter> &&OW,
- std::unique_ptr<MCCodeEmitter> &&Emitter, bool RelaxAll,
- bool DWARFMustBeAtTheEnd);
- using COFFStreamerCtorTy =
- MCStreamer *(*)(MCContext &Ctx, std::unique_ptr<MCAsmBackend> &&TAB,
- std::unique_ptr<MCObjectWriter> &&OW,
- std::unique_ptr<MCCodeEmitter> &&Emitter, bool RelaxAll,
- bool IncrementalLinkerCompatible);
- using WasmStreamerCtorTy =
- MCStreamer *(*)(const Triple &T, MCContext &Ctx,
- std::unique_ptr<MCAsmBackend> &&TAB,
- std::unique_ptr<MCObjectWriter> &&OW,
- std::unique_ptr<MCCodeEmitter> &&Emitter, bool RelaxAll);
- using XCOFFStreamerCtorTy =
- MCStreamer *(*)(const Triple &T, MCContext &Ctx,
- std::unique_ptr<MCAsmBackend> &&TAB,
- std::unique_ptr<MCObjectWriter> &&OW,
- std::unique_ptr<MCCodeEmitter> &&Emitter, bool RelaxAll);
- using SPIRVStreamerCtorTy =
- MCStreamer *(*)(const Triple &T, MCContext &Ctx,
- std::unique_ptr<MCAsmBackend> &&TAB,
- std::unique_ptr<MCObjectWriter> &&OW,
- std::unique_ptr<MCCodeEmitter> &&Emitter, bool RelaxAll);
-
- using DXContainerStreamerCtorTy =
- MCStreamer *(*)(const Triple &T, MCContext &Ctx,
- std::unique_ptr<MCAsmBackend> &&TAB,
- std::unique_ptr<MCObjectWriter> &&OW,
- std::unique_ptr<MCCodeEmitter> &&Emitter, bool RelaxAll);
- using NullTargetStreamerCtorTy = MCTargetStreamer *(*)(MCStreamer &S);
- using AsmTargetStreamerCtorTy = MCTargetStreamer *(*)(
- MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *InstPrint,
- bool IsVerboseAsm);
- using ObjectTargetStreamerCtorTy = MCTargetStreamer *(*)(
- MCStreamer &S, const MCSubtargetInfo &STI);
- using MCRelocationInfoCtorTy = MCRelocationInfo *(*)(const Triple &TT,
- MCContext &Ctx);
- using MCSymbolizerCtorTy = MCSymbolizer *(*)(
- const Triple &TT, LLVMOpInfoCallback GetOpInfo,
- LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo, MCContext *Ctx,
- std::unique_ptr<MCRelocationInfo> &&RelInfo);
- using CustomBehaviourCtorTy =
- mca::CustomBehaviour *(*)(const MCSubtargetInfo &STI,
- const mca::SourceMgr &SrcMgr,
- const MCInstrInfo &MCII);
- using InstrPostProcessCtorTy =
- mca::InstrPostProcess *(*)(const MCSubtargetInfo &STI,
- const MCInstrInfo &MCII);
- using InstrumentManagerCtorTy =
- mca::InstrumentManager *(*)(const MCSubtargetInfo &STI,
- const MCInstrInfo &MCII);
- private:
- /// Next - The next registered target in the linked list, maintained by the
- /// TargetRegistry.
- Target *Next;
- /// The target function for checking if an architecture is supported.
- ArchMatchFnTy ArchMatchFn;
- /// Name - The target name.
- const char *Name;
- /// ShortDesc - A short description of the target.
- const char *ShortDesc;
- /// BackendName - The name of the backend implementation. This must match the
- /// name of the 'def X : Target ...' in TableGen.
- const char *BackendName;
- /// HasJIT - Whether this target supports the JIT.
- bool HasJIT;
- /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
- /// registered.
- MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
- /// Constructor function for this target's MCObjectFileInfo, if registered.
- MCObjectFileInfoCtorFnTy MCObjectFileInfoCtorFn;
- /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
- /// if registered.
- MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
- /// MCInstrAnalysisCtorFn - Constructor function for this target's
- /// MCInstrAnalysis, if registered.
- MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
- /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
- /// if registered.
- MCRegInfoCtorFnTy MCRegInfoCtorFn;
- /// MCSubtargetInfoCtorFn - Constructor function for this target's
- /// MCSubtargetInfo, if registered.
- MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
- /// TargetMachineCtorFn - Construction function for this target's
- /// TargetMachine, if registered.
- TargetMachineCtorTy TargetMachineCtorFn;
- /// MCAsmBackendCtorFn - Construction function for this target's
- /// MCAsmBackend, if registered.
- MCAsmBackendCtorTy MCAsmBackendCtorFn;
- /// MCAsmParserCtorFn - Construction function for this target's
- /// MCTargetAsmParser, if registered.
- MCAsmParserCtorTy MCAsmParserCtorFn;
- /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
- /// if registered.
- AsmPrinterCtorTy AsmPrinterCtorFn;
- /// MCDisassemblerCtorFn - Construction function for this target's
- /// MCDisassembler, if registered.
- MCDisassemblerCtorTy MCDisassemblerCtorFn;
- /// MCInstPrinterCtorFn - Construction function for this target's
- /// MCInstPrinter, if registered.
- MCInstPrinterCtorTy MCInstPrinterCtorFn;
- /// MCCodeEmitterCtorFn - Construction function for this target's
- /// CodeEmitter, if registered.
- MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
- // Construction functions for the various object formats, if registered.
- COFFStreamerCtorTy COFFStreamerCtorFn = nullptr;
- MachOStreamerCtorTy MachOStreamerCtorFn = nullptr;
- ELFStreamerCtorTy ELFStreamerCtorFn = nullptr;
- WasmStreamerCtorTy WasmStreamerCtorFn = nullptr;
- XCOFFStreamerCtorTy XCOFFStreamerCtorFn = nullptr;
- SPIRVStreamerCtorTy SPIRVStreamerCtorFn = nullptr;
- DXContainerStreamerCtorTy DXContainerStreamerCtorFn = nullptr;
- /// Construction function for this target's null TargetStreamer, if
- /// registered (default = nullptr).
- NullTargetStreamerCtorTy NullTargetStreamerCtorFn = nullptr;
- /// Construction function for this target's asm TargetStreamer, if
- /// registered (default = nullptr).
- AsmTargetStreamerCtorTy AsmTargetStreamerCtorFn = nullptr;
- /// Construction function for this target's obj TargetStreamer, if
- /// registered (default = nullptr).
- ObjectTargetStreamerCtorTy ObjectTargetStreamerCtorFn = nullptr;
- /// MCRelocationInfoCtorFn - Construction function for this target's
- /// MCRelocationInfo, if registered (default = llvm::createMCRelocationInfo)
- MCRelocationInfoCtorTy MCRelocationInfoCtorFn = nullptr;
- /// MCSymbolizerCtorFn - Construction function for this target's
- /// MCSymbolizer, if registered (default = llvm::createMCSymbolizer)
- MCSymbolizerCtorTy MCSymbolizerCtorFn = nullptr;
- /// CustomBehaviourCtorFn - Construction function for this target's
- /// CustomBehaviour, if registered (default = nullptr).
- CustomBehaviourCtorTy CustomBehaviourCtorFn = nullptr;
- /// InstrPostProcessCtorFn - Construction function for this target's
- /// InstrPostProcess, if registered (default = nullptr).
- InstrPostProcessCtorTy InstrPostProcessCtorFn = nullptr;
- /// InstrumentManagerCtorFn - Construction function for this target's
- /// InstrumentManager, if registered (default = nullptr).
- InstrumentManagerCtorTy InstrumentManagerCtorFn = nullptr;
- public:
- Target() = default;
- /// @name Target Information
- /// @{
- // getNext - Return the next registered target.
- const Target *getNext() const { return Next; }
- /// getName - Get the target name.
- const char *getName() const { return Name; }
- /// getShortDescription - Get a short description of the target.
- const char *getShortDescription() const { return ShortDesc; }
- /// getBackendName - Get the backend name.
- const char *getBackendName() const { return BackendName; }
- /// @}
- /// @name Feature Predicates
- /// @{
- /// hasJIT - Check if this targets supports the just-in-time compilation.
- bool hasJIT() const { return HasJIT; }
- /// hasTargetMachine - Check if this target supports code generation.
- bool hasTargetMachine() const { return TargetMachineCtorFn != nullptr; }
- /// hasMCAsmBackend - Check if this target supports .o generation.
- bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != nullptr; }
- /// hasMCAsmParser - Check if this target supports assembly parsing.
- bool hasMCAsmParser() const { return MCAsmParserCtorFn != nullptr; }
- /// @}
- /// @name Feature Constructors
- /// @{
- /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
- /// target triple.
- ///
- /// \param TheTriple This argument is used to determine the target machine
- /// feature set; it should always be provided. Generally this should be
- /// either the target triple from the module, or the target triple of the
- /// host if that does not exist.
- MCAsmInfo *createMCAsmInfo(const MCRegisterInfo &MRI, StringRef TheTriple,
- const MCTargetOptions &Options) const {
- if (!MCAsmInfoCtorFn)
- return nullptr;
- return MCAsmInfoCtorFn(MRI, Triple(TheTriple), Options);
- }
- /// Create a MCObjectFileInfo implementation for the specified target
- /// triple.
- ///
- MCObjectFileInfo *createMCObjectFileInfo(MCContext &Ctx, bool PIC,
- bool LargeCodeModel = false) const {
- if (!MCObjectFileInfoCtorFn) {
- MCObjectFileInfo *MOFI = new MCObjectFileInfo();
- MOFI->initMCObjectFileInfo(Ctx, PIC, LargeCodeModel);
- return MOFI;
- }
- return MCObjectFileInfoCtorFn(Ctx, PIC, LargeCodeModel);
- }
- /// createMCInstrInfo - Create a MCInstrInfo implementation.
- ///
- MCInstrInfo *createMCInstrInfo() const {
- if (!MCInstrInfoCtorFn)
- return nullptr;
- return MCInstrInfoCtorFn();
- }
- /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
- ///
- MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
- if (!MCInstrAnalysisCtorFn)
- return nullptr;
- return MCInstrAnalysisCtorFn(Info);
- }
- /// createMCRegInfo - Create a MCRegisterInfo implementation.
- ///
- MCRegisterInfo *createMCRegInfo(StringRef TT) const {
- if (!MCRegInfoCtorFn)
- return nullptr;
- return MCRegInfoCtorFn(Triple(TT));
- }
- /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
- ///
- /// \param TheTriple This argument is used to determine the target machine
- /// feature set; it should always be provided. Generally this should be
- /// either the target triple from the module, or the target triple of the
- /// host if that does not exist.
- /// \param CPU This specifies the name of the target CPU.
- /// \param Features This specifies the string representation of the
- /// additional target features.
- MCSubtargetInfo *createMCSubtargetInfo(StringRef TheTriple, StringRef CPU,
- StringRef Features) const {
- if (!MCSubtargetInfoCtorFn)
- return nullptr;
- return MCSubtargetInfoCtorFn(Triple(TheTriple), CPU, Features);
- }
- /// createTargetMachine - Create a target specific machine implementation
- /// for the specified \p Triple.
- ///
- /// \param TT This argument is used to determine the target machine
- /// feature set; it should always be provided. Generally this should be
- /// either the target triple from the module, or the target triple of the
- /// host if that does not exist.
- TargetMachine *createTargetMachine(
- StringRef TT, StringRef CPU, StringRef Features,
- const TargetOptions &Options, std::optional<Reloc::Model> RM,
- std::optional<CodeModel::Model> CM = std::nullopt,
- CodeGenOpt::Level OL = CodeGenOpt::Default, bool JIT = false) const {
- if (!TargetMachineCtorFn)
- return nullptr;
- return TargetMachineCtorFn(*this, Triple(TT), CPU, Features, Options, RM,
- CM, OL, JIT);
- }
- /// createMCAsmBackend - Create a target specific assembly parser.
- MCAsmBackend *createMCAsmBackend(const MCSubtargetInfo &STI,
- const MCRegisterInfo &MRI,
- const MCTargetOptions &Options) const {
- if (!MCAsmBackendCtorFn)
- return nullptr;
- return MCAsmBackendCtorFn(*this, STI, MRI, Options);
- }
- /// createMCAsmParser - Create a target specific assembly parser.
- ///
- /// \param Parser The target independent parser implementation to use for
- /// parsing and lexing.
- MCTargetAsmParser *createMCAsmParser(const MCSubtargetInfo &STI,
- MCAsmParser &Parser,
- const MCInstrInfo &MII,
- const MCTargetOptions &Options) const {
- if (!MCAsmParserCtorFn)
- return nullptr;
- return MCAsmParserCtorFn(STI, Parser, MII, Options);
- }
- /// createAsmPrinter - Create a target specific assembly printer pass. This
- /// takes ownership of the MCStreamer object.
- AsmPrinter *createAsmPrinter(TargetMachine &TM,
- std::unique_ptr<MCStreamer> &&Streamer) const {
- if (!AsmPrinterCtorFn)
- return nullptr;
- return AsmPrinterCtorFn(TM, std::move(Streamer));
- }
- MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI,
- MCContext &Ctx) const {
- if (!MCDisassemblerCtorFn)
- return nullptr;
- return MCDisassemblerCtorFn(*this, STI, Ctx);
- }
- MCInstPrinter *createMCInstPrinter(const Triple &T, unsigned SyntaxVariant,
- const MCAsmInfo &MAI,
- const MCInstrInfo &MII,
- const MCRegisterInfo &MRI) const {
- if (!MCInstPrinterCtorFn)
- return nullptr;
- return MCInstPrinterCtorFn(T, SyntaxVariant, MAI, MII, MRI);
- }
- /// createMCCodeEmitter - Create a target specific code emitter.
- MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
- MCContext &Ctx) const {
- if (!MCCodeEmitterCtorFn)
- return nullptr;
- return MCCodeEmitterCtorFn(II, Ctx);
- }
- /// Create a target specific MCStreamer.
- ///
- /// \param T The target triple.
- /// \param Ctx The target context.
- /// \param TAB The target assembler backend object. Takes ownership.
- /// \param OW The stream object.
- /// \param Emitter The target independent assembler object.Takes ownership.
- /// \param RelaxAll Relax all fixups?
- MCStreamer *createMCObjectStreamer(const Triple &T, MCContext &Ctx,
- std::unique_ptr<MCAsmBackend> &&TAB,
- std::unique_ptr<MCObjectWriter> &&OW,
- std::unique_ptr<MCCodeEmitter> &&Emitter,
- const MCSubtargetInfo &STI, bool RelaxAll,
- bool IncrementalLinkerCompatible,
- bool DWARFMustBeAtTheEnd) const {
- MCStreamer *S = nullptr;
- switch (T.getObjectFormat()) {
- case Triple::UnknownObjectFormat:
- llvm_unreachable("Unknown object format");
- case Triple::COFF:
- assert(T.isOSWindows() && "only Windows COFF is supported");
- S = COFFStreamerCtorFn(Ctx, std::move(TAB), std::move(OW),
- std::move(Emitter), RelaxAll,
- IncrementalLinkerCompatible);
- break;
- case Triple::MachO:
- if (MachOStreamerCtorFn)
- S = MachOStreamerCtorFn(Ctx, std::move(TAB), std::move(OW),
- std::move(Emitter), RelaxAll,
- DWARFMustBeAtTheEnd);
- else
- S = createMachOStreamer(Ctx, std::move(TAB), std::move(OW),
- std::move(Emitter), RelaxAll,
- DWARFMustBeAtTheEnd);
- break;
- case Triple::ELF:
- if (ELFStreamerCtorFn)
- S = ELFStreamerCtorFn(T, Ctx, std::move(TAB), std::move(OW),
- std::move(Emitter), RelaxAll);
- else
- S = createELFStreamer(Ctx, std::move(TAB), std::move(OW),
- std::move(Emitter), RelaxAll);
- break;
- case Triple::Wasm:
- if (WasmStreamerCtorFn)
- S = WasmStreamerCtorFn(T, Ctx, std::move(TAB), std::move(OW),
- std::move(Emitter), RelaxAll);
- else
- S = createWasmStreamer(Ctx, std::move(TAB), std::move(OW),
- std::move(Emitter), RelaxAll);
- break;
- case Triple::GOFF:
- report_fatal_error("GOFF MCObjectStreamer not implemented yet");
- case Triple::XCOFF:
- if (XCOFFStreamerCtorFn)
- S = XCOFFStreamerCtorFn(T, Ctx, std::move(TAB), std::move(OW),
- std::move(Emitter), RelaxAll);
- else
- S = createXCOFFStreamer(Ctx, std::move(TAB), std::move(OW),
- std::move(Emitter), RelaxAll);
- break;
- case Triple::SPIRV:
- if (SPIRVStreamerCtorFn)
- S = SPIRVStreamerCtorFn(T, Ctx, std::move(TAB), std::move(OW),
- std::move(Emitter), RelaxAll);
- else
- S = createSPIRVStreamer(Ctx, std::move(TAB), std::move(OW),
- std::move(Emitter), RelaxAll);
- break;
- case Triple::DXContainer:
- if (DXContainerStreamerCtorFn)
- S = DXContainerStreamerCtorFn(T, Ctx, std::move(TAB), std::move(OW),
- std::move(Emitter), RelaxAll);
- else
- S = createDXContainerStreamer(Ctx, std::move(TAB), std::move(OW),
- std::move(Emitter), RelaxAll);
- break;
- }
- if (ObjectTargetStreamerCtorFn)
- ObjectTargetStreamerCtorFn(*S, STI);
- return S;
- }
- MCStreamer *createAsmStreamer(MCContext &Ctx,
- std::unique_ptr<formatted_raw_ostream> OS,
- bool IsVerboseAsm, bool UseDwarfDirectory,
- MCInstPrinter *InstPrint,
- std::unique_ptr<MCCodeEmitter> &&CE,
- std::unique_ptr<MCAsmBackend> &&TAB,
- bool ShowInst) const {
- formatted_raw_ostream &OSRef = *OS;
- MCStreamer *S = llvm::createAsmStreamer(
- Ctx, std::move(OS), IsVerboseAsm, UseDwarfDirectory, InstPrint,
- std::move(CE), std::move(TAB), ShowInst);
- createAsmTargetStreamer(*S, OSRef, InstPrint, IsVerboseAsm);
- return S;
- }
- MCTargetStreamer *createAsmTargetStreamer(MCStreamer &S,
- formatted_raw_ostream &OS,
- MCInstPrinter *InstPrint,
- bool IsVerboseAsm) const {
- if (AsmTargetStreamerCtorFn)
- return AsmTargetStreamerCtorFn(S, OS, InstPrint, IsVerboseAsm);
- return nullptr;
- }
- MCStreamer *createNullStreamer(MCContext &Ctx) const {
- MCStreamer *S = llvm::createNullStreamer(Ctx);
- createNullTargetStreamer(*S);
- return S;
- }
- MCTargetStreamer *createNullTargetStreamer(MCStreamer &S) const {
- if (NullTargetStreamerCtorFn)
- return NullTargetStreamerCtorFn(S);
- return nullptr;
- }
- /// createMCRelocationInfo - Create a target specific MCRelocationInfo.
- ///
- /// \param TT The target triple.
- /// \param Ctx The target context.
- MCRelocationInfo *createMCRelocationInfo(StringRef TT, MCContext &Ctx) const {
- MCRelocationInfoCtorTy Fn = MCRelocationInfoCtorFn
- ? MCRelocationInfoCtorFn
- : llvm::createMCRelocationInfo;
- return Fn(Triple(TT), Ctx);
- }
- /// createMCSymbolizer - Create a target specific MCSymbolizer.
- ///
- /// \param TT The target triple.
- /// \param GetOpInfo The function to get the symbolic information for
- /// operands.
- /// \param SymbolLookUp The function to lookup a symbol name.
- /// \param DisInfo The pointer to the block of symbolic information for above
- /// call
- /// back.
- /// \param Ctx The target context.
- /// \param RelInfo The relocation information for this target. Takes
- /// ownership.
- MCSymbolizer *
- createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
- LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo,
- MCContext *Ctx,
- std::unique_ptr<MCRelocationInfo> &&RelInfo) const {
- MCSymbolizerCtorTy Fn =
- MCSymbolizerCtorFn ? MCSymbolizerCtorFn : llvm::createMCSymbolizer;
- return Fn(Triple(TT), GetOpInfo, SymbolLookUp, DisInfo, Ctx,
- std::move(RelInfo));
- }
- /// createCustomBehaviour - Create a target specific CustomBehaviour.
- /// This class is used by llvm-mca and requires backend functionality.
- mca::CustomBehaviour *createCustomBehaviour(const MCSubtargetInfo &STI,
- const mca::SourceMgr &SrcMgr,
- const MCInstrInfo &MCII) const {
- if (CustomBehaviourCtorFn)
- return CustomBehaviourCtorFn(STI, SrcMgr, MCII);
- return nullptr;
- }
- /// createInstrPostProcess - Create a target specific InstrPostProcess.
- /// This class is used by llvm-mca and requires backend functionality.
- mca::InstrPostProcess *createInstrPostProcess(const MCSubtargetInfo &STI,
- const MCInstrInfo &MCII) const {
- if (InstrPostProcessCtorFn)
- return InstrPostProcessCtorFn(STI, MCII);
- return nullptr;
- }
- /// createInstrumentManager - Create a target specific
- /// InstrumentManager. This class is used by llvm-mca and requires
- /// backend functionality.
- mca::InstrumentManager *
- createInstrumentManager(const MCSubtargetInfo &STI,
- const MCInstrInfo &MCII) const {
- if (InstrumentManagerCtorFn)
- return InstrumentManagerCtorFn(STI, MCII);
- return nullptr;
- }
- /// @}
- };
- /// TargetRegistry - Generic interface to target specific features.
- struct TargetRegistry {
- // FIXME: Make this a namespace, probably just move all the Register*
- // functions into Target (currently they all just set members on the Target
- // anyway, and Target friends this class so those functions can...
- // function).
- TargetRegistry() = delete;
- class iterator {
- friend struct TargetRegistry;
- const Target *Current = nullptr;
- explicit iterator(Target *T) : Current(T) {}
- public:
- using iterator_category = std::forward_iterator_tag;
- using value_type = Target;
- using difference_type = std::ptrdiff_t;
- using pointer = value_type *;
- using reference = value_type &;
- iterator() = default;
- bool operator==(const iterator &x) const { return Current == x.Current; }
- bool operator!=(const iterator &x) const { return !operator==(x); }
- // Iterator traversal: forward iteration only
- iterator &operator++() { // Preincrement
- assert(Current && "Cannot increment end iterator!");
- Current = Current->getNext();
- return *this;
- }
- iterator operator++(int) { // Postincrement
- iterator tmp = *this;
- ++*this;
- return tmp;
- }
- const Target &operator*() const {
- assert(Current && "Cannot dereference end iterator!");
- return *Current;
- }
- const Target *operator->() const { return &operator*(); }
- };
- /// printRegisteredTargetsForVersion - Print the registered targets
- /// appropriately for inclusion in a tool's version output.
- static void printRegisteredTargetsForVersion(raw_ostream &OS);
- /// @name Registry Access
- /// @{
- static iterator_range<iterator> targets();
- /// lookupTarget - Lookup a target based on a target triple.
- ///
- /// \param Triple - The triple to use for finding a target.
- /// \param Error - On failure, an error string describing why no target was
- /// found.
- static const Target *lookupTarget(const std::string &Triple,
- std::string &Error);
- /// lookupTarget - Lookup a target based on an architecture name
- /// and a target triple. If the architecture name is non-empty,
- /// then the lookup is done by architecture. Otherwise, the target
- /// triple is used.
- ///
- /// \param ArchName - The architecture to use for finding a target.
- /// \param TheTriple - The triple to use for finding a target. The
- /// triple is updated with canonical architecture name if a lookup
- /// by architecture is done.
- /// \param Error - On failure, an error string describing why no target was
- /// found.
- static const Target *lookupTarget(const std::string &ArchName,
- Triple &TheTriple, std::string &Error);
- /// @}
- /// @name Target Registration
- /// @{
- /// RegisterTarget - Register the given target. Attempts to register a
- /// target which has already been registered will be ignored.
- ///
- /// Clients are responsible for ensuring that registration doesn't occur
- /// while another thread is attempting to access the registry. Typically
- /// this is done by initializing all targets at program startup.
- ///
- /// @param T - The target being registered.
- /// @param Name - The target name. This should be a static string.
- /// @param ShortDesc - A short target description. This should be a static
- /// string.
- /// @param BackendName - The name of the backend. This should be a static
- /// string that is the same for all targets that share a backend
- /// implementation and must match the name used in the 'def X : Target ...' in
- /// TableGen.
- /// @param ArchMatchFn - The arch match checking function for this target.
- /// @param HasJIT - Whether the target supports JIT code
- /// generation.
- static void RegisterTarget(Target &T, const char *Name, const char *ShortDesc,
- const char *BackendName,
- Target::ArchMatchFnTy ArchMatchFn,
- bool HasJIT = false);
- /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
- /// given target.
- ///
- /// Clients are responsible for ensuring that registration doesn't occur
- /// while another thread is attempting to access the registry. Typically
- /// this is done by initializing all targets at program startup.
- ///
- /// @param T - The target being registered.
- /// @param Fn - A function to construct a MCAsmInfo for the target.
- static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
- T.MCAsmInfoCtorFn = Fn;
- }
- /// Register a MCObjectFileInfo implementation for the given target.
- ///
- /// Clients are responsible for ensuring that registration doesn't occur
- /// while another thread is attempting to access the registry. Typically
- /// this is done by initializing all targets at program startup.
- ///
- /// @param T - The target being registered.
- /// @param Fn - A function to construct a MCObjectFileInfo for the target.
- static void RegisterMCObjectFileInfo(Target &T,
- Target::MCObjectFileInfoCtorFnTy Fn) {
- T.MCObjectFileInfoCtorFn = Fn;
- }
- /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
- /// given target.
- ///
- /// Clients are responsible for ensuring that registration doesn't occur
- /// while another thread is attempting to access the registry. Typically
- /// this is done by initializing all targets at program startup.
- ///
- /// @param T - The target being registered.
- /// @param Fn - A function to construct a MCInstrInfo for the target.
- static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
- T.MCInstrInfoCtorFn = Fn;
- }
- /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
- /// the given target.
- static void RegisterMCInstrAnalysis(Target &T,
- Target::MCInstrAnalysisCtorFnTy Fn) {
- T.MCInstrAnalysisCtorFn = Fn;
- }
- /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
- /// given target.
- ///
- /// Clients are responsible for ensuring that registration doesn't occur
- /// while another thread is attempting to access the registry. Typically
- /// this is done by initializing all targets at program startup.
- ///
- /// @param T - The target being registered.
- /// @param Fn - A function to construct a MCRegisterInfo for the target.
- static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
- T.MCRegInfoCtorFn = Fn;
- }
- /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
- /// the given target.
- ///
- /// Clients are responsible for ensuring that registration doesn't occur
- /// while another thread is attempting to access the registry. Typically
- /// this is done by initializing all targets at program startup.
- ///
- /// @param T - The target being registered.
- /// @param Fn - A function to construct a MCSubtargetInfo for the target.
- static void RegisterMCSubtargetInfo(Target &T,
- Target::MCSubtargetInfoCtorFnTy Fn) {
- T.MCSubtargetInfoCtorFn = Fn;
- }
- /// RegisterTargetMachine - Register a TargetMachine implementation for the
- /// given target.
- ///
- /// Clients are responsible for ensuring that registration doesn't occur
- /// while another thread is attempting to access the registry. Typically
- /// this is done by initializing all targets at program startup.
- ///
- /// @param T - The target being registered.
- /// @param Fn - A function to construct a TargetMachine for the target.
- static void RegisterTargetMachine(Target &T, Target::TargetMachineCtorTy Fn) {
- T.TargetMachineCtorFn = Fn;
- }
- /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
- /// given target.
- ///
- /// Clients are responsible for ensuring that registration doesn't occur
- /// while another thread is attempting to access the registry. Typically
- /// this is done by initializing all targets at program startup.
- ///
- /// @param T - The target being registered.
- /// @param Fn - A function to construct an AsmBackend for the target.
- static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
- T.MCAsmBackendCtorFn = Fn;
- }
- /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
- /// the given target.
- ///
- /// Clients are responsible for ensuring that registration doesn't occur
- /// while another thread is attempting to access the registry. Typically
- /// this is done by initializing all targets at program startup.
- ///
- /// @param T - The target being registered.
- /// @param Fn - A function to construct an MCTargetAsmParser for the target.
- static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
- T.MCAsmParserCtorFn = Fn;
- }
- /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
- /// target.
- ///
- /// Clients are responsible for ensuring that registration doesn't occur
- /// while another thread is attempting to access the registry. Typically
- /// this is done by initializing all targets at program startup.
- ///
- /// @param T - The target being registered.
- /// @param Fn - A function to construct an AsmPrinter for the target.
- static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
- T.AsmPrinterCtorFn = Fn;
- }
- /// RegisterMCDisassembler - Register a MCDisassembler implementation for
- /// the given target.
- ///
- /// Clients are responsible for ensuring that registration doesn't occur
- /// while another thread is attempting to access the registry. Typically
- /// this is done by initializing all targets at program startup.
- ///
- /// @param T - The target being registered.
- /// @param Fn - A function to construct an MCDisassembler for the target.
- static void RegisterMCDisassembler(Target &T,
- Target::MCDisassemblerCtorTy Fn) {
- T.MCDisassemblerCtorFn = Fn;
- }
- /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
- /// given target.
- ///
- /// Clients are responsible for ensuring that registration doesn't occur
- /// while another thread is attempting to access the registry. Typically
- /// this is done by initializing all targets at program startup.
- ///
- /// @param T - The target being registered.
- /// @param Fn - A function to construct an MCInstPrinter for the target.
- static void RegisterMCInstPrinter(Target &T, Target::MCInstPrinterCtorTy Fn) {
- T.MCInstPrinterCtorFn = Fn;
- }
- /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
- /// given target.
- ///
- /// Clients are responsible for ensuring that registration doesn't occur
- /// while another thread is attempting to access the registry. Typically
- /// this is done by initializing all targets at program startup.
- ///
- /// @param T - The target being registered.
- /// @param Fn - A function to construct an MCCodeEmitter for the target.
- static void RegisterMCCodeEmitter(Target &T, Target::MCCodeEmitterCtorTy Fn) {
- T.MCCodeEmitterCtorFn = Fn;
- }
- static void RegisterCOFFStreamer(Target &T, Target::COFFStreamerCtorTy Fn) {
- T.COFFStreamerCtorFn = Fn;
- }
- static void RegisterMachOStreamer(Target &T, Target::MachOStreamerCtorTy Fn) {
- T.MachOStreamerCtorFn = Fn;
- }
- static void RegisterELFStreamer(Target &T, Target::ELFStreamerCtorTy Fn) {
- T.ELFStreamerCtorFn = Fn;
- }
- static void RegisterSPIRVStreamer(Target &T, Target::SPIRVStreamerCtorTy Fn) {
- T.SPIRVStreamerCtorFn = Fn;
- }
- static void RegisterDXContainerStreamer(Target &T, Target::DXContainerStreamerCtorTy Fn) {
- T.DXContainerStreamerCtorFn = Fn;
- }
- static void RegisterWasmStreamer(Target &T, Target::WasmStreamerCtorTy Fn) {
- T.WasmStreamerCtorFn = Fn;
- }
- static void RegisterXCOFFStreamer(Target &T, Target::XCOFFStreamerCtorTy Fn) {
- T.XCOFFStreamerCtorFn = Fn;
- }
- static void RegisterNullTargetStreamer(Target &T,
- Target::NullTargetStreamerCtorTy Fn) {
- T.NullTargetStreamerCtorFn = Fn;
- }
- static void RegisterAsmTargetStreamer(Target &T,
- Target::AsmTargetStreamerCtorTy Fn) {
- T.AsmTargetStreamerCtorFn = Fn;
- }
- static void
- RegisterObjectTargetStreamer(Target &T,
- Target::ObjectTargetStreamerCtorTy Fn) {
- T.ObjectTargetStreamerCtorFn = Fn;
- }
- /// RegisterMCRelocationInfo - Register an MCRelocationInfo
- /// implementation for the given target.
- ///
- /// Clients are responsible for ensuring that registration doesn't occur
- /// while another thread is attempting to access the registry. Typically
- /// this is done by initializing all targets at program startup.
- ///
- /// @param T - The target being registered.
- /// @param Fn - A function to construct an MCRelocationInfo for the target.
- static void RegisterMCRelocationInfo(Target &T,
- Target::MCRelocationInfoCtorTy Fn) {
- T.MCRelocationInfoCtorFn = Fn;
- }
- /// RegisterMCSymbolizer - Register an MCSymbolizer
- /// implementation for the given target.
- ///
- /// Clients are responsible for ensuring that registration doesn't occur
- /// while another thread is attempting to access the registry. Typically
- /// this is done by initializing all targets at program startup.
- ///
- /// @param T - The target being registered.
- /// @param Fn - A function to construct an MCSymbolizer for the target.
- static void RegisterMCSymbolizer(Target &T, Target::MCSymbolizerCtorTy Fn) {
- T.MCSymbolizerCtorFn = Fn;
- }
- /// RegisterCustomBehaviour - Register a CustomBehaviour
- /// implementation for the given target.
- ///
- /// Clients are responsible for ensuring that registration doesn't occur
- /// while another thread is attempting to access the registry. Typically
- /// this is done by initializing all targets at program startup.
- ///
- /// @param T - The target being registered.
- /// @param Fn - A function to construct a CustomBehaviour for the target.
- static void RegisterCustomBehaviour(Target &T,
- Target::CustomBehaviourCtorTy Fn) {
- T.CustomBehaviourCtorFn = Fn;
- }
- /// RegisterInstrPostProcess - Register an InstrPostProcess
- /// implementation for the given target.
- ///
- /// Clients are responsible for ensuring that registration doesn't occur
- /// while another thread is attempting to access the registry. Typically
- /// this is done by initializing all targets at program startup.
- ///
- /// @param T - The target being registered.
- /// @param Fn - A function to construct an InstrPostProcess for the target.
- static void RegisterInstrPostProcess(Target &T,
- Target::InstrPostProcessCtorTy Fn) {
- T.InstrPostProcessCtorFn = Fn;
- }
- /// RegisterInstrumentManager - Register an InstrumentManager
- /// implementation for the given target.
- ///
- /// Clients are responsible for ensuring that registration doesn't occur
- /// while another thread is attempting to access the registry. Typically
- /// this is done by initializing all targets at program startup.
- ///
- /// @param T - The target being registered.
- /// @param Fn - A function to construct an InstrumentManager for the
- /// target.
- static void RegisterInstrumentManager(Target &T,
- Target::InstrumentManagerCtorTy Fn) {
- T.InstrumentManagerCtorFn = Fn;
- }
- /// @}
- };
- //===--------------------------------------------------------------------===//
- /// RegisterTarget - Helper template for registering a target, for use in the
- /// target's initialization function. Usage:
- ///
- ///
- /// Target &getTheFooTarget() { // The global target instance.
- /// static Target TheFooTarget;
- /// return TheFooTarget;
- /// }
- /// extern "C" void LLVMInitializeFooTargetInfo() {
- /// RegisterTarget<Triple::foo> X(getTheFooTarget(), "foo", "Foo
- /// description", "Foo" /* Backend Name */);
- /// }
- template <Triple::ArchType TargetArchType = Triple::UnknownArch,
- bool HasJIT = false>
- struct RegisterTarget {
- RegisterTarget(Target &T, const char *Name, const char *Desc,
- const char *BackendName) {
- TargetRegistry::RegisterTarget(T, Name, Desc, BackendName, &getArchMatch,
- HasJIT);
- }
- static bool getArchMatch(Triple::ArchType Arch) {
- return Arch == TargetArchType;
- }
- };
- /// RegisterMCAsmInfo - Helper template for registering a target assembly info
- /// implementation. This invokes the static "Create" method on the class to
- /// actually do the construction. Usage:
- ///
- /// extern "C" void LLVMInitializeFooTarget() {
- /// extern Target TheFooTarget;
- /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
- /// }
- template <class MCAsmInfoImpl> struct RegisterMCAsmInfo {
- RegisterMCAsmInfo(Target &T) {
- TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
- }
- private:
- static MCAsmInfo *Allocator(const MCRegisterInfo & /*MRI*/, const Triple &TT,
- const MCTargetOptions &Options) {
- return new MCAsmInfoImpl(TT, Options);
- }
- };
- /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
- /// implementation. This invokes the specified function to do the
- /// construction. Usage:
- ///
- /// extern "C" void LLVMInitializeFooTarget() {
- /// extern Target TheFooTarget;
- /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
- /// }
- struct RegisterMCAsmInfoFn {
- RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
- TargetRegistry::RegisterMCAsmInfo(T, Fn);
- }
- };
- /// Helper template for registering a target object file info implementation.
- /// This invokes the static "Create" method on the class to actually do the
- /// construction. Usage:
- ///
- /// extern "C" void LLVMInitializeFooTarget() {
- /// extern Target TheFooTarget;
- /// RegisterMCObjectFileInfo<FooMCObjectFileInfo> X(TheFooTarget);
- /// }
- template <class MCObjectFileInfoImpl> struct RegisterMCObjectFileInfo {
- RegisterMCObjectFileInfo(Target &T) {
- TargetRegistry::RegisterMCObjectFileInfo(T, &Allocator);
- }
- private:
- static MCObjectFileInfo *Allocator(MCContext &Ctx, bool PIC,
- bool LargeCodeModel = false) {
- return new MCObjectFileInfoImpl(Ctx, PIC, LargeCodeModel);
- }
- };
- /// Helper template for registering a target object file info implementation.
- /// This invokes the specified function to do the construction. Usage:
- ///
- /// extern "C" void LLVMInitializeFooTarget() {
- /// extern Target TheFooTarget;
- /// RegisterMCObjectFileInfoFn X(TheFooTarget, TheFunction);
- /// }
- struct RegisterMCObjectFileInfoFn {
- RegisterMCObjectFileInfoFn(Target &T, Target::MCObjectFileInfoCtorFnTy Fn) {
- TargetRegistry::RegisterMCObjectFileInfo(T, Fn);
- }
- };
- /// RegisterMCInstrInfo - Helper template for registering a target instruction
- /// info implementation. This invokes the static "Create" method on the class
- /// to actually do the construction. Usage:
- ///
- /// extern "C" void LLVMInitializeFooTarget() {
- /// extern Target TheFooTarget;
- /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
- /// }
- template <class MCInstrInfoImpl> struct RegisterMCInstrInfo {
- RegisterMCInstrInfo(Target &T) {
- TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
- }
- private:
- static MCInstrInfo *Allocator() { return new MCInstrInfoImpl(); }
- };
- /// RegisterMCInstrInfoFn - Helper template for registering a target
- /// instruction info implementation. This invokes the specified function to
- /// do the construction. Usage:
- ///
- /// extern "C" void LLVMInitializeFooTarget() {
- /// extern Target TheFooTarget;
- /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
- /// }
- struct RegisterMCInstrInfoFn {
- RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
- TargetRegistry::RegisterMCInstrInfo(T, Fn);
- }
- };
- /// RegisterMCInstrAnalysis - Helper template for registering a target
- /// instruction analyzer implementation. This invokes the static "Create"
- /// method on the class to actually do the construction. Usage:
- ///
- /// extern "C" void LLVMInitializeFooTarget() {
- /// extern Target TheFooTarget;
- /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
- /// }
- template <class MCInstrAnalysisImpl> struct RegisterMCInstrAnalysis {
- RegisterMCInstrAnalysis(Target &T) {
- TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
- }
- private:
- static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
- return new MCInstrAnalysisImpl(Info);
- }
- };
- /// RegisterMCInstrAnalysisFn - Helper template for registering a target
- /// instruction analyzer implementation. This invokes the specified function
- /// to do the construction. Usage:
- ///
- /// extern "C" void LLVMInitializeFooTarget() {
- /// extern Target TheFooTarget;
- /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
- /// }
- struct RegisterMCInstrAnalysisFn {
- RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
- TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
- }
- };
- /// RegisterMCRegInfo - Helper template for registering a target register info
- /// implementation. This invokes the static "Create" method on the class to
- /// actually do the construction. Usage:
- ///
- /// extern "C" void LLVMInitializeFooTarget() {
- /// extern Target TheFooTarget;
- /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
- /// }
- template <class MCRegisterInfoImpl> struct RegisterMCRegInfo {
- RegisterMCRegInfo(Target &T) {
- TargetRegistry::RegisterMCRegInfo(T, &Allocator);
- }
- private:
- static MCRegisterInfo *Allocator(const Triple & /*TT*/) {
- return new MCRegisterInfoImpl();
- }
- };
- /// RegisterMCRegInfoFn - Helper template for registering a target register
- /// info implementation. This invokes the specified function to do the
- /// construction. Usage:
- ///
- /// extern "C" void LLVMInitializeFooTarget() {
- /// extern Target TheFooTarget;
- /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
- /// }
- struct RegisterMCRegInfoFn {
- RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
- TargetRegistry::RegisterMCRegInfo(T, Fn);
- }
- };
- /// RegisterMCSubtargetInfo - Helper template for registering a target
- /// subtarget info implementation. This invokes the static "Create" method
- /// on the class to actually do the construction. Usage:
- ///
- /// extern "C" void LLVMInitializeFooTarget() {
- /// extern Target TheFooTarget;
- /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
- /// }
- template <class MCSubtargetInfoImpl> struct RegisterMCSubtargetInfo {
- RegisterMCSubtargetInfo(Target &T) {
- TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
- }
- private:
- static MCSubtargetInfo *Allocator(const Triple & /*TT*/, StringRef /*CPU*/,
- StringRef /*FS*/) {
- return new MCSubtargetInfoImpl();
- }
- };
- /// RegisterMCSubtargetInfoFn - Helper template for registering a target
- /// subtarget info implementation. This invokes the specified function to
- /// do the construction. Usage:
- ///
- /// extern "C" void LLVMInitializeFooTarget() {
- /// extern Target TheFooTarget;
- /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
- /// }
- struct RegisterMCSubtargetInfoFn {
- RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
- TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
- }
- };
- /// RegisterTargetMachine - Helper template for registering a target machine
- /// implementation, for use in the target machine initialization
- /// function. Usage:
- ///
- /// extern "C" void LLVMInitializeFooTarget() {
- /// extern Target TheFooTarget;
- /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
- /// }
- template <class TargetMachineImpl> struct RegisterTargetMachine {
- RegisterTargetMachine(Target &T) {
- TargetRegistry::RegisterTargetMachine(T, &Allocator);
- }
- private:
- static TargetMachine *Allocator(const Target &T, const Triple &TT,
- StringRef CPU, StringRef FS,
- const TargetOptions &Options,
- std::optional<Reloc::Model> RM,
- std::optional<CodeModel::Model> CM,
- CodeGenOpt::Level OL, bool JIT) {
- return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL, JIT);
- }
- };
- /// RegisterMCAsmBackend - Helper template for registering a target specific
- /// assembler backend. Usage:
- ///
- /// extern "C" void LLVMInitializeFooMCAsmBackend() {
- /// extern Target TheFooTarget;
- /// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
- /// }
- template <class MCAsmBackendImpl> struct RegisterMCAsmBackend {
- RegisterMCAsmBackend(Target &T) {
- TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
- }
- private:
- static MCAsmBackend *Allocator(const Target &T, const MCSubtargetInfo &STI,
- const MCRegisterInfo &MRI,
- const MCTargetOptions &Options) {
- return new MCAsmBackendImpl(T, STI, MRI);
- }
- };
- /// RegisterMCAsmParser - Helper template for registering a target specific
- /// assembly parser, for use in the target machine initialization
- /// function. Usage:
- ///
- /// extern "C" void LLVMInitializeFooMCAsmParser() {
- /// extern Target TheFooTarget;
- /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
- /// }
- template <class MCAsmParserImpl> struct RegisterMCAsmParser {
- RegisterMCAsmParser(Target &T) {
- TargetRegistry::RegisterMCAsmParser(T, &Allocator);
- }
- private:
- static MCTargetAsmParser *Allocator(const MCSubtargetInfo &STI,
- MCAsmParser &P, const MCInstrInfo &MII,
- const MCTargetOptions &Options) {
- return new MCAsmParserImpl(STI, P, MII, Options);
- }
- };
- /// RegisterAsmPrinter - Helper template for registering a target specific
- /// assembly printer, for use in the target machine initialization
- /// function. Usage:
- ///
- /// extern "C" void LLVMInitializeFooAsmPrinter() {
- /// extern Target TheFooTarget;
- /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
- /// }
- template <class AsmPrinterImpl> struct RegisterAsmPrinter {
- RegisterAsmPrinter(Target &T) {
- TargetRegistry::RegisterAsmPrinter(T, &Allocator);
- }
- private:
- static AsmPrinter *Allocator(TargetMachine &TM,
- std::unique_ptr<MCStreamer> &&Streamer) {
- return new AsmPrinterImpl(TM, std::move(Streamer));
- }
- };
- /// RegisterMCCodeEmitter - Helper template for registering a target specific
- /// machine code emitter, for use in the target initialization
- /// function. Usage:
- ///
- /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
- /// extern Target TheFooTarget;
- /// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
- /// }
- template <class MCCodeEmitterImpl> struct RegisterMCCodeEmitter {
- RegisterMCCodeEmitter(Target &T) {
- TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
- }
- private:
- static MCCodeEmitter *Allocator(const MCInstrInfo & /*II*/,
- MCContext & /*Ctx*/) {
- return new MCCodeEmitterImpl();
- }
- };
- } // end namespace llvm
- #endif // LLVM_MC_TARGETREGISTRY_H
- #ifdef __GNUC__
- #pragma GCC diagnostic pop
- #endif
|