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 MCStreamer *(*NullStreamerCtorTy)(MCContext &Ctx);
143 typedef MCTargetStreamer *(*NullTargetStreamerCtorTy)(MCStreamer &S);
144 typedef MCRelocationInfo *(*MCRelocationInfoCtorTy)(StringRef TT,
146 typedef MCSymbolizer *(*MCSymbolizerCtorTy)(
147 StringRef TT, LLVMOpInfoCallback GetOpInfo,
148 LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo, MCContext *Ctx,
149 std::unique_ptr<MCRelocationInfo> &&RelInfo);
152 /// Next - The next registered target in the linked list, maintained by the
156 /// The target function for checking if an architecture is supported.
157 ArchMatchFnTy ArchMatchFn;
159 /// Name - The target name.
162 /// ShortDesc - A short description of the target.
163 const char *ShortDesc;
165 /// HasJIT - Whether this target supports the JIT.
168 /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
170 MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
172 /// MCCodeGenInfoCtorFn - Constructor function for this target's
173 /// MCCodeGenInfo, if registered.
174 MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn;
176 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
178 MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
180 /// MCInstrAnalysisCtorFn - Constructor function for this target's
181 /// MCInstrAnalysis, if registered.
182 MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
184 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
186 MCRegInfoCtorFnTy MCRegInfoCtorFn;
188 /// MCSubtargetInfoCtorFn - Constructor function for this target's
189 /// MCSubtargetInfo, if registered.
190 MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
192 /// TargetMachineCtorFn - Construction function for this target's
193 /// TargetMachine, if registered.
194 TargetMachineCtorTy TargetMachineCtorFn;
196 /// MCAsmBackendCtorFn - Construction function for this target's
197 /// MCAsmBackend, if registered.
198 MCAsmBackendCtorTy MCAsmBackendCtorFn;
200 /// MCAsmParserCtorFn - Construction function for this target's
201 /// MCTargetAsmParser, if registered.
202 MCAsmParserCtorTy MCAsmParserCtorFn;
204 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
206 AsmPrinterCtorTy AsmPrinterCtorFn;
208 /// MCDisassemblerCtorFn - Construction function for this target's
209 /// MCDisassembler, if registered.
210 MCDisassemblerCtorTy MCDisassemblerCtorFn;
212 /// MCInstPrinterCtorFn - Construction function for this target's
213 /// MCInstPrinter, if registered.
214 MCInstPrinterCtorTy MCInstPrinterCtorFn;
216 /// MCCodeEmitterCtorFn - Construction function for this target's
217 /// CodeEmitter, if registered.
218 MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
220 /// MCObjectStreamerCtorFn - Construction function for this target's
221 /// MCObjectStreamer, if registered.
222 MCObjectStreamerCtorTy MCObjectStreamerCtorFn;
224 /// AsmStreamerCtorFn - Construction function for this target's
225 /// AsmStreamer, if registered (default = llvm::createAsmStreamer).
226 AsmStreamerCtorTy AsmStreamerCtorFn;
228 /// Construction function for this target's NullStreamer, if registered
229 /// (default = llvm::createNullStreamer).
230 NullStreamerCtorTy NullStreamerCtorFn;
232 /// Construction function for this target's null TargetStreamer, if
233 /// registered (default = nullptr).
234 NullTargetStreamerCtorTy NullTargetStreamerCtorFn;
236 /// MCRelocationInfoCtorFn - Construction function for this target's
237 /// MCRelocationInfo, if registered (default = llvm::createMCRelocationInfo)
238 MCRelocationInfoCtorTy MCRelocationInfoCtorFn;
240 /// MCSymbolizerCtorFn - Construction function for this target's
241 /// MCSymbolizer, if registered (default = llvm::createMCSymbolizer)
242 MCSymbolizerCtorTy MCSymbolizerCtorFn;
246 : AsmStreamerCtorFn(nullptr), NullStreamerCtorFn(nullptr),
247 MCRelocationInfoCtorFn(nullptr), MCSymbolizerCtorFn(nullptr) {}
249 /// @name Target Information
252 // getNext - Return the next registered target.
253 const Target *getNext() const { return Next; }
255 /// getName - Get the target name.
256 const char *getName() const { return Name; }
258 /// getShortDescription - Get a short description of the target.
259 const char *getShortDescription() const { return ShortDesc; }
262 /// @name Feature Predicates
265 /// hasJIT - Check if this targets supports the just-in-time compilation.
266 bool hasJIT() const { return HasJIT; }
268 /// hasTargetMachine - Check if this target supports code generation.
269 bool hasTargetMachine() const { return TargetMachineCtorFn != nullptr; }
271 /// hasMCAsmBackend - Check if this target supports .o generation.
272 bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != nullptr; }
275 /// @name Feature Constructors
278 /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
281 /// \param Triple This argument is used to determine the target machine
282 /// feature set; it should always be provided. Generally this should be
283 /// either the target triple from the module, or the target triple of the
284 /// host if that does not exist.
285 MCAsmInfo *createMCAsmInfo(const MCRegisterInfo &MRI,
286 StringRef Triple) const {
287 if (!MCAsmInfoCtorFn)
289 return MCAsmInfoCtorFn(MRI, Triple);
292 /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
294 MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model RM,
296 CodeGenOpt::Level OL) const {
297 if (!MCCodeGenInfoCtorFn)
299 return MCCodeGenInfoCtorFn(Triple, RM, CM, OL);
302 /// createMCInstrInfo - Create a MCInstrInfo implementation.
304 MCInstrInfo *createMCInstrInfo() const {
305 if (!MCInstrInfoCtorFn)
307 return MCInstrInfoCtorFn();
310 /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
312 MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
313 if (!MCInstrAnalysisCtorFn)
315 return MCInstrAnalysisCtorFn(Info);
318 /// createMCRegInfo - Create a MCRegisterInfo implementation.
320 MCRegisterInfo *createMCRegInfo(StringRef Triple) const {
321 if (!MCRegInfoCtorFn)
323 return MCRegInfoCtorFn(Triple);
326 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
328 /// \param Triple This argument is used to determine the target machine
329 /// feature set; it should always be provided. Generally this should be
330 /// either the target triple from the module, or the target triple of the
331 /// host if that does not exist.
332 /// \param CPU This specifies the name of the target CPU.
333 /// \param Features This specifies the string representation of the
334 /// additional target features.
335 MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU,
336 StringRef Features) const {
337 if (!MCSubtargetInfoCtorFn)
339 return MCSubtargetInfoCtorFn(Triple, CPU, Features);
342 /// createTargetMachine - Create a target specific machine implementation
343 /// for the specified \p Triple.
345 /// \param Triple This argument is used to determine the target machine
346 /// feature set; it should always be provided. Generally this should be
347 /// either the target triple from the module, or the target triple of the
348 /// host if that does not exist.
349 TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU,
350 StringRef Features, const TargetOptions &Options,
351 Reloc::Model RM = Reloc::Default,
352 CodeModel::Model CM = CodeModel::Default,
353 CodeGenOpt::Level OL = CodeGenOpt::Default) const {
354 if (!TargetMachineCtorFn)
356 return TargetMachineCtorFn(*this, Triple, CPU, Features, Options,
360 /// createMCAsmBackend - Create a target specific assembly parser.
362 /// \param Triple The target triple string.
363 MCAsmBackend *createMCAsmBackend(const MCRegisterInfo &MRI,
364 StringRef Triple, StringRef CPU) const {
365 if (!MCAsmBackendCtorFn)
367 return MCAsmBackendCtorFn(*this, MRI, Triple, CPU);
370 /// createMCAsmParser - Create a target specific assembly parser.
372 /// \param Parser The target independent parser implementation to use for
373 /// parsing and lexing.
374 MCTargetAsmParser *createMCAsmParser(
375 MCSubtargetInfo &STI,
377 const MCInstrInfo &MII,
378 const MCTargetOptions &Options) const {
379 if (!MCAsmParserCtorFn)
381 return MCAsmParserCtorFn(STI, Parser, MII, Options);
384 /// createAsmPrinter - Create a target specific assembly printer pass. This
385 /// takes ownership of the MCStreamer object.
386 AsmPrinter *createAsmPrinter(TargetMachine &TM,
387 std::unique_ptr<MCStreamer> &&Streamer) const {
388 if (!AsmPrinterCtorFn)
390 return AsmPrinterCtorFn(TM, std::move(Streamer));
393 MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI,
394 MCContext &Ctx) const {
395 if (!MCDisassemblerCtorFn)
397 return MCDisassemblerCtorFn(*this, STI, Ctx);
400 MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
401 const MCAsmInfo &MAI,
402 const MCInstrInfo &MII,
403 const MCRegisterInfo &MRI,
404 const MCSubtargetInfo &STI) const {
405 if (!MCInstPrinterCtorFn)
407 return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, MII, MRI, STI);
411 /// createMCCodeEmitter - Create a target specific code emitter.
412 MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
413 const MCRegisterInfo &MRI,
414 const MCSubtargetInfo &STI,
415 MCContext &Ctx) const {
416 if (!MCCodeEmitterCtorFn)
418 return MCCodeEmitterCtorFn(II, MRI, STI, Ctx);
421 /// createMCObjectStreamer - Create a target specific MCStreamer.
423 /// \param TT The target triple.
424 /// \param Ctx The target context.
425 /// \param TAB The target assembler backend object. Takes ownership.
426 /// \param _OS The stream object.
427 /// \param _Emitter The target independent assembler object.Takes ownership.
428 /// \param RelaxAll Relax all fixups?
429 MCStreamer *createMCObjectStreamer(StringRef TT, MCContext &Ctx,
430 MCAsmBackend &TAB, raw_ostream &_OS,
431 MCCodeEmitter *_Emitter,
432 const MCSubtargetInfo &STI,
433 bool RelaxAll) const {
434 if (!MCObjectStreamerCtorFn)
436 return MCObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter, STI,
440 /// createAsmStreamer - Create a target specific MCStreamer.
441 MCStreamer *createAsmStreamer(MCContext &Ctx,
442 formatted_raw_ostream &OS,
444 bool useDwarfDirectory,
445 MCInstPrinter *InstPrint,
448 bool ShowInst) const {
449 if (AsmStreamerCtorFn)
450 return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useDwarfDirectory,
451 InstPrint, CE, TAB, ShowInst);
452 return llvm::createAsmStreamer(Ctx, OS, isVerboseAsm, useDwarfDirectory,
453 InstPrint, CE, TAB, ShowInst);
456 MCStreamer *createNullStreamer(MCContext &Ctx) const {
457 if (NullStreamerCtorFn)
458 return NullStreamerCtorFn(Ctx);
459 return llvm::createNullStreamer(Ctx);
462 MCTargetStreamer *createNullTargetStreamer(MCStreamer &S) const {
463 if (NullTargetStreamerCtorFn)
464 return NullTargetStreamerCtorFn(S);
468 /// createMCRelocationInfo - Create a target specific MCRelocationInfo.
470 /// \param TT The target triple.
471 /// \param Ctx The target context.
473 createMCRelocationInfo(StringRef TT, MCContext &Ctx) const {
474 MCRelocationInfoCtorTy Fn = MCRelocationInfoCtorFn
475 ? MCRelocationInfoCtorFn
476 : llvm::createMCRelocationInfo;
480 /// createMCSymbolizer - Create a target specific MCSymbolizer.
482 /// \param TT The target triple.
483 /// \param GetOpInfo The function to get the symbolic information for operands.
484 /// \param SymbolLookUp The function to lookup a symbol name.
485 /// \param DisInfo The pointer to the block of symbolic information for above call
487 /// \param Ctx The target context.
488 /// \param RelInfo The relocation information for this target. Takes ownership.
490 createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
491 LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo,
493 std::unique_ptr<MCRelocationInfo> &&RelInfo) const {
494 MCSymbolizerCtorTy Fn =
495 MCSymbolizerCtorFn ? MCSymbolizerCtorFn : llvm::createMCSymbolizer;
496 return Fn(TT, GetOpInfo, SymbolLookUp, DisInfo, Ctx, std::move(RelInfo));
502 /// TargetRegistry - Generic interface to target specific features.
503 struct TargetRegistry {
505 const Target *Current;
506 explicit iterator(Target *T) : Current(T) {}
507 friend struct TargetRegistry;
509 iterator() : Current(nullptr) {}
511 bool operator==(const iterator &x) const {
512 return Current == x.Current;
514 bool operator!=(const iterator &x) const {
515 return !operator==(x);
518 // Iterator traversal: forward iteration only
519 iterator &operator++() { // Preincrement
520 assert(Current && "Cannot increment end iterator!");
521 Current = Current->getNext();
524 iterator operator++(int) { // Postincrement
525 iterator tmp = *this;
530 const Target &operator*() const {
531 assert(Current && "Cannot dereference end iterator!");
535 const Target *operator->() const {
540 /// printRegisteredTargetsForVersion - Print the registered targets
541 /// appropriately for inclusion in a tool's version output.
542 static void printRegisteredTargetsForVersion();
544 /// @name Registry Access
547 static iterator begin();
549 static iterator end() { return iterator(); }
551 /// lookupTarget - Lookup a target based on a target triple.
553 /// \param Triple - The triple to use for finding a target.
554 /// \param Error - On failure, an error string describing why no target was
556 static const Target *lookupTarget(const std::string &Triple,
559 /// lookupTarget - Lookup a target based on an architecture name
560 /// and a target triple. If the architecture name is non-empty,
561 /// then the lookup is done by architecture. Otherwise, the target
564 /// \param ArchName - The architecture to use for finding a target.
565 /// \param TheTriple - The triple to use for finding a target. The
566 /// triple is updated with canonical architecture name if a lookup
567 /// by architecture is done.
568 /// \param Error - On failure, an error string describing why no target was
570 static const Target *lookupTarget(const std::string &ArchName,
575 /// @name Target Registration
578 /// RegisterTarget - Register the given target. Attempts to register a
579 /// target which has already been registered will be ignored.
581 /// Clients are responsible for ensuring that registration doesn't occur
582 /// while another thread is attempting to access the registry. Typically
583 /// this is done by initializing all targets at program startup.
585 /// @param T - The target being registered.
586 /// @param Name - The target name. This should be a static string.
587 /// @param ShortDesc - A short target description. This should be a static
589 /// @param ArchMatchFn - The arch match checking function for this target.
590 /// @param HasJIT - Whether the target supports JIT code
592 static void RegisterTarget(Target &T,
594 const char *ShortDesc,
595 Target::ArchMatchFnTy ArchMatchFn,
596 bool HasJIT = false);
598 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
601 /// Clients are responsible for ensuring that registration doesn't occur
602 /// while another thread is attempting to access the registry. Typically
603 /// this is done by initializing all targets at program startup.
605 /// @param T - The target being registered.
606 /// @param Fn - A function to construct a MCAsmInfo for the target.
607 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
608 T.MCAsmInfoCtorFn = Fn;
611 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
614 /// Clients are responsible for ensuring that registration doesn't occur
615 /// while another thread is attempting to access the registry. Typically
616 /// this is done by initializing all targets at program startup.
618 /// @param T - The target being registered.
619 /// @param Fn - A function to construct a MCCodeGenInfo for the target.
620 static void RegisterMCCodeGenInfo(Target &T,
621 Target::MCCodeGenInfoCtorFnTy Fn) {
622 T.MCCodeGenInfoCtorFn = Fn;
625 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
628 /// Clients are responsible for ensuring that registration doesn't occur
629 /// while another thread is attempting to access the registry. Typically
630 /// this is done by initializing all targets at program startup.
632 /// @param T - The target being registered.
633 /// @param Fn - A function to construct a MCInstrInfo for the target.
634 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
635 T.MCInstrInfoCtorFn = Fn;
638 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
639 /// the given target.
640 static void RegisterMCInstrAnalysis(Target &T,
641 Target::MCInstrAnalysisCtorFnTy Fn) {
642 T.MCInstrAnalysisCtorFn = Fn;
645 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
648 /// Clients are responsible for ensuring that registration doesn't occur
649 /// while another thread is attempting to access the registry. Typically
650 /// this is done by initializing all targets at program startup.
652 /// @param T - The target being registered.
653 /// @param Fn - A function to construct a MCRegisterInfo for the target.
654 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
655 T.MCRegInfoCtorFn = Fn;
658 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
659 /// the given target.
661 /// Clients are responsible for ensuring that registration doesn't occur
662 /// while another thread is attempting to access the registry. Typically
663 /// this is done by initializing all targets at program startup.
665 /// @param T - The target being registered.
666 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
667 static void RegisterMCSubtargetInfo(Target &T,
668 Target::MCSubtargetInfoCtorFnTy Fn) {
669 T.MCSubtargetInfoCtorFn = Fn;
672 /// RegisterTargetMachine - Register a TargetMachine implementation for the
675 /// Clients are responsible for ensuring that registration doesn't occur
676 /// while another thread is attempting to access the registry. Typically
677 /// this is done by initializing all targets at program startup.
679 /// @param T - The target being registered.
680 /// @param Fn - A function to construct a TargetMachine for the target.
681 static void RegisterTargetMachine(Target &T,
682 Target::TargetMachineCtorTy Fn) {
683 T.TargetMachineCtorFn = Fn;
686 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
689 /// Clients are responsible for ensuring that registration doesn't occur
690 /// while another thread is attempting to access the registry. Typically
691 /// this is done by initializing all targets at program startup.
693 /// @param T - The target being registered.
694 /// @param Fn - A function to construct an AsmBackend for the target.
695 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
696 T.MCAsmBackendCtorFn = Fn;
699 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
700 /// the given target.
702 /// Clients are responsible for ensuring that registration doesn't occur
703 /// while another thread is attempting to access the registry. Typically
704 /// this is done by initializing all targets at program startup.
706 /// @param T - The target being registered.
707 /// @param Fn - A function to construct an MCTargetAsmParser for the target.
708 static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
709 T.MCAsmParserCtorFn = Fn;
712 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
715 /// Clients are responsible for ensuring that registration doesn't occur
716 /// while another thread is attempting to access the registry. Typically
717 /// this is done by initializing all targets at program startup.
719 /// @param T - The target being registered.
720 /// @param Fn - A function to construct an AsmPrinter for the target.
721 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
722 T.AsmPrinterCtorFn = Fn;
725 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
726 /// the given target.
728 /// Clients are responsible for ensuring that registration doesn't occur
729 /// while another thread is attempting to access the registry. Typically
730 /// this is done by initializing all targets at program startup.
732 /// @param T - The target being registered.
733 /// @param Fn - A function to construct an MCDisassembler for the target.
734 static void RegisterMCDisassembler(Target &T,
735 Target::MCDisassemblerCtorTy Fn) {
736 T.MCDisassemblerCtorFn = Fn;
739 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
742 /// Clients are responsible for ensuring that registration doesn't occur
743 /// while another thread is attempting to access the registry. Typically
744 /// this is done by initializing all targets at program startup.
746 /// @param T - The target being registered.
747 /// @param Fn - A function to construct an MCInstPrinter for the target.
748 static void RegisterMCInstPrinter(Target &T,
749 Target::MCInstPrinterCtorTy Fn) {
750 T.MCInstPrinterCtorFn = Fn;
753 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
756 /// Clients are responsible for ensuring that registration doesn't occur
757 /// while another thread is attempting to access the registry. Typically
758 /// this is done by initializing all targets at program startup.
760 /// @param T - The target being registered.
761 /// @param Fn - A function to construct an MCCodeEmitter for the target.
762 static void RegisterMCCodeEmitter(Target &T,
763 Target::MCCodeEmitterCtorTy Fn) {
764 T.MCCodeEmitterCtorFn = Fn;
767 /// RegisterMCObjectStreamer - Register a object code MCStreamer
768 /// implementation for the given target.
770 /// Clients are responsible for ensuring that registration doesn't occur
771 /// while another thread is attempting to access the registry. Typically
772 /// this is done by initializing all targets at program startup.
774 /// @param T - The target being registered.
775 /// @param Fn - A function to construct an MCStreamer for the target.
776 static void RegisterMCObjectStreamer(Target &T,
777 Target::MCObjectStreamerCtorTy Fn) {
778 T.MCObjectStreamerCtorFn = Fn;
781 /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
782 /// 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 MCStreamer for the target.
790 static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
791 T.AsmStreamerCtorFn = Fn;
794 static void RegisterNullStreamer(Target &T, Target::NullStreamerCtorTy Fn) {
795 T.NullStreamerCtorFn = Fn;
799 RegisterNullTargetStreamer(Target &T, Target::NullTargetStreamerCtorTy Fn) {
800 T.NullTargetStreamerCtorFn = Fn;
803 /// RegisterMCRelocationInfo - Register an MCRelocationInfo
804 /// implementation for the given target.
806 /// Clients are responsible for ensuring that registration doesn't occur
807 /// while another thread is attempting to access the registry. Typically
808 /// this is done by initializing all targets at program startup.
810 /// @param T - The target being registered.
811 /// @param Fn - A function to construct an MCRelocationInfo for the target.
812 static void RegisterMCRelocationInfo(Target &T,
813 Target::MCRelocationInfoCtorTy Fn) {
814 T.MCRelocationInfoCtorFn = Fn;
817 /// RegisterMCSymbolizer - Register an MCSymbolizer
818 /// implementation for the given target.
820 /// Clients are responsible for ensuring that registration doesn't occur
821 /// while another thread is attempting to access the registry. Typically
822 /// this is done by initializing all targets at program startup.
824 /// @param T - The target being registered.
825 /// @param Fn - A function to construct an MCSymbolizer for the target.
826 static void RegisterMCSymbolizer(Target &T,
827 Target::MCSymbolizerCtorTy Fn) {
828 T.MCSymbolizerCtorFn = Fn;
835 //===--------------------------------------------------------------------===//
837 /// RegisterTarget - Helper template for registering a target, for use in the
838 /// target's initialization function. Usage:
841 /// Target TheFooTarget; // The global target instance.
843 /// extern "C" void LLVMInitializeFooTargetInfo() {
844 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
846 template<Triple::ArchType TargetArchType = Triple::UnknownArch,
848 struct RegisterTarget {
849 RegisterTarget(Target &T, const char *Name, const char *Desc) {
850 TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch, HasJIT);
853 static bool getArchMatch(Triple::ArchType Arch) {
854 return Arch == TargetArchType;
858 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
859 /// implementation. This invokes the static "Create" method on the class to
860 /// actually do the construction. Usage:
862 /// extern "C" void LLVMInitializeFooTarget() {
863 /// extern Target TheFooTarget;
864 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
866 template<class MCAsmInfoImpl>
867 struct RegisterMCAsmInfo {
868 RegisterMCAsmInfo(Target &T) {
869 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
872 static MCAsmInfo *Allocator(const MCRegisterInfo &/*MRI*/, StringRef TT) {
873 return new MCAsmInfoImpl(TT);
878 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
879 /// implementation. This invokes the specified function to do the
880 /// construction. Usage:
882 /// extern "C" void LLVMInitializeFooTarget() {
883 /// extern Target TheFooTarget;
884 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
886 struct RegisterMCAsmInfoFn {
887 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
888 TargetRegistry::RegisterMCAsmInfo(T, Fn);
892 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
893 /// implementation. This invokes the static "Create" method on the class
894 /// to actually do the construction. Usage:
896 /// extern "C" void LLVMInitializeFooTarget() {
897 /// extern Target TheFooTarget;
898 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
900 template<class MCCodeGenInfoImpl>
901 struct RegisterMCCodeGenInfo {
902 RegisterMCCodeGenInfo(Target &T) {
903 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
906 static MCCodeGenInfo *Allocator(StringRef /*TT*/, Reloc::Model /*RM*/,
907 CodeModel::Model /*CM*/,
908 CodeGenOpt::Level /*OL*/) {
909 return new MCCodeGenInfoImpl();
913 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
914 /// info implementation. This invokes the specified function to do the
915 /// construction. Usage:
917 /// extern "C" void LLVMInitializeFooTarget() {
918 /// extern Target TheFooTarget;
919 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
921 struct RegisterMCCodeGenInfoFn {
922 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
923 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
927 /// RegisterMCInstrInfo - Helper template for registering a target instruction
928 /// info implementation. This invokes the static "Create" method on the class
929 /// to actually do the construction. Usage:
931 /// extern "C" void LLVMInitializeFooTarget() {
932 /// extern Target TheFooTarget;
933 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
935 template<class MCInstrInfoImpl>
936 struct RegisterMCInstrInfo {
937 RegisterMCInstrInfo(Target &T) {
938 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
941 static MCInstrInfo *Allocator() {
942 return new MCInstrInfoImpl();
946 /// RegisterMCInstrInfoFn - Helper template for registering a target
947 /// instruction info implementation. This invokes the specified function to
948 /// do the construction. Usage:
950 /// extern "C" void LLVMInitializeFooTarget() {
951 /// extern Target TheFooTarget;
952 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
954 struct RegisterMCInstrInfoFn {
955 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
956 TargetRegistry::RegisterMCInstrInfo(T, Fn);
960 /// RegisterMCInstrAnalysis - Helper template for registering a target
961 /// instruction analyzer implementation. This invokes the static "Create"
962 /// method on the class to actually do the construction. Usage:
964 /// extern "C" void LLVMInitializeFooTarget() {
965 /// extern Target TheFooTarget;
966 /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
968 template<class MCInstrAnalysisImpl>
969 struct RegisterMCInstrAnalysis {
970 RegisterMCInstrAnalysis(Target &T) {
971 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
974 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
975 return new MCInstrAnalysisImpl(Info);
979 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
980 /// instruction analyzer implementation. This invokes the specified function
981 /// to do the construction. Usage:
983 /// extern "C" void LLVMInitializeFooTarget() {
984 /// extern Target TheFooTarget;
985 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
987 struct RegisterMCInstrAnalysisFn {
988 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
989 TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
993 /// RegisterMCRegInfo - Helper template for registering a target register info
994 /// implementation. This invokes the static "Create" method on the class to
995 /// actually do the construction. Usage:
997 /// extern "C" void LLVMInitializeFooTarget() {
998 /// extern Target TheFooTarget;
999 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
1001 template<class MCRegisterInfoImpl>
1002 struct RegisterMCRegInfo {
1003 RegisterMCRegInfo(Target &T) {
1004 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
1007 static MCRegisterInfo *Allocator(StringRef /*TT*/) {
1008 return new MCRegisterInfoImpl();
1012 /// RegisterMCRegInfoFn - Helper template for registering a target register
1013 /// info implementation. This invokes the specified function to do the
1014 /// construction. Usage:
1016 /// extern "C" void LLVMInitializeFooTarget() {
1017 /// extern Target TheFooTarget;
1018 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
1020 struct RegisterMCRegInfoFn {
1021 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
1022 TargetRegistry::RegisterMCRegInfo(T, Fn);
1026 /// RegisterMCSubtargetInfo - Helper template for registering a target
1027 /// subtarget info implementation. This invokes the static "Create" method
1028 /// on the class to actually do the construction. Usage:
1030 /// extern "C" void LLVMInitializeFooTarget() {
1031 /// extern Target TheFooTarget;
1032 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
1034 template<class MCSubtargetInfoImpl>
1035 struct RegisterMCSubtargetInfo {
1036 RegisterMCSubtargetInfo(Target &T) {
1037 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
1040 static MCSubtargetInfo *Allocator(StringRef /*TT*/, StringRef /*CPU*/,
1042 return new MCSubtargetInfoImpl();
1046 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
1047 /// subtarget info implementation. This invokes the specified function to
1048 /// do the construction. Usage:
1050 /// extern "C" void LLVMInitializeFooTarget() {
1051 /// extern Target TheFooTarget;
1052 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1054 struct RegisterMCSubtargetInfoFn {
1055 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
1056 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
1060 /// RegisterTargetMachine - Helper template for registering a target machine
1061 /// implementation, for use in the target machine initialization
1062 /// function. Usage:
1064 /// extern "C" void LLVMInitializeFooTarget() {
1065 /// extern Target TheFooTarget;
1066 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1068 template<class TargetMachineImpl>
1069 struct RegisterTargetMachine {
1070 RegisterTargetMachine(Target &T) {
1071 TargetRegistry::RegisterTargetMachine(T, &Allocator);
1075 static TargetMachine *Allocator(const Target &T, StringRef TT,
1076 StringRef CPU, StringRef FS,
1077 const TargetOptions &Options,
1079 CodeModel::Model CM,
1080 CodeGenOpt::Level OL) {
1081 return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
1085 /// RegisterMCAsmBackend - Helper template for registering a target specific
1086 /// assembler backend. Usage:
1088 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1089 /// extern Target TheFooTarget;
1090 /// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1092 template<class MCAsmBackendImpl>
1093 struct RegisterMCAsmBackend {
1094 RegisterMCAsmBackend(Target &T) {
1095 TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1099 static MCAsmBackend *Allocator(const Target &T,
1100 const MCRegisterInfo &MRI,
1101 StringRef Triple, StringRef CPU) {
1102 return new MCAsmBackendImpl(T, MRI, Triple, CPU);
1106 /// RegisterMCAsmParser - Helper template for registering a target specific
1107 /// assembly parser, for use in the target machine initialization
1108 /// function. Usage:
1110 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1111 /// extern Target TheFooTarget;
1112 /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1114 template<class MCAsmParserImpl>
1115 struct RegisterMCAsmParser {
1116 RegisterMCAsmParser(Target &T) {
1117 TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1121 static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P,
1122 const MCInstrInfo &MII,
1123 const MCTargetOptions &Options) {
1124 return new MCAsmParserImpl(STI, P, MII, Options);
1128 /// RegisterAsmPrinter - Helper template for registering a target specific
1129 /// assembly printer, for use in the target machine initialization
1130 /// function. Usage:
1132 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1133 /// extern Target TheFooTarget;
1134 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1136 template<class AsmPrinterImpl>
1137 struct RegisterAsmPrinter {
1138 RegisterAsmPrinter(Target &T) {
1139 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1143 static AsmPrinter *Allocator(TargetMachine &TM,
1144 std::unique_ptr<MCStreamer> &&Streamer) {
1145 return new AsmPrinterImpl(TM, std::move(Streamer));
1149 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1150 /// machine code emitter, for use in the target initialization
1151 /// function. Usage:
1153 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1154 /// extern Target TheFooTarget;
1155 /// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1157 template<class MCCodeEmitterImpl>
1158 struct RegisterMCCodeEmitter {
1159 RegisterMCCodeEmitter(Target &T) {
1160 TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1164 static MCCodeEmitter *Allocator(const MCInstrInfo &/*II*/,
1165 const MCRegisterInfo &/*MRI*/,
1166 const MCSubtargetInfo &/*STI*/,
1167 MCContext &/*Ctx*/) {
1168 return new MCCodeEmitterImpl();