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/ADT/Triple.h"
23 #include "llvm/Support/CodeGen.h"
24 #include "llvm-c/Disassembler.h"
39 class MCInstrAnalysis;
44 class MCSubtargetInfo;
46 class MCRelocationInfo;
47 class MCTargetAsmParser;
49 class MCTargetStreamer;
52 class formatted_raw_ostream;
54 MCStreamer *createAsmStreamer(MCContext &Ctx,
55 MCTargetStreamer *TargetStreamer,
56 formatted_raw_ostream &OS, bool isVerboseAsm,
57 bool useLoc, bool useCFI,
58 bool useDwarfDirectory,
59 MCInstPrinter *InstPrint, MCCodeEmitter *CE,
60 MCAsmBackend *TAB, bool ShowInst);
62 MCRelocationInfo *createMCRelocationInfo(StringRef TT, MCContext &Ctx);
64 MCSymbolizer *createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
65 LLVMSymbolLookupCallback SymbolLookUp,
68 MCRelocationInfo *RelInfo);
70 /// Target - Wrapper for Target specific information.
72 /// For registration purposes, this is a POD type so that targets can be
73 /// registered without the use of static constructors.
75 /// Targets should implement a single global instance of this class (which
76 /// will be zero initialized), and pass that instance to the TargetRegistry as
77 /// part of their initialization.
80 friend struct TargetRegistry;
82 typedef unsigned (*TripleMatchQualityFnTy)(const std::string &TT);
84 typedef MCAsmInfo *(*MCAsmInfoCtorFnTy)(const MCRegisterInfo &MRI,
86 typedef MCCodeGenInfo *(*MCCodeGenInfoCtorFnTy)(StringRef TT,
89 CodeGenOpt::Level OL);
90 typedef MCInstrInfo *(*MCInstrInfoCtorFnTy)(void);
91 typedef MCInstrAnalysis *(*MCInstrAnalysisCtorFnTy)(const MCInstrInfo*Info);
92 typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(StringRef TT);
93 typedef MCSubtargetInfo *(*MCSubtargetInfoCtorFnTy)(StringRef TT,
96 typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T,
100 const TargetOptions &Options,
103 CodeGenOpt::Level OL);
104 typedef AsmPrinter *(*AsmPrinterCtorTy)(TargetMachine &TM,
105 MCStreamer &Streamer);
106 typedef MCAsmBackend *(*MCAsmBackendCtorTy)(const Target &T,
107 const MCRegisterInfo &MRI,
110 typedef MCTargetAsmParser *(*MCAsmParserCtorTy)(MCSubtargetInfo &STI,
112 const MCInstrInfo &MII);
113 typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T,
114 const MCSubtargetInfo &STI);
115 typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
116 unsigned SyntaxVariant,
117 const MCAsmInfo &MAI,
118 const MCInstrInfo &MII,
119 const MCRegisterInfo &MRI,
120 const MCSubtargetInfo &STI);
121 typedef MCCodeEmitter *(*MCCodeEmitterCtorTy)(const MCInstrInfo &II,
122 const MCRegisterInfo &MRI,
123 const MCSubtargetInfo &STI,
125 typedef MCStreamer *(*MCObjectStreamerCtorTy)(const Target &T,
130 MCCodeEmitter *_Emitter,
133 typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx,
134 formatted_raw_ostream &OS,
138 bool useDwarfDirectory,
139 MCInstPrinter *InstPrint,
143 typedef MCRelocationInfo *(*MCRelocationInfoCtorTy)(StringRef TT,
145 typedef MCSymbolizer *(*MCSymbolizerCtorTy)(StringRef TT,
146 LLVMOpInfoCallback GetOpInfo,
147 LLVMSymbolLookupCallback SymbolLookUp,
150 MCRelocationInfo *RelInfo);
153 /// Next - The next registered target in the linked list, maintained by the
157 /// TripleMatchQualityFn - The target function for rating the match quality
159 TripleMatchQualityFnTy TripleMatchQualityFn;
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(0), MCRelocationInfoCtorFn(0),
241 MCSymbolizerCtorFn(0) {}
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 != 0; }
265 /// hasMCAsmBackend - Check if this target supports .o generation.
266 bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != 0; }
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(MCSubtargetInfo &STI,
370 const MCInstrInfo &MII) const {
371 if (!MCAsmParserCtorFn)
373 return MCAsmParserCtorFn(STI, Parser, MII);
376 /// createAsmPrinter - Create a target specific assembly printer pass. This
377 /// takes ownership of the MCStreamer object.
378 AsmPrinter *createAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) const{
379 if (!AsmPrinterCtorFn)
381 return AsmPrinterCtorFn(TM, Streamer);
384 MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI) const {
385 if (!MCDisassemblerCtorFn)
387 return MCDisassemblerCtorFn(*this, STI);
390 MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
391 const MCAsmInfo &MAI,
392 const MCInstrInfo &MII,
393 const MCRegisterInfo &MRI,
394 const MCSubtargetInfo &STI) const {
395 if (!MCInstPrinterCtorFn)
397 return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, MII, MRI, STI);
401 /// createMCCodeEmitter - Create a target specific code emitter.
402 MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
403 const MCRegisterInfo &MRI,
404 const MCSubtargetInfo &STI,
405 MCContext &Ctx) const {
406 if (!MCCodeEmitterCtorFn)
408 return MCCodeEmitterCtorFn(II, MRI, STI, Ctx);
411 /// createMCObjectStreamer - Create a target specific MCStreamer.
413 /// \param TT The target triple.
414 /// \param Ctx The target context.
415 /// \param TAB The target assembler backend object. Takes ownership.
416 /// \param _OS The stream object.
417 /// \param _Emitter The target independent assembler object.Takes ownership.
418 /// \param RelaxAll Relax all fixups?
419 /// \param NoExecStack Mark file as not needing a executable stack.
420 MCStreamer *createMCObjectStreamer(StringRef TT, MCContext &Ctx,
423 MCCodeEmitter *_Emitter,
425 bool NoExecStack) const {
426 if (!MCObjectStreamerCtorFn)
428 return MCObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter,
429 RelaxAll, NoExecStack);
432 /// createAsmStreamer - Create a target specific MCStreamer.
433 MCStreamer *createAsmStreamer(MCContext &Ctx,
434 formatted_raw_ostream &OS,
438 bool useDwarfDirectory,
439 MCInstPrinter *InstPrint,
442 bool ShowInst) const {
443 if (AsmStreamerCtorFn)
444 return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useLoc, useCFI,
445 useDwarfDirectory, InstPrint, CE, TAB,
447 return llvm::createAsmStreamer(Ctx, 0, OS, isVerboseAsm, useLoc, useCFI,
448 useDwarfDirectory, InstPrint, CE, TAB,
452 /// createMCRelocationInfo - Create a target specific MCRelocationInfo.
454 /// \param TT The target triple.
455 /// \param Ctx The target context.
457 createMCRelocationInfo(StringRef TT, MCContext &Ctx) const {
458 MCRelocationInfoCtorTy Fn = MCRelocationInfoCtorFn
459 ? MCRelocationInfoCtorFn
460 : llvm::createMCRelocationInfo;
464 /// createMCSymbolizer - Create a target specific MCSymbolizer.
466 /// \param TT The target triple.
467 /// \param GetOpInfo The function to get the symbolic information for operands.
468 /// \param SymbolLookUp The function to lookup a symbol name.
469 /// \param DisInfo The pointer to the block of symbolic information for above call
471 /// \param Ctx The target context.
472 /// \param RelInfo The relocation information for this target. Takes ownership.
474 createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
475 LLVMSymbolLookupCallback SymbolLookUp,
477 MCContext *Ctx, MCRelocationInfo *RelInfo) const {
478 MCSymbolizerCtorTy Fn =
479 MCSymbolizerCtorFn ? MCSymbolizerCtorFn : llvm::createMCSymbolizer;
480 return Fn(TT, GetOpInfo, SymbolLookUp, DisInfo, Ctx, RelInfo);
486 /// TargetRegistry - Generic interface to target specific features.
487 struct TargetRegistry {
489 const Target *Current;
490 explicit iterator(Target *T) : Current(T) {}
491 friend struct TargetRegistry;
493 iterator(const iterator &I) : Current(I.Current) {}
494 iterator() : Current(0) {}
496 bool operator==(const iterator &x) const {
497 return Current == x.Current;
499 bool operator!=(const iterator &x) const {
500 return !operator==(x);
503 // Iterator traversal: forward iteration only
504 iterator &operator++() { // Preincrement
505 assert(Current && "Cannot increment end iterator!");
506 Current = Current->getNext();
509 iterator operator++(int) { // Postincrement
510 iterator tmp = *this;
515 const Target &operator*() const {
516 assert(Current && "Cannot dereference end iterator!");
520 const Target *operator->() const {
525 /// printRegisteredTargetsForVersion - Print the registered targets
526 /// appropriately for inclusion in a tool's version output.
527 static void printRegisteredTargetsForVersion();
529 /// @name Registry Access
532 static iterator begin();
534 static iterator end() { return iterator(); }
536 /// lookupTarget - Lookup a target based on a target triple.
538 /// \param Triple - The triple to use for finding a target.
539 /// \param Error - On failure, an error string describing why no target was
541 static const Target *lookupTarget(const std::string &Triple,
544 /// lookupTarget - Lookup a target based on an architecture name
545 /// and a target triple. If the architecture name is non-empty,
546 /// then the lookup is done by architecture. Otherwise, the target
549 /// \param ArchName - The architecture to use for finding a target.
550 /// \param TheTriple - The triple to use for finding a target. The
551 /// triple is updated with canonical architecture name if a lookup
552 /// by architecture is done.
553 /// \param Error - On failure, an error string describing why no target was
555 static const Target *lookupTarget(const std::string &ArchName,
559 /// getClosestTargetForJIT - Pick the best target that is compatible with
560 /// the current host. If no close target can be found, this returns null
561 /// and sets the Error string to a reason.
563 /// Maintained for compatibility through 2.6.
564 static const Target *getClosestTargetForJIT(std::string &Error);
567 /// @name Target Registration
570 /// RegisterTarget - Register the given target. Attempts to register a
571 /// target which has already been registered will be ignored.
573 /// Clients are responsible for ensuring that registration doesn't occur
574 /// while another thread is attempting to access the registry. Typically
575 /// this is done by initializing all targets at program startup.
577 /// @param T - The target being registered.
578 /// @param Name - The target name. This should be a static string.
579 /// @param ShortDesc - A short target description. This should be a static
581 /// @param TQualityFn - The triple match quality computation function for
583 /// @param HasJIT - Whether the target supports JIT code
585 static void RegisterTarget(Target &T,
587 const char *ShortDesc,
588 Target::TripleMatchQualityFnTy TQualityFn,
589 bool HasJIT = false);
591 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
594 /// Clients are responsible for ensuring that registration doesn't occur
595 /// while another thread is attempting to access the registry. Typically
596 /// this is done by initializing all targets at program startup.
598 /// @param T - The target being registered.
599 /// @param Fn - A function to construct a MCAsmInfo for the target.
600 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
601 T.MCAsmInfoCtorFn = Fn;
604 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
607 /// Clients are responsible for ensuring that registration doesn't occur
608 /// while another thread is attempting to access the registry. Typically
609 /// this is done by initializing all targets at program startup.
611 /// @param T - The target being registered.
612 /// @param Fn - A function to construct a MCCodeGenInfo for the target.
613 static void RegisterMCCodeGenInfo(Target &T,
614 Target::MCCodeGenInfoCtorFnTy Fn) {
615 T.MCCodeGenInfoCtorFn = Fn;
618 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
621 /// Clients are responsible for ensuring that registration doesn't occur
622 /// while another thread is attempting to access the registry. Typically
623 /// this is done by initializing all targets at program startup.
625 /// @param T - The target being registered.
626 /// @param Fn - A function to construct a MCInstrInfo for the target.
627 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
628 T.MCInstrInfoCtorFn = Fn;
631 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
632 /// the given target.
633 static void RegisterMCInstrAnalysis(Target &T,
634 Target::MCInstrAnalysisCtorFnTy Fn) {
635 T.MCInstrAnalysisCtorFn = Fn;
638 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
641 /// Clients are responsible for ensuring that registration doesn't occur
642 /// while another thread is attempting to access the registry. Typically
643 /// this is done by initializing all targets at program startup.
645 /// @param T - The target being registered.
646 /// @param Fn - A function to construct a MCRegisterInfo for the target.
647 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
648 T.MCRegInfoCtorFn = Fn;
651 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
652 /// the given target.
654 /// Clients are responsible for ensuring that registration doesn't occur
655 /// while another thread is attempting to access the registry. Typically
656 /// this is done by initializing all targets at program startup.
658 /// @param T - The target being registered.
659 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
660 static void RegisterMCSubtargetInfo(Target &T,
661 Target::MCSubtargetInfoCtorFnTy Fn) {
662 T.MCSubtargetInfoCtorFn = Fn;
665 /// RegisterTargetMachine - Register a TargetMachine implementation for the
668 /// Clients are responsible for ensuring that registration doesn't occur
669 /// while another thread is attempting to access the registry. Typically
670 /// this is done by initializing all targets at program startup.
672 /// @param T - The target being registered.
673 /// @param Fn - A function to construct a TargetMachine for the target.
674 static void RegisterTargetMachine(Target &T,
675 Target::TargetMachineCtorTy Fn) {
676 T.TargetMachineCtorFn = Fn;
679 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
682 /// Clients are responsible for ensuring that registration doesn't occur
683 /// while another thread is attempting to access the registry. Typically
684 /// this is done by initializing all targets at program startup.
686 /// @param T - The target being registered.
687 /// @param Fn - A function to construct an AsmBackend for the target.
688 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
689 T.MCAsmBackendCtorFn = Fn;
692 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
693 /// the given target.
695 /// Clients are responsible for ensuring that registration doesn't occur
696 /// while another thread is attempting to access the registry. Typically
697 /// this is done by initializing all targets at program startup.
699 /// @param T - The target being registered.
700 /// @param Fn - A function to construct an MCTargetAsmParser for the target.
701 static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
702 T.MCAsmParserCtorFn = Fn;
705 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
708 /// Clients are responsible for ensuring that registration doesn't occur
709 /// while another thread is attempting to access the registry. Typically
710 /// this is done by initializing all targets at program startup.
712 /// @param T - The target being registered.
713 /// @param Fn - A function to construct an AsmPrinter for the target.
714 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
715 T.AsmPrinterCtorFn = Fn;
718 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
719 /// the given target.
721 /// Clients are responsible for ensuring that registration doesn't occur
722 /// while another thread is attempting to access the registry. Typically
723 /// this is done by initializing all targets at program startup.
725 /// @param T - The target being registered.
726 /// @param Fn - A function to construct an MCDisassembler for the target.
727 static void RegisterMCDisassembler(Target &T,
728 Target::MCDisassemblerCtorTy Fn) {
729 T.MCDisassemblerCtorFn = Fn;
732 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
735 /// Clients are responsible for ensuring that registration doesn't occur
736 /// while another thread is attempting to access the registry. Typically
737 /// this is done by initializing all targets at program startup.
739 /// @param T - The target being registered.
740 /// @param Fn - A function to construct an MCInstPrinter for the target.
741 static void RegisterMCInstPrinter(Target &T,
742 Target::MCInstPrinterCtorTy Fn) {
743 T.MCInstPrinterCtorFn = Fn;
746 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
749 /// Clients are responsible for ensuring that registration doesn't occur
750 /// while another thread is attempting to access the registry. Typically
751 /// this is done by initializing all targets at program startup.
753 /// @param T - The target being registered.
754 /// @param Fn - A function to construct an MCCodeEmitter for the target.
755 static void RegisterMCCodeEmitter(Target &T,
756 Target::MCCodeEmitterCtorTy Fn) {
757 T.MCCodeEmitterCtorFn = Fn;
760 /// RegisterMCObjectStreamer - Register a object code MCStreamer
761 /// implementation for the given target.
763 /// Clients are responsible for ensuring that registration doesn't occur
764 /// while another thread is attempting to access the registry. Typically
765 /// this is done by initializing all targets at program startup.
767 /// @param T - The target being registered.
768 /// @param Fn - A function to construct an MCStreamer for the target.
769 static void RegisterMCObjectStreamer(Target &T,
770 Target::MCObjectStreamerCtorTy Fn) {
771 T.MCObjectStreamerCtorFn = Fn;
774 /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
775 /// for the given target.
777 /// Clients are responsible for ensuring that registration doesn't occur
778 /// while another thread is attempting to access the registry. Typically
779 /// this is done by initializing all targets at program startup.
781 /// @param T - The target being registered.
782 /// @param Fn - A function to construct an MCStreamer for the target.
783 static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
784 T.AsmStreamerCtorFn = Fn;
787 /// RegisterMCRelocationInfo - Register an MCRelocationInfo
788 /// implementation for the given target.
790 /// Clients are responsible for ensuring that registration doesn't occur
791 /// while another thread is attempting to access the registry. Typically
792 /// this is done by initializing all targets at program startup.
794 /// @param T - The target being registered.
795 /// @param Fn - A function to construct an MCRelocationInfo for the target.
796 static void RegisterMCRelocationInfo(Target &T,
797 Target::MCRelocationInfoCtorTy Fn) {
798 T.MCRelocationInfoCtorFn = Fn;
801 /// RegisterMCSymbolizer - Register an MCSymbolizer
802 /// implementation for the given target.
804 /// Clients are responsible for ensuring that registration doesn't occur
805 /// while another thread is attempting to access the registry. Typically
806 /// this is done by initializing all targets at program startup.
808 /// @param T - The target being registered.
809 /// @param Fn - A function to construct an MCSymbolizer for the target.
810 static void RegisterMCSymbolizer(Target &T,
811 Target::MCSymbolizerCtorTy Fn) {
812 T.MCSymbolizerCtorFn = Fn;
819 //===--------------------------------------------------------------------===//
821 /// RegisterTarget - Helper template for registering a target, for use in the
822 /// target's initialization function. Usage:
825 /// Target TheFooTarget; // The global target instance.
827 /// extern "C" void LLVMInitializeFooTargetInfo() {
828 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
830 template<Triple::ArchType TargetArchType = Triple::UnknownArch,
832 struct RegisterTarget {
833 RegisterTarget(Target &T, const char *Name, const char *Desc) {
834 TargetRegistry::RegisterTarget(T, Name, Desc,
835 &getTripleMatchQuality,
839 static unsigned getTripleMatchQuality(const std::string &TT) {
840 if (Triple(TT).getArch() == TargetArchType)
846 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
847 /// implementation. This invokes the static "Create" method on the class to
848 /// actually do the construction. Usage:
850 /// extern "C" void LLVMInitializeFooTarget() {
851 /// extern Target TheFooTarget;
852 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
854 template<class MCAsmInfoImpl>
855 struct RegisterMCAsmInfo {
856 RegisterMCAsmInfo(Target &T) {
857 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
860 static MCAsmInfo *Allocator(const MCRegisterInfo &/*MRI*/, StringRef TT) {
861 return new MCAsmInfoImpl(TT);
866 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
867 /// implementation. This invokes the specified function to do the
868 /// construction. Usage:
870 /// extern "C" void LLVMInitializeFooTarget() {
871 /// extern Target TheFooTarget;
872 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
874 struct RegisterMCAsmInfoFn {
875 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
876 TargetRegistry::RegisterMCAsmInfo(T, Fn);
880 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
881 /// implementation. This invokes the static "Create" method on the class
882 /// to actually do the construction. Usage:
884 /// extern "C" void LLVMInitializeFooTarget() {
885 /// extern Target TheFooTarget;
886 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
888 template<class MCCodeGenInfoImpl>
889 struct RegisterMCCodeGenInfo {
890 RegisterMCCodeGenInfo(Target &T) {
891 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
894 static MCCodeGenInfo *Allocator(StringRef /*TT*/, Reloc::Model /*RM*/,
895 CodeModel::Model /*CM*/,
896 CodeGenOpt::Level /*OL*/) {
897 return new MCCodeGenInfoImpl();
901 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
902 /// info implementation. This invokes the specified function to do the
903 /// construction. Usage:
905 /// extern "C" void LLVMInitializeFooTarget() {
906 /// extern Target TheFooTarget;
907 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
909 struct RegisterMCCodeGenInfoFn {
910 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
911 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
915 /// RegisterMCInstrInfo - Helper template for registering a target instruction
916 /// info implementation. This invokes the static "Create" method on the class
917 /// to actually do the construction. Usage:
919 /// extern "C" void LLVMInitializeFooTarget() {
920 /// extern Target TheFooTarget;
921 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
923 template<class MCInstrInfoImpl>
924 struct RegisterMCInstrInfo {
925 RegisterMCInstrInfo(Target &T) {
926 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
929 static MCInstrInfo *Allocator() {
930 return new MCInstrInfoImpl();
934 /// RegisterMCInstrInfoFn - Helper template for registering a target
935 /// instruction info implementation. This invokes the specified function to
936 /// do the construction. Usage:
938 /// extern "C" void LLVMInitializeFooTarget() {
939 /// extern Target TheFooTarget;
940 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
942 struct RegisterMCInstrInfoFn {
943 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
944 TargetRegistry::RegisterMCInstrInfo(T, Fn);
948 /// RegisterMCInstrAnalysis - Helper template for registering a target
949 /// instruction analyzer implementation. This invokes the static "Create"
950 /// method on the class to actually do the construction. Usage:
952 /// extern "C" void LLVMInitializeFooTarget() {
953 /// extern Target TheFooTarget;
954 /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
956 template<class MCInstrAnalysisImpl>
957 struct RegisterMCInstrAnalysis {
958 RegisterMCInstrAnalysis(Target &T) {
959 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
962 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
963 return new MCInstrAnalysisImpl(Info);
967 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
968 /// instruction analyzer implementation. This invokes the specified function
969 /// to do the construction. Usage:
971 /// extern "C" void LLVMInitializeFooTarget() {
972 /// extern Target TheFooTarget;
973 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
975 struct RegisterMCInstrAnalysisFn {
976 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
977 TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
981 /// RegisterMCRegInfo - Helper template for registering a target register info
982 /// implementation. This invokes the static "Create" method on the class to
983 /// actually do the construction. Usage:
985 /// extern "C" void LLVMInitializeFooTarget() {
986 /// extern Target TheFooTarget;
987 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
989 template<class MCRegisterInfoImpl>
990 struct RegisterMCRegInfo {
991 RegisterMCRegInfo(Target &T) {
992 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
995 static MCRegisterInfo *Allocator(StringRef /*TT*/) {
996 return new MCRegisterInfoImpl();
1000 /// RegisterMCRegInfoFn - Helper template for registering a target register
1001 /// info implementation. This invokes the specified function to do the
1002 /// construction. Usage:
1004 /// extern "C" void LLVMInitializeFooTarget() {
1005 /// extern Target TheFooTarget;
1006 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
1008 struct RegisterMCRegInfoFn {
1009 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
1010 TargetRegistry::RegisterMCRegInfo(T, Fn);
1014 /// RegisterMCSubtargetInfo - Helper template for registering a target
1015 /// subtarget info implementation. This invokes the static "Create" method
1016 /// on the class to actually do the construction. Usage:
1018 /// extern "C" void LLVMInitializeFooTarget() {
1019 /// extern Target TheFooTarget;
1020 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
1022 template<class MCSubtargetInfoImpl>
1023 struct RegisterMCSubtargetInfo {
1024 RegisterMCSubtargetInfo(Target &T) {
1025 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
1028 static MCSubtargetInfo *Allocator(StringRef /*TT*/, StringRef /*CPU*/,
1030 return new MCSubtargetInfoImpl();
1034 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
1035 /// subtarget info implementation. This invokes the specified function to
1036 /// do the construction. Usage:
1038 /// extern "C" void LLVMInitializeFooTarget() {
1039 /// extern Target TheFooTarget;
1040 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1042 struct RegisterMCSubtargetInfoFn {
1043 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
1044 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
1048 /// RegisterTargetMachine - Helper template for registering a target machine
1049 /// implementation, for use in the target machine initialization
1050 /// function. Usage:
1052 /// extern "C" void LLVMInitializeFooTarget() {
1053 /// extern Target TheFooTarget;
1054 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1056 template<class TargetMachineImpl>
1057 struct RegisterTargetMachine {
1058 RegisterTargetMachine(Target &T) {
1059 TargetRegistry::RegisterTargetMachine(T, &Allocator);
1063 static TargetMachine *Allocator(const Target &T, StringRef TT,
1064 StringRef CPU, StringRef FS,
1065 const TargetOptions &Options,
1067 CodeModel::Model CM,
1068 CodeGenOpt::Level OL) {
1069 return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
1073 /// RegisterMCAsmBackend - Helper template for registering a target specific
1074 /// assembler backend. Usage:
1076 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1077 /// extern Target TheFooTarget;
1078 /// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1080 template<class MCAsmBackendImpl>
1081 struct RegisterMCAsmBackend {
1082 RegisterMCAsmBackend(Target &T) {
1083 TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1087 static MCAsmBackend *Allocator(const Target &T,
1088 const MCRegisterInfo &MRI,
1089 StringRef Triple, StringRef CPU) {
1090 return new MCAsmBackendImpl(T, MRI, Triple, CPU);
1094 /// RegisterMCAsmParser - Helper template for registering a target specific
1095 /// assembly parser, for use in the target machine initialization
1096 /// function. Usage:
1098 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1099 /// extern Target TheFooTarget;
1100 /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1102 template<class MCAsmParserImpl>
1103 struct RegisterMCAsmParser {
1104 RegisterMCAsmParser(Target &T) {
1105 TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1109 static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P,
1110 const MCInstrInfo &MII) {
1111 return new MCAsmParserImpl(STI, P, MII);
1115 /// RegisterAsmPrinter - Helper template for registering a target specific
1116 /// assembly printer, for use in the target machine initialization
1117 /// function. Usage:
1119 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1120 /// extern Target TheFooTarget;
1121 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1123 template<class AsmPrinterImpl>
1124 struct RegisterAsmPrinter {
1125 RegisterAsmPrinter(Target &T) {
1126 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1130 static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) {
1131 return new AsmPrinterImpl(TM, Streamer);
1135 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1136 /// machine code emitter, for use in the target initialization
1137 /// function. Usage:
1139 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1140 /// extern Target TheFooTarget;
1141 /// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1143 template<class MCCodeEmitterImpl>
1144 struct RegisterMCCodeEmitter {
1145 RegisterMCCodeEmitter(Target &T) {
1146 TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1150 static MCCodeEmitter *Allocator(const MCInstrInfo &/*II*/,
1151 const MCRegisterInfo &/*MRI*/,
1152 const MCSubtargetInfo &/*STI*/,
1153 MCContext &/*Ctx*/) {
1154 return new MCCodeEmitterImpl();