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,
54 formatted_raw_ostream &OS, bool isVerboseAsm,
55 bool useLoc, 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)(MCSubtargetInfo &STI,
110 const MCInstrInfo &MII);
111 typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T,
112 const MCSubtargetInfo &STI);
113 typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
114 unsigned SyntaxVariant,
115 const MCAsmInfo &MAI,
116 const MCInstrInfo &MII,
117 const MCRegisterInfo &MRI,
118 const MCSubtargetInfo &STI);
119 typedef MCCodeEmitter *(*MCCodeEmitterCtorTy)(const MCInstrInfo &II,
120 const MCRegisterInfo &MRI,
121 const MCSubtargetInfo &STI,
123 typedef MCStreamer *(*MCObjectStreamerCtorTy)(const Target &T,
128 MCCodeEmitter *_Emitter,
131 typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx,
132 formatted_raw_ostream &OS,
136 bool useDwarfDirectory,
137 MCInstPrinter *InstPrint,
141 typedef MCRelocationInfo *(*MCRelocationInfoCtorTy)(StringRef TT,
143 typedef MCSymbolizer *(*MCSymbolizerCtorTy)(StringRef TT,
144 LLVMOpInfoCallback GetOpInfo,
145 LLVMSymbolLookupCallback SymbolLookUp,
148 MCRelocationInfo *RelInfo);
151 /// Next - The next registered target in the linked list, maintained by the
155 /// The target function for checking if an architecture is supported.
156 ArchMatchFnTy ArchMatchFn;
158 /// Name - The target name.
161 /// ShortDesc - A short description of the target.
162 const char *ShortDesc;
164 /// HasJIT - Whether this target supports the JIT.
167 /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
169 MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
171 /// MCCodeGenInfoCtorFn - Constructor function for this target's
172 /// MCCodeGenInfo, if registered.
173 MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn;
175 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
177 MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
179 /// MCInstrAnalysisCtorFn - Constructor function for this target's
180 /// MCInstrAnalysis, if registered.
181 MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
183 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
185 MCRegInfoCtorFnTy MCRegInfoCtorFn;
187 /// MCSubtargetInfoCtorFn - Constructor function for this target's
188 /// MCSubtargetInfo, if registered.
189 MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
191 /// TargetMachineCtorFn - Construction function for this target's
192 /// TargetMachine, if registered.
193 TargetMachineCtorTy TargetMachineCtorFn;
195 /// MCAsmBackendCtorFn - Construction function for this target's
196 /// MCAsmBackend, if registered.
197 MCAsmBackendCtorTy MCAsmBackendCtorFn;
199 /// MCAsmParserCtorFn - Construction function for this target's
200 /// MCTargetAsmParser, if registered.
201 MCAsmParserCtorTy MCAsmParserCtorFn;
203 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
205 AsmPrinterCtorTy AsmPrinterCtorFn;
207 /// MCDisassemblerCtorFn - Construction function for this target's
208 /// MCDisassembler, if registered.
209 MCDisassemblerCtorTy MCDisassemblerCtorFn;
211 /// MCInstPrinterCtorFn - Construction function for this target's
212 /// MCInstPrinter, if registered.
213 MCInstPrinterCtorTy MCInstPrinterCtorFn;
215 /// MCCodeEmitterCtorFn - Construction function for this target's
216 /// CodeEmitter, if registered.
217 MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
219 /// MCObjectStreamerCtorFn - Construction function for this target's
220 /// MCObjectStreamer, if registered.
221 MCObjectStreamerCtorTy MCObjectStreamerCtorFn;
223 /// AsmStreamerCtorFn - Construction function for this target's
224 /// AsmStreamer, if registered (default = llvm::createAsmStreamer).
225 AsmStreamerCtorTy AsmStreamerCtorFn;
227 /// MCRelocationInfoCtorFn - Construction function for this target's
228 /// MCRelocationInfo, if registered (default = llvm::createMCRelocationInfo)
229 MCRelocationInfoCtorTy MCRelocationInfoCtorFn;
231 /// MCSymbolizerCtorFn - Construction function for this target's
232 /// MCSymbolizer, if registered (default = llvm::createMCSymbolizer)
233 MCSymbolizerCtorTy MCSymbolizerCtorFn;
237 : AsmStreamerCtorFn(0), MCRelocationInfoCtorFn(0),
238 MCSymbolizerCtorFn(0) {}
240 /// @name Target Information
243 // getNext - Return the next registered target.
244 const Target *getNext() const { return Next; }
246 /// getName - Get the target name.
247 const char *getName() const { return Name; }
249 /// getShortDescription - Get a short description of the target.
250 const char *getShortDescription() const { return ShortDesc; }
253 /// @name Feature Predicates
256 /// hasJIT - Check if this targets supports the just-in-time compilation.
257 bool hasJIT() const { return HasJIT; }
259 /// hasTargetMachine - Check if this target supports code generation.
260 bool hasTargetMachine() const { return TargetMachineCtorFn != 0; }
262 /// hasMCAsmBackend - Check if this target supports .o generation.
263 bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != 0; }
266 /// @name Feature Constructors
269 /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
272 /// \param Triple This argument is used to determine the target machine
273 /// feature set; it should always be provided. Generally this should be
274 /// either the target triple from the module, or the target triple of the
275 /// host if that does not exist.
276 MCAsmInfo *createMCAsmInfo(const MCRegisterInfo &MRI,
277 StringRef Triple) const {
278 if (!MCAsmInfoCtorFn)
280 return MCAsmInfoCtorFn(MRI, Triple);
283 /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
285 MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model RM,
287 CodeGenOpt::Level OL) const {
288 if (!MCCodeGenInfoCtorFn)
290 return MCCodeGenInfoCtorFn(Triple, RM, CM, OL);
293 /// createMCInstrInfo - Create a MCInstrInfo implementation.
295 MCInstrInfo *createMCInstrInfo() const {
296 if (!MCInstrInfoCtorFn)
298 return MCInstrInfoCtorFn();
301 /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
303 MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
304 if (!MCInstrAnalysisCtorFn)
306 return MCInstrAnalysisCtorFn(Info);
309 /// createMCRegInfo - Create a MCRegisterInfo implementation.
311 MCRegisterInfo *createMCRegInfo(StringRef Triple) const {
312 if (!MCRegInfoCtorFn)
314 return MCRegInfoCtorFn(Triple);
317 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
319 /// \param Triple This argument is used to determine the target machine
320 /// feature set; it should always be provided. Generally this should be
321 /// either the target triple from the module, or the target triple of the
322 /// host if that does not exist.
323 /// \param CPU This specifies the name of the target CPU.
324 /// \param Features This specifies the string representation of the
325 /// additional target features.
326 MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU,
327 StringRef Features) const {
328 if (!MCSubtargetInfoCtorFn)
330 return MCSubtargetInfoCtorFn(Triple, CPU, Features);
333 /// createTargetMachine - Create a target specific machine implementation
334 /// for the specified \p Triple.
336 /// \param Triple This argument is used to determine the target machine
337 /// feature set; it should always be provided. Generally this should be
338 /// either the target triple from the module, or the target triple of the
339 /// host if that does not exist.
340 TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU,
341 StringRef Features, const TargetOptions &Options,
342 Reloc::Model RM = Reloc::Default,
343 CodeModel::Model CM = CodeModel::Default,
344 CodeGenOpt::Level OL = CodeGenOpt::Default) const {
345 if (!TargetMachineCtorFn)
347 return TargetMachineCtorFn(*this, Triple, CPU, Features, Options,
351 /// createMCAsmBackend - Create a target specific assembly parser.
353 /// \param Triple The target triple string.
354 MCAsmBackend *createMCAsmBackend(const MCRegisterInfo &MRI,
355 StringRef Triple, StringRef CPU) const {
356 if (!MCAsmBackendCtorFn)
358 return MCAsmBackendCtorFn(*this, MRI, Triple, CPU);
361 /// createMCAsmParser - Create a target specific assembly parser.
363 /// \param Parser The target independent parser implementation to use for
364 /// parsing and lexing.
365 MCTargetAsmParser *createMCAsmParser(MCSubtargetInfo &STI,
367 const MCInstrInfo &MII) const {
368 if (!MCAsmParserCtorFn)
370 return MCAsmParserCtorFn(STI, Parser, MII);
373 /// createAsmPrinter - Create a target specific assembly printer pass. This
374 /// takes ownership of the MCStreamer object.
375 AsmPrinter *createAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) const{
376 if (!AsmPrinterCtorFn)
378 return AsmPrinterCtorFn(TM, Streamer);
381 MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI) const {
382 if (!MCDisassemblerCtorFn)
384 return MCDisassemblerCtorFn(*this, STI);
387 MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
388 const MCAsmInfo &MAI,
389 const MCInstrInfo &MII,
390 const MCRegisterInfo &MRI,
391 const MCSubtargetInfo &STI) const {
392 if (!MCInstPrinterCtorFn)
394 return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, MII, MRI, STI);
398 /// createMCCodeEmitter - Create a target specific code emitter.
399 MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
400 const MCRegisterInfo &MRI,
401 const MCSubtargetInfo &STI,
402 MCContext &Ctx) const {
403 if (!MCCodeEmitterCtorFn)
405 return MCCodeEmitterCtorFn(II, MRI, STI, Ctx);
408 /// createMCObjectStreamer - Create a target specific MCStreamer.
410 /// \param TT The target triple.
411 /// \param Ctx The target context.
412 /// \param TAB The target assembler backend object. Takes ownership.
413 /// \param _OS The stream object.
414 /// \param _Emitter The target independent assembler object.Takes ownership.
415 /// \param RelaxAll Relax all fixups?
416 /// \param NoExecStack Mark file as not needing a executable stack.
417 MCStreamer *createMCObjectStreamer(StringRef TT, MCContext &Ctx,
420 MCCodeEmitter *_Emitter,
422 bool NoExecStack) const {
423 if (!MCObjectStreamerCtorFn)
425 return MCObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter,
426 RelaxAll, NoExecStack);
429 /// createAsmStreamer - Create a target specific MCStreamer.
430 MCStreamer *createAsmStreamer(MCContext &Ctx,
431 formatted_raw_ostream &OS,
435 bool useDwarfDirectory,
436 MCInstPrinter *InstPrint,
439 bool ShowInst) const {
440 if (AsmStreamerCtorFn)
441 return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useLoc, useCFI,
442 useDwarfDirectory, InstPrint, CE, TAB,
444 return llvm::createAsmStreamer(Ctx, OS, isVerboseAsm, useLoc, useCFI,
445 useDwarfDirectory, InstPrint, CE, TAB,
449 /// createMCRelocationInfo - Create a target specific MCRelocationInfo.
451 /// \param TT The target triple.
452 /// \param Ctx The target context.
454 createMCRelocationInfo(StringRef TT, MCContext &Ctx) const {
455 MCRelocationInfoCtorTy Fn = MCRelocationInfoCtorFn
456 ? MCRelocationInfoCtorFn
457 : llvm::createMCRelocationInfo;
461 /// createMCSymbolizer - Create a target specific MCSymbolizer.
463 /// \param TT The target triple.
464 /// \param GetOpInfo The function to get the symbolic information for operands.
465 /// \param SymbolLookUp The function to lookup a symbol name.
466 /// \param DisInfo The pointer to the block of symbolic information for above call
468 /// \param Ctx The target context.
469 /// \param RelInfo The relocation information for this target. Takes ownership.
471 createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
472 LLVMSymbolLookupCallback SymbolLookUp,
474 MCContext *Ctx, MCRelocationInfo *RelInfo) const {
475 MCSymbolizerCtorTy Fn =
476 MCSymbolizerCtorFn ? MCSymbolizerCtorFn : llvm::createMCSymbolizer;
477 return Fn(TT, GetOpInfo, SymbolLookUp, DisInfo, Ctx, RelInfo);
483 /// TargetRegistry - Generic interface to target specific features.
484 struct TargetRegistry {
486 const Target *Current;
487 explicit iterator(Target *T) : Current(T) {}
488 friend struct TargetRegistry;
490 iterator(const iterator &I) : Current(I.Current) {}
491 iterator() : Current(0) {}
493 bool operator==(const iterator &x) const {
494 return Current == x.Current;
496 bool operator!=(const iterator &x) const {
497 return !operator==(x);
500 // Iterator traversal: forward iteration only
501 iterator &operator++() { // Preincrement
502 assert(Current && "Cannot increment end iterator!");
503 Current = Current->getNext();
506 iterator operator++(int) { // Postincrement
507 iterator tmp = *this;
512 const Target &operator*() const {
513 assert(Current && "Cannot dereference end iterator!");
517 const Target *operator->() const {
522 /// printRegisteredTargetsForVersion - Print the registered targets
523 /// appropriately for inclusion in a tool's version output.
524 static void printRegisteredTargetsForVersion();
526 /// @name Registry Access
529 static iterator begin();
531 static iterator end() { return iterator(); }
533 /// lookupTarget - Lookup a target based on a target triple.
535 /// \param Triple - The triple to use for finding a target.
536 /// \param Error - On failure, an error string describing why no target was
538 static const Target *lookupTarget(const std::string &Triple,
541 /// lookupTarget - Lookup a target based on an architecture name
542 /// and a target triple. If the architecture name is non-empty,
543 /// then the lookup is done by architecture. Otherwise, the target
546 /// \param ArchName - The architecture to use for finding a target.
547 /// \param TheTriple - The triple to use for finding a target. The
548 /// triple is updated with canonical architecture name if a lookup
549 /// by architecture is done.
550 /// \param Error - On failure, an error string describing why no target was
552 static const Target *lookupTarget(const std::string &ArchName,
556 /// getClosestTargetForJIT - Pick the best target that is compatible with
557 /// the current host. If no close target can be found, this returns null
558 /// and sets the Error string to a reason.
560 /// Maintained for compatibility through 2.6.
561 static const Target *getClosestTargetForJIT(std::string &Error);
564 /// @name Target Registration
567 /// RegisterTarget - Register the given target. Attempts to register a
568 /// target which has already been registered will be ignored.
570 /// Clients are responsible for ensuring that registration doesn't occur
571 /// while another thread is attempting to access the registry. Typically
572 /// this is done by initializing all targets at program startup.
574 /// @param T - The target being registered.
575 /// @param Name - The target name. This should be a static string.
576 /// @param ShortDesc - A short target description. This should be a static
578 /// @param ArchMatchFn - The arch match checking function for this target.
579 /// @param HasJIT - Whether the target supports JIT code
581 static void RegisterTarget(Target &T,
583 const char *ShortDesc,
584 Target::ArchMatchFnTy ArchMatchFn,
585 bool HasJIT = false);
587 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
590 /// Clients are responsible for ensuring that registration doesn't occur
591 /// while another thread is attempting to access the registry. Typically
592 /// this is done by initializing all targets at program startup.
594 /// @param T - The target being registered.
595 /// @param Fn - A function to construct a MCAsmInfo for the target.
596 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
597 T.MCAsmInfoCtorFn = Fn;
600 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
603 /// Clients are responsible for ensuring that registration doesn't occur
604 /// while another thread is attempting to access the registry. Typically
605 /// this is done by initializing all targets at program startup.
607 /// @param T - The target being registered.
608 /// @param Fn - A function to construct a MCCodeGenInfo for the target.
609 static void RegisterMCCodeGenInfo(Target &T,
610 Target::MCCodeGenInfoCtorFnTy Fn) {
611 T.MCCodeGenInfoCtorFn = Fn;
614 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
617 /// Clients are responsible for ensuring that registration doesn't occur
618 /// while another thread is attempting to access the registry. Typically
619 /// this is done by initializing all targets at program startup.
621 /// @param T - The target being registered.
622 /// @param Fn - A function to construct a MCInstrInfo for the target.
623 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
624 T.MCInstrInfoCtorFn = Fn;
627 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
628 /// the given target.
629 static void RegisterMCInstrAnalysis(Target &T,
630 Target::MCInstrAnalysisCtorFnTy Fn) {
631 T.MCInstrAnalysisCtorFn = Fn;
634 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
637 /// Clients are responsible for ensuring that registration doesn't occur
638 /// while another thread is attempting to access the registry. Typically
639 /// this is done by initializing all targets at program startup.
641 /// @param T - The target being registered.
642 /// @param Fn - A function to construct a MCRegisterInfo for the target.
643 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
644 T.MCRegInfoCtorFn = Fn;
647 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
648 /// the given target.
650 /// Clients are responsible for ensuring that registration doesn't occur
651 /// while another thread is attempting to access the registry. Typically
652 /// this is done by initializing all targets at program startup.
654 /// @param T - The target being registered.
655 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
656 static void RegisterMCSubtargetInfo(Target &T,
657 Target::MCSubtargetInfoCtorFnTy Fn) {
658 T.MCSubtargetInfoCtorFn = Fn;
661 /// RegisterTargetMachine - Register a TargetMachine implementation for the
664 /// Clients are responsible for ensuring that registration doesn't occur
665 /// while another thread is attempting to access the registry. Typically
666 /// this is done by initializing all targets at program startup.
668 /// @param T - The target being registered.
669 /// @param Fn - A function to construct a TargetMachine for the target.
670 static void RegisterTargetMachine(Target &T,
671 Target::TargetMachineCtorTy Fn) {
672 T.TargetMachineCtorFn = Fn;
675 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
678 /// Clients are responsible for ensuring that registration doesn't occur
679 /// while another thread is attempting to access the registry. Typically
680 /// this is done by initializing all targets at program startup.
682 /// @param T - The target being registered.
683 /// @param Fn - A function to construct an AsmBackend for the target.
684 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
685 T.MCAsmBackendCtorFn = Fn;
688 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
689 /// the given target.
691 /// Clients are responsible for ensuring that registration doesn't occur
692 /// while another thread is attempting to access the registry. Typically
693 /// this is done by initializing all targets at program startup.
695 /// @param T - The target being registered.
696 /// @param Fn - A function to construct an MCTargetAsmParser for the target.
697 static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
698 T.MCAsmParserCtorFn = Fn;
701 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
704 /// Clients are responsible for ensuring that registration doesn't occur
705 /// while another thread is attempting to access the registry. Typically
706 /// this is done by initializing all targets at program startup.
708 /// @param T - The target being registered.
709 /// @param Fn - A function to construct an AsmPrinter for the target.
710 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
711 T.AsmPrinterCtorFn = Fn;
714 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
715 /// the given target.
717 /// Clients are responsible for ensuring that registration doesn't occur
718 /// while another thread is attempting to access the registry. Typically
719 /// this is done by initializing all targets at program startup.
721 /// @param T - The target being registered.
722 /// @param Fn - A function to construct an MCDisassembler for the target.
723 static void RegisterMCDisassembler(Target &T,
724 Target::MCDisassemblerCtorTy Fn) {
725 T.MCDisassemblerCtorFn = Fn;
728 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
731 /// Clients are responsible for ensuring that registration doesn't occur
732 /// while another thread is attempting to access the registry. Typically
733 /// this is done by initializing all targets at program startup.
735 /// @param T - The target being registered.
736 /// @param Fn - A function to construct an MCInstPrinter for the target.
737 static void RegisterMCInstPrinter(Target &T,
738 Target::MCInstPrinterCtorTy Fn) {
739 T.MCInstPrinterCtorFn = Fn;
742 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
745 /// Clients are responsible for ensuring that registration doesn't occur
746 /// while another thread is attempting to access the registry. Typically
747 /// this is done by initializing all targets at program startup.
749 /// @param T - The target being registered.
750 /// @param Fn - A function to construct an MCCodeEmitter for the target.
751 static void RegisterMCCodeEmitter(Target &T,
752 Target::MCCodeEmitterCtorTy Fn) {
753 T.MCCodeEmitterCtorFn = Fn;
756 /// RegisterMCObjectStreamer - Register a object code MCStreamer
757 /// implementation for the given target.
759 /// Clients are responsible for ensuring that registration doesn't occur
760 /// while another thread is attempting to access the registry. Typically
761 /// this is done by initializing all targets at program startup.
763 /// @param T - The target being registered.
764 /// @param Fn - A function to construct an MCStreamer for the target.
765 static void RegisterMCObjectStreamer(Target &T,
766 Target::MCObjectStreamerCtorTy Fn) {
767 T.MCObjectStreamerCtorFn = Fn;
770 /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
771 /// for the given target.
773 /// Clients are responsible for ensuring that registration doesn't occur
774 /// while another thread is attempting to access the registry. Typically
775 /// this is done by initializing all targets at program startup.
777 /// @param T - The target being registered.
778 /// @param Fn - A function to construct an MCStreamer for the target.
779 static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
780 T.AsmStreamerCtorFn = Fn;
783 /// RegisterMCRelocationInfo - Register an MCRelocationInfo
784 /// implementation for the given target.
786 /// Clients are responsible for ensuring that registration doesn't occur
787 /// while another thread is attempting to access the registry. Typically
788 /// this is done by initializing all targets at program startup.
790 /// @param T - The target being registered.
791 /// @param Fn - A function to construct an MCRelocationInfo for the target.
792 static void RegisterMCRelocationInfo(Target &T,
793 Target::MCRelocationInfoCtorTy Fn) {
794 T.MCRelocationInfoCtorFn = Fn;
797 /// RegisterMCSymbolizer - Register an MCSymbolizer
798 /// implementation for the given target.
800 /// Clients are responsible for ensuring that registration doesn't occur
801 /// while another thread is attempting to access the registry. Typically
802 /// this is done by initializing all targets at program startup.
804 /// @param T - The target being registered.
805 /// @param Fn - A function to construct an MCSymbolizer for the target.
806 static void RegisterMCSymbolizer(Target &T,
807 Target::MCSymbolizerCtorTy Fn) {
808 T.MCSymbolizerCtorFn = Fn;
815 //===--------------------------------------------------------------------===//
817 /// RegisterTarget - Helper template for registering a target, for use in the
818 /// target's initialization function. Usage:
821 /// Target TheFooTarget; // The global target instance.
823 /// extern "C" void LLVMInitializeFooTargetInfo() {
824 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
826 template<Triple::ArchType TargetArchType = Triple::UnknownArch,
828 struct RegisterTarget {
829 RegisterTarget(Target &T, const char *Name, const char *Desc) {
830 TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch, HasJIT);
833 static bool getArchMatch(Triple::ArchType Arch) {
834 return Arch == TargetArchType;
838 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
839 /// implementation. This invokes the static "Create" method on the class to
840 /// actually do the construction. Usage:
842 /// extern "C" void LLVMInitializeFooTarget() {
843 /// extern Target TheFooTarget;
844 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
846 template<class MCAsmInfoImpl>
847 struct RegisterMCAsmInfo {
848 RegisterMCAsmInfo(Target &T) {
849 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
852 static MCAsmInfo *Allocator(const MCRegisterInfo &/*MRI*/, StringRef TT) {
853 return new MCAsmInfoImpl(TT);
858 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
859 /// implementation. This invokes the specified function to do the
860 /// construction. Usage:
862 /// extern "C" void LLVMInitializeFooTarget() {
863 /// extern Target TheFooTarget;
864 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
866 struct RegisterMCAsmInfoFn {
867 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
868 TargetRegistry::RegisterMCAsmInfo(T, Fn);
872 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
873 /// implementation. This invokes the static "Create" method on the class
874 /// to actually do the construction. Usage:
876 /// extern "C" void LLVMInitializeFooTarget() {
877 /// extern Target TheFooTarget;
878 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
880 template<class MCCodeGenInfoImpl>
881 struct RegisterMCCodeGenInfo {
882 RegisterMCCodeGenInfo(Target &T) {
883 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
886 static MCCodeGenInfo *Allocator(StringRef /*TT*/, Reloc::Model /*RM*/,
887 CodeModel::Model /*CM*/,
888 CodeGenOpt::Level /*OL*/) {
889 return new MCCodeGenInfoImpl();
893 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
894 /// info implementation. This invokes the specified function to do the
895 /// construction. Usage:
897 /// extern "C" void LLVMInitializeFooTarget() {
898 /// extern Target TheFooTarget;
899 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
901 struct RegisterMCCodeGenInfoFn {
902 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
903 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
907 /// RegisterMCInstrInfo - Helper template for registering a target instruction
908 /// info implementation. This invokes the static "Create" method on the class
909 /// to actually do the construction. Usage:
911 /// extern "C" void LLVMInitializeFooTarget() {
912 /// extern Target TheFooTarget;
913 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
915 template<class MCInstrInfoImpl>
916 struct RegisterMCInstrInfo {
917 RegisterMCInstrInfo(Target &T) {
918 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
921 static MCInstrInfo *Allocator() {
922 return new MCInstrInfoImpl();
926 /// RegisterMCInstrInfoFn - Helper template for registering a target
927 /// instruction info implementation. This invokes the specified function to
928 /// do the construction. Usage:
930 /// extern "C" void LLVMInitializeFooTarget() {
931 /// extern Target TheFooTarget;
932 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
934 struct RegisterMCInstrInfoFn {
935 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
936 TargetRegistry::RegisterMCInstrInfo(T, Fn);
940 /// RegisterMCInstrAnalysis - Helper template for registering a target
941 /// instruction analyzer implementation. This invokes the static "Create"
942 /// method on the class to actually do the construction. Usage:
944 /// extern "C" void LLVMInitializeFooTarget() {
945 /// extern Target TheFooTarget;
946 /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
948 template<class MCInstrAnalysisImpl>
949 struct RegisterMCInstrAnalysis {
950 RegisterMCInstrAnalysis(Target &T) {
951 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
954 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
955 return new MCInstrAnalysisImpl(Info);
959 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
960 /// instruction analyzer implementation. This invokes the specified function
961 /// to do the construction. Usage:
963 /// extern "C" void LLVMInitializeFooTarget() {
964 /// extern Target TheFooTarget;
965 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
967 struct RegisterMCInstrAnalysisFn {
968 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
969 TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
973 /// RegisterMCRegInfo - Helper template for registering a target register info
974 /// implementation. This invokes the static "Create" method on the class to
975 /// actually do the construction. Usage:
977 /// extern "C" void LLVMInitializeFooTarget() {
978 /// extern Target TheFooTarget;
979 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
981 template<class MCRegisterInfoImpl>
982 struct RegisterMCRegInfo {
983 RegisterMCRegInfo(Target &T) {
984 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
987 static MCRegisterInfo *Allocator(StringRef /*TT*/) {
988 return new MCRegisterInfoImpl();
992 /// RegisterMCRegInfoFn - Helper template for registering a target register
993 /// info implementation. This invokes the specified function to do the
994 /// construction. Usage:
996 /// extern "C" void LLVMInitializeFooTarget() {
997 /// extern Target TheFooTarget;
998 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
1000 struct RegisterMCRegInfoFn {
1001 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
1002 TargetRegistry::RegisterMCRegInfo(T, Fn);
1006 /// RegisterMCSubtargetInfo - Helper template for registering a target
1007 /// subtarget info implementation. This invokes the static "Create" method
1008 /// on the class to actually do the construction. Usage:
1010 /// extern "C" void LLVMInitializeFooTarget() {
1011 /// extern Target TheFooTarget;
1012 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
1014 template<class MCSubtargetInfoImpl>
1015 struct RegisterMCSubtargetInfo {
1016 RegisterMCSubtargetInfo(Target &T) {
1017 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
1020 static MCSubtargetInfo *Allocator(StringRef /*TT*/, StringRef /*CPU*/,
1022 return new MCSubtargetInfoImpl();
1026 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
1027 /// subtarget info implementation. This invokes the specified function to
1028 /// do the construction. Usage:
1030 /// extern "C" void LLVMInitializeFooTarget() {
1031 /// extern Target TheFooTarget;
1032 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1034 struct RegisterMCSubtargetInfoFn {
1035 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
1036 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
1040 /// RegisterTargetMachine - Helper template for registering a target machine
1041 /// implementation, for use in the target machine initialization
1042 /// function. Usage:
1044 /// extern "C" void LLVMInitializeFooTarget() {
1045 /// extern Target TheFooTarget;
1046 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1048 template<class TargetMachineImpl>
1049 struct RegisterTargetMachine {
1050 RegisterTargetMachine(Target &T) {
1051 TargetRegistry::RegisterTargetMachine(T, &Allocator);
1055 static TargetMachine *Allocator(const Target &T, StringRef TT,
1056 StringRef CPU, StringRef FS,
1057 const TargetOptions &Options,
1059 CodeModel::Model CM,
1060 CodeGenOpt::Level OL) {
1061 return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
1065 /// RegisterMCAsmBackend - Helper template for registering a target specific
1066 /// assembler backend. Usage:
1068 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1069 /// extern Target TheFooTarget;
1070 /// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1072 template<class MCAsmBackendImpl>
1073 struct RegisterMCAsmBackend {
1074 RegisterMCAsmBackend(Target &T) {
1075 TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1079 static MCAsmBackend *Allocator(const Target &T,
1080 const MCRegisterInfo &MRI,
1081 StringRef Triple, StringRef CPU) {
1082 return new MCAsmBackendImpl(T, MRI, Triple, CPU);
1086 /// RegisterMCAsmParser - Helper template for registering a target specific
1087 /// assembly parser, for use in the target machine initialization
1088 /// function. Usage:
1090 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1091 /// extern Target TheFooTarget;
1092 /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1094 template<class MCAsmParserImpl>
1095 struct RegisterMCAsmParser {
1096 RegisterMCAsmParser(Target &T) {
1097 TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1101 static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P,
1102 const MCInstrInfo &MII) {
1103 return new MCAsmParserImpl(STI, P, MII);
1107 /// RegisterAsmPrinter - Helper template for registering a target specific
1108 /// assembly printer, for use in the target machine initialization
1109 /// function. Usage:
1111 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1112 /// extern Target TheFooTarget;
1113 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1115 template<class AsmPrinterImpl>
1116 struct RegisterAsmPrinter {
1117 RegisterAsmPrinter(Target &T) {
1118 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1122 static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) {
1123 return new AsmPrinterImpl(TM, Streamer);
1127 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1128 /// machine code emitter, for use in the target initialization
1129 /// function. Usage:
1131 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1132 /// extern Target TheFooTarget;
1133 /// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1135 template<class MCCodeEmitterImpl>
1136 struct RegisterMCCodeEmitter {
1137 RegisterMCCodeEmitter(Target &T) {
1138 TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1142 static MCCodeEmitter *Allocator(const MCInstrInfo &/*II*/,
1143 const MCRegisterInfo &/*MRI*/,
1144 const MCSubtargetInfo &/*STI*/,
1145 MCContext &/*Ctx*/) {
1146 return new MCCodeEmitterImpl();