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/ADT/TargetTuple.h"
25 #include "llvm/Support/CodeGen.h"
26 #include "llvm/Support/FormattedStream.h"
40 class MCInstrAnalysis;
45 class MCSubtargetInfo;
47 class MCRelocationInfo;
48 class MCTargetAsmParser;
49 class MCTargetOptions;
50 class MCTargetStreamer;
54 class raw_pwrite_stream;
55 class formatted_raw_ostream;
57 MCStreamer *createNullStreamer(MCContext &Ctx);
58 MCStreamer *createAsmStreamer(MCContext &Ctx,
59 std::unique_ptr<formatted_raw_ostream> OS,
60 bool isVerboseAsm, bool useDwarfDirectory,
61 MCInstPrinter *InstPrint, MCCodeEmitter *CE,
62 MCAsmBackend *TAB, bool ShowInst);
64 /// Takes ownership of \p TAB and \p CE.
65 MCStreamer *createELFStreamer(MCContext &Ctx, MCAsmBackend &TAB,
66 raw_pwrite_stream &OS, MCCodeEmitter *CE,
68 MCStreamer *createMachOStreamer(MCContext &Ctx, MCAsmBackend &TAB,
69 raw_pwrite_stream &OS, MCCodeEmitter *CE,
70 bool RelaxAll, bool DWARFMustBeAtTheEnd,
71 bool LabelSections = false);
73 MCRelocationInfo *createMCRelocationInfo(const TargetTuple &TT, MCContext &Ctx);
75 MCSymbolizer *createMCSymbolizer(const TargetTuple &TT,
76 LLVMOpInfoCallback GetOpInfo,
77 LLVMSymbolLookupCallback SymbolLookUp,
78 void *DisInfo, MCContext *Ctx,
79 std::unique_ptr<MCRelocationInfo> &&RelInfo);
81 /// Target - Wrapper for Target specific information.
83 /// For registration purposes, this is a POD type so that targets can be
84 /// registered without the use of static constructors.
86 /// Targets should implement a single global instance of this class (which
87 /// will be zero initialized), and pass that instance to the TargetRegistry as
88 /// part of their initialization.
91 friend struct TargetRegistry;
93 typedef bool (*ArchMatchFnTy)(Triple::ArchType Arch);
95 typedef MCAsmInfo *(*MCAsmInfoCtorFnTy)(const MCRegisterInfo &MRI,
96 const TargetTuple &TT);
97 typedef MCCodeGenInfo *(*MCCodeGenInfoCtorFnTy)(const TargetTuple &TT,
100 CodeGenOpt::Level OL);
101 typedef MCInstrInfo *(*MCInstrInfoCtorFnTy)(void);
102 typedef MCInstrAnalysis *(*MCInstrAnalysisCtorFnTy)(const MCInstrInfo *Info);
103 typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(const TargetTuple &TT);
104 // FIXME: CPU and Features should be merged into TargetTuple when possible.
105 typedef MCSubtargetInfo *(*MCSubtargetInfoCtorFnTy)(const TargetTuple &TT,
108 // FIXME: CPU and Features should be merged into TargetTuple when possible.
109 typedef TargetMachine *(*TargetMachineCtorTy)(
110 const Target &T, const TargetTuple &TT, StringRef CPU, StringRef Features,
111 const TargetOptions &Options, Reloc::Model RM, CodeModel::Model CM,
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 // FIXME: CPU and Features should be merged into TargetTuple when possible.
119 typedef MCAsmBackend *(*MCAsmBackendCtorTy)(const Target &T,
120 const MCRegisterInfo &MRI,
121 const TargetTuple &TT,
123 typedef MCTargetAsmParser *(*MCAsmParserCtorTy)(
124 MCSubtargetInfo &STI, MCAsmParser &P, const MCInstrInfo &MII,
125 const MCTargetOptions &Options);
126 typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T,
127 const MCSubtargetInfo &STI,
129 typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const TargetTuple &T,
130 unsigned SyntaxVariant,
131 const MCAsmInfo &MAI,
132 const MCInstrInfo &MII,
133 const MCRegisterInfo &MRI);
134 typedef MCCodeEmitter *(*MCCodeEmitterCtorTy)(const MCInstrInfo &II,
135 const MCRegisterInfo &MRI,
137 typedef MCStreamer *(*ELFStreamerCtorTy)(const TargetTuple &T, MCContext &Ctx,
139 raw_pwrite_stream &OS,
140 MCCodeEmitter *Emitter,
142 typedef MCStreamer *(*MachOStreamerCtorTy)(MCContext &Ctx, MCAsmBackend &TAB,
143 raw_pwrite_stream &OS,
144 MCCodeEmitter *Emitter,
146 bool DWARFMustBeAtTheEnd);
147 typedef MCStreamer *(*COFFStreamerCtorTy)(MCContext &Ctx, MCAsmBackend &TAB,
148 raw_pwrite_stream &OS,
149 MCCodeEmitter *Emitter,
151 typedef MCTargetStreamer *(*NullTargetStreamerCtorTy)(MCStreamer &S);
152 typedef MCTargetStreamer *(*AsmTargetStreamerCtorTy)(
153 MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *InstPrint,
155 typedef MCTargetStreamer *(*ObjectTargetStreamerCtorTy)(
156 MCStreamer &S, const MCSubtargetInfo &STI);
157 typedef MCRelocationInfo *(*MCRelocationInfoCtorTy)(const TargetTuple &TT,
159 typedef MCSymbolizer *(*MCSymbolizerCtorTy)(
160 const TargetTuple &TT, LLVMOpInfoCallback GetOpInfo,
161 LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo, MCContext *Ctx,
162 std::unique_ptr<MCRelocationInfo> &&RelInfo);
165 /// Next - The next registered target in the linked list, maintained by the
169 /// The target function for checking if an architecture is supported.
170 ArchMatchFnTy ArchMatchFn;
172 /// Name - The target name.
175 /// ShortDesc - A short description of the target.
176 const char *ShortDesc;
178 /// HasJIT - Whether this target supports the JIT.
181 /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
183 MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
185 /// MCCodeGenInfoCtorFn - Constructor function for this target's
186 /// MCCodeGenInfo, if registered.
187 MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn;
189 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
191 MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
193 /// MCInstrAnalysisCtorFn - Constructor function for this target's
194 /// MCInstrAnalysis, if registered.
195 MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
197 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
199 MCRegInfoCtorFnTy MCRegInfoCtorFn;
201 /// MCSubtargetInfoCtorFn - Constructor function for this target's
202 /// MCSubtargetInfo, if registered.
203 MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
205 /// TargetMachineCtorFn - Construction function for this target's
206 /// TargetMachine, if registered.
207 TargetMachineCtorTy TargetMachineCtorFn;
209 /// MCAsmBackendCtorFn - Construction function for this target's
210 /// MCAsmBackend, if registered.
211 MCAsmBackendCtorTy MCAsmBackendCtorFn;
213 /// MCAsmParserCtorFn - Construction function for this target's
214 /// MCTargetAsmParser, if registered.
215 MCAsmParserCtorTy MCAsmParserCtorFn;
217 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
219 AsmPrinterCtorTy AsmPrinterCtorFn;
221 /// MCDisassemblerCtorFn - Construction function for this target's
222 /// MCDisassembler, if registered.
223 MCDisassemblerCtorTy MCDisassemblerCtorFn;
225 /// MCInstPrinterCtorFn - Construction function for this target's
226 /// MCInstPrinter, if registered.
227 MCInstPrinterCtorTy MCInstPrinterCtorFn;
229 /// MCCodeEmitterCtorFn - Construction function for this target's
230 /// CodeEmitter, if registered.
231 MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
233 // Construction functions for the various object formats, if registered.
234 COFFStreamerCtorTy COFFStreamerCtorFn;
235 MachOStreamerCtorTy MachOStreamerCtorFn;
236 ELFStreamerCtorTy ELFStreamerCtorFn;
238 /// Construction function for this target's null TargetStreamer, if
239 /// registered (default = nullptr).
240 NullTargetStreamerCtorTy NullTargetStreamerCtorFn;
242 /// Construction function for this target's asm TargetStreamer, if
243 /// registered (default = nullptr).
244 AsmTargetStreamerCtorTy AsmTargetStreamerCtorFn;
246 /// Construction function for this target's obj TargetStreamer, if
247 /// registered (default = nullptr).
248 ObjectTargetStreamerCtorTy ObjectTargetStreamerCtorFn;
250 /// MCRelocationInfoCtorFn - Construction function for this target's
251 /// MCRelocationInfo, if registered (default = llvm::createMCRelocationInfo)
252 MCRelocationInfoCtorTy MCRelocationInfoCtorFn;
254 /// MCSymbolizerCtorFn - Construction function for this target's
255 /// MCSymbolizer, if registered (default = llvm::createMCSymbolizer)
256 MCSymbolizerCtorTy MCSymbolizerCtorFn;
260 : COFFStreamerCtorFn(nullptr), MachOStreamerCtorFn(nullptr),
261 ELFStreamerCtorFn(nullptr), NullTargetStreamerCtorFn(nullptr),
262 AsmTargetStreamerCtorFn(nullptr), ObjectTargetStreamerCtorFn(nullptr),
263 MCRelocationInfoCtorFn(nullptr), MCSymbolizerCtorFn(nullptr) {}
265 /// @name Target Information
268 // getNext - Return the next registered target.
269 const Target *getNext() const { return Next; }
271 /// getName - Get the target name.
272 const char *getName() const { return Name; }
274 /// getShortDescription - Get a short description of the target.
275 const char *getShortDescription() const { return ShortDesc; }
278 /// @name Feature Predicates
281 /// hasJIT - Check if this targets supports the just-in-time compilation.
282 bool hasJIT() const { return HasJIT; }
284 /// hasTargetMachine - Check if this target supports code generation.
285 bool hasTargetMachine() const { return TargetMachineCtorFn != nullptr; }
287 /// hasMCAsmBackend - Check if this target supports .o generation.
288 bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != nullptr; }
291 /// @name Feature Constructors
294 /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
297 /// \param TT This argument is used to determine the target machine
298 /// feature set; it should always be provided. Generally this should be
299 /// either the target triple from the module, or the target triple of the
300 /// host if that does not exist.
301 MCAsmInfo *createMCAsmInfo(const MCRegisterInfo &MRI, StringRef TT) const {
302 if (!MCAsmInfoCtorFn)
304 return MCAsmInfoCtorFn(MRI, TargetTuple(Triple(TT)));
307 /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
309 MCCodeGenInfo *createMCCodeGenInfo(StringRef TT, Reloc::Model RM,
311 CodeGenOpt::Level OL) const {
312 if (!MCCodeGenInfoCtorFn)
314 return MCCodeGenInfoCtorFn(TargetTuple(Triple(TT)), 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 TT) const {
336 if (!MCRegInfoCtorFn)
338 return MCRegInfoCtorFn(TargetTuple(Triple(TT)));
341 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
343 /// \param TT 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 TT, StringRef CPU,
351 StringRef Features) const {
352 if (!MCSubtargetInfoCtorFn)
354 return MCSubtargetInfoCtorFn(TargetTuple(Triple(TT)), CPU, Features);
357 /// createTargetMachine - Create a target specific machine implementation
358 /// for the specified \p TT.
360 /// \param TT 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.
365 createTargetMachine(StringRef TT, StringRef CPU, StringRef Features,
366 const TargetOptions &Options,
367 Reloc::Model RM = Reloc::Default,
368 CodeModel::Model CM = CodeModel::Default,
369 CodeGenOpt::Level OL = CodeGenOpt::Default) const {
370 if (!TargetMachineCtorFn)
372 return TargetMachineCtorFn(*this, TargetTuple(Triple(TT)), CPU, Features,
373 Options, RM, CM, OL);
376 /// createMCAsmBackend - Create a target specific assembly parser.
378 /// \param TT The target triple string.
379 MCAsmBackend *createMCAsmBackend(const MCRegisterInfo &MRI, StringRef TT,
380 StringRef CPU) const {
381 if (!MCAsmBackendCtorFn)
383 return MCAsmBackendCtorFn(*this, MRI, TargetTuple(Triple(TT)), CPU);
386 /// createMCAsmParser - Create a target specific assembly parser.
388 /// \param Parser The target independent parser implementation to use for
389 /// parsing and lexing.
390 MCTargetAsmParser *createMCAsmParser(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 TargetTuple &TT,
416 unsigned SyntaxVariant,
417 const MCAsmInfo &MAI,
418 const MCInstrInfo &MII,
419 const MCRegisterInfo &MRI) const {
420 if (!MCInstPrinterCtorFn)
422 return MCInstPrinterCtorFn(TT, 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 TT 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 TargetTuple &TT, MCContext &Ctx,
443 MCAsmBackend &TAB, raw_pwrite_stream &OS,
444 MCCodeEmitter *Emitter,
445 const MCSubtargetInfo &STI, bool RelaxAll,
446 bool DWARFMustBeAtTheEnd) const {
448 switch (TT.getObjectFormat()) {
450 llvm_unreachable("Unknown object format");
451 case TargetTuple::COFF:
452 assert(TT.isOSWindows() && "only Windows COFF is supported");
453 S = COFFStreamerCtorFn(Ctx, TAB, OS, Emitter, RelaxAll);
455 case TargetTuple::MachO:
456 if (MachOStreamerCtorFn)
457 S = MachOStreamerCtorFn(Ctx, TAB, OS, Emitter, RelaxAll,
458 DWARFMustBeAtTheEnd);
460 S = createMachOStreamer(Ctx, TAB, OS, Emitter, RelaxAll,
461 DWARFMustBeAtTheEnd);
463 case TargetTuple::ELF:
464 if (ELFStreamerCtorFn)
465 S = ELFStreamerCtorFn(TT, Ctx, TAB, OS, Emitter, RelaxAll);
467 S = createELFStreamer(Ctx, TAB, OS, Emitter, RelaxAll);
470 if (ObjectTargetStreamerCtorFn)
471 ObjectTargetStreamerCtorFn(*S, STI);
475 MCStreamer *createAsmStreamer(MCContext &Ctx,
476 std::unique_ptr<formatted_raw_ostream> OS,
477 bool IsVerboseAsm, bool UseDwarfDirectory,
478 MCInstPrinter *InstPrint, MCCodeEmitter *CE,
479 MCAsmBackend *TAB, bool ShowInst) const {
480 formatted_raw_ostream &OSRef = *OS;
481 MCStreamer *S = llvm::createAsmStreamer(Ctx, std::move(OS), IsVerboseAsm,
482 UseDwarfDirectory, InstPrint, CE,
484 createAsmTargetStreamer(*S, OSRef, InstPrint, IsVerboseAsm);
488 MCTargetStreamer *createAsmTargetStreamer(MCStreamer &S,
489 formatted_raw_ostream &OS,
490 MCInstPrinter *InstPrint,
491 bool IsVerboseAsm) const {
492 if (AsmTargetStreamerCtorFn)
493 return AsmTargetStreamerCtorFn(S, OS, InstPrint, IsVerboseAsm);
497 MCStreamer *createNullStreamer(MCContext &Ctx) const {
498 MCStreamer *S = llvm::createNullStreamer(Ctx);
499 createNullTargetStreamer(*S);
503 MCTargetStreamer *createNullTargetStreamer(MCStreamer &S) const {
504 if (NullTargetStreamerCtorFn)
505 return NullTargetStreamerCtorFn(S);
509 /// createMCRelocationInfo - Create a target specific MCRelocationInfo.
511 /// \param TT The target triple.
512 /// \param Ctx The target context.
513 MCRelocationInfo *createMCRelocationInfo(StringRef TT, MCContext &Ctx) const {
514 MCRelocationInfoCtorTy Fn = MCRelocationInfoCtorFn
515 ? MCRelocationInfoCtorFn
516 : llvm::createMCRelocationInfo;
517 return Fn(TargetTuple(Triple(TT)), Ctx);
520 /// createMCSymbolizer - Create a target specific MCSymbolizer.
522 /// \param TT The target triple.
523 /// \param GetOpInfo The function to get the symbolic information for
525 /// \param SymbolLookUp The function to lookup a symbol name.
526 /// \param DisInfo The pointer to the block of symbolic information for above
529 /// \param Ctx The target context.
530 /// \param RelInfo The relocation information for this target. Takes
533 createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
534 LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo,
536 std::unique_ptr<MCRelocationInfo> &&RelInfo) const {
537 MCSymbolizerCtorTy Fn =
538 MCSymbolizerCtorFn ? MCSymbolizerCtorFn : llvm::createMCSymbolizer;
539 return Fn(TargetTuple(Triple(TT)), GetOpInfo, SymbolLookUp, DisInfo, Ctx,
546 /// TargetRegistry - Generic interface to target specific features.
547 struct TargetRegistry {
548 // FIXME: Make this a namespace, probably just move all the Register*
549 // functions into Target (currently they all just set members on the Target
550 // anyway, and Target friends this class so those functions can...
552 TargetRegistry() = delete;
555 : public std::iterator<std::forward_iterator_tag, Target, ptrdiff_t> {
556 const Target *Current;
557 explicit iterator(Target *T) : Current(T) {}
558 friend struct TargetRegistry;
561 iterator() : Current(nullptr) {}
563 bool operator==(const iterator &x) const { return Current == x.Current; }
564 bool operator!=(const iterator &x) const { return !operator==(x); }
566 // Iterator traversal: forward iteration only
567 iterator &operator++() { // Preincrement
568 assert(Current && "Cannot increment end iterator!");
569 Current = Current->getNext();
572 iterator operator++(int) { // Postincrement
573 iterator tmp = *this;
578 const Target &operator*() const {
579 assert(Current && "Cannot dereference end iterator!");
583 const Target *operator->() const { return &operator*(); }
586 /// printRegisteredTargetsForVersion - Print the registered targets
587 /// appropriately for inclusion in a tool's version output.
588 static void printRegisteredTargetsForVersion();
590 /// @name Registry Access
593 static iterator_range<iterator> targets();
595 /// lookupTarget - Lookup a target based on a target triple.
597 /// \param TT - The triple to use for finding a target.
598 /// \param Error - On failure, an error string describing why no target was
600 static const Target *lookupTarget(const std::string &TT, std::string &Error);
602 /// lookupTarget - Lookup a target based on an architecture name
603 /// and a target triple. If the architecture name is non-empty,
604 /// then the lookup is done by architecture. Otherwise, the target
607 /// \param ArchName - The architecture to use for finding a target.
608 /// \param TT - The triple to use for finding a target. The
609 /// triple is updated with canonical architecture name if a lookup
610 /// by architecture is done.
611 /// \param Error - On failure, an error string describing why no target was
613 static const Target *lookupTarget(const std::string &ArchName, Triple &TT,
617 /// @name Target Registration
620 /// RegisterTarget - Register the given target. Attempts to register a
621 /// target which has already been registered will be ignored.
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 Name - The target name. This should be a static string.
629 /// @param ShortDesc - A short target description. This should be a static
631 /// @param ArchMatchFn - The arch match checking function for this target.
632 /// @param HasJIT - Whether the target supports JIT code
634 static void RegisterTarget(Target &T, const char *Name, const char *ShortDesc,
635 Target::ArchMatchFnTy ArchMatchFn,
636 bool HasJIT = false);
638 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
641 /// Clients are responsible for ensuring that registration doesn't occur
642 /// while another thread is attempting to access the registry. Typically
643 /// this is done by initializing all targets at program startup.
645 /// @param T - The target being registered.
646 /// @param Fn - A function to construct a MCAsmInfo for the target.
647 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
648 T.MCAsmInfoCtorFn = Fn;
651 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
654 /// Clients are responsible for ensuring that registration doesn't occur
655 /// while another thread is attempting to access the registry. Typically
656 /// this is done by initializing all targets at program startup.
658 /// @param T - The target being registered.
659 /// @param Fn - A function to construct a MCCodeGenInfo for the target.
660 static void RegisterMCCodeGenInfo(Target &T,
661 Target::MCCodeGenInfoCtorFnTy Fn) {
662 T.MCCodeGenInfoCtorFn = Fn;
665 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
668 /// Clients are responsible for ensuring that registration doesn't occur
669 /// while another thread is attempting to access the registry. Typically
670 /// this is done by initializing all targets at program startup.
672 /// @param T - The target being registered.
673 /// @param Fn - A function to construct a MCInstrInfo for the target.
674 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
675 T.MCInstrInfoCtorFn = Fn;
678 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
679 /// the given target.
680 static void RegisterMCInstrAnalysis(Target &T,
681 Target::MCInstrAnalysisCtorFnTy Fn) {
682 T.MCInstrAnalysisCtorFn = Fn;
685 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
688 /// Clients are responsible for ensuring that registration doesn't occur
689 /// while another thread is attempting to access the registry. Typically
690 /// this is done by initializing all targets at program startup.
692 /// @param T - The target being registered.
693 /// @param Fn - A function to construct a MCRegisterInfo for the target.
694 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
695 T.MCRegInfoCtorFn = Fn;
698 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
699 /// the given target.
701 /// Clients are responsible for ensuring that registration doesn't occur
702 /// while another thread is attempting to access the registry. Typically
703 /// this is done by initializing all targets at program startup.
705 /// @param T - The target being registered.
706 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
707 static void RegisterMCSubtargetInfo(Target &T,
708 Target::MCSubtargetInfoCtorFnTy Fn) {
709 T.MCSubtargetInfoCtorFn = Fn;
712 /// RegisterTargetMachine - Register a TargetMachine implementation for the
715 /// Clients are responsible for ensuring that registration doesn't occur
716 /// while another thread is attempting to access the registry. Typically
717 /// this is done by initializing all targets at program startup.
719 /// @param T - The target being registered.
720 /// @param Fn - A function to construct a TargetMachine for the target.
721 static void RegisterTargetMachine(Target &T, Target::TargetMachineCtorTy Fn) {
722 T.TargetMachineCtorFn = Fn;
725 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
728 /// Clients are responsible for ensuring that registration doesn't occur
729 /// while another thread is attempting to access the registry. Typically
730 /// this is done by initializing all targets at program startup.
732 /// @param T - The target being registered.
733 /// @param Fn - A function to construct an AsmBackend for the target.
734 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
735 T.MCAsmBackendCtorFn = Fn;
738 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
739 /// the given target.
741 /// Clients are responsible for ensuring that registration doesn't occur
742 /// while another thread is attempting to access the registry. Typically
743 /// this is done by initializing all targets at program startup.
745 /// @param T - The target being registered.
746 /// @param Fn - A function to construct an MCTargetAsmParser for the target.
747 static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
748 T.MCAsmParserCtorFn = Fn;
751 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
754 /// Clients are responsible for ensuring that registration doesn't occur
755 /// while another thread is attempting to access the registry. Typically
756 /// this is done by initializing all targets at program startup.
758 /// @param T - The target being registered.
759 /// @param Fn - A function to construct an AsmPrinter for the target.
760 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
761 T.AsmPrinterCtorFn = Fn;
764 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
765 /// the given target.
767 /// Clients are responsible for ensuring that registration doesn't occur
768 /// while another thread is attempting to access the registry. Typically
769 /// this is done by initializing all targets at program startup.
771 /// @param T - The target being registered.
772 /// @param Fn - A function to construct an MCDisassembler for the target.
773 static void RegisterMCDisassembler(Target &T,
774 Target::MCDisassemblerCtorTy Fn) {
775 T.MCDisassemblerCtorFn = Fn;
778 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
781 /// Clients are responsible for ensuring that registration doesn't occur
782 /// while another thread is attempting to access the registry. Typically
783 /// this is done by initializing all targets at program startup.
785 /// @param T - The target being registered.
786 /// @param Fn - A function to construct an MCInstPrinter for the target.
787 static void RegisterMCInstPrinter(Target &T, Target::MCInstPrinterCtorTy Fn) {
788 T.MCInstPrinterCtorFn = Fn;
791 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
794 /// Clients are responsible for ensuring that registration doesn't occur
795 /// while another thread is attempting to access the registry. Typically
796 /// this is done by initializing all targets at program startup.
798 /// @param T - The target being registered.
799 /// @param Fn - A function to construct an MCCodeEmitter for the target.
800 static void RegisterMCCodeEmitter(Target &T, Target::MCCodeEmitterCtorTy Fn) {
801 T.MCCodeEmitterCtorFn = Fn;
804 static void RegisterCOFFStreamer(Target &T, Target::COFFStreamerCtorTy Fn) {
805 T.COFFStreamerCtorFn = Fn;
808 static void RegisterMachOStreamer(Target &T, Target::MachOStreamerCtorTy Fn) {
809 T.MachOStreamerCtorFn = Fn;
812 static void RegisterELFStreamer(Target &T, Target::ELFStreamerCtorTy Fn) {
813 T.ELFStreamerCtorFn = Fn;
816 static void RegisterNullTargetStreamer(Target &T,
817 Target::NullTargetStreamerCtorTy Fn) {
818 T.NullTargetStreamerCtorFn = Fn;
821 static void RegisterAsmTargetStreamer(Target &T,
822 Target::AsmTargetStreamerCtorTy Fn) {
823 T.AsmTargetStreamerCtorFn = Fn;
827 RegisterObjectTargetStreamer(Target &T,
828 Target::ObjectTargetStreamerCtorTy Fn) {
829 T.ObjectTargetStreamerCtorFn = Fn;
832 /// RegisterMCRelocationInfo - Register an MCRelocationInfo
833 /// implementation for the given target.
835 /// Clients are responsible for ensuring that registration doesn't occur
836 /// while another thread is attempting to access the registry. Typically
837 /// this is done by initializing all targets at program startup.
839 /// @param T - The target being registered.
840 /// @param Fn - A function to construct an MCRelocationInfo for the target.
841 static void RegisterMCRelocationInfo(Target &T,
842 Target::MCRelocationInfoCtorTy Fn) {
843 T.MCRelocationInfoCtorFn = Fn;
846 /// RegisterMCSymbolizer - Register an MCSymbolizer
847 /// implementation for the given target.
849 /// Clients are responsible for ensuring that registration doesn't occur
850 /// while another thread is attempting to access the registry. Typically
851 /// this is done by initializing all targets at program startup.
853 /// @param T - The target being registered.
854 /// @param Fn - A function to construct an MCSymbolizer for the target.
855 static void RegisterMCSymbolizer(Target &T, Target::MCSymbolizerCtorTy Fn) {
856 T.MCSymbolizerCtorFn = Fn;
862 //===--------------------------------------------------------------------===//
864 /// RegisterTarget - Helper template for registering a target, for use in the
865 /// target's initialization function. Usage:
868 /// Target TheFooTarget; // The global target instance.
870 /// extern "C" void LLVMInitializeFooTargetInfo() {
871 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
873 template <Triple::ArchType TargetArchType = Triple::UnknownArch,
875 struct RegisterTarget {
876 RegisterTarget(Target &T, const char *Name, const char *Desc) {
877 TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch, HasJIT);
880 static bool getArchMatch(Triple::ArchType Arch) {
881 return Arch == TargetArchType;
885 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
886 /// implementation. This invokes the static "Create" method on the class to
887 /// actually do the construction. Usage:
889 /// extern "C" void LLVMInitializeFooTarget() {
890 /// extern Target TheFooTarget;
891 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
893 template <class MCAsmInfoImpl> struct RegisterMCAsmInfo {
894 RegisterMCAsmInfo(Target &T) {
895 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
899 static MCAsmInfo *Allocator(const MCRegisterInfo & /*MRI*/,
900 const TargetTuple &TT) {
901 return new MCAsmInfoImpl(TargetTuple(TT));
905 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
906 /// implementation. This invokes the specified function to do the
907 /// construction. Usage:
909 /// extern "C" void LLVMInitializeFooTarget() {
910 /// extern Target TheFooTarget;
911 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
913 struct RegisterMCAsmInfoFn {
914 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
915 TargetRegistry::RegisterMCAsmInfo(T, Fn);
919 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen
921 /// implementation. This invokes the static "Create" method on the class
922 /// to actually do the construction. Usage:
924 /// extern "C" void LLVMInitializeFooTarget() {
925 /// extern Target TheFooTarget;
926 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
928 template <class MCCodeGenInfoImpl> struct RegisterMCCodeGenInfo {
929 RegisterMCCodeGenInfo(Target &T) {
930 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
934 static MCCodeGenInfo *Allocator(const TargetTuple & /*TT*/,
935 Reloc::Model /*RM*/, CodeModel::Model /*CM*/,
936 CodeGenOpt::Level /*OL*/) {
937 return new MCCodeGenInfoImpl();
941 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
942 /// info implementation. This invokes the specified function to do the
943 /// construction. Usage:
945 /// extern "C" void LLVMInitializeFooTarget() {
946 /// extern Target TheFooTarget;
947 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
949 struct RegisterMCCodeGenInfoFn {
950 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
951 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
955 /// RegisterMCInstrInfo - Helper template for registering a target instruction
956 /// info implementation. This invokes the static "Create" method on the class
957 /// to actually do the construction. Usage:
959 /// extern "C" void LLVMInitializeFooTarget() {
960 /// extern Target TheFooTarget;
961 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
963 template <class MCInstrInfoImpl> struct RegisterMCInstrInfo {
964 RegisterMCInstrInfo(Target &T) {
965 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
969 static MCInstrInfo *Allocator() { return new MCInstrInfoImpl(); }
972 /// RegisterMCInstrInfoFn - Helper template for registering a target
973 /// instruction info implementation. This invokes the specified function to
974 /// do the construction. Usage:
976 /// extern "C" void LLVMInitializeFooTarget() {
977 /// extern Target TheFooTarget;
978 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
980 struct RegisterMCInstrInfoFn {
981 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
982 TargetRegistry::RegisterMCInstrInfo(T, Fn);
986 /// RegisterMCInstrAnalysis - Helper template for registering a target
987 /// instruction analyzer implementation. This invokes the static "Create"
988 /// method on the class to actually do the construction. Usage:
990 /// extern "C" void LLVMInitializeFooTarget() {
991 /// extern Target TheFooTarget;
992 /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
994 template <class MCInstrAnalysisImpl> struct RegisterMCInstrAnalysis {
995 RegisterMCInstrAnalysis(Target &T) {
996 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
1000 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
1001 return new MCInstrAnalysisImpl(Info);
1005 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
1006 /// instruction analyzer implementation. This invokes the specified function
1007 /// to do the construction. Usage:
1009 /// extern "C" void LLVMInitializeFooTarget() {
1010 /// extern Target TheFooTarget;
1011 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
1013 struct RegisterMCInstrAnalysisFn {
1014 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
1015 TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
1019 /// RegisterMCRegInfo - Helper template for registering a target register info
1020 /// implementation. This invokes the static "Create" method on the class to
1021 /// actually do the construction. Usage:
1023 /// extern "C" void LLVMInitializeFooTarget() {
1024 /// extern Target TheFooTarget;
1025 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
1027 template <class MCRegisterInfoImpl> struct RegisterMCRegInfo {
1028 RegisterMCRegInfo(Target &T) {
1029 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
1033 static MCRegisterInfo *Allocator(const TargetTuple & /*TT*/) {
1034 return new MCRegisterInfoImpl();
1038 /// RegisterMCRegInfoFn - Helper template for registering a target register
1039 /// info implementation. This invokes the specified function to do the
1040 /// construction. Usage:
1042 /// extern "C" void LLVMInitializeFooTarget() {
1043 /// extern Target TheFooTarget;
1044 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
1046 struct RegisterMCRegInfoFn {
1047 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
1048 TargetRegistry::RegisterMCRegInfo(T, Fn);
1052 /// RegisterMCSubtargetInfo - Helper template for registering a target
1053 /// subtarget info implementation. This invokes the static "Create" method
1054 /// on the class to actually do the construction. Usage:
1056 /// extern "C" void LLVMInitializeFooTarget() {
1057 /// extern Target TheFooTarget;
1058 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
1060 template <class MCSubtargetInfoImpl> struct RegisterMCSubtargetInfo {
1061 RegisterMCSubtargetInfo(Target &T) {
1062 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
1066 static MCSubtargetInfo *Allocator(const TargetTuple & /*TT*/,
1067 StringRef /*CPU*/, StringRef /*FS*/) {
1068 return new MCSubtargetInfoImpl();
1072 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
1073 /// subtarget info implementation. This invokes the specified function to
1074 /// do the construction. Usage:
1076 /// extern "C" void LLVMInitializeFooTarget() {
1077 /// extern Target TheFooTarget;
1078 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1080 struct RegisterMCSubtargetInfoFn {
1081 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
1082 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
1086 /// RegisterTargetMachine - Helper template for registering a target machine
1087 /// implementation, for use in the target machine initialization
1088 /// function. Usage:
1090 /// extern "C" void LLVMInitializeFooTarget() {
1091 /// extern Target TheFooTarget;
1092 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1094 template <class TargetMachineImpl> struct RegisterTargetMachine {
1095 RegisterTargetMachine(Target &T) {
1096 TargetRegistry::RegisterTargetMachine(T, &Allocator);
1100 static TargetMachine *Allocator(const Target &T, const TargetTuple &TT,
1101 StringRef CPU, StringRef FS,
1102 const TargetOptions &Options, Reloc::Model RM,
1103 CodeModel::Model CM, CodeGenOpt::Level OL) {
1104 return new TargetMachineImpl(T, TT.getTargetTriple(), CPU, FS, Options, RM,
1109 /// RegisterMCAsmBackend - Helper template for registering a target specific
1110 /// assembler backend. Usage:
1112 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1113 /// extern Target TheFooTarget;
1114 /// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1116 template <class MCAsmBackendImpl> struct RegisterMCAsmBackend {
1117 RegisterMCAsmBackend(Target &T) {
1118 TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1122 static MCAsmBackend *Allocator(const Target &T, const MCRegisterInfo &MRI,
1123 const TargetTuple &TT, StringRef CPU) {
1124 return new MCAsmBackendImpl(T, MRI, TT, CPU);
1128 /// RegisterMCAsmParser - Helper template for registering a target specific
1129 /// assembly parser, for use in the target machine initialization
1130 /// function. Usage:
1132 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1133 /// extern Target TheFooTarget;
1134 /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1136 template <class MCAsmParserImpl> struct RegisterMCAsmParser {
1137 RegisterMCAsmParser(Target &T) {
1138 TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1142 static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P,
1143 const MCInstrInfo &MII,
1144 const MCTargetOptions &Options) {
1145 return new MCAsmParserImpl(STI, P, MII, Options);
1149 /// RegisterAsmPrinter - Helper template for registering a target specific
1150 /// assembly printer, for use in the target machine initialization
1151 /// function. Usage:
1153 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1154 /// extern Target TheFooTarget;
1155 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1157 template <class AsmPrinterImpl> struct RegisterAsmPrinter {
1158 RegisterAsmPrinter(Target &T) {
1159 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1163 static AsmPrinter *Allocator(TargetMachine &TM,
1164 std::unique_ptr<MCStreamer> &&Streamer) {
1165 return new AsmPrinterImpl(TM, std::move(Streamer));
1169 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1170 /// machine code emitter, for use in the target initialization
1171 /// function. Usage:
1173 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1174 /// extern Target TheFooTarget;
1175 /// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1177 template <class MCCodeEmitterImpl> struct RegisterMCCodeEmitter {
1178 RegisterMCCodeEmitter(Target &T) {
1179 TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1183 static MCCodeEmitter *Allocator(const MCInstrInfo & /*II*/,
1184 const MCRegisterInfo & /*MRI*/,
1185 MCContext & /*Ctx*/) {
1186 return new MCCodeEmitterImpl();