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);
61 MCStreamer *createObjectStreamer(const Triple &T, MCContext &Ctx,
62 MCAsmBackend &TAB, raw_ostream &OS,
63 MCCodeEmitter *Emitter,
64 const MCSubtargetInfo &STI, bool RelaxAll);
66 MCRelocationInfo *createMCRelocationInfo(StringRef TT, MCContext &Ctx);
68 MCSymbolizer *createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
69 LLVMSymbolLookupCallback SymbolLookUp,
70 void *DisInfo, MCContext *Ctx,
71 std::unique_ptr<MCRelocationInfo> &&RelInfo);
73 /// Target - Wrapper for Target specific information.
75 /// For registration purposes, this is a POD type so that targets can be
76 /// registered without the use of static constructors.
78 /// Targets should implement a single global instance of this class (which
79 /// will be zero initialized), and pass that instance to the TargetRegistry as
80 /// part of their initialization.
83 friend struct TargetRegistry;
85 typedef bool (*ArchMatchFnTy)(Triple::ArchType Arch);
87 typedef MCAsmInfo *(*MCAsmInfoCtorFnTy)(const MCRegisterInfo &MRI,
89 typedef MCCodeGenInfo *(*MCCodeGenInfoCtorFnTy)(StringRef TT,
92 CodeGenOpt::Level OL);
93 typedef MCInstrInfo *(*MCInstrInfoCtorFnTy)(void);
94 typedef MCInstrAnalysis *(*MCInstrAnalysisCtorFnTy)(const MCInstrInfo*Info);
95 typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(StringRef TT);
96 typedef MCSubtargetInfo *(*MCSubtargetInfoCtorFnTy)(StringRef TT,
99 typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T,
103 const TargetOptions &Options,
106 CodeGenOpt::Level OL);
107 // If it weren't for layering issues (this header is in llvm/Support, but
108 // depends on MC?) this should take the Streamer by value rather than rvalue
110 typedef AsmPrinter *(*AsmPrinterCtorTy)(
111 TargetMachine &TM, std::unique_ptr<MCStreamer> &&Streamer);
112 typedef MCAsmBackend *(*MCAsmBackendCtorTy)(const Target &T,
113 const MCRegisterInfo &MRI,
116 typedef MCTargetAsmParser *(*MCAsmParserCtorTy)(
117 MCSubtargetInfo &STI,
119 const MCInstrInfo &MII,
120 const MCTargetOptions &Options);
121 typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T,
122 const MCSubtargetInfo &STI,
124 typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
125 unsigned SyntaxVariant,
126 const MCAsmInfo &MAI,
127 const MCInstrInfo &MII,
128 const MCRegisterInfo &MRI,
129 const MCSubtargetInfo &STI);
130 typedef MCCodeEmitter *(*MCCodeEmitterCtorTy)(const MCInstrInfo &II,
131 const MCRegisterInfo &MRI,
133 typedef MCStreamer *(*MCObjectStreamerCtorTy)(
134 const Triple &T, MCContext &Ctx, MCAsmBackend &TAB, raw_ostream &OS,
135 MCCodeEmitter *Emitter, const MCSubtargetInfo &STI, bool RelaxAll);
136 typedef MCTargetStreamer *(*NullTargetStreamerCtorTy)(MCStreamer &S);
137 typedef MCTargetStreamer *(*AsmTargetStreamerCtorTy)(
138 MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *InstPrint,
140 typedef MCRelocationInfo *(*MCRelocationInfoCtorTy)(StringRef TT,
142 typedef MCSymbolizer *(*MCSymbolizerCtorTy)(
143 StringRef TT, LLVMOpInfoCallback GetOpInfo,
144 LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo, MCContext *Ctx,
145 std::unique_ptr<MCRelocationInfo> &&RelInfo);
148 /// Next - The next registered target in the linked list, maintained by the
152 /// The target function for checking if an architecture is supported.
153 ArchMatchFnTy ArchMatchFn;
155 /// Name - The target name.
158 /// ShortDesc - A short description of the target.
159 const char *ShortDesc;
161 /// HasJIT - Whether this target supports the JIT.
164 /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
166 MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
168 /// MCCodeGenInfoCtorFn - Constructor function for this target's
169 /// MCCodeGenInfo, if registered.
170 MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn;
172 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
174 MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
176 /// MCInstrAnalysisCtorFn - Constructor function for this target's
177 /// MCInstrAnalysis, if registered.
178 MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
180 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
182 MCRegInfoCtorFnTy MCRegInfoCtorFn;
184 /// MCSubtargetInfoCtorFn - Constructor function for this target's
185 /// MCSubtargetInfo, if registered.
186 MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
188 /// TargetMachineCtorFn - Construction function for this target's
189 /// TargetMachine, if registered.
190 TargetMachineCtorTy TargetMachineCtorFn;
192 /// MCAsmBackendCtorFn - Construction function for this target's
193 /// MCAsmBackend, if registered.
194 MCAsmBackendCtorTy MCAsmBackendCtorFn;
196 /// MCAsmParserCtorFn - Construction function for this target's
197 /// MCTargetAsmParser, if registered.
198 MCAsmParserCtorTy MCAsmParserCtorFn;
200 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
202 AsmPrinterCtorTy AsmPrinterCtorFn;
204 /// MCDisassemblerCtorFn - Construction function for this target's
205 /// MCDisassembler, if registered.
206 MCDisassemblerCtorTy MCDisassemblerCtorFn;
208 /// MCInstPrinterCtorFn - Construction function for this target's
209 /// MCInstPrinter, if registered.
210 MCInstPrinterCtorTy MCInstPrinterCtorFn;
212 /// MCCodeEmitterCtorFn - Construction function for this target's
213 /// CodeEmitter, if registered.
214 MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
216 /// MCObjectStreamerCtorFn - Construction function for this target's
217 /// MCObjectStreamer, if registered.
218 MCObjectStreamerCtorTy MCObjectStreamerCtorFn;
220 /// Construction function for this target's null TargetStreamer, if
221 /// registered (default = nullptr).
222 NullTargetStreamerCtorTy NullTargetStreamerCtorFn;
224 /// Construction function for this target's asm TargetStreamer, if
225 /// registered (default = nullptr).
226 AsmTargetStreamerCtorTy AsmTargetStreamerCtorFn;
228 /// MCRelocationInfoCtorFn - Construction function for this target's
229 /// MCRelocationInfo, if registered (default = llvm::createMCRelocationInfo)
230 MCRelocationInfoCtorTy MCRelocationInfoCtorFn;
232 /// MCSymbolizerCtorFn - Construction function for this target's
233 /// MCSymbolizer, if registered (default = llvm::createMCSymbolizer)
234 MCSymbolizerCtorTy MCSymbolizerCtorFn;
238 : MCObjectStreamerCtorFn(nullptr), NullTargetStreamerCtorFn(nullptr),
239 AsmTargetStreamerCtorFn(nullptr), MCRelocationInfoCtorFn(nullptr),
240 MCSymbolizerCtorFn(nullptr) {}
242 /// @name Target Information
245 // getNext - Return the next registered target.
246 const Target *getNext() const { return Next; }
248 /// getName - Get the target name.
249 const char *getName() const { return Name; }
251 /// getShortDescription - Get a short description of the target.
252 const char *getShortDescription() const { return ShortDesc; }
255 /// @name Feature Predicates
258 /// hasJIT - Check if this targets supports the just-in-time compilation.
259 bool hasJIT() const { return HasJIT; }
261 /// hasTargetMachine - Check if this target supports code generation.
262 bool hasTargetMachine() const { return TargetMachineCtorFn != nullptr; }
264 /// hasMCAsmBackend - Check if this target supports .o generation.
265 bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != nullptr; }
268 /// @name Feature Constructors
271 /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
274 /// \param Triple This argument is used to determine the target machine
275 /// feature set; it should always be provided. Generally this should be
276 /// either the target triple from the module, or the target triple of the
277 /// host if that does not exist.
278 MCAsmInfo *createMCAsmInfo(const MCRegisterInfo &MRI,
279 StringRef Triple) const {
280 if (!MCAsmInfoCtorFn)
282 return MCAsmInfoCtorFn(MRI, Triple);
285 /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
287 MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model RM,
289 CodeGenOpt::Level OL) const {
290 if (!MCCodeGenInfoCtorFn)
292 return MCCodeGenInfoCtorFn(Triple, RM, CM, OL);
295 /// createMCInstrInfo - Create a MCInstrInfo implementation.
297 MCInstrInfo *createMCInstrInfo() const {
298 if (!MCInstrInfoCtorFn)
300 return MCInstrInfoCtorFn();
303 /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
305 MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
306 if (!MCInstrAnalysisCtorFn)
308 return MCInstrAnalysisCtorFn(Info);
311 /// createMCRegInfo - Create a MCRegisterInfo implementation.
313 MCRegisterInfo *createMCRegInfo(StringRef Triple) const {
314 if (!MCRegInfoCtorFn)
316 return MCRegInfoCtorFn(Triple);
319 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
321 /// \param Triple This argument is used to determine the target machine
322 /// feature set; it should always be provided. Generally this should be
323 /// either the target triple from the module, or the target triple of the
324 /// host if that does not exist.
325 /// \param CPU This specifies the name of the target CPU.
326 /// \param Features This specifies the string representation of the
327 /// additional target features.
328 MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU,
329 StringRef Features) const {
330 if (!MCSubtargetInfoCtorFn)
332 return MCSubtargetInfoCtorFn(Triple, CPU, Features);
335 /// createTargetMachine - Create a target specific machine implementation
336 /// for the specified \p Triple.
338 /// \param Triple This argument is used to determine the target machine
339 /// feature set; it should always be provided. Generally this should be
340 /// either the target triple from the module, or the target triple of the
341 /// host if that does not exist.
342 TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU,
343 StringRef Features, const TargetOptions &Options,
344 Reloc::Model RM = Reloc::Default,
345 CodeModel::Model CM = CodeModel::Default,
346 CodeGenOpt::Level OL = CodeGenOpt::Default) const {
347 if (!TargetMachineCtorFn)
349 return TargetMachineCtorFn(*this, Triple, CPU, Features, Options,
353 /// createMCAsmBackend - Create a target specific assembly parser.
355 /// \param Triple The target triple string.
356 MCAsmBackend *createMCAsmBackend(const MCRegisterInfo &MRI,
357 StringRef Triple, StringRef CPU) const {
358 if (!MCAsmBackendCtorFn)
360 return MCAsmBackendCtorFn(*this, MRI, Triple, CPU);
363 /// createMCAsmParser - Create a target specific assembly parser.
365 /// \param Parser The target independent parser implementation to use for
366 /// parsing and lexing.
367 MCTargetAsmParser *createMCAsmParser(
368 MCSubtargetInfo &STI,
370 const MCInstrInfo &MII,
371 const MCTargetOptions &Options) const {
372 if (!MCAsmParserCtorFn)
374 return MCAsmParserCtorFn(STI, Parser, MII, Options);
377 /// createAsmPrinter - Create a target specific assembly printer pass. This
378 /// takes ownership of the MCStreamer object.
379 AsmPrinter *createAsmPrinter(TargetMachine &TM,
380 std::unique_ptr<MCStreamer> &&Streamer) const {
381 if (!AsmPrinterCtorFn)
383 return AsmPrinterCtorFn(TM, std::move(Streamer));
386 MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI,
387 MCContext &Ctx) const {
388 if (!MCDisassemblerCtorFn)
390 return MCDisassemblerCtorFn(*this, STI, Ctx);
393 MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
394 const MCAsmInfo &MAI,
395 const MCInstrInfo &MII,
396 const MCRegisterInfo &MRI,
397 const MCSubtargetInfo &STI) const {
398 if (!MCInstPrinterCtorFn)
400 return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, MII, MRI, STI);
404 /// createMCCodeEmitter - Create a target specific code emitter.
405 MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
406 const MCRegisterInfo &MRI,
407 MCContext &Ctx) const {
408 if (!MCCodeEmitterCtorFn)
410 return MCCodeEmitterCtorFn(II, MRI, Ctx);
413 /// Create a target specific MCStreamer.
415 /// \param T The target triple.
416 /// \param Ctx The target context.
417 /// \param TAB The target assembler backend object. Takes ownership.
418 /// \param OS The stream object.
419 /// \param Emitter The target independent assembler object.Takes ownership.
420 /// \param RelaxAll Relax all fixups?
421 MCStreamer *createMCObjectStreamer(const Triple &T, MCContext &Ctx,
422 MCAsmBackend &TAB, raw_ostream &OS,
423 MCCodeEmitter *Emitter,
424 const MCSubtargetInfo &STI,
425 bool RelaxAll) const {
426 if (!MCObjectStreamerCtorFn)
427 return llvm::createObjectStreamer(T, Ctx, TAB, OS, Emitter, STI,
429 return MCObjectStreamerCtorFn(T, Ctx, TAB, OS, Emitter, STI, RelaxAll);
432 MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
433 bool IsVerboseAsm, bool UseDwarfDirectory,
434 MCInstPrinter *InstPrint, MCCodeEmitter *CE,
435 MCAsmBackend *TAB, bool ShowInst) const {
437 llvm::createAsmStreamer(Ctx, OS, IsVerboseAsm, UseDwarfDirectory,
438 InstPrint, CE, TAB, ShowInst);
439 createAsmTargetStreamer(*S, OS, InstPrint, IsVerboseAsm);
443 MCTargetStreamer *createAsmTargetStreamer(MCStreamer &S,
444 formatted_raw_ostream &OS,
445 MCInstPrinter *InstPrint,
446 bool IsVerboseAsm) const {
447 if (AsmTargetStreamerCtorFn)
448 return AsmTargetStreamerCtorFn(S, OS, InstPrint, IsVerboseAsm);
452 MCStreamer *createNullStreamer(MCContext &Ctx) const {
453 MCStreamer *S = llvm::createNullStreamer(Ctx);
454 createNullTargetStreamer(*S);
458 MCTargetStreamer *createNullTargetStreamer(MCStreamer &S) const {
459 if (NullTargetStreamerCtorFn)
460 return NullTargetStreamerCtorFn(S);
464 /// createMCRelocationInfo - Create a target specific MCRelocationInfo.
466 /// \param TT The target triple.
467 /// \param Ctx The target context.
469 createMCRelocationInfo(StringRef TT, MCContext &Ctx) const {
470 MCRelocationInfoCtorTy Fn = MCRelocationInfoCtorFn
471 ? MCRelocationInfoCtorFn
472 : llvm::createMCRelocationInfo;
476 /// createMCSymbolizer - Create a target specific MCSymbolizer.
478 /// \param TT The target triple.
479 /// \param GetOpInfo The function to get the symbolic information for operands.
480 /// \param SymbolLookUp The function to lookup a symbol name.
481 /// \param DisInfo The pointer to the block of symbolic information for above call
483 /// \param Ctx The target context.
484 /// \param RelInfo The relocation information for this target. Takes ownership.
486 createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
487 LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo,
489 std::unique_ptr<MCRelocationInfo> &&RelInfo) const {
490 MCSymbolizerCtorTy Fn =
491 MCSymbolizerCtorFn ? MCSymbolizerCtorFn : llvm::createMCSymbolizer;
492 return Fn(TT, GetOpInfo, SymbolLookUp, DisInfo, Ctx, std::move(RelInfo));
498 /// TargetRegistry - Generic interface to target specific features.
499 struct TargetRegistry {
501 const Target *Current;
502 explicit iterator(Target *T) : Current(T) {}
503 friend struct TargetRegistry;
505 iterator() : Current(nullptr) {}
507 bool operator==(const iterator &x) const {
508 return Current == x.Current;
510 bool operator!=(const iterator &x) const {
511 return !operator==(x);
514 // Iterator traversal: forward iteration only
515 iterator &operator++() { // Preincrement
516 assert(Current && "Cannot increment end iterator!");
517 Current = Current->getNext();
520 iterator operator++(int) { // Postincrement
521 iterator tmp = *this;
526 const Target &operator*() const {
527 assert(Current && "Cannot dereference end iterator!");
531 const Target *operator->() const {
536 /// printRegisteredTargetsForVersion - Print the registered targets
537 /// appropriately for inclusion in a tool's version output.
538 static void printRegisteredTargetsForVersion();
540 /// @name Registry Access
543 static iterator begin();
545 static iterator end() { return iterator(); }
547 /// lookupTarget - Lookup a target based on a target triple.
549 /// \param Triple - The triple to use for finding a target.
550 /// \param Error - On failure, an error string describing why no target was
552 static const Target *lookupTarget(const std::string &Triple,
555 /// lookupTarget - Lookup a target based on an architecture name
556 /// and a target triple. If the architecture name is non-empty,
557 /// then the lookup is done by architecture. Otherwise, the target
560 /// \param ArchName - The architecture to use for finding a target.
561 /// \param TheTriple - The triple to use for finding a target. The
562 /// triple is updated with canonical architecture name if a lookup
563 /// by architecture is done.
564 /// \param Error - On failure, an error string describing why no target was
566 static const Target *lookupTarget(const std::string &ArchName,
571 /// @name Target Registration
574 /// RegisterTarget - Register the given target. Attempts to register a
575 /// target which has already been registered will be ignored.
577 /// Clients are responsible for ensuring that registration doesn't occur
578 /// while another thread is attempting to access the registry. Typically
579 /// this is done by initializing all targets at program startup.
581 /// @param T - The target being registered.
582 /// @param Name - The target name. This should be a static string.
583 /// @param ShortDesc - A short target description. This should be a static
585 /// @param ArchMatchFn - The arch match checking function for this target.
586 /// @param HasJIT - Whether the target supports JIT code
588 static void RegisterTarget(Target &T,
590 const char *ShortDesc,
591 Target::ArchMatchFnTy ArchMatchFn,
592 bool HasJIT = false);
594 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
597 /// Clients are responsible for ensuring that registration doesn't occur
598 /// while another thread is attempting to access the registry. Typically
599 /// this is done by initializing all targets at program startup.
601 /// @param T - The target being registered.
602 /// @param Fn - A function to construct a MCAsmInfo for the target.
603 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
604 T.MCAsmInfoCtorFn = Fn;
607 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
610 /// Clients are responsible for ensuring that registration doesn't occur
611 /// while another thread is attempting to access the registry. Typically
612 /// this is done by initializing all targets at program startup.
614 /// @param T - The target being registered.
615 /// @param Fn - A function to construct a MCCodeGenInfo for the target.
616 static void RegisterMCCodeGenInfo(Target &T,
617 Target::MCCodeGenInfoCtorFnTy Fn) {
618 T.MCCodeGenInfoCtorFn = Fn;
621 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
624 /// Clients are responsible for ensuring that registration doesn't occur
625 /// while another thread is attempting to access the registry. Typically
626 /// this is done by initializing all targets at program startup.
628 /// @param T - The target being registered.
629 /// @param Fn - A function to construct a MCInstrInfo for the target.
630 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
631 T.MCInstrInfoCtorFn = Fn;
634 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
635 /// the given target.
636 static void RegisterMCInstrAnalysis(Target &T,
637 Target::MCInstrAnalysisCtorFnTy Fn) {
638 T.MCInstrAnalysisCtorFn = Fn;
641 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
644 /// Clients are responsible for ensuring that registration doesn't occur
645 /// while another thread is attempting to access the registry. Typically
646 /// this is done by initializing all targets at program startup.
648 /// @param T - The target being registered.
649 /// @param Fn - A function to construct a MCRegisterInfo for the target.
650 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
651 T.MCRegInfoCtorFn = Fn;
654 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
655 /// the given target.
657 /// Clients are responsible for ensuring that registration doesn't occur
658 /// while another thread is attempting to access the registry. Typically
659 /// this is done by initializing all targets at program startup.
661 /// @param T - The target being registered.
662 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
663 static void RegisterMCSubtargetInfo(Target &T,
664 Target::MCSubtargetInfoCtorFnTy Fn) {
665 T.MCSubtargetInfoCtorFn = Fn;
668 /// RegisterTargetMachine - Register a TargetMachine implementation for the
671 /// Clients are responsible for ensuring that registration doesn't occur
672 /// while another thread is attempting to access the registry. Typically
673 /// this is done by initializing all targets at program startup.
675 /// @param T - The target being registered.
676 /// @param Fn - A function to construct a TargetMachine for the target.
677 static void RegisterTargetMachine(Target &T,
678 Target::TargetMachineCtorTy Fn) {
679 T.TargetMachineCtorFn = Fn;
682 /// RegisterMCAsmBackend - Register a MCAsmBackend 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 an AsmBackend for the target.
691 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
692 T.MCAsmBackendCtorFn = Fn;
695 /// RegisterMCAsmParser - Register a MCTargetAsmParser 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 an MCTargetAsmParser for the target.
704 static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
705 T.MCAsmParserCtorFn = Fn;
708 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
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 an AsmPrinter for the target.
717 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
718 T.AsmPrinterCtorFn = Fn;
721 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
722 /// the given target.
724 /// Clients are responsible for ensuring that registration doesn't occur
725 /// while another thread is attempting to access the registry. Typically
726 /// this is done by initializing all targets at program startup.
728 /// @param T - The target being registered.
729 /// @param Fn - A function to construct an MCDisassembler for the target.
730 static void RegisterMCDisassembler(Target &T,
731 Target::MCDisassemblerCtorTy Fn) {
732 T.MCDisassemblerCtorFn = Fn;
735 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
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 MCInstPrinter for the target.
744 static void RegisterMCInstPrinter(Target &T,
745 Target::MCInstPrinterCtorTy Fn) {
746 T.MCInstPrinterCtorFn = Fn;
749 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
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 MCCodeEmitter for the target.
758 static void RegisterMCCodeEmitter(Target &T,
759 Target::MCCodeEmitterCtorTy Fn) {
760 T.MCCodeEmitterCtorFn = Fn;
763 /// RegisterMCObjectStreamer - Register a object code MCStreamer
764 /// implementation for the given target.
766 /// Clients are responsible for ensuring that registration doesn't occur
767 /// while another thread is attempting to access the registry. Typically
768 /// this is done by initializing all targets at program startup.
770 /// @param T - The target being registered.
771 /// @param Fn - A function to construct an MCStreamer for the target.
772 static void RegisterMCObjectStreamer(Target &T,
773 Target::MCObjectStreamerCtorTy Fn) {
774 T.MCObjectStreamerCtorFn = Fn;
778 RegisterNullTargetStreamer(Target &T, Target::NullTargetStreamerCtorTy Fn) {
779 T.NullTargetStreamerCtorFn = Fn;
782 static void RegisterAsmTargetStreamer(Target &T,
783 Target::AsmTargetStreamerCtorTy Fn) {
784 T.AsmTargetStreamerCtorFn = Fn;
787 /// RegisterMCRelocationInfo - Register an MCRelocationInfo
788 /// implementation for the given target.
790 /// Clients are responsible for ensuring that registration doesn't occur
791 /// while another thread is attempting to access the registry. Typically
792 /// this is done by initializing all targets at program startup.
794 /// @param T - The target being registered.
795 /// @param Fn - A function to construct an MCRelocationInfo for the target.
796 static void RegisterMCRelocationInfo(Target &T,
797 Target::MCRelocationInfoCtorTy Fn) {
798 T.MCRelocationInfoCtorFn = Fn;
801 /// RegisterMCSymbolizer - Register an MCSymbolizer
802 /// implementation for the given target.
804 /// Clients are responsible for ensuring that registration doesn't occur
805 /// while another thread is attempting to access the registry. Typically
806 /// this is done by initializing all targets at program startup.
808 /// @param T - The target being registered.
809 /// @param Fn - A function to construct an MCSymbolizer for the target.
810 static void RegisterMCSymbolizer(Target &T,
811 Target::MCSymbolizerCtorTy Fn) {
812 T.MCSymbolizerCtorFn = Fn;
819 //===--------------------------------------------------------------------===//
821 /// RegisterTarget - Helper template for registering a target, for use in the
822 /// target's initialization function. Usage:
825 /// Target TheFooTarget; // The global target instance.
827 /// extern "C" void LLVMInitializeFooTargetInfo() {
828 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
830 template<Triple::ArchType TargetArchType = Triple::UnknownArch,
832 struct RegisterTarget {
833 RegisterTarget(Target &T, const char *Name, const char *Desc) {
834 TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch, HasJIT);
837 static bool getArchMatch(Triple::ArchType Arch) {
838 return Arch == TargetArchType;
842 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
843 /// implementation. This invokes the static "Create" method on the class to
844 /// actually do the construction. Usage:
846 /// extern "C" void LLVMInitializeFooTarget() {
847 /// extern Target TheFooTarget;
848 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
850 template<class MCAsmInfoImpl>
851 struct RegisterMCAsmInfo {
852 RegisterMCAsmInfo(Target &T) {
853 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
856 static MCAsmInfo *Allocator(const MCRegisterInfo &/*MRI*/, StringRef TT) {
857 return new MCAsmInfoImpl(TT);
862 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
863 /// implementation. This invokes the specified function to do the
864 /// construction. Usage:
866 /// extern "C" void LLVMInitializeFooTarget() {
867 /// extern Target TheFooTarget;
868 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
870 struct RegisterMCAsmInfoFn {
871 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
872 TargetRegistry::RegisterMCAsmInfo(T, Fn);
876 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
877 /// implementation. This invokes the static "Create" method on the class
878 /// to actually do the construction. Usage:
880 /// extern "C" void LLVMInitializeFooTarget() {
881 /// extern Target TheFooTarget;
882 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
884 template<class MCCodeGenInfoImpl>
885 struct RegisterMCCodeGenInfo {
886 RegisterMCCodeGenInfo(Target &T) {
887 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
890 static MCCodeGenInfo *Allocator(StringRef /*TT*/, Reloc::Model /*RM*/,
891 CodeModel::Model /*CM*/,
892 CodeGenOpt::Level /*OL*/) {
893 return new MCCodeGenInfoImpl();
897 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
898 /// info implementation. This invokes the specified function to do the
899 /// construction. Usage:
901 /// extern "C" void LLVMInitializeFooTarget() {
902 /// extern Target TheFooTarget;
903 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
905 struct RegisterMCCodeGenInfoFn {
906 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
907 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
911 /// RegisterMCInstrInfo - Helper template for registering a target instruction
912 /// info implementation. This invokes the static "Create" method on the class
913 /// to actually do the construction. Usage:
915 /// extern "C" void LLVMInitializeFooTarget() {
916 /// extern Target TheFooTarget;
917 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
919 template<class MCInstrInfoImpl>
920 struct RegisterMCInstrInfo {
921 RegisterMCInstrInfo(Target &T) {
922 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
925 static MCInstrInfo *Allocator() {
926 return new MCInstrInfoImpl();
930 /// RegisterMCInstrInfoFn - Helper template for registering a target
931 /// instruction info implementation. This invokes the specified function to
932 /// do the construction. Usage:
934 /// extern "C" void LLVMInitializeFooTarget() {
935 /// extern Target TheFooTarget;
936 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
938 struct RegisterMCInstrInfoFn {
939 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
940 TargetRegistry::RegisterMCInstrInfo(T, Fn);
944 /// RegisterMCInstrAnalysis - Helper template for registering a target
945 /// instruction analyzer implementation. This invokes the static "Create"
946 /// method on the class to actually do the construction. Usage:
948 /// extern "C" void LLVMInitializeFooTarget() {
949 /// extern Target TheFooTarget;
950 /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
952 template<class MCInstrAnalysisImpl>
953 struct RegisterMCInstrAnalysis {
954 RegisterMCInstrAnalysis(Target &T) {
955 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
958 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
959 return new MCInstrAnalysisImpl(Info);
963 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
964 /// instruction analyzer implementation. This invokes the specified function
965 /// to do the construction. Usage:
967 /// extern "C" void LLVMInitializeFooTarget() {
968 /// extern Target TheFooTarget;
969 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
971 struct RegisterMCInstrAnalysisFn {
972 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
973 TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
977 /// RegisterMCRegInfo - Helper template for registering a target register info
978 /// implementation. This invokes the static "Create" method on the class to
979 /// actually do the construction. Usage:
981 /// extern "C" void LLVMInitializeFooTarget() {
982 /// extern Target TheFooTarget;
983 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
985 template<class MCRegisterInfoImpl>
986 struct RegisterMCRegInfo {
987 RegisterMCRegInfo(Target &T) {
988 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
991 static MCRegisterInfo *Allocator(StringRef /*TT*/) {
992 return new MCRegisterInfoImpl();
996 /// RegisterMCRegInfoFn - Helper template for registering a target register
997 /// info implementation. This invokes the specified function to do the
998 /// construction. Usage:
1000 /// extern "C" void LLVMInitializeFooTarget() {
1001 /// extern Target TheFooTarget;
1002 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
1004 struct RegisterMCRegInfoFn {
1005 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
1006 TargetRegistry::RegisterMCRegInfo(T, Fn);
1010 /// RegisterMCSubtargetInfo - Helper template for registering a target
1011 /// subtarget info implementation. This invokes the static "Create" method
1012 /// on the class to actually do the construction. Usage:
1014 /// extern "C" void LLVMInitializeFooTarget() {
1015 /// extern Target TheFooTarget;
1016 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
1018 template<class MCSubtargetInfoImpl>
1019 struct RegisterMCSubtargetInfo {
1020 RegisterMCSubtargetInfo(Target &T) {
1021 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
1024 static MCSubtargetInfo *Allocator(StringRef /*TT*/, StringRef /*CPU*/,
1026 return new MCSubtargetInfoImpl();
1030 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
1031 /// subtarget info implementation. This invokes the specified function to
1032 /// do the construction. Usage:
1034 /// extern "C" void LLVMInitializeFooTarget() {
1035 /// extern Target TheFooTarget;
1036 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1038 struct RegisterMCSubtargetInfoFn {
1039 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
1040 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
1044 /// RegisterTargetMachine - Helper template for registering a target machine
1045 /// implementation, for use in the target machine initialization
1046 /// function. Usage:
1048 /// extern "C" void LLVMInitializeFooTarget() {
1049 /// extern Target TheFooTarget;
1050 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1052 template<class TargetMachineImpl>
1053 struct RegisterTargetMachine {
1054 RegisterTargetMachine(Target &T) {
1055 TargetRegistry::RegisterTargetMachine(T, &Allocator);
1059 static TargetMachine *Allocator(const Target &T, StringRef TT,
1060 StringRef CPU, StringRef FS,
1061 const TargetOptions &Options,
1063 CodeModel::Model CM,
1064 CodeGenOpt::Level OL) {
1065 return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
1069 /// RegisterMCAsmBackend - Helper template for registering a target specific
1070 /// assembler backend. Usage:
1072 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1073 /// extern Target TheFooTarget;
1074 /// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1076 template<class MCAsmBackendImpl>
1077 struct RegisterMCAsmBackend {
1078 RegisterMCAsmBackend(Target &T) {
1079 TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1083 static MCAsmBackend *Allocator(const Target &T,
1084 const MCRegisterInfo &MRI,
1085 StringRef Triple, StringRef CPU) {
1086 return new MCAsmBackendImpl(T, MRI, Triple, CPU);
1090 /// RegisterMCAsmParser - Helper template for registering a target specific
1091 /// assembly parser, for use in the target machine initialization
1092 /// function. Usage:
1094 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1095 /// extern Target TheFooTarget;
1096 /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1098 template<class MCAsmParserImpl>
1099 struct RegisterMCAsmParser {
1100 RegisterMCAsmParser(Target &T) {
1101 TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1105 static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P,
1106 const MCInstrInfo &MII,
1107 const MCTargetOptions &Options) {
1108 return new MCAsmParserImpl(STI, P, MII, Options);
1112 /// RegisterAsmPrinter - Helper template for registering a target specific
1113 /// assembly printer, for use in the target machine initialization
1114 /// function. Usage:
1116 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1117 /// extern Target TheFooTarget;
1118 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1120 template<class AsmPrinterImpl>
1121 struct RegisterAsmPrinter {
1122 RegisterAsmPrinter(Target &T) {
1123 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1127 static AsmPrinter *Allocator(TargetMachine &TM,
1128 std::unique_ptr<MCStreamer> &&Streamer) {
1129 return new AsmPrinterImpl(TM, std::move(Streamer));
1133 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1134 /// machine code emitter, for use in the target initialization
1135 /// function. Usage:
1137 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1138 /// extern Target TheFooTarget;
1139 /// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1141 template<class MCCodeEmitterImpl>
1142 struct RegisterMCCodeEmitter {
1143 RegisterMCCodeEmitter(Target &T) {
1144 TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1148 static MCCodeEmitter *Allocator(const MCInstrInfo & /*II*/,
1149 const MCRegisterInfo & /*MRI*/,
1150 MCContext & /*Ctx*/) {
1151 return new MCCodeEmitterImpl();