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 Triple &T, MCContext &Ctx, MCAsmBackend &TAB, raw_ostream &OS,
131 MCCodeEmitter *Emitter, const MCSubtargetInfo &STI, bool RelaxAll);
132 typedef MCTargetStreamer *(*NullTargetStreamerCtorTy)(MCStreamer &S);
133 typedef MCTargetStreamer *(*AsmTargetStreamerCtorTy)(
134 MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *InstPrint,
136 typedef MCRelocationInfo *(*MCRelocationInfoCtorTy)(StringRef TT,
138 typedef MCSymbolizer *(*MCSymbolizerCtorTy)(
139 StringRef TT, LLVMOpInfoCallback GetOpInfo,
140 LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo, MCContext *Ctx,
141 std::unique_ptr<MCRelocationInfo> &&RelInfo);
144 /// Next - The next registered target in the linked list, maintained by the
148 /// The target function for checking if an architecture is supported.
149 ArchMatchFnTy ArchMatchFn;
151 /// Name - The target name.
154 /// ShortDesc - A short description of the target.
155 const char *ShortDesc;
157 /// HasJIT - Whether this target supports the JIT.
160 /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
162 MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
164 /// MCCodeGenInfoCtorFn - Constructor function for this target's
165 /// MCCodeGenInfo, if registered.
166 MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn;
168 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
170 MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
172 /// MCInstrAnalysisCtorFn - Constructor function for this target's
173 /// MCInstrAnalysis, if registered.
174 MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
176 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
178 MCRegInfoCtorFnTy MCRegInfoCtorFn;
180 /// MCSubtargetInfoCtorFn - Constructor function for this target's
181 /// MCSubtargetInfo, if registered.
182 MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
184 /// TargetMachineCtorFn - Construction function for this target's
185 /// TargetMachine, if registered.
186 TargetMachineCtorTy TargetMachineCtorFn;
188 /// MCAsmBackendCtorFn - Construction function for this target's
189 /// MCAsmBackend, if registered.
190 MCAsmBackendCtorTy MCAsmBackendCtorFn;
192 /// MCAsmParserCtorFn - Construction function for this target's
193 /// MCTargetAsmParser, if registered.
194 MCAsmParserCtorTy MCAsmParserCtorFn;
196 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
198 AsmPrinterCtorTy AsmPrinterCtorFn;
200 /// MCDisassemblerCtorFn - Construction function for this target's
201 /// MCDisassembler, if registered.
202 MCDisassemblerCtorTy MCDisassemblerCtorFn;
204 /// MCInstPrinterCtorFn - Construction function for this target's
205 /// MCInstPrinter, if registered.
206 MCInstPrinterCtorTy MCInstPrinterCtorFn;
208 /// MCCodeEmitterCtorFn - Construction function for this target's
209 /// CodeEmitter, if registered.
210 MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
212 /// MCObjectStreamerCtorFn - Construction function for this target's
213 /// MCObjectStreamer, if registered.
214 MCObjectStreamerCtorTy MCObjectStreamerCtorFn;
216 /// Construction function for this target's null TargetStreamer, if
217 /// registered (default = nullptr).
218 NullTargetStreamerCtorTy NullTargetStreamerCtorFn;
220 /// Construction function for this target's asm TargetStreamer, if
221 /// registered (default = nullptr).
222 AsmTargetStreamerCtorTy AsmTargetStreamerCtorFn;
224 /// MCRelocationInfoCtorFn - Construction function for this target's
225 /// MCRelocationInfo, if registered (default = llvm::createMCRelocationInfo)
226 MCRelocationInfoCtorTy MCRelocationInfoCtorFn;
228 /// MCSymbolizerCtorFn - Construction function for this target's
229 /// MCSymbolizer, if registered (default = llvm::createMCSymbolizer)
230 MCSymbolizerCtorTy MCSymbolizerCtorFn;
234 : NullTargetStreamerCtorFn(nullptr), AsmTargetStreamerCtorFn(nullptr),
235 MCRelocationInfoCtorFn(nullptr), MCSymbolizerCtorFn(nullptr) {}
237 /// @name Target Information
240 // getNext - Return the next registered target.
241 const Target *getNext() const { return Next; }
243 /// getName - Get the target name.
244 const char *getName() const { return Name; }
246 /// getShortDescription - Get a short description of the target.
247 const char *getShortDescription() const { return ShortDesc; }
250 /// @name Feature Predicates
253 /// hasJIT - Check if this targets supports the just-in-time compilation.
254 bool hasJIT() const { return HasJIT; }
256 /// hasTargetMachine - Check if this target supports code generation.
257 bool hasTargetMachine() const { return TargetMachineCtorFn != nullptr; }
259 /// hasMCAsmBackend - Check if this target supports .o generation.
260 bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != nullptr; }
263 /// @name Feature Constructors
266 /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
269 /// \param Triple This argument is used to determine the target machine
270 /// feature set; it should always be provided. Generally this should be
271 /// either the target triple from the module, or the target triple of the
272 /// host if that does not exist.
273 MCAsmInfo *createMCAsmInfo(const MCRegisterInfo &MRI,
274 StringRef Triple) const {
275 if (!MCAsmInfoCtorFn)
277 return MCAsmInfoCtorFn(MRI, Triple);
280 /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
282 MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model RM,
284 CodeGenOpt::Level OL) const {
285 if (!MCCodeGenInfoCtorFn)
287 return MCCodeGenInfoCtorFn(Triple, RM, CM, OL);
290 /// createMCInstrInfo - Create a MCInstrInfo implementation.
292 MCInstrInfo *createMCInstrInfo() const {
293 if (!MCInstrInfoCtorFn)
295 return MCInstrInfoCtorFn();
298 /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
300 MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
301 if (!MCInstrAnalysisCtorFn)
303 return MCInstrAnalysisCtorFn(Info);
306 /// createMCRegInfo - Create a MCRegisterInfo implementation.
308 MCRegisterInfo *createMCRegInfo(StringRef Triple) const {
309 if (!MCRegInfoCtorFn)
311 return MCRegInfoCtorFn(Triple);
314 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
316 /// \param Triple This argument is used to determine the target machine
317 /// feature set; it should always be provided. Generally this should be
318 /// either the target triple from the module, or the target triple of the
319 /// host if that does not exist.
320 /// \param CPU This specifies the name of the target CPU.
321 /// \param Features This specifies the string representation of the
322 /// additional target features.
323 MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU,
324 StringRef Features) const {
325 if (!MCSubtargetInfoCtorFn)
327 return MCSubtargetInfoCtorFn(Triple, CPU, Features);
330 /// createTargetMachine - Create a target specific machine implementation
331 /// for the specified \p Triple.
333 /// \param Triple This argument is used to determine the target machine
334 /// feature set; it should always be provided. Generally this should be
335 /// either the target triple from the module, or the target triple of the
336 /// host if that does not exist.
337 TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU,
338 StringRef Features, const TargetOptions &Options,
339 Reloc::Model RM = Reloc::Default,
340 CodeModel::Model CM = CodeModel::Default,
341 CodeGenOpt::Level OL = CodeGenOpt::Default) const {
342 if (!TargetMachineCtorFn)
344 return TargetMachineCtorFn(*this, Triple, CPU, Features, Options,
348 /// createMCAsmBackend - Create a target specific assembly parser.
350 /// \param Triple The target triple string.
351 MCAsmBackend *createMCAsmBackend(const MCRegisterInfo &MRI,
352 StringRef Triple, StringRef CPU) const {
353 if (!MCAsmBackendCtorFn)
355 return MCAsmBackendCtorFn(*this, MRI, Triple, CPU);
358 /// createMCAsmParser - Create a target specific assembly parser.
360 /// \param Parser The target independent parser implementation to use for
361 /// parsing and lexing.
362 MCTargetAsmParser *createMCAsmParser(
363 MCSubtargetInfo &STI,
365 const MCInstrInfo &MII,
366 const MCTargetOptions &Options) const {
367 if (!MCAsmParserCtorFn)
369 return MCAsmParserCtorFn(STI, Parser, MII, Options);
372 /// createAsmPrinter - Create a target specific assembly printer pass. This
373 /// takes ownership of the MCStreamer object.
374 AsmPrinter *createAsmPrinter(TargetMachine &TM,
375 std::unique_ptr<MCStreamer> &&Streamer) const {
376 if (!AsmPrinterCtorFn)
378 return AsmPrinterCtorFn(TM, std::move(Streamer));
381 MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI,
382 MCContext &Ctx) const {
383 if (!MCDisassemblerCtorFn)
385 return MCDisassemblerCtorFn(*this, STI, Ctx);
388 MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
389 const MCAsmInfo &MAI,
390 const MCInstrInfo &MII,
391 const MCRegisterInfo &MRI,
392 const MCSubtargetInfo &STI) const {
393 if (!MCInstPrinterCtorFn)
395 return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, MII, MRI, STI);
399 /// createMCCodeEmitter - Create a target specific code emitter.
400 MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
401 const MCRegisterInfo &MRI,
402 MCContext &Ctx) const {
403 if (!MCCodeEmitterCtorFn)
405 return MCCodeEmitterCtorFn(II, MRI, Ctx);
408 /// Create a target specific MCStreamer.
410 /// \param T The target triple.
411 /// \param Ctx The target context.
412 /// \param TAB The target assembler backend object. Takes ownership.
413 /// \param OS The stream object.
414 /// \param Emitter The target independent assembler object.Takes ownership.
415 /// \param RelaxAll Relax all fixups?
416 MCStreamer *createMCObjectStreamer(const Triple &T, MCContext &Ctx,
417 MCAsmBackend &TAB, raw_ostream &OS,
418 MCCodeEmitter *Emitter,
419 const MCSubtargetInfo &STI,
420 bool RelaxAll) const {
421 if (!MCObjectStreamerCtorFn)
423 return MCObjectStreamerCtorFn(T, Ctx, TAB, OS, Emitter, STI, RelaxAll);
426 MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
427 bool IsVerboseAsm, bool UseDwarfDirectory,
428 MCInstPrinter *InstPrint, MCCodeEmitter *CE,
429 MCAsmBackend *TAB, bool ShowInst) const {
431 llvm::createAsmStreamer(Ctx, OS, IsVerboseAsm, UseDwarfDirectory,
432 InstPrint, CE, TAB, ShowInst);
433 createAsmTargetStreamer(*S, OS, InstPrint, IsVerboseAsm);
437 MCTargetStreamer *createAsmTargetStreamer(MCStreamer &S,
438 formatted_raw_ostream &OS,
439 MCInstPrinter *InstPrint,
440 bool IsVerboseAsm) const {
441 if (AsmTargetStreamerCtorFn)
442 return AsmTargetStreamerCtorFn(S, OS, InstPrint, IsVerboseAsm);
446 MCStreamer *createNullStreamer(MCContext &Ctx) const {
447 MCStreamer *S = llvm::createNullStreamer(Ctx);
448 createNullTargetStreamer(*S);
452 MCTargetStreamer *createNullTargetStreamer(MCStreamer &S) const {
453 if (NullTargetStreamerCtorFn)
454 return NullTargetStreamerCtorFn(S);
458 /// createMCRelocationInfo - Create a target specific MCRelocationInfo.
460 /// \param TT The target triple.
461 /// \param Ctx The target context.
463 createMCRelocationInfo(StringRef TT, MCContext &Ctx) const {
464 MCRelocationInfoCtorTy Fn = MCRelocationInfoCtorFn
465 ? MCRelocationInfoCtorFn
466 : llvm::createMCRelocationInfo;
470 /// createMCSymbolizer - Create a target specific MCSymbolizer.
472 /// \param TT The target triple.
473 /// \param GetOpInfo The function to get the symbolic information for operands.
474 /// \param SymbolLookUp The function to lookup a symbol name.
475 /// \param DisInfo The pointer to the block of symbolic information for above call
477 /// \param Ctx The target context.
478 /// \param RelInfo The relocation information for this target. Takes ownership.
480 createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
481 LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo,
483 std::unique_ptr<MCRelocationInfo> &&RelInfo) const {
484 MCSymbolizerCtorTy Fn =
485 MCSymbolizerCtorFn ? MCSymbolizerCtorFn : llvm::createMCSymbolizer;
486 return Fn(TT, GetOpInfo, SymbolLookUp, DisInfo, Ctx, std::move(RelInfo));
492 /// TargetRegistry - Generic interface to target specific features.
493 struct TargetRegistry {
495 const Target *Current;
496 explicit iterator(Target *T) : Current(T) {}
497 friend struct TargetRegistry;
499 iterator() : Current(nullptr) {}
501 bool operator==(const iterator &x) const {
502 return Current == x.Current;
504 bool operator!=(const iterator &x) const {
505 return !operator==(x);
508 // Iterator traversal: forward iteration only
509 iterator &operator++() { // Preincrement
510 assert(Current && "Cannot increment end iterator!");
511 Current = Current->getNext();
514 iterator operator++(int) { // Postincrement
515 iterator tmp = *this;
520 const Target &operator*() const {
521 assert(Current && "Cannot dereference end iterator!");
525 const Target *operator->() const {
530 /// printRegisteredTargetsForVersion - Print the registered targets
531 /// appropriately for inclusion in a tool's version output.
532 static void printRegisteredTargetsForVersion();
534 /// @name Registry Access
537 static iterator begin();
539 static iterator end() { return iterator(); }
541 /// lookupTarget - Lookup a target based on a target triple.
543 /// \param Triple - The triple to use for finding a target.
544 /// \param Error - On failure, an error string describing why no target was
546 static const Target *lookupTarget(const std::string &Triple,
549 /// lookupTarget - Lookup a target based on an architecture name
550 /// and a target triple. If the architecture name is non-empty,
551 /// then the lookup is done by architecture. Otherwise, the target
554 /// \param ArchName - The architecture to use for finding a target.
555 /// \param TheTriple - The triple to use for finding a target. The
556 /// triple is updated with canonical architecture name if a lookup
557 /// by architecture is done.
558 /// \param Error - On failure, an error string describing why no target was
560 static const Target *lookupTarget(const std::string &ArchName,
565 /// @name Target Registration
568 /// RegisterTarget - Register the given target. Attempts to register a
569 /// target which has already been registered will be ignored.
571 /// Clients are responsible for ensuring that registration doesn't occur
572 /// while another thread is attempting to access the registry. Typically
573 /// this is done by initializing all targets at program startup.
575 /// @param T - The target being registered.
576 /// @param Name - The target name. This should be a static string.
577 /// @param ShortDesc - A short target description. This should be a static
579 /// @param ArchMatchFn - The arch match checking function for this target.
580 /// @param HasJIT - Whether the target supports JIT code
582 static void RegisterTarget(Target &T,
584 const char *ShortDesc,
585 Target::ArchMatchFnTy ArchMatchFn,
586 bool HasJIT = false);
588 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
591 /// Clients are responsible for ensuring that registration doesn't occur
592 /// while another thread is attempting to access the registry. Typically
593 /// this is done by initializing all targets at program startup.
595 /// @param T - The target being registered.
596 /// @param Fn - A function to construct a MCAsmInfo for the target.
597 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
598 T.MCAsmInfoCtorFn = Fn;
601 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
604 /// Clients are responsible for ensuring that registration doesn't occur
605 /// while another thread is attempting to access the registry. Typically
606 /// this is done by initializing all targets at program startup.
608 /// @param T - The target being registered.
609 /// @param Fn - A function to construct a MCCodeGenInfo for the target.
610 static void RegisterMCCodeGenInfo(Target &T,
611 Target::MCCodeGenInfoCtorFnTy Fn) {
612 T.MCCodeGenInfoCtorFn = Fn;
615 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
618 /// Clients are responsible for ensuring that registration doesn't occur
619 /// while another thread is attempting to access the registry. Typically
620 /// this is done by initializing all targets at program startup.
622 /// @param T - The target being registered.
623 /// @param Fn - A function to construct a MCInstrInfo for the target.
624 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
625 T.MCInstrInfoCtorFn = Fn;
628 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
629 /// the given target.
630 static void RegisterMCInstrAnalysis(Target &T,
631 Target::MCInstrAnalysisCtorFnTy Fn) {
632 T.MCInstrAnalysisCtorFn = Fn;
635 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
638 /// Clients are responsible for ensuring that registration doesn't occur
639 /// while another thread is attempting to access the registry. Typically
640 /// this is done by initializing all targets at program startup.
642 /// @param T - The target being registered.
643 /// @param Fn - A function to construct a MCRegisterInfo for the target.
644 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
645 T.MCRegInfoCtorFn = Fn;
648 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
649 /// the given target.
651 /// Clients are responsible for ensuring that registration doesn't occur
652 /// while another thread is attempting to access the registry. Typically
653 /// this is done by initializing all targets at program startup.
655 /// @param T - The target being registered.
656 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
657 static void RegisterMCSubtargetInfo(Target &T,
658 Target::MCSubtargetInfoCtorFnTy Fn) {
659 T.MCSubtargetInfoCtorFn = Fn;
662 /// RegisterTargetMachine - Register a TargetMachine implementation for the
665 /// Clients are responsible for ensuring that registration doesn't occur
666 /// while another thread is attempting to access the registry. Typically
667 /// this is done by initializing all targets at program startup.
669 /// @param T - The target being registered.
670 /// @param Fn - A function to construct a TargetMachine for the target.
671 static void RegisterTargetMachine(Target &T,
672 Target::TargetMachineCtorTy Fn) {
673 T.TargetMachineCtorFn = Fn;
676 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
679 /// Clients are responsible for ensuring that registration doesn't occur
680 /// while another thread is attempting to access the registry. Typically
681 /// this is done by initializing all targets at program startup.
683 /// @param T - The target being registered.
684 /// @param Fn - A function to construct an AsmBackend for the target.
685 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
686 T.MCAsmBackendCtorFn = Fn;
689 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
690 /// the given target.
692 /// Clients are responsible for ensuring that registration doesn't occur
693 /// while another thread is attempting to access the registry. Typically
694 /// this is done by initializing all targets at program startup.
696 /// @param T - The target being registered.
697 /// @param Fn - A function to construct an MCTargetAsmParser for the target.
698 static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
699 T.MCAsmParserCtorFn = Fn;
702 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
705 /// Clients are responsible for ensuring that registration doesn't occur
706 /// while another thread is attempting to access the registry. Typically
707 /// this is done by initializing all targets at program startup.
709 /// @param T - The target being registered.
710 /// @param Fn - A function to construct an AsmPrinter for the target.
711 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
712 T.AsmPrinterCtorFn = Fn;
715 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
716 /// the given target.
718 /// Clients are responsible for ensuring that registration doesn't occur
719 /// while another thread is attempting to access the registry. Typically
720 /// this is done by initializing all targets at program startup.
722 /// @param T - The target being registered.
723 /// @param Fn - A function to construct an MCDisassembler for the target.
724 static void RegisterMCDisassembler(Target &T,
725 Target::MCDisassemblerCtorTy Fn) {
726 T.MCDisassemblerCtorFn = Fn;
729 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
732 /// Clients are responsible for ensuring that registration doesn't occur
733 /// while another thread is attempting to access the registry. Typically
734 /// this is done by initializing all targets at program startup.
736 /// @param T - The target being registered.
737 /// @param Fn - A function to construct an MCInstPrinter for the target.
738 static void RegisterMCInstPrinter(Target &T,
739 Target::MCInstPrinterCtorTy Fn) {
740 T.MCInstPrinterCtorFn = Fn;
743 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
746 /// Clients are responsible for ensuring that registration doesn't occur
747 /// while another thread is attempting to access the registry. Typically
748 /// this is done by initializing all targets at program startup.
750 /// @param T - The target being registered.
751 /// @param Fn - A function to construct an MCCodeEmitter for the target.
752 static void RegisterMCCodeEmitter(Target &T,
753 Target::MCCodeEmitterCtorTy Fn) {
754 T.MCCodeEmitterCtorFn = Fn;
757 /// RegisterMCObjectStreamer - Register a object code MCStreamer
758 /// implementation for the given target.
760 /// Clients are responsible for ensuring that registration doesn't occur
761 /// while another thread is attempting to access the registry. Typically
762 /// this is done by initializing all targets at program startup.
764 /// @param T - The target being registered.
765 /// @param Fn - A function to construct an MCStreamer for the target.
766 static void RegisterMCObjectStreamer(Target &T,
767 Target::MCObjectStreamerCtorTy Fn) {
768 T.MCObjectStreamerCtorFn = Fn;
772 RegisterNullTargetStreamer(Target &T, Target::NullTargetStreamerCtorTy Fn) {
773 T.NullTargetStreamerCtorFn = Fn;
776 static void RegisterAsmTargetStreamer(Target &T,
777 Target::AsmTargetStreamerCtorTy Fn) {
778 T.AsmTargetStreamerCtorFn = Fn;
781 /// RegisterMCRelocationInfo - Register an MCRelocationInfo
782 /// implementation for the given target.
784 /// Clients are responsible for ensuring that registration doesn't occur
785 /// while another thread is attempting to access the registry. Typically
786 /// this is done by initializing all targets at program startup.
788 /// @param T - The target being registered.
789 /// @param Fn - A function to construct an MCRelocationInfo for the target.
790 static void RegisterMCRelocationInfo(Target &T,
791 Target::MCRelocationInfoCtorTy Fn) {
792 T.MCRelocationInfoCtorFn = Fn;
795 /// RegisterMCSymbolizer - Register an MCSymbolizer
796 /// implementation for the given target.
798 /// Clients are responsible for ensuring that registration doesn't occur
799 /// while another thread is attempting to access the registry. Typically
800 /// this is done by initializing all targets at program startup.
802 /// @param T - The target being registered.
803 /// @param Fn - A function to construct an MCSymbolizer for the target.
804 static void RegisterMCSymbolizer(Target &T,
805 Target::MCSymbolizerCtorTy Fn) {
806 T.MCSymbolizerCtorFn = Fn;
813 //===--------------------------------------------------------------------===//
815 /// RegisterTarget - Helper template for registering a target, for use in the
816 /// target's initialization function. Usage:
819 /// Target TheFooTarget; // The global target instance.
821 /// extern "C" void LLVMInitializeFooTargetInfo() {
822 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
824 template<Triple::ArchType TargetArchType = Triple::UnknownArch,
826 struct RegisterTarget {
827 RegisterTarget(Target &T, const char *Name, const char *Desc) {
828 TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch, HasJIT);
831 static bool getArchMatch(Triple::ArchType Arch) {
832 return Arch == TargetArchType;
836 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
837 /// implementation. This invokes the static "Create" method on the class to
838 /// actually do the construction. Usage:
840 /// extern "C" void LLVMInitializeFooTarget() {
841 /// extern Target TheFooTarget;
842 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
844 template<class MCAsmInfoImpl>
845 struct RegisterMCAsmInfo {
846 RegisterMCAsmInfo(Target &T) {
847 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
850 static MCAsmInfo *Allocator(const MCRegisterInfo &/*MRI*/, StringRef TT) {
851 return new MCAsmInfoImpl(TT);
856 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
857 /// implementation. This invokes the specified function to do the
858 /// construction. Usage:
860 /// extern "C" void LLVMInitializeFooTarget() {
861 /// extern Target TheFooTarget;
862 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
864 struct RegisterMCAsmInfoFn {
865 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
866 TargetRegistry::RegisterMCAsmInfo(T, Fn);
870 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
871 /// implementation. This invokes the static "Create" method on the class
872 /// to actually do the construction. Usage:
874 /// extern "C" void LLVMInitializeFooTarget() {
875 /// extern Target TheFooTarget;
876 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
878 template<class MCCodeGenInfoImpl>
879 struct RegisterMCCodeGenInfo {
880 RegisterMCCodeGenInfo(Target &T) {
881 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
884 static MCCodeGenInfo *Allocator(StringRef /*TT*/, Reloc::Model /*RM*/,
885 CodeModel::Model /*CM*/,
886 CodeGenOpt::Level /*OL*/) {
887 return new MCCodeGenInfoImpl();
891 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
892 /// info implementation. This invokes the specified function to do the
893 /// construction. Usage:
895 /// extern "C" void LLVMInitializeFooTarget() {
896 /// extern Target TheFooTarget;
897 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
899 struct RegisterMCCodeGenInfoFn {
900 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
901 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
905 /// RegisterMCInstrInfo - Helper template for registering a target instruction
906 /// info implementation. This invokes the static "Create" method on the class
907 /// to actually do the construction. Usage:
909 /// extern "C" void LLVMInitializeFooTarget() {
910 /// extern Target TheFooTarget;
911 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
913 template<class MCInstrInfoImpl>
914 struct RegisterMCInstrInfo {
915 RegisterMCInstrInfo(Target &T) {
916 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
919 static MCInstrInfo *Allocator() {
920 return new MCInstrInfoImpl();
924 /// RegisterMCInstrInfoFn - Helper template for registering a target
925 /// instruction info implementation. This invokes the specified function to
926 /// do the construction. Usage:
928 /// extern "C" void LLVMInitializeFooTarget() {
929 /// extern Target TheFooTarget;
930 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
932 struct RegisterMCInstrInfoFn {
933 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
934 TargetRegistry::RegisterMCInstrInfo(T, Fn);
938 /// RegisterMCInstrAnalysis - Helper template for registering a target
939 /// instruction analyzer implementation. This invokes the static "Create"
940 /// method on the class to actually do the construction. Usage:
942 /// extern "C" void LLVMInitializeFooTarget() {
943 /// extern Target TheFooTarget;
944 /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
946 template<class MCInstrAnalysisImpl>
947 struct RegisterMCInstrAnalysis {
948 RegisterMCInstrAnalysis(Target &T) {
949 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
952 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
953 return new MCInstrAnalysisImpl(Info);
957 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
958 /// instruction analyzer implementation. This invokes the specified function
959 /// to do the construction. Usage:
961 /// extern "C" void LLVMInitializeFooTarget() {
962 /// extern Target TheFooTarget;
963 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
965 struct RegisterMCInstrAnalysisFn {
966 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
967 TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
971 /// RegisterMCRegInfo - Helper template for registering a target register info
972 /// implementation. This invokes the static "Create" method on the class to
973 /// actually do the construction. Usage:
975 /// extern "C" void LLVMInitializeFooTarget() {
976 /// extern Target TheFooTarget;
977 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
979 template<class MCRegisterInfoImpl>
980 struct RegisterMCRegInfo {
981 RegisterMCRegInfo(Target &T) {
982 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
985 static MCRegisterInfo *Allocator(StringRef /*TT*/) {
986 return new MCRegisterInfoImpl();
990 /// RegisterMCRegInfoFn - Helper template for registering a target register
991 /// info implementation. This invokes the specified function to do the
992 /// construction. Usage:
994 /// extern "C" void LLVMInitializeFooTarget() {
995 /// extern Target TheFooTarget;
996 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
998 struct RegisterMCRegInfoFn {
999 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
1000 TargetRegistry::RegisterMCRegInfo(T, Fn);
1004 /// RegisterMCSubtargetInfo - Helper template for registering a target
1005 /// subtarget info implementation. This invokes the static "Create" method
1006 /// on the class to actually do the construction. Usage:
1008 /// extern "C" void LLVMInitializeFooTarget() {
1009 /// extern Target TheFooTarget;
1010 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
1012 template<class MCSubtargetInfoImpl>
1013 struct RegisterMCSubtargetInfo {
1014 RegisterMCSubtargetInfo(Target &T) {
1015 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
1018 static MCSubtargetInfo *Allocator(StringRef /*TT*/, StringRef /*CPU*/,
1020 return new MCSubtargetInfoImpl();
1024 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
1025 /// subtarget info implementation. This invokes the specified function to
1026 /// do the construction. Usage:
1028 /// extern "C" void LLVMInitializeFooTarget() {
1029 /// extern Target TheFooTarget;
1030 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1032 struct RegisterMCSubtargetInfoFn {
1033 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
1034 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
1038 /// RegisterTargetMachine - Helper template for registering a target machine
1039 /// implementation, for use in the target machine initialization
1040 /// function. Usage:
1042 /// extern "C" void LLVMInitializeFooTarget() {
1043 /// extern Target TheFooTarget;
1044 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1046 template<class TargetMachineImpl>
1047 struct RegisterTargetMachine {
1048 RegisterTargetMachine(Target &T) {
1049 TargetRegistry::RegisterTargetMachine(T, &Allocator);
1053 static TargetMachine *Allocator(const Target &T, StringRef TT,
1054 StringRef CPU, StringRef FS,
1055 const TargetOptions &Options,
1057 CodeModel::Model CM,
1058 CodeGenOpt::Level OL) {
1059 return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
1063 /// RegisterMCAsmBackend - Helper template for registering a target specific
1064 /// assembler backend. Usage:
1066 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1067 /// extern Target TheFooTarget;
1068 /// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1070 template<class MCAsmBackendImpl>
1071 struct RegisterMCAsmBackend {
1072 RegisterMCAsmBackend(Target &T) {
1073 TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1077 static MCAsmBackend *Allocator(const Target &T,
1078 const MCRegisterInfo &MRI,
1079 StringRef Triple, StringRef CPU) {
1080 return new MCAsmBackendImpl(T, MRI, Triple, CPU);
1084 /// RegisterMCAsmParser - Helper template for registering a target specific
1085 /// assembly parser, for use in the target machine initialization
1086 /// function. Usage:
1088 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1089 /// extern Target TheFooTarget;
1090 /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1092 template<class MCAsmParserImpl>
1093 struct RegisterMCAsmParser {
1094 RegisterMCAsmParser(Target &T) {
1095 TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1099 static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P,
1100 const MCInstrInfo &MII,
1101 const MCTargetOptions &Options) {
1102 return new MCAsmParserImpl(STI, P, MII, Options);
1106 /// RegisterAsmPrinter - Helper template for registering a target specific
1107 /// assembly printer, for use in the target machine initialization
1108 /// function. Usage:
1110 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1111 /// extern Target TheFooTarget;
1112 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1114 template<class AsmPrinterImpl>
1115 struct RegisterAsmPrinter {
1116 RegisterAsmPrinter(Target &T) {
1117 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1121 static AsmPrinter *Allocator(TargetMachine &TM,
1122 std::unique_ptr<MCStreamer> &&Streamer) {
1123 return new AsmPrinterImpl(TM, std::move(Streamer));
1127 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1128 /// machine code emitter, for use in the target initialization
1129 /// function. Usage:
1131 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1132 /// extern Target TheFooTarget;
1133 /// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1135 template<class MCCodeEmitterImpl>
1136 struct RegisterMCCodeEmitter {
1137 RegisterMCCodeEmitter(Target &T) {
1138 TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1142 static MCCodeEmitter *Allocator(const MCInstrInfo & /*II*/,
1143 const MCRegisterInfo & /*MRI*/,
1144 MCContext & /*Ctx*/) {
1145 return new MCCodeEmitterImpl();