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 {
547 const Target *Current;
548 explicit iterator(Target *T) : Current(T) {}
549 friend struct TargetRegistry;
551 iterator() : Current(nullptr) {}
553 bool operator==(const iterator &x) const {
554 return Current == x.Current;
556 bool operator!=(const iterator &x) const {
557 return !operator==(x);
560 // Iterator traversal: forward iteration only
561 iterator &operator++() { // Preincrement
562 assert(Current && "Cannot increment end iterator!");
563 Current = Current->getNext();
566 iterator operator++(int) { // Postincrement
567 iterator tmp = *this;
572 const Target &operator*() const {
573 assert(Current && "Cannot dereference end iterator!");
577 const Target *operator->() const {
582 /// printRegisteredTargetsForVersion - Print the registered targets
583 /// appropriately for inclusion in a tool's version output.
584 static void printRegisteredTargetsForVersion();
586 /// @name Registry Access
589 static iterator begin();
591 static iterator end() { return iterator(); }
593 /// lookupTarget - Lookup a target based on a target triple.
595 /// \param Triple - The triple to use for finding a target.
596 /// \param Error - On failure, an error string describing why no target was
598 static const Target *lookupTarget(const std::string &Triple,
601 /// lookupTarget - Lookup a target based on an architecture name
602 /// and a target triple. If the architecture name is non-empty,
603 /// then the lookup is done by architecture. Otherwise, the target
606 /// \param ArchName - The architecture to use for finding a target.
607 /// \param TheTriple - The triple to use for finding a target. The
608 /// triple is updated with canonical architecture name if a lookup
609 /// by architecture is done.
610 /// \param Error - On failure, an error string describing why no target was
612 static const Target *lookupTarget(const std::string &ArchName,
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,
636 const char *ShortDesc,
637 Target::ArchMatchFnTy ArchMatchFn,
638 bool HasJIT = false);
640 /// RegisterMCAsmInfo - Register a MCAsmInfo 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 MCAsmInfo for the target.
649 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
650 T.MCAsmInfoCtorFn = Fn;
653 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
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 MCCodeGenInfo for the target.
662 static void RegisterMCCodeGenInfo(Target &T,
663 Target::MCCodeGenInfoCtorFnTy Fn) {
664 T.MCCodeGenInfoCtorFn = Fn;
667 /// RegisterMCInstrInfo - Register a MCInstrInfo 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 MCInstrInfo for the target.
676 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
677 T.MCInstrInfoCtorFn = Fn;
680 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
681 /// the given target.
682 static void RegisterMCInstrAnalysis(Target &T,
683 Target::MCInstrAnalysisCtorFnTy Fn) {
684 T.MCInstrAnalysisCtorFn = Fn;
687 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
690 /// Clients are responsible for ensuring that registration doesn't occur
691 /// while another thread is attempting to access the registry. Typically
692 /// this is done by initializing all targets at program startup.
694 /// @param T - The target being registered.
695 /// @param Fn - A function to construct a MCRegisterInfo for the target.
696 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
697 T.MCRegInfoCtorFn = Fn;
700 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
701 /// the given target.
703 /// Clients are responsible for ensuring that registration doesn't occur
704 /// while another thread is attempting to access the registry. Typically
705 /// this is done by initializing all targets at program startup.
707 /// @param T - The target being registered.
708 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
709 static void RegisterMCSubtargetInfo(Target &T,
710 Target::MCSubtargetInfoCtorFnTy Fn) {
711 T.MCSubtargetInfoCtorFn = Fn;
714 /// RegisterTargetMachine - Register a TargetMachine implementation for the
717 /// Clients are responsible for ensuring that registration doesn't occur
718 /// while another thread is attempting to access the registry. Typically
719 /// this is done by initializing all targets at program startup.
721 /// @param T - The target being registered.
722 /// @param Fn - A function to construct a TargetMachine for the target.
723 static void RegisterTargetMachine(Target &T,
724 Target::TargetMachineCtorTy Fn) {
725 T.TargetMachineCtorFn = Fn;
728 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
731 /// Clients are responsible for ensuring that registration doesn't occur
732 /// while another thread is attempting to access the registry. Typically
733 /// this is done by initializing all targets at program startup.
735 /// @param T - The target being registered.
736 /// @param Fn - A function to construct an AsmBackend for the target.
737 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
738 T.MCAsmBackendCtorFn = Fn;
741 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
742 /// the given target.
744 /// Clients are responsible for ensuring that registration doesn't occur
745 /// while another thread is attempting to access the registry. Typically
746 /// this is done by initializing all targets at program startup.
748 /// @param T - The target being registered.
749 /// @param Fn - A function to construct an MCTargetAsmParser for the target.
750 static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
751 T.MCAsmParserCtorFn = Fn;
754 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
757 /// Clients are responsible for ensuring that registration doesn't occur
758 /// while another thread is attempting to access the registry. Typically
759 /// this is done by initializing all targets at program startup.
761 /// @param T - The target being registered.
762 /// @param Fn - A function to construct an AsmPrinter for the target.
763 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
764 T.AsmPrinterCtorFn = Fn;
767 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
768 /// the given target.
770 /// Clients are responsible for ensuring that registration doesn't occur
771 /// while another thread is attempting to access the registry. Typically
772 /// this is done by initializing all targets at program startup.
774 /// @param T - The target being registered.
775 /// @param Fn - A function to construct an MCDisassembler for the target.
776 static void RegisterMCDisassembler(Target &T,
777 Target::MCDisassemblerCtorTy Fn) {
778 T.MCDisassemblerCtorFn = Fn;
781 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
784 /// Clients are responsible for ensuring that registration doesn't occur
785 /// while another thread is attempting to access the registry. Typically
786 /// this is done by initializing all targets at program startup.
788 /// @param T - The target being registered.
789 /// @param Fn - A function to construct an MCInstPrinter for the target.
790 static void RegisterMCInstPrinter(Target &T,
791 Target::MCInstPrinterCtorTy Fn) {
792 T.MCInstPrinterCtorFn = Fn;
795 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
798 /// Clients are responsible for ensuring that registration doesn't occur
799 /// while another thread is attempting to access the registry. Typically
800 /// this is done by initializing all targets at program startup.
802 /// @param T - The target being registered.
803 /// @param Fn - A function to construct an MCCodeEmitter for the target.
804 static void RegisterMCCodeEmitter(Target &T,
805 Target::MCCodeEmitterCtorTy Fn) {
806 T.MCCodeEmitterCtorFn = Fn;
809 static void RegisterCOFFStreamer(Target &T, Target::COFFStreamerCtorTy Fn) {
810 T.COFFStreamerCtorFn = Fn;
813 static void RegisterMachOStreamer(Target &T,
814 Target::MachOStreamerCtorTy Fn) {
815 T.MachOStreamerCtorFn = Fn;
818 static void RegisterELFStreamer(Target &T, Target::ELFStreamerCtorTy Fn) {
819 T.ELFStreamerCtorFn = Fn;
823 RegisterNullTargetStreamer(Target &T, Target::NullTargetStreamerCtorTy Fn) {
824 T.NullTargetStreamerCtorFn = Fn;
827 static void RegisterAsmTargetStreamer(Target &T,
828 Target::AsmTargetStreamerCtorTy Fn) {
829 T.AsmTargetStreamerCtorFn = Fn;
833 RegisterObjectTargetStreamer(Target &T,
834 Target::ObjectTargetStreamerCtorTy Fn) {
835 T.ObjectTargetStreamerCtorFn = Fn;
838 /// RegisterMCRelocationInfo - Register an MCRelocationInfo
839 /// implementation for the given target.
841 /// Clients are responsible for ensuring that registration doesn't occur
842 /// while another thread is attempting to access the registry. Typically
843 /// this is done by initializing all targets at program startup.
845 /// @param T - The target being registered.
846 /// @param Fn - A function to construct an MCRelocationInfo for the target.
847 static void RegisterMCRelocationInfo(Target &T,
848 Target::MCRelocationInfoCtorTy Fn) {
849 T.MCRelocationInfoCtorFn = Fn;
852 /// RegisterMCSymbolizer - Register an MCSymbolizer
853 /// implementation for the given target.
855 /// Clients are responsible for ensuring that registration doesn't occur
856 /// while another thread is attempting to access the registry. Typically
857 /// this is done by initializing all targets at program startup.
859 /// @param T - The target being registered.
860 /// @param Fn - A function to construct an MCSymbolizer for the target.
861 static void RegisterMCSymbolizer(Target &T,
862 Target::MCSymbolizerCtorTy Fn) {
863 T.MCSymbolizerCtorFn = Fn;
870 //===--------------------------------------------------------------------===//
872 /// RegisterTarget - Helper template for registering a target, for use in the
873 /// target's initialization function. Usage:
876 /// Target TheFooTarget; // The global target instance.
878 /// extern "C" void LLVMInitializeFooTargetInfo() {
879 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
881 template<Triple::ArchType TargetArchType = Triple::UnknownArch,
883 struct RegisterTarget {
884 RegisterTarget(Target &T, const char *Name, const char *Desc) {
885 TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch, HasJIT);
888 static bool getArchMatch(Triple::ArchType Arch) {
889 return Arch == TargetArchType;
893 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
894 /// implementation. This invokes the static "Create" method on the class to
895 /// actually do the construction. Usage:
897 /// extern "C" void LLVMInitializeFooTarget() {
898 /// extern Target TheFooTarget;
899 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
901 template<class MCAsmInfoImpl>
902 struct RegisterMCAsmInfo {
903 RegisterMCAsmInfo(Target &T) {
904 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
907 static MCAsmInfo *Allocator(const MCRegisterInfo &/*MRI*/, StringRef TT) {
908 return new MCAsmInfoImpl(TT);
913 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
914 /// implementation. This invokes the specified function to do the
915 /// construction. Usage:
917 /// extern "C" void LLVMInitializeFooTarget() {
918 /// extern Target TheFooTarget;
919 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
921 struct RegisterMCAsmInfoFn {
922 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
923 TargetRegistry::RegisterMCAsmInfo(T, Fn);
927 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
928 /// implementation. This invokes the static "Create" method on the class
929 /// to actually do the construction. Usage:
931 /// extern "C" void LLVMInitializeFooTarget() {
932 /// extern Target TheFooTarget;
933 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
935 template<class MCCodeGenInfoImpl>
936 struct RegisterMCCodeGenInfo {
937 RegisterMCCodeGenInfo(Target &T) {
938 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
941 static MCCodeGenInfo *Allocator(StringRef /*TT*/, Reloc::Model /*RM*/,
942 CodeModel::Model /*CM*/,
943 CodeGenOpt::Level /*OL*/) {
944 return new MCCodeGenInfoImpl();
948 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
949 /// info implementation. This invokes the specified function to do the
950 /// construction. Usage:
952 /// extern "C" void LLVMInitializeFooTarget() {
953 /// extern Target TheFooTarget;
954 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
956 struct RegisterMCCodeGenInfoFn {
957 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
958 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
962 /// RegisterMCInstrInfo - Helper template for registering a target instruction
963 /// info implementation. This invokes the static "Create" method on the class
964 /// to actually do the construction. Usage:
966 /// extern "C" void LLVMInitializeFooTarget() {
967 /// extern Target TheFooTarget;
968 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
970 template<class MCInstrInfoImpl>
971 struct RegisterMCInstrInfo {
972 RegisterMCInstrInfo(Target &T) {
973 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
976 static MCInstrInfo *Allocator() {
977 return new MCInstrInfoImpl();
981 /// RegisterMCInstrInfoFn - Helper template for registering a target
982 /// instruction info implementation. This invokes the specified function to
983 /// do the construction. Usage:
985 /// extern "C" void LLVMInitializeFooTarget() {
986 /// extern Target TheFooTarget;
987 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
989 struct RegisterMCInstrInfoFn {
990 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
991 TargetRegistry::RegisterMCInstrInfo(T, Fn);
995 /// RegisterMCInstrAnalysis - Helper template for registering a target
996 /// instruction analyzer implementation. This invokes the static "Create"
997 /// method on the class to actually do the construction. Usage:
999 /// extern "C" void LLVMInitializeFooTarget() {
1000 /// extern Target TheFooTarget;
1001 /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
1003 template<class MCInstrAnalysisImpl>
1004 struct RegisterMCInstrAnalysis {
1005 RegisterMCInstrAnalysis(Target &T) {
1006 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
1009 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
1010 return new MCInstrAnalysisImpl(Info);
1014 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
1015 /// instruction analyzer implementation. This invokes the specified function
1016 /// to do the construction. Usage:
1018 /// extern "C" void LLVMInitializeFooTarget() {
1019 /// extern Target TheFooTarget;
1020 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
1022 struct RegisterMCInstrAnalysisFn {
1023 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
1024 TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
1028 /// RegisterMCRegInfo - Helper template for registering a target register info
1029 /// implementation. This invokes the static "Create" method on the class to
1030 /// actually do the construction. Usage:
1032 /// extern "C" void LLVMInitializeFooTarget() {
1033 /// extern Target TheFooTarget;
1034 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
1036 template<class MCRegisterInfoImpl>
1037 struct RegisterMCRegInfo {
1038 RegisterMCRegInfo(Target &T) {
1039 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
1042 static MCRegisterInfo *Allocator(StringRef /*TT*/) {
1043 return new MCRegisterInfoImpl();
1047 /// RegisterMCRegInfoFn - Helper template for registering a target register
1048 /// info implementation. This invokes the specified function to do the
1049 /// construction. Usage:
1051 /// extern "C" void LLVMInitializeFooTarget() {
1052 /// extern Target TheFooTarget;
1053 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
1055 struct RegisterMCRegInfoFn {
1056 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
1057 TargetRegistry::RegisterMCRegInfo(T, Fn);
1061 /// RegisterMCSubtargetInfo - Helper template for registering a target
1062 /// subtarget info implementation. This invokes the static "Create" method
1063 /// on the class to actually do the construction. Usage:
1065 /// extern "C" void LLVMInitializeFooTarget() {
1066 /// extern Target TheFooTarget;
1067 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
1069 template<class MCSubtargetInfoImpl>
1070 struct RegisterMCSubtargetInfo {
1071 RegisterMCSubtargetInfo(Target &T) {
1072 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
1075 static MCSubtargetInfo *Allocator(StringRef /*TT*/, StringRef /*CPU*/,
1077 return new MCSubtargetInfoImpl();
1081 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
1082 /// subtarget info implementation. This invokes the specified function to
1083 /// do the construction. Usage:
1085 /// extern "C" void LLVMInitializeFooTarget() {
1086 /// extern Target TheFooTarget;
1087 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1089 struct RegisterMCSubtargetInfoFn {
1090 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
1091 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
1095 /// RegisterTargetMachine - Helper template for registering a target machine
1096 /// implementation, for use in the target machine initialization
1097 /// function. Usage:
1099 /// extern "C" void LLVMInitializeFooTarget() {
1100 /// extern Target TheFooTarget;
1101 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1103 template<class TargetMachineImpl>
1104 struct RegisterTargetMachine {
1105 RegisterTargetMachine(Target &T) {
1106 TargetRegistry::RegisterTargetMachine(T, &Allocator);
1110 static TargetMachine *Allocator(const Target &T, StringRef TT,
1111 StringRef CPU, StringRef FS,
1112 const TargetOptions &Options,
1114 CodeModel::Model CM,
1115 CodeGenOpt::Level OL) {
1116 return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
1120 /// RegisterMCAsmBackend - Helper template for registering a target specific
1121 /// assembler backend. Usage:
1123 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1124 /// extern Target TheFooTarget;
1125 /// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1127 template<class MCAsmBackendImpl>
1128 struct RegisterMCAsmBackend {
1129 RegisterMCAsmBackend(Target &T) {
1130 TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1134 static MCAsmBackend *Allocator(const Target &T,
1135 const MCRegisterInfo &MRI,
1136 StringRef Triple, StringRef CPU) {
1137 return new MCAsmBackendImpl(T, MRI, Triple, CPU);
1141 /// RegisterMCAsmParser - Helper template for registering a target specific
1142 /// assembly parser, for use in the target machine initialization
1143 /// function. Usage:
1145 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1146 /// extern Target TheFooTarget;
1147 /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1149 template<class MCAsmParserImpl>
1150 struct RegisterMCAsmParser {
1151 RegisterMCAsmParser(Target &T) {
1152 TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1156 static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P,
1157 const MCInstrInfo &MII,
1158 const MCTargetOptions &Options) {
1159 return new MCAsmParserImpl(STI, P, MII, Options);
1163 /// RegisterAsmPrinter - Helper template for registering a target specific
1164 /// assembly printer, for use in the target machine initialization
1165 /// function. Usage:
1167 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1168 /// extern Target TheFooTarget;
1169 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1171 template<class AsmPrinterImpl>
1172 struct RegisterAsmPrinter {
1173 RegisterAsmPrinter(Target &T) {
1174 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1178 static AsmPrinter *Allocator(TargetMachine &TM,
1179 std::unique_ptr<MCStreamer> &&Streamer) {
1180 return new AsmPrinterImpl(TM, std::move(Streamer));
1184 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1185 /// machine code emitter, for use in the target initialization
1186 /// function. Usage:
1188 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1189 /// extern Target TheFooTarget;
1190 /// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1192 template<class MCCodeEmitterImpl>
1193 struct RegisterMCCodeEmitter {
1194 RegisterMCCodeEmitter(Target &T) {
1195 TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1199 static MCCodeEmitter *Allocator(const MCInstrInfo & /*II*/,
1200 const MCRegisterInfo & /*MRI*/,
1201 MCContext & /*Ctx*/) {
1202 return new MCCodeEmitterImpl();