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;
51 class formatted_raw_ostream;
53 MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
54 bool isVerboseAsm, bool useCFI,
55 bool useDwarfDirectory,
56 MCInstPrinter *InstPrint, MCCodeEmitter *CE,
57 MCAsmBackend *TAB, bool ShowInst);
59 MCRelocationInfo *createMCRelocationInfo(StringRef TT, MCContext &Ctx);
61 MCSymbolizer *createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
62 LLVMSymbolLookupCallback SymbolLookUp,
65 MCRelocationInfo *RelInfo);
67 /// Target - Wrapper for Target specific information.
69 /// For registration purposes, this is a POD type so that targets can be
70 /// registered without the use of static constructors.
72 /// Targets should implement a single global instance of this class (which
73 /// will be zero initialized), and pass that instance to the TargetRegistry as
74 /// part of their initialization.
77 friend struct TargetRegistry;
79 typedef bool (*ArchMatchFnTy)(Triple::ArchType Arch);
81 typedef MCAsmInfo *(*MCAsmInfoCtorFnTy)(const MCRegisterInfo &MRI,
83 typedef MCCodeGenInfo *(*MCCodeGenInfoCtorFnTy)(StringRef TT,
86 CodeGenOpt::Level OL);
87 typedef MCInstrInfo *(*MCInstrInfoCtorFnTy)(void);
88 typedef MCInstrAnalysis *(*MCInstrAnalysisCtorFnTy)(const MCInstrInfo*Info);
89 typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(StringRef TT);
90 typedef MCSubtargetInfo *(*MCSubtargetInfoCtorFnTy)(StringRef TT,
93 typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T,
97 const TargetOptions &Options,
100 CodeGenOpt::Level OL);
101 typedef AsmPrinter *(*AsmPrinterCtorTy)(TargetMachine &TM,
102 MCStreamer &Streamer);
103 typedef MCAsmBackend *(*MCAsmBackendCtorTy)(const Target &T,
104 const MCRegisterInfo &MRI,
107 typedef MCTargetAsmParser *(*MCAsmParserCtorTy)(MCSubtargetInfo &STI,
109 const MCInstrInfo &MII);
110 typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T,
111 const MCSubtargetInfo &STI);
112 typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
113 unsigned SyntaxVariant,
114 const MCAsmInfo &MAI,
115 const MCInstrInfo &MII,
116 const MCRegisterInfo &MRI,
117 const MCSubtargetInfo &STI);
118 typedef MCCodeEmitter *(*MCCodeEmitterCtorTy)(const MCInstrInfo &II,
119 const MCRegisterInfo &MRI,
120 const MCSubtargetInfo &STI,
122 typedef MCStreamer *(*MCObjectStreamerCtorTy)(const Target &T,
127 MCCodeEmitter *_Emitter,
128 const MCSubtargetInfo &STI,
131 typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx,
132 formatted_raw_ostream &OS,
135 bool useDwarfDirectory,
136 MCInstPrinter *InstPrint,
140 typedef MCRelocationInfo *(*MCRelocationInfoCtorTy)(StringRef TT,
142 typedef MCSymbolizer *(*MCSymbolizerCtorTy)(StringRef TT,
143 LLVMOpInfoCallback GetOpInfo,
144 LLVMSymbolLookupCallback SymbolLookUp,
147 MCRelocationInfo *RelInfo);
150 /// Next - The next registered target in the linked list, maintained by the
154 /// The target function for checking if an architecture is supported.
155 ArchMatchFnTy ArchMatchFn;
157 /// Name - The target name.
160 /// ShortDesc - A short description of the target.
161 const char *ShortDesc;
163 /// HasJIT - Whether this target supports the JIT.
166 /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
168 MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
170 /// MCCodeGenInfoCtorFn - Constructor function for this target's
171 /// MCCodeGenInfo, if registered.
172 MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn;
174 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
176 MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
178 /// MCInstrAnalysisCtorFn - Constructor function for this target's
179 /// MCInstrAnalysis, if registered.
180 MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
182 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
184 MCRegInfoCtorFnTy MCRegInfoCtorFn;
186 /// MCSubtargetInfoCtorFn - Constructor function for this target's
187 /// MCSubtargetInfo, if registered.
188 MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
190 /// TargetMachineCtorFn - Construction function for this target's
191 /// TargetMachine, if registered.
192 TargetMachineCtorTy TargetMachineCtorFn;
194 /// MCAsmBackendCtorFn - Construction function for this target's
195 /// MCAsmBackend, if registered.
196 MCAsmBackendCtorTy MCAsmBackendCtorFn;
198 /// MCAsmParserCtorFn - Construction function for this target's
199 /// MCTargetAsmParser, if registered.
200 MCAsmParserCtorTy MCAsmParserCtorFn;
202 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
204 AsmPrinterCtorTy AsmPrinterCtorFn;
206 /// MCDisassemblerCtorFn - Construction function for this target's
207 /// MCDisassembler, if registered.
208 MCDisassemblerCtorTy MCDisassemblerCtorFn;
210 /// MCInstPrinterCtorFn - Construction function for this target's
211 /// MCInstPrinter, if registered.
212 MCInstPrinterCtorTy MCInstPrinterCtorFn;
214 /// MCCodeEmitterCtorFn - Construction function for this target's
215 /// CodeEmitter, if registered.
216 MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
218 /// MCObjectStreamerCtorFn - Construction function for this target's
219 /// MCObjectStreamer, if registered.
220 MCObjectStreamerCtorTy MCObjectStreamerCtorFn;
222 /// AsmStreamerCtorFn - Construction function for this target's
223 /// AsmStreamer, if registered (default = llvm::createAsmStreamer).
224 AsmStreamerCtorTy AsmStreamerCtorFn;
226 /// MCRelocationInfoCtorFn - Construction function for this target's
227 /// MCRelocationInfo, if registered (default = llvm::createMCRelocationInfo)
228 MCRelocationInfoCtorTy MCRelocationInfoCtorFn;
230 /// MCSymbolizerCtorFn - Construction function for this target's
231 /// MCSymbolizer, if registered (default = llvm::createMCSymbolizer)
232 MCSymbolizerCtorTy MCSymbolizerCtorFn;
236 : AsmStreamerCtorFn(nullptr), MCRelocationInfoCtorFn(nullptr),
237 MCSymbolizerCtorFn(nullptr) {}
239 /// @name Target Information
242 // getNext - Return the next registered target.
243 const Target *getNext() const { return Next; }
245 /// getName - Get the target name.
246 const char *getName() const { return Name; }
248 /// getShortDescription - Get a short description of the target.
249 const char *getShortDescription() const { return ShortDesc; }
252 /// @name Feature Predicates
255 /// hasJIT - Check if this targets supports the just-in-time compilation.
256 bool hasJIT() const { return HasJIT; }
258 /// hasTargetMachine - Check if this target supports code generation.
259 bool hasTargetMachine() const { return TargetMachineCtorFn != nullptr; }
261 /// hasMCAsmBackend - Check if this target supports .o generation.
262 bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != nullptr; }
265 /// @name Feature Constructors
268 /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
271 /// \param Triple This argument is used to determine the target machine
272 /// feature set; it should always be provided. Generally this should be
273 /// either the target triple from the module, or the target triple of the
274 /// host if that does not exist.
275 MCAsmInfo *createMCAsmInfo(const MCRegisterInfo &MRI,
276 StringRef Triple) const {
277 if (!MCAsmInfoCtorFn)
279 return MCAsmInfoCtorFn(MRI, Triple);
282 /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
284 MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model RM,
286 CodeGenOpt::Level OL) const {
287 if (!MCCodeGenInfoCtorFn)
289 return MCCodeGenInfoCtorFn(Triple, RM, CM, OL);
292 /// createMCInstrInfo - Create a MCInstrInfo implementation.
294 MCInstrInfo *createMCInstrInfo() const {
295 if (!MCInstrInfoCtorFn)
297 return MCInstrInfoCtorFn();
300 /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
302 MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
303 if (!MCInstrAnalysisCtorFn)
305 return MCInstrAnalysisCtorFn(Info);
308 /// createMCRegInfo - Create a MCRegisterInfo implementation.
310 MCRegisterInfo *createMCRegInfo(StringRef Triple) const {
311 if (!MCRegInfoCtorFn)
313 return MCRegInfoCtorFn(Triple);
316 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
318 /// \param Triple This argument is used to determine the target machine
319 /// feature set; it should always be provided. Generally this should be
320 /// either the target triple from the module, or the target triple of the
321 /// host if that does not exist.
322 /// \param CPU This specifies the name of the target CPU.
323 /// \param Features This specifies the string representation of the
324 /// additional target features.
325 MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU,
326 StringRef Features) const {
327 if (!MCSubtargetInfoCtorFn)
329 return MCSubtargetInfoCtorFn(Triple, CPU, Features);
332 /// createTargetMachine - Create a target specific machine implementation
333 /// for the specified \p Triple.
335 /// \param Triple This argument is used to determine the target machine
336 /// feature set; it should always be provided. Generally this should be
337 /// either the target triple from the module, or the target triple of the
338 /// host if that does not exist.
339 TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU,
340 StringRef Features, const TargetOptions &Options,
341 Reloc::Model RM = Reloc::Default,
342 CodeModel::Model CM = CodeModel::Default,
343 CodeGenOpt::Level OL = CodeGenOpt::Default) const {
344 if (!TargetMachineCtorFn)
346 return TargetMachineCtorFn(*this, Triple, CPU, Features, Options,
350 /// createMCAsmBackend - Create a target specific assembly parser.
352 /// \param Triple The target triple string.
353 MCAsmBackend *createMCAsmBackend(const MCRegisterInfo &MRI,
354 StringRef Triple, StringRef CPU) const {
355 if (!MCAsmBackendCtorFn)
357 return MCAsmBackendCtorFn(*this, MRI, Triple, CPU);
360 /// createMCAsmParser - Create a target specific assembly parser.
362 /// \param Parser The target independent parser implementation to use for
363 /// parsing and lexing.
364 MCTargetAsmParser *createMCAsmParser(MCSubtargetInfo &STI,
366 const MCInstrInfo &MII) const {
367 if (!MCAsmParserCtorFn)
369 return MCAsmParserCtorFn(STI, Parser, MII);
372 /// createAsmPrinter - Create a target specific assembly printer pass. This
373 /// takes ownership of the MCStreamer object.
374 AsmPrinter *createAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) const{
375 if (!AsmPrinterCtorFn)
377 return AsmPrinterCtorFn(TM, Streamer);
380 MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI) const {
381 if (!MCDisassemblerCtorFn)
383 return MCDisassemblerCtorFn(*this, STI);
386 MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
387 const MCAsmInfo &MAI,
388 const MCInstrInfo &MII,
389 const MCRegisterInfo &MRI,
390 const MCSubtargetInfo &STI) const {
391 if (!MCInstPrinterCtorFn)
393 return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, MII, MRI, STI);
397 /// createMCCodeEmitter - Create a target specific code emitter.
398 MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
399 const MCRegisterInfo &MRI,
400 const MCSubtargetInfo &STI,
401 MCContext &Ctx) const {
402 if (!MCCodeEmitterCtorFn)
404 return MCCodeEmitterCtorFn(II, MRI, STI, Ctx);
407 /// createMCObjectStreamer - Create a target specific MCStreamer.
409 /// \param TT The target triple.
410 /// \param Ctx The target context.
411 /// \param TAB The target assembler backend object. Takes ownership.
412 /// \param _OS The stream object.
413 /// \param _Emitter The target independent assembler object.Takes ownership.
414 /// \param RelaxAll Relax all fixups?
415 /// \param NoExecStack Mark file as not needing a executable stack.
416 MCStreamer *createMCObjectStreamer(StringRef TT, MCContext &Ctx,
419 MCCodeEmitter *_Emitter,
420 const MCSubtargetInfo &STI,
422 bool NoExecStack) const {
423 if (!MCObjectStreamerCtorFn)
425 return MCObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter, STI,
426 RelaxAll, NoExecStack);
429 /// createAsmStreamer - Create a target specific MCStreamer.
430 MCStreamer *createAsmStreamer(MCContext &Ctx,
431 formatted_raw_ostream &OS,
434 bool useDwarfDirectory,
435 MCInstPrinter *InstPrint,
438 bool ShowInst) const {
439 if (AsmStreamerCtorFn)
440 return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useCFI,
441 useDwarfDirectory, InstPrint, CE, TAB,
443 return llvm::createAsmStreamer(Ctx, OS, isVerboseAsm, useCFI,
444 useDwarfDirectory, InstPrint, CE, TAB,
448 /// createMCRelocationInfo - Create a target specific MCRelocationInfo.
450 /// \param TT The target triple.
451 /// \param Ctx The target context.
453 createMCRelocationInfo(StringRef TT, MCContext &Ctx) const {
454 MCRelocationInfoCtorTy Fn = MCRelocationInfoCtorFn
455 ? MCRelocationInfoCtorFn
456 : llvm::createMCRelocationInfo;
460 /// createMCSymbolizer - Create a target specific MCSymbolizer.
462 /// \param TT The target triple.
463 /// \param GetOpInfo The function to get the symbolic information for operands.
464 /// \param SymbolLookUp The function to lookup a symbol name.
465 /// \param DisInfo The pointer to the block of symbolic information for above call
467 /// \param Ctx The target context.
468 /// \param RelInfo The relocation information for this target. Takes ownership.
470 createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
471 LLVMSymbolLookupCallback SymbolLookUp,
473 MCContext *Ctx, MCRelocationInfo *RelInfo) const {
474 MCSymbolizerCtorTy Fn =
475 MCSymbolizerCtorFn ? MCSymbolizerCtorFn : llvm::createMCSymbolizer;
476 return Fn(TT, GetOpInfo, SymbolLookUp, DisInfo, Ctx, RelInfo);
482 /// TargetRegistry - Generic interface to target specific features.
483 struct TargetRegistry {
485 const Target *Current;
486 explicit iterator(Target *T) : Current(T) {}
487 friend struct TargetRegistry;
489 iterator() : Current(nullptr) {}
491 bool operator==(const iterator &x) const {
492 return Current == x.Current;
494 bool operator!=(const iterator &x) const {
495 return !operator==(x);
498 // Iterator traversal: forward iteration only
499 iterator &operator++() { // Preincrement
500 assert(Current && "Cannot increment end iterator!");
501 Current = Current->getNext();
504 iterator operator++(int) { // Postincrement
505 iterator tmp = *this;
510 const Target &operator*() const {
511 assert(Current && "Cannot dereference end iterator!");
515 const Target *operator->() const {
520 /// printRegisteredTargetsForVersion - Print the registered targets
521 /// appropriately for inclusion in a tool's version output.
522 static void printRegisteredTargetsForVersion();
524 /// @name Registry Access
527 static iterator begin();
529 static iterator end() { return iterator(); }
531 /// lookupTarget - Lookup a target based on a target triple.
533 /// \param Triple - The triple to use for finding a target.
534 /// \param Error - On failure, an error string describing why no target was
536 static const Target *lookupTarget(const std::string &Triple,
539 /// lookupTarget - Lookup a target based on an architecture name
540 /// and a target triple. If the architecture name is non-empty,
541 /// then the lookup is done by architecture. Otherwise, the target
544 /// \param ArchName - The architecture to use for finding a target.
545 /// \param TheTriple - The triple to use for finding a target. The
546 /// triple is updated with canonical architecture name if a lookup
547 /// by architecture is done.
548 /// \param Error - On failure, an error string describing why no target was
550 static const Target *lookupTarget(const std::string &ArchName,
554 /// getClosestTargetForJIT - Pick the best target that is compatible with
555 /// the current host. If no close target can be found, this returns null
556 /// and sets the Error string to a reason.
558 /// Maintained for compatibility through 2.6.
559 static const Target *getClosestTargetForJIT(std::string &Error);
562 /// @name Target Registration
565 /// RegisterTarget - Register the given target. Attempts to register a
566 /// target which has already been registered will be ignored.
568 /// Clients are responsible for ensuring that registration doesn't occur
569 /// while another thread is attempting to access the registry. Typically
570 /// this is done by initializing all targets at program startup.
572 /// @param T - The target being registered.
573 /// @param Name - The target name. This should be a static string.
574 /// @param ShortDesc - A short target description. This should be a static
576 /// @param ArchMatchFn - The arch match checking function for this target.
577 /// @param HasJIT - Whether the target supports JIT code
579 static void RegisterTarget(Target &T,
581 const char *ShortDesc,
582 Target::ArchMatchFnTy ArchMatchFn,
583 bool HasJIT = false);
585 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
588 /// Clients are responsible for ensuring that registration doesn't occur
589 /// while another thread is attempting to access the registry. Typically
590 /// this is done by initializing all targets at program startup.
592 /// @param T - The target being registered.
593 /// @param Fn - A function to construct a MCAsmInfo for the target.
594 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
595 T.MCAsmInfoCtorFn = Fn;
598 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
601 /// Clients are responsible for ensuring that registration doesn't occur
602 /// while another thread is attempting to access the registry. Typically
603 /// this is done by initializing all targets at program startup.
605 /// @param T - The target being registered.
606 /// @param Fn - A function to construct a MCCodeGenInfo for the target.
607 static void RegisterMCCodeGenInfo(Target &T,
608 Target::MCCodeGenInfoCtorFnTy Fn) {
609 T.MCCodeGenInfoCtorFn = Fn;
612 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
615 /// Clients are responsible for ensuring that registration doesn't occur
616 /// while another thread is attempting to access the registry. Typically
617 /// this is done by initializing all targets at program startup.
619 /// @param T - The target being registered.
620 /// @param Fn - A function to construct a MCInstrInfo for the target.
621 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
622 T.MCInstrInfoCtorFn = Fn;
625 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
626 /// the given target.
627 static void RegisterMCInstrAnalysis(Target &T,
628 Target::MCInstrAnalysisCtorFnTy Fn) {
629 T.MCInstrAnalysisCtorFn = Fn;
632 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
635 /// Clients are responsible for ensuring that registration doesn't occur
636 /// while another thread is attempting to access the registry. Typically
637 /// this is done by initializing all targets at program startup.
639 /// @param T - The target being registered.
640 /// @param Fn - A function to construct a MCRegisterInfo for the target.
641 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
642 T.MCRegInfoCtorFn = Fn;
645 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
646 /// the given target.
648 /// Clients are responsible for ensuring that registration doesn't occur
649 /// while another thread is attempting to access the registry. Typically
650 /// this is done by initializing all targets at program startup.
652 /// @param T - The target being registered.
653 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
654 static void RegisterMCSubtargetInfo(Target &T,
655 Target::MCSubtargetInfoCtorFnTy Fn) {
656 T.MCSubtargetInfoCtorFn = Fn;
659 /// RegisterTargetMachine - Register a TargetMachine implementation for the
662 /// Clients are responsible for ensuring that registration doesn't occur
663 /// while another thread is attempting to access the registry. Typically
664 /// this is done by initializing all targets at program startup.
666 /// @param T - The target being registered.
667 /// @param Fn - A function to construct a TargetMachine for the target.
668 static void RegisterTargetMachine(Target &T,
669 Target::TargetMachineCtorTy Fn) {
670 T.TargetMachineCtorFn = Fn;
673 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
676 /// Clients are responsible for ensuring that registration doesn't occur
677 /// while another thread is attempting to access the registry. Typically
678 /// this is done by initializing all targets at program startup.
680 /// @param T - The target being registered.
681 /// @param Fn - A function to construct an AsmBackend for the target.
682 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
683 T.MCAsmBackendCtorFn = Fn;
686 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
687 /// the given target.
689 /// Clients are responsible for ensuring that registration doesn't occur
690 /// while another thread is attempting to access the registry. Typically
691 /// this is done by initializing all targets at program startup.
693 /// @param T - The target being registered.
694 /// @param Fn - A function to construct an MCTargetAsmParser for the target.
695 static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
696 T.MCAsmParserCtorFn = Fn;
699 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
702 /// Clients are responsible for ensuring that registration doesn't occur
703 /// while another thread is attempting to access the registry. Typically
704 /// this is done by initializing all targets at program startup.
706 /// @param T - The target being registered.
707 /// @param Fn - A function to construct an AsmPrinter for the target.
708 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
709 T.AsmPrinterCtorFn = Fn;
712 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
713 /// the given target.
715 /// Clients are responsible for ensuring that registration doesn't occur
716 /// while another thread is attempting to access the registry. Typically
717 /// this is done by initializing all targets at program startup.
719 /// @param T - The target being registered.
720 /// @param Fn - A function to construct an MCDisassembler for the target.
721 static void RegisterMCDisassembler(Target &T,
722 Target::MCDisassemblerCtorTy Fn) {
723 T.MCDisassemblerCtorFn = Fn;
726 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
729 /// Clients are responsible for ensuring that registration doesn't occur
730 /// while another thread is attempting to access the registry. Typically
731 /// this is done by initializing all targets at program startup.
733 /// @param T - The target being registered.
734 /// @param Fn - A function to construct an MCInstPrinter for the target.
735 static void RegisterMCInstPrinter(Target &T,
736 Target::MCInstPrinterCtorTy Fn) {
737 T.MCInstPrinterCtorFn = Fn;
740 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
743 /// Clients are responsible for ensuring that registration doesn't occur
744 /// while another thread is attempting to access the registry. Typically
745 /// this is done by initializing all targets at program startup.
747 /// @param T - The target being registered.
748 /// @param Fn - A function to construct an MCCodeEmitter for the target.
749 static void RegisterMCCodeEmitter(Target &T,
750 Target::MCCodeEmitterCtorTy Fn) {
751 T.MCCodeEmitterCtorFn = Fn;
754 /// RegisterMCObjectStreamer - Register a object code MCStreamer
755 /// implementation for the given target.
757 /// Clients are responsible for ensuring that registration doesn't occur
758 /// while another thread is attempting to access the registry. Typically
759 /// this is done by initializing all targets at program startup.
761 /// @param T - The target being registered.
762 /// @param Fn - A function to construct an MCStreamer for the target.
763 static void RegisterMCObjectStreamer(Target &T,
764 Target::MCObjectStreamerCtorTy Fn) {
765 T.MCObjectStreamerCtorFn = Fn;
768 /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
769 /// for the given target.
771 /// Clients are responsible for ensuring that registration doesn't occur
772 /// while another thread is attempting to access the registry. Typically
773 /// this is done by initializing all targets at program startup.
775 /// @param T - The target being registered.
776 /// @param Fn - A function to construct an MCStreamer for the target.
777 static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
778 T.AsmStreamerCtorFn = Fn;
781 /// RegisterMCRelocationInfo - Register an MCRelocationInfo
782 /// implementation for the given target.
784 /// Clients are responsible for ensuring that registration doesn't occur
785 /// while another thread is attempting to access the registry. Typically
786 /// this is done by initializing all targets at program startup.
788 /// @param T - The target being registered.
789 /// @param Fn - A function to construct an MCRelocationInfo for the target.
790 static void RegisterMCRelocationInfo(Target &T,
791 Target::MCRelocationInfoCtorTy Fn) {
792 T.MCRelocationInfoCtorFn = Fn;
795 /// RegisterMCSymbolizer - Register an MCSymbolizer
796 /// implementation for the given target.
798 /// Clients are responsible for ensuring that registration doesn't occur
799 /// while another thread is attempting to access the registry. Typically
800 /// this is done by initializing all targets at program startup.
802 /// @param T - The target being registered.
803 /// @param Fn - A function to construct an MCSymbolizer for the target.
804 static void RegisterMCSymbolizer(Target &T,
805 Target::MCSymbolizerCtorTy Fn) {
806 T.MCSymbolizerCtorFn = Fn;
813 //===--------------------------------------------------------------------===//
815 /// RegisterTarget - Helper template for registering a target, for use in the
816 /// target's initialization function. Usage:
819 /// Target TheFooTarget; // The global target instance.
821 /// extern "C" void LLVMInitializeFooTargetInfo() {
822 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
824 template<Triple::ArchType TargetArchType = Triple::UnknownArch,
826 struct RegisterTarget {
827 RegisterTarget(Target &T, const char *Name, const char *Desc) {
828 TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch, HasJIT);
831 static bool getArchMatch(Triple::ArchType Arch) {
832 return Arch == TargetArchType;
836 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
837 /// implementation. This invokes the static "Create" method on the class to
838 /// actually do the construction. Usage:
840 /// extern "C" void LLVMInitializeFooTarget() {
841 /// extern Target TheFooTarget;
842 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
844 template<class MCAsmInfoImpl>
845 struct RegisterMCAsmInfo {
846 RegisterMCAsmInfo(Target &T) {
847 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
850 static MCAsmInfo *Allocator(const MCRegisterInfo &/*MRI*/, StringRef TT) {
851 return new MCAsmInfoImpl(TT);
856 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
857 /// implementation. This invokes the specified function to do the
858 /// construction. Usage:
860 /// extern "C" void LLVMInitializeFooTarget() {
861 /// extern Target TheFooTarget;
862 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
864 struct RegisterMCAsmInfoFn {
865 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
866 TargetRegistry::RegisterMCAsmInfo(T, Fn);
870 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
871 /// implementation. This invokes the static "Create" method on the class
872 /// to actually do the construction. Usage:
874 /// extern "C" void LLVMInitializeFooTarget() {
875 /// extern Target TheFooTarget;
876 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
878 template<class MCCodeGenInfoImpl>
879 struct RegisterMCCodeGenInfo {
880 RegisterMCCodeGenInfo(Target &T) {
881 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
884 static MCCodeGenInfo *Allocator(StringRef /*TT*/, Reloc::Model /*RM*/,
885 CodeModel::Model /*CM*/,
886 CodeGenOpt::Level /*OL*/) {
887 return new MCCodeGenInfoImpl();
891 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
892 /// info implementation. This invokes the specified function to do the
893 /// construction. Usage:
895 /// extern "C" void LLVMInitializeFooTarget() {
896 /// extern Target TheFooTarget;
897 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
899 struct RegisterMCCodeGenInfoFn {
900 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
901 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
905 /// RegisterMCInstrInfo - Helper template for registering a target instruction
906 /// info implementation. This invokes the static "Create" method on the class
907 /// to actually do the construction. Usage:
909 /// extern "C" void LLVMInitializeFooTarget() {
910 /// extern Target TheFooTarget;
911 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
913 template<class MCInstrInfoImpl>
914 struct RegisterMCInstrInfo {
915 RegisterMCInstrInfo(Target &T) {
916 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
919 static MCInstrInfo *Allocator() {
920 return new MCInstrInfoImpl();
924 /// RegisterMCInstrInfoFn - Helper template for registering a target
925 /// instruction info implementation. This invokes the specified function to
926 /// do the construction. Usage:
928 /// extern "C" void LLVMInitializeFooTarget() {
929 /// extern Target TheFooTarget;
930 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
932 struct RegisterMCInstrInfoFn {
933 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
934 TargetRegistry::RegisterMCInstrInfo(T, Fn);
938 /// RegisterMCInstrAnalysis - Helper template for registering a target
939 /// instruction analyzer implementation. This invokes the static "Create"
940 /// method on the class to actually do the construction. Usage:
942 /// extern "C" void LLVMInitializeFooTarget() {
943 /// extern Target TheFooTarget;
944 /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
946 template<class MCInstrAnalysisImpl>
947 struct RegisterMCInstrAnalysis {
948 RegisterMCInstrAnalysis(Target &T) {
949 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
952 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
953 return new MCInstrAnalysisImpl(Info);
957 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
958 /// instruction analyzer implementation. This invokes the specified function
959 /// to do the construction. Usage:
961 /// extern "C" void LLVMInitializeFooTarget() {
962 /// extern Target TheFooTarget;
963 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
965 struct RegisterMCInstrAnalysisFn {
966 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
967 TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
971 /// RegisterMCRegInfo - Helper template for registering a target register info
972 /// implementation. This invokes the static "Create" method on the class to
973 /// actually do the construction. Usage:
975 /// extern "C" void LLVMInitializeFooTarget() {
976 /// extern Target TheFooTarget;
977 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
979 template<class MCRegisterInfoImpl>
980 struct RegisterMCRegInfo {
981 RegisterMCRegInfo(Target &T) {
982 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
985 static MCRegisterInfo *Allocator(StringRef /*TT*/) {
986 return new MCRegisterInfoImpl();
990 /// RegisterMCRegInfoFn - Helper template for registering a target register
991 /// info implementation. This invokes the specified function to do the
992 /// construction. Usage:
994 /// extern "C" void LLVMInitializeFooTarget() {
995 /// extern Target TheFooTarget;
996 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
998 struct RegisterMCRegInfoFn {
999 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
1000 TargetRegistry::RegisterMCRegInfo(T, Fn);
1004 /// RegisterMCSubtargetInfo - Helper template for registering a target
1005 /// subtarget info implementation. This invokes the static "Create" method
1006 /// on the class to actually do the construction. Usage:
1008 /// extern "C" void LLVMInitializeFooTarget() {
1009 /// extern Target TheFooTarget;
1010 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
1012 template<class MCSubtargetInfoImpl>
1013 struct RegisterMCSubtargetInfo {
1014 RegisterMCSubtargetInfo(Target &T) {
1015 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
1018 static MCSubtargetInfo *Allocator(StringRef /*TT*/, StringRef /*CPU*/,
1020 return new MCSubtargetInfoImpl();
1024 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
1025 /// subtarget info implementation. This invokes the specified function to
1026 /// do the construction. Usage:
1028 /// extern "C" void LLVMInitializeFooTarget() {
1029 /// extern Target TheFooTarget;
1030 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1032 struct RegisterMCSubtargetInfoFn {
1033 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
1034 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
1038 /// RegisterTargetMachine - Helper template for registering a target machine
1039 /// implementation, for use in the target machine initialization
1040 /// function. Usage:
1042 /// extern "C" void LLVMInitializeFooTarget() {
1043 /// extern Target TheFooTarget;
1044 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1046 template<class TargetMachineImpl>
1047 struct RegisterTargetMachine {
1048 RegisterTargetMachine(Target &T) {
1049 TargetRegistry::RegisterTargetMachine(T, &Allocator);
1053 static TargetMachine *Allocator(const Target &T, StringRef TT,
1054 StringRef CPU, StringRef FS,
1055 const TargetOptions &Options,
1057 CodeModel::Model CM,
1058 CodeGenOpt::Level OL) {
1059 return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
1063 /// RegisterMCAsmBackend - Helper template for registering a target specific
1064 /// assembler backend. Usage:
1066 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1067 /// extern Target TheFooTarget;
1068 /// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1070 template<class MCAsmBackendImpl>
1071 struct RegisterMCAsmBackend {
1072 RegisterMCAsmBackend(Target &T) {
1073 TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1077 static MCAsmBackend *Allocator(const Target &T,
1078 const MCRegisterInfo &MRI,
1079 StringRef Triple, StringRef CPU) {
1080 return new MCAsmBackendImpl(T, MRI, Triple, CPU);
1084 /// RegisterMCAsmParser - Helper template for registering a target specific
1085 /// assembly parser, for use in the target machine initialization
1086 /// function. Usage:
1088 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1089 /// extern Target TheFooTarget;
1090 /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1092 template<class MCAsmParserImpl>
1093 struct RegisterMCAsmParser {
1094 RegisterMCAsmParser(Target &T) {
1095 TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1099 static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P,
1100 const MCInstrInfo &MII) {
1101 return new MCAsmParserImpl(STI, P, MII);
1105 /// RegisterAsmPrinter - Helper template for registering a target specific
1106 /// assembly printer, for use in the target machine initialization
1107 /// function. Usage:
1109 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1110 /// extern Target TheFooTarget;
1111 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1113 template<class AsmPrinterImpl>
1114 struct RegisterAsmPrinter {
1115 RegisterAsmPrinter(Target &T) {
1116 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1120 static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) {
1121 return new AsmPrinterImpl(TM, Streamer);
1125 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1126 /// machine code emitter, for use in the target initialization
1127 /// function. Usage:
1129 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1130 /// extern Target TheFooTarget;
1131 /// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1133 template<class MCCodeEmitterImpl>
1134 struct RegisterMCCodeEmitter {
1135 RegisterMCCodeEmitter(Target &T) {
1136 TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1140 static MCCodeEmitter *Allocator(const MCInstrInfo &/*II*/,
1141 const MCRegisterInfo &/*MRI*/,
1142 const MCSubtargetInfo &/*STI*/,
1143 MCContext &/*Ctx*/) {
1144 return new MCCodeEmitterImpl();