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)(const Triple &T,
128 unsigned SyntaxVariant,
129 const MCAsmInfo &MAI,
130 const MCInstrInfo &MII,
131 const MCRegisterInfo &MRI);
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(const Triple &T, unsigned SyntaxVariant,
412 const MCAsmInfo &MAI,
413 const MCInstrInfo &MII,
414 const MCRegisterInfo &MRI) const {
415 if (!MCInstPrinterCtorFn)
417 return MCInstPrinterCtorFn(T, SyntaxVariant, MAI, MII, MRI);
421 /// createMCCodeEmitter - Create a target specific code emitter.
422 MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
423 const MCRegisterInfo &MRI,
424 MCContext &Ctx) const {
425 if (!MCCodeEmitterCtorFn)
427 return MCCodeEmitterCtorFn(II, MRI, Ctx);
430 /// Create a target specific MCStreamer.
432 /// \param T The target triple.
433 /// \param Ctx The target context.
434 /// \param TAB The target assembler backend object. Takes ownership.
435 /// \param OS The stream object.
436 /// \param Emitter The target independent assembler object.Takes ownership.
437 /// \param RelaxAll Relax all fixups?
438 MCStreamer *createMCObjectStreamer(const Triple &T, MCContext &Ctx,
439 MCAsmBackend &TAB, raw_ostream &OS,
440 MCCodeEmitter *Emitter,
441 const MCSubtargetInfo &STI,
443 bool DWARFMustBeAtTheEnd) const {
445 switch (T.getObjectFormat()) {
447 llvm_unreachable("Unknown object format");
449 assert(T.isOSWindows() && "only Windows COFF is supported");
450 S = COFFStreamerCtorFn(Ctx, TAB, OS, Emitter, RelaxAll);
453 if (MachOStreamerCtorFn)
454 S = MachOStreamerCtorFn(Ctx, TAB, OS, Emitter, RelaxAll,
455 DWARFMustBeAtTheEnd);
457 S = createMachOStreamer(Ctx, TAB, OS, Emitter, RelaxAll,
458 DWARFMustBeAtTheEnd);
461 if (ELFStreamerCtorFn)
462 S = ELFStreamerCtorFn(T, Ctx, TAB, OS, Emitter, RelaxAll);
464 S = createELFStreamer(Ctx, TAB, OS, Emitter, RelaxAll);
467 if (ObjectTargetStreamerCtorFn)
468 ObjectTargetStreamerCtorFn(*S, STI);
472 MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
473 bool IsVerboseAsm, bool UseDwarfDirectory,
474 MCInstPrinter *InstPrint, MCCodeEmitter *CE,
475 MCAsmBackend *TAB, bool ShowInst) const {
477 llvm::createAsmStreamer(Ctx, OS, IsVerboseAsm, UseDwarfDirectory,
478 InstPrint, CE, TAB, ShowInst);
479 createAsmTargetStreamer(*S, OS, InstPrint, IsVerboseAsm);
483 MCTargetStreamer *createAsmTargetStreamer(MCStreamer &S,
484 formatted_raw_ostream &OS,
485 MCInstPrinter *InstPrint,
486 bool IsVerboseAsm) const {
487 if (AsmTargetStreamerCtorFn)
488 return AsmTargetStreamerCtorFn(S, OS, InstPrint, IsVerboseAsm);
492 MCStreamer *createNullStreamer(MCContext &Ctx) const {
493 MCStreamer *S = llvm::createNullStreamer(Ctx);
494 createNullTargetStreamer(*S);
498 MCTargetStreamer *createNullTargetStreamer(MCStreamer &S) const {
499 if (NullTargetStreamerCtorFn)
500 return NullTargetStreamerCtorFn(S);
504 /// createMCRelocationInfo - Create a target specific MCRelocationInfo.
506 /// \param TT The target triple.
507 /// \param Ctx The target context.
509 createMCRelocationInfo(StringRef TT, MCContext &Ctx) const {
510 MCRelocationInfoCtorTy Fn = MCRelocationInfoCtorFn
511 ? MCRelocationInfoCtorFn
512 : llvm::createMCRelocationInfo;
516 /// createMCSymbolizer - Create a target specific MCSymbolizer.
518 /// \param TT The target triple.
519 /// \param GetOpInfo The function to get the symbolic information for operands.
520 /// \param SymbolLookUp The function to lookup a symbol name.
521 /// \param DisInfo The pointer to the block of symbolic information for above call
523 /// \param Ctx The target context.
524 /// \param RelInfo The relocation information for this target. Takes ownership.
526 createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
527 LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo,
529 std::unique_ptr<MCRelocationInfo> &&RelInfo) const {
530 MCSymbolizerCtorTy Fn =
531 MCSymbolizerCtorFn ? MCSymbolizerCtorFn : llvm::createMCSymbolizer;
532 return Fn(TT, GetOpInfo, SymbolLookUp, DisInfo, Ctx, std::move(RelInfo));
538 /// TargetRegistry - Generic interface to target specific features.
539 struct TargetRegistry {
541 const Target *Current;
542 explicit iterator(Target *T) : Current(T) {}
543 friend struct TargetRegistry;
545 iterator() : Current(nullptr) {}
547 bool operator==(const iterator &x) const {
548 return Current == x.Current;
550 bool operator!=(const iterator &x) const {
551 return !operator==(x);
554 // Iterator traversal: forward iteration only
555 iterator &operator++() { // Preincrement
556 assert(Current && "Cannot increment end iterator!");
557 Current = Current->getNext();
560 iterator operator++(int) { // Postincrement
561 iterator tmp = *this;
566 const Target &operator*() const {
567 assert(Current && "Cannot dereference end iterator!");
571 const Target *operator->() const {
576 /// printRegisteredTargetsForVersion - Print the registered targets
577 /// appropriately for inclusion in a tool's version output.
578 static void printRegisteredTargetsForVersion();
580 /// @name Registry Access
583 static iterator begin();
585 static iterator end() { return iterator(); }
587 /// lookupTarget - Lookup a target based on a target triple.
589 /// \param Triple - The triple to use for finding a target.
590 /// \param Error - On failure, an error string describing why no target was
592 static const Target *lookupTarget(const std::string &Triple,
595 /// lookupTarget - Lookup a target based on an architecture name
596 /// and a target triple. If the architecture name is non-empty,
597 /// then the lookup is done by architecture. Otherwise, the target
600 /// \param ArchName - The architecture to use for finding a target.
601 /// \param TheTriple - The triple to use for finding a target. The
602 /// triple is updated with canonical architecture name if a lookup
603 /// by architecture is done.
604 /// \param Error - On failure, an error string describing why no target was
606 static const Target *lookupTarget(const std::string &ArchName,
611 /// @name Target Registration
614 /// RegisterTarget - Register the given target. Attempts to register a
615 /// target which has already been registered will be ignored.
617 /// Clients are responsible for ensuring that registration doesn't occur
618 /// while another thread is attempting to access the registry. Typically
619 /// this is done by initializing all targets at program startup.
621 /// @param T - The target being registered.
622 /// @param Name - The target name. This should be a static string.
623 /// @param ShortDesc - A short target description. This should be a static
625 /// @param ArchMatchFn - The arch match checking function for this target.
626 /// @param HasJIT - Whether the target supports JIT code
628 static void RegisterTarget(Target &T,
630 const char *ShortDesc,
631 Target::ArchMatchFnTy ArchMatchFn,
632 bool HasJIT = false);
634 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
637 /// Clients are responsible for ensuring that registration doesn't occur
638 /// while another thread is attempting to access the registry. Typically
639 /// this is done by initializing all targets at program startup.
641 /// @param T - The target being registered.
642 /// @param Fn - A function to construct a MCAsmInfo for the target.
643 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
644 T.MCAsmInfoCtorFn = Fn;
647 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
650 /// Clients are responsible for ensuring that registration doesn't occur
651 /// while another thread is attempting to access the registry. Typically
652 /// this is done by initializing all targets at program startup.
654 /// @param T - The target being registered.
655 /// @param Fn - A function to construct a MCCodeGenInfo for the target.
656 static void RegisterMCCodeGenInfo(Target &T,
657 Target::MCCodeGenInfoCtorFnTy Fn) {
658 T.MCCodeGenInfoCtorFn = Fn;
661 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
664 /// Clients are responsible for ensuring that registration doesn't occur
665 /// while another thread is attempting to access the registry. Typically
666 /// this is done by initializing all targets at program startup.
668 /// @param T - The target being registered.
669 /// @param Fn - A function to construct a MCInstrInfo for the target.
670 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
671 T.MCInstrInfoCtorFn = Fn;
674 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
675 /// the given target.
676 static void RegisterMCInstrAnalysis(Target &T,
677 Target::MCInstrAnalysisCtorFnTy Fn) {
678 T.MCInstrAnalysisCtorFn = Fn;
681 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
684 /// Clients are responsible for ensuring that registration doesn't occur
685 /// while another thread is attempting to access the registry. Typically
686 /// this is done by initializing all targets at program startup.
688 /// @param T - The target being registered.
689 /// @param Fn - A function to construct a MCRegisterInfo for the target.
690 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
691 T.MCRegInfoCtorFn = Fn;
694 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
695 /// the given target.
697 /// Clients are responsible for ensuring that registration doesn't occur
698 /// while another thread is attempting to access the registry. Typically
699 /// this is done by initializing all targets at program startup.
701 /// @param T - The target being registered.
702 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
703 static void RegisterMCSubtargetInfo(Target &T,
704 Target::MCSubtargetInfoCtorFnTy Fn) {
705 T.MCSubtargetInfoCtorFn = Fn;
708 /// RegisterTargetMachine - Register a TargetMachine implementation for the
711 /// Clients are responsible for ensuring that registration doesn't occur
712 /// while another thread is attempting to access the registry. Typically
713 /// this is done by initializing all targets at program startup.
715 /// @param T - The target being registered.
716 /// @param Fn - A function to construct a TargetMachine for the target.
717 static void RegisterTargetMachine(Target &T,
718 Target::TargetMachineCtorTy Fn) {
719 T.TargetMachineCtorFn = Fn;
722 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
725 /// Clients are responsible for ensuring that registration doesn't occur
726 /// while another thread is attempting to access the registry. Typically
727 /// this is done by initializing all targets at program startup.
729 /// @param T - The target being registered.
730 /// @param Fn - A function to construct an AsmBackend for the target.
731 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
732 T.MCAsmBackendCtorFn = Fn;
735 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
736 /// the given target.
738 /// Clients are responsible for ensuring that registration doesn't occur
739 /// while another thread is attempting to access the registry. Typically
740 /// this is done by initializing all targets at program startup.
742 /// @param T - The target being registered.
743 /// @param Fn - A function to construct an MCTargetAsmParser for the target.
744 static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
745 T.MCAsmParserCtorFn = Fn;
748 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
751 /// Clients are responsible for ensuring that registration doesn't occur
752 /// while another thread is attempting to access the registry. Typically
753 /// this is done by initializing all targets at program startup.
755 /// @param T - The target being registered.
756 /// @param Fn - A function to construct an AsmPrinter for the target.
757 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
758 T.AsmPrinterCtorFn = Fn;
761 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
762 /// the given target.
764 /// Clients are responsible for ensuring that registration doesn't occur
765 /// while another thread is attempting to access the registry. Typically
766 /// this is done by initializing all targets at program startup.
768 /// @param T - The target being registered.
769 /// @param Fn - A function to construct an MCDisassembler for the target.
770 static void RegisterMCDisassembler(Target &T,
771 Target::MCDisassemblerCtorTy Fn) {
772 T.MCDisassemblerCtorFn = Fn;
775 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
778 /// Clients are responsible for ensuring that registration doesn't occur
779 /// while another thread is attempting to access the registry. Typically
780 /// this is done by initializing all targets at program startup.
782 /// @param T - The target being registered.
783 /// @param Fn - A function to construct an MCInstPrinter for the target.
784 static void RegisterMCInstPrinter(Target &T,
785 Target::MCInstPrinterCtorTy Fn) {
786 T.MCInstPrinterCtorFn = Fn;
789 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
792 /// Clients are responsible for ensuring that registration doesn't occur
793 /// while another thread is attempting to access the registry. Typically
794 /// this is done by initializing all targets at program startup.
796 /// @param T - The target being registered.
797 /// @param Fn - A function to construct an MCCodeEmitter for the target.
798 static void RegisterMCCodeEmitter(Target &T,
799 Target::MCCodeEmitterCtorTy Fn) {
800 T.MCCodeEmitterCtorFn = Fn;
803 static void RegisterCOFFStreamer(Target &T, Target::COFFStreamerCtorTy Fn) {
804 T.COFFStreamerCtorFn = Fn;
807 static void RegisterMachOStreamer(Target &T,
808 Target::MachOStreamerCtorTy Fn) {
809 T.MachOStreamerCtorFn = Fn;
812 static void RegisterELFStreamer(Target &T, Target::ELFStreamerCtorTy Fn) {
813 T.ELFStreamerCtorFn = Fn;
817 RegisterNullTargetStreamer(Target &T, Target::NullTargetStreamerCtorTy Fn) {
818 T.NullTargetStreamerCtorFn = Fn;
821 static void RegisterAsmTargetStreamer(Target &T,
822 Target::AsmTargetStreamerCtorTy Fn) {
823 T.AsmTargetStreamerCtorFn = Fn;
827 RegisterObjectTargetStreamer(Target &T,
828 Target::ObjectTargetStreamerCtorTy Fn) {
829 T.ObjectTargetStreamerCtorFn = Fn;
832 /// RegisterMCRelocationInfo - Register an MCRelocationInfo
833 /// implementation for the given target.
835 /// Clients are responsible for ensuring that registration doesn't occur
836 /// while another thread is attempting to access the registry. Typically
837 /// this is done by initializing all targets at program startup.
839 /// @param T - The target being registered.
840 /// @param Fn - A function to construct an MCRelocationInfo for the target.
841 static void RegisterMCRelocationInfo(Target &T,
842 Target::MCRelocationInfoCtorTy Fn) {
843 T.MCRelocationInfoCtorFn = Fn;
846 /// RegisterMCSymbolizer - Register an MCSymbolizer
847 /// implementation for the given target.
849 /// Clients are responsible for ensuring that registration doesn't occur
850 /// while another thread is attempting to access the registry. Typically
851 /// this is done by initializing all targets at program startup.
853 /// @param T - The target being registered.
854 /// @param Fn - A function to construct an MCSymbolizer for the target.
855 static void RegisterMCSymbolizer(Target &T,
856 Target::MCSymbolizerCtorTy Fn) {
857 T.MCSymbolizerCtorFn = Fn;
864 //===--------------------------------------------------------------------===//
866 /// RegisterTarget - Helper template for registering a target, for use in the
867 /// target's initialization function. Usage:
870 /// Target TheFooTarget; // The global target instance.
872 /// extern "C" void LLVMInitializeFooTargetInfo() {
873 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
875 template<Triple::ArchType TargetArchType = Triple::UnknownArch,
877 struct RegisterTarget {
878 RegisterTarget(Target &T, const char *Name, const char *Desc) {
879 TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch, HasJIT);
882 static bool getArchMatch(Triple::ArchType Arch) {
883 return Arch == TargetArchType;
887 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
888 /// implementation. This invokes the static "Create" method on the class to
889 /// actually do the construction. Usage:
891 /// extern "C" void LLVMInitializeFooTarget() {
892 /// extern Target TheFooTarget;
893 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
895 template<class MCAsmInfoImpl>
896 struct RegisterMCAsmInfo {
897 RegisterMCAsmInfo(Target &T) {
898 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
901 static MCAsmInfo *Allocator(const MCRegisterInfo &/*MRI*/, StringRef TT) {
902 return new MCAsmInfoImpl(TT);
907 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
908 /// implementation. This invokes the specified function to do the
909 /// construction. Usage:
911 /// extern "C" void LLVMInitializeFooTarget() {
912 /// extern Target TheFooTarget;
913 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
915 struct RegisterMCAsmInfoFn {
916 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
917 TargetRegistry::RegisterMCAsmInfo(T, Fn);
921 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
922 /// implementation. This invokes the static "Create" method on the class
923 /// to actually do the construction. Usage:
925 /// extern "C" void LLVMInitializeFooTarget() {
926 /// extern Target TheFooTarget;
927 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
929 template<class MCCodeGenInfoImpl>
930 struct RegisterMCCodeGenInfo {
931 RegisterMCCodeGenInfo(Target &T) {
932 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
935 static MCCodeGenInfo *Allocator(StringRef /*TT*/, Reloc::Model /*RM*/,
936 CodeModel::Model /*CM*/,
937 CodeGenOpt::Level /*OL*/) {
938 return new MCCodeGenInfoImpl();
942 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
943 /// info implementation. This invokes the specified function to do the
944 /// construction. Usage:
946 /// extern "C" void LLVMInitializeFooTarget() {
947 /// extern Target TheFooTarget;
948 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
950 struct RegisterMCCodeGenInfoFn {
951 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
952 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
956 /// RegisterMCInstrInfo - Helper template for registering a target instruction
957 /// info implementation. This invokes the static "Create" method on the class
958 /// to actually do the construction. Usage:
960 /// extern "C" void LLVMInitializeFooTarget() {
961 /// extern Target TheFooTarget;
962 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
964 template<class MCInstrInfoImpl>
965 struct RegisterMCInstrInfo {
966 RegisterMCInstrInfo(Target &T) {
967 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
970 static MCInstrInfo *Allocator() {
971 return new MCInstrInfoImpl();
975 /// RegisterMCInstrInfoFn - Helper template for registering a target
976 /// instruction info implementation. This invokes the specified function to
977 /// do the construction. Usage:
979 /// extern "C" void LLVMInitializeFooTarget() {
980 /// extern Target TheFooTarget;
981 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
983 struct RegisterMCInstrInfoFn {
984 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
985 TargetRegistry::RegisterMCInstrInfo(T, Fn);
989 /// RegisterMCInstrAnalysis - Helper template for registering a target
990 /// instruction analyzer implementation. This invokes the static "Create"
991 /// method on the class to actually do the construction. Usage:
993 /// extern "C" void LLVMInitializeFooTarget() {
994 /// extern Target TheFooTarget;
995 /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
997 template<class MCInstrAnalysisImpl>
998 struct RegisterMCInstrAnalysis {
999 RegisterMCInstrAnalysis(Target &T) {
1000 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
1003 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
1004 return new MCInstrAnalysisImpl(Info);
1008 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
1009 /// instruction analyzer implementation. This invokes the specified function
1010 /// to do the construction. Usage:
1012 /// extern "C" void LLVMInitializeFooTarget() {
1013 /// extern Target TheFooTarget;
1014 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
1016 struct RegisterMCInstrAnalysisFn {
1017 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
1018 TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
1022 /// RegisterMCRegInfo - Helper template for registering a target register info
1023 /// implementation. This invokes the static "Create" method on the class to
1024 /// actually do the construction. Usage:
1026 /// extern "C" void LLVMInitializeFooTarget() {
1027 /// extern Target TheFooTarget;
1028 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
1030 template<class MCRegisterInfoImpl>
1031 struct RegisterMCRegInfo {
1032 RegisterMCRegInfo(Target &T) {
1033 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
1036 static MCRegisterInfo *Allocator(StringRef /*TT*/) {
1037 return new MCRegisterInfoImpl();
1041 /// RegisterMCRegInfoFn - Helper template for registering a target register
1042 /// info implementation. This invokes the specified function to do the
1043 /// construction. Usage:
1045 /// extern "C" void LLVMInitializeFooTarget() {
1046 /// extern Target TheFooTarget;
1047 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
1049 struct RegisterMCRegInfoFn {
1050 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
1051 TargetRegistry::RegisterMCRegInfo(T, Fn);
1055 /// RegisterMCSubtargetInfo - Helper template for registering a target
1056 /// subtarget info implementation. This invokes the static "Create" method
1057 /// on the class to actually do the construction. Usage:
1059 /// extern "C" void LLVMInitializeFooTarget() {
1060 /// extern Target TheFooTarget;
1061 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
1063 template<class MCSubtargetInfoImpl>
1064 struct RegisterMCSubtargetInfo {
1065 RegisterMCSubtargetInfo(Target &T) {
1066 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
1069 static MCSubtargetInfo *Allocator(StringRef /*TT*/, StringRef /*CPU*/,
1071 return new MCSubtargetInfoImpl();
1075 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
1076 /// subtarget info implementation. This invokes the specified function to
1077 /// do the construction. Usage:
1079 /// extern "C" void LLVMInitializeFooTarget() {
1080 /// extern Target TheFooTarget;
1081 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1083 struct RegisterMCSubtargetInfoFn {
1084 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
1085 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
1089 /// RegisterTargetMachine - Helper template for registering a target machine
1090 /// implementation, for use in the target machine initialization
1091 /// function. Usage:
1093 /// extern "C" void LLVMInitializeFooTarget() {
1094 /// extern Target TheFooTarget;
1095 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1097 template<class TargetMachineImpl>
1098 struct RegisterTargetMachine {
1099 RegisterTargetMachine(Target &T) {
1100 TargetRegistry::RegisterTargetMachine(T, &Allocator);
1104 static TargetMachine *Allocator(const Target &T, StringRef TT,
1105 StringRef CPU, StringRef FS,
1106 const TargetOptions &Options,
1108 CodeModel::Model CM,
1109 CodeGenOpt::Level OL) {
1110 return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
1114 /// RegisterMCAsmBackend - Helper template for registering a target specific
1115 /// assembler backend. Usage:
1117 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1118 /// extern Target TheFooTarget;
1119 /// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1121 template<class MCAsmBackendImpl>
1122 struct RegisterMCAsmBackend {
1123 RegisterMCAsmBackend(Target &T) {
1124 TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1128 static MCAsmBackend *Allocator(const Target &T,
1129 const MCRegisterInfo &MRI,
1130 StringRef Triple, StringRef CPU) {
1131 return new MCAsmBackendImpl(T, MRI, Triple, CPU);
1135 /// RegisterMCAsmParser - Helper template for registering a target specific
1136 /// assembly parser, for use in the target machine initialization
1137 /// function. Usage:
1139 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1140 /// extern Target TheFooTarget;
1141 /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1143 template<class MCAsmParserImpl>
1144 struct RegisterMCAsmParser {
1145 RegisterMCAsmParser(Target &T) {
1146 TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1150 static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P,
1151 const MCInstrInfo &MII,
1152 const MCTargetOptions &Options) {
1153 return new MCAsmParserImpl(STI, P, MII, Options);
1157 /// RegisterAsmPrinter - Helper template for registering a target specific
1158 /// assembly printer, for use in the target machine initialization
1159 /// function. Usage:
1161 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1162 /// extern Target TheFooTarget;
1163 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1165 template<class AsmPrinterImpl>
1166 struct RegisterAsmPrinter {
1167 RegisterAsmPrinter(Target &T) {
1168 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1172 static AsmPrinter *Allocator(TargetMachine &TM,
1173 std::unique_ptr<MCStreamer> &&Streamer) {
1174 return new AsmPrinterImpl(TM, std::move(Streamer));
1178 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1179 /// machine code emitter, for use in the target initialization
1180 /// function. Usage:
1182 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1183 /// extern Target TheFooTarget;
1184 /// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1186 template<class MCCodeEmitterImpl>
1187 struct RegisterMCCodeEmitter {
1188 RegisterMCCodeEmitter(Target &T) {
1189 TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1193 static MCCodeEmitter *Allocator(const MCInstrInfo & /*II*/,
1194 const MCRegisterInfo & /*MRI*/,
1195 MCContext & /*Ctx*/) {
1196 return new MCCodeEmitterImpl();