1 //===-- Support/TargetRegistry.h - Target Registration ----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file exposes the TargetRegistry interface, which tools can use to access
11 // the appropriate target specific classes (TargetMachine, AsmPrinter, etc.)
12 // which have been registered.
14 // Target specific class implementations should register themselves using the
15 // appropriate TargetRegistry interfaces.
17 //===----------------------------------------------------------------------===//
19 #ifndef LLVM_SUPPORT_TARGETREGISTRY_H
20 #define LLVM_SUPPORT_TARGETREGISTRY_H
22 #include "llvm-c/Disassembler.h"
23 #include "llvm/ADT/Optional.h"
24 #include "llvm/ADT/Triple.h"
25 #include "llvm/Support/CodeGen.h"
26 #include "llvm/Support/FormattedStream.h"
39 class MCInstrAnalysis;
44 class MCSubtargetInfo;
46 class MCRelocationInfo;
47 class MCTargetAsmParser;
48 class MCTargetOptions;
49 class MCTargetStreamer;
53 class raw_pwrite_stream;
54 class formatted_raw_ostream;
56 MCStreamer *createNullStreamer(MCContext &Ctx);
57 MCStreamer *createAsmStreamer(MCContext &Ctx,
58 std::unique_ptr<formatted_raw_ostream> OS,
59 bool isVerboseAsm, bool useDwarfDirectory,
60 MCInstPrinter *InstPrint, MCCodeEmitter *CE,
61 MCAsmBackend *TAB, bool ShowInst);
63 /// Takes ownership of \p TAB and \p CE.
64 MCStreamer *createELFStreamer(MCContext &Ctx, MCAsmBackend &TAB,
65 raw_pwrite_stream &OS, MCCodeEmitter *CE,
67 MCStreamer *createMachOStreamer(MCContext &Ctx, MCAsmBackend &TAB,
68 raw_pwrite_stream &OS, MCCodeEmitter *CE,
69 bool RelaxAll, bool DWARFMustBeAtTheEnd,
70 bool LabelSections = false);
72 MCRelocationInfo *createMCRelocationInfo(const Triple &TT, MCContext &Ctx);
74 MCSymbolizer *createMCSymbolizer(const Triple &TT, LLVMOpInfoCallback GetOpInfo,
75 LLVMSymbolLookupCallback SymbolLookUp,
76 void *DisInfo, MCContext *Ctx,
77 std::unique_ptr<MCRelocationInfo> &&RelInfo);
79 /// Target - Wrapper for Target specific information.
81 /// For registration purposes, this is a POD type so that targets can be
82 /// registered without the use of static constructors.
84 /// Targets should implement a single global instance of this class (which
85 /// will be zero initialized), and pass that instance to the TargetRegistry as
86 /// part of their initialization.
89 friend struct TargetRegistry;
91 typedef bool (*ArchMatchFnTy)(Triple::ArchType Arch);
93 typedef MCAsmInfo *(*MCAsmInfoCtorFnTy)(const MCRegisterInfo &MRI,
95 typedef void (*MCAdjustCodeGenOptsFnTy)(const Triple &TT, Reloc::Model RM,
96 CodeModel::Model &CM);
98 typedef MCInstrInfo *(*MCInstrInfoCtorFnTy)(void);
99 typedef MCInstrAnalysis *(*MCInstrAnalysisCtorFnTy)(const MCInstrInfo *Info);
100 typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(const Triple &TT);
101 typedef MCSubtargetInfo *(*MCSubtargetInfoCtorFnTy)(const Triple &TT,
104 typedef TargetMachine *(*TargetMachineCtorTy)(
105 const Target &T, const Triple &TT, StringRef CPU, StringRef Features,
106 const TargetOptions &Options, Optional<Reloc::Model> RM,
107 CodeModel::Model CM, CodeGenOpt::Level OL);
108 // If it weren't for layering issues (this header is in llvm/Support, but
109 // depends on MC?) this should take the Streamer by value rather than rvalue
111 typedef AsmPrinter *(*AsmPrinterCtorTy)(
112 TargetMachine &TM, std::unique_ptr<MCStreamer> &&Streamer);
113 typedef MCAsmBackend *(*MCAsmBackendCtorTy)(const Target &T,
114 const MCRegisterInfo &MRI,
115 const Triple &TT, StringRef CPU);
116 typedef MCTargetAsmParser *(*MCAsmParserCtorTy)(
117 const MCSubtargetInfo &STI, MCAsmParser &P, const MCInstrInfo &MII,
118 const MCTargetOptions &Options);
119 typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T,
120 const MCSubtargetInfo &STI,
122 typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Triple &T,
123 unsigned SyntaxVariant,
124 const MCAsmInfo &MAI,
125 const MCInstrInfo &MII,
126 const MCRegisterInfo &MRI);
127 typedef MCCodeEmitter *(*MCCodeEmitterCtorTy)(const MCInstrInfo &II,
128 const MCRegisterInfo &MRI,
130 typedef MCStreamer *(*ELFStreamerCtorTy)(const Triple &T, MCContext &Ctx,
132 raw_pwrite_stream &OS,
133 MCCodeEmitter *Emitter,
135 typedef MCStreamer *(*MachOStreamerCtorTy)(MCContext &Ctx, MCAsmBackend &TAB,
136 raw_pwrite_stream &OS,
137 MCCodeEmitter *Emitter,
139 bool DWARFMustBeAtTheEnd);
140 typedef MCStreamer *(*COFFStreamerCtorTy)(MCContext &Ctx, MCAsmBackend &TAB,
141 raw_pwrite_stream &OS,
142 MCCodeEmitter *Emitter,
144 bool IncrementalLinkerCompatible);
145 typedef MCTargetStreamer *(*NullTargetStreamerCtorTy)(MCStreamer &S);
146 typedef MCTargetStreamer *(*AsmTargetStreamerCtorTy)(
147 MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *InstPrint,
149 typedef MCTargetStreamer *(*ObjectTargetStreamerCtorTy)(
150 MCStreamer &S, const MCSubtargetInfo &STI);
151 typedef MCRelocationInfo *(*MCRelocationInfoCtorTy)(const Triple &TT,
153 typedef MCSymbolizer *(*MCSymbolizerCtorTy)(
154 const Triple &TT, LLVMOpInfoCallback GetOpInfo,
155 LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo, MCContext *Ctx,
156 std::unique_ptr<MCRelocationInfo> &&RelInfo);
159 /// Next - The next registered target in the linked list, maintained by the
163 /// The target function for checking if an architecture is supported.
164 ArchMatchFnTy ArchMatchFn;
166 /// Name - The target name.
169 /// ShortDesc - A short description of the target.
170 const char *ShortDesc;
172 /// HasJIT - Whether this target supports the JIT.
175 /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
177 MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
179 MCAdjustCodeGenOptsFnTy MCAdjustCodeGenOptsFn;
181 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
183 MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
185 /// MCInstrAnalysisCtorFn - Constructor function for this target's
186 /// MCInstrAnalysis, if registered.
187 MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
189 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
191 MCRegInfoCtorFnTy MCRegInfoCtorFn;
193 /// MCSubtargetInfoCtorFn - Constructor function for this target's
194 /// MCSubtargetInfo, if registered.
195 MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
197 /// TargetMachineCtorFn - Construction function for this target's
198 /// TargetMachine, if registered.
199 TargetMachineCtorTy TargetMachineCtorFn;
201 /// MCAsmBackendCtorFn - Construction function for this target's
202 /// MCAsmBackend, if registered.
203 MCAsmBackendCtorTy MCAsmBackendCtorFn;
205 /// MCAsmParserCtorFn - Construction function for this target's
206 /// MCTargetAsmParser, if registered.
207 MCAsmParserCtorTy MCAsmParserCtorFn;
209 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
211 AsmPrinterCtorTy AsmPrinterCtorFn;
213 /// MCDisassemblerCtorFn - Construction function for this target's
214 /// MCDisassembler, if registered.
215 MCDisassemblerCtorTy MCDisassemblerCtorFn;
217 /// MCInstPrinterCtorFn - Construction function for this target's
218 /// MCInstPrinter, if registered.
219 MCInstPrinterCtorTy MCInstPrinterCtorFn;
221 /// MCCodeEmitterCtorFn - Construction function for this target's
222 /// CodeEmitter, if registered.
223 MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
225 // Construction functions for the various object formats, if registered.
226 COFFStreamerCtorTy COFFStreamerCtorFn;
227 MachOStreamerCtorTy MachOStreamerCtorFn;
228 ELFStreamerCtorTy ELFStreamerCtorFn;
230 /// Construction function for this target's null TargetStreamer, if
231 /// registered (default = nullptr).
232 NullTargetStreamerCtorTy NullTargetStreamerCtorFn;
234 /// Construction function for this target's asm TargetStreamer, if
235 /// registered (default = nullptr).
236 AsmTargetStreamerCtorTy AsmTargetStreamerCtorFn;
238 /// Construction function for this target's obj TargetStreamer, if
239 /// registered (default = nullptr).
240 ObjectTargetStreamerCtorTy ObjectTargetStreamerCtorFn;
242 /// MCRelocationInfoCtorFn - Construction function for this target's
243 /// MCRelocationInfo, if registered (default = llvm::createMCRelocationInfo)
244 MCRelocationInfoCtorTy MCRelocationInfoCtorFn;
246 /// MCSymbolizerCtorFn - Construction function for this target's
247 /// MCSymbolizer, if registered (default = llvm::createMCSymbolizer)
248 MCSymbolizerCtorTy MCSymbolizerCtorFn;
252 : COFFStreamerCtorFn(nullptr), MachOStreamerCtorFn(nullptr),
253 ELFStreamerCtorFn(nullptr), NullTargetStreamerCtorFn(nullptr),
254 AsmTargetStreamerCtorFn(nullptr), ObjectTargetStreamerCtorFn(nullptr),
255 MCRelocationInfoCtorFn(nullptr), MCSymbolizerCtorFn(nullptr) {}
257 /// @name Target Information
260 // getNext - Return the next registered target.
261 const Target *getNext() const { return Next; }
263 /// getName - Get the target name.
264 const char *getName() const { return Name; }
266 /// getShortDescription - Get a short description of the target.
267 const char *getShortDescription() const { return ShortDesc; }
270 /// @name Feature Predicates
273 /// hasJIT - Check if this targets supports the just-in-time compilation.
274 bool hasJIT() const { return HasJIT; }
276 /// hasTargetMachine - Check if this target supports code generation.
277 bool hasTargetMachine() const { return TargetMachineCtorFn != nullptr; }
279 /// hasMCAsmBackend - Check if this target supports .o generation.
280 bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != nullptr; }
283 /// @name Feature Constructors
286 /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
289 /// \param TheTriple This argument is used to determine the target machine
290 /// feature set; it should always be provided. Generally this should be
291 /// either the target triple from the module, or the target triple of the
292 /// host if that does not exist.
293 MCAsmInfo *createMCAsmInfo(const MCRegisterInfo &MRI,
294 StringRef TheTriple) const {
295 if (!MCAsmInfoCtorFn)
297 return MCAsmInfoCtorFn(MRI, Triple(TheTriple));
300 void adjustCodeGenOpts(const Triple &TT, Reloc::Model RM,
301 CodeModel::Model &CM) const {
302 if (MCAdjustCodeGenOptsFn)
303 MCAdjustCodeGenOptsFn(TT, RM, CM);
306 /// createMCInstrInfo - Create a MCInstrInfo implementation.
308 MCInstrInfo *createMCInstrInfo() const {
309 if (!MCInstrInfoCtorFn)
311 return MCInstrInfoCtorFn();
314 /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
316 MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
317 if (!MCInstrAnalysisCtorFn)
319 return MCInstrAnalysisCtorFn(Info);
322 /// createMCRegInfo - Create a MCRegisterInfo implementation.
324 MCRegisterInfo *createMCRegInfo(StringRef TT) const {
325 if (!MCRegInfoCtorFn)
327 return MCRegInfoCtorFn(Triple(TT));
330 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
332 /// \param TheTriple This argument is used to determine the target machine
333 /// feature set; it should always be provided. Generally this should be
334 /// either the target triple from the module, or the target triple of the
335 /// host if that does not exist.
336 /// \param CPU This specifies the name of the target CPU.
337 /// \param Features This specifies the string representation of the
338 /// additional target features.
339 MCSubtargetInfo *createMCSubtargetInfo(StringRef TheTriple, StringRef CPU,
340 StringRef Features) const {
341 if (!MCSubtargetInfoCtorFn)
343 return MCSubtargetInfoCtorFn(Triple(TheTriple), CPU, Features);
346 /// createTargetMachine - Create a target specific machine implementation
347 /// for the specified \p Triple.
349 /// \param TT This argument is used to determine the target machine
350 /// feature set; it should always be provided. Generally this should be
351 /// either the target triple from the module, or the target triple of the
352 /// host if that does not exist.
354 createTargetMachine(StringRef TT, StringRef CPU, StringRef Features,
355 const TargetOptions &Options, Optional<Reloc::Model> RM,
356 CodeModel::Model CM = CodeModel::Default,
357 CodeGenOpt::Level OL = CodeGenOpt::Default) const {
358 if (!TargetMachineCtorFn)
360 return TargetMachineCtorFn(*this, Triple(TT), CPU, Features, Options, RM,
364 /// createMCAsmBackend - Create a target specific assembly parser.
366 /// \param TheTriple The target triple string.
367 MCAsmBackend *createMCAsmBackend(const MCRegisterInfo &MRI,
368 StringRef TheTriple, StringRef CPU) const {
369 if (!MCAsmBackendCtorFn)
371 return MCAsmBackendCtorFn(*this, MRI, Triple(TheTriple), CPU);
374 /// createMCAsmParser - Create a target specific assembly parser.
376 /// \param Parser The target independent parser implementation to use for
377 /// parsing and lexing.
378 MCTargetAsmParser *createMCAsmParser(const MCSubtargetInfo &STI,
380 const MCInstrInfo &MII,
381 const MCTargetOptions &Options) const {
382 if (!MCAsmParserCtorFn)
384 return MCAsmParserCtorFn(STI, Parser, MII, Options);
387 /// createAsmPrinter - Create a target specific assembly printer pass. This
388 /// takes ownership of the MCStreamer object.
389 AsmPrinter *createAsmPrinter(TargetMachine &TM,
390 std::unique_ptr<MCStreamer> &&Streamer) const {
391 if (!AsmPrinterCtorFn)
393 return AsmPrinterCtorFn(TM, std::move(Streamer));
396 MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI,
397 MCContext &Ctx) const {
398 if (!MCDisassemblerCtorFn)
400 return MCDisassemblerCtorFn(*this, STI, Ctx);
403 MCInstPrinter *createMCInstPrinter(const Triple &T, unsigned SyntaxVariant,
404 const MCAsmInfo &MAI,
405 const MCInstrInfo &MII,
406 const MCRegisterInfo &MRI) const {
407 if (!MCInstPrinterCtorFn)
409 return MCInstPrinterCtorFn(T, SyntaxVariant, MAI, MII, MRI);
412 /// createMCCodeEmitter - Create a target specific code emitter.
413 MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
414 const MCRegisterInfo &MRI,
415 MCContext &Ctx) const {
416 if (!MCCodeEmitterCtorFn)
418 return MCCodeEmitterCtorFn(II, MRI, Ctx);
421 /// Create a target specific MCStreamer.
423 /// \param T The target triple.
424 /// \param Ctx The target context.
425 /// \param TAB The target assembler backend object. Takes ownership.
426 /// \param OS The stream object.
427 /// \param Emitter The target independent assembler object.Takes ownership.
428 /// \param RelaxAll Relax all fixups?
429 MCStreamer *createMCObjectStreamer(const Triple &T, MCContext &Ctx,
430 MCAsmBackend &TAB, raw_pwrite_stream &OS,
431 MCCodeEmitter *Emitter,
432 const MCSubtargetInfo &STI, bool RelaxAll,
433 bool IncrementalLinkerCompatible,
434 bool DWARFMustBeAtTheEnd) const {
436 switch (T.getObjectFormat()) {
438 llvm_unreachable("Unknown object format");
440 assert(T.isOSWindows() && "only Windows COFF is supported");
441 S = COFFStreamerCtorFn(Ctx, TAB, OS, Emitter, RelaxAll,
442 IncrementalLinkerCompatible);
445 if (MachOStreamerCtorFn)
446 S = MachOStreamerCtorFn(Ctx, TAB, OS, Emitter, RelaxAll,
447 DWARFMustBeAtTheEnd);
449 S = createMachOStreamer(Ctx, TAB, OS, Emitter, RelaxAll,
450 DWARFMustBeAtTheEnd);
453 if (ELFStreamerCtorFn)
454 S = ELFStreamerCtorFn(T, Ctx, TAB, OS, Emitter, RelaxAll);
456 S = createELFStreamer(Ctx, TAB, OS, Emitter, RelaxAll);
459 if (ObjectTargetStreamerCtorFn)
460 ObjectTargetStreamerCtorFn(*S, STI);
464 MCStreamer *createAsmStreamer(MCContext &Ctx,
465 std::unique_ptr<formatted_raw_ostream> OS,
466 bool IsVerboseAsm, bool UseDwarfDirectory,
467 MCInstPrinter *InstPrint, MCCodeEmitter *CE,
468 MCAsmBackend *TAB, bool ShowInst) const {
469 formatted_raw_ostream &OSRef = *OS;
470 MCStreamer *S = llvm::createAsmStreamer(Ctx, std::move(OS), IsVerboseAsm,
471 UseDwarfDirectory, InstPrint, CE,
473 createAsmTargetStreamer(*S, OSRef, InstPrint, IsVerboseAsm);
477 MCTargetStreamer *createAsmTargetStreamer(MCStreamer &S,
478 formatted_raw_ostream &OS,
479 MCInstPrinter *InstPrint,
480 bool IsVerboseAsm) const {
481 if (AsmTargetStreamerCtorFn)
482 return AsmTargetStreamerCtorFn(S, OS, InstPrint, IsVerboseAsm);
486 MCStreamer *createNullStreamer(MCContext &Ctx) const {
487 MCStreamer *S = llvm::createNullStreamer(Ctx);
488 createNullTargetStreamer(*S);
492 MCTargetStreamer *createNullTargetStreamer(MCStreamer &S) const {
493 if (NullTargetStreamerCtorFn)
494 return NullTargetStreamerCtorFn(S);
498 /// createMCRelocationInfo - Create a target specific MCRelocationInfo.
500 /// \param TT The target triple.
501 /// \param Ctx The target context.
502 MCRelocationInfo *createMCRelocationInfo(StringRef TT, MCContext &Ctx) const {
503 MCRelocationInfoCtorTy Fn = MCRelocationInfoCtorFn
504 ? MCRelocationInfoCtorFn
505 : llvm::createMCRelocationInfo;
506 return Fn(Triple(TT), Ctx);
509 /// createMCSymbolizer - Create a target specific MCSymbolizer.
511 /// \param TT The target triple.
512 /// \param GetOpInfo The function to get the symbolic information for
514 /// \param SymbolLookUp The function to lookup a symbol name.
515 /// \param DisInfo The pointer to the block of symbolic information for above
518 /// \param Ctx The target context.
519 /// \param RelInfo The relocation information for this target. Takes
522 createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
523 LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo,
525 std::unique_ptr<MCRelocationInfo> &&RelInfo) const {
526 MCSymbolizerCtorTy Fn =
527 MCSymbolizerCtorFn ? MCSymbolizerCtorFn : llvm::createMCSymbolizer;
528 return Fn(Triple(TT), GetOpInfo, SymbolLookUp, DisInfo, Ctx,
535 /// TargetRegistry - Generic interface to target specific features.
536 struct TargetRegistry {
537 // FIXME: Make this a namespace, probably just move all the Register*
538 // functions into Target (currently they all just set members on the Target
539 // anyway, and Target friends this class so those functions can...
541 TargetRegistry() = delete;
544 : public std::iterator<std::forward_iterator_tag, Target, ptrdiff_t> {
545 const Target *Current;
546 explicit iterator(Target *T) : Current(T) {}
547 friend struct TargetRegistry;
550 iterator() : Current(nullptr) {}
552 bool operator==(const iterator &x) const { return Current == x.Current; }
553 bool operator!=(const iterator &x) const { return !operator==(x); }
555 // Iterator traversal: forward iteration only
556 iterator &operator++() { // Preincrement
557 assert(Current && "Cannot increment end iterator!");
558 Current = Current->getNext();
561 iterator operator++(int) { // Postincrement
562 iterator tmp = *this;
567 const Target &operator*() const {
568 assert(Current && "Cannot dereference end iterator!");
572 const Target *operator->() const { return &operator*(); }
575 /// printRegisteredTargetsForVersion - Print the registered targets
576 /// appropriately for inclusion in a tool's version output.
577 static void printRegisteredTargetsForVersion();
579 /// @name Registry Access
582 static iterator_range<iterator> targets();
584 /// lookupTarget - Lookup a target based on a target triple.
586 /// \param Triple - The triple to use for finding a target.
587 /// \param Error - On failure, an error string describing why no target was
589 static const Target *lookupTarget(const std::string &Triple,
592 /// lookupTarget - Lookup a target based on an architecture name
593 /// and a target triple. If the architecture name is non-empty,
594 /// then the lookup is done by architecture. Otherwise, the target
597 /// \param ArchName - The architecture to use for finding a target.
598 /// \param TheTriple - The triple to use for finding a target. The
599 /// triple is updated with canonical architecture name if a lookup
600 /// by architecture is done.
601 /// \param Error - On failure, an error string describing why no target was
603 static const Target *lookupTarget(const std::string &ArchName,
604 Triple &TheTriple, std::string &Error);
607 /// @name Target Registration
610 /// RegisterTarget - Register the given target. Attempts to register a
611 /// target which has already been registered will be ignored.
613 /// Clients are responsible for ensuring that registration doesn't occur
614 /// while another thread is attempting to access the registry. Typically
615 /// this is done by initializing all targets at program startup.
617 /// @param T - The target being registered.
618 /// @param Name - The target name. This should be a static string.
619 /// @param ShortDesc - A short target description. This should be a static
621 /// @param ArchMatchFn - The arch match checking function for this target.
622 /// @param HasJIT - Whether the target supports JIT code
624 static void RegisterTarget(Target &T, const char *Name, const char *ShortDesc,
625 Target::ArchMatchFnTy ArchMatchFn,
626 bool HasJIT = false);
628 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
631 /// Clients are responsible for ensuring that registration doesn't occur
632 /// while another thread is attempting to access the registry. Typically
633 /// this is done by initializing all targets at program startup.
635 /// @param T - The target being registered.
636 /// @param Fn - A function to construct a MCAsmInfo for the target.
637 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
638 T.MCAsmInfoCtorFn = Fn;
641 static void registerMCAdjustCodeGenOpts(Target &T,
642 Target::MCAdjustCodeGenOptsFnTy Fn) {
643 T.MCAdjustCodeGenOptsFn = Fn;
646 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
649 /// Clients are responsible for ensuring that registration doesn't occur
650 /// while another thread is attempting to access the registry. Typically
651 /// this is done by initializing all targets at program startup.
653 /// @param T - The target being registered.
654 /// @param Fn - A function to construct a MCInstrInfo for the target.
655 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
656 T.MCInstrInfoCtorFn = Fn;
659 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
660 /// the given target.
661 static void RegisterMCInstrAnalysis(Target &T,
662 Target::MCInstrAnalysisCtorFnTy Fn) {
663 T.MCInstrAnalysisCtorFn = Fn;
666 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
669 /// Clients are responsible for ensuring that registration doesn't occur
670 /// while another thread is attempting to access the registry. Typically
671 /// this is done by initializing all targets at program startup.
673 /// @param T - The target being registered.
674 /// @param Fn - A function to construct a MCRegisterInfo for the target.
675 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
676 T.MCRegInfoCtorFn = Fn;
679 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
680 /// the given target.
682 /// Clients are responsible for ensuring that registration doesn't occur
683 /// while another thread is attempting to access the registry. Typically
684 /// this is done by initializing all targets at program startup.
686 /// @param T - The target being registered.
687 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
688 static void RegisterMCSubtargetInfo(Target &T,
689 Target::MCSubtargetInfoCtorFnTy Fn) {
690 T.MCSubtargetInfoCtorFn = Fn;
693 /// RegisterTargetMachine - Register a TargetMachine implementation for the
696 /// Clients are responsible for ensuring that registration doesn't occur
697 /// while another thread is attempting to access the registry. Typically
698 /// this is done by initializing all targets at program startup.
700 /// @param T - The target being registered.
701 /// @param Fn - A function to construct a TargetMachine for the target.
702 static void RegisterTargetMachine(Target &T, Target::TargetMachineCtorTy Fn) {
703 T.TargetMachineCtorFn = Fn;
706 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
709 /// Clients are responsible for ensuring that registration doesn't occur
710 /// while another thread is attempting to access the registry. Typically
711 /// this is done by initializing all targets at program startup.
713 /// @param T - The target being registered.
714 /// @param Fn - A function to construct an AsmBackend for the target.
715 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
716 T.MCAsmBackendCtorFn = Fn;
719 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
720 /// the given target.
722 /// Clients are responsible for ensuring that registration doesn't occur
723 /// while another thread is attempting to access the registry. Typically
724 /// this is done by initializing all targets at program startup.
726 /// @param T - The target being registered.
727 /// @param Fn - A function to construct an MCTargetAsmParser for the target.
728 static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
729 T.MCAsmParserCtorFn = Fn;
732 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
735 /// Clients are responsible for ensuring that registration doesn't occur
736 /// while another thread is attempting to access the registry. Typically
737 /// this is done by initializing all targets at program startup.
739 /// @param T - The target being registered.
740 /// @param Fn - A function to construct an AsmPrinter for the target.
741 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
742 T.AsmPrinterCtorFn = Fn;
745 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
746 /// the given target.
748 /// Clients are responsible for ensuring that registration doesn't occur
749 /// while another thread is attempting to access the registry. Typically
750 /// this is done by initializing all targets at program startup.
752 /// @param T - The target being registered.
753 /// @param Fn - A function to construct an MCDisassembler for the target.
754 static void RegisterMCDisassembler(Target &T,
755 Target::MCDisassemblerCtorTy Fn) {
756 T.MCDisassemblerCtorFn = Fn;
759 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
762 /// Clients are responsible for ensuring that registration doesn't occur
763 /// while another thread is attempting to access the registry. Typically
764 /// this is done by initializing all targets at program startup.
766 /// @param T - The target being registered.
767 /// @param Fn - A function to construct an MCInstPrinter for the target.
768 static void RegisterMCInstPrinter(Target &T, Target::MCInstPrinterCtorTy Fn) {
769 T.MCInstPrinterCtorFn = Fn;
772 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
775 /// Clients are responsible for ensuring that registration doesn't occur
776 /// while another thread is attempting to access the registry. Typically
777 /// this is done by initializing all targets at program startup.
779 /// @param T - The target being registered.
780 /// @param Fn - A function to construct an MCCodeEmitter for the target.
781 static void RegisterMCCodeEmitter(Target &T, Target::MCCodeEmitterCtorTy Fn) {
782 T.MCCodeEmitterCtorFn = Fn;
785 static void RegisterCOFFStreamer(Target &T, Target::COFFStreamerCtorTy Fn) {
786 T.COFFStreamerCtorFn = Fn;
789 static void RegisterMachOStreamer(Target &T, Target::MachOStreamerCtorTy Fn) {
790 T.MachOStreamerCtorFn = Fn;
793 static void RegisterELFStreamer(Target &T, Target::ELFStreamerCtorTy Fn) {
794 T.ELFStreamerCtorFn = Fn;
797 static void RegisterNullTargetStreamer(Target &T,
798 Target::NullTargetStreamerCtorTy Fn) {
799 T.NullTargetStreamerCtorFn = Fn;
802 static void RegisterAsmTargetStreamer(Target &T,
803 Target::AsmTargetStreamerCtorTy Fn) {
804 T.AsmTargetStreamerCtorFn = Fn;
808 RegisterObjectTargetStreamer(Target &T,
809 Target::ObjectTargetStreamerCtorTy Fn) {
810 T.ObjectTargetStreamerCtorFn = Fn;
813 /// RegisterMCRelocationInfo - Register an MCRelocationInfo
814 /// implementation for the given target.
816 /// Clients are responsible for ensuring that registration doesn't occur
817 /// while another thread is attempting to access the registry. Typically
818 /// this is done by initializing all targets at program startup.
820 /// @param T - The target being registered.
821 /// @param Fn - A function to construct an MCRelocationInfo for the target.
822 static void RegisterMCRelocationInfo(Target &T,
823 Target::MCRelocationInfoCtorTy Fn) {
824 T.MCRelocationInfoCtorFn = Fn;
827 /// RegisterMCSymbolizer - Register an MCSymbolizer
828 /// implementation for the given target.
830 /// Clients are responsible for ensuring that registration doesn't occur
831 /// while another thread is attempting to access the registry. Typically
832 /// this is done by initializing all targets at program startup.
834 /// @param T - The target being registered.
835 /// @param Fn - A function to construct an MCSymbolizer for the target.
836 static void RegisterMCSymbolizer(Target &T, Target::MCSymbolizerCtorTy Fn) {
837 T.MCSymbolizerCtorFn = Fn;
843 //===--------------------------------------------------------------------===//
845 /// RegisterTarget - Helper template for registering a target, for use in the
846 /// target's initialization function. Usage:
849 /// Target TheFooTarget; // The global target instance.
851 /// extern "C" void LLVMInitializeFooTargetInfo() {
852 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
854 template <Triple::ArchType TargetArchType = Triple::UnknownArch,
856 struct RegisterTarget {
857 RegisterTarget(Target &T, const char *Name, const char *Desc) {
858 TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch, HasJIT);
861 static bool getArchMatch(Triple::ArchType Arch) {
862 return Arch == TargetArchType;
866 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
867 /// implementation. This invokes the static "Create" method on the class to
868 /// actually do the construction. Usage:
870 /// extern "C" void LLVMInitializeFooTarget() {
871 /// extern Target TheFooTarget;
872 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
874 template <class MCAsmInfoImpl> struct RegisterMCAsmInfo {
875 RegisterMCAsmInfo(Target &T) {
876 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
880 static MCAsmInfo *Allocator(const MCRegisterInfo & /*MRI*/,
882 return new MCAsmInfoImpl(TT);
886 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
887 /// implementation. This invokes the specified function to do the
888 /// construction. Usage:
890 /// extern "C" void LLVMInitializeFooTarget() {
891 /// extern Target TheFooTarget;
892 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
894 struct RegisterMCAsmInfoFn {
895 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
896 TargetRegistry::RegisterMCAsmInfo(T, Fn);
900 struct RegisterMCAdjustCodeGenOptsFn {
901 RegisterMCAdjustCodeGenOptsFn(Target &T, Target::MCAdjustCodeGenOptsFnTy Fn) {
902 TargetRegistry::registerMCAdjustCodeGenOpts(T, Fn);
906 /// RegisterMCInstrInfo - Helper template for registering a target instruction
907 /// info implementation. This invokes the static "Create" method on the class
908 /// to actually do the construction. Usage:
910 /// extern "C" void LLVMInitializeFooTarget() {
911 /// extern Target TheFooTarget;
912 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
914 template <class MCInstrInfoImpl> struct RegisterMCInstrInfo {
915 RegisterMCInstrInfo(Target &T) {
916 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
920 static MCInstrInfo *Allocator() { return new MCInstrInfoImpl(); }
923 /// RegisterMCInstrInfoFn - Helper template for registering a target
924 /// instruction info implementation. This invokes the specified function to
925 /// do the construction. Usage:
927 /// extern "C" void LLVMInitializeFooTarget() {
928 /// extern Target TheFooTarget;
929 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
931 struct RegisterMCInstrInfoFn {
932 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
933 TargetRegistry::RegisterMCInstrInfo(T, Fn);
937 /// RegisterMCInstrAnalysis - Helper template for registering a target
938 /// instruction analyzer implementation. This invokes the static "Create"
939 /// method on the class to actually do the construction. Usage:
941 /// extern "C" void LLVMInitializeFooTarget() {
942 /// extern Target TheFooTarget;
943 /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
945 template <class MCInstrAnalysisImpl> struct RegisterMCInstrAnalysis {
946 RegisterMCInstrAnalysis(Target &T) {
947 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
951 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
952 return new MCInstrAnalysisImpl(Info);
956 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
957 /// instruction analyzer implementation. This invokes the specified function
958 /// to do the construction. Usage:
960 /// extern "C" void LLVMInitializeFooTarget() {
961 /// extern Target TheFooTarget;
962 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
964 struct RegisterMCInstrAnalysisFn {
965 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
966 TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
970 /// RegisterMCRegInfo - Helper template for registering a target register info
971 /// implementation. This invokes the static "Create" method on the class to
972 /// actually do the construction. Usage:
974 /// extern "C" void LLVMInitializeFooTarget() {
975 /// extern Target TheFooTarget;
976 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
978 template <class MCRegisterInfoImpl> struct RegisterMCRegInfo {
979 RegisterMCRegInfo(Target &T) {
980 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
984 static MCRegisterInfo *Allocator(const Triple & /*TT*/) {
985 return new MCRegisterInfoImpl();
989 /// RegisterMCRegInfoFn - Helper template for registering a target register
990 /// info implementation. This invokes the specified function to do the
991 /// construction. Usage:
993 /// extern "C" void LLVMInitializeFooTarget() {
994 /// extern Target TheFooTarget;
995 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
997 struct RegisterMCRegInfoFn {
998 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
999 TargetRegistry::RegisterMCRegInfo(T, Fn);
1003 /// RegisterMCSubtargetInfo - Helper template for registering a target
1004 /// subtarget info implementation. This invokes the static "Create" method
1005 /// on the class to actually do the construction. Usage:
1007 /// extern "C" void LLVMInitializeFooTarget() {
1008 /// extern Target TheFooTarget;
1009 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
1011 template <class MCSubtargetInfoImpl> struct RegisterMCSubtargetInfo {
1012 RegisterMCSubtargetInfo(Target &T) {
1013 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
1017 static MCSubtargetInfo *Allocator(const Triple & /*TT*/, StringRef /*CPU*/,
1019 return new MCSubtargetInfoImpl();
1023 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
1024 /// subtarget info implementation. This invokes the specified function to
1025 /// do the construction. Usage:
1027 /// extern "C" void LLVMInitializeFooTarget() {
1028 /// extern Target TheFooTarget;
1029 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1031 struct RegisterMCSubtargetInfoFn {
1032 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
1033 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
1037 /// RegisterTargetMachine - Helper template for registering a target machine
1038 /// implementation, for use in the target machine initialization
1039 /// function. Usage:
1041 /// extern "C" void LLVMInitializeFooTarget() {
1042 /// extern Target TheFooTarget;
1043 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1045 template <class TargetMachineImpl> struct RegisterTargetMachine {
1046 RegisterTargetMachine(Target &T) {
1047 TargetRegistry::RegisterTargetMachine(T, &Allocator);
1051 static TargetMachine *Allocator(const Target &T, const Triple &TT,
1052 StringRef CPU, StringRef FS,
1053 const TargetOptions &Options,
1054 Optional<Reloc::Model> RM,
1055 CodeModel::Model CM, CodeGenOpt::Level OL) {
1056 return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
1060 /// RegisterMCAsmBackend - Helper template for registering a target specific
1061 /// assembler backend. Usage:
1063 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1064 /// extern Target TheFooTarget;
1065 /// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1067 template <class MCAsmBackendImpl> struct RegisterMCAsmBackend {
1068 RegisterMCAsmBackend(Target &T) {
1069 TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1073 static MCAsmBackend *Allocator(const Target &T, const MCRegisterInfo &MRI,
1074 const Triple &TheTriple, StringRef CPU) {
1075 return new MCAsmBackendImpl(T, MRI, TheTriple, CPU);
1079 /// RegisterMCAsmParser - Helper template for registering a target specific
1080 /// assembly parser, for use in the target machine initialization
1081 /// function. Usage:
1083 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1084 /// extern Target TheFooTarget;
1085 /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1087 template <class MCAsmParserImpl> struct RegisterMCAsmParser {
1088 RegisterMCAsmParser(Target &T) {
1089 TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1093 static MCTargetAsmParser *Allocator(const MCSubtargetInfo &STI,
1094 MCAsmParser &P, const MCInstrInfo &MII,
1095 const MCTargetOptions &Options) {
1096 return new MCAsmParserImpl(STI, P, MII, Options);
1100 /// RegisterAsmPrinter - Helper template for registering a target specific
1101 /// assembly printer, for use in the target machine initialization
1102 /// function. Usage:
1104 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1105 /// extern Target TheFooTarget;
1106 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1108 template <class AsmPrinterImpl> struct RegisterAsmPrinter {
1109 RegisterAsmPrinter(Target &T) {
1110 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1114 static AsmPrinter *Allocator(TargetMachine &TM,
1115 std::unique_ptr<MCStreamer> &&Streamer) {
1116 return new AsmPrinterImpl(TM, std::move(Streamer));
1120 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1121 /// machine code emitter, for use in the target initialization
1122 /// function. Usage:
1124 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1125 /// extern Target TheFooTarget;
1126 /// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1128 template <class MCCodeEmitterImpl> struct RegisterMCCodeEmitter {
1129 RegisterMCCodeEmitter(Target &T) {
1130 TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1134 static MCCodeEmitter *Allocator(const MCInstrInfo & /*II*/,
1135 const MCRegisterInfo & /*MRI*/,
1136 MCContext & /*Ctx*/) {
1137 return new MCCodeEmitterImpl();