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 assert(!T.MCAsmInfoCtorFn);
602 T.MCAsmInfoCtorFn = Fn;
605 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
608 /// Clients are responsible for ensuring that registration doesn't occur
609 /// while another thread is attempting to access the registry. Typically
610 /// this is done by initializing all targets at program startup.
612 /// @param T - The target being registered.
613 /// @param Fn - A function to construct a MCCodeGenInfo for the target.
614 static void RegisterMCCodeGenInfo(Target &T,
615 Target::MCCodeGenInfoCtorFnTy Fn) {
616 assert(!T.MCCodeGenInfoCtorFn);
617 T.MCCodeGenInfoCtorFn = Fn;
620 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
623 /// Clients are responsible for ensuring that registration doesn't occur
624 /// while another thread is attempting to access the registry. Typically
625 /// this is done by initializing all targets at program startup.
627 /// @param T - The target being registered.
628 /// @param Fn - A function to construct a MCInstrInfo for the target.
629 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
630 assert(!T.MCInstrInfoCtorFn);
631 T.MCInstrInfoCtorFn = Fn;
634 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
635 /// the given target.
636 static void RegisterMCInstrAnalysis(Target &T,
637 Target::MCInstrAnalysisCtorFnTy Fn) {
638 assert(!T.MCInstrAnalysisCtorFn);
639 T.MCInstrAnalysisCtorFn = Fn;
642 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
645 /// Clients are responsible for ensuring that registration doesn't occur
646 /// while another thread is attempting to access the registry. Typically
647 /// this is done by initializing all targets at program startup.
649 /// @param T - The target being registered.
650 /// @param Fn - A function to construct a MCRegisterInfo for the target.
651 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
652 assert(!T.MCRegInfoCtorFn);
653 T.MCRegInfoCtorFn = Fn;
656 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
657 /// the given target.
659 /// Clients are responsible for ensuring that registration doesn't occur
660 /// while another thread is attempting to access the registry. Typically
661 /// this is done by initializing all targets at program startup.
663 /// @param T - The target being registered.
664 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
665 static void RegisterMCSubtargetInfo(Target &T,
666 Target::MCSubtargetInfoCtorFnTy Fn) {
667 assert(!T.MCSubtargetInfoCtorFn);
668 T.MCSubtargetInfoCtorFn = Fn;
671 /// RegisterTargetMachine - Register a TargetMachine implementation for the
674 /// Clients are responsible for ensuring that registration doesn't occur
675 /// while another thread is attempting to access the registry. Typically
676 /// this is done by initializing all targets at program startup.
678 /// @param T - The target being registered.
679 /// @param Fn - A function to construct a TargetMachine for the target.
680 static void RegisterTargetMachine(Target &T,
681 Target::TargetMachineCtorTy Fn) {
682 assert(!T.TargetMachineCtorFn);
683 T.TargetMachineCtorFn = Fn;
686 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
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 AsmBackend for the target.
695 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
696 assert(!T.MCAsmBackendCtorFn);
697 T.MCAsmBackendCtorFn = Fn;
700 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
701 /// the given target.
703 /// Clients are responsible for ensuring that registration doesn't occur
704 /// while another thread is attempting to access the registry. Typically
705 /// this is done by initializing all targets at program startup.
707 /// @param T - The target being registered.
708 /// @param Fn - A function to construct an MCTargetAsmParser for the target.
709 static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
710 assert(!T.MCAsmParserCtorFn);
711 T.MCAsmParserCtorFn = Fn;
714 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
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 AsmPrinter for the target.
723 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
724 assert(!T.AsmPrinterCtorFn);
725 T.AsmPrinterCtorFn = Fn;
728 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
729 /// the given target.
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 MCDisassembler for the target.
737 static void RegisterMCDisassembler(Target &T,
738 Target::MCDisassemblerCtorTy Fn) {
739 assert(!T.MCDisassemblerCtorFn);
740 T.MCDisassemblerCtorFn = Fn;
743 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
746 /// Clients are responsible for ensuring that registration doesn't occur
747 /// while another thread is attempting to access the registry. Typically
748 /// this is done by initializing all targets at program startup.
750 /// @param T - The target being registered.
751 /// @param Fn - A function to construct an MCInstPrinter for the target.
752 static void RegisterMCInstPrinter(Target &T,
753 Target::MCInstPrinterCtorTy Fn) {
754 assert(!T.MCInstPrinterCtorFn);
755 T.MCInstPrinterCtorFn = Fn;
758 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
761 /// Clients are responsible for ensuring that registration doesn't occur
762 /// while another thread is attempting to access the registry. Typically
763 /// this is done by initializing all targets at program startup.
765 /// @param T - The target being registered.
766 /// @param Fn - A function to construct an MCCodeEmitter for the target.
767 static void RegisterMCCodeEmitter(Target &T,
768 Target::MCCodeEmitterCtorTy Fn) {
769 assert(!T.MCCodeEmitterCtorFn);
770 T.MCCodeEmitterCtorFn = Fn;
773 /// RegisterMCObjectStreamer - Register a object code MCStreamer
774 /// implementation for the given target.
776 /// Clients are responsible for ensuring that registration doesn't occur
777 /// while another thread is attempting to access the registry. Typically
778 /// this is done by initializing all targets at program startup.
780 /// @param T - The target being registered.
781 /// @param Fn - A function to construct an MCStreamer for the target.
782 static void RegisterMCObjectStreamer(Target &T,
783 Target::MCObjectStreamerCtorTy Fn) {
784 assert(!T.MCObjectStreamerCtorFn);
785 T.MCObjectStreamerCtorFn = Fn;
788 /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
789 /// for the given target.
791 /// Clients are responsible for ensuring that registration doesn't occur
792 /// while another thread is attempting to access the registry. Typically
793 /// this is done by initializing all targets at program startup.
795 /// @param T - The target being registered.
796 /// @param Fn - A function to construct an MCStreamer for the target.
797 static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
798 assert(!T.AsmStreamerCtorFn);
799 T.AsmStreamerCtorFn = Fn;
802 /// RegisterMCRelocationInfo - Register an MCRelocationInfo
803 /// implementation for the given target.
805 /// Clients are responsible for ensuring that registration doesn't occur
806 /// while another thread is attempting to access the registry. Typically
807 /// this is done by initializing all targets at program startup.
809 /// @param T - The target being registered.
810 /// @param Fn - A function to construct an MCRelocationInfo for the target.
811 static void RegisterMCRelocationInfo(Target &T,
812 Target::MCRelocationInfoCtorTy Fn) {
813 assert(!T.MCRelocationInfoCtorFn);
814 T.MCRelocationInfoCtorFn = Fn;
817 /// RegisterMCSymbolizer - Register an MCSymbolizer
818 /// implementation for the given target.
820 /// Clients are responsible for ensuring that registration doesn't occur
821 /// while another thread is attempting to access the registry. Typically
822 /// this is done by initializing all targets at program startup.
824 /// @param T - The target being registered.
825 /// @param Fn - A function to construct an MCSymbolizer for the target.
826 static void RegisterMCSymbolizer(Target &T,
827 Target::MCSymbolizerCtorTy Fn) {
828 assert(!T.MCSymbolizerCtorFn);
829 T.MCSymbolizerCtorFn = Fn;
836 //===--------------------------------------------------------------------===//
838 /// RegisterTarget - Helper template for registering a target, for use in the
839 /// target's initialization function. Usage:
842 /// Target TheFooTarget; // The global target instance.
844 /// extern "C" void LLVMInitializeFooTargetInfo() {
845 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
847 template<Triple::ArchType TargetArchType = Triple::UnknownArch,
849 struct RegisterTarget {
850 RegisterTarget(Target &T, const char *Name, const char *Desc) {
851 TargetRegistry::RegisterTarget(T, Name, Desc,
852 &getTripleMatchQuality,
856 static unsigned getTripleMatchQuality(const std::string &TT) {
857 if (Triple(TT).getArch() == TargetArchType)
863 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
864 /// implementation. This invokes the static "Create" method on the class to
865 /// actually do the construction. Usage:
867 /// extern "C" void LLVMInitializeFooTarget() {
868 /// extern Target TheFooTarget;
869 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
871 template<class MCAsmInfoImpl>
872 struct RegisterMCAsmInfo {
873 RegisterMCAsmInfo(Target &T) {
874 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
877 static MCAsmInfo *Allocator(const MCRegisterInfo &/*MRI*/, StringRef TT) {
878 return new MCAsmInfoImpl(TT);
883 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
884 /// implementation. This invokes the specified function to do the
885 /// construction. Usage:
887 /// extern "C" void LLVMInitializeFooTarget() {
888 /// extern Target TheFooTarget;
889 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
891 struct RegisterMCAsmInfoFn {
892 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
893 TargetRegistry::RegisterMCAsmInfo(T, Fn);
897 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
898 /// implementation. This invokes the static "Create" method on the class
899 /// to actually do the construction. Usage:
901 /// extern "C" void LLVMInitializeFooTarget() {
902 /// extern Target TheFooTarget;
903 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
905 template<class MCCodeGenInfoImpl>
906 struct RegisterMCCodeGenInfo {
907 RegisterMCCodeGenInfo(Target &T) {
908 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
911 static MCCodeGenInfo *Allocator(StringRef /*TT*/, Reloc::Model /*RM*/,
912 CodeModel::Model /*CM*/,
913 CodeGenOpt::Level /*OL*/) {
914 return new MCCodeGenInfoImpl();
918 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
919 /// info implementation. This invokes the specified function to do the
920 /// construction. Usage:
922 /// extern "C" void LLVMInitializeFooTarget() {
923 /// extern Target TheFooTarget;
924 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
926 struct RegisterMCCodeGenInfoFn {
927 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
928 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
932 /// RegisterMCInstrInfo - Helper template for registering a target instruction
933 /// info implementation. This invokes the static "Create" method on the class
934 /// to actually do the construction. Usage:
936 /// extern "C" void LLVMInitializeFooTarget() {
937 /// extern Target TheFooTarget;
938 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
940 template<class MCInstrInfoImpl>
941 struct RegisterMCInstrInfo {
942 RegisterMCInstrInfo(Target &T) {
943 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
946 static MCInstrInfo *Allocator() {
947 return new MCInstrInfoImpl();
951 /// RegisterMCInstrInfoFn - Helper template for registering a target
952 /// instruction info implementation. This invokes the specified function to
953 /// do the construction. Usage:
955 /// extern "C" void LLVMInitializeFooTarget() {
956 /// extern Target TheFooTarget;
957 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
959 struct RegisterMCInstrInfoFn {
960 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
961 TargetRegistry::RegisterMCInstrInfo(T, Fn);
965 /// RegisterMCInstrAnalysis - Helper template for registering a target
966 /// instruction analyzer implementation. This invokes the static "Create"
967 /// method on the class to actually do the construction. Usage:
969 /// extern "C" void LLVMInitializeFooTarget() {
970 /// extern Target TheFooTarget;
971 /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
973 template<class MCInstrAnalysisImpl>
974 struct RegisterMCInstrAnalysis {
975 RegisterMCInstrAnalysis(Target &T) {
976 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
979 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
980 return new MCInstrAnalysisImpl(Info);
984 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
985 /// instruction analyzer implementation. This invokes the specified function
986 /// to do the construction. Usage:
988 /// extern "C" void LLVMInitializeFooTarget() {
989 /// extern Target TheFooTarget;
990 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
992 struct RegisterMCInstrAnalysisFn {
993 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
994 TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
998 /// RegisterMCRegInfo - Helper template for registering a target register info
999 /// implementation. This invokes the static "Create" method on the class to
1000 /// actually do the construction. Usage:
1002 /// extern "C" void LLVMInitializeFooTarget() {
1003 /// extern Target TheFooTarget;
1004 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
1006 template<class MCRegisterInfoImpl>
1007 struct RegisterMCRegInfo {
1008 RegisterMCRegInfo(Target &T) {
1009 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
1012 static MCRegisterInfo *Allocator(StringRef /*TT*/) {
1013 return new MCRegisterInfoImpl();
1017 /// RegisterMCRegInfoFn - Helper template for registering a target register
1018 /// info implementation. This invokes the specified function to do the
1019 /// construction. Usage:
1021 /// extern "C" void LLVMInitializeFooTarget() {
1022 /// extern Target TheFooTarget;
1023 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
1025 struct RegisterMCRegInfoFn {
1026 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
1027 TargetRegistry::RegisterMCRegInfo(T, Fn);
1031 /// RegisterMCSubtargetInfo - Helper template for registering a target
1032 /// subtarget info implementation. This invokes the static "Create" method
1033 /// on the class to actually do the construction. Usage:
1035 /// extern "C" void LLVMInitializeFooTarget() {
1036 /// extern Target TheFooTarget;
1037 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
1039 template<class MCSubtargetInfoImpl>
1040 struct RegisterMCSubtargetInfo {
1041 RegisterMCSubtargetInfo(Target &T) {
1042 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
1045 static MCSubtargetInfo *Allocator(StringRef /*TT*/, StringRef /*CPU*/,
1047 return new MCSubtargetInfoImpl();
1051 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
1052 /// subtarget info implementation. This invokes the specified function to
1053 /// do the construction. Usage:
1055 /// extern "C" void LLVMInitializeFooTarget() {
1056 /// extern Target TheFooTarget;
1057 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1059 struct RegisterMCSubtargetInfoFn {
1060 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
1061 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
1065 /// RegisterTargetMachine - Helper template for registering a target machine
1066 /// implementation, for use in the target machine initialization
1067 /// function. Usage:
1069 /// extern "C" void LLVMInitializeFooTarget() {
1070 /// extern Target TheFooTarget;
1071 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1073 template<class TargetMachineImpl>
1074 struct RegisterTargetMachine {
1075 RegisterTargetMachine(Target &T) {
1076 TargetRegistry::RegisterTargetMachine(T, &Allocator);
1080 static TargetMachine *Allocator(const Target &T, StringRef TT,
1081 StringRef CPU, StringRef FS,
1082 const TargetOptions &Options,
1084 CodeModel::Model CM,
1085 CodeGenOpt::Level OL) {
1086 return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
1090 /// RegisterMCAsmBackend - Helper template for registering a target specific
1091 /// assembler backend. Usage:
1093 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1094 /// extern Target TheFooTarget;
1095 /// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1097 template<class MCAsmBackendImpl>
1098 struct RegisterMCAsmBackend {
1099 RegisterMCAsmBackend(Target &T) {
1100 TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1104 static MCAsmBackend *Allocator(const Target &T,
1105 const MCRegisterInfo &MRI,
1106 StringRef Triple, StringRef CPU) {
1107 return new MCAsmBackendImpl(T, MRI, Triple, CPU);
1111 /// RegisterMCAsmParser - Helper template for registering a target specific
1112 /// assembly parser, for use in the target machine initialization
1113 /// function. Usage:
1115 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1116 /// extern Target TheFooTarget;
1117 /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1119 template<class MCAsmParserImpl>
1120 struct RegisterMCAsmParser {
1121 RegisterMCAsmParser(Target &T) {
1122 TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1126 static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P,
1127 const MCInstrInfo &MII) {
1128 return new MCAsmParserImpl(STI, P, MII);
1132 /// RegisterAsmPrinter - Helper template for registering a target specific
1133 /// assembly printer, for use in the target machine initialization
1134 /// function. Usage:
1136 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1137 /// extern Target TheFooTarget;
1138 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1140 template<class AsmPrinterImpl>
1141 struct RegisterAsmPrinter {
1142 RegisterAsmPrinter(Target &T) {
1143 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1147 static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) {
1148 return new AsmPrinterImpl(TM, Streamer);
1152 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1153 /// machine code emitter, for use in the target initialization
1154 /// function. Usage:
1156 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1157 /// extern Target TheFooTarget;
1158 /// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1160 template<class MCCodeEmitterImpl>
1161 struct RegisterMCCodeEmitter {
1162 RegisterMCCodeEmitter(Target &T) {
1163 TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1167 static MCCodeEmitter *Allocator(const MCInstrInfo &/*II*/,
1168 const MCRegisterInfo &/*MRI*/,
1169 const MCSubtargetInfo &/*STI*/,
1170 MCContext &/*Ctx*/) {
1171 return new MCCodeEmitterImpl();