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 : NullTargetStreamerCtorFn(nullptr), AsmTargetStreamerCtorFn(nullptr),
239 MCRelocationInfoCtorFn(nullptr), MCSymbolizerCtorFn(nullptr) {}
241 /// @name Target Information
244 // getNext - Return the next registered target.
245 const Target *getNext() const { return Next; }
247 /// getName - Get the target name.
248 const char *getName() const { return Name; }
250 /// getShortDescription - Get a short description of the target.
251 const char *getShortDescription() const { return ShortDesc; }
254 /// @name Feature Predicates
257 /// hasJIT - Check if this targets supports the just-in-time compilation.
258 bool hasJIT() const { return HasJIT; }
260 /// hasTargetMachine - Check if this target supports code generation.
261 bool hasTargetMachine() const { return TargetMachineCtorFn != nullptr; }
263 /// hasMCAsmBackend - Check if this target supports .o generation.
264 bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != nullptr; }
267 /// @name Feature Constructors
270 /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
273 /// \param Triple This argument is used to determine the target machine
274 /// feature set; it should always be provided. Generally this should be
275 /// either the target triple from the module, or the target triple of the
276 /// host if that does not exist.
277 MCAsmInfo *createMCAsmInfo(const MCRegisterInfo &MRI,
278 StringRef Triple) const {
279 if (!MCAsmInfoCtorFn)
281 return MCAsmInfoCtorFn(MRI, Triple);
284 /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
286 MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model RM,
288 CodeGenOpt::Level OL) const {
289 if (!MCCodeGenInfoCtorFn)
291 return MCCodeGenInfoCtorFn(Triple, RM, CM, OL);
294 /// createMCInstrInfo - Create a MCInstrInfo implementation.
296 MCInstrInfo *createMCInstrInfo() const {
297 if (!MCInstrInfoCtorFn)
299 return MCInstrInfoCtorFn();
302 /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
304 MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
305 if (!MCInstrAnalysisCtorFn)
307 return MCInstrAnalysisCtorFn(Info);
310 /// createMCRegInfo - Create a MCRegisterInfo implementation.
312 MCRegisterInfo *createMCRegInfo(StringRef Triple) const {
313 if (!MCRegInfoCtorFn)
315 return MCRegInfoCtorFn(Triple);
318 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
320 /// \param Triple This argument is used to determine the target machine
321 /// feature set; it should always be provided. Generally this should be
322 /// either the target triple from the module, or the target triple of the
323 /// host if that does not exist.
324 /// \param CPU This specifies the name of the target CPU.
325 /// \param Features This specifies the string representation of the
326 /// additional target features.
327 MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU,
328 StringRef Features) const {
329 if (!MCSubtargetInfoCtorFn)
331 return MCSubtargetInfoCtorFn(Triple, CPU, Features);
334 /// createTargetMachine - Create a target specific machine implementation
335 /// for the specified \p Triple.
337 /// \param Triple This argument is used to determine the target machine
338 /// feature set; it should always be provided. Generally this should be
339 /// either the target triple from the module, or the target triple of the
340 /// host if that does not exist.
341 TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU,
342 StringRef Features, const TargetOptions &Options,
343 Reloc::Model RM = Reloc::Default,
344 CodeModel::Model CM = CodeModel::Default,
345 CodeGenOpt::Level OL = CodeGenOpt::Default) const {
346 if (!TargetMachineCtorFn)
348 return TargetMachineCtorFn(*this, Triple, CPU, Features, Options,
352 /// createMCAsmBackend - Create a target specific assembly parser.
354 /// \param Triple The target triple string.
355 MCAsmBackend *createMCAsmBackend(const MCRegisterInfo &MRI,
356 StringRef Triple, StringRef CPU) const {
357 if (!MCAsmBackendCtorFn)
359 return MCAsmBackendCtorFn(*this, MRI, Triple, CPU);
362 /// createMCAsmParser - Create a target specific assembly parser.
364 /// \param Parser The target independent parser implementation to use for
365 /// parsing and lexing.
366 MCTargetAsmParser *createMCAsmParser(
367 MCSubtargetInfo &STI,
369 const MCInstrInfo &MII,
370 const MCTargetOptions &Options) const {
371 if (!MCAsmParserCtorFn)
373 return MCAsmParserCtorFn(STI, Parser, MII, Options);
376 /// createAsmPrinter - Create a target specific assembly printer pass. This
377 /// takes ownership of the MCStreamer object.
378 AsmPrinter *createAsmPrinter(TargetMachine &TM,
379 std::unique_ptr<MCStreamer> &&Streamer) const {
380 if (!AsmPrinterCtorFn)
382 return AsmPrinterCtorFn(TM, std::move(Streamer));
385 MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI,
386 MCContext &Ctx) const {
387 if (!MCDisassemblerCtorFn)
389 return MCDisassemblerCtorFn(*this, STI, Ctx);
392 MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
393 const MCAsmInfo &MAI,
394 const MCInstrInfo &MII,
395 const MCRegisterInfo &MRI,
396 const MCSubtargetInfo &STI) const {
397 if (!MCInstPrinterCtorFn)
399 return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, MII, MRI, STI);
403 /// createMCCodeEmitter - Create a target specific code emitter.
404 MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
405 const MCRegisterInfo &MRI,
406 MCContext &Ctx) const {
407 if (!MCCodeEmitterCtorFn)
409 return MCCodeEmitterCtorFn(II, MRI, Ctx);
412 /// Create a target specific MCStreamer.
414 /// \param T The target triple.
415 /// \param Ctx The target context.
416 /// \param TAB The target assembler backend object. Takes ownership.
417 /// \param OS The stream object.
418 /// \param Emitter The target independent assembler object.Takes ownership.
419 /// \param RelaxAll Relax all fixups?
420 MCStreamer *createMCObjectStreamer(const Triple &T, MCContext &Ctx,
421 MCAsmBackend &TAB, raw_ostream &OS,
422 MCCodeEmitter *Emitter,
423 const MCSubtargetInfo &STI,
424 bool RelaxAll) const {
425 if (!MCObjectStreamerCtorFn)
426 return llvm::createObjectStreamer(T, Ctx, TAB, OS, Emitter, STI,
428 return MCObjectStreamerCtorFn(T, Ctx, TAB, OS, Emitter, STI, RelaxAll);
431 MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
432 bool IsVerboseAsm, bool UseDwarfDirectory,
433 MCInstPrinter *InstPrint, MCCodeEmitter *CE,
434 MCAsmBackend *TAB, bool ShowInst) const {
436 llvm::createAsmStreamer(Ctx, OS, IsVerboseAsm, UseDwarfDirectory,
437 InstPrint, CE, TAB, ShowInst);
438 createAsmTargetStreamer(*S, OS, InstPrint, IsVerboseAsm);
442 MCTargetStreamer *createAsmTargetStreamer(MCStreamer &S,
443 formatted_raw_ostream &OS,
444 MCInstPrinter *InstPrint,
445 bool IsVerboseAsm) const {
446 if (AsmTargetStreamerCtorFn)
447 return AsmTargetStreamerCtorFn(S, OS, InstPrint, IsVerboseAsm);
451 MCStreamer *createNullStreamer(MCContext &Ctx) const {
452 MCStreamer *S = llvm::createNullStreamer(Ctx);
453 createNullTargetStreamer(*S);
457 MCTargetStreamer *createNullTargetStreamer(MCStreamer &S) const {
458 if (NullTargetStreamerCtorFn)
459 return NullTargetStreamerCtorFn(S);
463 /// createMCRelocationInfo - Create a target specific MCRelocationInfo.
465 /// \param TT The target triple.
466 /// \param Ctx The target context.
468 createMCRelocationInfo(StringRef TT, MCContext &Ctx) const {
469 MCRelocationInfoCtorTy Fn = MCRelocationInfoCtorFn
470 ? MCRelocationInfoCtorFn
471 : llvm::createMCRelocationInfo;
475 /// createMCSymbolizer - Create a target specific MCSymbolizer.
477 /// \param TT The target triple.
478 /// \param GetOpInfo The function to get the symbolic information for operands.
479 /// \param SymbolLookUp The function to lookup a symbol name.
480 /// \param DisInfo The pointer to the block of symbolic information for above call
482 /// \param Ctx The target context.
483 /// \param RelInfo The relocation information for this target. Takes ownership.
485 createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
486 LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo,
488 std::unique_ptr<MCRelocationInfo> &&RelInfo) const {
489 MCSymbolizerCtorTy Fn =
490 MCSymbolizerCtorFn ? MCSymbolizerCtorFn : llvm::createMCSymbolizer;
491 return Fn(TT, GetOpInfo, SymbolLookUp, DisInfo, Ctx, std::move(RelInfo));
497 /// TargetRegistry - Generic interface to target specific features.
498 struct TargetRegistry {
500 const Target *Current;
501 explicit iterator(Target *T) : Current(T) {}
502 friend struct TargetRegistry;
504 iterator() : Current(nullptr) {}
506 bool operator==(const iterator &x) const {
507 return Current == x.Current;
509 bool operator!=(const iterator &x) const {
510 return !operator==(x);
513 // Iterator traversal: forward iteration only
514 iterator &operator++() { // Preincrement
515 assert(Current && "Cannot increment end iterator!");
516 Current = Current->getNext();
519 iterator operator++(int) { // Postincrement
520 iterator tmp = *this;
525 const Target &operator*() const {
526 assert(Current && "Cannot dereference end iterator!");
530 const Target *operator->() const {
535 /// printRegisteredTargetsForVersion - Print the registered targets
536 /// appropriately for inclusion in a tool's version output.
537 static void printRegisteredTargetsForVersion();
539 /// @name Registry Access
542 static iterator begin();
544 static iterator end() { return iterator(); }
546 /// lookupTarget - Lookup a target based on a target triple.
548 /// \param Triple - The triple to use for finding a target.
549 /// \param Error - On failure, an error string describing why no target was
551 static const Target *lookupTarget(const std::string &Triple,
554 /// lookupTarget - Lookup a target based on an architecture name
555 /// and a target triple. If the architecture name is non-empty,
556 /// then the lookup is done by architecture. Otherwise, the target
559 /// \param ArchName - The architecture to use for finding a target.
560 /// \param TheTriple - The triple to use for finding a target. The
561 /// triple is updated with canonical architecture name if a lookup
562 /// by architecture is done.
563 /// \param Error - On failure, an error string describing why no target was
565 static const Target *lookupTarget(const std::string &ArchName,
570 /// @name Target Registration
573 /// RegisterTarget - Register the given target. Attempts to register a
574 /// target which has already been registered will be ignored.
576 /// Clients are responsible for ensuring that registration doesn't occur
577 /// while another thread is attempting to access the registry. Typically
578 /// this is done by initializing all targets at program startup.
580 /// @param T - The target being registered.
581 /// @param Name - The target name. This should be a static string.
582 /// @param ShortDesc - A short target description. This should be a static
584 /// @param ArchMatchFn - The arch match checking function for this target.
585 /// @param HasJIT - Whether the target supports JIT code
587 static void RegisterTarget(Target &T,
589 const char *ShortDesc,
590 Target::ArchMatchFnTy ArchMatchFn,
591 bool HasJIT = false);
593 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
596 /// Clients are responsible for ensuring that registration doesn't occur
597 /// while another thread is attempting to access the registry. Typically
598 /// this is done by initializing all targets at program startup.
600 /// @param T - The target being registered.
601 /// @param Fn - A function to construct a MCAsmInfo for the target.
602 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
603 T.MCAsmInfoCtorFn = Fn;
606 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
609 /// Clients are responsible for ensuring that registration doesn't occur
610 /// while another thread is attempting to access the registry. Typically
611 /// this is done by initializing all targets at program startup.
613 /// @param T - The target being registered.
614 /// @param Fn - A function to construct a MCCodeGenInfo for the target.
615 static void RegisterMCCodeGenInfo(Target &T,
616 Target::MCCodeGenInfoCtorFnTy Fn) {
617 T.MCCodeGenInfoCtorFn = Fn;
620 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
623 /// Clients are responsible for ensuring that registration doesn't occur
624 /// while another thread is attempting to access the registry. Typically
625 /// this is done by initializing all targets at program startup.
627 /// @param T - The target being registered.
628 /// @param Fn - A function to construct a MCInstrInfo for the target.
629 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
630 T.MCInstrInfoCtorFn = Fn;
633 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
634 /// the given target.
635 static void RegisterMCInstrAnalysis(Target &T,
636 Target::MCInstrAnalysisCtorFnTy Fn) {
637 T.MCInstrAnalysisCtorFn = Fn;
640 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
643 /// Clients are responsible for ensuring that registration doesn't occur
644 /// while another thread is attempting to access the registry. Typically
645 /// this is done by initializing all targets at program startup.
647 /// @param T - The target being registered.
648 /// @param Fn - A function to construct a MCRegisterInfo for the target.
649 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
650 T.MCRegInfoCtorFn = Fn;
653 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
654 /// the given target.
656 /// Clients are responsible for ensuring that registration doesn't occur
657 /// while another thread is attempting to access the registry. Typically
658 /// this is done by initializing all targets at program startup.
660 /// @param T - The target being registered.
661 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
662 static void RegisterMCSubtargetInfo(Target &T,
663 Target::MCSubtargetInfoCtorFnTy Fn) {
664 T.MCSubtargetInfoCtorFn = Fn;
667 /// RegisterTargetMachine - Register a TargetMachine implementation for the
670 /// Clients are responsible for ensuring that registration doesn't occur
671 /// while another thread is attempting to access the registry. Typically
672 /// this is done by initializing all targets at program startup.
674 /// @param T - The target being registered.
675 /// @param Fn - A function to construct a TargetMachine for the target.
676 static void RegisterTargetMachine(Target &T,
677 Target::TargetMachineCtorTy Fn) {
678 T.TargetMachineCtorFn = Fn;
681 /// RegisterMCAsmBackend - Register a MCAsmBackend 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 an AsmBackend for the target.
690 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
691 T.MCAsmBackendCtorFn = Fn;
694 /// RegisterMCAsmParser - Register a MCTargetAsmParser 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 an MCTargetAsmParser for the target.
703 static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
704 T.MCAsmParserCtorFn = Fn;
707 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
710 /// Clients are responsible for ensuring that registration doesn't occur
711 /// while another thread is attempting to access the registry. Typically
712 /// this is done by initializing all targets at program startup.
714 /// @param T - The target being registered.
715 /// @param Fn - A function to construct an AsmPrinter for the target.
716 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
717 T.AsmPrinterCtorFn = Fn;
720 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
721 /// the given target.
723 /// Clients are responsible for ensuring that registration doesn't occur
724 /// while another thread is attempting to access the registry. Typically
725 /// this is done by initializing all targets at program startup.
727 /// @param T - The target being registered.
728 /// @param Fn - A function to construct an MCDisassembler for the target.
729 static void RegisterMCDisassembler(Target &T,
730 Target::MCDisassemblerCtorTy Fn) {
731 T.MCDisassemblerCtorFn = Fn;
734 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
737 /// Clients are responsible for ensuring that registration doesn't occur
738 /// while another thread is attempting to access the registry. Typically
739 /// this is done by initializing all targets at program startup.
741 /// @param T - The target being registered.
742 /// @param Fn - A function to construct an MCInstPrinter for the target.
743 static void RegisterMCInstPrinter(Target &T,
744 Target::MCInstPrinterCtorTy Fn) {
745 T.MCInstPrinterCtorFn = Fn;
748 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
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 MCCodeEmitter for the target.
757 static void RegisterMCCodeEmitter(Target &T,
758 Target::MCCodeEmitterCtorTy Fn) {
759 T.MCCodeEmitterCtorFn = Fn;
762 /// RegisterMCObjectStreamer - Register a object code MCStreamer
763 /// implementation for 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 MCStreamer for the target.
771 static void RegisterMCObjectStreamer(Target &T,
772 Target::MCObjectStreamerCtorTy Fn) {
773 T.MCObjectStreamerCtorFn = Fn;
777 RegisterNullTargetStreamer(Target &T, Target::NullTargetStreamerCtorTy Fn) {
778 T.NullTargetStreamerCtorFn = Fn;
781 static void RegisterAsmTargetStreamer(Target &T,
782 Target::AsmTargetStreamerCtorTy Fn) {
783 T.AsmTargetStreamerCtorFn = Fn;
786 /// RegisterMCRelocationInfo - Register an MCRelocationInfo
787 /// implementation for the given target.
789 /// Clients are responsible for ensuring that registration doesn't occur
790 /// while another thread is attempting to access the registry. Typically
791 /// this is done by initializing all targets at program startup.
793 /// @param T - The target being registered.
794 /// @param Fn - A function to construct an MCRelocationInfo for the target.
795 static void RegisterMCRelocationInfo(Target &T,
796 Target::MCRelocationInfoCtorTy Fn) {
797 T.MCRelocationInfoCtorFn = Fn;
800 /// RegisterMCSymbolizer - Register an MCSymbolizer
801 /// implementation for the given target.
803 /// Clients are responsible for ensuring that registration doesn't occur
804 /// while another thread is attempting to access the registry. Typically
805 /// this is done by initializing all targets at program startup.
807 /// @param T - The target being registered.
808 /// @param Fn - A function to construct an MCSymbolizer for the target.
809 static void RegisterMCSymbolizer(Target &T,
810 Target::MCSymbolizerCtorTy Fn) {
811 T.MCSymbolizerCtorFn = Fn;
818 //===--------------------------------------------------------------------===//
820 /// RegisterTarget - Helper template for registering a target, for use in the
821 /// target's initialization function. Usage:
824 /// Target TheFooTarget; // The global target instance.
826 /// extern "C" void LLVMInitializeFooTargetInfo() {
827 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
829 template<Triple::ArchType TargetArchType = Triple::UnknownArch,
831 struct RegisterTarget {
832 RegisterTarget(Target &T, const char *Name, const char *Desc) {
833 TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch, HasJIT);
836 static bool getArchMatch(Triple::ArchType Arch) {
837 return Arch == TargetArchType;
841 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
842 /// implementation. This invokes the static "Create" method on the class to
843 /// actually do the construction. Usage:
845 /// extern "C" void LLVMInitializeFooTarget() {
846 /// extern Target TheFooTarget;
847 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
849 template<class MCAsmInfoImpl>
850 struct RegisterMCAsmInfo {
851 RegisterMCAsmInfo(Target &T) {
852 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
855 static MCAsmInfo *Allocator(const MCRegisterInfo &/*MRI*/, StringRef TT) {
856 return new MCAsmInfoImpl(TT);
861 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
862 /// implementation. This invokes the specified function to do the
863 /// construction. Usage:
865 /// extern "C" void LLVMInitializeFooTarget() {
866 /// extern Target TheFooTarget;
867 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
869 struct RegisterMCAsmInfoFn {
870 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
871 TargetRegistry::RegisterMCAsmInfo(T, Fn);
875 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
876 /// implementation. This invokes the static "Create" method on the class
877 /// to actually do the construction. Usage:
879 /// extern "C" void LLVMInitializeFooTarget() {
880 /// extern Target TheFooTarget;
881 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
883 template<class MCCodeGenInfoImpl>
884 struct RegisterMCCodeGenInfo {
885 RegisterMCCodeGenInfo(Target &T) {
886 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
889 static MCCodeGenInfo *Allocator(StringRef /*TT*/, Reloc::Model /*RM*/,
890 CodeModel::Model /*CM*/,
891 CodeGenOpt::Level /*OL*/) {
892 return new MCCodeGenInfoImpl();
896 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
897 /// info implementation. This invokes the specified function to do the
898 /// construction. Usage:
900 /// extern "C" void LLVMInitializeFooTarget() {
901 /// extern Target TheFooTarget;
902 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
904 struct RegisterMCCodeGenInfoFn {
905 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
906 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
910 /// RegisterMCInstrInfo - Helper template for registering a target instruction
911 /// info implementation. This invokes the static "Create" method on the class
912 /// to actually do the construction. Usage:
914 /// extern "C" void LLVMInitializeFooTarget() {
915 /// extern Target TheFooTarget;
916 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
918 template<class MCInstrInfoImpl>
919 struct RegisterMCInstrInfo {
920 RegisterMCInstrInfo(Target &T) {
921 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
924 static MCInstrInfo *Allocator() {
925 return new MCInstrInfoImpl();
929 /// RegisterMCInstrInfoFn - Helper template for registering a target
930 /// instruction info implementation. This invokes the specified function to
931 /// do the construction. Usage:
933 /// extern "C" void LLVMInitializeFooTarget() {
934 /// extern Target TheFooTarget;
935 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
937 struct RegisterMCInstrInfoFn {
938 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
939 TargetRegistry::RegisterMCInstrInfo(T, Fn);
943 /// RegisterMCInstrAnalysis - Helper template for registering a target
944 /// instruction analyzer implementation. This invokes the static "Create"
945 /// method on the class to actually do the construction. Usage:
947 /// extern "C" void LLVMInitializeFooTarget() {
948 /// extern Target TheFooTarget;
949 /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
951 template<class MCInstrAnalysisImpl>
952 struct RegisterMCInstrAnalysis {
953 RegisterMCInstrAnalysis(Target &T) {
954 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
957 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
958 return new MCInstrAnalysisImpl(Info);
962 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
963 /// instruction analyzer implementation. This invokes the specified function
964 /// to do the construction. Usage:
966 /// extern "C" void LLVMInitializeFooTarget() {
967 /// extern Target TheFooTarget;
968 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
970 struct RegisterMCInstrAnalysisFn {
971 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
972 TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
976 /// RegisterMCRegInfo - Helper template for registering a target register info
977 /// implementation. This invokes the static "Create" method on the class to
978 /// actually do the construction. Usage:
980 /// extern "C" void LLVMInitializeFooTarget() {
981 /// extern Target TheFooTarget;
982 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
984 template<class MCRegisterInfoImpl>
985 struct RegisterMCRegInfo {
986 RegisterMCRegInfo(Target &T) {
987 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
990 static MCRegisterInfo *Allocator(StringRef /*TT*/) {
991 return new MCRegisterInfoImpl();
995 /// RegisterMCRegInfoFn - Helper template for registering a target register
996 /// info implementation. This invokes the specified function to do the
997 /// construction. Usage:
999 /// extern "C" void LLVMInitializeFooTarget() {
1000 /// extern Target TheFooTarget;
1001 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
1003 struct RegisterMCRegInfoFn {
1004 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
1005 TargetRegistry::RegisterMCRegInfo(T, Fn);
1009 /// RegisterMCSubtargetInfo - Helper template for registering a target
1010 /// subtarget info implementation. This invokes the static "Create" method
1011 /// on the class to actually do the construction. Usage:
1013 /// extern "C" void LLVMInitializeFooTarget() {
1014 /// extern Target TheFooTarget;
1015 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
1017 template<class MCSubtargetInfoImpl>
1018 struct RegisterMCSubtargetInfo {
1019 RegisterMCSubtargetInfo(Target &T) {
1020 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
1023 static MCSubtargetInfo *Allocator(StringRef /*TT*/, StringRef /*CPU*/,
1025 return new MCSubtargetInfoImpl();
1029 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
1030 /// subtarget info implementation. This invokes the specified function to
1031 /// do the construction. Usage:
1033 /// extern "C" void LLVMInitializeFooTarget() {
1034 /// extern Target TheFooTarget;
1035 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1037 struct RegisterMCSubtargetInfoFn {
1038 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
1039 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
1043 /// RegisterTargetMachine - Helper template for registering a target machine
1044 /// implementation, for use in the target machine initialization
1045 /// function. Usage:
1047 /// extern "C" void LLVMInitializeFooTarget() {
1048 /// extern Target TheFooTarget;
1049 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1051 template<class TargetMachineImpl>
1052 struct RegisterTargetMachine {
1053 RegisterTargetMachine(Target &T) {
1054 TargetRegistry::RegisterTargetMachine(T, &Allocator);
1058 static TargetMachine *Allocator(const Target &T, StringRef TT,
1059 StringRef CPU, StringRef FS,
1060 const TargetOptions &Options,
1062 CodeModel::Model CM,
1063 CodeGenOpt::Level OL) {
1064 return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
1068 /// RegisterMCAsmBackend - Helper template for registering a target specific
1069 /// assembler backend. Usage:
1071 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1072 /// extern Target TheFooTarget;
1073 /// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1075 template<class MCAsmBackendImpl>
1076 struct RegisterMCAsmBackend {
1077 RegisterMCAsmBackend(Target &T) {
1078 TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1082 static MCAsmBackend *Allocator(const Target &T,
1083 const MCRegisterInfo &MRI,
1084 StringRef Triple, StringRef CPU) {
1085 return new MCAsmBackendImpl(T, MRI, Triple, CPU);
1089 /// RegisterMCAsmParser - Helper template for registering a target specific
1090 /// assembly parser, for use in the target machine initialization
1091 /// function. Usage:
1093 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1094 /// extern Target TheFooTarget;
1095 /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1097 template<class MCAsmParserImpl>
1098 struct RegisterMCAsmParser {
1099 RegisterMCAsmParser(Target &T) {
1100 TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1104 static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P,
1105 const MCInstrInfo &MII,
1106 const MCTargetOptions &Options) {
1107 return new MCAsmParserImpl(STI, P, MII, Options);
1111 /// RegisterAsmPrinter - Helper template for registering a target specific
1112 /// assembly printer, for use in the target machine initialization
1113 /// function. Usage:
1115 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1116 /// extern Target TheFooTarget;
1117 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1119 template<class AsmPrinterImpl>
1120 struct RegisterAsmPrinter {
1121 RegisterAsmPrinter(Target &T) {
1122 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1126 static AsmPrinter *Allocator(TargetMachine &TM,
1127 std::unique_ptr<MCStreamer> &&Streamer) {
1128 return new AsmPrinterImpl(TM, std::move(Streamer));
1132 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1133 /// machine code emitter, for use in the target initialization
1134 /// function. Usage:
1136 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1137 /// extern Target TheFooTarget;
1138 /// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1140 template<class MCCodeEmitterImpl>
1141 struct RegisterMCCodeEmitter {
1142 RegisterMCCodeEmitter(Target &T) {
1143 TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1147 static MCCodeEmitter *Allocator(const MCInstrInfo & /*II*/,
1148 const MCRegisterInfo & /*MRI*/,
1149 MCContext & /*Ctx*/) {
1150 return new MCCodeEmitterImpl();