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"
38 class MCInstrAnalysis;
43 class MCSubtargetInfo;
45 class MCRelocationInfo;
46 class MCTargetAsmParser;
47 class MCTargetOptions;
48 class MCTargetStreamer;
52 class formatted_raw_ostream;
54 MCStreamer *createNullStreamer(MCContext &Ctx);
55 MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
56 bool isVerboseAsm, bool useDwarfDirectory,
57 MCInstPrinter *InstPrint, MCCodeEmitter *CE,
58 MCAsmBackend *TAB, bool ShowInst);
60 /// Takes ownership of \p TAB and \p CE.
61 MCStreamer *createELFStreamer(MCContext &Ctx, MCAsmBackend &TAB,
62 raw_ostream &OS, MCCodeEmitter *CE,
64 MCStreamer *createMachOStreamer(MCContext &Ctx, MCAsmBackend &TAB,
65 raw_ostream &OS, MCCodeEmitter *CE,
66 bool RelaxAll, bool DWARFMustBeAtTheEnd,
67 bool LabelSections = false);
69 MCRelocationInfo *createMCRelocationInfo(StringRef TT, MCContext &Ctx);
71 MCSymbolizer *createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
72 LLVMSymbolLookupCallback SymbolLookUp,
73 void *DisInfo, MCContext *Ctx,
74 std::unique_ptr<MCRelocationInfo> &&RelInfo);
76 /// Target - Wrapper for Target specific information.
78 /// For registration purposes, this is a POD type so that targets can be
79 /// registered without the use of static constructors.
81 /// Targets should implement a single global instance of this class (which
82 /// will be zero initialized), and pass that instance to the TargetRegistry as
83 /// part of their initialization.
86 friend struct TargetRegistry;
88 typedef bool (*ArchMatchFnTy)(Triple::ArchType Arch);
90 typedef MCAsmInfo *(*MCAsmInfoCtorFnTy)(const MCRegisterInfo &MRI,
92 typedef MCCodeGenInfo *(*MCCodeGenInfoCtorFnTy)(StringRef TT,
95 CodeGenOpt::Level OL);
96 typedef MCInstrInfo *(*MCInstrInfoCtorFnTy)(void);
97 typedef MCInstrAnalysis *(*MCInstrAnalysisCtorFnTy)(const MCInstrInfo*Info);
98 typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(StringRef TT);
99 typedef MCSubtargetInfo *(*MCSubtargetInfoCtorFnTy)(StringRef TT,
102 typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T,
106 const TargetOptions &Options,
109 CodeGenOpt::Level OL);
110 // If it weren't for layering issues (this header is in llvm/Support, but
111 // depends on MC?) this should take the Streamer by value rather than rvalue
113 typedef AsmPrinter *(*AsmPrinterCtorTy)(
114 TargetMachine &TM, std::unique_ptr<MCStreamer> &&Streamer);
115 typedef MCAsmBackend *(*MCAsmBackendCtorTy)(const Target &T,
116 const MCRegisterInfo &MRI,
119 typedef MCTargetAsmParser *(*MCAsmParserCtorTy)(
120 MCSubtargetInfo &STI,
122 const MCInstrInfo &MII,
123 const MCTargetOptions &Options);
124 typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T,
125 const MCSubtargetInfo &STI,
127 typedef MCInstPrinter *(*MCInstPrinterCtorTy)(unsigned SyntaxVariant,
128 const MCAsmInfo &MAI,
129 const MCInstrInfo &MII,
130 const MCRegisterInfo &MRI,
131 const MCSubtargetInfo &STI);
132 typedef MCCodeEmitter *(*MCCodeEmitterCtorTy)(const MCInstrInfo &II,
133 const MCRegisterInfo &MRI,
135 typedef MCStreamer *(*ELFStreamerCtorTy)(const Triple &T, MCContext &Ctx,
136 MCAsmBackend &TAB, raw_ostream &OS,
137 MCCodeEmitter *Emitter,
139 typedef MCStreamer *(*MachOStreamerCtorTy)(
140 MCContext &Ctx, MCAsmBackend &TAB, raw_ostream &OS,
141 MCCodeEmitter *Emitter, bool RelaxAll, bool DWARFMustBeAtTheEnd);
142 typedef MCStreamer *(*COFFStreamerCtorTy)(MCContext &Ctx, MCAsmBackend &TAB,
144 MCCodeEmitter *Emitter,
146 typedef MCTargetStreamer *(*NullTargetStreamerCtorTy)(MCStreamer &S);
147 typedef MCTargetStreamer *(*AsmTargetStreamerCtorTy)(
148 MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *InstPrint,
150 typedef MCTargetStreamer *(*ObjectTargetStreamerCtorTy)(
151 MCStreamer &S, const MCSubtargetInfo &STI);
152 typedef MCRelocationInfo *(*MCRelocationInfoCtorTy)(StringRef TT,
154 typedef MCSymbolizer *(*MCSymbolizerCtorTy)(
155 StringRef TT, LLVMOpInfoCallback GetOpInfo,
156 LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo, MCContext *Ctx,
157 std::unique_ptr<MCRelocationInfo> &&RelInfo);
160 /// Next - The next registered target in the linked list, maintained by the
164 /// The target function for checking if an architecture is supported.
165 ArchMatchFnTy ArchMatchFn;
167 /// Name - The target name.
170 /// ShortDesc - A short description of the target.
171 const char *ShortDesc;
173 /// HasJIT - Whether this target supports the JIT.
176 /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
178 MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
180 /// MCCodeGenInfoCtorFn - Constructor function for this target's
181 /// MCCodeGenInfo, if registered.
182 MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn;
184 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
186 MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
188 /// MCInstrAnalysisCtorFn - Constructor function for this target's
189 /// MCInstrAnalysis, if registered.
190 MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
192 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
194 MCRegInfoCtorFnTy MCRegInfoCtorFn;
196 /// MCSubtargetInfoCtorFn - Constructor function for this target's
197 /// MCSubtargetInfo, if registered.
198 MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
200 /// TargetMachineCtorFn - Construction function for this target's
201 /// TargetMachine, if registered.
202 TargetMachineCtorTy TargetMachineCtorFn;
204 /// MCAsmBackendCtorFn - Construction function for this target's
205 /// MCAsmBackend, if registered.
206 MCAsmBackendCtorTy MCAsmBackendCtorFn;
208 /// MCAsmParserCtorFn - Construction function for this target's
209 /// MCTargetAsmParser, if registered.
210 MCAsmParserCtorTy MCAsmParserCtorFn;
212 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
214 AsmPrinterCtorTy AsmPrinterCtorFn;
216 /// MCDisassemblerCtorFn - Construction function for this target's
217 /// MCDisassembler, if registered.
218 MCDisassemblerCtorTy MCDisassemblerCtorFn;
220 /// MCInstPrinterCtorFn - Construction function for this target's
221 /// MCInstPrinter, if registered.
222 MCInstPrinterCtorTy MCInstPrinterCtorFn;
224 /// MCCodeEmitterCtorFn - Construction function for this target's
225 /// CodeEmitter, if registered.
226 MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
228 // Construction functions for the various object formats, if registered.
229 COFFStreamerCtorTy COFFStreamerCtorFn;
230 MachOStreamerCtorTy MachOStreamerCtorFn;
231 ELFStreamerCtorTy ELFStreamerCtorFn;
233 /// Construction function for this target's null TargetStreamer, if
234 /// registered (default = nullptr).
235 NullTargetStreamerCtorTy NullTargetStreamerCtorFn;
237 /// Construction function for this target's asm TargetStreamer, if
238 /// registered (default = nullptr).
239 AsmTargetStreamerCtorTy AsmTargetStreamerCtorFn;
241 /// Construction function for this target's obj TargetStreamer, if
242 /// registered (default = nullptr).
243 ObjectTargetStreamerCtorTy ObjectTargetStreamerCtorFn;
245 /// MCRelocationInfoCtorFn - Construction function for this target's
246 /// MCRelocationInfo, if registered (default = llvm::createMCRelocationInfo)
247 MCRelocationInfoCtorTy MCRelocationInfoCtorFn;
249 /// MCSymbolizerCtorFn - Construction function for this target's
250 /// MCSymbolizer, if registered (default = llvm::createMCSymbolizer)
251 MCSymbolizerCtorTy MCSymbolizerCtorFn;
255 : COFFStreamerCtorFn(nullptr), MachOStreamerCtorFn(nullptr),
256 ELFStreamerCtorFn(nullptr), NullTargetStreamerCtorFn(nullptr),
257 AsmTargetStreamerCtorFn(nullptr), ObjectTargetStreamerCtorFn(nullptr),
258 MCRelocationInfoCtorFn(nullptr), MCSymbolizerCtorFn(nullptr) {}
260 /// @name Target Information
263 // getNext - Return the next registered target.
264 const Target *getNext() const { return Next; }
266 /// getName - Get the target name.
267 const char *getName() const { return Name; }
269 /// getShortDescription - Get a short description of the target.
270 const char *getShortDescription() const { return ShortDesc; }
273 /// @name Feature Predicates
276 /// hasJIT - Check if this targets supports the just-in-time compilation.
277 bool hasJIT() const { return HasJIT; }
279 /// hasTargetMachine - Check if this target supports code generation.
280 bool hasTargetMachine() const { return TargetMachineCtorFn != nullptr; }
282 /// hasMCAsmBackend - Check if this target supports .o generation.
283 bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != nullptr; }
286 /// @name Feature Constructors
289 /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
292 /// \param Triple This argument is used to determine the target machine
293 /// feature set; it should always be provided. Generally this should be
294 /// either the target triple from the module, or the target triple of the
295 /// host if that does not exist.
296 MCAsmInfo *createMCAsmInfo(const MCRegisterInfo &MRI,
297 StringRef Triple) const {
298 if (!MCAsmInfoCtorFn)
300 return MCAsmInfoCtorFn(MRI, Triple);
303 /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
305 MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model RM,
307 CodeGenOpt::Level OL) const {
308 if (!MCCodeGenInfoCtorFn)
310 return MCCodeGenInfoCtorFn(Triple, RM, CM, OL);
313 /// createMCInstrInfo - Create a MCInstrInfo implementation.
315 MCInstrInfo *createMCInstrInfo() const {
316 if (!MCInstrInfoCtorFn)
318 return MCInstrInfoCtorFn();
321 /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
323 MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
324 if (!MCInstrAnalysisCtorFn)
326 return MCInstrAnalysisCtorFn(Info);
329 /// createMCRegInfo - Create a MCRegisterInfo implementation.
331 MCRegisterInfo *createMCRegInfo(StringRef Triple) const {
332 if (!MCRegInfoCtorFn)
334 return MCRegInfoCtorFn(Triple);
337 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
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 /// \param CPU This specifies the name of the target CPU.
344 /// \param Features This specifies the string representation of the
345 /// additional target features.
346 MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU,
347 StringRef Features) const {
348 if (!MCSubtargetInfoCtorFn)
350 return MCSubtargetInfoCtorFn(Triple, CPU, Features);
353 /// createTargetMachine - Create a target specific machine implementation
354 /// for the specified \p Triple.
356 /// \param Triple This argument is used to determine the target machine
357 /// feature set; it should always be provided. Generally this should be
358 /// either the target triple from the module, or the target triple of the
359 /// host if that does not exist.
360 TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU,
361 StringRef Features, const TargetOptions &Options,
362 Reloc::Model RM = Reloc::Default,
363 CodeModel::Model CM = CodeModel::Default,
364 CodeGenOpt::Level OL = CodeGenOpt::Default) const {
365 if (!TargetMachineCtorFn)
367 return TargetMachineCtorFn(*this, Triple, CPU, Features, Options,
371 /// createMCAsmBackend - Create a target specific assembly parser.
373 /// \param Triple The target triple string.
374 MCAsmBackend *createMCAsmBackend(const MCRegisterInfo &MRI,
375 StringRef Triple, StringRef CPU) const {
376 if (!MCAsmBackendCtorFn)
378 return MCAsmBackendCtorFn(*this, MRI, Triple, CPU);
381 /// createMCAsmParser - Create a target specific assembly parser.
383 /// \param Parser The target independent parser implementation to use for
384 /// parsing and lexing.
385 MCTargetAsmParser *createMCAsmParser(
386 MCSubtargetInfo &STI,
388 const MCInstrInfo &MII,
389 const MCTargetOptions &Options) const {
390 if (!MCAsmParserCtorFn)
392 return MCAsmParserCtorFn(STI, Parser, MII, Options);
395 /// createAsmPrinter - Create a target specific assembly printer pass. This
396 /// takes ownership of the MCStreamer object.
397 AsmPrinter *createAsmPrinter(TargetMachine &TM,
398 std::unique_ptr<MCStreamer> &&Streamer) const {
399 if (!AsmPrinterCtorFn)
401 return AsmPrinterCtorFn(TM, std::move(Streamer));
404 MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI,
405 MCContext &Ctx) const {
406 if (!MCDisassemblerCtorFn)
408 return MCDisassemblerCtorFn(*this, STI, Ctx);
411 MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
412 const MCAsmInfo &MAI,
413 const MCInstrInfo &MII,
414 const MCRegisterInfo &MRI,
415 const MCSubtargetInfo &STI) const {
416 if (!MCInstPrinterCtorFn)
418 return MCInstPrinterCtorFn(SyntaxVariant, MAI, MII, MRI, STI);
422 /// createMCCodeEmitter - Create a target specific code emitter.
423 MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
424 const MCRegisterInfo &MRI,
425 MCContext &Ctx) const {
426 if (!MCCodeEmitterCtorFn)
428 return MCCodeEmitterCtorFn(II, MRI, Ctx);
431 /// Create a target specific MCStreamer.
433 /// \param T The target triple.
434 /// \param Ctx The target context.
435 /// \param TAB The target assembler backend object. Takes ownership.
436 /// \param OS The stream object.
437 /// \param Emitter The target independent assembler object.Takes ownership.
438 /// \param RelaxAll Relax all fixups?
439 MCStreamer *createMCObjectStreamer(const Triple &T, MCContext &Ctx,
440 MCAsmBackend &TAB, raw_ostream &OS,
441 MCCodeEmitter *Emitter,
442 const MCSubtargetInfo &STI,
444 bool DWARFMustBeAtTheEnd) const {
446 switch (T.getObjectFormat()) {
448 llvm_unreachable("Unknown object format");
450 assert(T.isOSWindows() && "only Windows COFF is supported");
451 S = COFFStreamerCtorFn(Ctx, TAB, OS, Emitter, RelaxAll);
454 if (MachOStreamerCtorFn)
455 S = MachOStreamerCtorFn(Ctx, TAB, OS, Emitter, RelaxAll,
456 DWARFMustBeAtTheEnd);
458 S = createMachOStreamer(Ctx, TAB, OS, Emitter, RelaxAll,
459 DWARFMustBeAtTheEnd);
462 if (ELFStreamerCtorFn)
463 S = ELFStreamerCtorFn(T, Ctx, TAB, OS, Emitter, RelaxAll);
465 S = createELFStreamer(Ctx, TAB, OS, Emitter, RelaxAll);
468 if (ObjectTargetStreamerCtorFn)
469 ObjectTargetStreamerCtorFn(*S, STI);
473 MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
474 bool IsVerboseAsm, bool UseDwarfDirectory,
475 MCInstPrinter *InstPrint, MCCodeEmitter *CE,
476 MCAsmBackend *TAB, bool ShowInst) const {
478 llvm::createAsmStreamer(Ctx, OS, IsVerboseAsm, UseDwarfDirectory,
479 InstPrint, CE, TAB, ShowInst);
480 createAsmTargetStreamer(*S, OS, InstPrint, IsVerboseAsm);
484 MCTargetStreamer *createAsmTargetStreamer(MCStreamer &S,
485 formatted_raw_ostream &OS,
486 MCInstPrinter *InstPrint,
487 bool IsVerboseAsm) const {
488 if (AsmTargetStreamerCtorFn)
489 return AsmTargetStreamerCtorFn(S, OS, InstPrint, IsVerboseAsm);
493 MCStreamer *createNullStreamer(MCContext &Ctx) const {
494 MCStreamer *S = llvm::createNullStreamer(Ctx);
495 createNullTargetStreamer(*S);
499 MCTargetStreamer *createNullTargetStreamer(MCStreamer &S) const {
500 if (NullTargetStreamerCtorFn)
501 return NullTargetStreamerCtorFn(S);
505 /// createMCRelocationInfo - Create a target specific MCRelocationInfo.
507 /// \param TT The target triple.
508 /// \param Ctx The target context.
510 createMCRelocationInfo(StringRef TT, MCContext &Ctx) const {
511 MCRelocationInfoCtorTy Fn = MCRelocationInfoCtorFn
512 ? MCRelocationInfoCtorFn
513 : llvm::createMCRelocationInfo;
517 /// createMCSymbolizer - Create a target specific MCSymbolizer.
519 /// \param TT The target triple.
520 /// \param GetOpInfo The function to get the symbolic information for operands.
521 /// \param SymbolLookUp The function to lookup a symbol name.
522 /// \param DisInfo The pointer to the block of symbolic information for above call
524 /// \param Ctx The target context.
525 /// \param RelInfo The relocation information for this target. Takes ownership.
527 createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
528 LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo,
530 std::unique_ptr<MCRelocationInfo> &&RelInfo) const {
531 MCSymbolizerCtorTy Fn =
532 MCSymbolizerCtorFn ? MCSymbolizerCtorFn : llvm::createMCSymbolizer;
533 return Fn(TT, GetOpInfo, SymbolLookUp, DisInfo, Ctx, std::move(RelInfo));
539 /// TargetRegistry - Generic interface to target specific features.
540 struct TargetRegistry {
542 const Target *Current;
543 explicit iterator(Target *T) : Current(T) {}
544 friend struct TargetRegistry;
546 iterator() : Current(nullptr) {}
548 bool operator==(const iterator &x) const {
549 return Current == x.Current;
551 bool operator!=(const iterator &x) const {
552 return !operator==(x);
555 // Iterator traversal: forward iteration only
556 iterator &operator++() { // Preincrement
557 assert(Current && "Cannot increment end iterator!");
558 Current = Current->getNext();
561 iterator operator++(int) { // Postincrement
562 iterator tmp = *this;
567 const Target &operator*() const {
568 assert(Current && "Cannot dereference end iterator!");
572 const Target *operator->() const {
577 /// printRegisteredTargetsForVersion - Print the registered targets
578 /// appropriately for inclusion in a tool's version output.
579 static void printRegisteredTargetsForVersion();
581 /// @name Registry Access
584 static iterator begin();
586 static iterator end() { return iterator(); }
588 /// lookupTarget - Lookup a target based on a target triple.
590 /// \param Triple - The triple to use for finding a target.
591 /// \param Error - On failure, an error string describing why no target was
593 static const Target *lookupTarget(const std::string &Triple,
596 /// lookupTarget - Lookup a target based on an architecture name
597 /// and a target triple. If the architecture name is non-empty,
598 /// then the lookup is done by architecture. Otherwise, the target
601 /// \param ArchName - The architecture to use for finding a target.
602 /// \param TheTriple - The triple to use for finding a target. The
603 /// triple is updated with canonical architecture name if a lookup
604 /// by architecture is done.
605 /// \param Error - On failure, an error string describing why no target was
607 static const Target *lookupTarget(const std::string &ArchName,
612 /// @name Target Registration
615 /// RegisterTarget - Register the given target. Attempts to register a
616 /// target which has already been registered will be ignored.
618 /// Clients are responsible for ensuring that registration doesn't occur
619 /// while another thread is attempting to access the registry. Typically
620 /// this is done by initializing all targets at program startup.
622 /// @param T - The target being registered.
623 /// @param Name - The target name. This should be a static string.
624 /// @param ShortDesc - A short target description. This should be a static
626 /// @param ArchMatchFn - The arch match checking function for this target.
627 /// @param HasJIT - Whether the target supports JIT code
629 static void RegisterTarget(Target &T,
631 const char *ShortDesc,
632 Target::ArchMatchFnTy ArchMatchFn,
633 bool HasJIT = false);
635 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
638 /// Clients are responsible for ensuring that registration doesn't occur
639 /// while another thread is attempting to access the registry. Typically
640 /// this is done by initializing all targets at program startup.
642 /// @param T - The target being registered.
643 /// @param Fn - A function to construct a MCAsmInfo for the target.
644 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
645 T.MCAsmInfoCtorFn = Fn;
648 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
651 /// Clients are responsible for ensuring that registration doesn't occur
652 /// while another thread is attempting to access the registry. Typically
653 /// this is done by initializing all targets at program startup.
655 /// @param T - The target being registered.
656 /// @param Fn - A function to construct a MCCodeGenInfo for the target.
657 static void RegisterMCCodeGenInfo(Target &T,
658 Target::MCCodeGenInfoCtorFnTy Fn) {
659 T.MCCodeGenInfoCtorFn = Fn;
662 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
665 /// Clients are responsible for ensuring that registration doesn't occur
666 /// while another thread is attempting to access the registry. Typically
667 /// this is done by initializing all targets at program startup.
669 /// @param T - The target being registered.
670 /// @param Fn - A function to construct a MCInstrInfo for the target.
671 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
672 T.MCInstrInfoCtorFn = Fn;
675 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
676 /// the given target.
677 static void RegisterMCInstrAnalysis(Target &T,
678 Target::MCInstrAnalysisCtorFnTy Fn) {
679 T.MCInstrAnalysisCtorFn = Fn;
682 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
685 /// Clients are responsible for ensuring that registration doesn't occur
686 /// while another thread is attempting to access the registry. Typically
687 /// this is done by initializing all targets at program startup.
689 /// @param T - The target being registered.
690 /// @param Fn - A function to construct a MCRegisterInfo for the target.
691 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
692 T.MCRegInfoCtorFn = Fn;
695 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
696 /// the given target.
698 /// Clients are responsible for ensuring that registration doesn't occur
699 /// while another thread is attempting to access the registry. Typically
700 /// this is done by initializing all targets at program startup.
702 /// @param T - The target being registered.
703 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
704 static void RegisterMCSubtargetInfo(Target &T,
705 Target::MCSubtargetInfoCtorFnTy Fn) {
706 T.MCSubtargetInfoCtorFn = Fn;
709 /// RegisterTargetMachine - Register a TargetMachine implementation for the
712 /// Clients are responsible for ensuring that registration doesn't occur
713 /// while another thread is attempting to access the registry. Typically
714 /// this is done by initializing all targets at program startup.
716 /// @param T - The target being registered.
717 /// @param Fn - A function to construct a TargetMachine for the target.
718 static void RegisterTargetMachine(Target &T,
719 Target::TargetMachineCtorTy Fn) {
720 T.TargetMachineCtorFn = Fn;
723 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
726 /// Clients are responsible for ensuring that registration doesn't occur
727 /// while another thread is attempting to access the registry. Typically
728 /// this is done by initializing all targets at program startup.
730 /// @param T - The target being registered.
731 /// @param Fn - A function to construct an AsmBackend for the target.
732 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
733 T.MCAsmBackendCtorFn = Fn;
736 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
737 /// the given target.
739 /// Clients are responsible for ensuring that registration doesn't occur
740 /// while another thread is attempting to access the registry. Typically
741 /// this is done by initializing all targets at program startup.
743 /// @param T - The target being registered.
744 /// @param Fn - A function to construct an MCTargetAsmParser for the target.
745 static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
746 T.MCAsmParserCtorFn = Fn;
749 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
752 /// Clients are responsible for ensuring that registration doesn't occur
753 /// while another thread is attempting to access the registry. Typically
754 /// this is done by initializing all targets at program startup.
756 /// @param T - The target being registered.
757 /// @param Fn - A function to construct an AsmPrinter for the target.
758 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
759 T.AsmPrinterCtorFn = Fn;
762 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
763 /// 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 MCDisassembler for the target.
771 static void RegisterMCDisassembler(Target &T,
772 Target::MCDisassemblerCtorTy Fn) {
773 T.MCDisassemblerCtorFn = Fn;
776 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
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 MCInstPrinter for the target.
785 static void RegisterMCInstPrinter(Target &T,
786 Target::MCInstPrinterCtorTy Fn) {
787 T.MCInstPrinterCtorFn = Fn;
790 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
793 /// Clients are responsible for ensuring that registration doesn't occur
794 /// while another thread is attempting to access the registry. Typically
795 /// this is done by initializing all targets at program startup.
797 /// @param T - The target being registered.
798 /// @param Fn - A function to construct an MCCodeEmitter for the target.
799 static void RegisterMCCodeEmitter(Target &T,
800 Target::MCCodeEmitterCtorTy Fn) {
801 T.MCCodeEmitterCtorFn = Fn;
804 static void RegisterCOFFStreamer(Target &T, Target::COFFStreamerCtorTy Fn) {
805 T.COFFStreamerCtorFn = Fn;
808 static void RegisterMachOStreamer(Target &T,
809 Target::MachOStreamerCtorTy Fn) {
810 T.MachOStreamerCtorFn = Fn;
813 static void RegisterELFStreamer(Target &T, Target::ELFStreamerCtorTy Fn) {
814 T.ELFStreamerCtorFn = Fn;
818 RegisterNullTargetStreamer(Target &T, Target::NullTargetStreamerCtorTy Fn) {
819 T.NullTargetStreamerCtorFn = Fn;
822 static void RegisterAsmTargetStreamer(Target &T,
823 Target::AsmTargetStreamerCtorTy Fn) {
824 T.AsmTargetStreamerCtorFn = Fn;
828 RegisterObjectTargetStreamer(Target &T,
829 Target::ObjectTargetStreamerCtorTy Fn) {
830 T.ObjectTargetStreamerCtorFn = Fn;
833 /// RegisterMCRelocationInfo - Register an MCRelocationInfo
834 /// implementation for the given target.
836 /// Clients are responsible for ensuring that registration doesn't occur
837 /// while another thread is attempting to access the registry. Typically
838 /// this is done by initializing all targets at program startup.
840 /// @param T - The target being registered.
841 /// @param Fn - A function to construct an MCRelocationInfo for the target.
842 static void RegisterMCRelocationInfo(Target &T,
843 Target::MCRelocationInfoCtorTy Fn) {
844 T.MCRelocationInfoCtorFn = Fn;
847 /// RegisterMCSymbolizer - Register an MCSymbolizer
848 /// implementation for the given target.
850 /// Clients are responsible for ensuring that registration doesn't occur
851 /// while another thread is attempting to access the registry. Typically
852 /// this is done by initializing all targets at program startup.
854 /// @param T - The target being registered.
855 /// @param Fn - A function to construct an MCSymbolizer for the target.
856 static void RegisterMCSymbolizer(Target &T,
857 Target::MCSymbolizerCtorTy Fn) {
858 T.MCSymbolizerCtorFn = Fn;
865 //===--------------------------------------------------------------------===//
867 /// RegisterTarget - Helper template for registering a target, for use in the
868 /// target's initialization function. Usage:
871 /// Target TheFooTarget; // The global target instance.
873 /// extern "C" void LLVMInitializeFooTargetInfo() {
874 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
876 template<Triple::ArchType TargetArchType = Triple::UnknownArch,
878 struct RegisterTarget {
879 RegisterTarget(Target &T, const char *Name, const char *Desc) {
880 TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch, HasJIT);
883 static bool getArchMatch(Triple::ArchType Arch) {
884 return Arch == TargetArchType;
888 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
889 /// implementation. This invokes the static "Create" method on the class to
890 /// actually do the construction. Usage:
892 /// extern "C" void LLVMInitializeFooTarget() {
893 /// extern Target TheFooTarget;
894 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
896 template<class MCAsmInfoImpl>
897 struct RegisterMCAsmInfo {
898 RegisterMCAsmInfo(Target &T) {
899 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
902 static MCAsmInfo *Allocator(const MCRegisterInfo &/*MRI*/, StringRef TT) {
903 return new MCAsmInfoImpl(TT);
908 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
909 /// implementation. This invokes the specified function to do the
910 /// construction. Usage:
912 /// extern "C" void LLVMInitializeFooTarget() {
913 /// extern Target TheFooTarget;
914 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
916 struct RegisterMCAsmInfoFn {
917 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
918 TargetRegistry::RegisterMCAsmInfo(T, Fn);
922 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
923 /// implementation. This invokes the static "Create" method on the class
924 /// to actually do the construction. Usage:
926 /// extern "C" void LLVMInitializeFooTarget() {
927 /// extern Target TheFooTarget;
928 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
930 template<class MCCodeGenInfoImpl>
931 struct RegisterMCCodeGenInfo {
932 RegisterMCCodeGenInfo(Target &T) {
933 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
936 static MCCodeGenInfo *Allocator(StringRef /*TT*/, Reloc::Model /*RM*/,
937 CodeModel::Model /*CM*/,
938 CodeGenOpt::Level /*OL*/) {
939 return new MCCodeGenInfoImpl();
943 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
944 /// info implementation. This invokes the specified function to do the
945 /// construction. Usage:
947 /// extern "C" void LLVMInitializeFooTarget() {
948 /// extern Target TheFooTarget;
949 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
951 struct RegisterMCCodeGenInfoFn {
952 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
953 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
957 /// RegisterMCInstrInfo - Helper template for registering a target instruction
958 /// info implementation. This invokes the static "Create" method on the class
959 /// to actually do the construction. Usage:
961 /// extern "C" void LLVMInitializeFooTarget() {
962 /// extern Target TheFooTarget;
963 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
965 template<class MCInstrInfoImpl>
966 struct RegisterMCInstrInfo {
967 RegisterMCInstrInfo(Target &T) {
968 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
971 static MCInstrInfo *Allocator() {
972 return new MCInstrInfoImpl();
976 /// RegisterMCInstrInfoFn - Helper template for registering a target
977 /// instruction info implementation. This invokes the specified function to
978 /// do the construction. Usage:
980 /// extern "C" void LLVMInitializeFooTarget() {
981 /// extern Target TheFooTarget;
982 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
984 struct RegisterMCInstrInfoFn {
985 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
986 TargetRegistry::RegisterMCInstrInfo(T, Fn);
990 /// RegisterMCInstrAnalysis - Helper template for registering a target
991 /// instruction analyzer implementation. This invokes the static "Create"
992 /// method on the class to actually do the construction. Usage:
994 /// extern "C" void LLVMInitializeFooTarget() {
995 /// extern Target TheFooTarget;
996 /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
998 template<class MCInstrAnalysisImpl>
999 struct RegisterMCInstrAnalysis {
1000 RegisterMCInstrAnalysis(Target &T) {
1001 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
1004 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
1005 return new MCInstrAnalysisImpl(Info);
1009 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
1010 /// instruction analyzer implementation. This invokes the specified function
1011 /// to do the construction. Usage:
1013 /// extern "C" void LLVMInitializeFooTarget() {
1014 /// extern Target TheFooTarget;
1015 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
1017 struct RegisterMCInstrAnalysisFn {
1018 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
1019 TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
1023 /// RegisterMCRegInfo - Helper template for registering a target register info
1024 /// implementation. This invokes the static "Create" method on the class to
1025 /// actually do the construction. Usage:
1027 /// extern "C" void LLVMInitializeFooTarget() {
1028 /// extern Target TheFooTarget;
1029 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
1031 template<class MCRegisterInfoImpl>
1032 struct RegisterMCRegInfo {
1033 RegisterMCRegInfo(Target &T) {
1034 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
1037 static MCRegisterInfo *Allocator(StringRef /*TT*/) {
1038 return new MCRegisterInfoImpl();
1042 /// RegisterMCRegInfoFn - Helper template for registering a target register
1043 /// info implementation. This invokes the specified function to do the
1044 /// construction. Usage:
1046 /// extern "C" void LLVMInitializeFooTarget() {
1047 /// extern Target TheFooTarget;
1048 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
1050 struct RegisterMCRegInfoFn {
1051 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
1052 TargetRegistry::RegisterMCRegInfo(T, Fn);
1056 /// RegisterMCSubtargetInfo - Helper template for registering a target
1057 /// subtarget info implementation. This invokes the static "Create" method
1058 /// on the class to actually do the construction. Usage:
1060 /// extern "C" void LLVMInitializeFooTarget() {
1061 /// extern Target TheFooTarget;
1062 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
1064 template<class MCSubtargetInfoImpl>
1065 struct RegisterMCSubtargetInfo {
1066 RegisterMCSubtargetInfo(Target &T) {
1067 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
1070 static MCSubtargetInfo *Allocator(StringRef /*TT*/, StringRef /*CPU*/,
1072 return new MCSubtargetInfoImpl();
1076 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
1077 /// subtarget info implementation. This invokes the specified function to
1078 /// do the construction. Usage:
1080 /// extern "C" void LLVMInitializeFooTarget() {
1081 /// extern Target TheFooTarget;
1082 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1084 struct RegisterMCSubtargetInfoFn {
1085 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
1086 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
1090 /// RegisterTargetMachine - Helper template for registering a target machine
1091 /// implementation, for use in the target machine initialization
1092 /// function. Usage:
1094 /// extern "C" void LLVMInitializeFooTarget() {
1095 /// extern Target TheFooTarget;
1096 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1098 template<class TargetMachineImpl>
1099 struct RegisterTargetMachine {
1100 RegisterTargetMachine(Target &T) {
1101 TargetRegistry::RegisterTargetMachine(T, &Allocator);
1105 static TargetMachine *Allocator(const Target &T, StringRef TT,
1106 StringRef CPU, StringRef FS,
1107 const TargetOptions &Options,
1109 CodeModel::Model CM,
1110 CodeGenOpt::Level OL) {
1111 return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
1115 /// RegisterMCAsmBackend - Helper template for registering a target specific
1116 /// assembler backend. Usage:
1118 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1119 /// extern Target TheFooTarget;
1120 /// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1122 template<class MCAsmBackendImpl>
1123 struct RegisterMCAsmBackend {
1124 RegisterMCAsmBackend(Target &T) {
1125 TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1129 static MCAsmBackend *Allocator(const Target &T,
1130 const MCRegisterInfo &MRI,
1131 StringRef Triple, StringRef CPU) {
1132 return new MCAsmBackendImpl(T, MRI, Triple, CPU);
1136 /// RegisterMCAsmParser - Helper template for registering a target specific
1137 /// assembly parser, for use in the target machine initialization
1138 /// function. Usage:
1140 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1141 /// extern Target TheFooTarget;
1142 /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1144 template<class MCAsmParserImpl>
1145 struct RegisterMCAsmParser {
1146 RegisterMCAsmParser(Target &T) {
1147 TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1151 static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P,
1152 const MCInstrInfo &MII,
1153 const MCTargetOptions &Options) {
1154 return new MCAsmParserImpl(STI, P, MII, Options);
1158 /// RegisterAsmPrinter - Helper template for registering a target specific
1159 /// assembly printer, for use in the target machine initialization
1160 /// function. Usage:
1162 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1163 /// extern Target TheFooTarget;
1164 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1166 template<class AsmPrinterImpl>
1167 struct RegisterAsmPrinter {
1168 RegisterAsmPrinter(Target &T) {
1169 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1173 static AsmPrinter *Allocator(TargetMachine &TM,
1174 std::unique_ptr<MCStreamer> &&Streamer) {
1175 return new AsmPrinterImpl(TM, std::move(Streamer));
1179 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1180 /// machine code emitter, for use in the target initialization
1181 /// function. Usage:
1183 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1184 /// extern Target TheFooTarget;
1185 /// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1187 template<class MCCodeEmitterImpl>
1188 struct RegisterMCCodeEmitter {
1189 RegisterMCCodeEmitter(Target &T) {
1190 TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1194 static MCCodeEmitter *Allocator(const MCInstrInfo & /*II*/,
1195 const MCRegisterInfo & /*MRI*/,
1196 MCContext & /*Ctx*/) {
1197 return new MCCodeEmitterImpl();