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)(
127 const Target &T, StringRef TT, MCContext &Ctx, MCAsmBackend &TAB,
128 raw_ostream &_OS, MCCodeEmitter *_Emitter, const MCSubtargetInfo &STI,
130 typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx,
131 formatted_raw_ostream &OS,
133 bool useDwarfDirectory,
134 MCInstPrinter *InstPrint,
138 typedef MCStreamer *(*NullStreamerCtorTy)(MCContext &Ctx);
139 typedef MCRelocationInfo *(*MCRelocationInfoCtorTy)(StringRef TT,
141 typedef MCSymbolizer *(*MCSymbolizerCtorTy)(StringRef TT,
142 LLVMOpInfoCallback GetOpInfo,
143 LLVMSymbolLookupCallback SymbolLookUp,
146 MCRelocationInfo *RelInfo);
149 /// Next - The next registered target in the linked list, maintained by the
153 /// The target function for checking if an architecture is supported.
154 ArchMatchFnTy ArchMatchFn;
156 /// Name - The target name.
159 /// ShortDesc - A short description of the target.
160 const char *ShortDesc;
162 /// HasJIT - Whether this target supports the JIT.
165 /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
167 MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
169 /// MCCodeGenInfoCtorFn - Constructor function for this target's
170 /// MCCodeGenInfo, if registered.
171 MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn;
173 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
175 MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
177 /// MCInstrAnalysisCtorFn - Constructor function for this target's
178 /// MCInstrAnalysis, if registered.
179 MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
181 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
183 MCRegInfoCtorFnTy MCRegInfoCtorFn;
185 /// MCSubtargetInfoCtorFn - Constructor function for this target's
186 /// MCSubtargetInfo, if registered.
187 MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
189 /// TargetMachineCtorFn - Construction function for this target's
190 /// TargetMachine, if registered.
191 TargetMachineCtorTy TargetMachineCtorFn;
193 /// MCAsmBackendCtorFn - Construction function for this target's
194 /// MCAsmBackend, if registered.
195 MCAsmBackendCtorTy MCAsmBackendCtorFn;
197 /// MCAsmParserCtorFn - Construction function for this target's
198 /// MCTargetAsmParser, if registered.
199 MCAsmParserCtorTy MCAsmParserCtorFn;
201 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
203 AsmPrinterCtorTy AsmPrinterCtorFn;
205 /// MCDisassemblerCtorFn - Construction function for this target's
206 /// MCDisassembler, if registered.
207 MCDisassemblerCtorTy MCDisassemblerCtorFn;
209 /// MCInstPrinterCtorFn - Construction function for this target's
210 /// MCInstPrinter, if registered.
211 MCInstPrinterCtorTy MCInstPrinterCtorFn;
213 /// MCCodeEmitterCtorFn - Construction function for this target's
214 /// CodeEmitter, if registered.
215 MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
217 /// MCObjectStreamerCtorFn - Construction function for this target's
218 /// MCObjectStreamer, if registered.
219 MCObjectStreamerCtorTy MCObjectStreamerCtorFn;
221 /// AsmStreamerCtorFn - Construction function for this target's
222 /// AsmStreamer, if registered (default = llvm::createAsmStreamer).
223 AsmStreamerCtorTy AsmStreamerCtorFn;
225 /// Construction function for this target's NullStreamer, if registered
226 /// (default = llvm::createNullStreamer).
227 NullStreamerCtorTy NullStreamerCtorFn;
229 /// MCRelocationInfoCtorFn - Construction function for this target's
230 /// MCRelocationInfo, if registered (default = llvm::createMCRelocationInfo)
231 MCRelocationInfoCtorTy MCRelocationInfoCtorFn;
233 /// MCSymbolizerCtorFn - Construction function for this target's
234 /// MCSymbolizer, if registered (default = llvm::createMCSymbolizer)
235 MCSymbolizerCtorTy MCSymbolizerCtorFn;
239 : AsmStreamerCtorFn(nullptr), NullStreamerCtorFn(nullptr),
240 MCRelocationInfoCtorFn(nullptr), MCSymbolizerCtorFn(nullptr) {}
242 /// @name Target Information
245 // getNext - Return the next registered target.
246 const Target *getNext() const { return Next; }
248 /// getName - Get the target name.
249 const char *getName() const { return Name; }
251 /// getShortDescription - Get a short description of the target.
252 const char *getShortDescription() const { return ShortDesc; }
255 /// @name Feature Predicates
258 /// hasJIT - Check if this targets supports the just-in-time compilation.
259 bool hasJIT() const { return HasJIT; }
261 /// hasTargetMachine - Check if this target supports code generation.
262 bool hasTargetMachine() const { return TargetMachineCtorFn != nullptr; }
264 /// hasMCAsmBackend - Check if this target supports .o generation.
265 bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != nullptr; }
268 /// @name Feature Constructors
271 /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
274 /// \param Triple This argument is used to determine the target machine
275 /// feature set; it should always be provided. Generally this should be
276 /// either the target triple from the module, or the target triple of the
277 /// host if that does not exist.
278 MCAsmInfo *createMCAsmInfo(const MCRegisterInfo &MRI,
279 StringRef Triple) const {
280 if (!MCAsmInfoCtorFn)
282 return MCAsmInfoCtorFn(MRI, Triple);
285 /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
287 MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model RM,
289 CodeGenOpt::Level OL) const {
290 if (!MCCodeGenInfoCtorFn)
292 return MCCodeGenInfoCtorFn(Triple, RM, CM, OL);
295 /// createMCInstrInfo - Create a MCInstrInfo implementation.
297 MCInstrInfo *createMCInstrInfo() const {
298 if (!MCInstrInfoCtorFn)
300 return MCInstrInfoCtorFn();
303 /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
305 MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
306 if (!MCInstrAnalysisCtorFn)
308 return MCInstrAnalysisCtorFn(Info);
311 /// createMCRegInfo - Create a MCRegisterInfo implementation.
313 MCRegisterInfo *createMCRegInfo(StringRef Triple) const {
314 if (!MCRegInfoCtorFn)
316 return MCRegInfoCtorFn(Triple);
319 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
321 /// \param Triple This argument is used to determine the target machine
322 /// feature set; it should always be provided. Generally this should be
323 /// either the target triple from the module, or the target triple of the
324 /// host if that does not exist.
325 /// \param CPU This specifies the name of the target CPU.
326 /// \param Features This specifies the string representation of the
327 /// additional target features.
328 MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU,
329 StringRef Features) const {
330 if (!MCSubtargetInfoCtorFn)
332 return MCSubtargetInfoCtorFn(Triple, CPU, Features);
335 /// createTargetMachine - Create a target specific machine implementation
336 /// for the specified \p Triple.
338 /// \param Triple This argument is used to determine the target machine
339 /// feature set; it should always be provided. Generally this should be
340 /// either the target triple from the module, or the target triple of the
341 /// host if that does not exist.
342 TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU,
343 StringRef Features, const TargetOptions &Options,
344 Reloc::Model RM = Reloc::Default,
345 CodeModel::Model CM = CodeModel::Default,
346 CodeGenOpt::Level OL = CodeGenOpt::Default) const {
347 if (!TargetMachineCtorFn)
349 return TargetMachineCtorFn(*this, Triple, CPU, Features, Options,
353 /// createMCAsmBackend - Create a target specific assembly parser.
355 /// \param Triple The target triple string.
356 MCAsmBackend *createMCAsmBackend(const MCRegisterInfo &MRI,
357 StringRef Triple, StringRef CPU) const {
358 if (!MCAsmBackendCtorFn)
360 return MCAsmBackendCtorFn(*this, MRI, Triple, CPU);
363 /// createMCAsmParser - Create a target specific assembly parser.
365 /// \param Parser The target independent parser implementation to use for
366 /// parsing and lexing.
367 MCTargetAsmParser *createMCAsmParser(
368 MCSubtargetInfo &STI,
370 const MCInstrInfo &MII,
371 const MCTargetOptions &Options) const {
372 if (!MCAsmParserCtorFn)
374 return MCAsmParserCtorFn(STI, Parser, MII, Options);
377 /// createAsmPrinter - Create a target specific assembly printer pass. This
378 /// takes ownership of the MCStreamer object.
379 AsmPrinter *createAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) const{
380 if (!AsmPrinterCtorFn)
382 return AsmPrinterCtorFn(TM, Streamer);
385 MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI,
386 MCContext &Ctx) const {
387 if (!MCDisassemblerCtorFn)
389 return MCDisassemblerCtorFn(*this, STI, Ctx);
392 MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
393 const MCAsmInfo &MAI,
394 const MCInstrInfo &MII,
395 const MCRegisterInfo &MRI,
396 const MCSubtargetInfo &STI) const {
397 if (!MCInstPrinterCtorFn)
399 return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, MII, MRI, STI);
403 /// createMCCodeEmitter - Create a target specific code emitter.
404 MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
405 const MCRegisterInfo &MRI,
406 const MCSubtargetInfo &STI,
407 MCContext &Ctx) const {
408 if (!MCCodeEmitterCtorFn)
410 return MCCodeEmitterCtorFn(II, MRI, STI, Ctx);
413 /// createMCObjectStreamer - Create a target specific MCStreamer.
415 /// \param TT The target triple.
416 /// \param Ctx The target context.
417 /// \param TAB The target assembler backend object. Takes ownership.
418 /// \param _OS The stream object.
419 /// \param _Emitter The target independent assembler object.Takes ownership.
420 /// \param RelaxAll Relax all fixups?
421 MCStreamer *createMCObjectStreamer(StringRef TT, MCContext &Ctx,
422 MCAsmBackend &TAB, raw_ostream &_OS,
423 MCCodeEmitter *_Emitter,
424 const MCSubtargetInfo &STI,
425 bool RelaxAll) const {
426 if (!MCObjectStreamerCtorFn)
428 return MCObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter, STI,
432 /// createAsmStreamer - Create a target specific MCStreamer.
433 MCStreamer *createAsmStreamer(MCContext &Ctx,
434 formatted_raw_ostream &OS,
436 bool useDwarfDirectory,
437 MCInstPrinter *InstPrint,
440 bool ShowInst) const {
441 if (AsmStreamerCtorFn)
442 return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useDwarfDirectory,
443 InstPrint, CE, TAB, ShowInst);
444 return llvm::createAsmStreamer(Ctx, OS, isVerboseAsm, useDwarfDirectory,
445 InstPrint, CE, TAB, ShowInst);
448 MCStreamer *createNullStreamer(MCContext &Ctx) const {
449 if (NullStreamerCtorFn)
450 return NullStreamerCtorFn(Ctx);
451 return llvm::createNullStreamer(Ctx);
454 /// createMCRelocationInfo - Create a target specific MCRelocationInfo.
456 /// \param TT The target triple.
457 /// \param Ctx The target context.
459 createMCRelocationInfo(StringRef TT, MCContext &Ctx) const {
460 MCRelocationInfoCtorTy Fn = MCRelocationInfoCtorFn
461 ? MCRelocationInfoCtorFn
462 : llvm::createMCRelocationInfo;
466 /// createMCSymbolizer - Create a target specific MCSymbolizer.
468 /// \param TT The target triple.
469 /// \param GetOpInfo The function to get the symbolic information for operands.
470 /// \param SymbolLookUp The function to lookup a symbol name.
471 /// \param DisInfo The pointer to the block of symbolic information for above call
473 /// \param Ctx The target context.
474 /// \param RelInfo The relocation information for this target. Takes ownership.
476 createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
477 LLVMSymbolLookupCallback SymbolLookUp,
479 MCContext *Ctx, MCRelocationInfo *RelInfo) const {
480 MCSymbolizerCtorTy Fn =
481 MCSymbolizerCtorFn ? MCSymbolizerCtorFn : llvm::createMCSymbolizer;
482 return Fn(TT, GetOpInfo, SymbolLookUp, DisInfo, Ctx, RelInfo);
488 /// TargetRegistry - Generic interface to target specific features.
489 struct TargetRegistry {
491 const Target *Current;
492 explicit iterator(Target *T) : Current(T) {}
493 friend struct TargetRegistry;
495 iterator() : Current(nullptr) {}
497 bool operator==(const iterator &x) const {
498 return Current == x.Current;
500 bool operator!=(const iterator &x) const {
501 return !operator==(x);
504 // Iterator traversal: forward iteration only
505 iterator &operator++() { // Preincrement
506 assert(Current && "Cannot increment end iterator!");
507 Current = Current->getNext();
510 iterator operator++(int) { // Postincrement
511 iterator tmp = *this;
516 const Target &operator*() const {
517 assert(Current && "Cannot dereference end iterator!");
521 const Target *operator->() const {
526 /// printRegisteredTargetsForVersion - Print the registered targets
527 /// appropriately for inclusion in a tool's version output.
528 static void printRegisteredTargetsForVersion();
530 /// @name Registry Access
533 static iterator begin();
535 static iterator end() { return iterator(); }
537 /// lookupTarget - Lookup a target based on a target triple.
539 /// \param Triple - The triple to use for finding a target.
540 /// \param Error - On failure, an error string describing why no target was
542 static const Target *lookupTarget(const std::string &Triple,
545 /// lookupTarget - Lookup a target based on an architecture name
546 /// and a target triple. If the architecture name is non-empty,
547 /// then the lookup is done by architecture. Otherwise, the target
550 /// \param ArchName - The architecture to use for finding a target.
551 /// \param TheTriple - The triple to use for finding a target. The
552 /// triple is updated with canonical architecture name if a lookup
553 /// by architecture is done.
554 /// \param Error - On failure, an error string describing why no target was
556 static const Target *lookupTarget(const std::string &ArchName,
561 /// @name Target Registration
564 /// RegisterTarget - Register the given target. Attempts to register a
565 /// target which has already been registered will be ignored.
567 /// Clients are responsible for ensuring that registration doesn't occur
568 /// while another thread is attempting to access the registry. Typically
569 /// this is done by initializing all targets at program startup.
571 /// @param T - The target being registered.
572 /// @param Name - The target name. This should be a static string.
573 /// @param ShortDesc - A short target description. This should be a static
575 /// @param ArchMatchFn - The arch match checking function for this target.
576 /// @param HasJIT - Whether the target supports JIT code
578 static void RegisterTarget(Target &T,
580 const char *ShortDesc,
581 Target::ArchMatchFnTy ArchMatchFn,
582 bool HasJIT = false);
584 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
587 /// Clients are responsible for ensuring that registration doesn't occur
588 /// while another thread is attempting to access the registry. Typically
589 /// this is done by initializing all targets at program startup.
591 /// @param T - The target being registered.
592 /// @param Fn - A function to construct a MCAsmInfo for the target.
593 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
594 T.MCAsmInfoCtorFn = Fn;
597 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
600 /// Clients are responsible for ensuring that registration doesn't occur
601 /// while another thread is attempting to access the registry. Typically
602 /// this is done by initializing all targets at program startup.
604 /// @param T - The target being registered.
605 /// @param Fn - A function to construct a MCCodeGenInfo for the target.
606 static void RegisterMCCodeGenInfo(Target &T,
607 Target::MCCodeGenInfoCtorFnTy Fn) {
608 T.MCCodeGenInfoCtorFn = Fn;
611 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
614 /// Clients are responsible for ensuring that registration doesn't occur
615 /// while another thread is attempting to access the registry. Typically
616 /// this is done by initializing all targets at program startup.
618 /// @param T - The target being registered.
619 /// @param Fn - A function to construct a MCInstrInfo for the target.
620 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
621 T.MCInstrInfoCtorFn = Fn;
624 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
625 /// the given target.
626 static void RegisterMCInstrAnalysis(Target &T,
627 Target::MCInstrAnalysisCtorFnTy Fn) {
628 T.MCInstrAnalysisCtorFn = Fn;
631 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
634 /// Clients are responsible for ensuring that registration doesn't occur
635 /// while another thread is attempting to access the registry. Typically
636 /// this is done by initializing all targets at program startup.
638 /// @param T - The target being registered.
639 /// @param Fn - A function to construct a MCRegisterInfo for the target.
640 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
641 T.MCRegInfoCtorFn = Fn;
644 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
645 /// the given target.
647 /// Clients are responsible for ensuring that registration doesn't occur
648 /// while another thread is attempting to access the registry. Typically
649 /// this is done by initializing all targets at program startup.
651 /// @param T - The target being registered.
652 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
653 static void RegisterMCSubtargetInfo(Target &T,
654 Target::MCSubtargetInfoCtorFnTy Fn) {
655 T.MCSubtargetInfoCtorFn = Fn;
658 /// RegisterTargetMachine - Register a TargetMachine implementation for the
661 /// Clients are responsible for ensuring that registration doesn't occur
662 /// while another thread is attempting to access the registry. Typically
663 /// this is done by initializing all targets at program startup.
665 /// @param T - The target being registered.
666 /// @param Fn - A function to construct a TargetMachine for the target.
667 static void RegisterTargetMachine(Target &T,
668 Target::TargetMachineCtorTy Fn) {
669 T.TargetMachineCtorFn = Fn;
672 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
675 /// Clients are responsible for ensuring that registration doesn't occur
676 /// while another thread is attempting to access the registry. Typically
677 /// this is done by initializing all targets at program startup.
679 /// @param T - The target being registered.
680 /// @param Fn - A function to construct an AsmBackend for the target.
681 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
682 T.MCAsmBackendCtorFn = Fn;
685 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
686 /// the given target.
688 /// Clients are responsible for ensuring that registration doesn't occur
689 /// while another thread is attempting to access the registry. Typically
690 /// this is done by initializing all targets at program startup.
692 /// @param T - The target being registered.
693 /// @param Fn - A function to construct an MCTargetAsmParser for the target.
694 static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
695 T.MCAsmParserCtorFn = Fn;
698 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
701 /// Clients are responsible for ensuring that registration doesn't occur
702 /// while another thread is attempting to access the registry. Typically
703 /// this is done by initializing all targets at program startup.
705 /// @param T - The target being registered.
706 /// @param Fn - A function to construct an AsmPrinter for the target.
707 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
708 T.AsmPrinterCtorFn = Fn;
711 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
712 /// the given target.
714 /// Clients are responsible for ensuring that registration doesn't occur
715 /// while another thread is attempting to access the registry. Typically
716 /// this is done by initializing all targets at program startup.
718 /// @param T - The target being registered.
719 /// @param Fn - A function to construct an MCDisassembler for the target.
720 static void RegisterMCDisassembler(Target &T,
721 Target::MCDisassemblerCtorTy Fn) {
722 T.MCDisassemblerCtorFn = Fn;
725 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
728 /// Clients are responsible for ensuring that registration doesn't occur
729 /// while another thread is attempting to access the registry. Typically
730 /// this is done by initializing all targets at program startup.
732 /// @param T - The target being registered.
733 /// @param Fn - A function to construct an MCInstPrinter for the target.
734 static void RegisterMCInstPrinter(Target &T,
735 Target::MCInstPrinterCtorTy Fn) {
736 T.MCInstPrinterCtorFn = Fn;
739 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
742 /// Clients are responsible for ensuring that registration doesn't occur
743 /// while another thread is attempting to access the registry. Typically
744 /// this is done by initializing all targets at program startup.
746 /// @param T - The target being registered.
747 /// @param Fn - A function to construct an MCCodeEmitter for the target.
748 static void RegisterMCCodeEmitter(Target &T,
749 Target::MCCodeEmitterCtorTy Fn) {
750 T.MCCodeEmitterCtorFn = Fn;
753 /// RegisterMCObjectStreamer - Register a object code MCStreamer
754 /// implementation for the given target.
756 /// Clients are responsible for ensuring that registration doesn't occur
757 /// while another thread is attempting to access the registry. Typically
758 /// this is done by initializing all targets at program startup.
760 /// @param T - The target being registered.
761 /// @param Fn - A function to construct an MCStreamer for the target.
762 static void RegisterMCObjectStreamer(Target &T,
763 Target::MCObjectStreamerCtorTy Fn) {
764 T.MCObjectStreamerCtorFn = Fn;
767 /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
768 /// for the given target.
770 /// Clients are responsible for ensuring that registration doesn't occur
771 /// while another thread is attempting to access the registry. Typically
772 /// this is done by initializing all targets at program startup.
774 /// @param T - The target being registered.
775 /// @param Fn - A function to construct an MCStreamer for the target.
776 static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
777 T.AsmStreamerCtorFn = Fn;
780 static void RegisterNullStreamer(Target &T, Target::NullStreamerCtorTy Fn) {
781 T.NullStreamerCtorFn = Fn;
784 /// RegisterMCRelocationInfo - Register an MCRelocationInfo
785 /// implementation for the given target.
787 /// Clients are responsible for ensuring that registration doesn't occur
788 /// while another thread is attempting to access the registry. Typically
789 /// this is done by initializing all targets at program startup.
791 /// @param T - The target being registered.
792 /// @param Fn - A function to construct an MCRelocationInfo for the target.
793 static void RegisterMCRelocationInfo(Target &T,
794 Target::MCRelocationInfoCtorTy Fn) {
795 T.MCRelocationInfoCtorFn = Fn;
798 /// RegisterMCSymbolizer - Register an MCSymbolizer
799 /// implementation for the given target.
801 /// Clients are responsible for ensuring that registration doesn't occur
802 /// while another thread is attempting to access the registry. Typically
803 /// this is done by initializing all targets at program startup.
805 /// @param T - The target being registered.
806 /// @param Fn - A function to construct an MCSymbolizer for the target.
807 static void RegisterMCSymbolizer(Target &T,
808 Target::MCSymbolizerCtorTy Fn) {
809 T.MCSymbolizerCtorFn = Fn;
816 //===--------------------------------------------------------------------===//
818 /// RegisterTarget - Helper template for registering a target, for use in the
819 /// target's initialization function. Usage:
822 /// Target TheFooTarget; // The global target instance.
824 /// extern "C" void LLVMInitializeFooTargetInfo() {
825 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
827 template<Triple::ArchType TargetArchType = Triple::UnknownArch,
829 struct RegisterTarget {
830 RegisterTarget(Target &T, const char *Name, const char *Desc) {
831 TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch, HasJIT);
834 static bool getArchMatch(Triple::ArchType Arch) {
835 return Arch == TargetArchType;
839 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
840 /// implementation. This invokes the static "Create" method on the class to
841 /// actually do the construction. Usage:
843 /// extern "C" void LLVMInitializeFooTarget() {
844 /// extern Target TheFooTarget;
845 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
847 template<class MCAsmInfoImpl>
848 struct RegisterMCAsmInfo {
849 RegisterMCAsmInfo(Target &T) {
850 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
853 static MCAsmInfo *Allocator(const MCRegisterInfo &/*MRI*/, StringRef TT) {
854 return new MCAsmInfoImpl(TT);
859 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
860 /// implementation. This invokes the specified function to do the
861 /// construction. Usage:
863 /// extern "C" void LLVMInitializeFooTarget() {
864 /// extern Target TheFooTarget;
865 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
867 struct RegisterMCAsmInfoFn {
868 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
869 TargetRegistry::RegisterMCAsmInfo(T, Fn);
873 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
874 /// implementation. This invokes the static "Create" method on the class
875 /// to actually do the construction. Usage:
877 /// extern "C" void LLVMInitializeFooTarget() {
878 /// extern Target TheFooTarget;
879 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
881 template<class MCCodeGenInfoImpl>
882 struct RegisterMCCodeGenInfo {
883 RegisterMCCodeGenInfo(Target &T) {
884 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
887 static MCCodeGenInfo *Allocator(StringRef /*TT*/, Reloc::Model /*RM*/,
888 CodeModel::Model /*CM*/,
889 CodeGenOpt::Level /*OL*/) {
890 return new MCCodeGenInfoImpl();
894 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
895 /// info implementation. This invokes the specified function to do the
896 /// construction. Usage:
898 /// extern "C" void LLVMInitializeFooTarget() {
899 /// extern Target TheFooTarget;
900 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
902 struct RegisterMCCodeGenInfoFn {
903 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
904 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
908 /// RegisterMCInstrInfo - Helper template for registering a target instruction
909 /// info implementation. This invokes the static "Create" method on the class
910 /// to actually do the construction. Usage:
912 /// extern "C" void LLVMInitializeFooTarget() {
913 /// extern Target TheFooTarget;
914 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
916 template<class MCInstrInfoImpl>
917 struct RegisterMCInstrInfo {
918 RegisterMCInstrInfo(Target &T) {
919 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
922 static MCInstrInfo *Allocator() {
923 return new MCInstrInfoImpl();
927 /// RegisterMCInstrInfoFn - Helper template for registering a target
928 /// instruction info implementation. This invokes the specified function to
929 /// do the construction. Usage:
931 /// extern "C" void LLVMInitializeFooTarget() {
932 /// extern Target TheFooTarget;
933 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
935 struct RegisterMCInstrInfoFn {
936 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
937 TargetRegistry::RegisterMCInstrInfo(T, Fn);
941 /// RegisterMCInstrAnalysis - Helper template for registering a target
942 /// instruction analyzer implementation. This invokes the static "Create"
943 /// method on the class to actually do the construction. Usage:
945 /// extern "C" void LLVMInitializeFooTarget() {
946 /// extern Target TheFooTarget;
947 /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
949 template<class MCInstrAnalysisImpl>
950 struct RegisterMCInstrAnalysis {
951 RegisterMCInstrAnalysis(Target &T) {
952 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
955 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
956 return new MCInstrAnalysisImpl(Info);
960 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
961 /// instruction analyzer implementation. This invokes the specified function
962 /// to do the construction. Usage:
964 /// extern "C" void LLVMInitializeFooTarget() {
965 /// extern Target TheFooTarget;
966 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
968 struct RegisterMCInstrAnalysisFn {
969 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
970 TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
974 /// RegisterMCRegInfo - Helper template for registering a target register info
975 /// implementation. This invokes the static "Create" method on the class to
976 /// actually do the construction. Usage:
978 /// extern "C" void LLVMInitializeFooTarget() {
979 /// extern Target TheFooTarget;
980 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
982 template<class MCRegisterInfoImpl>
983 struct RegisterMCRegInfo {
984 RegisterMCRegInfo(Target &T) {
985 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
988 static MCRegisterInfo *Allocator(StringRef /*TT*/) {
989 return new MCRegisterInfoImpl();
993 /// RegisterMCRegInfoFn - Helper template for registering a target register
994 /// info implementation. This invokes the specified function to do the
995 /// construction. Usage:
997 /// extern "C" void LLVMInitializeFooTarget() {
998 /// extern Target TheFooTarget;
999 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
1001 struct RegisterMCRegInfoFn {
1002 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
1003 TargetRegistry::RegisterMCRegInfo(T, Fn);
1007 /// RegisterMCSubtargetInfo - Helper template for registering a target
1008 /// subtarget info implementation. This invokes the static "Create" method
1009 /// on the class to actually do the construction. Usage:
1011 /// extern "C" void LLVMInitializeFooTarget() {
1012 /// extern Target TheFooTarget;
1013 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
1015 template<class MCSubtargetInfoImpl>
1016 struct RegisterMCSubtargetInfo {
1017 RegisterMCSubtargetInfo(Target &T) {
1018 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
1021 static MCSubtargetInfo *Allocator(StringRef /*TT*/, StringRef /*CPU*/,
1023 return new MCSubtargetInfoImpl();
1027 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
1028 /// subtarget info implementation. This invokes the specified function to
1029 /// do the construction. Usage:
1031 /// extern "C" void LLVMInitializeFooTarget() {
1032 /// extern Target TheFooTarget;
1033 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1035 struct RegisterMCSubtargetInfoFn {
1036 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
1037 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
1041 /// RegisterTargetMachine - Helper template for registering a target machine
1042 /// implementation, for use in the target machine initialization
1043 /// function. Usage:
1045 /// extern "C" void LLVMInitializeFooTarget() {
1046 /// extern Target TheFooTarget;
1047 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1049 template<class TargetMachineImpl>
1050 struct RegisterTargetMachine {
1051 RegisterTargetMachine(Target &T) {
1052 TargetRegistry::RegisterTargetMachine(T, &Allocator);
1056 static TargetMachine *Allocator(const Target &T, StringRef TT,
1057 StringRef CPU, StringRef FS,
1058 const TargetOptions &Options,
1060 CodeModel::Model CM,
1061 CodeGenOpt::Level OL) {
1062 return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
1066 /// RegisterMCAsmBackend - Helper template for registering a target specific
1067 /// assembler backend. Usage:
1069 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1070 /// extern Target TheFooTarget;
1071 /// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1073 template<class MCAsmBackendImpl>
1074 struct RegisterMCAsmBackend {
1075 RegisterMCAsmBackend(Target &T) {
1076 TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1080 static MCAsmBackend *Allocator(const Target &T,
1081 const MCRegisterInfo &MRI,
1082 StringRef Triple, StringRef CPU) {
1083 return new MCAsmBackendImpl(T, MRI, Triple, CPU);
1087 /// RegisterMCAsmParser - Helper template for registering a target specific
1088 /// assembly parser, for use in the target machine initialization
1089 /// function. Usage:
1091 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1092 /// extern Target TheFooTarget;
1093 /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1095 template<class MCAsmParserImpl>
1096 struct RegisterMCAsmParser {
1097 RegisterMCAsmParser(Target &T) {
1098 TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1102 static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P,
1103 const MCInstrInfo &MII,
1104 const MCTargetOptions &Options) {
1105 return new MCAsmParserImpl(STI, P, MII, Options);
1109 /// RegisterAsmPrinter - Helper template for registering a target specific
1110 /// assembly printer, for use in the target machine initialization
1111 /// function. Usage:
1113 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1114 /// extern Target TheFooTarget;
1115 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1117 template<class AsmPrinterImpl>
1118 struct RegisterAsmPrinter {
1119 RegisterAsmPrinter(Target &T) {
1120 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1124 static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) {
1125 return new AsmPrinterImpl(TM, Streamer);
1129 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1130 /// machine code emitter, for use in the target initialization
1131 /// function. Usage:
1133 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1134 /// extern Target TheFooTarget;
1135 /// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1137 template<class MCCodeEmitterImpl>
1138 struct RegisterMCCodeEmitter {
1139 RegisterMCCodeEmitter(Target &T) {
1140 TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1144 static MCCodeEmitter *Allocator(const MCInstrInfo &/*II*/,
1145 const MCRegisterInfo &/*MRI*/,
1146 const MCSubtargetInfo &/*STI*/,
1147 MCContext &/*Ctx*/) {
1148 return new MCCodeEmitterImpl();