1 //===-- Support/TargetRegistry.h - Target Registration ----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file exposes the TargetRegistry interface, which tools can use to access
11 // the appropriate target specific classes (TargetMachine, AsmPrinter, etc.)
12 // which have been registered.
14 // Target specific class implementations should register themselves using the
15 // appropriate TargetRegistry interfaces.
17 //===----------------------------------------------------------------------===//
19 #ifndef LLVM_SUPPORT_TARGETREGISTRY_H
20 #define LLVM_SUPPORT_TARGETREGISTRY_H
22 #include "llvm-c/Disassembler.h"
23 #include "llvm/ADT/Triple.h"
24 #include "llvm/Support/CodeGen.h"
39 class MCInstrAnalysis;
44 class MCSubtargetInfo;
46 class MCRelocationInfo;
47 class MCTargetAsmParser;
48 class MCTargetOptions;
52 class formatted_raw_ostream;
54 MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
55 bool isVerboseAsm, bool useDwarfDirectory,
56 MCInstPrinter *InstPrint, MCCodeEmitter *CE,
57 MCAsmBackend *TAB, bool ShowInst);
59 MCRelocationInfo *createMCRelocationInfo(StringRef TT, MCContext &Ctx);
61 MCSymbolizer *createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
62 LLVMSymbolLookupCallback SymbolLookUp,
65 MCRelocationInfo *RelInfo);
67 /// Target - Wrapper for Target specific information.
69 /// For registration purposes, this is a POD type so that targets can be
70 /// registered without the use of static constructors.
72 /// Targets should implement a single global instance of this class (which
73 /// will be zero initialized), and pass that instance to the TargetRegistry as
74 /// part of their initialization.
77 friend struct TargetRegistry;
79 typedef bool (*ArchMatchFnTy)(Triple::ArchType Arch);
81 typedef MCAsmInfo *(*MCAsmInfoCtorFnTy)(const MCRegisterInfo &MRI,
83 typedef MCCodeGenInfo *(*MCCodeGenInfoCtorFnTy)(StringRef TT,
86 CodeGenOpt::Level OL);
87 typedef MCInstrInfo *(*MCInstrInfoCtorFnTy)(void);
88 typedef MCInstrAnalysis *(*MCInstrAnalysisCtorFnTy)(const MCInstrInfo*Info);
89 typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(StringRef TT);
90 typedef MCSubtargetInfo *(*MCSubtargetInfoCtorFnTy)(StringRef TT,
93 typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T,
97 const TargetOptions &Options,
100 CodeGenOpt::Level OL);
101 typedef AsmPrinter *(*AsmPrinterCtorTy)(TargetMachine &TM,
102 MCStreamer &Streamer);
103 typedef MCAsmBackend *(*MCAsmBackendCtorTy)(const Target &T,
104 const MCRegisterInfo &MRI,
107 typedef MCTargetAsmParser *(*MCAsmParserCtorTy)(
108 MCSubtargetInfo &STI,
110 const MCInstrInfo &MII,
111 const MCTargetOptions &Options);
112 typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T,
113 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,
131 const MCSubtargetInfo &STI,
134 typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx,
135 formatted_raw_ostream &OS,
137 bool useDwarfDirectory,
138 MCInstPrinter *InstPrint,
142 typedef MCRelocationInfo *(*MCRelocationInfoCtorTy)(StringRef TT,
144 typedef MCSymbolizer *(*MCSymbolizerCtorTy)(StringRef TT,
145 LLVMOpInfoCallback GetOpInfo,
146 LLVMSymbolLookupCallback SymbolLookUp,
149 MCRelocationInfo *RelInfo);
152 /// Next - The next registered target in the linked list, maintained by the
156 /// The target function for checking if an architecture is supported.
157 ArchMatchFnTy ArchMatchFn;
159 /// Name - The target name.
162 /// ShortDesc - A short description of the target.
163 const char *ShortDesc;
165 /// HasJIT - Whether this target supports the JIT.
168 /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
170 MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
172 /// MCCodeGenInfoCtorFn - Constructor function for this target's
173 /// MCCodeGenInfo, if registered.
174 MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn;
176 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
178 MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
180 /// MCInstrAnalysisCtorFn - Constructor function for this target's
181 /// MCInstrAnalysis, if registered.
182 MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
184 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
186 MCRegInfoCtorFnTy MCRegInfoCtorFn;
188 /// MCSubtargetInfoCtorFn - Constructor function for this target's
189 /// MCSubtargetInfo, if registered.
190 MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
192 /// TargetMachineCtorFn - Construction function for this target's
193 /// TargetMachine, if registered.
194 TargetMachineCtorTy TargetMachineCtorFn;
196 /// MCAsmBackendCtorFn - Construction function for this target's
197 /// MCAsmBackend, if registered.
198 MCAsmBackendCtorTy MCAsmBackendCtorFn;
200 /// MCAsmParserCtorFn - Construction function for this target's
201 /// MCTargetAsmParser, if registered.
202 MCAsmParserCtorTy MCAsmParserCtorFn;
204 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
206 AsmPrinterCtorTy AsmPrinterCtorFn;
208 /// MCDisassemblerCtorFn - Construction function for this target's
209 /// MCDisassembler, if registered.
210 MCDisassemblerCtorTy MCDisassemblerCtorFn;
212 /// MCInstPrinterCtorFn - Construction function for this target's
213 /// MCInstPrinter, if registered.
214 MCInstPrinterCtorTy MCInstPrinterCtorFn;
216 /// MCCodeEmitterCtorFn - Construction function for this target's
217 /// CodeEmitter, if registered.
218 MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
220 /// MCObjectStreamerCtorFn - Construction function for this target's
221 /// MCObjectStreamer, if registered.
222 MCObjectStreamerCtorTy MCObjectStreamerCtorFn;
224 /// AsmStreamerCtorFn - Construction function for this target's
225 /// AsmStreamer, if registered (default = llvm::createAsmStreamer).
226 AsmStreamerCtorTy AsmStreamerCtorFn;
228 /// MCRelocationInfoCtorFn - Construction function for this target's
229 /// MCRelocationInfo, if registered (default = llvm::createMCRelocationInfo)
230 MCRelocationInfoCtorTy MCRelocationInfoCtorFn;
232 /// MCSymbolizerCtorFn - Construction function for this target's
233 /// MCSymbolizer, if registered (default = llvm::createMCSymbolizer)
234 MCSymbolizerCtorTy MCSymbolizerCtorFn;
238 : AsmStreamerCtorFn(nullptr), MCRelocationInfoCtorFn(nullptr),
239 MCSymbolizerCtorFn(nullptr) {}
241 /// @name Target Information
244 // getNext - Return the next registered target.
245 const Target *getNext() const { return Next; }
247 /// getName - Get the target name.
248 const char *getName() const { return Name; }
250 /// getShortDescription - Get a short description of the target.
251 const char *getShortDescription() const { return ShortDesc; }
254 /// @name Feature Predicates
257 /// hasJIT - Check if this targets supports the just-in-time compilation.
258 bool hasJIT() const { return HasJIT; }
260 /// hasTargetMachine - Check if this target supports code generation.
261 bool hasTargetMachine() const { return TargetMachineCtorFn != nullptr; }
263 /// hasMCAsmBackend - Check if this target supports .o generation.
264 bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != nullptr; }
267 /// @name Feature Constructors
270 /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
273 /// \param Triple This argument is used to determine the target machine
274 /// feature set; it should always be provided. Generally this should be
275 /// either the target triple from the module, or the target triple of the
276 /// host if that does not exist.
277 MCAsmInfo *createMCAsmInfo(const MCRegisterInfo &MRI,
278 StringRef Triple) const {
279 if (!MCAsmInfoCtorFn)
281 return MCAsmInfoCtorFn(MRI, Triple);
284 /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
286 MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model RM,
288 CodeGenOpt::Level OL) const {
289 if (!MCCodeGenInfoCtorFn)
291 return MCCodeGenInfoCtorFn(Triple, RM, CM, OL);
294 /// createMCInstrInfo - Create a MCInstrInfo implementation.
296 MCInstrInfo *createMCInstrInfo() const {
297 if (!MCInstrInfoCtorFn)
299 return MCInstrInfoCtorFn();
302 /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
304 MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
305 if (!MCInstrAnalysisCtorFn)
307 return MCInstrAnalysisCtorFn(Info);
310 /// createMCRegInfo - Create a MCRegisterInfo implementation.
312 MCRegisterInfo *createMCRegInfo(StringRef Triple) const {
313 if (!MCRegInfoCtorFn)
315 return MCRegInfoCtorFn(Triple);
318 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
320 /// \param Triple This argument is used to determine the target machine
321 /// feature set; it should always be provided. Generally this should be
322 /// either the target triple from the module, or the target triple of the
323 /// host if that does not exist.
324 /// \param CPU This specifies the name of the target CPU.
325 /// \param Features This specifies the string representation of the
326 /// additional target features.
327 MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU,
328 StringRef Features) const {
329 if (!MCSubtargetInfoCtorFn)
331 return MCSubtargetInfoCtorFn(Triple, CPU, Features);
334 /// createTargetMachine - Create a target specific machine implementation
335 /// for the specified \p Triple.
337 /// \param Triple This argument is used to determine the target machine
338 /// feature set; it should always be provided. Generally this should be
339 /// either the target triple from the module, or the target triple of the
340 /// host if that does not exist.
341 TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU,
342 StringRef Features, const TargetOptions &Options,
343 Reloc::Model RM = Reloc::Default,
344 CodeModel::Model CM = CodeModel::Default,
345 CodeGenOpt::Level OL = CodeGenOpt::Default) const {
346 if (!TargetMachineCtorFn)
348 return TargetMachineCtorFn(*this, Triple, CPU, Features, Options,
352 /// createMCAsmBackend - Create a target specific assembly parser.
354 /// \param Triple The target triple string.
355 MCAsmBackend *createMCAsmBackend(const MCRegisterInfo &MRI,
356 StringRef Triple, StringRef CPU) const {
357 if (!MCAsmBackendCtorFn)
359 return MCAsmBackendCtorFn(*this, MRI, Triple, CPU);
362 /// createMCAsmParser - Create a target specific assembly parser.
364 /// \param Parser The target independent parser implementation to use for
365 /// parsing and lexing.
366 MCTargetAsmParser *createMCAsmParser(
367 MCSubtargetInfo &STI,
369 const MCInstrInfo &MII,
370 const MCTargetOptions &Options) const {
371 if (!MCAsmParserCtorFn)
373 return MCAsmParserCtorFn(STI, Parser, MII, Options);
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,
385 MCContext &Ctx) const {
386 if (!MCDisassemblerCtorFn)
388 return MCDisassemblerCtorFn(*this, STI, Ctx);
391 MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
392 const MCAsmInfo &MAI,
393 const MCInstrInfo &MII,
394 const MCRegisterInfo &MRI,
395 const MCSubtargetInfo &STI) const {
396 if (!MCInstPrinterCtorFn)
398 return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, MII, MRI, STI);
402 /// createMCCodeEmitter - Create a target specific code emitter.
403 MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
404 const MCRegisterInfo &MRI,
405 const MCSubtargetInfo &STI,
406 MCContext &Ctx) const {
407 if (!MCCodeEmitterCtorFn)
409 return MCCodeEmitterCtorFn(II, MRI, STI, Ctx);
412 /// createMCObjectStreamer - Create a target specific MCStreamer.
414 /// \param TT The target triple.
415 /// \param Ctx The target context.
416 /// \param TAB The target assembler backend object. Takes ownership.
417 /// \param _OS The stream object.
418 /// \param _Emitter The target independent assembler object.Takes ownership.
419 /// \param RelaxAll Relax all fixups?
420 /// \param NoExecStack Mark file as not needing a executable stack.
421 MCStreamer *createMCObjectStreamer(StringRef TT, MCContext &Ctx,
424 MCCodeEmitter *_Emitter,
425 const MCSubtargetInfo &STI,
427 bool NoExecStack) const {
428 if (!MCObjectStreamerCtorFn)
430 return MCObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter, STI,
431 RelaxAll, NoExecStack);
434 /// createAsmStreamer - Create a target specific MCStreamer.
435 MCStreamer *createAsmStreamer(MCContext &Ctx,
436 formatted_raw_ostream &OS,
438 bool useDwarfDirectory,
439 MCInstPrinter *InstPrint,
442 bool ShowInst) const {
443 if (AsmStreamerCtorFn)
444 return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useDwarfDirectory,
445 InstPrint, CE, TAB, ShowInst);
446 return llvm::createAsmStreamer(Ctx, OS, isVerboseAsm, useDwarfDirectory,
447 InstPrint, CE, TAB, ShowInst);
450 /// createMCRelocationInfo - Create a target specific MCRelocationInfo.
452 /// \param TT The target triple.
453 /// \param Ctx The target context.
455 createMCRelocationInfo(StringRef TT, MCContext &Ctx) const {
456 MCRelocationInfoCtorTy Fn = MCRelocationInfoCtorFn
457 ? MCRelocationInfoCtorFn
458 : llvm::createMCRelocationInfo;
462 /// createMCSymbolizer - Create a target specific MCSymbolizer.
464 /// \param TT The target triple.
465 /// \param GetOpInfo The function to get the symbolic information for operands.
466 /// \param SymbolLookUp The function to lookup a symbol name.
467 /// \param DisInfo The pointer to the block of symbolic information for above call
469 /// \param Ctx The target context.
470 /// \param RelInfo The relocation information for this target. Takes ownership.
472 createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
473 LLVMSymbolLookupCallback SymbolLookUp,
475 MCContext *Ctx, MCRelocationInfo *RelInfo) const {
476 MCSymbolizerCtorTy Fn =
477 MCSymbolizerCtorFn ? MCSymbolizerCtorFn : llvm::createMCSymbolizer;
478 return Fn(TT, GetOpInfo, SymbolLookUp, DisInfo, Ctx, RelInfo);
484 /// TargetRegistry - Generic interface to target specific features.
485 struct TargetRegistry {
487 const Target *Current;
488 explicit iterator(Target *T) : Current(T) {}
489 friend struct TargetRegistry;
491 iterator() : Current(nullptr) {}
493 bool operator==(const iterator &x) const {
494 return Current == x.Current;
496 bool operator!=(const iterator &x) const {
497 return !operator==(x);
500 // Iterator traversal: forward iteration only
501 iterator &operator++() { // Preincrement
502 assert(Current && "Cannot increment end iterator!");
503 Current = Current->getNext();
506 iterator operator++(int) { // Postincrement
507 iterator tmp = *this;
512 const Target &operator*() const {
513 assert(Current && "Cannot dereference end iterator!");
517 const Target *operator->() const {
522 /// printRegisteredTargetsForVersion - Print the registered targets
523 /// appropriately for inclusion in a tool's version output.
524 static void printRegisteredTargetsForVersion();
526 /// @name Registry Access
529 static iterator begin();
531 static iterator end() { return iterator(); }
533 /// lookupTarget - Lookup a target based on a target triple.
535 /// \param Triple - The triple to use for finding a target.
536 /// \param Error - On failure, an error string describing why no target was
538 static const Target *lookupTarget(const std::string &Triple,
541 /// lookupTarget - Lookup a target based on an architecture name
542 /// and a target triple. If the architecture name is non-empty,
543 /// then the lookup is done by architecture. Otherwise, the target
546 /// \param ArchName - The architecture to use for finding a target.
547 /// \param TheTriple - The triple to use for finding a target. The
548 /// triple is updated with canonical architecture name if a lookup
549 /// by architecture is done.
550 /// \param Error - On failure, an error string describing why no target was
552 static const Target *lookupTarget(const std::string &ArchName,
556 /// getClosestTargetForJIT - Pick the best target that is compatible with
557 /// the current host. If no close target can be found, this returns null
558 /// and sets the Error string to a reason.
560 /// Maintained for compatibility through 2.6.
561 static const Target *getClosestTargetForJIT(std::string &Error);
564 /// @name Target Registration
567 /// RegisterTarget - Register the given target. Attempts to register a
568 /// target which has already been registered will be ignored.
570 /// Clients are responsible for ensuring that registration doesn't occur
571 /// while another thread is attempting to access the registry. Typically
572 /// this is done by initializing all targets at program startup.
574 /// @param T - The target being registered.
575 /// @param Name - The target name. This should be a static string.
576 /// @param ShortDesc - A short target description. This should be a static
578 /// @param ArchMatchFn - The arch match checking function for this target.
579 /// @param HasJIT - Whether the target supports JIT code
581 static void RegisterTarget(Target &T,
583 const char *ShortDesc,
584 Target::ArchMatchFnTy ArchMatchFn,
585 bool HasJIT = false);
587 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
590 /// Clients are responsible for ensuring that registration doesn't occur
591 /// while another thread is attempting to access the registry. Typically
592 /// this is done by initializing all targets at program startup.
594 /// @param T - The target being registered.
595 /// @param Fn - A function to construct a MCAsmInfo for the target.
596 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
597 T.MCAsmInfoCtorFn = Fn;
600 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
603 /// Clients are responsible for ensuring that registration doesn't occur
604 /// while another thread is attempting to access the registry. Typically
605 /// this is done by initializing all targets at program startup.
607 /// @param T - The target being registered.
608 /// @param Fn - A function to construct a MCCodeGenInfo for the target.
609 static void RegisterMCCodeGenInfo(Target &T,
610 Target::MCCodeGenInfoCtorFnTy Fn) {
611 T.MCCodeGenInfoCtorFn = Fn;
614 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
617 /// Clients are responsible for ensuring that registration doesn't occur
618 /// while another thread is attempting to access the registry. Typically
619 /// this is done by initializing all targets at program startup.
621 /// @param T - The target being registered.
622 /// @param Fn - A function to construct a MCInstrInfo for the target.
623 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
624 T.MCInstrInfoCtorFn = Fn;
627 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
628 /// the given target.
629 static void RegisterMCInstrAnalysis(Target &T,
630 Target::MCInstrAnalysisCtorFnTy Fn) {
631 T.MCInstrAnalysisCtorFn = Fn;
634 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
637 /// Clients are responsible for ensuring that registration doesn't occur
638 /// while another thread is attempting to access the registry. Typically
639 /// this is done by initializing all targets at program startup.
641 /// @param T - The target being registered.
642 /// @param Fn - A function to construct a MCRegisterInfo for the target.
643 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
644 T.MCRegInfoCtorFn = Fn;
647 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
648 /// the given target.
650 /// Clients are responsible for ensuring that registration doesn't occur
651 /// while another thread is attempting to access the registry. Typically
652 /// this is done by initializing all targets at program startup.
654 /// @param T - The target being registered.
655 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
656 static void RegisterMCSubtargetInfo(Target &T,
657 Target::MCSubtargetInfoCtorFnTy Fn) {
658 T.MCSubtargetInfoCtorFn = Fn;
661 /// RegisterTargetMachine - Register a TargetMachine implementation for the
664 /// Clients are responsible for ensuring that registration doesn't occur
665 /// while another thread is attempting to access the registry. Typically
666 /// this is done by initializing all targets at program startup.
668 /// @param T - The target being registered.
669 /// @param Fn - A function to construct a TargetMachine for the target.
670 static void RegisterTargetMachine(Target &T,
671 Target::TargetMachineCtorTy Fn) {
672 T.TargetMachineCtorFn = Fn;
675 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
678 /// Clients are responsible for ensuring that registration doesn't occur
679 /// while another thread is attempting to access the registry. Typically
680 /// this is done by initializing all targets at program startup.
682 /// @param T - The target being registered.
683 /// @param Fn - A function to construct an AsmBackend for the target.
684 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
685 T.MCAsmBackendCtorFn = Fn;
688 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
689 /// the given target.
691 /// Clients are responsible for ensuring that registration doesn't occur
692 /// while another thread is attempting to access the registry. Typically
693 /// this is done by initializing all targets at program startup.
695 /// @param T - The target being registered.
696 /// @param Fn - A function to construct an MCTargetAsmParser for the target.
697 static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
698 T.MCAsmParserCtorFn = Fn;
701 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
704 /// Clients are responsible for ensuring that registration doesn't occur
705 /// while another thread is attempting to access the registry. Typically
706 /// this is done by initializing all targets at program startup.
708 /// @param T - The target being registered.
709 /// @param Fn - A function to construct an AsmPrinter for the target.
710 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
711 T.AsmPrinterCtorFn = Fn;
714 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
715 /// the given target.
717 /// Clients are responsible for ensuring that registration doesn't occur
718 /// while another thread is attempting to access the registry. Typically
719 /// this is done by initializing all targets at program startup.
721 /// @param T - The target being registered.
722 /// @param Fn - A function to construct an MCDisassembler for the target.
723 static void RegisterMCDisassembler(Target &T,
724 Target::MCDisassemblerCtorTy Fn) {
725 T.MCDisassemblerCtorFn = Fn;
728 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
731 /// Clients are responsible for ensuring that registration doesn't occur
732 /// while another thread is attempting to access the registry. Typically
733 /// this is done by initializing all targets at program startup.
735 /// @param T - The target being registered.
736 /// @param Fn - A function to construct an MCInstPrinter for the target.
737 static void RegisterMCInstPrinter(Target &T,
738 Target::MCInstPrinterCtorTy Fn) {
739 T.MCInstPrinterCtorFn = Fn;
742 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
745 /// Clients are responsible for ensuring that registration doesn't occur
746 /// while another thread is attempting to access the registry. Typically
747 /// this is done by initializing all targets at program startup.
749 /// @param T - The target being registered.
750 /// @param Fn - A function to construct an MCCodeEmitter for the target.
751 static void RegisterMCCodeEmitter(Target &T,
752 Target::MCCodeEmitterCtorTy Fn) {
753 T.MCCodeEmitterCtorFn = Fn;
756 /// RegisterMCObjectStreamer - Register a object code MCStreamer
757 /// implementation for the given target.
759 /// Clients are responsible for ensuring that registration doesn't occur
760 /// while another thread is attempting to access the registry. Typically
761 /// this is done by initializing all targets at program startup.
763 /// @param T - The target being registered.
764 /// @param Fn - A function to construct an MCStreamer for the target.
765 static void RegisterMCObjectStreamer(Target &T,
766 Target::MCObjectStreamerCtorTy Fn) {
767 T.MCObjectStreamerCtorFn = Fn;
770 /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
771 /// for the given target.
773 /// Clients are responsible for ensuring that registration doesn't occur
774 /// while another thread is attempting to access the registry. Typically
775 /// this is done by initializing all targets at program startup.
777 /// @param T - The target being registered.
778 /// @param Fn - A function to construct an MCStreamer for the target.
779 static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
780 T.AsmStreamerCtorFn = Fn;
783 /// RegisterMCRelocationInfo - Register an MCRelocationInfo
784 /// implementation for the given target.
786 /// Clients are responsible for ensuring that registration doesn't occur
787 /// while another thread is attempting to access the registry. Typically
788 /// this is done by initializing all targets at program startup.
790 /// @param T - The target being registered.
791 /// @param Fn - A function to construct an MCRelocationInfo for the target.
792 static void RegisterMCRelocationInfo(Target &T,
793 Target::MCRelocationInfoCtorTy Fn) {
794 T.MCRelocationInfoCtorFn = Fn;
797 /// RegisterMCSymbolizer - Register an MCSymbolizer
798 /// implementation for the given target.
800 /// Clients are responsible for ensuring that registration doesn't occur
801 /// while another thread is attempting to access the registry. Typically
802 /// this is done by initializing all targets at program startup.
804 /// @param T - The target being registered.
805 /// @param Fn - A function to construct an MCSymbolizer for the target.
806 static void RegisterMCSymbolizer(Target &T,
807 Target::MCSymbolizerCtorTy Fn) {
808 T.MCSymbolizerCtorFn = Fn;
815 //===--------------------------------------------------------------------===//
817 /// RegisterTarget - Helper template for registering a target, for use in the
818 /// target's initialization function. Usage:
821 /// Target TheFooTarget; // The global target instance.
823 /// extern "C" void LLVMInitializeFooTargetInfo() {
824 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
826 template<Triple::ArchType TargetArchType = Triple::UnknownArch,
828 struct RegisterTarget {
829 RegisterTarget(Target &T, const char *Name, const char *Desc) {
830 TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch, HasJIT);
833 static bool getArchMatch(Triple::ArchType Arch) {
834 return Arch == TargetArchType;
838 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
839 /// implementation. This invokes the static "Create" method on the class to
840 /// actually do the construction. Usage:
842 /// extern "C" void LLVMInitializeFooTarget() {
843 /// extern Target TheFooTarget;
844 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
846 template<class MCAsmInfoImpl>
847 struct RegisterMCAsmInfo {
848 RegisterMCAsmInfo(Target &T) {
849 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
852 static MCAsmInfo *Allocator(const MCRegisterInfo &/*MRI*/, StringRef TT) {
853 return new MCAsmInfoImpl(TT);
858 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
859 /// implementation. This invokes the specified function to do the
860 /// construction. Usage:
862 /// extern "C" void LLVMInitializeFooTarget() {
863 /// extern Target TheFooTarget;
864 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
866 struct RegisterMCAsmInfoFn {
867 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
868 TargetRegistry::RegisterMCAsmInfo(T, Fn);
872 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
873 /// implementation. This invokes the static "Create" method on the class
874 /// to actually do the construction. Usage:
876 /// extern "C" void LLVMInitializeFooTarget() {
877 /// extern Target TheFooTarget;
878 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
880 template<class MCCodeGenInfoImpl>
881 struct RegisterMCCodeGenInfo {
882 RegisterMCCodeGenInfo(Target &T) {
883 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
886 static MCCodeGenInfo *Allocator(StringRef /*TT*/, Reloc::Model /*RM*/,
887 CodeModel::Model /*CM*/,
888 CodeGenOpt::Level /*OL*/) {
889 return new MCCodeGenInfoImpl();
893 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
894 /// info implementation. This invokes the specified function to do the
895 /// construction. Usage:
897 /// extern "C" void LLVMInitializeFooTarget() {
898 /// extern Target TheFooTarget;
899 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
901 struct RegisterMCCodeGenInfoFn {
902 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
903 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
907 /// RegisterMCInstrInfo - Helper template for registering a target instruction
908 /// info implementation. This invokes the static "Create" method on the class
909 /// to actually do the construction. Usage:
911 /// extern "C" void LLVMInitializeFooTarget() {
912 /// extern Target TheFooTarget;
913 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
915 template<class MCInstrInfoImpl>
916 struct RegisterMCInstrInfo {
917 RegisterMCInstrInfo(Target &T) {
918 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
921 static MCInstrInfo *Allocator() {
922 return new MCInstrInfoImpl();
926 /// RegisterMCInstrInfoFn - Helper template for registering a target
927 /// instruction info implementation. This invokes the specified function to
928 /// do the construction. Usage:
930 /// extern "C" void LLVMInitializeFooTarget() {
931 /// extern Target TheFooTarget;
932 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
934 struct RegisterMCInstrInfoFn {
935 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
936 TargetRegistry::RegisterMCInstrInfo(T, Fn);
940 /// RegisterMCInstrAnalysis - Helper template for registering a target
941 /// instruction analyzer implementation. This invokes the static "Create"
942 /// method on the class to actually do the construction. Usage:
944 /// extern "C" void LLVMInitializeFooTarget() {
945 /// extern Target TheFooTarget;
946 /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
948 template<class MCInstrAnalysisImpl>
949 struct RegisterMCInstrAnalysis {
950 RegisterMCInstrAnalysis(Target &T) {
951 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
954 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
955 return new MCInstrAnalysisImpl(Info);
959 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
960 /// instruction analyzer implementation. This invokes the specified function
961 /// to do the construction. Usage:
963 /// extern "C" void LLVMInitializeFooTarget() {
964 /// extern Target TheFooTarget;
965 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
967 struct RegisterMCInstrAnalysisFn {
968 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
969 TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
973 /// RegisterMCRegInfo - Helper template for registering a target register info
974 /// implementation. This invokes the static "Create" method on the class to
975 /// actually do the construction. Usage:
977 /// extern "C" void LLVMInitializeFooTarget() {
978 /// extern Target TheFooTarget;
979 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
981 template<class MCRegisterInfoImpl>
982 struct RegisterMCRegInfo {
983 RegisterMCRegInfo(Target &T) {
984 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
987 static MCRegisterInfo *Allocator(StringRef /*TT*/) {
988 return new MCRegisterInfoImpl();
992 /// RegisterMCRegInfoFn - Helper template for registering a target register
993 /// info implementation. This invokes the specified function to do the
994 /// construction. Usage:
996 /// extern "C" void LLVMInitializeFooTarget() {
997 /// extern Target TheFooTarget;
998 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
1000 struct RegisterMCRegInfoFn {
1001 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
1002 TargetRegistry::RegisterMCRegInfo(T, Fn);
1006 /// RegisterMCSubtargetInfo - Helper template for registering a target
1007 /// subtarget info implementation. This invokes the static "Create" method
1008 /// on the class to actually do the construction. Usage:
1010 /// extern "C" void LLVMInitializeFooTarget() {
1011 /// extern Target TheFooTarget;
1012 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
1014 template<class MCSubtargetInfoImpl>
1015 struct RegisterMCSubtargetInfo {
1016 RegisterMCSubtargetInfo(Target &T) {
1017 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
1020 static MCSubtargetInfo *Allocator(StringRef /*TT*/, StringRef /*CPU*/,
1022 return new MCSubtargetInfoImpl();
1026 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
1027 /// subtarget info implementation. This invokes the specified function to
1028 /// do the construction. Usage:
1030 /// extern "C" void LLVMInitializeFooTarget() {
1031 /// extern Target TheFooTarget;
1032 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1034 struct RegisterMCSubtargetInfoFn {
1035 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
1036 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
1040 /// RegisterTargetMachine - Helper template for registering a target machine
1041 /// implementation, for use in the target machine initialization
1042 /// function. Usage:
1044 /// extern "C" void LLVMInitializeFooTarget() {
1045 /// extern Target TheFooTarget;
1046 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1048 template<class TargetMachineImpl>
1049 struct RegisterTargetMachine {
1050 RegisterTargetMachine(Target &T) {
1051 TargetRegistry::RegisterTargetMachine(T, &Allocator);
1055 static TargetMachine *Allocator(const Target &T, StringRef TT,
1056 StringRef CPU, StringRef FS,
1057 const TargetOptions &Options,
1059 CodeModel::Model CM,
1060 CodeGenOpt::Level OL) {
1061 return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
1065 /// RegisterMCAsmBackend - Helper template for registering a target specific
1066 /// assembler backend. Usage:
1068 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1069 /// extern Target TheFooTarget;
1070 /// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1072 template<class MCAsmBackendImpl>
1073 struct RegisterMCAsmBackend {
1074 RegisterMCAsmBackend(Target &T) {
1075 TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1079 static MCAsmBackend *Allocator(const Target &T,
1080 const MCRegisterInfo &MRI,
1081 StringRef Triple, StringRef CPU) {
1082 return new MCAsmBackendImpl(T, MRI, Triple, CPU);
1086 /// RegisterMCAsmParser - Helper template for registering a target specific
1087 /// assembly parser, for use in the target machine initialization
1088 /// function. Usage:
1090 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1091 /// extern Target TheFooTarget;
1092 /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1094 template<class MCAsmParserImpl>
1095 struct RegisterMCAsmParser {
1096 RegisterMCAsmParser(Target &T) {
1097 TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1101 static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P,
1102 const MCInstrInfo &MII,
1103 const MCTargetOptions &Options) {
1104 return new MCAsmParserImpl(STI, P, MII, Options);
1108 /// RegisterAsmPrinter - Helper template for registering a target specific
1109 /// assembly printer, for use in the target machine initialization
1110 /// function. Usage:
1112 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1113 /// extern Target TheFooTarget;
1114 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1116 template<class AsmPrinterImpl>
1117 struct RegisterAsmPrinter {
1118 RegisterAsmPrinter(Target &T) {
1119 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1123 static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) {
1124 return new AsmPrinterImpl(TM, Streamer);
1128 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1129 /// machine code emitter, for use in the target initialization
1130 /// function. Usage:
1132 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1133 /// extern Target TheFooTarget;
1134 /// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1136 template<class MCCodeEmitterImpl>
1137 struct RegisterMCCodeEmitter {
1138 RegisterMCCodeEmitter(Target &T) {
1139 TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1143 static MCCodeEmitter *Allocator(const MCInstrInfo &/*II*/,
1144 const MCRegisterInfo &/*MRI*/,
1145 const MCSubtargetInfo &/*STI*/,
1146 MCContext &/*Ctx*/) {
1147 return new MCCodeEmitterImpl();