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,
569 /// @name Target Registration
572 /// RegisterTarget - Register the given target. Attempts to register a
573 /// target which has already been registered will be ignored.
575 /// Clients are responsible for ensuring that registration doesn't occur
576 /// while another thread is attempting to access the registry. Typically
577 /// this is done by initializing all targets at program startup.
579 /// @param T - The target being registered.
580 /// @param Name - The target name. This should be a static string.
581 /// @param ShortDesc - A short target description. This should be a static
583 /// @param ArchMatchFn - The arch match checking function for this target.
584 /// @param HasJIT - Whether the target supports JIT code
586 static void RegisterTarget(Target &T,
588 const char *ShortDesc,
589 Target::ArchMatchFnTy ArchMatchFn,
590 bool HasJIT = false);
592 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
595 /// Clients are responsible for ensuring that registration doesn't occur
596 /// while another thread is attempting to access the registry. Typically
597 /// this is done by initializing all targets at program startup.
599 /// @param T - The target being registered.
600 /// @param Fn - A function to construct a MCAsmInfo for the target.
601 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
602 T.MCAsmInfoCtorFn = Fn;
605 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
608 /// Clients are responsible for ensuring that registration doesn't occur
609 /// while another thread is attempting to access the registry. Typically
610 /// this is done by initializing all targets at program startup.
612 /// @param T - The target being registered.
613 /// @param Fn - A function to construct a MCCodeGenInfo for the target.
614 static void RegisterMCCodeGenInfo(Target &T,
615 Target::MCCodeGenInfoCtorFnTy Fn) {
616 T.MCCodeGenInfoCtorFn = Fn;
619 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
622 /// Clients are responsible for ensuring that registration doesn't occur
623 /// while another thread is attempting to access the registry. Typically
624 /// this is done by initializing all targets at program startup.
626 /// @param T - The target being registered.
627 /// @param Fn - A function to construct a MCInstrInfo for the target.
628 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
629 T.MCInstrInfoCtorFn = Fn;
632 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
633 /// the given target.
634 static void RegisterMCInstrAnalysis(Target &T,
635 Target::MCInstrAnalysisCtorFnTy Fn) {
636 T.MCInstrAnalysisCtorFn = Fn;
639 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
642 /// Clients are responsible for ensuring that registration doesn't occur
643 /// while another thread is attempting to access the registry. Typically
644 /// this is done by initializing all targets at program startup.
646 /// @param T - The target being registered.
647 /// @param Fn - A function to construct a MCRegisterInfo for the target.
648 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
649 T.MCRegInfoCtorFn = Fn;
652 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
653 /// the given target.
655 /// Clients are responsible for ensuring that registration doesn't occur
656 /// while another thread is attempting to access the registry. Typically
657 /// this is done by initializing all targets at program startup.
659 /// @param T - The target being registered.
660 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
661 static void RegisterMCSubtargetInfo(Target &T,
662 Target::MCSubtargetInfoCtorFnTy Fn) {
663 T.MCSubtargetInfoCtorFn = Fn;
666 /// RegisterTargetMachine - Register a TargetMachine implementation for the
669 /// Clients are responsible for ensuring that registration doesn't occur
670 /// while another thread is attempting to access the registry. Typically
671 /// this is done by initializing all targets at program startup.
673 /// @param T - The target being registered.
674 /// @param Fn - A function to construct a TargetMachine for the target.
675 static void RegisterTargetMachine(Target &T,
676 Target::TargetMachineCtorTy Fn) {
677 T.TargetMachineCtorFn = Fn;
680 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
683 /// Clients are responsible for ensuring that registration doesn't occur
684 /// while another thread is attempting to access the registry. Typically
685 /// this is done by initializing all targets at program startup.
687 /// @param T - The target being registered.
688 /// @param Fn - A function to construct an AsmBackend for the target.
689 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
690 T.MCAsmBackendCtorFn = Fn;
693 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
694 /// the given target.
696 /// Clients are responsible for ensuring that registration doesn't occur
697 /// while another thread is attempting to access the registry. Typically
698 /// this is done by initializing all targets at program startup.
700 /// @param T - The target being registered.
701 /// @param Fn - A function to construct an MCTargetAsmParser for the target.
702 static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
703 T.MCAsmParserCtorFn = Fn;
706 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
709 /// Clients are responsible for ensuring that registration doesn't occur
710 /// while another thread is attempting to access the registry. Typically
711 /// this is done by initializing all targets at program startup.
713 /// @param T - The target being registered.
714 /// @param Fn - A function to construct an AsmPrinter for the target.
715 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
716 T.AsmPrinterCtorFn = Fn;
719 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
720 /// the given target.
722 /// Clients are responsible for ensuring that registration doesn't occur
723 /// while another thread is attempting to access the registry. Typically
724 /// this is done by initializing all targets at program startup.
726 /// @param T - The target being registered.
727 /// @param Fn - A function to construct an MCDisassembler for the target.
728 static void RegisterMCDisassembler(Target &T,
729 Target::MCDisassemblerCtorTy Fn) {
730 T.MCDisassemblerCtorFn = Fn;
733 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
736 /// Clients are responsible for ensuring that registration doesn't occur
737 /// while another thread is attempting to access the registry. Typically
738 /// this is done by initializing all targets at program startup.
740 /// @param T - The target being registered.
741 /// @param Fn - A function to construct an MCInstPrinter for the target.
742 static void RegisterMCInstPrinter(Target &T,
743 Target::MCInstPrinterCtorTy Fn) {
744 T.MCInstPrinterCtorFn = Fn;
747 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
750 /// Clients are responsible for ensuring that registration doesn't occur
751 /// while another thread is attempting to access the registry. Typically
752 /// this is done by initializing all targets at program startup.
754 /// @param T - The target being registered.
755 /// @param Fn - A function to construct an MCCodeEmitter for the target.
756 static void RegisterMCCodeEmitter(Target &T,
757 Target::MCCodeEmitterCtorTy Fn) {
758 T.MCCodeEmitterCtorFn = Fn;
761 /// RegisterMCObjectStreamer - Register a object code MCStreamer
762 /// implementation for the given target.
764 /// Clients are responsible for ensuring that registration doesn't occur
765 /// while another thread is attempting to access the registry. Typically
766 /// this is done by initializing all targets at program startup.
768 /// @param T - The target being registered.
769 /// @param Fn - A function to construct an MCStreamer for the target.
770 static void RegisterMCObjectStreamer(Target &T,
771 Target::MCObjectStreamerCtorTy Fn) {
772 T.MCObjectStreamerCtorFn = Fn;
775 /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
776 /// for the given target.
778 /// Clients are responsible for ensuring that registration doesn't occur
779 /// while another thread is attempting to access the registry. Typically
780 /// this is done by initializing all targets at program startup.
782 /// @param T - The target being registered.
783 /// @param Fn - A function to construct an MCStreamer for the target.
784 static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
785 T.AsmStreamerCtorFn = Fn;
788 static void RegisterNullStreamer(Target &T, Target::NullStreamerCtorTy Fn) {
789 T.NullStreamerCtorFn = Fn;
792 /// RegisterMCRelocationInfo - Register an MCRelocationInfo
793 /// implementation for the given target.
795 /// Clients are responsible for ensuring that registration doesn't occur
796 /// while another thread is attempting to access the registry. Typically
797 /// this is done by initializing all targets at program startup.
799 /// @param T - The target being registered.
800 /// @param Fn - A function to construct an MCRelocationInfo for the target.
801 static void RegisterMCRelocationInfo(Target &T,
802 Target::MCRelocationInfoCtorTy Fn) {
803 T.MCRelocationInfoCtorFn = Fn;
806 /// RegisterMCSymbolizer - Register an MCSymbolizer
807 /// implementation for the given target.
809 /// Clients are responsible for ensuring that registration doesn't occur
810 /// while another thread is attempting to access the registry. Typically
811 /// this is done by initializing all targets at program startup.
813 /// @param T - The target being registered.
814 /// @param Fn - A function to construct an MCSymbolizer for the target.
815 static void RegisterMCSymbolizer(Target &T,
816 Target::MCSymbolizerCtorTy Fn) {
817 T.MCSymbolizerCtorFn = Fn;
824 //===--------------------------------------------------------------------===//
826 /// RegisterTarget - Helper template for registering a target, for use in the
827 /// target's initialization function. Usage:
830 /// Target TheFooTarget; // The global target instance.
832 /// extern "C" void LLVMInitializeFooTargetInfo() {
833 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
835 template<Triple::ArchType TargetArchType = Triple::UnknownArch,
837 struct RegisterTarget {
838 RegisterTarget(Target &T, const char *Name, const char *Desc) {
839 TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch, HasJIT);
842 static bool getArchMatch(Triple::ArchType Arch) {
843 return Arch == TargetArchType;
847 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
848 /// implementation. This invokes the static "Create" method on the class to
849 /// actually do the construction. Usage:
851 /// extern "C" void LLVMInitializeFooTarget() {
852 /// extern Target TheFooTarget;
853 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
855 template<class MCAsmInfoImpl>
856 struct RegisterMCAsmInfo {
857 RegisterMCAsmInfo(Target &T) {
858 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
861 static MCAsmInfo *Allocator(const MCRegisterInfo &/*MRI*/, StringRef TT) {
862 return new MCAsmInfoImpl(TT);
867 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
868 /// implementation. This invokes the specified function to do the
869 /// construction. Usage:
871 /// extern "C" void LLVMInitializeFooTarget() {
872 /// extern Target TheFooTarget;
873 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
875 struct RegisterMCAsmInfoFn {
876 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
877 TargetRegistry::RegisterMCAsmInfo(T, Fn);
881 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
882 /// implementation. This invokes the static "Create" method on the class
883 /// to actually do the construction. Usage:
885 /// extern "C" void LLVMInitializeFooTarget() {
886 /// extern Target TheFooTarget;
887 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
889 template<class MCCodeGenInfoImpl>
890 struct RegisterMCCodeGenInfo {
891 RegisterMCCodeGenInfo(Target &T) {
892 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
895 static MCCodeGenInfo *Allocator(StringRef /*TT*/, Reloc::Model /*RM*/,
896 CodeModel::Model /*CM*/,
897 CodeGenOpt::Level /*OL*/) {
898 return new MCCodeGenInfoImpl();
902 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
903 /// info implementation. This invokes the specified function to do the
904 /// construction. Usage:
906 /// extern "C" void LLVMInitializeFooTarget() {
907 /// extern Target TheFooTarget;
908 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
910 struct RegisterMCCodeGenInfoFn {
911 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
912 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
916 /// RegisterMCInstrInfo - Helper template for registering a target instruction
917 /// info implementation. This invokes the static "Create" method on the class
918 /// to actually do the construction. Usage:
920 /// extern "C" void LLVMInitializeFooTarget() {
921 /// extern Target TheFooTarget;
922 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
924 template<class MCInstrInfoImpl>
925 struct RegisterMCInstrInfo {
926 RegisterMCInstrInfo(Target &T) {
927 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
930 static MCInstrInfo *Allocator() {
931 return new MCInstrInfoImpl();
935 /// RegisterMCInstrInfoFn - Helper template for registering a target
936 /// instruction info implementation. This invokes the specified function to
937 /// do the construction. Usage:
939 /// extern "C" void LLVMInitializeFooTarget() {
940 /// extern Target TheFooTarget;
941 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
943 struct RegisterMCInstrInfoFn {
944 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
945 TargetRegistry::RegisterMCInstrInfo(T, Fn);
949 /// RegisterMCInstrAnalysis - Helper template for registering a target
950 /// instruction analyzer implementation. This invokes the static "Create"
951 /// method on the class to actually do the construction. Usage:
953 /// extern "C" void LLVMInitializeFooTarget() {
954 /// extern Target TheFooTarget;
955 /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
957 template<class MCInstrAnalysisImpl>
958 struct RegisterMCInstrAnalysis {
959 RegisterMCInstrAnalysis(Target &T) {
960 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
963 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
964 return new MCInstrAnalysisImpl(Info);
968 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
969 /// instruction analyzer implementation. This invokes the specified function
970 /// to do the construction. Usage:
972 /// extern "C" void LLVMInitializeFooTarget() {
973 /// extern Target TheFooTarget;
974 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
976 struct RegisterMCInstrAnalysisFn {
977 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
978 TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
982 /// RegisterMCRegInfo - Helper template for registering a target register info
983 /// implementation. This invokes the static "Create" method on the class to
984 /// actually do the construction. Usage:
986 /// extern "C" void LLVMInitializeFooTarget() {
987 /// extern Target TheFooTarget;
988 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
990 template<class MCRegisterInfoImpl>
991 struct RegisterMCRegInfo {
992 RegisterMCRegInfo(Target &T) {
993 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
996 static MCRegisterInfo *Allocator(StringRef /*TT*/) {
997 return new MCRegisterInfoImpl();
1001 /// RegisterMCRegInfoFn - Helper template for registering a target register
1002 /// info implementation. This invokes the specified function to do the
1003 /// construction. Usage:
1005 /// extern "C" void LLVMInitializeFooTarget() {
1006 /// extern Target TheFooTarget;
1007 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
1009 struct RegisterMCRegInfoFn {
1010 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
1011 TargetRegistry::RegisterMCRegInfo(T, Fn);
1015 /// RegisterMCSubtargetInfo - Helper template for registering a target
1016 /// subtarget info implementation. This invokes the static "Create" method
1017 /// on the class to actually do the construction. Usage:
1019 /// extern "C" void LLVMInitializeFooTarget() {
1020 /// extern Target TheFooTarget;
1021 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
1023 template<class MCSubtargetInfoImpl>
1024 struct RegisterMCSubtargetInfo {
1025 RegisterMCSubtargetInfo(Target &T) {
1026 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
1029 static MCSubtargetInfo *Allocator(StringRef /*TT*/, StringRef /*CPU*/,
1031 return new MCSubtargetInfoImpl();
1035 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
1036 /// subtarget info implementation. This invokes the specified function to
1037 /// do the construction. Usage:
1039 /// extern "C" void LLVMInitializeFooTarget() {
1040 /// extern Target TheFooTarget;
1041 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1043 struct RegisterMCSubtargetInfoFn {
1044 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
1045 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
1049 /// RegisterTargetMachine - Helper template for registering a target machine
1050 /// implementation, for use in the target machine initialization
1051 /// function. Usage:
1053 /// extern "C" void LLVMInitializeFooTarget() {
1054 /// extern Target TheFooTarget;
1055 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1057 template<class TargetMachineImpl>
1058 struct RegisterTargetMachine {
1059 RegisterTargetMachine(Target &T) {
1060 TargetRegistry::RegisterTargetMachine(T, &Allocator);
1064 static TargetMachine *Allocator(const Target &T, StringRef TT,
1065 StringRef CPU, StringRef FS,
1066 const TargetOptions &Options,
1068 CodeModel::Model CM,
1069 CodeGenOpt::Level OL) {
1070 return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
1074 /// RegisterMCAsmBackend - Helper template for registering a target specific
1075 /// assembler backend. Usage:
1077 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1078 /// extern Target TheFooTarget;
1079 /// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1081 template<class MCAsmBackendImpl>
1082 struct RegisterMCAsmBackend {
1083 RegisterMCAsmBackend(Target &T) {
1084 TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1088 static MCAsmBackend *Allocator(const Target &T,
1089 const MCRegisterInfo &MRI,
1090 StringRef Triple, StringRef CPU) {
1091 return new MCAsmBackendImpl(T, MRI, Triple, CPU);
1095 /// RegisterMCAsmParser - Helper template for registering a target specific
1096 /// assembly parser, for use in the target machine initialization
1097 /// function. Usage:
1099 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1100 /// extern Target TheFooTarget;
1101 /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1103 template<class MCAsmParserImpl>
1104 struct RegisterMCAsmParser {
1105 RegisterMCAsmParser(Target &T) {
1106 TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1110 static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P,
1111 const MCInstrInfo &MII,
1112 const MCTargetOptions &Options) {
1113 return new MCAsmParserImpl(STI, P, MII, Options);
1117 /// RegisterAsmPrinter - Helper template for registering a target specific
1118 /// assembly printer, for use in the target machine initialization
1119 /// function. Usage:
1121 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1122 /// extern Target TheFooTarget;
1123 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1125 template<class AsmPrinterImpl>
1126 struct RegisterAsmPrinter {
1127 RegisterAsmPrinter(Target &T) {
1128 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1132 static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) {
1133 return new AsmPrinterImpl(TM, Streamer);
1137 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1138 /// machine code emitter, for use in the target initialization
1139 /// function. Usage:
1141 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1142 /// extern Target TheFooTarget;
1143 /// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1145 template<class MCCodeEmitterImpl>
1146 struct RegisterMCCodeEmitter {
1147 RegisterMCCodeEmitter(Target &T) {
1148 TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1152 static MCCodeEmitter *Allocator(const MCInstrInfo &/*II*/,
1153 const MCRegisterInfo &/*MRI*/,
1154 const MCSubtargetInfo &/*STI*/,
1155 MCContext &/*Ctx*/) {
1156 return new MCCodeEmitterImpl();