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 MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx,
134 formatted_raw_ostream &OS,
136 bool useDwarfDirectory,
137 MCInstPrinter *InstPrint,
141 typedef MCTargetStreamer *(*NullTargetStreamerCtorTy)(MCStreamer &S);
142 typedef MCRelocationInfo *(*MCRelocationInfoCtorTy)(StringRef TT,
144 typedef MCSymbolizer *(*MCSymbolizerCtorTy)(
145 StringRef TT, LLVMOpInfoCallback GetOpInfo,
146 LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo, MCContext *Ctx,
147 std::unique_ptr<MCRelocationInfo> &&RelInfo);
150 /// Next - The next registered target in the linked list, maintained by the
154 /// The target function for checking if an architecture is supported.
155 ArchMatchFnTy ArchMatchFn;
157 /// Name - The target name.
160 /// ShortDesc - A short description of the target.
161 const char *ShortDesc;
163 /// HasJIT - Whether this target supports the JIT.
166 /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
168 MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
170 /// MCCodeGenInfoCtorFn - Constructor function for this target's
171 /// MCCodeGenInfo, if registered.
172 MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn;
174 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
176 MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
178 /// MCInstrAnalysisCtorFn - Constructor function for this target's
179 /// MCInstrAnalysis, if registered.
180 MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
182 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
184 MCRegInfoCtorFnTy MCRegInfoCtorFn;
186 /// MCSubtargetInfoCtorFn - Constructor function for this target's
187 /// MCSubtargetInfo, if registered.
188 MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
190 /// TargetMachineCtorFn - Construction function for this target's
191 /// TargetMachine, if registered.
192 TargetMachineCtorTy TargetMachineCtorFn;
194 /// MCAsmBackendCtorFn - Construction function for this target's
195 /// MCAsmBackend, if registered.
196 MCAsmBackendCtorTy MCAsmBackendCtorFn;
198 /// MCAsmParserCtorFn - Construction function for this target's
199 /// MCTargetAsmParser, if registered.
200 MCAsmParserCtorTy MCAsmParserCtorFn;
202 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
204 AsmPrinterCtorTy AsmPrinterCtorFn;
206 /// MCDisassemblerCtorFn - Construction function for this target's
207 /// MCDisassembler, if registered.
208 MCDisassemblerCtorTy MCDisassemblerCtorFn;
210 /// MCInstPrinterCtorFn - Construction function for this target's
211 /// MCInstPrinter, if registered.
212 MCInstPrinterCtorTy MCInstPrinterCtorFn;
214 /// MCCodeEmitterCtorFn - Construction function for this target's
215 /// CodeEmitter, if registered.
216 MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
218 /// MCObjectStreamerCtorFn - Construction function for this target's
219 /// MCObjectStreamer, if registered.
220 MCObjectStreamerCtorTy MCObjectStreamerCtorFn;
222 /// AsmStreamerCtorFn - Construction function for this target's
223 /// AsmStreamer, if registered (default = llvm::createAsmStreamer).
224 AsmStreamerCtorTy AsmStreamerCtorFn;
226 /// Construction function for this target's null TargetStreamer, if
227 /// registered (default = nullptr).
228 NullTargetStreamerCtorTy NullTargetStreamerCtorFn;
230 /// MCRelocationInfoCtorFn - Construction function for this target's
231 /// MCRelocationInfo, if registered (default = llvm::createMCRelocationInfo)
232 MCRelocationInfoCtorTy MCRelocationInfoCtorFn;
234 /// MCSymbolizerCtorFn - Construction function for this target's
235 /// MCSymbolizer, if registered (default = llvm::createMCSymbolizer)
236 MCSymbolizerCtorTy MCSymbolizerCtorFn;
240 : AsmStreamerCtorFn(nullptr), MCRelocationInfoCtorFn(nullptr),
241 MCSymbolizerCtorFn(nullptr) {}
243 /// @name Target Information
246 // getNext - Return the next registered target.
247 const Target *getNext() const { return Next; }
249 /// getName - Get the target name.
250 const char *getName() const { return Name; }
252 /// getShortDescription - Get a short description of the target.
253 const char *getShortDescription() const { return ShortDesc; }
256 /// @name Feature Predicates
259 /// hasJIT - Check if this targets supports the just-in-time compilation.
260 bool hasJIT() const { return HasJIT; }
262 /// hasTargetMachine - Check if this target supports code generation.
263 bool hasTargetMachine() const { return TargetMachineCtorFn != nullptr; }
265 /// hasMCAsmBackend - Check if this target supports .o generation.
266 bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != nullptr; }
269 /// @name Feature Constructors
272 /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
275 /// \param Triple This argument is used to determine the target machine
276 /// feature set; it should always be provided. Generally this should be
277 /// either the target triple from the module, or the target triple of the
278 /// host if that does not exist.
279 MCAsmInfo *createMCAsmInfo(const MCRegisterInfo &MRI,
280 StringRef Triple) const {
281 if (!MCAsmInfoCtorFn)
283 return MCAsmInfoCtorFn(MRI, Triple);
286 /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
288 MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model RM,
290 CodeGenOpt::Level OL) const {
291 if (!MCCodeGenInfoCtorFn)
293 return MCCodeGenInfoCtorFn(Triple, RM, CM, OL);
296 /// createMCInstrInfo - Create a MCInstrInfo implementation.
298 MCInstrInfo *createMCInstrInfo() const {
299 if (!MCInstrInfoCtorFn)
301 return MCInstrInfoCtorFn();
304 /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
306 MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
307 if (!MCInstrAnalysisCtorFn)
309 return MCInstrAnalysisCtorFn(Info);
312 /// createMCRegInfo - Create a MCRegisterInfo implementation.
314 MCRegisterInfo *createMCRegInfo(StringRef Triple) const {
315 if (!MCRegInfoCtorFn)
317 return MCRegInfoCtorFn(Triple);
320 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
322 /// \param Triple This argument is used to determine the target machine
323 /// feature set; it should always be provided. Generally this should be
324 /// either the target triple from the module, or the target triple of the
325 /// host if that does not exist.
326 /// \param CPU This specifies the name of the target CPU.
327 /// \param Features This specifies the string representation of the
328 /// additional target features.
329 MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU,
330 StringRef Features) const {
331 if (!MCSubtargetInfoCtorFn)
333 return MCSubtargetInfoCtorFn(Triple, CPU, Features);
336 /// createTargetMachine - Create a target specific machine implementation
337 /// for the specified \p Triple.
339 /// \param Triple This argument is used to determine the target machine
340 /// feature set; it should always be provided. Generally this should be
341 /// either the target triple from the module, or the target triple of the
342 /// host if that does not exist.
343 TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU,
344 StringRef Features, const TargetOptions &Options,
345 Reloc::Model RM = Reloc::Default,
346 CodeModel::Model CM = CodeModel::Default,
347 CodeGenOpt::Level OL = CodeGenOpt::Default) const {
348 if (!TargetMachineCtorFn)
350 return TargetMachineCtorFn(*this, Triple, CPU, Features, Options,
354 /// createMCAsmBackend - Create a target specific assembly parser.
356 /// \param Triple The target triple string.
357 MCAsmBackend *createMCAsmBackend(const MCRegisterInfo &MRI,
358 StringRef Triple, StringRef CPU) const {
359 if (!MCAsmBackendCtorFn)
361 return MCAsmBackendCtorFn(*this, MRI, Triple, CPU);
364 /// createMCAsmParser - Create a target specific assembly parser.
366 /// \param Parser The target independent parser implementation to use for
367 /// parsing and lexing.
368 MCTargetAsmParser *createMCAsmParser(
369 MCSubtargetInfo &STI,
371 const MCInstrInfo &MII,
372 const MCTargetOptions &Options) const {
373 if (!MCAsmParserCtorFn)
375 return MCAsmParserCtorFn(STI, Parser, MII, Options);
378 /// createAsmPrinter - Create a target specific assembly printer pass. This
379 /// takes ownership of the MCStreamer object.
380 AsmPrinter *createAsmPrinter(TargetMachine &TM,
381 std::unique_ptr<MCStreamer> &&Streamer) const {
382 if (!AsmPrinterCtorFn)
384 return AsmPrinterCtorFn(TM, std::move(Streamer));
387 MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI,
388 MCContext &Ctx) const {
389 if (!MCDisassemblerCtorFn)
391 return MCDisassemblerCtorFn(*this, STI, Ctx);
394 MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
395 const MCAsmInfo &MAI,
396 const MCInstrInfo &MII,
397 const MCRegisterInfo &MRI,
398 const MCSubtargetInfo &STI) const {
399 if (!MCInstPrinterCtorFn)
401 return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, MII, MRI, STI);
405 /// createMCCodeEmitter - Create a target specific code emitter.
406 MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
407 const MCRegisterInfo &MRI,
408 MCContext &Ctx) const {
409 if (!MCCodeEmitterCtorFn)
411 return MCCodeEmitterCtorFn(II, MRI, Ctx);
414 /// createMCObjectStreamer - Create a target specific MCStreamer.
416 /// \param TT The target triple.
417 /// \param Ctx The target context.
418 /// \param TAB The target assembler backend object. Takes ownership.
419 /// \param OS The stream object.
420 /// \param Emitter The target independent assembler object.Takes ownership.
421 /// \param RelaxAll Relax all fixups?
422 MCStreamer *createMCObjectStreamer(StringRef TT, MCContext &Ctx,
423 MCAsmBackend &TAB, raw_ostream &OS,
424 MCCodeEmitter *Emitter,
425 const MCSubtargetInfo &STI,
426 bool RelaxAll) const {
427 if (!MCObjectStreamerCtorFn)
429 return MCObjectStreamerCtorFn(*this, TT, Ctx, TAB, OS, Emitter, STI,
433 /// createAsmStreamer - Create a target specific MCStreamer.
434 MCStreamer *createAsmStreamer(MCContext &Ctx,
435 formatted_raw_ostream &OS,
437 bool useDwarfDirectory,
438 MCInstPrinter *InstPrint,
441 bool ShowInst) const {
442 if (AsmStreamerCtorFn)
443 return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useDwarfDirectory,
444 InstPrint, CE, TAB, ShowInst);
445 return llvm::createAsmStreamer(Ctx, OS, isVerboseAsm, useDwarfDirectory,
446 InstPrint, CE, TAB, ShowInst);
449 MCStreamer *createNullStreamer(MCContext &Ctx) const {
450 MCStreamer *S = llvm::createNullStreamer(Ctx);
451 createNullTargetStreamer(*S);
455 MCTargetStreamer *createNullTargetStreamer(MCStreamer &S) const {
456 if (NullTargetStreamerCtorFn)
457 return NullTargetStreamerCtorFn(S);
461 /// createMCRelocationInfo - Create a target specific MCRelocationInfo.
463 /// \param TT The target triple.
464 /// \param Ctx The target context.
466 createMCRelocationInfo(StringRef TT, MCContext &Ctx) const {
467 MCRelocationInfoCtorTy Fn = MCRelocationInfoCtorFn
468 ? MCRelocationInfoCtorFn
469 : llvm::createMCRelocationInfo;
473 /// createMCSymbolizer - Create a target specific MCSymbolizer.
475 /// \param TT The target triple.
476 /// \param GetOpInfo The function to get the symbolic information for operands.
477 /// \param SymbolLookUp The function to lookup a symbol name.
478 /// \param DisInfo The pointer to the block of symbolic information for above call
480 /// \param Ctx The target context.
481 /// \param RelInfo The relocation information for this target. Takes ownership.
483 createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
484 LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo,
486 std::unique_ptr<MCRelocationInfo> &&RelInfo) const {
487 MCSymbolizerCtorTy Fn =
488 MCSymbolizerCtorFn ? MCSymbolizerCtorFn : llvm::createMCSymbolizer;
489 return Fn(TT, GetOpInfo, SymbolLookUp, DisInfo, Ctx, std::move(RelInfo));
495 /// TargetRegistry - Generic interface to target specific features.
496 struct TargetRegistry {
498 const Target *Current;
499 explicit iterator(Target *T) : Current(T) {}
500 friend struct TargetRegistry;
502 iterator() : Current(nullptr) {}
504 bool operator==(const iterator &x) const {
505 return Current == x.Current;
507 bool operator!=(const iterator &x) const {
508 return !operator==(x);
511 // Iterator traversal: forward iteration only
512 iterator &operator++() { // Preincrement
513 assert(Current && "Cannot increment end iterator!");
514 Current = Current->getNext();
517 iterator operator++(int) { // Postincrement
518 iterator tmp = *this;
523 const Target &operator*() const {
524 assert(Current && "Cannot dereference end iterator!");
528 const Target *operator->() const {
533 /// printRegisteredTargetsForVersion - Print the registered targets
534 /// appropriately for inclusion in a tool's version output.
535 static void printRegisteredTargetsForVersion();
537 /// @name Registry Access
540 static iterator begin();
542 static iterator end() { return iterator(); }
544 /// lookupTarget - Lookup a target based on a target triple.
546 /// \param Triple - The triple to use for finding a target.
547 /// \param Error - On failure, an error string describing why no target was
549 static const Target *lookupTarget(const std::string &Triple,
552 /// lookupTarget - Lookup a target based on an architecture name
553 /// and a target triple. If the architecture name is non-empty,
554 /// then the lookup is done by architecture. Otherwise, the target
557 /// \param ArchName - The architecture to use for finding a target.
558 /// \param TheTriple - The triple to use for finding a target. The
559 /// triple is updated with canonical architecture name if a lookup
560 /// by architecture is done.
561 /// \param Error - On failure, an error string describing why no target was
563 static const Target *lookupTarget(const std::string &ArchName,
568 /// @name Target Registration
571 /// RegisterTarget - Register the given target. Attempts to register a
572 /// target which has already been registered will be ignored.
574 /// Clients are responsible for ensuring that registration doesn't occur
575 /// while another thread is attempting to access the registry. Typically
576 /// this is done by initializing all targets at program startup.
578 /// @param T - The target being registered.
579 /// @param Name - The target name. This should be a static string.
580 /// @param ShortDesc - A short target description. This should be a static
582 /// @param ArchMatchFn - The arch match checking function for this target.
583 /// @param HasJIT - Whether the target supports JIT code
585 static void RegisterTarget(Target &T,
587 const char *ShortDesc,
588 Target::ArchMatchFnTy ArchMatchFn,
589 bool HasJIT = false);
591 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
594 /// Clients are responsible for ensuring that registration doesn't occur
595 /// while another thread is attempting to access the registry. Typically
596 /// this is done by initializing all targets at program startup.
598 /// @param T - The target being registered.
599 /// @param Fn - A function to construct a MCAsmInfo for the target.
600 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
601 T.MCAsmInfoCtorFn = Fn;
604 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
607 /// Clients are responsible for ensuring that registration doesn't occur
608 /// while another thread is attempting to access the registry. Typically
609 /// this is done by initializing all targets at program startup.
611 /// @param T - The target being registered.
612 /// @param Fn - A function to construct a MCCodeGenInfo for the target.
613 static void RegisterMCCodeGenInfo(Target &T,
614 Target::MCCodeGenInfoCtorFnTy Fn) {
615 T.MCCodeGenInfoCtorFn = Fn;
618 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
621 /// Clients are responsible for ensuring that registration doesn't occur
622 /// while another thread is attempting to access the registry. Typically
623 /// this is done by initializing all targets at program startup.
625 /// @param T - The target being registered.
626 /// @param Fn - A function to construct a MCInstrInfo for the target.
627 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
628 T.MCInstrInfoCtorFn = Fn;
631 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
632 /// the given target.
633 static void RegisterMCInstrAnalysis(Target &T,
634 Target::MCInstrAnalysisCtorFnTy Fn) {
635 T.MCInstrAnalysisCtorFn = Fn;
638 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
641 /// Clients are responsible for ensuring that registration doesn't occur
642 /// while another thread is attempting to access the registry. Typically
643 /// this is done by initializing all targets at program startup.
645 /// @param T - The target being registered.
646 /// @param Fn - A function to construct a MCRegisterInfo for the target.
647 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
648 T.MCRegInfoCtorFn = Fn;
651 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
652 /// the given target.
654 /// Clients are responsible for ensuring that registration doesn't occur
655 /// while another thread is attempting to access the registry. Typically
656 /// this is done by initializing all targets at program startup.
658 /// @param T - The target being registered.
659 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
660 static void RegisterMCSubtargetInfo(Target &T,
661 Target::MCSubtargetInfoCtorFnTy Fn) {
662 T.MCSubtargetInfoCtorFn = Fn;
665 /// RegisterTargetMachine - Register a TargetMachine implementation for the
668 /// Clients are responsible for ensuring that registration doesn't occur
669 /// while another thread is attempting to access the registry. Typically
670 /// this is done by initializing all targets at program startup.
672 /// @param T - The target being registered.
673 /// @param Fn - A function to construct a TargetMachine for the target.
674 static void RegisterTargetMachine(Target &T,
675 Target::TargetMachineCtorTy Fn) {
676 T.TargetMachineCtorFn = Fn;
679 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
682 /// Clients are responsible for ensuring that registration doesn't occur
683 /// while another thread is attempting to access the registry. Typically
684 /// this is done by initializing all targets at program startup.
686 /// @param T - The target being registered.
687 /// @param Fn - A function to construct an AsmBackend for the target.
688 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
689 T.MCAsmBackendCtorFn = Fn;
692 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
693 /// the given target.
695 /// Clients are responsible for ensuring that registration doesn't occur
696 /// while another thread is attempting to access the registry. Typically
697 /// this is done by initializing all targets at program startup.
699 /// @param T - The target being registered.
700 /// @param Fn - A function to construct an MCTargetAsmParser for the target.
701 static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
702 T.MCAsmParserCtorFn = Fn;
705 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
708 /// Clients are responsible for ensuring that registration doesn't occur
709 /// while another thread is attempting to access the registry. Typically
710 /// this is done by initializing all targets at program startup.
712 /// @param T - The target being registered.
713 /// @param Fn - A function to construct an AsmPrinter for the target.
714 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
715 T.AsmPrinterCtorFn = Fn;
718 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
719 /// the given target.
721 /// Clients are responsible for ensuring that registration doesn't occur
722 /// while another thread is attempting to access the registry. Typically
723 /// this is done by initializing all targets at program startup.
725 /// @param T - The target being registered.
726 /// @param Fn - A function to construct an MCDisassembler for the target.
727 static void RegisterMCDisassembler(Target &T,
728 Target::MCDisassemblerCtorTy Fn) {
729 T.MCDisassemblerCtorFn = Fn;
732 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
735 /// Clients are responsible for ensuring that registration doesn't occur
736 /// while another thread is attempting to access the registry. Typically
737 /// this is done by initializing all targets at program startup.
739 /// @param T - The target being registered.
740 /// @param Fn - A function to construct an MCInstPrinter for the target.
741 static void RegisterMCInstPrinter(Target &T,
742 Target::MCInstPrinterCtorTy Fn) {
743 T.MCInstPrinterCtorFn = Fn;
746 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
749 /// Clients are responsible for ensuring that registration doesn't occur
750 /// while another thread is attempting to access the registry. Typically
751 /// this is done by initializing all targets at program startup.
753 /// @param T - The target being registered.
754 /// @param Fn - A function to construct an MCCodeEmitter for the target.
755 static void RegisterMCCodeEmitter(Target &T,
756 Target::MCCodeEmitterCtorTy Fn) {
757 T.MCCodeEmitterCtorFn = Fn;
760 /// RegisterMCObjectStreamer - Register a object code MCStreamer
761 /// implementation for the given target.
763 /// Clients are responsible for ensuring that registration doesn't occur
764 /// while another thread is attempting to access the registry. Typically
765 /// this is done by initializing all targets at program startup.
767 /// @param T - The target being registered.
768 /// @param Fn - A function to construct an MCStreamer for the target.
769 static void RegisterMCObjectStreamer(Target &T,
770 Target::MCObjectStreamerCtorTy Fn) {
771 T.MCObjectStreamerCtorFn = Fn;
774 /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
775 /// for the given target.
777 /// Clients are responsible for ensuring that registration doesn't occur
778 /// while another thread is attempting to access the registry. Typically
779 /// this is done by initializing all targets at program startup.
781 /// @param T - The target being registered.
782 /// @param Fn - A function to construct an MCStreamer for the target.
783 static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
784 T.AsmStreamerCtorFn = Fn;
788 RegisterNullTargetStreamer(Target &T, Target::NullTargetStreamerCtorTy Fn) {
789 T.NullTargetStreamerCtorFn = Fn;
792 /// RegisterMCRelocationInfo - Register an MCRelocationInfo
793 /// implementation for the given target.
795 /// Clients are responsible for ensuring that registration doesn't occur
796 /// while another thread is attempting to access the registry. Typically
797 /// this is done by initializing all targets at program startup.
799 /// @param T - The target being registered.
800 /// @param Fn - A function to construct an MCRelocationInfo for the target.
801 static void RegisterMCRelocationInfo(Target &T,
802 Target::MCRelocationInfoCtorTy Fn) {
803 T.MCRelocationInfoCtorFn = Fn;
806 /// RegisterMCSymbolizer - Register an MCSymbolizer
807 /// implementation for the given target.
809 /// Clients are responsible for ensuring that registration doesn't occur
810 /// while another thread is attempting to access the registry. Typically
811 /// this is done by initializing all targets at program startup.
813 /// @param T - The target being registered.
814 /// @param Fn - A function to construct an MCSymbolizer for the target.
815 static void RegisterMCSymbolizer(Target &T,
816 Target::MCSymbolizerCtorTy Fn) {
817 T.MCSymbolizerCtorFn = Fn;
824 //===--------------------------------------------------------------------===//
826 /// RegisterTarget - Helper template for registering a target, for use in the
827 /// target's initialization function. Usage:
830 /// Target TheFooTarget; // The global target instance.
832 /// extern "C" void LLVMInitializeFooTargetInfo() {
833 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
835 template<Triple::ArchType TargetArchType = Triple::UnknownArch,
837 struct RegisterTarget {
838 RegisterTarget(Target &T, const char *Name, const char *Desc) {
839 TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch, HasJIT);
842 static bool getArchMatch(Triple::ArchType Arch) {
843 return Arch == TargetArchType;
847 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
848 /// implementation. This invokes the static "Create" method on the class to
849 /// actually do the construction. Usage:
851 /// extern "C" void LLVMInitializeFooTarget() {
852 /// extern Target TheFooTarget;
853 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
855 template<class MCAsmInfoImpl>
856 struct RegisterMCAsmInfo {
857 RegisterMCAsmInfo(Target &T) {
858 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
861 static MCAsmInfo *Allocator(const MCRegisterInfo &/*MRI*/, StringRef TT) {
862 return new MCAsmInfoImpl(TT);
867 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
868 /// implementation. This invokes the specified function to do the
869 /// construction. Usage:
871 /// extern "C" void LLVMInitializeFooTarget() {
872 /// extern Target TheFooTarget;
873 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
875 struct RegisterMCAsmInfoFn {
876 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
877 TargetRegistry::RegisterMCAsmInfo(T, Fn);
881 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
882 /// implementation. This invokes the static "Create" method on the class
883 /// to actually do the construction. Usage:
885 /// extern "C" void LLVMInitializeFooTarget() {
886 /// extern Target TheFooTarget;
887 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
889 template<class MCCodeGenInfoImpl>
890 struct RegisterMCCodeGenInfo {
891 RegisterMCCodeGenInfo(Target &T) {
892 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
895 static MCCodeGenInfo *Allocator(StringRef /*TT*/, Reloc::Model /*RM*/,
896 CodeModel::Model /*CM*/,
897 CodeGenOpt::Level /*OL*/) {
898 return new MCCodeGenInfoImpl();
902 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
903 /// info implementation. This invokes the specified function to do the
904 /// construction. Usage:
906 /// extern "C" void LLVMInitializeFooTarget() {
907 /// extern Target TheFooTarget;
908 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
910 struct RegisterMCCodeGenInfoFn {
911 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
912 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
916 /// RegisterMCInstrInfo - Helper template for registering a target instruction
917 /// info implementation. This invokes the static "Create" method on the class
918 /// to actually do the construction. Usage:
920 /// extern "C" void LLVMInitializeFooTarget() {
921 /// extern Target TheFooTarget;
922 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
924 template<class MCInstrInfoImpl>
925 struct RegisterMCInstrInfo {
926 RegisterMCInstrInfo(Target &T) {
927 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
930 static MCInstrInfo *Allocator() {
931 return new MCInstrInfoImpl();
935 /// RegisterMCInstrInfoFn - Helper template for registering a target
936 /// instruction info implementation. This invokes the specified function to
937 /// do the construction. Usage:
939 /// extern "C" void LLVMInitializeFooTarget() {
940 /// extern Target TheFooTarget;
941 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
943 struct RegisterMCInstrInfoFn {
944 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
945 TargetRegistry::RegisterMCInstrInfo(T, Fn);
949 /// RegisterMCInstrAnalysis - Helper template for registering a target
950 /// instruction analyzer implementation. This invokes the static "Create"
951 /// method on the class to actually do the construction. Usage:
953 /// extern "C" void LLVMInitializeFooTarget() {
954 /// extern Target TheFooTarget;
955 /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
957 template<class MCInstrAnalysisImpl>
958 struct RegisterMCInstrAnalysis {
959 RegisterMCInstrAnalysis(Target &T) {
960 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
963 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
964 return new MCInstrAnalysisImpl(Info);
968 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
969 /// instruction analyzer implementation. This invokes the specified function
970 /// to do the construction. Usage:
972 /// extern "C" void LLVMInitializeFooTarget() {
973 /// extern Target TheFooTarget;
974 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
976 struct RegisterMCInstrAnalysisFn {
977 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
978 TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
982 /// RegisterMCRegInfo - Helper template for registering a target register info
983 /// implementation. This invokes the static "Create" method on the class to
984 /// actually do the construction. Usage:
986 /// extern "C" void LLVMInitializeFooTarget() {
987 /// extern Target TheFooTarget;
988 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
990 template<class MCRegisterInfoImpl>
991 struct RegisterMCRegInfo {
992 RegisterMCRegInfo(Target &T) {
993 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
996 static MCRegisterInfo *Allocator(StringRef /*TT*/) {
997 return new MCRegisterInfoImpl();
1001 /// RegisterMCRegInfoFn - Helper template for registering a target register
1002 /// info implementation. This invokes the specified function to do the
1003 /// construction. Usage:
1005 /// extern "C" void LLVMInitializeFooTarget() {
1006 /// extern Target TheFooTarget;
1007 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
1009 struct RegisterMCRegInfoFn {
1010 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
1011 TargetRegistry::RegisterMCRegInfo(T, Fn);
1015 /// RegisterMCSubtargetInfo - Helper template for registering a target
1016 /// subtarget info implementation. This invokes the static "Create" method
1017 /// on the class to actually do the construction. Usage:
1019 /// extern "C" void LLVMInitializeFooTarget() {
1020 /// extern Target TheFooTarget;
1021 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
1023 template<class MCSubtargetInfoImpl>
1024 struct RegisterMCSubtargetInfo {
1025 RegisterMCSubtargetInfo(Target &T) {
1026 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
1029 static MCSubtargetInfo *Allocator(StringRef /*TT*/, StringRef /*CPU*/,
1031 return new MCSubtargetInfoImpl();
1035 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
1036 /// subtarget info implementation. This invokes the specified function to
1037 /// do the construction. Usage:
1039 /// extern "C" void LLVMInitializeFooTarget() {
1040 /// extern Target TheFooTarget;
1041 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1043 struct RegisterMCSubtargetInfoFn {
1044 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
1045 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
1049 /// RegisterTargetMachine - Helper template for registering a target machine
1050 /// implementation, for use in the target machine initialization
1051 /// function. Usage:
1053 /// extern "C" void LLVMInitializeFooTarget() {
1054 /// extern Target TheFooTarget;
1055 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1057 template<class TargetMachineImpl>
1058 struct RegisterTargetMachine {
1059 RegisterTargetMachine(Target &T) {
1060 TargetRegistry::RegisterTargetMachine(T, &Allocator);
1064 static TargetMachine *Allocator(const Target &T, StringRef TT,
1065 StringRef CPU, StringRef FS,
1066 const TargetOptions &Options,
1068 CodeModel::Model CM,
1069 CodeGenOpt::Level OL) {
1070 return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
1074 /// RegisterMCAsmBackend - Helper template for registering a target specific
1075 /// assembler backend. Usage:
1077 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1078 /// extern Target TheFooTarget;
1079 /// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1081 template<class MCAsmBackendImpl>
1082 struct RegisterMCAsmBackend {
1083 RegisterMCAsmBackend(Target &T) {
1084 TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1088 static MCAsmBackend *Allocator(const Target &T,
1089 const MCRegisterInfo &MRI,
1090 StringRef Triple, StringRef CPU) {
1091 return new MCAsmBackendImpl(T, MRI, Triple, CPU);
1095 /// RegisterMCAsmParser - Helper template for registering a target specific
1096 /// assembly parser, for use in the target machine initialization
1097 /// function. Usage:
1099 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1100 /// extern Target TheFooTarget;
1101 /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1103 template<class MCAsmParserImpl>
1104 struct RegisterMCAsmParser {
1105 RegisterMCAsmParser(Target &T) {
1106 TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1110 static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P,
1111 const MCInstrInfo &MII,
1112 const MCTargetOptions &Options) {
1113 return new MCAsmParserImpl(STI, P, MII, Options);
1117 /// RegisterAsmPrinter - Helper template for registering a target specific
1118 /// assembly printer, for use in the target machine initialization
1119 /// function. Usage:
1121 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1122 /// extern Target TheFooTarget;
1123 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1125 template<class AsmPrinterImpl>
1126 struct RegisterAsmPrinter {
1127 RegisterAsmPrinter(Target &T) {
1128 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1132 static AsmPrinter *Allocator(TargetMachine &TM,
1133 std::unique_ptr<MCStreamer> &&Streamer) {
1134 return new AsmPrinterImpl(TM, std::move(Streamer));
1138 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1139 /// machine code emitter, for use in the target initialization
1140 /// function. Usage:
1142 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1143 /// extern Target TheFooTarget;
1144 /// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1146 template<class MCCodeEmitterImpl>
1147 struct RegisterMCCodeEmitter {
1148 RegisterMCCodeEmitter(Target &T) {
1149 TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1153 static MCCodeEmitter *Allocator(const MCInstrInfo & /*II*/,
1154 const MCRegisterInfo & /*MRI*/,
1155 MCContext & /*Ctx*/) {
1156 return new MCCodeEmitterImpl();