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 *createNullStreamer(MCContext &Ctx);
55 MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
56 bool isVerboseAsm, bool useDwarfDirectory,
57 MCInstPrinter *InstPrint, MCCodeEmitter *CE,
58 MCAsmBackend *TAB, bool ShowInst);
60 MCRelocationInfo *createMCRelocationInfo(StringRef TT, MCContext &Ctx);
62 MCSymbolizer *createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
63 LLVMSymbolLookupCallback SymbolLookUp,
66 MCRelocationInfo *RelInfo);
68 /// Target - Wrapper for Target specific information.
70 /// For registration purposes, this is a POD type so that targets can be
71 /// registered without the use of static constructors.
73 /// Targets should implement a single global instance of this class (which
74 /// will be zero initialized), and pass that instance to the TargetRegistry as
75 /// part of their initialization.
78 friend struct TargetRegistry;
80 typedef bool (*ArchMatchFnTy)(Triple::ArchType Arch);
82 typedef MCAsmInfo *(*MCAsmInfoCtorFnTy)(const MCRegisterInfo &MRI,
84 typedef MCCodeGenInfo *(*MCCodeGenInfoCtorFnTy)(StringRef TT,
87 CodeGenOpt::Level OL);
88 typedef MCInstrInfo *(*MCInstrInfoCtorFnTy)(void);
89 typedef MCInstrAnalysis *(*MCInstrAnalysisCtorFnTy)(const MCInstrInfo*Info);
90 typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(StringRef TT);
91 typedef MCSubtargetInfo *(*MCSubtargetInfoCtorFnTy)(StringRef TT,
94 typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T,
98 const TargetOptions &Options,
101 CodeGenOpt::Level OL);
102 typedef AsmPrinter *(*AsmPrinterCtorTy)(TargetMachine &TM,
103 MCStreamer &Streamer);
104 typedef MCAsmBackend *(*MCAsmBackendCtorTy)(const Target &T,
105 const MCRegisterInfo &MRI,
108 typedef MCTargetAsmParser *(*MCAsmParserCtorTy)(
109 MCSubtargetInfo &STI,
111 const MCInstrInfo &MII,
112 const MCTargetOptions &Options);
113 typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T,
114 const MCSubtargetInfo &STI,
116 typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
117 unsigned SyntaxVariant,
118 const MCAsmInfo &MAI,
119 const MCInstrInfo &MII,
120 const MCRegisterInfo &MRI,
121 const MCSubtargetInfo &STI);
122 typedef MCCodeEmitter *(*MCCodeEmitterCtorTy)(const MCInstrInfo &II,
123 const MCRegisterInfo &MRI,
124 const MCSubtargetInfo &STI,
126 typedef MCStreamer *(*MCObjectStreamerCtorTy)(const Target &T,
131 MCCodeEmitter *_Emitter,
132 const MCSubtargetInfo &STI,
135 typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx,
136 formatted_raw_ostream &OS,
138 bool useDwarfDirectory,
139 MCInstPrinter *InstPrint,
143 typedef MCStreamer *(*NullStreamerCtorTy)(MCContext &Ctx);
144 typedef MCRelocationInfo *(*MCRelocationInfoCtorTy)(StringRef TT,
146 typedef MCSymbolizer *(*MCSymbolizerCtorTy)(StringRef TT,
147 LLVMOpInfoCallback GetOpInfo,
148 LLVMSymbolLookupCallback SymbolLookUp,
151 MCRelocationInfo *RelInfo);
154 /// Next - The next registered target in the linked list, maintained by the
158 /// The target function for checking if an architecture is supported.
159 ArchMatchFnTy ArchMatchFn;
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 /// Construction function for this target's NullStreamer, if registered
231 /// (default = llvm::createNullStreamer).
232 NullStreamerCtorTy NullStreamerCtorFn;
234 /// MCRelocationInfoCtorFn - Construction function for this target's
235 /// MCRelocationInfo, if registered (default = llvm::createMCRelocationInfo)
236 MCRelocationInfoCtorTy MCRelocationInfoCtorFn;
238 /// MCSymbolizerCtorFn - Construction function for this target's
239 /// MCSymbolizer, if registered (default = llvm::createMCSymbolizer)
240 MCSymbolizerCtorTy MCSymbolizerCtorFn;
244 : AsmStreamerCtorFn(nullptr), NullStreamerCtorFn(nullptr),
245 MCRelocationInfoCtorFn(nullptr), MCSymbolizerCtorFn(nullptr) {}
247 /// @name Target Information
250 // getNext - Return the next registered target.
251 const Target *getNext() const { return Next; }
253 /// getName - Get the target name.
254 const char *getName() const { return Name; }
256 /// getShortDescription - Get a short description of the target.
257 const char *getShortDescription() const { return ShortDesc; }
260 /// @name Feature Predicates
263 /// hasJIT - Check if this targets supports the just-in-time compilation.
264 bool hasJIT() const { return HasJIT; }
266 /// hasTargetMachine - Check if this target supports code generation.
267 bool hasTargetMachine() const { return TargetMachineCtorFn != nullptr; }
269 /// hasMCAsmBackend - Check if this target supports .o generation.
270 bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != nullptr; }
273 /// @name Feature Constructors
276 /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
279 /// \param Triple This argument is used to determine the target machine
280 /// feature set; it should always be provided. Generally this should be
281 /// either the target triple from the module, or the target triple of the
282 /// host if that does not exist.
283 MCAsmInfo *createMCAsmInfo(const MCRegisterInfo &MRI,
284 StringRef Triple) const {
285 if (!MCAsmInfoCtorFn)
287 return MCAsmInfoCtorFn(MRI, Triple);
290 /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
292 MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model RM,
294 CodeGenOpt::Level OL) const {
295 if (!MCCodeGenInfoCtorFn)
297 return MCCodeGenInfoCtorFn(Triple, RM, CM, OL);
300 /// createMCInstrInfo - Create a MCInstrInfo implementation.
302 MCInstrInfo *createMCInstrInfo() const {
303 if (!MCInstrInfoCtorFn)
305 return MCInstrInfoCtorFn();
308 /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
310 MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
311 if (!MCInstrAnalysisCtorFn)
313 return MCInstrAnalysisCtorFn(Info);
316 /// createMCRegInfo - Create a MCRegisterInfo implementation.
318 MCRegisterInfo *createMCRegInfo(StringRef Triple) const {
319 if (!MCRegInfoCtorFn)
321 return MCRegInfoCtorFn(Triple);
324 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
326 /// \param Triple This argument is used to determine the target machine
327 /// feature set; it should always be provided. Generally this should be
328 /// either the target triple from the module, or the target triple of the
329 /// host if that does not exist.
330 /// \param CPU This specifies the name of the target CPU.
331 /// \param Features This specifies the string representation of the
332 /// additional target features.
333 MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU,
334 StringRef Features) const {
335 if (!MCSubtargetInfoCtorFn)
337 return MCSubtargetInfoCtorFn(Triple, CPU, Features);
340 /// createTargetMachine - Create a target specific machine implementation
341 /// for the specified \p Triple.
343 /// \param Triple This argument is used to determine the target machine
344 /// feature set; it should always be provided. Generally this should be
345 /// either the target triple from the module, or the target triple of the
346 /// host if that does not exist.
347 TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU,
348 StringRef Features, const TargetOptions &Options,
349 Reloc::Model RM = Reloc::Default,
350 CodeModel::Model CM = CodeModel::Default,
351 CodeGenOpt::Level OL = CodeGenOpt::Default) const {
352 if (!TargetMachineCtorFn)
354 return TargetMachineCtorFn(*this, Triple, CPU, Features, Options,
358 /// createMCAsmBackend - Create a target specific assembly parser.
360 /// \param Triple The target triple string.
361 MCAsmBackend *createMCAsmBackend(const MCRegisterInfo &MRI,
362 StringRef Triple, StringRef CPU) const {
363 if (!MCAsmBackendCtorFn)
365 return MCAsmBackendCtorFn(*this, MRI, Triple, CPU);
368 /// createMCAsmParser - Create a target specific assembly parser.
370 /// \param Parser The target independent parser implementation to use for
371 /// parsing and lexing.
372 MCTargetAsmParser *createMCAsmParser(
373 MCSubtargetInfo &STI,
375 const MCInstrInfo &MII,
376 const MCTargetOptions &Options) const {
377 if (!MCAsmParserCtorFn)
379 return MCAsmParserCtorFn(STI, Parser, MII, Options);
382 /// createAsmPrinter - Create a target specific assembly printer pass. This
383 /// takes ownership of the MCStreamer object.
384 AsmPrinter *createAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) const{
385 if (!AsmPrinterCtorFn)
387 return AsmPrinterCtorFn(TM, Streamer);
390 MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI,
391 MCContext &Ctx) const {
392 if (!MCDisassemblerCtorFn)
394 return MCDisassemblerCtorFn(*this, STI, Ctx);
397 MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
398 const MCAsmInfo &MAI,
399 const MCInstrInfo &MII,
400 const MCRegisterInfo &MRI,
401 const MCSubtargetInfo &STI) const {
402 if (!MCInstPrinterCtorFn)
404 return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, MII, MRI, STI);
408 /// createMCCodeEmitter - Create a target specific code emitter.
409 MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
410 const MCRegisterInfo &MRI,
411 const MCSubtargetInfo &STI,
412 MCContext &Ctx) const {
413 if (!MCCodeEmitterCtorFn)
415 return MCCodeEmitterCtorFn(II, MRI, STI, Ctx);
418 /// createMCObjectStreamer - Create a target specific MCStreamer.
420 /// \param TT The target triple.
421 /// \param Ctx The target context.
422 /// \param TAB The target assembler backend object. Takes ownership.
423 /// \param _OS The stream object.
424 /// \param _Emitter The target independent assembler object.Takes ownership.
425 /// \param RelaxAll Relax all fixups?
426 /// \param NoExecStack Mark file as not needing a executable stack.
427 MCStreamer *createMCObjectStreamer(StringRef TT, MCContext &Ctx,
430 MCCodeEmitter *_Emitter,
431 const MCSubtargetInfo &STI,
433 bool NoExecStack) const {
434 if (!MCObjectStreamerCtorFn)
436 return MCObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter, STI,
437 RelaxAll, NoExecStack);
440 /// createAsmStreamer - Create a target specific MCStreamer.
441 MCStreamer *createAsmStreamer(MCContext &Ctx,
442 formatted_raw_ostream &OS,
444 bool useDwarfDirectory,
445 MCInstPrinter *InstPrint,
448 bool ShowInst) const {
449 if (AsmStreamerCtorFn)
450 return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useDwarfDirectory,
451 InstPrint, CE, TAB, ShowInst);
452 return llvm::createAsmStreamer(Ctx, OS, isVerboseAsm, useDwarfDirectory,
453 InstPrint, CE, TAB, ShowInst);
456 MCStreamer *createNullStreamer(MCContext &Ctx) const {
457 if (NullStreamerCtorFn)
458 return NullStreamerCtorFn(Ctx);
459 return llvm::createNullStreamer(Ctx);
462 /// createMCRelocationInfo - Create a target specific MCRelocationInfo.
464 /// \param TT The target triple.
465 /// \param Ctx The target context.
467 createMCRelocationInfo(StringRef TT, MCContext &Ctx) const {
468 MCRelocationInfoCtorTy Fn = MCRelocationInfoCtorFn
469 ? MCRelocationInfoCtorFn
470 : llvm::createMCRelocationInfo;
474 /// createMCSymbolizer - Create a target specific MCSymbolizer.
476 /// \param TT The target triple.
477 /// \param GetOpInfo The function to get the symbolic information for operands.
478 /// \param SymbolLookUp The function to lookup a symbol name.
479 /// \param DisInfo The pointer to the block of symbolic information for above call
481 /// \param Ctx The target context.
482 /// \param RelInfo The relocation information for this target. Takes ownership.
484 createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
485 LLVMSymbolLookupCallback SymbolLookUp,
487 MCContext *Ctx, MCRelocationInfo *RelInfo) const {
488 MCSymbolizerCtorTy Fn =
489 MCSymbolizerCtorFn ? MCSymbolizerCtorFn : llvm::createMCSymbolizer;
490 return Fn(TT, GetOpInfo, SymbolLookUp, DisInfo, Ctx, RelInfo);
496 /// TargetRegistry - Generic interface to target specific features.
497 struct TargetRegistry {
499 const Target *Current;
500 explicit iterator(Target *T) : Current(T) {}
501 friend struct TargetRegistry;
503 iterator() : Current(nullptr) {}
505 bool operator==(const iterator &x) const {
506 return Current == x.Current;
508 bool operator!=(const iterator &x) const {
509 return !operator==(x);
512 // Iterator traversal: forward iteration only
513 iterator &operator++() { // Preincrement
514 assert(Current && "Cannot increment end iterator!");
515 Current = Current->getNext();
518 iterator operator++(int) { // Postincrement
519 iterator tmp = *this;
524 const Target &operator*() const {
525 assert(Current && "Cannot dereference end iterator!");
529 const Target *operator->() const {
534 /// printRegisteredTargetsForVersion - Print the registered targets
535 /// appropriately for inclusion in a tool's version output.
536 static void printRegisteredTargetsForVersion();
538 /// @name Registry Access
541 static iterator begin();
543 static iterator end() { return iterator(); }
545 /// lookupTarget - Lookup a target based on a target triple.
547 /// \param Triple - The triple to use for finding a target.
548 /// \param Error - On failure, an error string describing why no target was
550 static const Target *lookupTarget(const std::string &Triple,
553 /// lookupTarget - Lookup a target based on an architecture name
554 /// and a target triple. If the architecture name is non-empty,
555 /// then the lookup is done by architecture. Otherwise, the target
558 /// \param ArchName - The architecture to use for finding a target.
559 /// \param TheTriple - The triple to use for finding a target. The
560 /// triple is updated with canonical architecture name if a lookup
561 /// by architecture is done.
562 /// \param Error - On failure, an error string describing why no target was
564 static const Target *lookupTarget(const std::string &ArchName,
568 /// getClosestTargetForJIT - Pick the best target that is compatible with
569 /// the current host. If no close target can be found, this returns null
570 /// and sets the Error string to a reason.
572 /// Maintained for compatibility through 2.6.
573 static const Target *getClosestTargetForJIT(std::string &Error);
576 /// @name Target Registration
579 /// RegisterTarget - Register the given target. Attempts to register a
580 /// target which has already been registered will be ignored.
582 /// Clients are responsible for ensuring that registration doesn't occur
583 /// while another thread is attempting to access the registry. Typically
584 /// this is done by initializing all targets at program startup.
586 /// @param T - The target being registered.
587 /// @param Name - The target name. This should be a static string.
588 /// @param ShortDesc - A short target description. This should be a static
590 /// @param ArchMatchFn - The arch match checking function for this target.
591 /// @param HasJIT - Whether the target supports JIT code
593 static void RegisterTarget(Target &T,
595 const char *ShortDesc,
596 Target::ArchMatchFnTy ArchMatchFn,
597 bool HasJIT = false);
599 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
602 /// Clients are responsible for ensuring that registration doesn't occur
603 /// while another thread is attempting to access the registry. Typically
604 /// this is done by initializing all targets at program startup.
606 /// @param T - The target being registered.
607 /// @param Fn - A function to construct a MCAsmInfo for the target.
608 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
609 T.MCAsmInfoCtorFn = Fn;
612 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
615 /// Clients are responsible for ensuring that registration doesn't occur
616 /// while another thread is attempting to access the registry. Typically
617 /// this is done by initializing all targets at program startup.
619 /// @param T - The target being registered.
620 /// @param Fn - A function to construct a MCCodeGenInfo for the target.
621 static void RegisterMCCodeGenInfo(Target &T,
622 Target::MCCodeGenInfoCtorFnTy Fn) {
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 T.MCInstrInfoCtorFn = Fn;
639 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
640 /// the given target.
641 static void RegisterMCInstrAnalysis(Target &T,
642 Target::MCInstrAnalysisCtorFnTy Fn) {
643 T.MCInstrAnalysisCtorFn = Fn;
646 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
649 /// Clients are responsible for ensuring that registration doesn't occur
650 /// while another thread is attempting to access the registry. Typically
651 /// this is done by initializing all targets at program startup.
653 /// @param T - The target being registered.
654 /// @param Fn - A function to construct a MCRegisterInfo for the target.
655 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
656 T.MCRegInfoCtorFn = Fn;
659 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
660 /// the given target.
662 /// Clients are responsible for ensuring that registration doesn't occur
663 /// while another thread is attempting to access the registry. Typically
664 /// this is done by initializing all targets at program startup.
666 /// @param T - The target being registered.
667 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
668 static void RegisterMCSubtargetInfo(Target &T,
669 Target::MCSubtargetInfoCtorFnTy Fn) {
670 T.MCSubtargetInfoCtorFn = Fn;
673 /// RegisterTargetMachine - Register a TargetMachine implementation for the
676 /// Clients are responsible for ensuring that registration doesn't occur
677 /// while another thread is attempting to access the registry. Typically
678 /// this is done by initializing all targets at program startup.
680 /// @param T - The target being registered.
681 /// @param Fn - A function to construct a TargetMachine for the target.
682 static void RegisterTargetMachine(Target &T,
683 Target::TargetMachineCtorTy Fn) {
684 T.TargetMachineCtorFn = Fn;
687 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
690 /// Clients are responsible for ensuring that registration doesn't occur
691 /// while another thread is attempting to access the registry. Typically
692 /// this is done by initializing all targets at program startup.
694 /// @param T - The target being registered.
695 /// @param Fn - A function to construct an AsmBackend for the target.
696 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
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 T.MCAsmParserCtorFn = Fn;
713 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
716 /// Clients are responsible for ensuring that registration doesn't occur
717 /// while another thread is attempting to access the registry. Typically
718 /// this is done by initializing all targets at program startup.
720 /// @param T - The target being registered.
721 /// @param Fn - A function to construct an AsmPrinter for the target.
722 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
723 T.AsmPrinterCtorFn = Fn;
726 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
727 /// the given target.
729 /// Clients are responsible for ensuring that registration doesn't occur
730 /// while another thread is attempting to access the registry. Typically
731 /// this is done by initializing all targets at program startup.
733 /// @param T - The target being registered.
734 /// @param Fn - A function to construct an MCDisassembler for the target.
735 static void RegisterMCDisassembler(Target &T,
736 Target::MCDisassemblerCtorTy Fn) {
737 T.MCDisassemblerCtorFn = Fn;
740 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
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 MCInstPrinter for the target.
749 static void RegisterMCInstPrinter(Target &T,
750 Target::MCInstPrinterCtorTy Fn) {
751 T.MCInstPrinterCtorFn = Fn;
754 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
757 /// Clients are responsible for ensuring that registration doesn't occur
758 /// while another thread is attempting to access the registry. Typically
759 /// this is done by initializing all targets at program startup.
761 /// @param T - The target being registered.
762 /// @param Fn - A function to construct an MCCodeEmitter for the target.
763 static void RegisterMCCodeEmitter(Target &T,
764 Target::MCCodeEmitterCtorTy Fn) {
765 T.MCCodeEmitterCtorFn = Fn;
768 /// RegisterMCObjectStreamer - Register a object code MCStreamer
769 /// implementation for the given target.
771 /// Clients are responsible for ensuring that registration doesn't occur
772 /// while another thread is attempting to access the registry. Typically
773 /// this is done by initializing all targets at program startup.
775 /// @param T - The target being registered.
776 /// @param Fn - A function to construct an MCStreamer for the target.
777 static void RegisterMCObjectStreamer(Target &T,
778 Target::MCObjectStreamerCtorTy Fn) {
779 T.MCObjectStreamerCtorFn = Fn;
782 /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
783 /// for the given target.
785 /// Clients are responsible for ensuring that registration doesn't occur
786 /// while another thread is attempting to access the registry. Typically
787 /// this is done by initializing all targets at program startup.
789 /// @param T - The target being registered.
790 /// @param Fn - A function to construct an MCStreamer for the target.
791 static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
792 T.AsmStreamerCtorFn = Fn;
795 static void RegisterNullStreamer(Target &T, Target::NullStreamerCtorTy Fn) {
796 T.NullStreamerCtorFn = Fn;
799 /// RegisterMCRelocationInfo - Register an MCRelocationInfo
800 /// implementation for the given target.
802 /// Clients are responsible for ensuring that registration doesn't occur
803 /// while another thread is attempting to access the registry. Typically
804 /// this is done by initializing all targets at program startup.
806 /// @param T - The target being registered.
807 /// @param Fn - A function to construct an MCRelocationInfo for the target.
808 static void RegisterMCRelocationInfo(Target &T,
809 Target::MCRelocationInfoCtorTy Fn) {
810 T.MCRelocationInfoCtorFn = Fn;
813 /// RegisterMCSymbolizer - Register an MCSymbolizer
814 /// implementation for the given target.
816 /// Clients are responsible for ensuring that registration doesn't occur
817 /// while another thread is attempting to access the registry. Typically
818 /// this is done by initializing all targets at program startup.
820 /// @param T - The target being registered.
821 /// @param Fn - A function to construct an MCSymbolizer for the target.
822 static void RegisterMCSymbolizer(Target &T,
823 Target::MCSymbolizerCtorTy Fn) {
824 T.MCSymbolizerCtorFn = Fn;
831 //===--------------------------------------------------------------------===//
833 /// RegisterTarget - Helper template for registering a target, for use in the
834 /// target's initialization function. Usage:
837 /// Target TheFooTarget; // The global target instance.
839 /// extern "C" void LLVMInitializeFooTargetInfo() {
840 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
842 template<Triple::ArchType TargetArchType = Triple::UnknownArch,
844 struct RegisterTarget {
845 RegisterTarget(Target &T, const char *Name, const char *Desc) {
846 TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch, HasJIT);
849 static bool getArchMatch(Triple::ArchType Arch) {
850 return Arch == TargetArchType;
854 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
855 /// implementation. This invokes the static "Create" method on the class to
856 /// actually do the construction. Usage:
858 /// extern "C" void LLVMInitializeFooTarget() {
859 /// extern Target TheFooTarget;
860 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
862 template<class MCAsmInfoImpl>
863 struct RegisterMCAsmInfo {
864 RegisterMCAsmInfo(Target &T) {
865 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
868 static MCAsmInfo *Allocator(const MCRegisterInfo &/*MRI*/, StringRef TT) {
869 return new MCAsmInfoImpl(TT);
874 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
875 /// implementation. This invokes the specified function to do the
876 /// construction. Usage:
878 /// extern "C" void LLVMInitializeFooTarget() {
879 /// extern Target TheFooTarget;
880 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
882 struct RegisterMCAsmInfoFn {
883 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
884 TargetRegistry::RegisterMCAsmInfo(T, Fn);
888 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
889 /// implementation. This invokes the static "Create" method on the class
890 /// to actually do the construction. Usage:
892 /// extern "C" void LLVMInitializeFooTarget() {
893 /// extern Target TheFooTarget;
894 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
896 template<class MCCodeGenInfoImpl>
897 struct RegisterMCCodeGenInfo {
898 RegisterMCCodeGenInfo(Target &T) {
899 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
902 static MCCodeGenInfo *Allocator(StringRef /*TT*/, Reloc::Model /*RM*/,
903 CodeModel::Model /*CM*/,
904 CodeGenOpt::Level /*OL*/) {
905 return new MCCodeGenInfoImpl();
909 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
910 /// info implementation. This invokes the specified function to do the
911 /// construction. Usage:
913 /// extern "C" void LLVMInitializeFooTarget() {
914 /// extern Target TheFooTarget;
915 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
917 struct RegisterMCCodeGenInfoFn {
918 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
919 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
923 /// RegisterMCInstrInfo - Helper template for registering a target instruction
924 /// info implementation. This invokes the static "Create" method on the class
925 /// to actually do the construction. Usage:
927 /// extern "C" void LLVMInitializeFooTarget() {
928 /// extern Target TheFooTarget;
929 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
931 template<class MCInstrInfoImpl>
932 struct RegisterMCInstrInfo {
933 RegisterMCInstrInfo(Target &T) {
934 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
937 static MCInstrInfo *Allocator() {
938 return new MCInstrInfoImpl();
942 /// RegisterMCInstrInfoFn - Helper template for registering a target
943 /// instruction info implementation. This invokes the specified function to
944 /// do the construction. Usage:
946 /// extern "C" void LLVMInitializeFooTarget() {
947 /// extern Target TheFooTarget;
948 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
950 struct RegisterMCInstrInfoFn {
951 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
952 TargetRegistry::RegisterMCInstrInfo(T, Fn);
956 /// RegisterMCInstrAnalysis - Helper template for registering a target
957 /// instruction analyzer implementation. This invokes the static "Create"
958 /// method on the class to actually do the construction. Usage:
960 /// extern "C" void LLVMInitializeFooTarget() {
961 /// extern Target TheFooTarget;
962 /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
964 template<class MCInstrAnalysisImpl>
965 struct RegisterMCInstrAnalysis {
966 RegisterMCInstrAnalysis(Target &T) {
967 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
970 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
971 return new MCInstrAnalysisImpl(Info);
975 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
976 /// instruction analyzer implementation. This invokes the specified function
977 /// to do the construction. Usage:
979 /// extern "C" void LLVMInitializeFooTarget() {
980 /// extern Target TheFooTarget;
981 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
983 struct RegisterMCInstrAnalysisFn {
984 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
985 TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
989 /// RegisterMCRegInfo - Helper template for registering a target register info
990 /// implementation. This invokes the static "Create" method on the class to
991 /// actually do the construction. Usage:
993 /// extern "C" void LLVMInitializeFooTarget() {
994 /// extern Target TheFooTarget;
995 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
997 template<class MCRegisterInfoImpl>
998 struct RegisterMCRegInfo {
999 RegisterMCRegInfo(Target &T) {
1000 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
1003 static MCRegisterInfo *Allocator(StringRef /*TT*/) {
1004 return new MCRegisterInfoImpl();
1008 /// RegisterMCRegInfoFn - Helper template for registering a target register
1009 /// info implementation. This invokes the specified function to do the
1010 /// construction. Usage:
1012 /// extern "C" void LLVMInitializeFooTarget() {
1013 /// extern Target TheFooTarget;
1014 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
1016 struct RegisterMCRegInfoFn {
1017 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
1018 TargetRegistry::RegisterMCRegInfo(T, Fn);
1022 /// RegisterMCSubtargetInfo - Helper template for registering a target
1023 /// subtarget info implementation. This invokes the static "Create" method
1024 /// on the class to actually do the construction. Usage:
1026 /// extern "C" void LLVMInitializeFooTarget() {
1027 /// extern Target TheFooTarget;
1028 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
1030 template<class MCSubtargetInfoImpl>
1031 struct RegisterMCSubtargetInfo {
1032 RegisterMCSubtargetInfo(Target &T) {
1033 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
1036 static MCSubtargetInfo *Allocator(StringRef /*TT*/, StringRef /*CPU*/,
1038 return new MCSubtargetInfoImpl();
1042 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
1043 /// subtarget info implementation. This invokes the specified function to
1044 /// do the construction. Usage:
1046 /// extern "C" void LLVMInitializeFooTarget() {
1047 /// extern Target TheFooTarget;
1048 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1050 struct RegisterMCSubtargetInfoFn {
1051 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
1052 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
1056 /// RegisterTargetMachine - Helper template for registering a target machine
1057 /// implementation, for use in the target machine initialization
1058 /// function. Usage:
1060 /// extern "C" void LLVMInitializeFooTarget() {
1061 /// extern Target TheFooTarget;
1062 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1064 template<class TargetMachineImpl>
1065 struct RegisterTargetMachine {
1066 RegisterTargetMachine(Target &T) {
1067 TargetRegistry::RegisterTargetMachine(T, &Allocator);
1071 static TargetMachine *Allocator(const Target &T, StringRef TT,
1072 StringRef CPU, StringRef FS,
1073 const TargetOptions &Options,
1075 CodeModel::Model CM,
1076 CodeGenOpt::Level OL) {
1077 return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
1081 /// RegisterMCAsmBackend - Helper template for registering a target specific
1082 /// assembler backend. Usage:
1084 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1085 /// extern Target TheFooTarget;
1086 /// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1088 template<class MCAsmBackendImpl>
1089 struct RegisterMCAsmBackend {
1090 RegisterMCAsmBackend(Target &T) {
1091 TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1095 static MCAsmBackend *Allocator(const Target &T,
1096 const MCRegisterInfo &MRI,
1097 StringRef Triple, StringRef CPU) {
1098 return new MCAsmBackendImpl(T, MRI, Triple, CPU);
1102 /// RegisterMCAsmParser - Helper template for registering a target specific
1103 /// assembly parser, for use in the target machine initialization
1104 /// function. Usage:
1106 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1107 /// extern Target TheFooTarget;
1108 /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1110 template<class MCAsmParserImpl>
1111 struct RegisterMCAsmParser {
1112 RegisterMCAsmParser(Target &T) {
1113 TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1117 static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P,
1118 const MCInstrInfo &MII,
1119 const MCTargetOptions &Options) {
1120 return new MCAsmParserImpl(STI, P, MII, Options);
1124 /// RegisterAsmPrinter - Helper template for registering a target specific
1125 /// assembly printer, for use in the target machine initialization
1126 /// function. Usage:
1128 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1129 /// extern Target TheFooTarget;
1130 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1132 template<class AsmPrinterImpl>
1133 struct RegisterAsmPrinter {
1134 RegisterAsmPrinter(Target &T) {
1135 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1139 static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) {
1140 return new AsmPrinterImpl(TM, Streamer);
1144 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1145 /// machine code emitter, for use in the target initialization
1146 /// function. Usage:
1148 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1149 /// extern Target TheFooTarget;
1150 /// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1152 template<class MCCodeEmitterImpl>
1153 struct RegisterMCCodeEmitter {
1154 RegisterMCCodeEmitter(Target &T) {
1155 TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1159 static MCCodeEmitter *Allocator(const MCInstrInfo &/*II*/,
1160 const MCRegisterInfo &/*MRI*/,
1161 const MCSubtargetInfo &/*STI*/,
1162 MCContext &/*Ctx*/) {
1163 return new MCCodeEmitterImpl();