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,
128 const MCSubtargetInfo &STI,
130 typedef MCStreamer *(*MCObjectStreamerCtorTy)(
131 const Target &T, StringRef TT, MCContext &Ctx, MCAsmBackend &TAB,
132 raw_ostream &_OS, MCCodeEmitter *_Emitter, const MCSubtargetInfo &STI,
134 typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx,
135 formatted_raw_ostream &OS,
137 bool useDwarfDirectory,
138 MCInstPrinter *InstPrint,
142 typedef MCTargetStreamer *(*NullTargetStreamerCtorTy)(MCStreamer &S);
143 typedef MCRelocationInfo *(*MCRelocationInfoCtorTy)(StringRef TT,
145 typedef MCSymbolizer *(*MCSymbolizerCtorTy)(
146 StringRef TT, LLVMOpInfoCallback GetOpInfo,
147 LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo, MCContext *Ctx,
148 std::unique_ptr<MCRelocationInfo> &&RelInfo);
151 /// Next - The next registered target in the linked list, maintained by the
155 /// The target function for checking if an architecture is supported.
156 ArchMatchFnTy ArchMatchFn;
158 /// Name - The target name.
161 /// ShortDesc - A short description of the target.
162 const char *ShortDesc;
164 /// HasJIT - Whether this target supports the JIT.
167 /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
169 MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
171 /// MCCodeGenInfoCtorFn - Constructor function for this target's
172 /// MCCodeGenInfo, if registered.
173 MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn;
175 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
177 MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
179 /// MCInstrAnalysisCtorFn - Constructor function for this target's
180 /// MCInstrAnalysis, if registered.
181 MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
183 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
185 MCRegInfoCtorFnTy MCRegInfoCtorFn;
187 /// MCSubtargetInfoCtorFn - Constructor function for this target's
188 /// MCSubtargetInfo, if registered.
189 MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
191 /// TargetMachineCtorFn - Construction function for this target's
192 /// TargetMachine, if registered.
193 TargetMachineCtorTy TargetMachineCtorFn;
195 /// MCAsmBackendCtorFn - Construction function for this target's
196 /// MCAsmBackend, if registered.
197 MCAsmBackendCtorTy MCAsmBackendCtorFn;
199 /// MCAsmParserCtorFn - Construction function for this target's
200 /// MCTargetAsmParser, if registered.
201 MCAsmParserCtorTy MCAsmParserCtorFn;
203 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
205 AsmPrinterCtorTy AsmPrinterCtorFn;
207 /// MCDisassemblerCtorFn - Construction function for this target's
208 /// MCDisassembler, if registered.
209 MCDisassemblerCtorTy MCDisassemblerCtorFn;
211 /// MCInstPrinterCtorFn - Construction function for this target's
212 /// MCInstPrinter, if registered.
213 MCInstPrinterCtorTy MCInstPrinterCtorFn;
215 /// MCCodeEmitterCtorFn - Construction function for this target's
216 /// CodeEmitter, if registered.
217 MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
219 /// MCObjectStreamerCtorFn - Construction function for this target's
220 /// MCObjectStreamer, if registered.
221 MCObjectStreamerCtorTy MCObjectStreamerCtorFn;
223 /// AsmStreamerCtorFn - Construction function for this target's
224 /// AsmStreamer, if registered (default = llvm::createAsmStreamer).
225 AsmStreamerCtorTy AsmStreamerCtorFn;
227 /// Construction function for this target's null TargetStreamer, if
228 /// registered (default = nullptr).
229 NullTargetStreamerCtorTy NullTargetStreamerCtorFn;
231 /// MCRelocationInfoCtorFn - Construction function for this target's
232 /// MCRelocationInfo, if registered (default = llvm::createMCRelocationInfo)
233 MCRelocationInfoCtorTy MCRelocationInfoCtorFn;
235 /// MCSymbolizerCtorFn - Construction function for this target's
236 /// MCSymbolizer, if registered (default = llvm::createMCSymbolizer)
237 MCSymbolizerCtorTy MCSymbolizerCtorFn;
241 : AsmStreamerCtorFn(nullptr), MCRelocationInfoCtorFn(nullptr),
242 MCSymbolizerCtorFn(nullptr) {}
244 /// @name Target Information
247 // getNext - Return the next registered target.
248 const Target *getNext() const { return Next; }
250 /// getName - Get the target name.
251 const char *getName() const { return Name; }
253 /// getShortDescription - Get a short description of the target.
254 const char *getShortDescription() const { return ShortDesc; }
257 /// @name Feature Predicates
260 /// hasJIT - Check if this targets supports the just-in-time compilation.
261 bool hasJIT() const { return HasJIT; }
263 /// hasTargetMachine - Check if this target supports code generation.
264 bool hasTargetMachine() const { return TargetMachineCtorFn != nullptr; }
266 /// hasMCAsmBackend - Check if this target supports .o generation.
267 bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != nullptr; }
270 /// @name Feature Constructors
273 /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
276 /// \param Triple This argument is used to determine the target machine
277 /// feature set; it should always be provided. Generally this should be
278 /// either the target triple from the module, or the target triple of the
279 /// host if that does not exist.
280 MCAsmInfo *createMCAsmInfo(const MCRegisterInfo &MRI,
281 StringRef Triple) const {
282 if (!MCAsmInfoCtorFn)
284 return MCAsmInfoCtorFn(MRI, Triple);
287 /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
289 MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model RM,
291 CodeGenOpt::Level OL) const {
292 if (!MCCodeGenInfoCtorFn)
294 return MCCodeGenInfoCtorFn(Triple, RM, CM, OL);
297 /// createMCInstrInfo - Create a MCInstrInfo implementation.
299 MCInstrInfo *createMCInstrInfo() const {
300 if (!MCInstrInfoCtorFn)
302 return MCInstrInfoCtorFn();
305 /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
307 MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
308 if (!MCInstrAnalysisCtorFn)
310 return MCInstrAnalysisCtorFn(Info);
313 /// createMCRegInfo - Create a MCRegisterInfo implementation.
315 MCRegisterInfo *createMCRegInfo(StringRef Triple) const {
316 if (!MCRegInfoCtorFn)
318 return MCRegInfoCtorFn(Triple);
321 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
323 /// \param Triple This argument is used to determine the target machine
324 /// feature set; it should always be provided. Generally this should be
325 /// either the target triple from the module, or the target triple of the
326 /// host if that does not exist.
327 /// \param CPU This specifies the name of the target CPU.
328 /// \param Features This specifies the string representation of the
329 /// additional target features.
330 MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU,
331 StringRef Features) const {
332 if (!MCSubtargetInfoCtorFn)
334 return MCSubtargetInfoCtorFn(Triple, CPU, Features);
337 /// createTargetMachine - Create a target specific machine implementation
338 /// for the specified \p Triple.
340 /// \param Triple This argument is used to determine the target machine
341 /// feature set; it should always be provided. Generally this should be
342 /// either the target triple from the module, or the target triple of the
343 /// host if that does not exist.
344 TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU,
345 StringRef Features, const TargetOptions &Options,
346 Reloc::Model RM = Reloc::Default,
347 CodeModel::Model CM = CodeModel::Default,
348 CodeGenOpt::Level OL = CodeGenOpt::Default) const {
349 if (!TargetMachineCtorFn)
351 return TargetMachineCtorFn(*this, Triple, CPU, Features, Options,
355 /// createMCAsmBackend - Create a target specific assembly parser.
357 /// \param Triple The target triple string.
358 MCAsmBackend *createMCAsmBackend(const MCRegisterInfo &MRI,
359 StringRef Triple, StringRef CPU) const {
360 if (!MCAsmBackendCtorFn)
362 return MCAsmBackendCtorFn(*this, MRI, Triple, CPU);
365 /// createMCAsmParser - Create a target specific assembly parser.
367 /// \param Parser The target independent parser implementation to use for
368 /// parsing and lexing.
369 MCTargetAsmParser *createMCAsmParser(
370 MCSubtargetInfo &STI,
372 const MCInstrInfo &MII,
373 const MCTargetOptions &Options) const {
374 if (!MCAsmParserCtorFn)
376 return MCAsmParserCtorFn(STI, Parser, MII, Options);
379 /// createAsmPrinter - Create a target specific assembly printer pass. This
380 /// takes ownership of the MCStreamer object.
381 AsmPrinter *createAsmPrinter(TargetMachine &TM,
382 std::unique_ptr<MCStreamer> &&Streamer) const {
383 if (!AsmPrinterCtorFn)
385 return AsmPrinterCtorFn(TM, std::move(Streamer));
388 MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI,
389 MCContext &Ctx) const {
390 if (!MCDisassemblerCtorFn)
392 return MCDisassemblerCtorFn(*this, STI, Ctx);
395 MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
396 const MCAsmInfo &MAI,
397 const MCInstrInfo &MII,
398 const MCRegisterInfo &MRI,
399 const MCSubtargetInfo &STI) const {
400 if (!MCInstPrinterCtorFn)
402 return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, MII, MRI, STI);
406 /// createMCCodeEmitter - Create a target specific code emitter.
407 MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
408 const MCRegisterInfo &MRI,
409 const MCSubtargetInfo &STI,
410 MCContext &Ctx) const {
411 if (!MCCodeEmitterCtorFn)
413 return MCCodeEmitterCtorFn(II, MRI, STI, Ctx);
416 /// createMCObjectStreamer - Create a target specific MCStreamer.
418 /// \param TT The target triple.
419 /// \param Ctx The target context.
420 /// \param TAB The target assembler backend object. Takes ownership.
421 /// \param _OS The stream object.
422 /// \param _Emitter The target independent assembler object.Takes ownership.
423 /// \param RelaxAll Relax all fixups?
424 MCStreamer *createMCObjectStreamer(StringRef TT, MCContext &Ctx,
425 MCAsmBackend &TAB, raw_ostream &_OS,
426 MCCodeEmitter *_Emitter,
427 const MCSubtargetInfo &STI,
428 bool RelaxAll) const {
429 if (!MCObjectStreamerCtorFn)
431 return MCObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter, STI,
435 /// createAsmStreamer - Create a target specific MCStreamer.
436 MCStreamer *createAsmStreamer(MCContext &Ctx,
437 formatted_raw_ostream &OS,
439 bool useDwarfDirectory,
440 MCInstPrinter *InstPrint,
443 bool ShowInst) const {
444 if (AsmStreamerCtorFn)
445 return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useDwarfDirectory,
446 InstPrint, CE, TAB, ShowInst);
447 return llvm::createAsmStreamer(Ctx, OS, isVerboseAsm, useDwarfDirectory,
448 InstPrint, CE, TAB, ShowInst);
451 MCStreamer *createNullStreamer(MCContext &Ctx) const {
452 MCStreamer *S = llvm::createNullStreamer(Ctx);
453 createNullTargetStreamer(*S);
457 MCTargetStreamer *createNullTargetStreamer(MCStreamer &S) const {
458 if (NullTargetStreamerCtorFn)
459 return NullTargetStreamerCtorFn(S);
463 /// createMCRelocationInfo - Create a target specific MCRelocationInfo.
465 /// \param TT The target triple.
466 /// \param Ctx The target context.
468 createMCRelocationInfo(StringRef TT, MCContext &Ctx) const {
469 MCRelocationInfoCtorTy Fn = MCRelocationInfoCtorFn
470 ? MCRelocationInfoCtorFn
471 : llvm::createMCRelocationInfo;
475 /// createMCSymbolizer - Create a target specific MCSymbolizer.
477 /// \param TT The target triple.
478 /// \param GetOpInfo The function to get the symbolic information for operands.
479 /// \param SymbolLookUp The function to lookup a symbol name.
480 /// \param DisInfo The pointer to the block of symbolic information for above call
482 /// \param Ctx The target context.
483 /// \param RelInfo The relocation information for this target. Takes ownership.
485 createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
486 LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo,
488 std::unique_ptr<MCRelocationInfo> &&RelInfo) const {
489 MCSymbolizerCtorTy Fn =
490 MCSymbolizerCtorFn ? MCSymbolizerCtorFn : llvm::createMCSymbolizer;
491 return Fn(TT, GetOpInfo, SymbolLookUp, DisInfo, Ctx, std::move(RelInfo));
497 /// TargetRegistry - Generic interface to target specific features.
498 struct TargetRegistry {
500 const Target *Current;
501 explicit iterator(Target *T) : Current(T) {}
502 friend struct TargetRegistry;
504 iterator() : Current(nullptr) {}
506 bool operator==(const iterator &x) const {
507 return Current == x.Current;
509 bool operator!=(const iterator &x) const {
510 return !operator==(x);
513 // Iterator traversal: forward iteration only
514 iterator &operator++() { // Preincrement
515 assert(Current && "Cannot increment end iterator!");
516 Current = Current->getNext();
519 iterator operator++(int) { // Postincrement
520 iterator tmp = *this;
525 const Target &operator*() const {
526 assert(Current && "Cannot dereference end iterator!");
530 const Target *operator->() const {
535 /// printRegisteredTargetsForVersion - Print the registered targets
536 /// appropriately for inclusion in a tool's version output.
537 static void printRegisteredTargetsForVersion();
539 /// @name Registry Access
542 static iterator begin();
544 static iterator end() { return iterator(); }
546 /// lookupTarget - Lookup a target based on a target triple.
548 /// \param Triple - The triple to use for finding a target.
549 /// \param Error - On failure, an error string describing why no target was
551 static const Target *lookupTarget(const std::string &Triple,
554 /// lookupTarget - Lookup a target based on an architecture name
555 /// and a target triple. If the architecture name is non-empty,
556 /// then the lookup is done by architecture. Otherwise, the target
559 /// \param ArchName - The architecture to use for finding a target.
560 /// \param TheTriple - The triple to use for finding a target. The
561 /// triple is updated with canonical architecture name if a lookup
562 /// by architecture is done.
563 /// \param Error - On failure, an error string describing why no target was
565 static const Target *lookupTarget(const std::string &ArchName,
570 /// @name Target Registration
573 /// RegisterTarget - Register the given target. Attempts to register a
574 /// target which has already been registered will be ignored.
576 /// Clients are responsible for ensuring that registration doesn't occur
577 /// while another thread is attempting to access the registry. Typically
578 /// this is done by initializing all targets at program startup.
580 /// @param T - The target being registered.
581 /// @param Name - The target name. This should be a static string.
582 /// @param ShortDesc - A short target description. This should be a static
584 /// @param ArchMatchFn - The arch match checking function for this target.
585 /// @param HasJIT - Whether the target supports JIT code
587 static void RegisterTarget(Target &T,
589 const char *ShortDesc,
590 Target::ArchMatchFnTy ArchMatchFn,
591 bool HasJIT = false);
593 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
596 /// Clients are responsible for ensuring that registration doesn't occur
597 /// while another thread is attempting to access the registry. Typically
598 /// this is done by initializing all targets at program startup.
600 /// @param T - The target being registered.
601 /// @param Fn - A function to construct a MCAsmInfo for the target.
602 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
603 T.MCAsmInfoCtorFn = Fn;
606 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
609 /// Clients are responsible for ensuring that registration doesn't occur
610 /// while another thread is attempting to access the registry. Typically
611 /// this is done by initializing all targets at program startup.
613 /// @param T - The target being registered.
614 /// @param Fn - A function to construct a MCCodeGenInfo for the target.
615 static void RegisterMCCodeGenInfo(Target &T,
616 Target::MCCodeGenInfoCtorFnTy Fn) {
617 T.MCCodeGenInfoCtorFn = Fn;
620 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
623 /// Clients are responsible for ensuring that registration doesn't occur
624 /// while another thread is attempting to access the registry. Typically
625 /// this is done by initializing all targets at program startup.
627 /// @param T - The target being registered.
628 /// @param Fn - A function to construct a MCInstrInfo for the target.
629 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
630 T.MCInstrInfoCtorFn = Fn;
633 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
634 /// the given target.
635 static void RegisterMCInstrAnalysis(Target &T,
636 Target::MCInstrAnalysisCtorFnTy Fn) {
637 T.MCInstrAnalysisCtorFn = Fn;
640 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
643 /// Clients are responsible for ensuring that registration doesn't occur
644 /// while another thread is attempting to access the registry. Typically
645 /// this is done by initializing all targets at program startup.
647 /// @param T - The target being registered.
648 /// @param Fn - A function to construct a MCRegisterInfo for the target.
649 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
650 T.MCRegInfoCtorFn = Fn;
653 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
654 /// the given target.
656 /// Clients are responsible for ensuring that registration doesn't occur
657 /// while another thread is attempting to access the registry. Typically
658 /// this is done by initializing all targets at program startup.
660 /// @param T - The target being registered.
661 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
662 static void RegisterMCSubtargetInfo(Target &T,
663 Target::MCSubtargetInfoCtorFnTy Fn) {
664 T.MCSubtargetInfoCtorFn = Fn;
667 /// RegisterTargetMachine - Register a TargetMachine implementation for the
670 /// Clients are responsible for ensuring that registration doesn't occur
671 /// while another thread is attempting to access the registry. Typically
672 /// this is done by initializing all targets at program startup.
674 /// @param T - The target being registered.
675 /// @param Fn - A function to construct a TargetMachine for the target.
676 static void RegisterTargetMachine(Target &T,
677 Target::TargetMachineCtorTy Fn) {
678 T.TargetMachineCtorFn = Fn;
681 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
684 /// Clients are responsible for ensuring that registration doesn't occur
685 /// while another thread is attempting to access the registry. Typically
686 /// this is done by initializing all targets at program startup.
688 /// @param T - The target being registered.
689 /// @param Fn - A function to construct an AsmBackend for the target.
690 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
691 T.MCAsmBackendCtorFn = Fn;
694 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
695 /// the given target.
697 /// Clients are responsible for ensuring that registration doesn't occur
698 /// while another thread is attempting to access the registry. Typically
699 /// this is done by initializing all targets at program startup.
701 /// @param T - The target being registered.
702 /// @param Fn - A function to construct an MCTargetAsmParser for the target.
703 static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
704 T.MCAsmParserCtorFn = Fn;
707 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
710 /// Clients are responsible for ensuring that registration doesn't occur
711 /// while another thread is attempting to access the registry. Typically
712 /// this is done by initializing all targets at program startup.
714 /// @param T - The target being registered.
715 /// @param Fn - A function to construct an AsmPrinter for the target.
716 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
717 T.AsmPrinterCtorFn = Fn;
720 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
721 /// the given target.
723 /// Clients are responsible for ensuring that registration doesn't occur
724 /// while another thread is attempting to access the registry. Typically
725 /// this is done by initializing all targets at program startup.
727 /// @param T - The target being registered.
728 /// @param Fn - A function to construct an MCDisassembler for the target.
729 static void RegisterMCDisassembler(Target &T,
730 Target::MCDisassemblerCtorTy Fn) {
731 T.MCDisassemblerCtorFn = Fn;
734 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
737 /// Clients are responsible for ensuring that registration doesn't occur
738 /// while another thread is attempting to access the registry. Typically
739 /// this is done by initializing all targets at program startup.
741 /// @param T - The target being registered.
742 /// @param Fn - A function to construct an MCInstPrinter for the target.
743 static void RegisterMCInstPrinter(Target &T,
744 Target::MCInstPrinterCtorTy Fn) {
745 T.MCInstPrinterCtorFn = Fn;
748 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
751 /// Clients are responsible for ensuring that registration doesn't occur
752 /// while another thread is attempting to access the registry. Typically
753 /// this is done by initializing all targets at program startup.
755 /// @param T - The target being registered.
756 /// @param Fn - A function to construct an MCCodeEmitter for the target.
757 static void RegisterMCCodeEmitter(Target &T,
758 Target::MCCodeEmitterCtorTy Fn) {
759 T.MCCodeEmitterCtorFn = Fn;
762 /// RegisterMCObjectStreamer - Register a object code MCStreamer
763 /// implementation for the given target.
765 /// Clients are responsible for ensuring that registration doesn't occur
766 /// while another thread is attempting to access the registry. Typically
767 /// this is done by initializing all targets at program startup.
769 /// @param T - The target being registered.
770 /// @param Fn - A function to construct an MCStreamer for the target.
771 static void RegisterMCObjectStreamer(Target &T,
772 Target::MCObjectStreamerCtorTy Fn) {
773 T.MCObjectStreamerCtorFn = Fn;
776 /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
777 /// for the given target.
779 /// Clients are responsible for ensuring that registration doesn't occur
780 /// while another thread is attempting to access the registry. Typically
781 /// this is done by initializing all targets at program startup.
783 /// @param T - The target being registered.
784 /// @param Fn - A function to construct an MCStreamer for the target.
785 static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
786 T.AsmStreamerCtorFn = Fn;
790 RegisterNullTargetStreamer(Target &T, Target::NullTargetStreamerCtorTy Fn) {
791 T.NullTargetStreamerCtorFn = Fn;
794 /// RegisterMCRelocationInfo - Register an MCRelocationInfo
795 /// implementation for the given target.
797 /// Clients are responsible for ensuring that registration doesn't occur
798 /// while another thread is attempting to access the registry. Typically
799 /// this is done by initializing all targets at program startup.
801 /// @param T - The target being registered.
802 /// @param Fn - A function to construct an MCRelocationInfo for the target.
803 static void RegisterMCRelocationInfo(Target &T,
804 Target::MCRelocationInfoCtorTy Fn) {
805 T.MCRelocationInfoCtorFn = Fn;
808 /// RegisterMCSymbolizer - Register an MCSymbolizer
809 /// implementation for the given target.
811 /// Clients are responsible for ensuring that registration doesn't occur
812 /// while another thread is attempting to access the registry. Typically
813 /// this is done by initializing all targets at program startup.
815 /// @param T - The target being registered.
816 /// @param Fn - A function to construct an MCSymbolizer for the target.
817 static void RegisterMCSymbolizer(Target &T,
818 Target::MCSymbolizerCtorTy Fn) {
819 T.MCSymbolizerCtorFn = Fn;
826 //===--------------------------------------------------------------------===//
828 /// RegisterTarget - Helper template for registering a target, for use in the
829 /// target's initialization function. Usage:
832 /// Target TheFooTarget; // The global target instance.
834 /// extern "C" void LLVMInitializeFooTargetInfo() {
835 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
837 template<Triple::ArchType TargetArchType = Triple::UnknownArch,
839 struct RegisterTarget {
840 RegisterTarget(Target &T, const char *Name, const char *Desc) {
841 TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch, HasJIT);
844 static bool getArchMatch(Triple::ArchType Arch) {
845 return Arch == TargetArchType;
849 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
850 /// implementation. This invokes the static "Create" method on the class to
851 /// actually do the construction. Usage:
853 /// extern "C" void LLVMInitializeFooTarget() {
854 /// extern Target TheFooTarget;
855 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
857 template<class MCAsmInfoImpl>
858 struct RegisterMCAsmInfo {
859 RegisterMCAsmInfo(Target &T) {
860 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
863 static MCAsmInfo *Allocator(const MCRegisterInfo &/*MRI*/, StringRef TT) {
864 return new MCAsmInfoImpl(TT);
869 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
870 /// implementation. This invokes the specified function to do the
871 /// construction. Usage:
873 /// extern "C" void LLVMInitializeFooTarget() {
874 /// extern Target TheFooTarget;
875 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
877 struct RegisterMCAsmInfoFn {
878 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
879 TargetRegistry::RegisterMCAsmInfo(T, Fn);
883 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
884 /// implementation. This invokes the static "Create" method on the class
885 /// to actually do the construction. Usage:
887 /// extern "C" void LLVMInitializeFooTarget() {
888 /// extern Target TheFooTarget;
889 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
891 template<class MCCodeGenInfoImpl>
892 struct RegisterMCCodeGenInfo {
893 RegisterMCCodeGenInfo(Target &T) {
894 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
897 static MCCodeGenInfo *Allocator(StringRef /*TT*/, Reloc::Model /*RM*/,
898 CodeModel::Model /*CM*/,
899 CodeGenOpt::Level /*OL*/) {
900 return new MCCodeGenInfoImpl();
904 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
905 /// info implementation. This invokes the specified function to do the
906 /// construction. Usage:
908 /// extern "C" void LLVMInitializeFooTarget() {
909 /// extern Target TheFooTarget;
910 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
912 struct RegisterMCCodeGenInfoFn {
913 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
914 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
918 /// RegisterMCInstrInfo - Helper template for registering a target instruction
919 /// info implementation. This invokes the static "Create" method on the class
920 /// to actually do the construction. Usage:
922 /// extern "C" void LLVMInitializeFooTarget() {
923 /// extern Target TheFooTarget;
924 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
926 template<class MCInstrInfoImpl>
927 struct RegisterMCInstrInfo {
928 RegisterMCInstrInfo(Target &T) {
929 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
932 static MCInstrInfo *Allocator() {
933 return new MCInstrInfoImpl();
937 /// RegisterMCInstrInfoFn - Helper template for registering a target
938 /// instruction info implementation. This invokes the specified function to
939 /// do the construction. Usage:
941 /// extern "C" void LLVMInitializeFooTarget() {
942 /// extern Target TheFooTarget;
943 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
945 struct RegisterMCInstrInfoFn {
946 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
947 TargetRegistry::RegisterMCInstrInfo(T, Fn);
951 /// RegisterMCInstrAnalysis - Helper template for registering a target
952 /// instruction analyzer implementation. This invokes the static "Create"
953 /// method on the class to actually do the construction. Usage:
955 /// extern "C" void LLVMInitializeFooTarget() {
956 /// extern Target TheFooTarget;
957 /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
959 template<class MCInstrAnalysisImpl>
960 struct RegisterMCInstrAnalysis {
961 RegisterMCInstrAnalysis(Target &T) {
962 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
965 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
966 return new MCInstrAnalysisImpl(Info);
970 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
971 /// instruction analyzer implementation. This invokes the specified function
972 /// to do the construction. Usage:
974 /// extern "C" void LLVMInitializeFooTarget() {
975 /// extern Target TheFooTarget;
976 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
978 struct RegisterMCInstrAnalysisFn {
979 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
980 TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
984 /// RegisterMCRegInfo - Helper template for registering a target register info
985 /// implementation. This invokes the static "Create" method on the class to
986 /// actually do the construction. Usage:
988 /// extern "C" void LLVMInitializeFooTarget() {
989 /// extern Target TheFooTarget;
990 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
992 template<class MCRegisterInfoImpl>
993 struct RegisterMCRegInfo {
994 RegisterMCRegInfo(Target &T) {
995 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
998 static MCRegisterInfo *Allocator(StringRef /*TT*/) {
999 return new MCRegisterInfoImpl();
1003 /// RegisterMCRegInfoFn - Helper template for registering a target register
1004 /// info implementation. This invokes the specified function to do the
1005 /// construction. Usage:
1007 /// extern "C" void LLVMInitializeFooTarget() {
1008 /// extern Target TheFooTarget;
1009 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
1011 struct RegisterMCRegInfoFn {
1012 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
1013 TargetRegistry::RegisterMCRegInfo(T, Fn);
1017 /// RegisterMCSubtargetInfo - Helper template for registering a target
1018 /// subtarget info implementation. This invokes the static "Create" method
1019 /// on the class to actually do the construction. Usage:
1021 /// extern "C" void LLVMInitializeFooTarget() {
1022 /// extern Target TheFooTarget;
1023 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
1025 template<class MCSubtargetInfoImpl>
1026 struct RegisterMCSubtargetInfo {
1027 RegisterMCSubtargetInfo(Target &T) {
1028 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
1031 static MCSubtargetInfo *Allocator(StringRef /*TT*/, StringRef /*CPU*/,
1033 return new MCSubtargetInfoImpl();
1037 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
1038 /// subtarget info implementation. This invokes the specified function to
1039 /// do the construction. Usage:
1041 /// extern "C" void LLVMInitializeFooTarget() {
1042 /// extern Target TheFooTarget;
1043 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1045 struct RegisterMCSubtargetInfoFn {
1046 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
1047 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
1051 /// RegisterTargetMachine - Helper template for registering a target machine
1052 /// implementation, for use in the target machine initialization
1053 /// function. Usage:
1055 /// extern "C" void LLVMInitializeFooTarget() {
1056 /// extern Target TheFooTarget;
1057 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1059 template<class TargetMachineImpl>
1060 struct RegisterTargetMachine {
1061 RegisterTargetMachine(Target &T) {
1062 TargetRegistry::RegisterTargetMachine(T, &Allocator);
1066 static TargetMachine *Allocator(const Target &T, StringRef TT,
1067 StringRef CPU, StringRef FS,
1068 const TargetOptions &Options,
1070 CodeModel::Model CM,
1071 CodeGenOpt::Level OL) {
1072 return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
1076 /// RegisterMCAsmBackend - Helper template for registering a target specific
1077 /// assembler backend. Usage:
1079 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1080 /// extern Target TheFooTarget;
1081 /// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1083 template<class MCAsmBackendImpl>
1084 struct RegisterMCAsmBackend {
1085 RegisterMCAsmBackend(Target &T) {
1086 TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1090 static MCAsmBackend *Allocator(const Target &T,
1091 const MCRegisterInfo &MRI,
1092 StringRef Triple, StringRef CPU) {
1093 return new MCAsmBackendImpl(T, MRI, Triple, CPU);
1097 /// RegisterMCAsmParser - Helper template for registering a target specific
1098 /// assembly parser, for use in the target machine initialization
1099 /// function. Usage:
1101 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1102 /// extern Target TheFooTarget;
1103 /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1105 template<class MCAsmParserImpl>
1106 struct RegisterMCAsmParser {
1107 RegisterMCAsmParser(Target &T) {
1108 TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1112 static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P,
1113 const MCInstrInfo &MII,
1114 const MCTargetOptions &Options) {
1115 return new MCAsmParserImpl(STI, P, MII, Options);
1119 /// RegisterAsmPrinter - Helper template for registering a target specific
1120 /// assembly printer, for use in the target machine initialization
1121 /// function. Usage:
1123 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1124 /// extern Target TheFooTarget;
1125 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1127 template<class AsmPrinterImpl>
1128 struct RegisterAsmPrinter {
1129 RegisterAsmPrinter(Target &T) {
1130 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1134 static AsmPrinter *Allocator(TargetMachine &TM,
1135 std::unique_ptr<MCStreamer> &&Streamer) {
1136 return new AsmPrinterImpl(TM, std::move(Streamer));
1140 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1141 /// machine code emitter, for use in the target initialization
1142 /// function. Usage:
1144 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1145 /// extern Target TheFooTarget;
1146 /// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1148 template<class MCCodeEmitterImpl>
1149 struct RegisterMCCodeEmitter {
1150 RegisterMCCodeEmitter(Target &T) {
1151 TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1155 static MCCodeEmitter *Allocator(const MCInstrInfo &/*II*/,
1156 const MCRegisterInfo &/*MRI*/,
1157 const MCSubtargetInfo &/*STI*/,
1158 MCContext &/*Ctx*/) {
1159 return new MCCodeEmitterImpl();