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"
39 class MCInstrAnalysis;
44 class MCSubtargetInfo;
46 class MCRelocationInfo;
47 class MCTargetAsmParser;
48 class MCTargetOptions;
52 class formatted_raw_ostream;
54 MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
55 bool isVerboseAsm, bool useCFI,
56 bool useDwarfDirectory,
57 MCInstPrinter *InstPrint, MCCodeEmitter *CE,
58 MCAsmBackend *TAB, bool ShowInst);
60 MCRelocationInfo *createMCRelocationInfo(StringRef TT, MCContext &Ctx);
62 MCSymbolizer *createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
63 LLVMSymbolLookupCallback SymbolLookUp,
66 MCRelocationInfo *RelInfo);
68 /// Target - Wrapper for Target specific information.
70 /// For registration purposes, this is a POD type so that targets can be
71 /// registered without the use of static constructors.
73 /// Targets should implement a single global instance of this class (which
74 /// will be zero initialized), and pass that instance to the TargetRegistry as
75 /// part of their initialization.
78 friend struct TargetRegistry;
80 typedef bool (*ArchMatchFnTy)(Triple::ArchType Arch);
82 typedef MCAsmInfo *(*MCAsmInfoCtorFnTy)(const MCRegisterInfo &MRI,
84 typedef MCCodeGenInfo *(*MCCodeGenInfoCtorFnTy)(StringRef TT,
87 CodeGenOpt::Level OL);
88 typedef MCInstrInfo *(*MCInstrInfoCtorFnTy)(void);
89 typedef MCInstrAnalysis *(*MCInstrAnalysisCtorFnTy)(const MCInstrInfo*Info);
90 typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(StringRef TT);
91 typedef MCSubtargetInfo *(*MCSubtargetInfoCtorFnTy)(StringRef TT,
94 typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T,
98 const TargetOptions &Options,
101 CodeGenOpt::Level OL);
102 typedef AsmPrinter *(*AsmPrinterCtorTy)(TargetMachine &TM,
103 MCStreamer &Streamer);
104 typedef MCAsmBackend *(*MCAsmBackendCtorTy)(const Target &T,
105 const MCRegisterInfo &MRI,
108 typedef MCTargetAsmParser *(*MCAsmParserCtorTy)(
109 MCSubtargetInfo &STI,
111 const MCInstrInfo &MII,
112 const MCTargetOptions &Options);
113 typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T,
114 const MCSubtargetInfo &STI,
116 typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
117 unsigned SyntaxVariant,
118 const MCAsmInfo &MAI,
119 const MCInstrInfo &MII,
120 const MCRegisterInfo &MRI,
121 const MCSubtargetInfo &STI);
122 typedef MCCodeEmitter *(*MCCodeEmitterCtorTy)(const MCInstrInfo &II,
123 const MCRegisterInfo &MRI,
124 const MCSubtargetInfo &STI,
126 typedef MCStreamer *(*MCObjectStreamerCtorTy)(const Target &T,
131 MCCodeEmitter *_Emitter,
132 const MCSubtargetInfo &STI,
135 typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx,
136 formatted_raw_ostream &OS,
139 bool useDwarfDirectory,
140 MCInstPrinter *InstPrint,
144 typedef MCRelocationInfo *(*MCRelocationInfoCtorTy)(StringRef TT,
146 typedef MCSymbolizer *(*MCSymbolizerCtorTy)(StringRef TT,
147 LLVMOpInfoCallback GetOpInfo,
148 LLVMSymbolLookupCallback SymbolLookUp,
151 MCRelocationInfo *RelInfo);
154 /// Next - The next registered target in the linked list, maintained by the
158 /// The target function for checking if an architecture is supported.
159 ArchMatchFnTy ArchMatchFn;
161 /// Name - The target name.
164 /// ShortDesc - A short description of the target.
165 const char *ShortDesc;
167 /// HasJIT - Whether this target supports the JIT.
170 /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
172 MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
174 /// MCCodeGenInfoCtorFn - Constructor function for this target's
175 /// MCCodeGenInfo, if registered.
176 MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn;
178 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
180 MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
182 /// MCInstrAnalysisCtorFn - Constructor function for this target's
183 /// MCInstrAnalysis, if registered.
184 MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
186 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
188 MCRegInfoCtorFnTy MCRegInfoCtorFn;
190 /// MCSubtargetInfoCtorFn - Constructor function for this target's
191 /// MCSubtargetInfo, if registered.
192 MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
194 /// TargetMachineCtorFn - Construction function for this target's
195 /// TargetMachine, if registered.
196 TargetMachineCtorTy TargetMachineCtorFn;
198 /// MCAsmBackendCtorFn - Construction function for this target's
199 /// MCAsmBackend, if registered.
200 MCAsmBackendCtorTy MCAsmBackendCtorFn;
202 /// MCAsmParserCtorFn - Construction function for this target's
203 /// MCTargetAsmParser, if registered.
204 MCAsmParserCtorTy MCAsmParserCtorFn;
206 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
208 AsmPrinterCtorTy AsmPrinterCtorFn;
210 /// MCDisassemblerCtorFn - Construction function for this target's
211 /// MCDisassembler, if registered.
212 MCDisassemblerCtorTy MCDisassemblerCtorFn;
214 /// MCInstPrinterCtorFn - Construction function for this target's
215 /// MCInstPrinter, if registered.
216 MCInstPrinterCtorTy MCInstPrinterCtorFn;
218 /// MCCodeEmitterCtorFn - Construction function for this target's
219 /// CodeEmitter, if registered.
220 MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
222 /// MCObjectStreamerCtorFn - Construction function for this target's
223 /// MCObjectStreamer, if registered.
224 MCObjectStreamerCtorTy MCObjectStreamerCtorFn;
226 /// AsmStreamerCtorFn - Construction function for this target's
227 /// AsmStreamer, if registered (default = llvm::createAsmStreamer).
228 AsmStreamerCtorTy AsmStreamerCtorFn;
230 /// MCRelocationInfoCtorFn - Construction function for this target's
231 /// MCRelocationInfo, if registered (default = llvm::createMCRelocationInfo)
232 MCRelocationInfoCtorTy MCRelocationInfoCtorFn;
234 /// MCSymbolizerCtorFn - Construction function for this target's
235 /// MCSymbolizer, if registered (default = llvm::createMCSymbolizer)
236 MCSymbolizerCtorTy MCSymbolizerCtorFn;
240 : AsmStreamerCtorFn(nullptr), MCRelocationInfoCtorFn(nullptr),
241 MCSymbolizerCtorFn(nullptr) {}
243 /// @name Target Information
246 // getNext - Return the next registered target.
247 const Target *getNext() const { return Next; }
249 /// getName - Get the target name.
250 const char *getName() const { return Name; }
252 /// getShortDescription - Get a short description of the target.
253 const char *getShortDescription() const { return ShortDesc; }
256 /// @name Feature Predicates
259 /// hasJIT - Check if this targets supports the just-in-time compilation.
260 bool hasJIT() const { return HasJIT; }
262 /// hasTargetMachine - Check if this target supports code generation.
263 bool hasTargetMachine() const { return TargetMachineCtorFn != nullptr; }
265 /// hasMCAsmBackend - Check if this target supports .o generation.
266 bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != nullptr; }
269 /// @name Feature Constructors
272 /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
275 /// \param Triple This argument is used to determine the target machine
276 /// feature set; it should always be provided. Generally this should be
277 /// either the target triple from the module, or the target triple of the
278 /// host if that does not exist.
279 MCAsmInfo *createMCAsmInfo(const MCRegisterInfo &MRI,
280 StringRef Triple) const {
281 if (!MCAsmInfoCtorFn)
283 return MCAsmInfoCtorFn(MRI, Triple);
286 /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
288 MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model RM,
290 CodeGenOpt::Level OL) const {
291 if (!MCCodeGenInfoCtorFn)
293 return MCCodeGenInfoCtorFn(Triple, RM, CM, OL);
296 /// createMCInstrInfo - Create a MCInstrInfo implementation.
298 MCInstrInfo *createMCInstrInfo() const {
299 if (!MCInstrInfoCtorFn)
301 return MCInstrInfoCtorFn();
304 /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
306 MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
307 if (!MCInstrAnalysisCtorFn)
309 return MCInstrAnalysisCtorFn(Info);
312 /// createMCRegInfo - Create a MCRegisterInfo implementation.
314 MCRegisterInfo *createMCRegInfo(StringRef Triple) const {
315 if (!MCRegInfoCtorFn)
317 return MCRegInfoCtorFn(Triple);
320 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
322 /// \param Triple This argument is used to determine the target machine
323 /// feature set; it should always be provided. Generally this should be
324 /// either the target triple from the module, or the target triple of the
325 /// host if that does not exist.
326 /// \param CPU This specifies the name of the target CPU.
327 /// \param Features This specifies the string representation of the
328 /// additional target features.
329 MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU,
330 StringRef Features) const {
331 if (!MCSubtargetInfoCtorFn)
333 return MCSubtargetInfoCtorFn(Triple, CPU, Features);
336 /// createTargetMachine - Create a target specific machine implementation
337 /// for the specified \p Triple.
339 /// \param Triple 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 TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU,
344 StringRef Features, const TargetOptions &Options,
345 Reloc::Model RM = Reloc::Default,
346 CodeModel::Model CM = CodeModel::Default,
347 CodeGenOpt::Level OL = CodeGenOpt::Default) const {
348 if (!TargetMachineCtorFn)
350 return TargetMachineCtorFn(*this, Triple, CPU, Features, Options,
354 /// createMCAsmBackend - Create a target specific assembly parser.
356 /// \param Triple The target triple string.
357 MCAsmBackend *createMCAsmBackend(const MCRegisterInfo &MRI,
358 StringRef Triple, StringRef CPU) const {
359 if (!MCAsmBackendCtorFn)
361 return MCAsmBackendCtorFn(*this, MRI, Triple, CPU);
364 /// createMCAsmParser - Create a target specific assembly parser.
366 /// \param Parser The target independent parser implementation to use for
367 /// parsing and lexing.
368 MCTargetAsmParser *createMCAsmParser(
369 MCSubtargetInfo &STI,
371 const MCInstrInfo &MII,
372 const MCTargetOptions &Options) const {
373 if (!MCAsmParserCtorFn)
375 return MCAsmParserCtorFn(STI, Parser, MII, Options);
378 /// createAsmPrinter - Create a target specific assembly printer pass. This
379 /// takes ownership of the MCStreamer object.
380 AsmPrinter *createAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) const{
381 if (!AsmPrinterCtorFn)
383 return AsmPrinterCtorFn(TM, Streamer);
386 MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI,
387 MCContext &Ctx) const {
388 if (!MCDisassemblerCtorFn)
390 return MCDisassemblerCtorFn(*this, STI, Ctx);
393 MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
394 const MCAsmInfo &MAI,
395 const MCInstrInfo &MII,
396 const MCRegisterInfo &MRI,
397 const MCSubtargetInfo &STI) const {
398 if (!MCInstPrinterCtorFn)
400 return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, MII, MRI, STI);
404 /// createMCCodeEmitter - Create a target specific code emitter.
405 MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
406 const MCRegisterInfo &MRI,
407 const MCSubtargetInfo &STI,
408 MCContext &Ctx) const {
409 if (!MCCodeEmitterCtorFn)
411 return MCCodeEmitterCtorFn(II, MRI, STI, Ctx);
414 /// createMCObjectStreamer - Create a target specific MCStreamer.
416 /// \param TT The target triple.
417 /// \param Ctx The target context.
418 /// \param TAB The target assembler backend object. Takes ownership.
419 /// \param _OS The stream object.
420 /// \param _Emitter The target independent assembler object.Takes ownership.
421 /// \param RelaxAll Relax all fixups?
422 /// \param NoExecStack Mark file as not needing a executable stack.
423 MCStreamer *createMCObjectStreamer(StringRef TT, MCContext &Ctx,
426 MCCodeEmitter *_Emitter,
427 const MCSubtargetInfo &STI,
429 bool NoExecStack) const {
430 if (!MCObjectStreamerCtorFn)
432 return MCObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter, STI,
433 RelaxAll, NoExecStack);
436 /// createAsmStreamer - Create a target specific MCStreamer.
437 MCStreamer *createAsmStreamer(MCContext &Ctx,
438 formatted_raw_ostream &OS,
441 bool useDwarfDirectory,
442 MCInstPrinter *InstPrint,
445 bool ShowInst) const {
446 if (AsmStreamerCtorFn)
447 return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useCFI,
448 useDwarfDirectory, InstPrint, CE, TAB,
450 return llvm::createAsmStreamer(Ctx, OS, isVerboseAsm, useCFI,
451 useDwarfDirectory, InstPrint, CE, TAB,
455 /// createMCRelocationInfo - Create a target specific MCRelocationInfo.
457 /// \param TT The target triple.
458 /// \param Ctx The target context.
460 createMCRelocationInfo(StringRef TT, MCContext &Ctx) const {
461 MCRelocationInfoCtorTy Fn = MCRelocationInfoCtorFn
462 ? MCRelocationInfoCtorFn
463 : llvm::createMCRelocationInfo;
467 /// createMCSymbolizer - Create a target specific MCSymbolizer.
469 /// \param TT The target triple.
470 /// \param GetOpInfo The function to get the symbolic information for operands.
471 /// \param SymbolLookUp The function to lookup a symbol name.
472 /// \param DisInfo The pointer to the block of symbolic information for above call
474 /// \param Ctx The target context.
475 /// \param RelInfo The relocation information for this target. Takes ownership.
477 createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
478 LLVMSymbolLookupCallback SymbolLookUp,
480 MCContext *Ctx, MCRelocationInfo *RelInfo) const {
481 MCSymbolizerCtorTy Fn =
482 MCSymbolizerCtorFn ? MCSymbolizerCtorFn : llvm::createMCSymbolizer;
483 return Fn(TT, GetOpInfo, SymbolLookUp, DisInfo, Ctx, RelInfo);
489 /// TargetRegistry - Generic interface to target specific features.
490 struct TargetRegistry {
492 const Target *Current;
493 explicit iterator(Target *T) : Current(T) {}
494 friend struct TargetRegistry;
496 iterator() : Current(nullptr) {}
498 bool operator==(const iterator &x) const {
499 return Current == x.Current;
501 bool operator!=(const iterator &x) const {
502 return !operator==(x);
505 // Iterator traversal: forward iteration only
506 iterator &operator++() { // Preincrement
507 assert(Current && "Cannot increment end iterator!");
508 Current = Current->getNext();
511 iterator operator++(int) { // Postincrement
512 iterator tmp = *this;
517 const Target &operator*() const {
518 assert(Current && "Cannot dereference end iterator!");
522 const Target *operator->() const {
527 /// printRegisteredTargetsForVersion - Print the registered targets
528 /// appropriately for inclusion in a tool's version output.
529 static void printRegisteredTargetsForVersion();
531 /// @name Registry Access
534 static iterator begin();
536 static iterator end() { return iterator(); }
538 /// lookupTarget - Lookup a target based on a target triple.
540 /// \param Triple - The triple to use for finding a target.
541 /// \param Error - On failure, an error string describing why no target was
543 static const Target *lookupTarget(const std::string &Triple,
546 /// lookupTarget - Lookup a target based on an architecture name
547 /// and a target triple. If the architecture name is non-empty,
548 /// then the lookup is done by architecture. Otherwise, the target
551 /// \param ArchName - The architecture to use for finding a target.
552 /// \param TheTriple - The triple to use for finding a target. The
553 /// triple is updated with canonical architecture name if a lookup
554 /// by architecture is done.
555 /// \param Error - On failure, an error string describing why no target was
557 static const Target *lookupTarget(const std::string &ArchName,
561 /// getClosestTargetForJIT - Pick the best target that is compatible with
562 /// the current host. If no close target can be found, this returns null
563 /// and sets the Error string to a reason.
565 /// Maintained for compatibility through 2.6.
566 static const Target *getClosestTargetForJIT(std::string &Error);
569 /// @name Target Registration
572 /// RegisterTarget - Register the given target. Attempts to register a
573 /// target which has already been registered will be ignored.
575 /// Clients are responsible for ensuring that registration doesn't occur
576 /// while another thread is attempting to access the registry. Typically
577 /// this is done by initializing all targets at program startup.
579 /// @param T - The target being registered.
580 /// @param Name - The target name. This should be a static string.
581 /// @param ShortDesc - A short target description. This should be a static
583 /// @param ArchMatchFn - The arch match checking function for this target.
584 /// @param HasJIT - Whether the target supports JIT code
586 static void RegisterTarget(Target &T,
588 const char *ShortDesc,
589 Target::ArchMatchFnTy ArchMatchFn,
590 bool HasJIT = false);
592 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
595 /// Clients are responsible for ensuring that registration doesn't occur
596 /// while another thread is attempting to access the registry. Typically
597 /// this is done by initializing all targets at program startup.
599 /// @param T - The target being registered.
600 /// @param Fn - A function to construct a MCAsmInfo for the target.
601 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
602 T.MCAsmInfoCtorFn = Fn;
605 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
608 /// Clients are responsible for ensuring that registration doesn't occur
609 /// while another thread is attempting to access the registry. Typically
610 /// this is done by initializing all targets at program startup.
612 /// @param T - The target being registered.
613 /// @param Fn - A function to construct a MCCodeGenInfo for the target.
614 static void RegisterMCCodeGenInfo(Target &T,
615 Target::MCCodeGenInfoCtorFnTy Fn) {
616 T.MCCodeGenInfoCtorFn = Fn;
619 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
622 /// Clients are responsible for ensuring that registration doesn't occur
623 /// while another thread is attempting to access the registry. Typically
624 /// this is done by initializing all targets at program startup.
626 /// @param T - The target being registered.
627 /// @param Fn - A function to construct a MCInstrInfo for the target.
628 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
629 T.MCInstrInfoCtorFn = Fn;
632 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
633 /// the given target.
634 static void RegisterMCInstrAnalysis(Target &T,
635 Target::MCInstrAnalysisCtorFnTy Fn) {
636 T.MCInstrAnalysisCtorFn = Fn;
639 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
642 /// Clients are responsible for ensuring that registration doesn't occur
643 /// while another thread is attempting to access the registry. Typically
644 /// this is done by initializing all targets at program startup.
646 /// @param T - The target being registered.
647 /// @param Fn - A function to construct a MCRegisterInfo for the target.
648 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
649 T.MCRegInfoCtorFn = Fn;
652 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
653 /// the given target.
655 /// Clients are responsible for ensuring that registration doesn't occur
656 /// while another thread is attempting to access the registry. Typically
657 /// this is done by initializing all targets at program startup.
659 /// @param T - The target being registered.
660 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
661 static void RegisterMCSubtargetInfo(Target &T,
662 Target::MCSubtargetInfoCtorFnTy Fn) {
663 T.MCSubtargetInfoCtorFn = Fn;
666 /// RegisterTargetMachine - Register a TargetMachine 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 TargetMachine for the target.
675 static void RegisterTargetMachine(Target &T,
676 Target::TargetMachineCtorTy Fn) {
677 T.TargetMachineCtorFn = Fn;
680 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
683 /// Clients are responsible for ensuring that registration doesn't occur
684 /// while another thread is attempting to access the registry. Typically
685 /// this is done by initializing all targets at program startup.
687 /// @param T - The target being registered.
688 /// @param Fn - A function to construct an AsmBackend for the target.
689 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
690 T.MCAsmBackendCtorFn = Fn;
693 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
694 /// the given target.
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 an MCTargetAsmParser for the target.
702 static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
703 T.MCAsmParserCtorFn = Fn;
706 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
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 AsmPrinter for the target.
715 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
716 T.AsmPrinterCtorFn = Fn;
719 /// RegisterMCDisassembler - Register a MCDisassembler 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 MCDisassembler for the target.
728 static void RegisterMCDisassembler(Target &T,
729 Target::MCDisassemblerCtorTy Fn) {
730 T.MCDisassemblerCtorFn = Fn;
733 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
736 /// Clients are responsible for ensuring that registration doesn't occur
737 /// while another thread is attempting to access the registry. Typically
738 /// this is done by initializing all targets at program startup.
740 /// @param T - The target being registered.
741 /// @param Fn - A function to construct an MCInstPrinter for the target.
742 static void RegisterMCInstPrinter(Target &T,
743 Target::MCInstPrinterCtorTy Fn) {
744 T.MCInstPrinterCtorFn = Fn;
747 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
750 /// Clients are responsible for ensuring that registration doesn't occur
751 /// while another thread is attempting to access the registry. Typically
752 /// this is done by initializing all targets at program startup.
754 /// @param T - The target being registered.
755 /// @param Fn - A function to construct an MCCodeEmitter for the target.
756 static void RegisterMCCodeEmitter(Target &T,
757 Target::MCCodeEmitterCtorTy Fn) {
758 T.MCCodeEmitterCtorFn = Fn;
761 /// RegisterMCObjectStreamer - Register a object code MCStreamer
762 /// implementation for the given target.
764 /// Clients are responsible for ensuring that registration doesn't occur
765 /// while another thread is attempting to access the registry. Typically
766 /// this is done by initializing all targets at program startup.
768 /// @param T - The target being registered.
769 /// @param Fn - A function to construct an MCStreamer for the target.
770 static void RegisterMCObjectStreamer(Target &T,
771 Target::MCObjectStreamerCtorTy Fn) {
772 T.MCObjectStreamerCtorFn = Fn;
775 /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
776 /// for the given target.
778 /// Clients are responsible for ensuring that registration doesn't occur
779 /// while another thread is attempting to access the registry. Typically
780 /// this is done by initializing all targets at program startup.
782 /// @param T - The target being registered.
783 /// @param Fn - A function to construct an MCStreamer for the target.
784 static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
785 T.AsmStreamerCtorFn = Fn;
788 /// RegisterMCRelocationInfo - Register an MCRelocationInfo
789 /// implementation for the given target.
791 /// Clients are responsible for ensuring that registration doesn't occur
792 /// while another thread is attempting to access the registry. Typically
793 /// this is done by initializing all targets at program startup.
795 /// @param T - The target being registered.
796 /// @param Fn - A function to construct an MCRelocationInfo for the target.
797 static void RegisterMCRelocationInfo(Target &T,
798 Target::MCRelocationInfoCtorTy Fn) {
799 T.MCRelocationInfoCtorFn = Fn;
802 /// RegisterMCSymbolizer - Register an MCSymbolizer
803 /// implementation for the given target.
805 /// Clients are responsible for ensuring that registration doesn't occur
806 /// while another thread is attempting to access the registry. Typically
807 /// this is done by initializing all targets at program startup.
809 /// @param T - The target being registered.
810 /// @param Fn - A function to construct an MCSymbolizer for the target.
811 static void RegisterMCSymbolizer(Target &T,
812 Target::MCSymbolizerCtorTy Fn) {
813 T.MCSymbolizerCtorFn = Fn;
820 //===--------------------------------------------------------------------===//
822 /// RegisterTarget - Helper template for registering a target, for use in the
823 /// target's initialization function. Usage:
826 /// Target TheFooTarget; // The global target instance.
828 /// extern "C" void LLVMInitializeFooTargetInfo() {
829 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
831 template<Triple::ArchType TargetArchType = Triple::UnknownArch,
833 struct RegisterTarget {
834 RegisterTarget(Target &T, const char *Name, const char *Desc) {
835 TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch, HasJIT);
838 static bool getArchMatch(Triple::ArchType Arch) {
839 return Arch == TargetArchType;
843 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
844 /// implementation. This invokes the static "Create" method on the class to
845 /// actually do the construction. Usage:
847 /// extern "C" void LLVMInitializeFooTarget() {
848 /// extern Target TheFooTarget;
849 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
851 template<class MCAsmInfoImpl>
852 struct RegisterMCAsmInfo {
853 RegisterMCAsmInfo(Target &T) {
854 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
857 static MCAsmInfo *Allocator(const MCRegisterInfo &/*MRI*/, StringRef TT) {
858 return new MCAsmInfoImpl(TT);
863 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
864 /// implementation. This invokes the specified function to do the
865 /// construction. Usage:
867 /// extern "C" void LLVMInitializeFooTarget() {
868 /// extern Target TheFooTarget;
869 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
871 struct RegisterMCAsmInfoFn {
872 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
873 TargetRegistry::RegisterMCAsmInfo(T, Fn);
877 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
878 /// implementation. This invokes the static "Create" method on the class
879 /// to actually do the construction. Usage:
881 /// extern "C" void LLVMInitializeFooTarget() {
882 /// extern Target TheFooTarget;
883 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
885 template<class MCCodeGenInfoImpl>
886 struct RegisterMCCodeGenInfo {
887 RegisterMCCodeGenInfo(Target &T) {
888 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
891 static MCCodeGenInfo *Allocator(StringRef /*TT*/, Reloc::Model /*RM*/,
892 CodeModel::Model /*CM*/,
893 CodeGenOpt::Level /*OL*/) {
894 return new MCCodeGenInfoImpl();
898 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
899 /// info implementation. This invokes the specified function to do the
900 /// construction. Usage:
902 /// extern "C" void LLVMInitializeFooTarget() {
903 /// extern Target TheFooTarget;
904 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
906 struct RegisterMCCodeGenInfoFn {
907 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
908 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
912 /// RegisterMCInstrInfo - Helper template for registering a target instruction
913 /// info implementation. This invokes the static "Create" method on the class
914 /// to actually do the construction. Usage:
916 /// extern "C" void LLVMInitializeFooTarget() {
917 /// extern Target TheFooTarget;
918 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
920 template<class MCInstrInfoImpl>
921 struct RegisterMCInstrInfo {
922 RegisterMCInstrInfo(Target &T) {
923 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
926 static MCInstrInfo *Allocator() {
927 return new MCInstrInfoImpl();
931 /// RegisterMCInstrInfoFn - Helper template for registering a target
932 /// instruction info implementation. This invokes the specified function to
933 /// do the construction. Usage:
935 /// extern "C" void LLVMInitializeFooTarget() {
936 /// extern Target TheFooTarget;
937 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
939 struct RegisterMCInstrInfoFn {
940 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
941 TargetRegistry::RegisterMCInstrInfo(T, Fn);
945 /// RegisterMCInstrAnalysis - Helper template for registering a target
946 /// instruction analyzer implementation. This invokes the static "Create"
947 /// method on the class to actually do the construction. Usage:
949 /// extern "C" void LLVMInitializeFooTarget() {
950 /// extern Target TheFooTarget;
951 /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
953 template<class MCInstrAnalysisImpl>
954 struct RegisterMCInstrAnalysis {
955 RegisterMCInstrAnalysis(Target &T) {
956 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
959 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
960 return new MCInstrAnalysisImpl(Info);
964 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
965 /// instruction analyzer implementation. This invokes the specified function
966 /// to do the construction. Usage:
968 /// extern "C" void LLVMInitializeFooTarget() {
969 /// extern Target TheFooTarget;
970 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
972 struct RegisterMCInstrAnalysisFn {
973 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
974 TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
978 /// RegisterMCRegInfo - Helper template for registering a target register info
979 /// implementation. This invokes the static "Create" method on the class to
980 /// actually do the construction. Usage:
982 /// extern "C" void LLVMInitializeFooTarget() {
983 /// extern Target TheFooTarget;
984 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
986 template<class MCRegisterInfoImpl>
987 struct RegisterMCRegInfo {
988 RegisterMCRegInfo(Target &T) {
989 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
992 static MCRegisterInfo *Allocator(StringRef /*TT*/) {
993 return new MCRegisterInfoImpl();
997 /// RegisterMCRegInfoFn - Helper template for registering a target register
998 /// info implementation. This invokes the specified function to do the
999 /// construction. Usage:
1001 /// extern "C" void LLVMInitializeFooTarget() {
1002 /// extern Target TheFooTarget;
1003 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
1005 struct RegisterMCRegInfoFn {
1006 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
1007 TargetRegistry::RegisterMCRegInfo(T, Fn);
1011 /// RegisterMCSubtargetInfo - Helper template for registering a target
1012 /// subtarget info implementation. This invokes the static "Create" method
1013 /// on the class to actually do the construction. Usage:
1015 /// extern "C" void LLVMInitializeFooTarget() {
1016 /// extern Target TheFooTarget;
1017 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
1019 template<class MCSubtargetInfoImpl>
1020 struct RegisterMCSubtargetInfo {
1021 RegisterMCSubtargetInfo(Target &T) {
1022 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
1025 static MCSubtargetInfo *Allocator(StringRef /*TT*/, StringRef /*CPU*/,
1027 return new MCSubtargetInfoImpl();
1031 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
1032 /// subtarget info implementation. This invokes the specified function to
1033 /// do the construction. Usage:
1035 /// extern "C" void LLVMInitializeFooTarget() {
1036 /// extern Target TheFooTarget;
1037 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1039 struct RegisterMCSubtargetInfoFn {
1040 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
1041 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
1045 /// RegisterTargetMachine - Helper template for registering a target machine
1046 /// implementation, for use in the target machine initialization
1047 /// function. Usage:
1049 /// extern "C" void LLVMInitializeFooTarget() {
1050 /// extern Target TheFooTarget;
1051 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1053 template<class TargetMachineImpl>
1054 struct RegisterTargetMachine {
1055 RegisterTargetMachine(Target &T) {
1056 TargetRegistry::RegisterTargetMachine(T, &Allocator);
1060 static TargetMachine *Allocator(const Target &T, StringRef TT,
1061 StringRef CPU, StringRef FS,
1062 const TargetOptions &Options,
1064 CodeModel::Model CM,
1065 CodeGenOpt::Level OL) {
1066 return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
1070 /// RegisterMCAsmBackend - Helper template for registering a target specific
1071 /// assembler backend. Usage:
1073 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1074 /// extern Target TheFooTarget;
1075 /// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1077 template<class MCAsmBackendImpl>
1078 struct RegisterMCAsmBackend {
1079 RegisterMCAsmBackend(Target &T) {
1080 TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1084 static MCAsmBackend *Allocator(const Target &T,
1085 const MCRegisterInfo &MRI,
1086 StringRef Triple, StringRef CPU) {
1087 return new MCAsmBackendImpl(T, MRI, Triple, CPU);
1091 /// RegisterMCAsmParser - Helper template for registering a target specific
1092 /// assembly parser, for use in the target machine initialization
1093 /// function. Usage:
1095 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1096 /// extern Target TheFooTarget;
1097 /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1099 template<class MCAsmParserImpl>
1100 struct RegisterMCAsmParser {
1101 RegisterMCAsmParser(Target &T) {
1102 TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1106 static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P,
1107 const MCInstrInfo &MII,
1108 const MCTargetOptions &Options) {
1109 return new MCAsmParserImpl(STI, P, MII, Options);
1113 /// RegisterAsmPrinter - Helper template for registering a target specific
1114 /// assembly printer, for use in the target machine initialization
1115 /// function. Usage:
1117 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1118 /// extern Target TheFooTarget;
1119 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1121 template<class AsmPrinterImpl>
1122 struct RegisterAsmPrinter {
1123 RegisterAsmPrinter(Target &T) {
1124 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1128 static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) {
1129 return new AsmPrinterImpl(TM, Streamer);
1133 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1134 /// machine code emitter, for use in the target initialization
1135 /// function. Usage:
1137 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1138 /// extern Target TheFooTarget;
1139 /// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1141 template<class MCCodeEmitterImpl>
1142 struct RegisterMCCodeEmitter {
1143 RegisterMCCodeEmitter(Target &T) {
1144 TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1148 static MCCodeEmitter *Allocator(const MCInstrInfo &/*II*/,
1149 const MCRegisterInfo &/*MRI*/,
1150 const MCSubtargetInfo &/*STI*/,
1151 MCContext &/*Ctx*/) {
1152 return new MCCodeEmitterImpl();