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/Triple.h"
24 #include "llvm/Support/CodeGen.h"
25 #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 MCCodeGenInfo *(*MCCodeGenInfoCtorFnTy)(const Triple &TT,
98 CodeGenOpt::Level OL);
99 typedef MCInstrInfo *(*MCInstrInfoCtorFnTy)(void);
100 typedef MCInstrAnalysis *(*MCInstrAnalysisCtorFnTy)(const MCInstrInfo *Info);
101 typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(const Triple &TT);
102 typedef MCSubtargetInfo *(*MCSubtargetInfoCtorFnTy)(const Triple &TT,
105 typedef TargetMachine *(*TargetMachineCtorTy)(
106 const Target &T, const Triple &TT, StringRef CPU, StringRef Features,
107 const TargetOptions &Options, Reloc::Model RM, CodeModel::Model CM,
108 CodeGenOpt::Level OL);
109 // If it weren't for layering issues (this header is in llvm/Support, but
110 // depends on MC?) this should take the Streamer by value rather than rvalue
112 typedef AsmPrinter *(*AsmPrinterCtorTy)(
113 TargetMachine &TM, std::unique_ptr<MCStreamer> &&Streamer);
114 typedef MCAsmBackend *(*MCAsmBackendCtorTy)(const Target &T,
115 const MCRegisterInfo &MRI,
116 const Triple &TT, StringRef CPU);
117 typedef MCTargetAsmParser *(*MCAsmParserCtorTy)(
118 const MCSubtargetInfo &STI, MCAsmParser &P, const MCInstrInfo &MII,
119 const MCTargetOptions &Options);
120 typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T,
121 const MCSubtargetInfo &STI,
123 typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Triple &T,
124 unsigned SyntaxVariant,
125 const MCAsmInfo &MAI,
126 const MCInstrInfo &MII,
127 const MCRegisterInfo &MRI);
128 typedef MCCodeEmitter *(*MCCodeEmitterCtorTy)(const MCInstrInfo &II,
129 const MCRegisterInfo &MRI,
131 typedef MCStreamer *(*ELFStreamerCtorTy)(const Triple &T, MCContext &Ctx,
133 raw_pwrite_stream &OS,
134 MCCodeEmitter *Emitter,
136 typedef MCStreamer *(*MachOStreamerCtorTy)(MCContext &Ctx, MCAsmBackend &TAB,
137 raw_pwrite_stream &OS,
138 MCCodeEmitter *Emitter,
140 bool DWARFMustBeAtTheEnd);
141 typedef MCStreamer *(*COFFStreamerCtorTy)(MCContext &Ctx, MCAsmBackend &TAB,
142 raw_pwrite_stream &OS,
143 MCCodeEmitter *Emitter,
145 bool IncrementalLinkerCompatible);
146 typedef MCTargetStreamer *(*NullTargetStreamerCtorTy)(MCStreamer &S);
147 typedef MCTargetStreamer *(*AsmTargetStreamerCtorTy)(
148 MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *InstPrint,
150 typedef MCTargetStreamer *(*ObjectTargetStreamerCtorTy)(
151 MCStreamer &S, const MCSubtargetInfo &STI);
152 typedef MCRelocationInfo *(*MCRelocationInfoCtorTy)(const Triple &TT,
154 typedef MCSymbolizer *(*MCSymbolizerCtorTy)(
155 const Triple &TT, LLVMOpInfoCallback GetOpInfo,
156 LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo, MCContext *Ctx,
157 std::unique_ptr<MCRelocationInfo> &&RelInfo);
160 /// Next - The next registered target in the linked list, maintained by the
164 /// The target function for checking if an architecture is supported.
165 ArchMatchFnTy ArchMatchFn;
167 /// Name - The target name.
170 /// ShortDesc - A short description of the target.
171 const char *ShortDesc;
173 /// HasJIT - Whether this target supports the JIT.
176 /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
178 MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
180 /// MCCodeGenInfoCtorFn - Constructor function for this target's
181 /// MCCodeGenInfo, if registered.
182 MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn;
184 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
186 MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
188 /// MCInstrAnalysisCtorFn - Constructor function for this target's
189 /// MCInstrAnalysis, if registered.
190 MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
192 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
194 MCRegInfoCtorFnTy MCRegInfoCtorFn;
196 /// MCSubtargetInfoCtorFn - Constructor function for this target's
197 /// MCSubtargetInfo, if registered.
198 MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
200 /// TargetMachineCtorFn - Construction function for this target's
201 /// TargetMachine, if registered.
202 TargetMachineCtorTy TargetMachineCtorFn;
204 /// MCAsmBackendCtorFn - Construction function for this target's
205 /// MCAsmBackend, if registered.
206 MCAsmBackendCtorTy MCAsmBackendCtorFn;
208 /// MCAsmParserCtorFn - Construction function for this target's
209 /// MCTargetAsmParser, if registered.
210 MCAsmParserCtorTy MCAsmParserCtorFn;
212 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
214 AsmPrinterCtorTy AsmPrinterCtorFn;
216 /// MCDisassemblerCtorFn - Construction function for this target's
217 /// MCDisassembler, if registered.
218 MCDisassemblerCtorTy MCDisassemblerCtorFn;
220 /// MCInstPrinterCtorFn - Construction function for this target's
221 /// MCInstPrinter, if registered.
222 MCInstPrinterCtorTy MCInstPrinterCtorFn;
224 /// MCCodeEmitterCtorFn - Construction function for this target's
225 /// CodeEmitter, if registered.
226 MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
228 // Construction functions for the various object formats, if registered.
229 COFFStreamerCtorTy COFFStreamerCtorFn;
230 MachOStreamerCtorTy MachOStreamerCtorFn;
231 ELFStreamerCtorTy ELFStreamerCtorFn;
233 /// Construction function for this target's null TargetStreamer, if
234 /// registered (default = nullptr).
235 NullTargetStreamerCtorTy NullTargetStreamerCtorFn;
237 /// Construction function for this target's asm TargetStreamer, if
238 /// registered (default = nullptr).
239 AsmTargetStreamerCtorTy AsmTargetStreamerCtorFn;
241 /// Construction function for this target's obj TargetStreamer, if
242 /// registered (default = nullptr).
243 ObjectTargetStreamerCtorTy ObjectTargetStreamerCtorFn;
245 /// MCRelocationInfoCtorFn - Construction function for this target's
246 /// MCRelocationInfo, if registered (default = llvm::createMCRelocationInfo)
247 MCRelocationInfoCtorTy MCRelocationInfoCtorFn;
249 /// MCSymbolizerCtorFn - Construction function for this target's
250 /// MCSymbolizer, if registered (default = llvm::createMCSymbolizer)
251 MCSymbolizerCtorTy MCSymbolizerCtorFn;
255 : COFFStreamerCtorFn(nullptr), MachOStreamerCtorFn(nullptr),
256 ELFStreamerCtorFn(nullptr), NullTargetStreamerCtorFn(nullptr),
257 AsmTargetStreamerCtorFn(nullptr), ObjectTargetStreamerCtorFn(nullptr),
258 MCRelocationInfoCtorFn(nullptr), MCSymbolizerCtorFn(nullptr) {}
260 /// @name Target Information
263 // getNext - Return the next registered target.
264 const Target *getNext() const { return Next; }
266 /// getName - Get the target name.
267 const char *getName() const { return Name; }
269 /// getShortDescription - Get a short description of the target.
270 const char *getShortDescription() const { return ShortDesc; }
273 /// @name Feature Predicates
276 /// hasJIT - Check if this targets supports the just-in-time compilation.
277 bool hasJIT() const { return HasJIT; }
279 /// hasTargetMachine - Check if this target supports code generation.
280 bool hasTargetMachine() const { return TargetMachineCtorFn != nullptr; }
282 /// hasMCAsmBackend - Check if this target supports .o generation.
283 bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != nullptr; }
286 /// @name Feature Constructors
289 /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
292 /// \param TheTriple This argument is used to determine the target machine
293 /// feature set; it should always be provided. Generally this should be
294 /// either the target triple from the module, or the target triple of the
295 /// host if that does not exist.
296 MCAsmInfo *createMCAsmInfo(const MCRegisterInfo &MRI,
297 StringRef TheTriple) const {
298 if (!MCAsmInfoCtorFn)
300 return MCAsmInfoCtorFn(MRI, Triple(TheTriple));
303 /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
305 MCCodeGenInfo *createMCCodeGenInfo(StringRef TT, Reloc::Model RM,
307 CodeGenOpt::Level OL) const {
308 if (!MCCodeGenInfoCtorFn)
310 return MCCodeGenInfoCtorFn(Triple(TT), RM, CM, OL);
313 /// createMCInstrInfo - Create a MCInstrInfo implementation.
315 MCInstrInfo *createMCInstrInfo() const {
316 if (!MCInstrInfoCtorFn)
318 return MCInstrInfoCtorFn();
321 /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
323 MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
324 if (!MCInstrAnalysisCtorFn)
326 return MCInstrAnalysisCtorFn(Info);
329 /// createMCRegInfo - Create a MCRegisterInfo implementation.
331 MCRegisterInfo *createMCRegInfo(StringRef TT) const {
332 if (!MCRegInfoCtorFn)
334 return MCRegInfoCtorFn(Triple(TT));
337 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
339 /// \param TheTriple This argument is used to determine the target machine
340 /// feature set; it should always be provided. Generally this should be
341 /// either the target triple from the module, or the target triple of the
342 /// host if that does not exist.
343 /// \param CPU This specifies the name of the target CPU.
344 /// \param Features This specifies the string representation of the
345 /// additional target features.
346 MCSubtargetInfo *createMCSubtargetInfo(StringRef TheTriple, StringRef CPU,
347 StringRef Features) const {
348 if (!MCSubtargetInfoCtorFn)
350 return MCSubtargetInfoCtorFn(Triple(TheTriple), CPU, Features);
353 /// createTargetMachine - Create a target specific machine implementation
354 /// for the specified \p Triple.
356 /// \param TT This argument is used to determine the target machine
357 /// feature set; it should always be provided. Generally this should be
358 /// either the target triple from the module, or the target triple of the
359 /// host if that does not exist.
361 createTargetMachine(StringRef TT, StringRef CPU, StringRef Features,
362 const TargetOptions &Options,
363 Reloc::Model RM = Reloc::Default,
364 CodeModel::Model CM = CodeModel::Default,
365 CodeGenOpt::Level OL = CodeGenOpt::Default) const {
366 if (!TargetMachineCtorFn)
368 return TargetMachineCtorFn(*this, Triple(TT), CPU, Features, Options, RM,
372 /// createMCAsmBackend - Create a target specific assembly parser.
374 /// \param TheTriple The target triple string.
375 MCAsmBackend *createMCAsmBackend(const MCRegisterInfo &MRI,
376 StringRef TheTriple, StringRef CPU) const {
377 if (!MCAsmBackendCtorFn)
379 return MCAsmBackendCtorFn(*this, MRI, Triple(TheTriple), CPU);
382 /// createMCAsmParser - Create a target specific assembly parser.
384 /// \param Parser The target independent parser implementation to use for
385 /// parsing and lexing.
386 MCTargetAsmParser *createMCAsmParser(const MCSubtargetInfo &STI,
388 const MCInstrInfo &MII,
389 const MCTargetOptions &Options) const {
390 if (!MCAsmParserCtorFn)
392 return MCAsmParserCtorFn(STI, Parser, MII, Options);
395 /// createAsmPrinter - Create a target specific assembly printer pass. This
396 /// takes ownership of the MCStreamer object.
397 AsmPrinter *createAsmPrinter(TargetMachine &TM,
398 std::unique_ptr<MCStreamer> &&Streamer) const {
399 if (!AsmPrinterCtorFn)
401 return AsmPrinterCtorFn(TM, std::move(Streamer));
404 MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI,
405 MCContext &Ctx) const {
406 if (!MCDisassemblerCtorFn)
408 return MCDisassemblerCtorFn(*this, STI, Ctx);
411 MCInstPrinter *createMCInstPrinter(const Triple &T, unsigned SyntaxVariant,
412 const MCAsmInfo &MAI,
413 const MCInstrInfo &MII,
414 const MCRegisterInfo &MRI) const {
415 if (!MCInstPrinterCtorFn)
417 return MCInstPrinterCtorFn(T, SyntaxVariant, MAI, MII, MRI);
420 /// createMCCodeEmitter - Create a target specific code emitter.
421 MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
422 const MCRegisterInfo &MRI,
423 MCContext &Ctx) const {
424 if (!MCCodeEmitterCtorFn)
426 return MCCodeEmitterCtorFn(II, MRI, Ctx);
429 /// Create a target specific MCStreamer.
431 /// \param T The target triple.
432 /// \param Ctx The target context.
433 /// \param TAB The target assembler backend object. Takes ownership.
434 /// \param OS The stream object.
435 /// \param Emitter The target independent assembler object.Takes ownership.
436 /// \param RelaxAll Relax all fixups?
437 MCStreamer *createMCObjectStreamer(const Triple &T, MCContext &Ctx,
438 MCAsmBackend &TAB, raw_pwrite_stream &OS,
439 MCCodeEmitter *Emitter,
440 const MCSubtargetInfo &STI, bool RelaxAll,
441 bool IncrementalLinkerCompatible,
442 bool DWARFMustBeAtTheEnd) const {
444 switch (T.getObjectFormat()) {
446 llvm_unreachable("Unknown object format");
448 assert(T.isOSWindows() && "only Windows COFF is supported");
449 S = COFFStreamerCtorFn(Ctx, TAB, OS, Emitter, RelaxAll,
450 IncrementalLinkerCompatible);
453 if (MachOStreamerCtorFn)
454 S = MachOStreamerCtorFn(Ctx, TAB, OS, Emitter, RelaxAll,
455 DWARFMustBeAtTheEnd);
457 S = createMachOStreamer(Ctx, TAB, OS, Emitter, RelaxAll,
458 DWARFMustBeAtTheEnd);
461 if (ELFStreamerCtorFn)
462 S = ELFStreamerCtorFn(T, Ctx, TAB, OS, Emitter, RelaxAll);
464 S = createELFStreamer(Ctx, TAB, OS, Emitter, RelaxAll);
467 if (ObjectTargetStreamerCtorFn)
468 ObjectTargetStreamerCtorFn(*S, STI);
472 MCStreamer *createAsmStreamer(MCContext &Ctx,
473 std::unique_ptr<formatted_raw_ostream> OS,
474 bool IsVerboseAsm, bool UseDwarfDirectory,
475 MCInstPrinter *InstPrint, MCCodeEmitter *CE,
476 MCAsmBackend *TAB, bool ShowInst) const {
477 formatted_raw_ostream &OSRef = *OS;
478 MCStreamer *S = llvm::createAsmStreamer(Ctx, std::move(OS), IsVerboseAsm,
479 UseDwarfDirectory, InstPrint, CE,
481 createAsmTargetStreamer(*S, OSRef, InstPrint, IsVerboseAsm);
485 MCTargetStreamer *createAsmTargetStreamer(MCStreamer &S,
486 formatted_raw_ostream &OS,
487 MCInstPrinter *InstPrint,
488 bool IsVerboseAsm) const {
489 if (AsmTargetStreamerCtorFn)
490 return AsmTargetStreamerCtorFn(S, OS, InstPrint, IsVerboseAsm);
494 MCStreamer *createNullStreamer(MCContext &Ctx) const {
495 MCStreamer *S = llvm::createNullStreamer(Ctx);
496 createNullTargetStreamer(*S);
500 MCTargetStreamer *createNullTargetStreamer(MCStreamer &S) const {
501 if (NullTargetStreamerCtorFn)
502 return NullTargetStreamerCtorFn(S);
506 /// createMCRelocationInfo - Create a target specific MCRelocationInfo.
508 /// \param TT The target triple.
509 /// \param Ctx The target context.
510 MCRelocationInfo *createMCRelocationInfo(StringRef TT, MCContext &Ctx) const {
511 MCRelocationInfoCtorTy Fn = MCRelocationInfoCtorFn
512 ? MCRelocationInfoCtorFn
513 : llvm::createMCRelocationInfo;
514 return Fn(Triple(TT), Ctx);
517 /// createMCSymbolizer - Create a target specific MCSymbolizer.
519 /// \param TT The target triple.
520 /// \param GetOpInfo The function to get the symbolic information for
522 /// \param SymbolLookUp The function to lookup a symbol name.
523 /// \param DisInfo The pointer to the block of symbolic information for above
526 /// \param Ctx The target context.
527 /// \param RelInfo The relocation information for this target. Takes
530 createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
531 LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo,
533 std::unique_ptr<MCRelocationInfo> &&RelInfo) const {
534 MCSymbolizerCtorTy Fn =
535 MCSymbolizerCtorFn ? MCSymbolizerCtorFn : llvm::createMCSymbolizer;
536 return Fn(Triple(TT), GetOpInfo, SymbolLookUp, DisInfo, Ctx,
543 /// TargetRegistry - Generic interface to target specific features.
544 struct TargetRegistry {
545 // FIXME: Make this a namespace, probably just move all the Register*
546 // functions into Target (currently they all just set members on the Target
547 // anyway, and Target friends this class so those functions can...
549 TargetRegistry() = delete;
552 : public std::iterator<std::forward_iterator_tag, Target, ptrdiff_t> {
553 const Target *Current;
554 explicit iterator(Target *T) : Current(T) {}
555 friend struct TargetRegistry;
558 iterator() : Current(nullptr) {}
560 bool operator==(const iterator &x) const { return Current == x.Current; }
561 bool operator!=(const iterator &x) const { return !operator==(x); }
563 // Iterator traversal: forward iteration only
564 iterator &operator++() { // Preincrement
565 assert(Current && "Cannot increment end iterator!");
566 Current = Current->getNext();
569 iterator operator++(int) { // Postincrement
570 iterator tmp = *this;
575 const Target &operator*() const {
576 assert(Current && "Cannot dereference end iterator!");
580 const Target *operator->() const { return &operator*(); }
583 /// printRegisteredTargetsForVersion - Print the registered targets
584 /// appropriately for inclusion in a tool's version output.
585 static void printRegisteredTargetsForVersion();
587 /// @name Registry Access
590 static iterator_range<iterator> targets();
592 /// lookupTarget - Lookup a target based on a target triple.
594 /// \param Triple - The triple to use for finding a target.
595 /// \param Error - On failure, an error string describing why no target was
597 static const Target *lookupTarget(const std::string &Triple,
600 /// lookupTarget - Lookup a target based on an architecture name
601 /// and a target triple. If the architecture name is non-empty,
602 /// then the lookup is done by architecture. Otherwise, the target
605 /// \param ArchName - The architecture to use for finding a target.
606 /// \param TheTriple - The triple to use for finding a target. The
607 /// triple is updated with canonical architecture name if a lookup
608 /// by architecture is done.
609 /// \param Error - On failure, an error string describing why no target was
611 static const Target *lookupTarget(const std::string &ArchName,
612 Triple &TheTriple, std::string &Error);
615 /// @name Target Registration
618 /// RegisterTarget - Register the given target. Attempts to register a
619 /// target which has already been registered will be ignored.
621 /// Clients are responsible for ensuring that registration doesn't occur
622 /// while another thread is attempting to access the registry. Typically
623 /// this is done by initializing all targets at program startup.
625 /// @param T - The target being registered.
626 /// @param Name - The target name. This should be a static string.
627 /// @param ShortDesc - A short target description. This should be a static
629 /// @param ArchMatchFn - The arch match checking function for this target.
630 /// @param HasJIT - Whether the target supports JIT code
632 static void RegisterTarget(Target &T, const char *Name, const char *ShortDesc,
633 Target::ArchMatchFnTy ArchMatchFn,
634 bool HasJIT = false);
636 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
639 /// Clients are responsible for ensuring that registration doesn't occur
640 /// while another thread is attempting to access the registry. Typically
641 /// this is done by initializing all targets at program startup.
643 /// @param T - The target being registered.
644 /// @param Fn - A function to construct a MCAsmInfo for the target.
645 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
646 T.MCAsmInfoCtorFn = Fn;
649 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
652 /// Clients are responsible for ensuring that registration doesn't occur
653 /// while another thread is attempting to access the registry. Typically
654 /// this is done by initializing all targets at program startup.
656 /// @param T - The target being registered.
657 /// @param Fn - A function to construct a MCCodeGenInfo for the target.
658 static void RegisterMCCodeGenInfo(Target &T,
659 Target::MCCodeGenInfoCtorFnTy Fn) {
660 T.MCCodeGenInfoCtorFn = Fn;
663 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
666 /// Clients are responsible for ensuring that registration doesn't occur
667 /// while another thread is attempting to access the registry. Typically
668 /// this is done by initializing all targets at program startup.
670 /// @param T - The target being registered.
671 /// @param Fn - A function to construct a MCInstrInfo for the target.
672 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
673 T.MCInstrInfoCtorFn = Fn;
676 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
677 /// the given target.
678 static void RegisterMCInstrAnalysis(Target &T,
679 Target::MCInstrAnalysisCtorFnTy Fn) {
680 T.MCInstrAnalysisCtorFn = Fn;
683 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
686 /// Clients are responsible for ensuring that registration doesn't occur
687 /// while another thread is attempting to access the registry. Typically
688 /// this is done by initializing all targets at program startup.
690 /// @param T - The target being registered.
691 /// @param Fn - A function to construct a MCRegisterInfo for the target.
692 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
693 T.MCRegInfoCtorFn = Fn;
696 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
697 /// the given target.
699 /// Clients are responsible for ensuring that registration doesn't occur
700 /// while another thread is attempting to access the registry. Typically
701 /// this is done by initializing all targets at program startup.
703 /// @param T - The target being registered.
704 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
705 static void RegisterMCSubtargetInfo(Target &T,
706 Target::MCSubtargetInfoCtorFnTy Fn) {
707 T.MCSubtargetInfoCtorFn = Fn;
710 /// RegisterTargetMachine - Register a TargetMachine implementation for the
713 /// Clients are responsible for ensuring that registration doesn't occur
714 /// while another thread is attempting to access the registry. Typically
715 /// this is done by initializing all targets at program startup.
717 /// @param T - The target being registered.
718 /// @param Fn - A function to construct a TargetMachine for the target.
719 static void RegisterTargetMachine(Target &T, Target::TargetMachineCtorTy Fn) {
720 T.TargetMachineCtorFn = Fn;
723 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
726 /// Clients are responsible for ensuring that registration doesn't occur
727 /// while another thread is attempting to access the registry. Typically
728 /// this is done by initializing all targets at program startup.
730 /// @param T - The target being registered.
731 /// @param Fn - A function to construct an AsmBackend for the target.
732 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
733 T.MCAsmBackendCtorFn = Fn;
736 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
737 /// the given target.
739 /// Clients are responsible for ensuring that registration doesn't occur
740 /// while another thread is attempting to access the registry. Typically
741 /// this is done by initializing all targets at program startup.
743 /// @param T - The target being registered.
744 /// @param Fn - A function to construct an MCTargetAsmParser for the target.
745 static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
746 T.MCAsmParserCtorFn = Fn;
749 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
752 /// Clients are responsible for ensuring that registration doesn't occur
753 /// while another thread is attempting to access the registry. Typically
754 /// this is done by initializing all targets at program startup.
756 /// @param T - The target being registered.
757 /// @param Fn - A function to construct an AsmPrinter for the target.
758 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
759 T.AsmPrinterCtorFn = Fn;
762 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
763 /// the given target.
765 /// Clients are responsible for ensuring that registration doesn't occur
766 /// while another thread is attempting to access the registry. Typically
767 /// this is done by initializing all targets at program startup.
769 /// @param T - The target being registered.
770 /// @param Fn - A function to construct an MCDisassembler for the target.
771 static void RegisterMCDisassembler(Target &T,
772 Target::MCDisassemblerCtorTy Fn) {
773 T.MCDisassemblerCtorFn = Fn;
776 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
779 /// Clients are responsible for ensuring that registration doesn't occur
780 /// while another thread is attempting to access the registry. Typically
781 /// this is done by initializing all targets at program startup.
783 /// @param T - The target being registered.
784 /// @param Fn - A function to construct an MCInstPrinter for the target.
785 static void RegisterMCInstPrinter(Target &T, Target::MCInstPrinterCtorTy Fn) {
786 T.MCInstPrinterCtorFn = Fn;
789 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
792 /// Clients are responsible for ensuring that registration doesn't occur
793 /// while another thread is attempting to access the registry. Typically
794 /// this is done by initializing all targets at program startup.
796 /// @param T - The target being registered.
797 /// @param Fn - A function to construct an MCCodeEmitter for the target.
798 static void RegisterMCCodeEmitter(Target &T, Target::MCCodeEmitterCtorTy Fn) {
799 T.MCCodeEmitterCtorFn = Fn;
802 static void RegisterCOFFStreamer(Target &T, Target::COFFStreamerCtorTy Fn) {
803 T.COFFStreamerCtorFn = Fn;
806 static void RegisterMachOStreamer(Target &T, Target::MachOStreamerCtorTy Fn) {
807 T.MachOStreamerCtorFn = Fn;
810 static void RegisterELFStreamer(Target &T, Target::ELFStreamerCtorTy Fn) {
811 T.ELFStreamerCtorFn = Fn;
814 static void RegisterNullTargetStreamer(Target &T,
815 Target::NullTargetStreamerCtorTy Fn) {
816 T.NullTargetStreamerCtorFn = Fn;
819 static void RegisterAsmTargetStreamer(Target &T,
820 Target::AsmTargetStreamerCtorTy Fn) {
821 T.AsmTargetStreamerCtorFn = Fn;
825 RegisterObjectTargetStreamer(Target &T,
826 Target::ObjectTargetStreamerCtorTy Fn) {
827 T.ObjectTargetStreamerCtorFn = Fn;
830 /// RegisterMCRelocationInfo - Register an MCRelocationInfo
831 /// implementation for the given target.
833 /// Clients are responsible for ensuring that registration doesn't occur
834 /// while another thread is attempting to access the registry. Typically
835 /// this is done by initializing all targets at program startup.
837 /// @param T - The target being registered.
838 /// @param Fn - A function to construct an MCRelocationInfo for the target.
839 static void RegisterMCRelocationInfo(Target &T,
840 Target::MCRelocationInfoCtorTy Fn) {
841 T.MCRelocationInfoCtorFn = Fn;
844 /// RegisterMCSymbolizer - Register an MCSymbolizer
845 /// implementation for the given target.
847 /// Clients are responsible for ensuring that registration doesn't occur
848 /// while another thread is attempting to access the registry. Typically
849 /// this is done by initializing all targets at program startup.
851 /// @param T - The target being registered.
852 /// @param Fn - A function to construct an MCSymbolizer for the target.
853 static void RegisterMCSymbolizer(Target &T, Target::MCSymbolizerCtorTy Fn) {
854 T.MCSymbolizerCtorFn = Fn;
860 //===--------------------------------------------------------------------===//
862 /// RegisterTarget - Helper template for registering a target, for use in the
863 /// target's initialization function. Usage:
866 /// Target TheFooTarget; // The global target instance.
868 /// extern "C" void LLVMInitializeFooTargetInfo() {
869 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
871 template <Triple::ArchType TargetArchType = Triple::UnknownArch,
873 struct RegisterTarget {
874 RegisterTarget(Target &T, const char *Name, const char *Desc) {
875 TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch, HasJIT);
878 static bool getArchMatch(Triple::ArchType Arch) {
879 return Arch == TargetArchType;
883 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
884 /// implementation. This invokes the static "Create" method on the class to
885 /// actually do the construction. Usage:
887 /// extern "C" void LLVMInitializeFooTarget() {
888 /// extern Target TheFooTarget;
889 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
891 template <class MCAsmInfoImpl> struct RegisterMCAsmInfo {
892 RegisterMCAsmInfo(Target &T) {
893 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
897 static MCAsmInfo *Allocator(const MCRegisterInfo & /*MRI*/,
899 return new MCAsmInfoImpl(TT);
903 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
904 /// implementation. This invokes the specified function to do the
905 /// construction. Usage:
907 /// extern "C" void LLVMInitializeFooTarget() {
908 /// extern Target TheFooTarget;
909 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
911 struct RegisterMCAsmInfoFn {
912 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
913 TargetRegistry::RegisterMCAsmInfo(T, Fn);
917 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen
919 /// implementation. This invokes the static "Create" method on the class
920 /// to actually do the construction. Usage:
922 /// extern "C" void LLVMInitializeFooTarget() {
923 /// extern Target TheFooTarget;
924 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
926 template <class MCCodeGenInfoImpl> struct RegisterMCCodeGenInfo {
927 RegisterMCCodeGenInfo(Target &T) {
928 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
932 static MCCodeGenInfo *Allocator(const Triple & /*TT*/, Reloc::Model /*RM*/,
933 CodeModel::Model /*CM*/,
934 CodeGenOpt::Level /*OL*/) {
935 return new MCCodeGenInfoImpl();
939 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
940 /// info implementation. This invokes the specified function to do the
941 /// construction. Usage:
943 /// extern "C" void LLVMInitializeFooTarget() {
944 /// extern Target TheFooTarget;
945 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
947 struct RegisterMCCodeGenInfoFn {
948 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
949 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
953 /// RegisterMCInstrInfo - Helper template for registering a target instruction
954 /// info implementation. This invokes the static "Create" method on the class
955 /// to actually do the construction. Usage:
957 /// extern "C" void LLVMInitializeFooTarget() {
958 /// extern Target TheFooTarget;
959 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
961 template <class MCInstrInfoImpl> struct RegisterMCInstrInfo {
962 RegisterMCInstrInfo(Target &T) {
963 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
967 static MCInstrInfo *Allocator() { return new MCInstrInfoImpl(); }
970 /// RegisterMCInstrInfoFn - Helper template for registering a target
971 /// instruction info implementation. This invokes the specified function to
972 /// do the construction. Usage:
974 /// extern "C" void LLVMInitializeFooTarget() {
975 /// extern Target TheFooTarget;
976 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
978 struct RegisterMCInstrInfoFn {
979 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
980 TargetRegistry::RegisterMCInstrInfo(T, Fn);
984 /// RegisterMCInstrAnalysis - Helper template for registering a target
985 /// instruction analyzer implementation. This invokes the static "Create"
986 /// method on the class to actually do the construction. Usage:
988 /// extern "C" void LLVMInitializeFooTarget() {
989 /// extern Target TheFooTarget;
990 /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
992 template <class MCInstrAnalysisImpl> struct RegisterMCInstrAnalysis {
993 RegisterMCInstrAnalysis(Target &T) {
994 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
998 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
999 return new MCInstrAnalysisImpl(Info);
1003 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
1004 /// instruction analyzer implementation. This invokes the specified function
1005 /// to do the construction. Usage:
1007 /// extern "C" void LLVMInitializeFooTarget() {
1008 /// extern Target TheFooTarget;
1009 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
1011 struct RegisterMCInstrAnalysisFn {
1012 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
1013 TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
1017 /// RegisterMCRegInfo - Helper template for registering a target register info
1018 /// implementation. This invokes the static "Create" method on the class to
1019 /// actually do the construction. Usage:
1021 /// extern "C" void LLVMInitializeFooTarget() {
1022 /// extern Target TheFooTarget;
1023 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
1025 template <class MCRegisterInfoImpl> struct RegisterMCRegInfo {
1026 RegisterMCRegInfo(Target &T) {
1027 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
1031 static MCRegisterInfo *Allocator(const Triple & /*TT*/) {
1032 return new MCRegisterInfoImpl();
1036 /// RegisterMCRegInfoFn - Helper template for registering a target register
1037 /// info implementation. This invokes the specified function to do the
1038 /// construction. Usage:
1040 /// extern "C" void LLVMInitializeFooTarget() {
1041 /// extern Target TheFooTarget;
1042 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
1044 struct RegisterMCRegInfoFn {
1045 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
1046 TargetRegistry::RegisterMCRegInfo(T, Fn);
1050 /// RegisterMCSubtargetInfo - Helper template for registering a target
1051 /// subtarget info implementation. This invokes the static "Create" method
1052 /// on the class to actually do the construction. Usage:
1054 /// extern "C" void LLVMInitializeFooTarget() {
1055 /// extern Target TheFooTarget;
1056 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
1058 template <class MCSubtargetInfoImpl> struct RegisterMCSubtargetInfo {
1059 RegisterMCSubtargetInfo(Target &T) {
1060 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
1064 static MCSubtargetInfo *Allocator(const Triple & /*TT*/, StringRef /*CPU*/,
1066 return new MCSubtargetInfoImpl();
1070 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
1071 /// subtarget info implementation. This invokes the specified function to
1072 /// do the construction. Usage:
1074 /// extern "C" void LLVMInitializeFooTarget() {
1075 /// extern Target TheFooTarget;
1076 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1078 struct RegisterMCSubtargetInfoFn {
1079 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
1080 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
1084 /// RegisterTargetMachine - Helper template for registering a target machine
1085 /// implementation, for use in the target machine initialization
1086 /// function. Usage:
1088 /// extern "C" void LLVMInitializeFooTarget() {
1089 /// extern Target TheFooTarget;
1090 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1092 template <class TargetMachineImpl> struct RegisterTargetMachine {
1093 RegisterTargetMachine(Target &T) {
1094 TargetRegistry::RegisterTargetMachine(T, &Allocator);
1098 static TargetMachine *Allocator(const Target &T, const Triple &TT,
1099 StringRef CPU, StringRef FS,
1100 const TargetOptions &Options, Reloc::Model RM,
1101 CodeModel::Model CM, CodeGenOpt::Level OL) {
1102 return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
1106 /// RegisterMCAsmBackend - Helper template for registering a target specific
1107 /// assembler backend. Usage:
1109 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1110 /// extern Target TheFooTarget;
1111 /// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1113 template <class MCAsmBackendImpl> struct RegisterMCAsmBackend {
1114 RegisterMCAsmBackend(Target &T) {
1115 TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1119 static MCAsmBackend *Allocator(const Target &T, const MCRegisterInfo &MRI,
1120 const Triple &TheTriple, StringRef CPU) {
1121 return new MCAsmBackendImpl(T, MRI, TheTriple, CPU);
1125 /// RegisterMCAsmParser - Helper template for registering a target specific
1126 /// assembly parser, for use in the target machine initialization
1127 /// function. Usage:
1129 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1130 /// extern Target TheFooTarget;
1131 /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1133 template <class MCAsmParserImpl> struct RegisterMCAsmParser {
1134 RegisterMCAsmParser(Target &T) {
1135 TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1139 static MCTargetAsmParser *Allocator(const MCSubtargetInfo &STI,
1140 MCAsmParser &P, const MCInstrInfo &MII,
1141 const MCTargetOptions &Options) {
1142 return new MCAsmParserImpl(STI, P, MII, Options);
1146 /// RegisterAsmPrinter - Helper template for registering a target specific
1147 /// assembly printer, for use in the target machine initialization
1148 /// function. Usage:
1150 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1151 /// extern Target TheFooTarget;
1152 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1154 template <class AsmPrinterImpl> struct RegisterAsmPrinter {
1155 RegisterAsmPrinter(Target &T) {
1156 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1160 static AsmPrinter *Allocator(TargetMachine &TM,
1161 std::unique_ptr<MCStreamer> &&Streamer) {
1162 return new AsmPrinterImpl(TM, std::move(Streamer));
1166 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1167 /// machine code emitter, for use in the target initialization
1168 /// function. Usage:
1170 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1171 /// extern Target TheFooTarget;
1172 /// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1174 template <class MCCodeEmitterImpl> struct RegisterMCCodeEmitter {
1175 RegisterMCCodeEmitter(Target &T) {
1176 TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1180 static MCCodeEmitter *Allocator(const MCInstrInfo & /*II*/,
1181 const MCRegisterInfo & /*MRI*/,
1182 MCContext & /*Ctx*/) {
1183 return new MCCodeEmitterImpl();