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;
239 createDefaultAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
240 bool isVerboseAsm, bool useLoc, bool useCFI,
241 bool useDwarfDirectory, MCInstPrinter *InstPrint,
242 MCCodeEmitter *CE, MCAsmBackend *TAB,
244 return llvm::createAsmStreamer(Ctx, 0, OS, isVerboseAsm, useLoc, useCFI,
245 useDwarfDirectory, InstPrint, CE, TAB,
251 : AsmStreamerCtorFn(createDefaultAsmStreamer),
252 MCRelocationInfoCtorFn(llvm::createMCRelocationInfo),
253 MCSymbolizerCtorFn(llvm::createMCSymbolizer) {}
255 /// @name Target Information
258 // getNext - Return the next registered target.
259 const Target *getNext() const { return Next; }
261 /// getName - Get the target name.
262 const char *getName() const { return Name; }
264 /// getShortDescription - Get a short description of the target.
265 const char *getShortDescription() const { return ShortDesc; }
268 /// @name Feature Predicates
271 /// hasJIT - Check if this targets supports the just-in-time compilation.
272 bool hasJIT() const { return HasJIT; }
274 /// hasTargetMachine - Check if this target supports code generation.
275 bool hasTargetMachine() const { return TargetMachineCtorFn != 0; }
277 /// hasMCAsmBackend - Check if this target supports .o generation.
278 bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != 0; }
281 /// @name Feature Constructors
284 /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
287 /// \param Triple This argument is used to determine the target machine
288 /// feature set; it should always be provided. Generally this should be
289 /// either the target triple from the module, or the target triple of the
290 /// host if that does not exist.
291 MCAsmInfo *createMCAsmInfo(const MCRegisterInfo &MRI,
292 StringRef Triple) const {
293 if (!MCAsmInfoCtorFn)
295 return MCAsmInfoCtorFn(MRI, Triple);
298 /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
300 MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model RM,
302 CodeGenOpt::Level OL) const {
303 if (!MCCodeGenInfoCtorFn)
305 return MCCodeGenInfoCtorFn(Triple, RM, CM, OL);
308 /// createMCInstrInfo - Create a MCInstrInfo implementation.
310 MCInstrInfo *createMCInstrInfo() const {
311 if (!MCInstrInfoCtorFn)
313 return MCInstrInfoCtorFn();
316 /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
318 MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
319 if (!MCInstrAnalysisCtorFn)
321 return MCInstrAnalysisCtorFn(Info);
324 /// createMCRegInfo - Create a MCRegisterInfo implementation.
326 MCRegisterInfo *createMCRegInfo(StringRef Triple) const {
327 if (!MCRegInfoCtorFn)
329 return MCRegInfoCtorFn(Triple);
332 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
334 /// \param Triple This argument is used to determine the target machine
335 /// feature set; it should always be provided. Generally this should be
336 /// either the target triple from the module, or the target triple of the
337 /// host if that does not exist.
338 /// \param CPU This specifies the name of the target CPU.
339 /// \param Features This specifies the string representation of the
340 /// additional target features.
341 MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU,
342 StringRef Features) const {
343 if (!MCSubtargetInfoCtorFn)
345 return MCSubtargetInfoCtorFn(Triple, CPU, Features);
348 /// createTargetMachine - Create a target specific machine implementation
349 /// for the specified \p Triple.
351 /// \param Triple This argument is used to determine the target machine
352 /// feature set; it should always be provided. Generally this should be
353 /// either the target triple from the module, or the target triple of the
354 /// host if that does not exist.
355 TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU,
356 StringRef Features, const TargetOptions &Options,
357 Reloc::Model RM = Reloc::Default,
358 CodeModel::Model CM = CodeModel::Default,
359 CodeGenOpt::Level OL = CodeGenOpt::Default) const {
360 if (!TargetMachineCtorFn)
362 return TargetMachineCtorFn(*this, Triple, CPU, Features, Options,
366 /// createMCAsmBackend - Create a target specific assembly parser.
368 /// \param Triple The target triple string.
369 MCAsmBackend *createMCAsmBackend(const MCRegisterInfo &MRI,
370 StringRef Triple, StringRef CPU) const {
371 if (!MCAsmBackendCtorFn)
373 return MCAsmBackendCtorFn(*this, MRI, Triple, CPU);
376 /// createMCAsmParser - Create a target specific assembly parser.
378 /// \param Parser The target independent parser implementation to use for
379 /// parsing and lexing.
380 MCTargetAsmParser *createMCAsmParser(MCSubtargetInfo &STI,
382 const MCInstrInfo &MII) const {
383 if (!MCAsmParserCtorFn)
385 return MCAsmParserCtorFn(STI, Parser, MII);
388 /// createAsmPrinter - Create a target specific assembly printer pass. This
389 /// takes ownership of the MCStreamer object.
390 AsmPrinter *createAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) const{
391 if (!AsmPrinterCtorFn)
393 return AsmPrinterCtorFn(TM, Streamer);
396 MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI) const {
397 if (!MCDisassemblerCtorFn)
399 return MCDisassemblerCtorFn(*this, STI);
402 MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
403 const MCAsmInfo &MAI,
404 const MCInstrInfo &MII,
405 const MCRegisterInfo &MRI,
406 const MCSubtargetInfo &STI) const {
407 if (!MCInstPrinterCtorFn)
409 return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, MII, MRI, STI);
413 /// createMCCodeEmitter - Create a target specific code emitter.
414 MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
415 const MCRegisterInfo &MRI,
416 const MCSubtargetInfo &STI,
417 MCContext &Ctx) const {
418 if (!MCCodeEmitterCtorFn)
420 return MCCodeEmitterCtorFn(II, MRI, STI, Ctx);
423 /// createMCObjectStreamer - Create a target specific MCStreamer.
425 /// \param TT The target triple.
426 /// \param Ctx The target context.
427 /// \param TAB The target assembler backend object. Takes ownership.
428 /// \param _OS The stream object.
429 /// \param _Emitter The target independent assembler object.Takes ownership.
430 /// \param RelaxAll Relax all fixups?
431 /// \param NoExecStack Mark file as not needing a executable stack.
432 MCStreamer *createMCObjectStreamer(StringRef TT, MCContext &Ctx,
435 MCCodeEmitter *_Emitter,
437 bool NoExecStack) const {
438 if (!MCObjectStreamerCtorFn)
440 return MCObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter,
441 RelaxAll, NoExecStack);
444 /// createAsmStreamer - Create a target specific MCStreamer.
445 MCStreamer *createAsmStreamer(MCContext &Ctx,
446 formatted_raw_ostream &OS,
450 bool useDwarfDirectory,
451 MCInstPrinter *InstPrint,
454 bool ShowInst) const {
455 // AsmStreamerCtorFn is default to llvm::createAsmStreamer
456 return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useLoc, useCFI,
457 useDwarfDirectory, InstPrint, CE, TAB, ShowInst);
460 /// createMCRelocationInfo - Create a target specific MCRelocationInfo.
462 /// \param TT The target triple.
463 /// \param Ctx The target context.
465 createMCRelocationInfo(StringRef TT, MCContext &Ctx) const {
466 return MCRelocationInfoCtorFn(TT, Ctx);
469 /// createMCSymbolizer - Create a target specific MCSymbolizer.
471 /// \param TT The target triple.
472 /// \param GetOpInfo The function to get the symbolic information for operands.
473 /// \param SymbolLookUp The function to lookup a symbol name.
474 /// \param DisInfo The pointer to the block of symbolic information for above call
476 /// \param Ctx The target context.
477 /// \param RelInfo The relocation information for this target. Takes ownership.
479 createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
480 LLVMSymbolLookupCallback SymbolLookUp,
482 MCContext *Ctx, MCRelocationInfo *RelInfo) const {
483 return MCSymbolizerCtorFn(TT, GetOpInfo, SymbolLookUp, DisInfo,
490 /// TargetRegistry - Generic interface to target specific features.
491 struct TargetRegistry {
493 const Target *Current;
494 explicit iterator(Target *T) : Current(T) {}
495 friend struct TargetRegistry;
497 iterator(const iterator &I) : Current(I.Current) {}
498 iterator() : Current(0) {}
500 bool operator==(const iterator &x) const {
501 return Current == x.Current;
503 bool operator!=(const iterator &x) const {
504 return !operator==(x);
507 // Iterator traversal: forward iteration only
508 iterator &operator++() { // Preincrement
509 assert(Current && "Cannot increment end iterator!");
510 Current = Current->getNext();
513 iterator operator++(int) { // Postincrement
514 iterator tmp = *this;
519 const Target &operator*() const {
520 assert(Current && "Cannot dereference end iterator!");
524 const Target *operator->() const {
529 /// printRegisteredTargetsForVersion - Print the registered targets
530 /// appropriately for inclusion in a tool's version output.
531 static void printRegisteredTargetsForVersion();
533 /// @name Registry Access
536 static iterator begin();
538 static iterator end() { return iterator(); }
540 /// lookupTarget - Lookup a target based on a target triple.
542 /// \param Triple - The triple to use for finding a target.
543 /// \param Error - On failure, an error string describing why no target was
545 static const Target *lookupTarget(const std::string &Triple,
548 /// lookupTarget - Lookup a target based on an architecture name
549 /// and a target triple. If the architecture name is non-empty,
550 /// then the lookup is done by architecture. Otherwise, the target
553 /// \param ArchName - The architecture to use for finding a target.
554 /// \param TheTriple - The triple to use for finding a target. The
555 /// triple is updated with canonical architecture name if a lookup
556 /// by architecture is done.
557 /// \param Error - On failure, an error string describing why no target was
559 static const Target *lookupTarget(const std::string &ArchName,
563 /// getClosestTargetForJIT - Pick the best target that is compatible with
564 /// the current host. If no close target can be found, this returns null
565 /// and sets the Error string to a reason.
567 /// Maintained for compatibility through 2.6.
568 static const Target *getClosestTargetForJIT(std::string &Error);
571 /// @name Target Registration
574 /// RegisterTarget - Register the given target. Attempts to register a
575 /// target which has already been registered will be ignored.
577 /// Clients are responsible for ensuring that registration doesn't occur
578 /// while another thread is attempting to access the registry. Typically
579 /// this is done by initializing all targets at program startup.
581 /// @param T - The target being registered.
582 /// @param Name - The target name. This should be a static string.
583 /// @param ShortDesc - A short target description. This should be a static
585 /// @param TQualityFn - The triple match quality computation function for
587 /// @param HasJIT - Whether the target supports JIT code
589 static void RegisterTarget(Target &T,
591 const char *ShortDesc,
592 Target::TripleMatchQualityFnTy TQualityFn,
593 bool HasJIT = false);
595 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
598 /// Clients are responsible for ensuring that registration doesn't occur
599 /// while another thread is attempting to access the registry. Typically
600 /// this is done by initializing all targets at program startup.
602 /// @param T - The target being registered.
603 /// @param Fn - A function to construct a MCAsmInfo for the target.
604 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
605 // Ignore duplicate registration.
606 if (!T.MCAsmInfoCtorFn)
607 T.MCAsmInfoCtorFn = Fn;
610 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
613 /// Clients are responsible for ensuring that registration doesn't occur
614 /// while another thread is attempting to access the registry. Typically
615 /// this is done by initializing all targets at program startup.
617 /// @param T - The target being registered.
618 /// @param Fn - A function to construct a MCCodeGenInfo for the target.
619 static void RegisterMCCodeGenInfo(Target &T,
620 Target::MCCodeGenInfoCtorFnTy Fn) {
621 // Ignore duplicate registration.
622 if (!T.MCCodeGenInfoCtorFn)
623 T.MCCodeGenInfoCtorFn = Fn;
626 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
629 /// Clients are responsible for ensuring that registration doesn't occur
630 /// while another thread is attempting to access the registry. Typically
631 /// this is done by initializing all targets at program startup.
633 /// @param T - The target being registered.
634 /// @param Fn - A function to construct a MCInstrInfo for the target.
635 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
636 // Ignore duplicate registration.
637 if (!T.MCInstrInfoCtorFn)
638 T.MCInstrInfoCtorFn = Fn;
641 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
642 /// the given target.
643 static void RegisterMCInstrAnalysis(Target &T,
644 Target::MCInstrAnalysisCtorFnTy Fn) {
645 // Ignore duplicate registration.
646 if (!T.MCInstrAnalysisCtorFn)
647 T.MCInstrAnalysisCtorFn = Fn;
650 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
653 /// Clients are responsible for ensuring that registration doesn't occur
654 /// while another thread is attempting to access the registry. Typically
655 /// this is done by initializing all targets at program startup.
657 /// @param T - The target being registered.
658 /// @param Fn - A function to construct a MCRegisterInfo for the target.
659 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
660 // Ignore duplicate registration.
661 if (!T.MCRegInfoCtorFn)
662 T.MCRegInfoCtorFn = Fn;
665 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
666 /// the given target.
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 MCSubtargetInfo for the target.
674 static void RegisterMCSubtargetInfo(Target &T,
675 Target::MCSubtargetInfoCtorFnTy Fn) {
676 // Ignore duplicate registration.
677 if (!T.MCSubtargetInfoCtorFn)
678 T.MCSubtargetInfoCtorFn = Fn;
681 /// RegisterTargetMachine - Register a TargetMachine implementation for the
684 /// Clients are responsible for ensuring that registration doesn't occur
685 /// while another thread is attempting to access the registry. Typically
686 /// this is done by initializing all targets at program startup.
688 /// @param T - The target being registered.
689 /// @param Fn - A function to construct a TargetMachine for the target.
690 static void RegisterTargetMachine(Target &T,
691 Target::TargetMachineCtorTy Fn) {
692 // Ignore duplicate registration.
693 if (!T.TargetMachineCtorFn)
694 T.TargetMachineCtorFn = Fn;
697 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
700 /// Clients are responsible for ensuring that registration doesn't occur
701 /// while another thread is attempting to access the registry. Typically
702 /// this is done by initializing all targets at program startup.
704 /// @param T - The target being registered.
705 /// @param Fn - A function to construct an AsmBackend for the target.
706 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
707 if (!T.MCAsmBackendCtorFn)
708 T.MCAsmBackendCtorFn = Fn;
711 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
712 /// the given target.
714 /// Clients are responsible for ensuring that registration doesn't occur
715 /// while another thread is attempting to access the registry. Typically
716 /// this is done by initializing all targets at program startup.
718 /// @param T - The target being registered.
719 /// @param Fn - A function to construct an MCTargetAsmParser for the target.
720 static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
721 if (!T.MCAsmParserCtorFn)
722 T.MCAsmParserCtorFn = Fn;
725 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
728 /// Clients are responsible for ensuring that registration doesn't occur
729 /// while another thread is attempting to access the registry. Typically
730 /// this is done by initializing all targets at program startup.
732 /// @param T - The target being registered.
733 /// @param Fn - A function to construct an AsmPrinter for the target.
734 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
735 // Ignore duplicate registration.
736 if (!T.AsmPrinterCtorFn)
737 T.AsmPrinterCtorFn = Fn;
740 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
741 /// the given target.
743 /// Clients are responsible for ensuring that registration doesn't occur
744 /// while another thread is attempting to access the registry. Typically
745 /// this is done by initializing all targets at program startup.
747 /// @param T - The target being registered.
748 /// @param Fn - A function to construct an MCDisassembler for the target.
749 static void RegisterMCDisassembler(Target &T,
750 Target::MCDisassemblerCtorTy Fn) {
751 if (!T.MCDisassemblerCtorFn)
752 T.MCDisassemblerCtorFn = Fn;
755 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
758 /// Clients are responsible for ensuring that registration doesn't occur
759 /// while another thread is attempting to access the registry. Typically
760 /// this is done by initializing all targets at program startup.
762 /// @param T - The target being registered.
763 /// @param Fn - A function to construct an MCInstPrinter for the target.
764 static void RegisterMCInstPrinter(Target &T,
765 Target::MCInstPrinterCtorTy Fn) {
766 if (!T.MCInstPrinterCtorFn)
767 T.MCInstPrinterCtorFn = Fn;
770 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
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 MCCodeEmitter for the target.
779 static void RegisterMCCodeEmitter(Target &T,
780 Target::MCCodeEmitterCtorTy Fn) {
781 if (!T.MCCodeEmitterCtorFn)
782 T.MCCodeEmitterCtorFn = Fn;
785 /// RegisterMCObjectStreamer - Register a object code MCStreamer
786 /// implementation for the given target.
788 /// Clients are responsible for ensuring that registration doesn't occur
789 /// while another thread is attempting to access the registry. Typically
790 /// this is done by initializing all targets at program startup.
792 /// @param T - The target being registered.
793 /// @param Fn - A function to construct an MCStreamer for the target.
794 static void RegisterMCObjectStreamer(Target &T,
795 Target::MCObjectStreamerCtorTy Fn) {
796 if (!T.MCObjectStreamerCtorFn)
797 T.MCObjectStreamerCtorFn = Fn;
800 /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
801 /// for the given target.
803 /// Clients are responsible for ensuring that registration doesn't occur
804 /// while another thread is attempting to access the registry. Typically
805 /// this is done by initializing all targets at program startup.
807 /// @param T - The target being registered.
808 /// @param Fn - A function to construct an MCStreamer for the target.
809 static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
810 if (T.AsmStreamerCtorFn == Target::createDefaultAsmStreamer)
811 T.AsmStreamerCtorFn = Fn;
814 /// RegisterMCRelocationInfo - Register an MCRelocationInfo
815 /// implementation for the given target.
817 /// Clients are responsible for ensuring that registration doesn't occur
818 /// while another thread is attempting to access the registry. Typically
819 /// this is done by initializing all targets at program startup.
821 /// @param T - The target being registered.
822 /// @param Fn - A function to construct an MCRelocationInfo for the target.
823 static void RegisterMCRelocationInfo(Target &T,
824 Target::MCRelocationInfoCtorTy Fn) {
825 if (T.MCRelocationInfoCtorFn == llvm::createMCRelocationInfo)
826 T.MCRelocationInfoCtorFn = Fn;
829 /// RegisterMCSymbolizer - Register an MCSymbolizer
830 /// implementation for the given target.
832 /// Clients are responsible for ensuring that registration doesn't occur
833 /// while another thread is attempting to access the registry. Typically
834 /// this is done by initializing all targets at program startup.
836 /// @param T - The target being registered.
837 /// @param Fn - A function to construct an MCSymbolizer for the target.
838 static void RegisterMCSymbolizer(Target &T,
839 Target::MCSymbolizerCtorTy Fn) {
840 if (T.MCSymbolizerCtorFn == llvm::createMCSymbolizer)
841 T.MCSymbolizerCtorFn = Fn;
848 //===--------------------------------------------------------------------===//
850 /// RegisterTarget - Helper template for registering a target, for use in the
851 /// target's initialization function. Usage:
854 /// Target TheFooTarget; // The global target instance.
856 /// extern "C" void LLVMInitializeFooTargetInfo() {
857 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
859 template<Triple::ArchType TargetArchType = Triple::UnknownArch,
861 struct RegisterTarget {
862 RegisterTarget(Target &T, const char *Name, const char *Desc) {
863 TargetRegistry::RegisterTarget(T, Name, Desc,
864 &getTripleMatchQuality,
868 static unsigned getTripleMatchQuality(const std::string &TT) {
869 if (Triple(TT).getArch() == TargetArchType)
875 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
876 /// implementation. This invokes the static "Create" method on the class to
877 /// actually do the construction. Usage:
879 /// extern "C" void LLVMInitializeFooTarget() {
880 /// extern Target TheFooTarget;
881 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
883 template<class MCAsmInfoImpl>
884 struct RegisterMCAsmInfo {
885 RegisterMCAsmInfo(Target &T) {
886 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
889 static MCAsmInfo *Allocator(const MCRegisterInfo &/*MRI*/, StringRef TT) {
890 return new MCAsmInfoImpl(TT);
895 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
896 /// implementation. This invokes the specified function to do the
897 /// construction. Usage:
899 /// extern "C" void LLVMInitializeFooTarget() {
900 /// extern Target TheFooTarget;
901 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
903 struct RegisterMCAsmInfoFn {
904 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
905 TargetRegistry::RegisterMCAsmInfo(T, Fn);
909 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
910 /// implementation. This invokes the static "Create" method on the class
911 /// to actually do the construction. Usage:
913 /// extern "C" void LLVMInitializeFooTarget() {
914 /// extern Target TheFooTarget;
915 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
917 template<class MCCodeGenInfoImpl>
918 struct RegisterMCCodeGenInfo {
919 RegisterMCCodeGenInfo(Target &T) {
920 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
923 static MCCodeGenInfo *Allocator(StringRef /*TT*/, Reloc::Model /*RM*/,
924 CodeModel::Model /*CM*/,
925 CodeGenOpt::Level /*OL*/) {
926 return new MCCodeGenInfoImpl();
930 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
931 /// info implementation. This invokes the specified function to do the
932 /// construction. Usage:
934 /// extern "C" void LLVMInitializeFooTarget() {
935 /// extern Target TheFooTarget;
936 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
938 struct RegisterMCCodeGenInfoFn {
939 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
940 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
944 /// RegisterMCInstrInfo - Helper template for registering a target instruction
945 /// info implementation. This invokes the static "Create" method on the class
946 /// to actually do the construction. Usage:
948 /// extern "C" void LLVMInitializeFooTarget() {
949 /// extern Target TheFooTarget;
950 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
952 template<class MCInstrInfoImpl>
953 struct RegisterMCInstrInfo {
954 RegisterMCInstrInfo(Target &T) {
955 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
958 static MCInstrInfo *Allocator() {
959 return new MCInstrInfoImpl();
963 /// RegisterMCInstrInfoFn - Helper template for registering a target
964 /// instruction info implementation. This invokes the specified function to
965 /// do the construction. Usage:
967 /// extern "C" void LLVMInitializeFooTarget() {
968 /// extern Target TheFooTarget;
969 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
971 struct RegisterMCInstrInfoFn {
972 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
973 TargetRegistry::RegisterMCInstrInfo(T, Fn);
977 /// RegisterMCInstrAnalysis - Helper template for registering a target
978 /// instruction analyzer implementation. This invokes the static "Create"
979 /// method on the class to actually do the construction. Usage:
981 /// extern "C" void LLVMInitializeFooTarget() {
982 /// extern Target TheFooTarget;
983 /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
985 template<class MCInstrAnalysisImpl>
986 struct RegisterMCInstrAnalysis {
987 RegisterMCInstrAnalysis(Target &T) {
988 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
991 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
992 return new MCInstrAnalysisImpl(Info);
996 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
997 /// instruction analyzer implementation. This invokes the specified function
998 /// to do the construction. Usage:
1000 /// extern "C" void LLVMInitializeFooTarget() {
1001 /// extern Target TheFooTarget;
1002 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
1004 struct RegisterMCInstrAnalysisFn {
1005 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
1006 TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
1010 /// RegisterMCRegInfo - Helper template for registering a target register info
1011 /// implementation. This invokes the static "Create" method on the class to
1012 /// actually do the construction. Usage:
1014 /// extern "C" void LLVMInitializeFooTarget() {
1015 /// extern Target TheFooTarget;
1016 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
1018 template<class MCRegisterInfoImpl>
1019 struct RegisterMCRegInfo {
1020 RegisterMCRegInfo(Target &T) {
1021 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
1024 static MCRegisterInfo *Allocator(StringRef /*TT*/) {
1025 return new MCRegisterInfoImpl();
1029 /// RegisterMCRegInfoFn - Helper template for registering a target register
1030 /// info implementation. This invokes the specified function to do the
1031 /// construction. Usage:
1033 /// extern "C" void LLVMInitializeFooTarget() {
1034 /// extern Target TheFooTarget;
1035 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
1037 struct RegisterMCRegInfoFn {
1038 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
1039 TargetRegistry::RegisterMCRegInfo(T, Fn);
1043 /// RegisterMCSubtargetInfo - Helper template for registering a target
1044 /// subtarget info implementation. This invokes the static "Create" method
1045 /// on the class to actually do the construction. Usage:
1047 /// extern "C" void LLVMInitializeFooTarget() {
1048 /// extern Target TheFooTarget;
1049 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
1051 template<class MCSubtargetInfoImpl>
1052 struct RegisterMCSubtargetInfo {
1053 RegisterMCSubtargetInfo(Target &T) {
1054 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
1057 static MCSubtargetInfo *Allocator(StringRef /*TT*/, StringRef /*CPU*/,
1059 return new MCSubtargetInfoImpl();
1063 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
1064 /// subtarget info implementation. This invokes the specified function to
1065 /// do the construction. Usage:
1067 /// extern "C" void LLVMInitializeFooTarget() {
1068 /// extern Target TheFooTarget;
1069 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1071 struct RegisterMCSubtargetInfoFn {
1072 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
1073 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
1077 /// RegisterTargetMachine - Helper template for registering a target machine
1078 /// implementation, for use in the target machine initialization
1079 /// function. Usage:
1081 /// extern "C" void LLVMInitializeFooTarget() {
1082 /// extern Target TheFooTarget;
1083 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1085 template<class TargetMachineImpl>
1086 struct RegisterTargetMachine {
1087 RegisterTargetMachine(Target &T) {
1088 TargetRegistry::RegisterTargetMachine(T, &Allocator);
1092 static TargetMachine *Allocator(const Target &T, StringRef TT,
1093 StringRef CPU, StringRef FS,
1094 const TargetOptions &Options,
1096 CodeModel::Model CM,
1097 CodeGenOpt::Level OL) {
1098 return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
1102 /// RegisterMCAsmBackend - Helper template for registering a target specific
1103 /// assembler backend. Usage:
1105 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1106 /// extern Target TheFooTarget;
1107 /// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1109 template<class MCAsmBackendImpl>
1110 struct RegisterMCAsmBackend {
1111 RegisterMCAsmBackend(Target &T) {
1112 TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1116 static MCAsmBackend *Allocator(const Target &T,
1117 const MCRegisterInfo &MRI,
1118 StringRef Triple, StringRef CPU) {
1119 return new MCAsmBackendImpl(T, MRI, Triple, CPU);
1123 /// RegisterMCAsmParser - Helper template for registering a target specific
1124 /// assembly parser, for use in the target machine initialization
1125 /// function. Usage:
1127 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1128 /// extern Target TheFooTarget;
1129 /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1131 template<class MCAsmParserImpl>
1132 struct RegisterMCAsmParser {
1133 RegisterMCAsmParser(Target &T) {
1134 TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1138 static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P,
1139 const MCInstrInfo &MII) {
1140 return new MCAsmParserImpl(STI, P, MII);
1144 /// RegisterAsmPrinter - Helper template for registering a target specific
1145 /// assembly printer, for use in the target machine initialization
1146 /// function. Usage:
1148 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1149 /// extern Target TheFooTarget;
1150 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1152 template<class AsmPrinterImpl>
1153 struct RegisterAsmPrinter {
1154 RegisterAsmPrinter(Target &T) {
1155 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1159 static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) {
1160 return new AsmPrinterImpl(TM, Streamer);
1164 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1165 /// machine code emitter, for use in the target initialization
1166 /// function. Usage:
1168 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1169 /// extern Target TheFooTarget;
1170 /// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1172 template<class MCCodeEmitterImpl>
1173 struct RegisterMCCodeEmitter {
1174 RegisterMCCodeEmitter(Target &T) {
1175 TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1179 static MCCodeEmitter *Allocator(const MCInstrInfo &/*II*/,
1180 const MCRegisterInfo &/*MRI*/,
1181 const MCSubtargetInfo &/*STI*/,
1182 MCContext &/*Ctx*/) {
1183 return new MCCodeEmitterImpl();