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"
40 class MCInstrAnalysis;
45 class MCSubtargetInfo;
47 class MCRelocationInfo;
48 class MCTargetAsmParser;
49 class MCTargetOptions;
50 class MCTargetStreamer;
54 class formatted_raw_ostream;
56 MCStreamer *createNullStreamer(MCContext &Ctx);
57 MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
58 bool isVerboseAsm, bool useDwarfDirectory,
59 MCInstPrinter *InstPrint, MCCodeEmitter *CE,
60 MCAsmBackend *TAB, bool ShowInst);
62 MCRelocationInfo *createMCRelocationInfo(StringRef TT, MCContext &Ctx);
64 MCSymbolizer *createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
65 LLVMSymbolLookupCallback SymbolLookUp,
66 void *DisInfo, MCContext *Ctx,
67 std::unique_ptr<MCRelocationInfo> &&RelInfo);
69 /// Target - Wrapper for Target specific information.
71 /// For registration purposes, this is a POD type so that targets can be
72 /// registered without the use of static constructors.
74 /// Targets should implement a single global instance of this class (which
75 /// will be zero initialized), and pass that instance to the TargetRegistry as
76 /// part of their initialization.
79 friend struct TargetRegistry;
81 typedef bool (*ArchMatchFnTy)(Triple::ArchType Arch);
83 typedef MCAsmInfo *(*MCAsmInfoCtorFnTy)(const MCRegisterInfo &MRI,
85 typedef MCCodeGenInfo *(*MCCodeGenInfoCtorFnTy)(StringRef TT,
88 CodeGenOpt::Level OL);
89 typedef MCInstrInfo *(*MCInstrInfoCtorFnTy)(void);
90 typedef MCInstrAnalysis *(*MCInstrAnalysisCtorFnTy)(const MCInstrInfo*Info);
91 typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(StringRef TT);
92 typedef MCSubtargetInfo *(*MCSubtargetInfoCtorFnTy)(StringRef TT,
95 typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T,
99 const TargetOptions &Options,
102 CodeGenOpt::Level OL);
103 // If it weren't for layering issues (this header is in llvm/Support, but
104 // depends on MC?) this should take the Streamer by value rather than rvalue
106 typedef AsmPrinter *(*AsmPrinterCtorTy)(
107 TargetMachine &TM, std::unique_ptr<MCStreamer> &&Streamer);
108 typedef MCAsmBackend *(*MCAsmBackendCtorTy)(const Target &T,
109 const MCRegisterInfo &MRI,
112 typedef MCTargetAsmParser *(*MCAsmParserCtorTy)(
113 MCSubtargetInfo &STI,
115 const MCInstrInfo &MII,
116 const MCTargetOptions &Options);
117 typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T,
118 const MCSubtargetInfo &STI,
120 typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
121 unsigned SyntaxVariant,
122 const MCAsmInfo &MAI,
123 const MCInstrInfo &MII,
124 const MCRegisterInfo &MRI,
125 const MCSubtargetInfo &STI);
126 typedef MCCodeEmitter *(*MCCodeEmitterCtorTy)(const MCInstrInfo &II,
127 const MCRegisterInfo &MRI,
129 typedef MCStreamer *(*MCObjectStreamerCtorTy)(
130 const Target &T, StringRef TT, MCContext &Ctx, MCAsmBackend &TAB,
131 raw_ostream &OS, MCCodeEmitter *Emitter, const MCSubtargetInfo &STI,
133 typedef MCTargetStreamer *(*NullTargetStreamerCtorTy)(MCStreamer &S);
134 typedef MCTargetStreamer *(*AsmTargetStreamerCtorTy)(
135 MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *InstPrint,
137 typedef MCRelocationInfo *(*MCRelocationInfoCtorTy)(StringRef TT,
139 typedef MCSymbolizer *(*MCSymbolizerCtorTy)(
140 StringRef TT, LLVMOpInfoCallback GetOpInfo,
141 LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo, MCContext *Ctx,
142 std::unique_ptr<MCRelocationInfo> &&RelInfo);
145 /// Next - The next registered target in the linked list, maintained by the
149 /// The target function for checking if an architecture is supported.
150 ArchMatchFnTy ArchMatchFn;
152 /// Name - The target name.
155 /// ShortDesc - A short description of the target.
156 const char *ShortDesc;
158 /// HasJIT - Whether this target supports the JIT.
161 /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
163 MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
165 /// MCCodeGenInfoCtorFn - Constructor function for this target's
166 /// MCCodeGenInfo, if registered.
167 MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn;
169 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
171 MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
173 /// MCInstrAnalysisCtorFn - Constructor function for this target's
174 /// MCInstrAnalysis, if registered.
175 MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
177 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
179 MCRegInfoCtorFnTy MCRegInfoCtorFn;
181 /// MCSubtargetInfoCtorFn - Constructor function for this target's
182 /// MCSubtargetInfo, if registered.
183 MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
185 /// TargetMachineCtorFn - Construction function for this target's
186 /// TargetMachine, if registered.
187 TargetMachineCtorTy TargetMachineCtorFn;
189 /// MCAsmBackendCtorFn - Construction function for this target's
190 /// MCAsmBackend, if registered.
191 MCAsmBackendCtorTy MCAsmBackendCtorFn;
193 /// MCAsmParserCtorFn - Construction function for this target's
194 /// MCTargetAsmParser, if registered.
195 MCAsmParserCtorTy MCAsmParserCtorFn;
197 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
199 AsmPrinterCtorTy AsmPrinterCtorFn;
201 /// MCDisassemblerCtorFn - Construction function for this target's
202 /// MCDisassembler, if registered.
203 MCDisassemblerCtorTy MCDisassemblerCtorFn;
205 /// MCInstPrinterCtorFn - Construction function for this target's
206 /// MCInstPrinter, if registered.
207 MCInstPrinterCtorTy MCInstPrinterCtorFn;
209 /// MCCodeEmitterCtorFn - Construction function for this target's
210 /// CodeEmitter, if registered.
211 MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
213 /// MCObjectStreamerCtorFn - Construction function for this target's
214 /// MCObjectStreamer, if registered.
215 MCObjectStreamerCtorTy MCObjectStreamerCtorFn;
217 /// Construction function for this target's null TargetStreamer, if
218 /// registered (default = nullptr).
219 NullTargetStreamerCtorTy NullTargetStreamerCtorFn;
221 /// Construction function for this target's asm TargetStreamer, if
222 /// registered (default = nullptr).
223 AsmTargetStreamerCtorTy AsmTargetStreamerCtorFn;
225 /// MCRelocationInfoCtorFn - Construction function for this target's
226 /// MCRelocationInfo, if registered (default = llvm::createMCRelocationInfo)
227 MCRelocationInfoCtorTy MCRelocationInfoCtorFn;
229 /// MCSymbolizerCtorFn - Construction function for this target's
230 /// MCSymbolizer, if registered (default = llvm::createMCSymbolizer)
231 MCSymbolizerCtorTy MCSymbolizerCtorFn;
235 : NullTargetStreamerCtorFn(nullptr), AsmTargetStreamerCtorFn(nullptr),
236 MCRelocationInfoCtorFn(nullptr), MCSymbolizerCtorFn(nullptr) {}
238 /// @name Target Information
241 // getNext - Return the next registered target.
242 const Target *getNext() const { return Next; }
244 /// getName - Get the target name.
245 const char *getName() const { return Name; }
247 /// getShortDescription - Get a short description of the target.
248 const char *getShortDescription() const { return ShortDesc; }
251 /// @name Feature Predicates
254 /// hasJIT - Check if this targets supports the just-in-time compilation.
255 bool hasJIT() const { return HasJIT; }
257 /// hasTargetMachine - Check if this target supports code generation.
258 bool hasTargetMachine() const { return TargetMachineCtorFn != nullptr; }
260 /// hasMCAsmBackend - Check if this target supports .o generation.
261 bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != nullptr; }
264 /// @name Feature Constructors
267 /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
270 /// \param Triple This argument is used to determine the target machine
271 /// feature set; it should always be provided. Generally this should be
272 /// either the target triple from the module, or the target triple of the
273 /// host if that does not exist.
274 MCAsmInfo *createMCAsmInfo(const MCRegisterInfo &MRI,
275 StringRef Triple) const {
276 if (!MCAsmInfoCtorFn)
278 return MCAsmInfoCtorFn(MRI, Triple);
281 /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
283 MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model RM,
285 CodeGenOpt::Level OL) const {
286 if (!MCCodeGenInfoCtorFn)
288 return MCCodeGenInfoCtorFn(Triple, RM, CM, OL);
291 /// createMCInstrInfo - Create a MCInstrInfo implementation.
293 MCInstrInfo *createMCInstrInfo() const {
294 if (!MCInstrInfoCtorFn)
296 return MCInstrInfoCtorFn();
299 /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
301 MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
302 if (!MCInstrAnalysisCtorFn)
304 return MCInstrAnalysisCtorFn(Info);
307 /// createMCRegInfo - Create a MCRegisterInfo implementation.
309 MCRegisterInfo *createMCRegInfo(StringRef Triple) const {
310 if (!MCRegInfoCtorFn)
312 return MCRegInfoCtorFn(Triple);
315 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
317 /// \param Triple This argument is used to determine the target machine
318 /// feature set; it should always be provided. Generally this should be
319 /// either the target triple from the module, or the target triple of the
320 /// host if that does not exist.
321 /// \param CPU This specifies the name of the target CPU.
322 /// \param Features This specifies the string representation of the
323 /// additional target features.
324 MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU,
325 StringRef Features) const {
326 if (!MCSubtargetInfoCtorFn)
328 return MCSubtargetInfoCtorFn(Triple, CPU, Features);
331 /// createTargetMachine - Create a target specific machine implementation
332 /// for the specified \p Triple.
334 /// \param Triple This argument is used to determine the target machine
335 /// feature set; it should always be provided. Generally this should be
336 /// either the target triple from the module, or the target triple of the
337 /// host if that does not exist.
338 TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU,
339 StringRef Features, const TargetOptions &Options,
340 Reloc::Model RM = Reloc::Default,
341 CodeModel::Model CM = CodeModel::Default,
342 CodeGenOpt::Level OL = CodeGenOpt::Default) const {
343 if (!TargetMachineCtorFn)
345 return TargetMachineCtorFn(*this, Triple, CPU, Features, Options,
349 /// createMCAsmBackend - Create a target specific assembly parser.
351 /// \param Triple The target triple string.
352 MCAsmBackend *createMCAsmBackend(const MCRegisterInfo &MRI,
353 StringRef Triple, StringRef CPU) const {
354 if (!MCAsmBackendCtorFn)
356 return MCAsmBackendCtorFn(*this, MRI, Triple, CPU);
359 /// createMCAsmParser - Create a target specific assembly parser.
361 /// \param Parser The target independent parser implementation to use for
362 /// parsing and lexing.
363 MCTargetAsmParser *createMCAsmParser(
364 MCSubtargetInfo &STI,
366 const MCInstrInfo &MII,
367 const MCTargetOptions &Options) const {
368 if (!MCAsmParserCtorFn)
370 return MCAsmParserCtorFn(STI, Parser, MII, Options);
373 /// createAsmPrinter - Create a target specific assembly printer pass. This
374 /// takes ownership of the MCStreamer object.
375 AsmPrinter *createAsmPrinter(TargetMachine &TM,
376 std::unique_ptr<MCStreamer> &&Streamer) const {
377 if (!AsmPrinterCtorFn)
379 return AsmPrinterCtorFn(TM, std::move(Streamer));
382 MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI,
383 MCContext &Ctx) const {
384 if (!MCDisassemblerCtorFn)
386 return MCDisassemblerCtorFn(*this, STI, Ctx);
389 MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
390 const MCAsmInfo &MAI,
391 const MCInstrInfo &MII,
392 const MCRegisterInfo &MRI,
393 const MCSubtargetInfo &STI) const {
394 if (!MCInstPrinterCtorFn)
396 return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, MII, MRI, STI);
400 /// createMCCodeEmitter - Create a target specific code emitter.
401 MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
402 const MCRegisterInfo &MRI,
403 MCContext &Ctx) const {
404 if (!MCCodeEmitterCtorFn)
406 return MCCodeEmitterCtorFn(II, MRI, Ctx);
409 /// createMCObjectStreamer - Create a target specific MCStreamer.
411 /// \param TT The target triple.
412 /// \param Ctx The target context.
413 /// \param TAB The target assembler backend object. Takes ownership.
414 /// \param OS The stream object.
415 /// \param Emitter The target independent assembler object.Takes ownership.
416 /// \param RelaxAll Relax all fixups?
417 MCStreamer *createMCObjectStreamer(StringRef TT, MCContext &Ctx,
418 MCAsmBackend &TAB, raw_ostream &OS,
419 MCCodeEmitter *Emitter,
420 const MCSubtargetInfo &STI,
421 bool RelaxAll) const {
422 if (!MCObjectStreamerCtorFn)
424 return MCObjectStreamerCtorFn(*this, TT, Ctx, TAB, OS, Emitter, STI,
428 MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
429 bool IsVerboseAsm, bool UseDwarfDirectory,
430 MCInstPrinter *InstPrint, MCCodeEmitter *CE,
431 MCAsmBackend *TAB, bool ShowInst) const {
433 llvm::createAsmStreamer(Ctx, OS, IsVerboseAsm, UseDwarfDirectory,
434 InstPrint, CE, TAB, ShowInst);
435 createAsmTargetStreamer(*S, OS, InstPrint, IsVerboseAsm);
439 MCTargetStreamer *createAsmTargetStreamer(MCStreamer &S,
440 formatted_raw_ostream &OS,
441 MCInstPrinter *InstPrint,
442 bool IsVerboseAsm) const {
443 if (AsmTargetStreamerCtorFn)
444 return AsmTargetStreamerCtorFn(S, OS, InstPrint, IsVerboseAsm);
448 MCStreamer *createNullStreamer(MCContext &Ctx) const {
449 MCStreamer *S = llvm::createNullStreamer(Ctx);
450 createNullTargetStreamer(*S);
454 MCTargetStreamer *createNullTargetStreamer(MCStreamer &S) const {
455 if (NullTargetStreamerCtorFn)
456 return NullTargetStreamerCtorFn(S);
460 /// createMCRelocationInfo - Create a target specific MCRelocationInfo.
462 /// \param TT The target triple.
463 /// \param Ctx The target context.
465 createMCRelocationInfo(StringRef TT, MCContext &Ctx) const {
466 MCRelocationInfoCtorTy Fn = MCRelocationInfoCtorFn
467 ? MCRelocationInfoCtorFn
468 : llvm::createMCRelocationInfo;
472 /// createMCSymbolizer - Create a target specific MCSymbolizer.
474 /// \param TT The target triple.
475 /// \param GetOpInfo The function to get the symbolic information for operands.
476 /// \param SymbolLookUp The function to lookup a symbol name.
477 /// \param DisInfo The pointer to the block of symbolic information for above call
479 /// \param Ctx The target context.
480 /// \param RelInfo The relocation information for this target. Takes ownership.
482 createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
483 LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo,
485 std::unique_ptr<MCRelocationInfo> &&RelInfo) const {
486 MCSymbolizerCtorTy Fn =
487 MCSymbolizerCtorFn ? MCSymbolizerCtorFn : llvm::createMCSymbolizer;
488 return Fn(TT, GetOpInfo, SymbolLookUp, DisInfo, Ctx, std::move(RelInfo));
494 /// TargetRegistry - Generic interface to target specific features.
495 struct TargetRegistry {
497 const Target *Current;
498 explicit iterator(Target *T) : Current(T) {}
499 friend struct TargetRegistry;
501 iterator() : Current(nullptr) {}
503 bool operator==(const iterator &x) const {
504 return Current == x.Current;
506 bool operator!=(const iterator &x) const {
507 return !operator==(x);
510 // Iterator traversal: forward iteration only
511 iterator &operator++() { // Preincrement
512 assert(Current && "Cannot increment end iterator!");
513 Current = Current->getNext();
516 iterator operator++(int) { // Postincrement
517 iterator tmp = *this;
522 const Target &operator*() const {
523 assert(Current && "Cannot dereference end iterator!");
527 const Target *operator->() const {
532 /// printRegisteredTargetsForVersion - Print the registered targets
533 /// appropriately for inclusion in a tool's version output.
534 static void printRegisteredTargetsForVersion();
536 /// @name Registry Access
539 static iterator begin();
541 static iterator end() { return iterator(); }
543 /// lookupTarget - Lookup a target based on a target triple.
545 /// \param Triple - The triple to use for finding a target.
546 /// \param Error - On failure, an error string describing why no target was
548 static const Target *lookupTarget(const std::string &Triple,
551 /// lookupTarget - Lookup a target based on an architecture name
552 /// and a target triple. If the architecture name is non-empty,
553 /// then the lookup is done by architecture. Otherwise, the target
556 /// \param ArchName - The architecture to use for finding a target.
557 /// \param TheTriple - The triple to use for finding a target. The
558 /// triple is updated with canonical architecture name if a lookup
559 /// by architecture is done.
560 /// \param Error - On failure, an error string describing why no target was
562 static const Target *lookupTarget(const std::string &ArchName,
567 /// @name Target Registration
570 /// RegisterTarget - Register the given target. Attempts to register a
571 /// target which has already been registered will be ignored.
573 /// Clients are responsible for ensuring that registration doesn't occur
574 /// while another thread is attempting to access the registry. Typically
575 /// this is done by initializing all targets at program startup.
577 /// @param T - The target being registered.
578 /// @param Name - The target name. This should be a static string.
579 /// @param ShortDesc - A short target description. This should be a static
581 /// @param ArchMatchFn - The arch match checking function for this target.
582 /// @param HasJIT - Whether the target supports JIT code
584 static void RegisterTarget(Target &T,
586 const char *ShortDesc,
587 Target::ArchMatchFnTy ArchMatchFn,
588 bool HasJIT = false);
590 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
593 /// Clients are responsible for ensuring that registration doesn't occur
594 /// while another thread is attempting to access the registry. Typically
595 /// this is done by initializing all targets at program startup.
597 /// @param T - The target being registered.
598 /// @param Fn - A function to construct a MCAsmInfo for the target.
599 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
600 T.MCAsmInfoCtorFn = Fn;
603 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
606 /// Clients are responsible for ensuring that registration doesn't occur
607 /// while another thread is attempting to access the registry. Typically
608 /// this is done by initializing all targets at program startup.
610 /// @param T - The target being registered.
611 /// @param Fn - A function to construct a MCCodeGenInfo for the target.
612 static void RegisterMCCodeGenInfo(Target &T,
613 Target::MCCodeGenInfoCtorFnTy Fn) {
614 T.MCCodeGenInfoCtorFn = Fn;
617 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
620 /// Clients are responsible for ensuring that registration doesn't occur
621 /// while another thread is attempting to access the registry. Typically
622 /// this is done by initializing all targets at program startup.
624 /// @param T - The target being registered.
625 /// @param Fn - A function to construct a MCInstrInfo for the target.
626 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
627 T.MCInstrInfoCtorFn = Fn;
630 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
631 /// the given target.
632 static void RegisterMCInstrAnalysis(Target &T,
633 Target::MCInstrAnalysisCtorFnTy Fn) {
634 T.MCInstrAnalysisCtorFn = Fn;
637 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
640 /// Clients are responsible for ensuring that registration doesn't occur
641 /// while another thread is attempting to access the registry. Typically
642 /// this is done by initializing all targets at program startup.
644 /// @param T - The target being registered.
645 /// @param Fn - A function to construct a MCRegisterInfo for the target.
646 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
647 T.MCRegInfoCtorFn = Fn;
650 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
651 /// the given target.
653 /// Clients are responsible for ensuring that registration doesn't occur
654 /// while another thread is attempting to access the registry. Typically
655 /// this is done by initializing all targets at program startup.
657 /// @param T - The target being registered.
658 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
659 static void RegisterMCSubtargetInfo(Target &T,
660 Target::MCSubtargetInfoCtorFnTy Fn) {
661 T.MCSubtargetInfoCtorFn = Fn;
664 /// RegisterTargetMachine - Register a TargetMachine implementation for the
667 /// Clients are responsible for ensuring that registration doesn't occur
668 /// while another thread is attempting to access the registry. Typically
669 /// this is done by initializing all targets at program startup.
671 /// @param T - The target being registered.
672 /// @param Fn - A function to construct a TargetMachine for the target.
673 static void RegisterTargetMachine(Target &T,
674 Target::TargetMachineCtorTy Fn) {
675 T.TargetMachineCtorFn = Fn;
678 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
681 /// Clients are responsible for ensuring that registration doesn't occur
682 /// while another thread is attempting to access the registry. Typically
683 /// this is done by initializing all targets at program startup.
685 /// @param T - The target being registered.
686 /// @param Fn - A function to construct an AsmBackend for the target.
687 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
688 T.MCAsmBackendCtorFn = Fn;
691 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
692 /// the given target.
694 /// Clients are responsible for ensuring that registration doesn't occur
695 /// while another thread is attempting to access the registry. Typically
696 /// this is done by initializing all targets at program startup.
698 /// @param T - The target being registered.
699 /// @param Fn - A function to construct an MCTargetAsmParser for the target.
700 static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
701 T.MCAsmParserCtorFn = Fn;
704 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
707 /// Clients are responsible for ensuring that registration doesn't occur
708 /// while another thread is attempting to access the registry. Typically
709 /// this is done by initializing all targets at program startup.
711 /// @param T - The target being registered.
712 /// @param Fn - A function to construct an AsmPrinter for the target.
713 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
714 T.AsmPrinterCtorFn = Fn;
717 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
718 /// the given target.
720 /// Clients are responsible for ensuring that registration doesn't occur
721 /// while another thread is attempting to access the registry. Typically
722 /// this is done by initializing all targets at program startup.
724 /// @param T - The target being registered.
725 /// @param Fn - A function to construct an MCDisassembler for the target.
726 static void RegisterMCDisassembler(Target &T,
727 Target::MCDisassemblerCtorTy Fn) {
728 T.MCDisassemblerCtorFn = Fn;
731 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
734 /// Clients are responsible for ensuring that registration doesn't occur
735 /// while another thread is attempting to access the registry. Typically
736 /// this is done by initializing all targets at program startup.
738 /// @param T - The target being registered.
739 /// @param Fn - A function to construct an MCInstPrinter for the target.
740 static void RegisterMCInstPrinter(Target &T,
741 Target::MCInstPrinterCtorTy Fn) {
742 T.MCInstPrinterCtorFn = Fn;
745 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
748 /// Clients are responsible for ensuring that registration doesn't occur
749 /// while another thread is attempting to access the registry. Typically
750 /// this is done by initializing all targets at program startup.
752 /// @param T - The target being registered.
753 /// @param Fn - A function to construct an MCCodeEmitter for the target.
754 static void RegisterMCCodeEmitter(Target &T,
755 Target::MCCodeEmitterCtorTy Fn) {
756 T.MCCodeEmitterCtorFn = Fn;
759 /// RegisterMCObjectStreamer - Register a object code MCStreamer
760 /// implementation for the given target.
762 /// Clients are responsible for ensuring that registration doesn't occur
763 /// while another thread is attempting to access the registry. Typically
764 /// this is done by initializing all targets at program startup.
766 /// @param T - The target being registered.
767 /// @param Fn - A function to construct an MCStreamer for the target.
768 static void RegisterMCObjectStreamer(Target &T,
769 Target::MCObjectStreamerCtorTy Fn) {
770 T.MCObjectStreamerCtorFn = Fn;
774 RegisterNullTargetStreamer(Target &T, Target::NullTargetStreamerCtorTy Fn) {
775 T.NullTargetStreamerCtorFn = Fn;
778 static void RegisterAsmTargetStreamer(Target &T,
779 Target::AsmTargetStreamerCtorTy Fn) {
780 T.AsmTargetStreamerCtorFn = Fn;
783 /// RegisterMCRelocationInfo - Register an MCRelocationInfo
784 /// implementation for the given target.
786 /// Clients are responsible for ensuring that registration doesn't occur
787 /// while another thread is attempting to access the registry. Typically
788 /// this is done by initializing all targets at program startup.
790 /// @param T - The target being registered.
791 /// @param Fn - A function to construct an MCRelocationInfo for the target.
792 static void RegisterMCRelocationInfo(Target &T,
793 Target::MCRelocationInfoCtorTy Fn) {
794 T.MCRelocationInfoCtorFn = Fn;
797 /// RegisterMCSymbolizer - Register an MCSymbolizer
798 /// implementation for the given target.
800 /// Clients are responsible for ensuring that registration doesn't occur
801 /// while another thread is attempting to access the registry. Typically
802 /// this is done by initializing all targets at program startup.
804 /// @param T - The target being registered.
805 /// @param Fn - A function to construct an MCSymbolizer for the target.
806 static void RegisterMCSymbolizer(Target &T,
807 Target::MCSymbolizerCtorTy Fn) {
808 T.MCSymbolizerCtorFn = Fn;
815 //===--------------------------------------------------------------------===//
817 /// RegisterTarget - Helper template for registering a target, for use in the
818 /// target's initialization function. Usage:
821 /// Target TheFooTarget; // The global target instance.
823 /// extern "C" void LLVMInitializeFooTargetInfo() {
824 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
826 template<Triple::ArchType TargetArchType = Triple::UnknownArch,
828 struct RegisterTarget {
829 RegisterTarget(Target &T, const char *Name, const char *Desc) {
830 TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch, HasJIT);
833 static bool getArchMatch(Triple::ArchType Arch) {
834 return Arch == TargetArchType;
838 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
839 /// implementation. This invokes the static "Create" method on the class to
840 /// actually do the construction. Usage:
842 /// extern "C" void LLVMInitializeFooTarget() {
843 /// extern Target TheFooTarget;
844 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
846 template<class MCAsmInfoImpl>
847 struct RegisterMCAsmInfo {
848 RegisterMCAsmInfo(Target &T) {
849 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
852 static MCAsmInfo *Allocator(const MCRegisterInfo &/*MRI*/, StringRef TT) {
853 return new MCAsmInfoImpl(TT);
858 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
859 /// implementation. This invokes the specified function to do the
860 /// construction. Usage:
862 /// extern "C" void LLVMInitializeFooTarget() {
863 /// extern Target TheFooTarget;
864 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
866 struct RegisterMCAsmInfoFn {
867 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
868 TargetRegistry::RegisterMCAsmInfo(T, Fn);
872 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
873 /// implementation. This invokes the static "Create" method on the class
874 /// to actually do the construction. Usage:
876 /// extern "C" void LLVMInitializeFooTarget() {
877 /// extern Target TheFooTarget;
878 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
880 template<class MCCodeGenInfoImpl>
881 struct RegisterMCCodeGenInfo {
882 RegisterMCCodeGenInfo(Target &T) {
883 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
886 static MCCodeGenInfo *Allocator(StringRef /*TT*/, Reloc::Model /*RM*/,
887 CodeModel::Model /*CM*/,
888 CodeGenOpt::Level /*OL*/) {
889 return new MCCodeGenInfoImpl();
893 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
894 /// info implementation. This invokes the specified function to do the
895 /// construction. Usage:
897 /// extern "C" void LLVMInitializeFooTarget() {
898 /// extern Target TheFooTarget;
899 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
901 struct RegisterMCCodeGenInfoFn {
902 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
903 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
907 /// RegisterMCInstrInfo - Helper template for registering a target instruction
908 /// info implementation. This invokes the static "Create" method on the class
909 /// to actually do the construction. Usage:
911 /// extern "C" void LLVMInitializeFooTarget() {
912 /// extern Target TheFooTarget;
913 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
915 template<class MCInstrInfoImpl>
916 struct RegisterMCInstrInfo {
917 RegisterMCInstrInfo(Target &T) {
918 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
921 static MCInstrInfo *Allocator() {
922 return new MCInstrInfoImpl();
926 /// RegisterMCInstrInfoFn - Helper template for registering a target
927 /// instruction info implementation. This invokes the specified function to
928 /// do the construction. Usage:
930 /// extern "C" void LLVMInitializeFooTarget() {
931 /// extern Target TheFooTarget;
932 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
934 struct RegisterMCInstrInfoFn {
935 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
936 TargetRegistry::RegisterMCInstrInfo(T, Fn);
940 /// RegisterMCInstrAnalysis - Helper template for registering a target
941 /// instruction analyzer implementation. This invokes the static "Create"
942 /// method on the class to actually do the construction. Usage:
944 /// extern "C" void LLVMInitializeFooTarget() {
945 /// extern Target TheFooTarget;
946 /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
948 template<class MCInstrAnalysisImpl>
949 struct RegisterMCInstrAnalysis {
950 RegisterMCInstrAnalysis(Target &T) {
951 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
954 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
955 return new MCInstrAnalysisImpl(Info);
959 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
960 /// instruction analyzer implementation. This invokes the specified function
961 /// to do the construction. Usage:
963 /// extern "C" void LLVMInitializeFooTarget() {
964 /// extern Target TheFooTarget;
965 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
967 struct RegisterMCInstrAnalysisFn {
968 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
969 TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
973 /// RegisterMCRegInfo - Helper template for registering a target register info
974 /// implementation. This invokes the static "Create" method on the class to
975 /// actually do the construction. Usage:
977 /// extern "C" void LLVMInitializeFooTarget() {
978 /// extern Target TheFooTarget;
979 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
981 template<class MCRegisterInfoImpl>
982 struct RegisterMCRegInfo {
983 RegisterMCRegInfo(Target &T) {
984 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
987 static MCRegisterInfo *Allocator(StringRef /*TT*/) {
988 return new MCRegisterInfoImpl();
992 /// RegisterMCRegInfoFn - Helper template for registering a target register
993 /// info implementation. This invokes the specified function to do the
994 /// construction. Usage:
996 /// extern "C" void LLVMInitializeFooTarget() {
997 /// extern Target TheFooTarget;
998 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
1000 struct RegisterMCRegInfoFn {
1001 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
1002 TargetRegistry::RegisterMCRegInfo(T, Fn);
1006 /// RegisterMCSubtargetInfo - Helper template for registering a target
1007 /// subtarget info implementation. This invokes the static "Create" method
1008 /// on the class to actually do the construction. Usage:
1010 /// extern "C" void LLVMInitializeFooTarget() {
1011 /// extern Target TheFooTarget;
1012 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
1014 template<class MCSubtargetInfoImpl>
1015 struct RegisterMCSubtargetInfo {
1016 RegisterMCSubtargetInfo(Target &T) {
1017 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
1020 static MCSubtargetInfo *Allocator(StringRef /*TT*/, StringRef /*CPU*/,
1022 return new MCSubtargetInfoImpl();
1026 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
1027 /// subtarget info implementation. This invokes the specified function to
1028 /// do the construction. Usage:
1030 /// extern "C" void LLVMInitializeFooTarget() {
1031 /// extern Target TheFooTarget;
1032 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1034 struct RegisterMCSubtargetInfoFn {
1035 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
1036 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
1040 /// RegisterTargetMachine - Helper template for registering a target machine
1041 /// implementation, for use in the target machine initialization
1042 /// function. Usage:
1044 /// extern "C" void LLVMInitializeFooTarget() {
1045 /// extern Target TheFooTarget;
1046 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1048 template<class TargetMachineImpl>
1049 struct RegisterTargetMachine {
1050 RegisterTargetMachine(Target &T) {
1051 TargetRegistry::RegisterTargetMachine(T, &Allocator);
1055 static TargetMachine *Allocator(const Target &T, StringRef TT,
1056 StringRef CPU, StringRef FS,
1057 const TargetOptions &Options,
1059 CodeModel::Model CM,
1060 CodeGenOpt::Level OL) {
1061 return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
1065 /// RegisterMCAsmBackend - Helper template for registering a target specific
1066 /// assembler backend. Usage:
1068 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1069 /// extern Target TheFooTarget;
1070 /// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1072 template<class MCAsmBackendImpl>
1073 struct RegisterMCAsmBackend {
1074 RegisterMCAsmBackend(Target &T) {
1075 TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1079 static MCAsmBackend *Allocator(const Target &T,
1080 const MCRegisterInfo &MRI,
1081 StringRef Triple, StringRef CPU) {
1082 return new MCAsmBackendImpl(T, MRI, Triple, CPU);
1086 /// RegisterMCAsmParser - Helper template for registering a target specific
1087 /// assembly parser, for use in the target machine initialization
1088 /// function. Usage:
1090 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1091 /// extern Target TheFooTarget;
1092 /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1094 template<class MCAsmParserImpl>
1095 struct RegisterMCAsmParser {
1096 RegisterMCAsmParser(Target &T) {
1097 TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1101 static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P,
1102 const MCInstrInfo &MII,
1103 const MCTargetOptions &Options) {
1104 return new MCAsmParserImpl(STI, P, MII, Options);
1108 /// RegisterAsmPrinter - Helper template for registering a target specific
1109 /// assembly printer, for use in the target machine initialization
1110 /// function. Usage:
1112 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1113 /// extern Target TheFooTarget;
1114 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1116 template<class AsmPrinterImpl>
1117 struct RegisterAsmPrinter {
1118 RegisterAsmPrinter(Target &T) {
1119 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1123 static AsmPrinter *Allocator(TargetMachine &TM,
1124 std::unique_ptr<MCStreamer> &&Streamer) {
1125 return new AsmPrinterImpl(TM, std::move(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 MCContext & /*Ctx*/) {
1147 return new MCCodeEmitterImpl();