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"
25 #include "llvm/Support/FormattedStream.h"
39 class MCInstrAnalysis;
44 class MCSubtargetInfo;
46 class MCRelocationInfo;
47 class MCTargetAsmParser;
48 class MCTargetOptions;
49 class MCTargetStreamer;
53 class raw_pwrite_stream;
54 class formatted_raw_ostream;
56 MCStreamer *createNullStreamer(MCContext &Ctx);
57 MCStreamer *createAsmStreamer(MCContext &Ctx,
58 std::unique_ptr<formatted_raw_ostream> OS,
59 bool isVerboseAsm, bool useDwarfDirectory,
60 MCInstPrinter *InstPrint, MCCodeEmitter *CE,
61 MCAsmBackend *TAB, bool ShowInst);
63 /// Takes ownership of \p TAB and \p CE.
64 MCStreamer *createELFStreamer(MCContext &Ctx, MCAsmBackend &TAB,
65 raw_pwrite_stream &OS, MCCodeEmitter *CE,
67 MCStreamer *createMachOStreamer(MCContext &Ctx, MCAsmBackend &TAB,
68 raw_pwrite_stream &OS, MCCodeEmitter *CE,
69 bool RelaxAll, bool DWARFMustBeAtTheEnd,
70 bool LabelSections = false);
72 MCRelocationInfo *createMCRelocationInfo(StringRef TT, MCContext &Ctx);
74 MCSymbolizer *createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
75 LLVMSymbolLookupCallback SymbolLookUp,
76 void *DisInfo, MCContext *Ctx,
77 std::unique_ptr<MCRelocationInfo> &&RelInfo);
79 /// Target - Wrapper for Target specific information.
81 /// For registration purposes, this is a POD type so that targets can be
82 /// registered without the use of static constructors.
84 /// Targets should implement a single global instance of this class (which
85 /// will be zero initialized), and pass that instance to the TargetRegistry as
86 /// part of their initialization.
89 friend struct TargetRegistry;
91 typedef bool (*ArchMatchFnTy)(Triple::ArchType Arch);
93 typedef MCAsmInfo *(*MCAsmInfoCtorFnTy)(const MCRegisterInfo &MRI,
95 typedef MCCodeGenInfo *(*MCCodeGenInfoCtorFnTy)(StringRef TT,
98 CodeGenOpt::Level OL);
99 typedef MCInstrInfo *(*MCInstrInfoCtorFnTy)(void);
100 typedef MCInstrAnalysis *(*MCInstrAnalysisCtorFnTy)(const MCInstrInfo*Info);
101 typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(StringRef TT);
102 typedef MCSubtargetInfo *(*MCSubtargetInfoCtorFnTy)(StringRef TT,
105 typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T,
109 const TargetOptions &Options,
112 CodeGenOpt::Level OL);
113 // If it weren't for layering issues (this header is in llvm/Support, but
114 // depends on MC?) this should take the Streamer by value rather than rvalue
116 typedef AsmPrinter *(*AsmPrinterCtorTy)(
117 TargetMachine &TM, std::unique_ptr<MCStreamer> &&Streamer);
118 typedef MCAsmBackend *(*MCAsmBackendCtorTy)(const Target &T,
119 const MCRegisterInfo &MRI,
122 typedef MCTargetAsmParser *(*MCAsmParserCtorTy)(
123 MCSubtargetInfo &STI,
125 const MCInstrInfo &MII,
126 const MCTargetOptions &Options);
127 typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T,
128 const MCSubtargetInfo &STI,
130 typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Triple &T,
131 unsigned SyntaxVariant,
132 const MCAsmInfo &MAI,
133 const MCInstrInfo &MII,
134 const MCRegisterInfo &MRI);
135 typedef MCCodeEmitter *(*MCCodeEmitterCtorTy)(const MCInstrInfo &II,
136 const MCRegisterInfo &MRI,
138 typedef MCStreamer *(*ELFStreamerCtorTy)(const Triple &T, MCContext &Ctx,
140 raw_pwrite_stream &OS,
141 MCCodeEmitter *Emitter,
143 typedef MCStreamer *(*MachOStreamerCtorTy)(
144 MCContext &Ctx, MCAsmBackend &TAB, raw_pwrite_stream &OS,
145 MCCodeEmitter *Emitter, bool RelaxAll, bool DWARFMustBeAtTheEnd);
146 typedef MCStreamer *(*COFFStreamerCtorTy)(MCContext &Ctx, MCAsmBackend &TAB,
147 raw_pwrite_stream &OS,
148 MCCodeEmitter *Emitter,
150 typedef MCTargetStreamer *(*NullTargetStreamerCtorTy)(MCStreamer &S);
151 typedef MCTargetStreamer *(*AsmTargetStreamerCtorTy)(
152 MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *InstPrint,
154 typedef MCTargetStreamer *(*ObjectTargetStreamerCtorTy)(
155 MCStreamer &S, const MCSubtargetInfo &STI);
156 typedef MCRelocationInfo *(*MCRelocationInfoCtorTy)(StringRef TT,
158 typedef MCSymbolizer *(*MCSymbolizerCtorTy)(
159 StringRef TT, LLVMOpInfoCallback GetOpInfo,
160 LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo, MCContext *Ctx,
161 std::unique_ptr<MCRelocationInfo> &&RelInfo);
164 /// Next - The next registered target in the linked list, maintained by the
168 /// The target function for checking if an architecture is supported.
169 ArchMatchFnTy ArchMatchFn;
171 /// Name - The target name.
174 /// ShortDesc - A short description of the target.
175 const char *ShortDesc;
177 /// HasJIT - Whether this target supports the JIT.
180 /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
182 MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
184 /// MCCodeGenInfoCtorFn - Constructor function for this target's
185 /// MCCodeGenInfo, if registered.
186 MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn;
188 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
190 MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
192 /// MCInstrAnalysisCtorFn - Constructor function for this target's
193 /// MCInstrAnalysis, if registered.
194 MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
196 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
198 MCRegInfoCtorFnTy MCRegInfoCtorFn;
200 /// MCSubtargetInfoCtorFn - Constructor function for this target's
201 /// MCSubtargetInfo, if registered.
202 MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
204 /// TargetMachineCtorFn - Construction function for this target's
205 /// TargetMachine, if registered.
206 TargetMachineCtorTy TargetMachineCtorFn;
208 /// MCAsmBackendCtorFn - Construction function for this target's
209 /// MCAsmBackend, if registered.
210 MCAsmBackendCtorTy MCAsmBackendCtorFn;
212 /// MCAsmParserCtorFn - Construction function for this target's
213 /// MCTargetAsmParser, if registered.
214 MCAsmParserCtorTy MCAsmParserCtorFn;
216 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
218 AsmPrinterCtorTy AsmPrinterCtorFn;
220 /// MCDisassemblerCtorFn - Construction function for this target's
221 /// MCDisassembler, if registered.
222 MCDisassemblerCtorTy MCDisassemblerCtorFn;
224 /// MCInstPrinterCtorFn - Construction function for this target's
225 /// MCInstPrinter, if registered.
226 MCInstPrinterCtorTy MCInstPrinterCtorFn;
228 /// MCCodeEmitterCtorFn - Construction function for this target's
229 /// CodeEmitter, if registered.
230 MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
232 // Construction functions for the various object formats, if registered.
233 COFFStreamerCtorTy COFFStreamerCtorFn;
234 MachOStreamerCtorTy MachOStreamerCtorFn;
235 ELFStreamerCtorTy ELFStreamerCtorFn;
237 /// Construction function for this target's null TargetStreamer, if
238 /// registered (default = nullptr).
239 NullTargetStreamerCtorTy NullTargetStreamerCtorFn;
241 /// Construction function for this target's asm TargetStreamer, if
242 /// registered (default = nullptr).
243 AsmTargetStreamerCtorTy AsmTargetStreamerCtorFn;
245 /// Construction function for this target's obj TargetStreamer, if
246 /// registered (default = nullptr).
247 ObjectTargetStreamerCtorTy ObjectTargetStreamerCtorFn;
249 /// MCRelocationInfoCtorFn - Construction function for this target's
250 /// MCRelocationInfo, if registered (default = llvm::createMCRelocationInfo)
251 MCRelocationInfoCtorTy MCRelocationInfoCtorFn;
253 /// MCSymbolizerCtorFn - Construction function for this target's
254 /// MCSymbolizer, if registered (default = llvm::createMCSymbolizer)
255 MCSymbolizerCtorTy MCSymbolizerCtorFn;
259 : COFFStreamerCtorFn(nullptr), MachOStreamerCtorFn(nullptr),
260 ELFStreamerCtorFn(nullptr), NullTargetStreamerCtorFn(nullptr),
261 AsmTargetStreamerCtorFn(nullptr), ObjectTargetStreamerCtorFn(nullptr),
262 MCRelocationInfoCtorFn(nullptr), MCSymbolizerCtorFn(nullptr) {}
264 /// @name Target Information
267 // getNext - Return the next registered target.
268 const Target *getNext() const { return Next; }
270 /// getName - Get the target name.
271 const char *getName() const { return Name; }
273 /// getShortDescription - Get a short description of the target.
274 const char *getShortDescription() const { return ShortDesc; }
277 /// @name Feature Predicates
280 /// hasJIT - Check if this targets supports the just-in-time compilation.
281 bool hasJIT() const { return HasJIT; }
283 /// hasTargetMachine - Check if this target supports code generation.
284 bool hasTargetMachine() const { return TargetMachineCtorFn != nullptr; }
286 /// hasMCAsmBackend - Check if this target supports .o generation.
287 bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != nullptr; }
290 /// @name Feature Constructors
293 /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
296 /// \param Triple This argument is used to determine the target machine
297 /// feature set; it should always be provided. Generally this should be
298 /// either the target triple from the module, or the target triple of the
299 /// host if that does not exist.
300 MCAsmInfo *createMCAsmInfo(const MCRegisterInfo &MRI,
301 StringRef Triple) const {
302 if (!MCAsmInfoCtorFn)
304 return MCAsmInfoCtorFn(MRI, Triple);
307 /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
309 MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model RM,
311 CodeGenOpt::Level OL) const {
312 if (!MCCodeGenInfoCtorFn)
314 return MCCodeGenInfoCtorFn(Triple, RM, CM, OL);
317 /// createMCInstrInfo - Create a MCInstrInfo implementation.
319 MCInstrInfo *createMCInstrInfo() const {
320 if (!MCInstrInfoCtorFn)
322 return MCInstrInfoCtorFn();
325 /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
327 MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
328 if (!MCInstrAnalysisCtorFn)
330 return MCInstrAnalysisCtorFn(Info);
333 /// createMCRegInfo - Create a MCRegisterInfo implementation.
335 MCRegisterInfo *createMCRegInfo(StringRef Triple) const {
336 if (!MCRegInfoCtorFn)
338 return MCRegInfoCtorFn(Triple);
341 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
343 /// \param Triple This argument is used to determine the target machine
344 /// feature set; it should always be provided. Generally this should be
345 /// either the target triple from the module, or the target triple of the
346 /// host if that does not exist.
347 /// \param CPU This specifies the name of the target CPU.
348 /// \param Features This specifies the string representation of the
349 /// additional target features.
350 MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU,
351 StringRef Features) const {
352 if (!MCSubtargetInfoCtorFn)
354 return MCSubtargetInfoCtorFn(Triple, CPU, Features);
357 /// createTargetMachine - Create a target specific machine implementation
358 /// for the specified \p Triple.
360 /// \param Triple This argument is used to determine the target machine
361 /// feature set; it should always be provided. Generally this should be
362 /// either the target triple from the module, or the target triple of the
363 /// host if that does not exist.
364 TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU,
365 StringRef Features, const TargetOptions &Options,
366 Reloc::Model RM = Reloc::Default,
367 CodeModel::Model CM = CodeModel::Default,
368 CodeGenOpt::Level OL = CodeGenOpt::Default) const {
369 if (!TargetMachineCtorFn)
371 return TargetMachineCtorFn(*this, Triple, CPU, Features, Options,
375 /// createMCAsmBackend - Create a target specific assembly parser.
377 /// \param Triple The target triple string.
378 MCAsmBackend *createMCAsmBackend(const MCRegisterInfo &MRI,
379 StringRef Triple, StringRef CPU) const {
380 if (!MCAsmBackendCtorFn)
382 return MCAsmBackendCtorFn(*this, MRI, Triple, CPU);
385 /// createMCAsmParser - Create a target specific assembly parser.
387 /// \param Parser The target independent parser implementation to use for
388 /// parsing and lexing.
389 MCTargetAsmParser *createMCAsmParser(
390 MCSubtargetInfo &STI,
392 const MCInstrInfo &MII,
393 const MCTargetOptions &Options) const {
394 if (!MCAsmParserCtorFn)
396 return MCAsmParserCtorFn(STI, Parser, MII, Options);
399 /// createAsmPrinter - Create a target specific assembly printer pass. This
400 /// takes ownership of the MCStreamer object.
401 AsmPrinter *createAsmPrinter(TargetMachine &TM,
402 std::unique_ptr<MCStreamer> &&Streamer) const {
403 if (!AsmPrinterCtorFn)
405 return AsmPrinterCtorFn(TM, std::move(Streamer));
408 MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI,
409 MCContext &Ctx) const {
410 if (!MCDisassemblerCtorFn)
412 return MCDisassemblerCtorFn(*this, STI, Ctx);
415 MCInstPrinter *createMCInstPrinter(const Triple &T, unsigned SyntaxVariant,
416 const MCAsmInfo &MAI,
417 const MCInstrInfo &MII,
418 const MCRegisterInfo &MRI) const {
419 if (!MCInstPrinterCtorFn)
421 return MCInstPrinterCtorFn(T, SyntaxVariant, MAI, MII, MRI);
425 /// createMCCodeEmitter - Create a target specific code emitter.
426 MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
427 const MCRegisterInfo &MRI,
428 MCContext &Ctx) const {
429 if (!MCCodeEmitterCtorFn)
431 return MCCodeEmitterCtorFn(II, MRI, Ctx);
434 /// Create a target specific MCStreamer.
436 /// \param T The target triple.
437 /// \param Ctx The target context.
438 /// \param TAB The target assembler backend object. Takes ownership.
439 /// \param OS The stream object.
440 /// \param Emitter The target independent assembler object.Takes ownership.
441 /// \param RelaxAll Relax all fixups?
442 MCStreamer *createMCObjectStreamer(const Triple &T, MCContext &Ctx,
443 MCAsmBackend &TAB, raw_pwrite_stream &OS,
444 MCCodeEmitter *Emitter,
445 const MCSubtargetInfo &STI,
447 bool DWARFMustBeAtTheEnd) const {
449 switch (T.getObjectFormat()) {
451 llvm_unreachable("Unknown object format");
453 assert(T.isOSWindows() && "only Windows COFF is supported");
454 S = COFFStreamerCtorFn(Ctx, TAB, OS, Emitter, RelaxAll);
457 if (MachOStreamerCtorFn)
458 S = MachOStreamerCtorFn(Ctx, TAB, OS, Emitter, RelaxAll,
459 DWARFMustBeAtTheEnd);
461 S = createMachOStreamer(Ctx, TAB, OS, Emitter, RelaxAll,
462 DWARFMustBeAtTheEnd);
465 if (ELFStreamerCtorFn)
466 S = ELFStreamerCtorFn(T, Ctx, TAB, OS, Emitter, RelaxAll);
468 S = createELFStreamer(Ctx, TAB, OS, Emitter, RelaxAll);
471 if (ObjectTargetStreamerCtorFn)
472 ObjectTargetStreamerCtorFn(*S, STI);
476 MCStreamer *createAsmStreamer(MCContext &Ctx,
477 std::unique_ptr<formatted_raw_ostream> OS,
478 bool IsVerboseAsm, bool UseDwarfDirectory,
479 MCInstPrinter *InstPrint, MCCodeEmitter *CE,
480 MCAsmBackend *TAB, bool ShowInst) const {
481 formatted_raw_ostream &OSRef = *OS;
482 MCStreamer *S = llvm::createAsmStreamer(Ctx, std::move(OS), IsVerboseAsm,
483 UseDwarfDirectory, InstPrint, CE,
485 createAsmTargetStreamer(*S, OSRef, InstPrint, IsVerboseAsm);
489 MCTargetStreamer *createAsmTargetStreamer(MCStreamer &S,
490 formatted_raw_ostream &OS,
491 MCInstPrinter *InstPrint,
492 bool IsVerboseAsm) const {
493 if (AsmTargetStreamerCtorFn)
494 return AsmTargetStreamerCtorFn(S, OS, InstPrint, IsVerboseAsm);
498 MCStreamer *createNullStreamer(MCContext &Ctx) const {
499 MCStreamer *S = llvm::createNullStreamer(Ctx);
500 createNullTargetStreamer(*S);
504 MCTargetStreamer *createNullTargetStreamer(MCStreamer &S) const {
505 if (NullTargetStreamerCtorFn)
506 return NullTargetStreamerCtorFn(S);
510 /// createMCRelocationInfo - Create a target specific MCRelocationInfo.
512 /// \param TT The target triple.
513 /// \param Ctx The target context.
515 createMCRelocationInfo(StringRef TT, MCContext &Ctx) const {
516 MCRelocationInfoCtorTy Fn = MCRelocationInfoCtorFn
517 ? MCRelocationInfoCtorFn
518 : llvm::createMCRelocationInfo;
522 /// createMCSymbolizer - Create a target specific MCSymbolizer.
524 /// \param TT The target triple.
525 /// \param GetOpInfo The function to get the symbolic information for operands.
526 /// \param SymbolLookUp The function to lookup a symbol name.
527 /// \param DisInfo The pointer to the block of symbolic information for above call
529 /// \param Ctx The target context.
530 /// \param RelInfo The relocation information for this target. Takes ownership.
532 createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
533 LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo,
535 std::unique_ptr<MCRelocationInfo> &&RelInfo) const {
536 MCSymbolizerCtorTy Fn =
537 MCSymbolizerCtorFn ? MCSymbolizerCtorFn : llvm::createMCSymbolizer;
538 return Fn(TT, GetOpInfo, SymbolLookUp, DisInfo, Ctx, std::move(RelInfo));
544 /// TargetRegistry - Generic interface to target specific features.
545 struct TargetRegistry {
546 // FIXME: Make this a namespace, probably just move all the Register*
547 // functions into Target (currently they all just set members on the Target
548 // anyway, and Target friends this class so those functions can...
550 TargetRegistry() = delete;
553 : public std::iterator<std::forward_iterator_tag, Target, ptrdiff_t> {
554 const Target *Current;
555 explicit iterator(Target *T) : Current(T) {}
556 friend struct TargetRegistry;
558 iterator() : Current(nullptr) {}
560 bool operator==(const iterator &x) const {
561 return Current == x.Current;
563 bool operator!=(const iterator &x) const {
564 return !operator==(x);
567 // Iterator traversal: forward iteration only
568 iterator &operator++() { // Preincrement
569 assert(Current && "Cannot increment end iterator!");
570 Current = Current->getNext();
573 iterator operator++(int) { // Postincrement
574 iterator tmp = *this;
579 const Target &operator*() const {
580 assert(Current && "Cannot dereference end iterator!");
584 const Target *operator->() const {
589 /// printRegisteredTargetsForVersion - Print the registered targets
590 /// appropriately for inclusion in a tool's version output.
591 static void printRegisteredTargetsForVersion();
593 /// @name Registry Access
596 static iterator_range<iterator> targets();
598 /// lookupTarget - Lookup a target based on a target triple.
600 /// \param Triple - The triple to use for finding a target.
601 /// \param Error - On failure, an error string describing why no target was
603 static const Target *lookupTarget(const std::string &Triple,
606 /// lookupTarget - Lookup a target based on an architecture name
607 /// and a target triple. If the architecture name is non-empty,
608 /// then the lookup is done by architecture. Otherwise, the target
611 /// \param ArchName - The architecture to use for finding a target.
612 /// \param TheTriple - The triple to use for finding a target. The
613 /// triple is updated with canonical architecture name if a lookup
614 /// by architecture is done.
615 /// \param Error - On failure, an error string describing why no target was
617 static const Target *lookupTarget(const std::string &ArchName,
622 /// @name Target Registration
625 /// RegisterTarget - Register the given target. Attempts to register a
626 /// target which has already been registered will be ignored.
628 /// Clients are responsible for ensuring that registration doesn't occur
629 /// while another thread is attempting to access the registry. Typically
630 /// this is done by initializing all targets at program startup.
632 /// @param T - The target being registered.
633 /// @param Name - The target name. This should be a static string.
634 /// @param ShortDesc - A short target description. This should be a static
636 /// @param ArchMatchFn - The arch match checking function for this target.
637 /// @param HasJIT - Whether the target supports JIT code
639 static void RegisterTarget(Target &T,
641 const char *ShortDesc,
642 Target::ArchMatchFnTy ArchMatchFn,
643 bool HasJIT = false);
645 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
648 /// Clients are responsible for ensuring that registration doesn't occur
649 /// while another thread is attempting to access the registry. Typically
650 /// this is done by initializing all targets at program startup.
652 /// @param T - The target being registered.
653 /// @param Fn - A function to construct a MCAsmInfo for the target.
654 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
655 T.MCAsmInfoCtorFn = Fn;
658 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
661 /// Clients are responsible for ensuring that registration doesn't occur
662 /// while another thread is attempting to access the registry. Typically
663 /// this is done by initializing all targets at program startup.
665 /// @param T - The target being registered.
666 /// @param Fn - A function to construct a MCCodeGenInfo for the target.
667 static void RegisterMCCodeGenInfo(Target &T,
668 Target::MCCodeGenInfoCtorFnTy Fn) {
669 T.MCCodeGenInfoCtorFn = Fn;
672 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
675 /// Clients are responsible for ensuring that registration doesn't occur
676 /// while another thread is attempting to access the registry. Typically
677 /// this is done by initializing all targets at program startup.
679 /// @param T - The target being registered.
680 /// @param Fn - A function to construct a MCInstrInfo for the target.
681 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
682 T.MCInstrInfoCtorFn = Fn;
685 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
686 /// the given target.
687 static void RegisterMCInstrAnalysis(Target &T,
688 Target::MCInstrAnalysisCtorFnTy Fn) {
689 T.MCInstrAnalysisCtorFn = Fn;
692 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
695 /// Clients are responsible for ensuring that registration doesn't occur
696 /// while another thread is attempting to access the registry. Typically
697 /// this is done by initializing all targets at program startup.
699 /// @param T - The target being registered.
700 /// @param Fn - A function to construct a MCRegisterInfo for the target.
701 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
702 T.MCRegInfoCtorFn = Fn;
705 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
706 /// the given target.
708 /// Clients are responsible for ensuring that registration doesn't occur
709 /// while another thread is attempting to access the registry. Typically
710 /// this is done by initializing all targets at program startup.
712 /// @param T - The target being registered.
713 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
714 static void RegisterMCSubtargetInfo(Target &T,
715 Target::MCSubtargetInfoCtorFnTy Fn) {
716 T.MCSubtargetInfoCtorFn = Fn;
719 /// RegisterTargetMachine - Register a TargetMachine implementation for the
722 /// Clients are responsible for ensuring that registration doesn't occur
723 /// while another thread is attempting to access the registry. Typically
724 /// this is done by initializing all targets at program startup.
726 /// @param T - The target being registered.
727 /// @param Fn - A function to construct a TargetMachine for the target.
728 static void RegisterTargetMachine(Target &T,
729 Target::TargetMachineCtorTy Fn) {
730 T.TargetMachineCtorFn = Fn;
733 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
736 /// Clients are responsible for ensuring that registration doesn't occur
737 /// while another thread is attempting to access the registry. Typically
738 /// this is done by initializing all targets at program startup.
740 /// @param T - The target being registered.
741 /// @param Fn - A function to construct an AsmBackend for the target.
742 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
743 T.MCAsmBackendCtorFn = Fn;
746 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
747 /// the given target.
749 /// Clients are responsible for ensuring that registration doesn't occur
750 /// while another thread is attempting to access the registry. Typically
751 /// this is done by initializing all targets at program startup.
753 /// @param T - The target being registered.
754 /// @param Fn - A function to construct an MCTargetAsmParser for the target.
755 static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
756 T.MCAsmParserCtorFn = Fn;
759 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
762 /// Clients are responsible for ensuring that registration doesn't occur
763 /// while another thread is attempting to access the registry. Typically
764 /// this is done by initializing all targets at program startup.
766 /// @param T - The target being registered.
767 /// @param Fn - A function to construct an AsmPrinter for the target.
768 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
769 T.AsmPrinterCtorFn = Fn;
772 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
773 /// the given target.
775 /// Clients are responsible for ensuring that registration doesn't occur
776 /// while another thread is attempting to access the registry. Typically
777 /// this is done by initializing all targets at program startup.
779 /// @param T - The target being registered.
780 /// @param Fn - A function to construct an MCDisassembler for the target.
781 static void RegisterMCDisassembler(Target &T,
782 Target::MCDisassemblerCtorTy Fn) {
783 T.MCDisassemblerCtorFn = Fn;
786 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
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 MCInstPrinter for the target.
795 static void RegisterMCInstPrinter(Target &T,
796 Target::MCInstPrinterCtorTy Fn) {
797 T.MCInstPrinterCtorFn = Fn;
800 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
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 MCCodeEmitter for the target.
809 static void RegisterMCCodeEmitter(Target &T,
810 Target::MCCodeEmitterCtorTy Fn) {
811 T.MCCodeEmitterCtorFn = Fn;
814 static void RegisterCOFFStreamer(Target &T, Target::COFFStreamerCtorTy Fn) {
815 T.COFFStreamerCtorFn = Fn;
818 static void RegisterMachOStreamer(Target &T,
819 Target::MachOStreamerCtorTy Fn) {
820 T.MachOStreamerCtorFn = Fn;
823 static void RegisterELFStreamer(Target &T, Target::ELFStreamerCtorTy Fn) {
824 T.ELFStreamerCtorFn = Fn;
828 RegisterNullTargetStreamer(Target &T, Target::NullTargetStreamerCtorTy Fn) {
829 T.NullTargetStreamerCtorFn = Fn;
832 static void RegisterAsmTargetStreamer(Target &T,
833 Target::AsmTargetStreamerCtorTy Fn) {
834 T.AsmTargetStreamerCtorFn = Fn;
838 RegisterObjectTargetStreamer(Target &T,
839 Target::ObjectTargetStreamerCtorTy Fn) {
840 T.ObjectTargetStreamerCtorFn = Fn;
843 /// RegisterMCRelocationInfo - Register an MCRelocationInfo
844 /// implementation for the given target.
846 /// Clients are responsible for ensuring that registration doesn't occur
847 /// while another thread is attempting to access the registry. Typically
848 /// this is done by initializing all targets at program startup.
850 /// @param T - The target being registered.
851 /// @param Fn - A function to construct an MCRelocationInfo for the target.
852 static void RegisterMCRelocationInfo(Target &T,
853 Target::MCRelocationInfoCtorTy Fn) {
854 T.MCRelocationInfoCtorFn = Fn;
857 /// RegisterMCSymbolizer - Register an MCSymbolizer
858 /// implementation for the given target.
860 /// Clients are responsible for ensuring that registration doesn't occur
861 /// while another thread is attempting to access the registry. Typically
862 /// this is done by initializing all targets at program startup.
864 /// @param T - The target being registered.
865 /// @param Fn - A function to construct an MCSymbolizer for the target.
866 static void RegisterMCSymbolizer(Target &T,
867 Target::MCSymbolizerCtorTy Fn) {
868 T.MCSymbolizerCtorFn = Fn;
875 //===--------------------------------------------------------------------===//
877 /// RegisterTarget - Helper template for registering a target, for use in the
878 /// target's initialization function. Usage:
881 /// Target TheFooTarget; // The global target instance.
883 /// extern "C" void LLVMInitializeFooTargetInfo() {
884 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
886 template<Triple::ArchType TargetArchType = Triple::UnknownArch,
888 struct RegisterTarget {
889 RegisterTarget(Target &T, const char *Name, const char *Desc) {
890 TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch, HasJIT);
893 static bool getArchMatch(Triple::ArchType Arch) {
894 return Arch == TargetArchType;
898 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
899 /// implementation. This invokes the static "Create" method on the class to
900 /// actually do the construction. Usage:
902 /// extern "C" void LLVMInitializeFooTarget() {
903 /// extern Target TheFooTarget;
904 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
906 template<class MCAsmInfoImpl>
907 struct RegisterMCAsmInfo {
908 RegisterMCAsmInfo(Target &T) {
909 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
912 static MCAsmInfo *Allocator(const MCRegisterInfo &/*MRI*/, StringRef TT) {
913 return new MCAsmInfoImpl(TT);
918 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
919 /// implementation. This invokes the specified function to do the
920 /// construction. Usage:
922 /// extern "C" void LLVMInitializeFooTarget() {
923 /// extern Target TheFooTarget;
924 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
926 struct RegisterMCAsmInfoFn {
927 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
928 TargetRegistry::RegisterMCAsmInfo(T, Fn);
932 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
933 /// implementation. This invokes the static "Create" method on the class
934 /// to actually do the construction. Usage:
936 /// extern "C" void LLVMInitializeFooTarget() {
937 /// extern Target TheFooTarget;
938 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
940 template<class MCCodeGenInfoImpl>
941 struct RegisterMCCodeGenInfo {
942 RegisterMCCodeGenInfo(Target &T) {
943 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
946 static MCCodeGenInfo *Allocator(StringRef /*TT*/, Reloc::Model /*RM*/,
947 CodeModel::Model /*CM*/,
948 CodeGenOpt::Level /*OL*/) {
949 return new MCCodeGenInfoImpl();
953 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
954 /// info implementation. This invokes the specified function to do the
955 /// construction. Usage:
957 /// extern "C" void LLVMInitializeFooTarget() {
958 /// extern Target TheFooTarget;
959 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
961 struct RegisterMCCodeGenInfoFn {
962 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
963 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
967 /// RegisterMCInstrInfo - Helper template for registering a target instruction
968 /// info implementation. This invokes the static "Create" method on the class
969 /// to actually do the construction. Usage:
971 /// extern "C" void LLVMInitializeFooTarget() {
972 /// extern Target TheFooTarget;
973 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
975 template<class MCInstrInfoImpl>
976 struct RegisterMCInstrInfo {
977 RegisterMCInstrInfo(Target &T) {
978 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
981 static MCInstrInfo *Allocator() {
982 return new MCInstrInfoImpl();
986 /// RegisterMCInstrInfoFn - Helper template for registering a target
987 /// instruction info implementation. This invokes the specified function to
988 /// do the construction. Usage:
990 /// extern "C" void LLVMInitializeFooTarget() {
991 /// extern Target TheFooTarget;
992 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
994 struct RegisterMCInstrInfoFn {
995 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
996 TargetRegistry::RegisterMCInstrInfo(T, Fn);
1000 /// RegisterMCInstrAnalysis - Helper template for registering a target
1001 /// instruction analyzer implementation. This invokes the static "Create"
1002 /// method on the class to actually do the construction. Usage:
1004 /// extern "C" void LLVMInitializeFooTarget() {
1005 /// extern Target TheFooTarget;
1006 /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
1008 template<class MCInstrAnalysisImpl>
1009 struct RegisterMCInstrAnalysis {
1010 RegisterMCInstrAnalysis(Target &T) {
1011 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
1014 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
1015 return new MCInstrAnalysisImpl(Info);
1019 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
1020 /// instruction analyzer implementation. This invokes the specified function
1021 /// to do the construction. Usage:
1023 /// extern "C" void LLVMInitializeFooTarget() {
1024 /// extern Target TheFooTarget;
1025 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
1027 struct RegisterMCInstrAnalysisFn {
1028 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
1029 TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
1033 /// RegisterMCRegInfo - Helper template for registering a target register info
1034 /// implementation. This invokes the static "Create" method on the class to
1035 /// actually do the construction. Usage:
1037 /// extern "C" void LLVMInitializeFooTarget() {
1038 /// extern Target TheFooTarget;
1039 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
1041 template<class MCRegisterInfoImpl>
1042 struct RegisterMCRegInfo {
1043 RegisterMCRegInfo(Target &T) {
1044 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
1047 static MCRegisterInfo *Allocator(StringRef /*TT*/) {
1048 return new MCRegisterInfoImpl();
1052 /// RegisterMCRegInfoFn - Helper template for registering a target register
1053 /// info implementation. This invokes the specified function to do the
1054 /// construction. Usage:
1056 /// extern "C" void LLVMInitializeFooTarget() {
1057 /// extern Target TheFooTarget;
1058 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
1060 struct RegisterMCRegInfoFn {
1061 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
1062 TargetRegistry::RegisterMCRegInfo(T, Fn);
1066 /// RegisterMCSubtargetInfo - Helper template for registering a target
1067 /// subtarget info implementation. This invokes the static "Create" method
1068 /// on the class to actually do the construction. Usage:
1070 /// extern "C" void LLVMInitializeFooTarget() {
1071 /// extern Target TheFooTarget;
1072 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
1074 template<class MCSubtargetInfoImpl>
1075 struct RegisterMCSubtargetInfo {
1076 RegisterMCSubtargetInfo(Target &T) {
1077 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
1080 static MCSubtargetInfo *Allocator(StringRef /*TT*/, StringRef /*CPU*/,
1082 return new MCSubtargetInfoImpl();
1086 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
1087 /// subtarget info implementation. This invokes the specified function to
1088 /// do the construction. Usage:
1090 /// extern "C" void LLVMInitializeFooTarget() {
1091 /// extern Target TheFooTarget;
1092 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1094 struct RegisterMCSubtargetInfoFn {
1095 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
1096 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
1100 /// RegisterTargetMachine - Helper template for registering a target machine
1101 /// implementation, for use in the target machine initialization
1102 /// function. Usage:
1104 /// extern "C" void LLVMInitializeFooTarget() {
1105 /// extern Target TheFooTarget;
1106 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1108 template<class TargetMachineImpl>
1109 struct RegisterTargetMachine {
1110 RegisterTargetMachine(Target &T) {
1111 TargetRegistry::RegisterTargetMachine(T, &Allocator);
1115 static TargetMachine *Allocator(const Target &T, StringRef TT,
1116 StringRef CPU, StringRef FS,
1117 const TargetOptions &Options,
1119 CodeModel::Model CM,
1120 CodeGenOpt::Level OL) {
1121 return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
1125 /// RegisterMCAsmBackend - Helper template for registering a target specific
1126 /// assembler backend. Usage:
1128 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1129 /// extern Target TheFooTarget;
1130 /// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1132 template<class MCAsmBackendImpl>
1133 struct RegisterMCAsmBackend {
1134 RegisterMCAsmBackend(Target &T) {
1135 TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1139 static MCAsmBackend *Allocator(const Target &T,
1140 const MCRegisterInfo &MRI,
1141 StringRef Triple, StringRef CPU) {
1142 return new MCAsmBackendImpl(T, MRI, Triple, CPU);
1146 /// RegisterMCAsmParser - Helper template for registering a target specific
1147 /// assembly parser, for use in the target machine initialization
1148 /// function. Usage:
1150 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1151 /// extern Target TheFooTarget;
1152 /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1154 template<class MCAsmParserImpl>
1155 struct RegisterMCAsmParser {
1156 RegisterMCAsmParser(Target &T) {
1157 TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1161 static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P,
1162 const MCInstrInfo &MII,
1163 const MCTargetOptions &Options) {
1164 return new MCAsmParserImpl(STI, P, MII, Options);
1168 /// RegisterAsmPrinter - Helper template for registering a target specific
1169 /// assembly printer, for use in the target machine initialization
1170 /// function. Usage:
1172 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1173 /// extern Target TheFooTarget;
1174 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1176 template<class AsmPrinterImpl>
1177 struct RegisterAsmPrinter {
1178 RegisterAsmPrinter(Target &T) {
1179 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1183 static AsmPrinter *Allocator(TargetMachine &TM,
1184 std::unique_ptr<MCStreamer> &&Streamer) {
1185 return new AsmPrinterImpl(TM, std::move(Streamer));
1189 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1190 /// machine code emitter, for use in the target initialization
1191 /// function. Usage:
1193 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1194 /// extern Target TheFooTarget;
1195 /// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1197 template<class MCCodeEmitterImpl>
1198 struct RegisterMCCodeEmitter {
1199 RegisterMCCodeEmitter(Target &T) {
1200 TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1204 static MCCodeEmitter *Allocator(const MCInstrInfo & /*II*/,
1205 const MCRegisterInfo & /*MRI*/,
1206 MCContext & /*Ctx*/) {
1207 return new MCCodeEmitterImpl();