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"
38 class MCInstrAnalysis;
43 class MCSubtargetInfo;
45 class MCRelocationInfo;
46 class MCTargetAsmParser;
47 class MCTargetOptions;
48 class MCTargetStreamer;
52 class formatted_raw_ostream;
54 MCStreamer *createNullStreamer(MCContext &Ctx);
55 MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
56 bool isVerboseAsm, bool useDwarfDirectory,
57 MCInstPrinter *InstPrint, MCCodeEmitter *CE,
58 MCAsmBackend *TAB, bool ShowInst);
60 /// Takes ownership of \p TAB and \p CE.
61 MCStreamer *createELFStreamer(MCContext &Ctx, MCAsmBackend &TAB,
62 raw_ostream &OS, MCCodeEmitter *CE,
64 MCStreamer *createMachOStreamer(MCContext &Ctx, MCAsmBackend &TAB,
65 raw_ostream &OS, MCCodeEmitter *CE,
66 bool RelaxAll, bool DWARFMustBeAtTheEnd,
67 bool LabelSections = false);
69 MCRelocationInfo *createMCRelocationInfo(StringRef TT, MCContext &Ctx);
71 MCSymbolizer *createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
72 LLVMSymbolLookupCallback SymbolLookUp,
73 void *DisInfo, MCContext *Ctx,
74 std::unique_ptr<MCRelocationInfo> &&RelInfo);
76 /// Target - Wrapper for Target specific information.
78 /// For registration purposes, this is a POD type so that targets can be
79 /// registered without the use of static constructors.
81 /// Targets should implement a single global instance of this class (which
82 /// will be zero initialized), and pass that instance to the TargetRegistry as
83 /// part of their initialization.
86 friend struct TargetRegistry;
88 typedef bool (*ArchMatchFnTy)(Triple::ArchType Arch);
90 typedef MCAsmInfo *(*MCAsmInfoCtorFnTy)(const MCRegisterInfo &MRI,
92 typedef MCCodeGenInfo *(*MCCodeGenInfoCtorFnTy)(StringRef TT,
95 CodeGenOpt::Level OL);
96 typedef MCInstrInfo *(*MCInstrInfoCtorFnTy)(void);
97 typedef MCInstrAnalysis *(*MCInstrAnalysisCtorFnTy)(const MCInstrInfo*Info);
98 typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(StringRef TT);
99 typedef MCSubtargetInfo *(*MCSubtargetInfoCtorFnTy)(StringRef TT,
102 typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T,
106 const TargetOptions &Options,
109 CodeGenOpt::Level OL);
110 // If it weren't for layering issues (this header is in llvm/Support, but
111 // depends on MC?) this should take the Streamer by value rather than rvalue
113 typedef AsmPrinter *(*AsmPrinterCtorTy)(
114 TargetMachine &TM, std::unique_ptr<MCStreamer> &&Streamer);
115 typedef MCAsmBackend *(*MCAsmBackendCtorTy)(const Target &T,
116 const MCRegisterInfo &MRI,
119 typedef MCTargetAsmParser *(*MCAsmParserCtorTy)(
120 MCSubtargetInfo &STI,
122 const MCInstrInfo &MII,
123 const MCTargetOptions &Options);
124 typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T,
125 const MCSubtargetInfo &STI,
127 typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
128 unsigned SyntaxVariant,
129 const MCAsmInfo &MAI,
130 const MCInstrInfo &MII,
131 const MCRegisterInfo &MRI,
132 const MCSubtargetInfo &STI);
133 typedef MCCodeEmitter *(*MCCodeEmitterCtorTy)(const MCInstrInfo &II,
134 const MCRegisterInfo &MRI,
136 typedef MCStreamer *(*ELFStreamerCtorTy)(const Triple &T, MCContext &Ctx,
137 MCAsmBackend &TAB, raw_ostream &OS,
138 MCCodeEmitter *Emitter,
140 typedef MCStreamer *(*MachOStreamerCtorTy)(
141 MCContext &Ctx, MCAsmBackend &TAB, raw_ostream &OS,
142 MCCodeEmitter *Emitter, bool RelaxAll, bool DWARFMustBeAtTheEnd);
143 typedef MCStreamer *(*COFFStreamerCtorTy)(MCContext &Ctx, MCAsmBackend &TAB,
145 MCCodeEmitter *Emitter,
147 typedef MCTargetStreamer *(*NullTargetStreamerCtorTy)(MCStreamer &S);
148 typedef MCTargetStreamer *(*AsmTargetStreamerCtorTy)(
149 MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *InstPrint,
151 typedef MCTargetStreamer *(*ObjectTargetStreamerCtorTy)(
152 MCStreamer &S, const MCSubtargetInfo &STI);
153 typedef MCRelocationInfo *(*MCRelocationInfoCtorTy)(StringRef TT,
155 typedef MCSymbolizer *(*MCSymbolizerCtorTy)(
156 StringRef TT, LLVMOpInfoCallback GetOpInfo,
157 LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo, MCContext *Ctx,
158 std::unique_ptr<MCRelocationInfo> &&RelInfo);
161 /// Next - The next registered target in the linked list, maintained by the
165 /// The target function for checking if an architecture is supported.
166 ArchMatchFnTy ArchMatchFn;
168 /// Name - The target name.
171 /// ShortDesc - A short description of the target.
172 const char *ShortDesc;
174 /// HasJIT - Whether this target supports the JIT.
177 /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
179 MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
181 /// MCCodeGenInfoCtorFn - Constructor function for this target's
182 /// MCCodeGenInfo, if registered.
183 MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn;
185 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
187 MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
189 /// MCInstrAnalysisCtorFn - Constructor function for this target's
190 /// MCInstrAnalysis, if registered.
191 MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
193 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
195 MCRegInfoCtorFnTy MCRegInfoCtorFn;
197 /// MCSubtargetInfoCtorFn - Constructor function for this target's
198 /// MCSubtargetInfo, if registered.
199 MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
201 /// TargetMachineCtorFn - Construction function for this target's
202 /// TargetMachine, if registered.
203 TargetMachineCtorTy TargetMachineCtorFn;
205 /// MCAsmBackendCtorFn - Construction function for this target's
206 /// MCAsmBackend, if registered.
207 MCAsmBackendCtorTy MCAsmBackendCtorFn;
209 /// MCAsmParserCtorFn - Construction function for this target's
210 /// MCTargetAsmParser, if registered.
211 MCAsmParserCtorTy MCAsmParserCtorFn;
213 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
215 AsmPrinterCtorTy AsmPrinterCtorFn;
217 /// MCDisassemblerCtorFn - Construction function for this target's
218 /// MCDisassembler, if registered.
219 MCDisassemblerCtorTy MCDisassemblerCtorFn;
221 /// MCInstPrinterCtorFn - Construction function for this target's
222 /// MCInstPrinter, if registered.
223 MCInstPrinterCtorTy MCInstPrinterCtorFn;
225 /// MCCodeEmitterCtorFn - Construction function for this target's
226 /// CodeEmitter, if registered.
227 MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
229 // Construction functions for the various object formats, if registered.
230 COFFStreamerCtorTy COFFStreamerCtorFn;
231 MachOStreamerCtorTy MachOStreamerCtorFn;
232 ELFStreamerCtorTy ELFStreamerCtorFn;
234 /// Construction function for this target's null TargetStreamer, if
235 /// registered (default = nullptr).
236 NullTargetStreamerCtorTy NullTargetStreamerCtorFn;
238 /// Construction function for this target's asm TargetStreamer, if
239 /// registered (default = nullptr).
240 AsmTargetStreamerCtorTy AsmTargetStreamerCtorFn;
242 /// Construction function for this target's obj TargetStreamer, if
243 /// registered (default = nullptr).
244 ObjectTargetStreamerCtorTy ObjectTargetStreamerCtorFn;
246 /// MCRelocationInfoCtorFn - Construction function for this target's
247 /// MCRelocationInfo, if registered (default = llvm::createMCRelocationInfo)
248 MCRelocationInfoCtorTy MCRelocationInfoCtorFn;
250 /// MCSymbolizerCtorFn - Construction function for this target's
251 /// MCSymbolizer, if registered (default = llvm::createMCSymbolizer)
252 MCSymbolizerCtorTy MCSymbolizerCtorFn;
256 : COFFStreamerCtorFn(nullptr), MachOStreamerCtorFn(nullptr),
257 ELFStreamerCtorFn(nullptr), NullTargetStreamerCtorFn(nullptr),
258 AsmTargetStreamerCtorFn(nullptr), ObjectTargetStreamerCtorFn(nullptr),
259 MCRelocationInfoCtorFn(nullptr), MCSymbolizerCtorFn(nullptr) {}
261 /// @name Target Information
264 // getNext - Return the next registered target.
265 const Target *getNext() const { return Next; }
267 /// getName - Get the target name.
268 const char *getName() const { return Name; }
270 /// getShortDescription - Get a short description of the target.
271 const char *getShortDescription() const { return ShortDesc; }
274 /// @name Feature Predicates
277 /// hasJIT - Check if this targets supports the just-in-time compilation.
278 bool hasJIT() const { return HasJIT; }
280 /// hasTargetMachine - Check if this target supports code generation.
281 bool hasTargetMachine() const { return TargetMachineCtorFn != nullptr; }
283 /// hasMCAsmBackend - Check if this target supports .o generation.
284 bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != nullptr; }
287 /// @name Feature Constructors
290 /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
293 /// \param Triple This argument is used to determine the target machine
294 /// feature set; it should always be provided. Generally this should be
295 /// either the target triple from the module, or the target triple of the
296 /// host if that does not exist.
297 MCAsmInfo *createMCAsmInfo(const MCRegisterInfo &MRI,
298 StringRef Triple) const {
299 if (!MCAsmInfoCtorFn)
301 return MCAsmInfoCtorFn(MRI, Triple);
304 /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
306 MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model RM,
308 CodeGenOpt::Level OL) const {
309 if (!MCCodeGenInfoCtorFn)
311 return MCCodeGenInfoCtorFn(Triple, RM, CM, OL);
314 /// createMCInstrInfo - Create a MCInstrInfo implementation.
316 MCInstrInfo *createMCInstrInfo() const {
317 if (!MCInstrInfoCtorFn)
319 return MCInstrInfoCtorFn();
322 /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
324 MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
325 if (!MCInstrAnalysisCtorFn)
327 return MCInstrAnalysisCtorFn(Info);
330 /// createMCRegInfo - Create a MCRegisterInfo implementation.
332 MCRegisterInfo *createMCRegInfo(StringRef Triple) const {
333 if (!MCRegInfoCtorFn)
335 return MCRegInfoCtorFn(Triple);
338 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
340 /// \param Triple This argument is used to determine the target machine
341 /// feature set; it should always be provided. Generally this should be
342 /// either the target triple from the module, or the target triple of the
343 /// host if that does not exist.
344 /// \param CPU This specifies the name of the target CPU.
345 /// \param Features This specifies the string representation of the
346 /// additional target features.
347 MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU,
348 StringRef Features) const {
349 if (!MCSubtargetInfoCtorFn)
351 return MCSubtargetInfoCtorFn(Triple, CPU, Features);
354 /// createTargetMachine - Create a target specific machine implementation
355 /// for the specified \p Triple.
357 /// \param Triple This argument is used to determine the target machine
358 /// feature set; it should always be provided. Generally this should be
359 /// either the target triple from the module, or the target triple of the
360 /// host if that does not exist.
361 TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU,
362 StringRef Features, const TargetOptions &Options,
363 Reloc::Model RM = Reloc::Default,
364 CodeModel::Model CM = CodeModel::Default,
365 CodeGenOpt::Level OL = CodeGenOpt::Default) const {
366 if (!TargetMachineCtorFn)
368 return TargetMachineCtorFn(*this, Triple, CPU, Features, Options,
372 /// createMCAsmBackend - Create a target specific assembly parser.
374 /// \param Triple The target triple string.
375 MCAsmBackend *createMCAsmBackend(const MCRegisterInfo &MRI,
376 StringRef Triple, StringRef CPU) const {
377 if (!MCAsmBackendCtorFn)
379 return MCAsmBackendCtorFn(*this, MRI, Triple, CPU);
382 /// createMCAsmParser - Create a target specific assembly parser.
384 /// \param Parser The target independent parser implementation to use for
385 /// parsing and lexing.
386 MCTargetAsmParser *createMCAsmParser(
387 MCSubtargetInfo &STI,
389 const MCInstrInfo &MII,
390 const MCTargetOptions &Options) const {
391 if (!MCAsmParserCtorFn)
393 return MCAsmParserCtorFn(STI, Parser, MII, Options);
396 /// createAsmPrinter - Create a target specific assembly printer pass. This
397 /// takes ownership of the MCStreamer object.
398 AsmPrinter *createAsmPrinter(TargetMachine &TM,
399 std::unique_ptr<MCStreamer> &&Streamer) const {
400 if (!AsmPrinterCtorFn)
402 return AsmPrinterCtorFn(TM, std::move(Streamer));
405 MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI,
406 MCContext &Ctx) const {
407 if (!MCDisassemblerCtorFn)
409 return MCDisassemblerCtorFn(*this, STI, Ctx);
412 MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
413 const MCAsmInfo &MAI,
414 const MCInstrInfo &MII,
415 const MCRegisterInfo &MRI,
416 const MCSubtargetInfo &STI) const {
417 if (!MCInstPrinterCtorFn)
419 return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, MII, MRI, STI);
423 /// createMCCodeEmitter - Create a target specific code emitter.
424 MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
425 const MCRegisterInfo &MRI,
426 MCContext &Ctx) const {
427 if (!MCCodeEmitterCtorFn)
429 return MCCodeEmitterCtorFn(II, MRI, Ctx);
432 /// Create a target specific MCStreamer.
434 /// \param T The target triple.
435 /// \param Ctx The target context.
436 /// \param TAB The target assembler backend object. Takes ownership.
437 /// \param OS The stream object.
438 /// \param Emitter The target independent assembler object.Takes ownership.
439 /// \param RelaxAll Relax all fixups?
440 MCStreamer *createMCObjectStreamer(const Triple &T, MCContext &Ctx,
441 MCAsmBackend &TAB, raw_ostream &OS,
442 MCCodeEmitter *Emitter,
443 const MCSubtargetInfo &STI,
445 bool DWARFMustBeAtTheEnd) const {
447 switch (T.getObjectFormat()) {
449 llvm_unreachable("Unknown object format");
451 assert(T.isOSWindows() && "only Windows COFF is supported");
452 S = COFFStreamerCtorFn(Ctx, TAB, OS, Emitter, RelaxAll);
455 if (MachOStreamerCtorFn)
456 S = MachOStreamerCtorFn(Ctx, TAB, OS, Emitter, RelaxAll,
457 DWARFMustBeAtTheEnd);
459 S = createMachOStreamer(Ctx, TAB, OS, Emitter, RelaxAll,
460 DWARFMustBeAtTheEnd);
463 if (ELFStreamerCtorFn)
464 S = ELFStreamerCtorFn(T, Ctx, TAB, OS, Emitter, RelaxAll);
466 S = createELFStreamer(Ctx, TAB, OS, Emitter, RelaxAll);
469 if (ObjectTargetStreamerCtorFn)
470 ObjectTargetStreamerCtorFn(*S, STI);
474 MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
475 bool IsVerboseAsm, bool UseDwarfDirectory,
476 MCInstPrinter *InstPrint, MCCodeEmitter *CE,
477 MCAsmBackend *TAB, bool ShowInst) const {
479 llvm::createAsmStreamer(Ctx, OS, IsVerboseAsm, UseDwarfDirectory,
480 InstPrint, CE, TAB, ShowInst);
481 createAsmTargetStreamer(*S, OS, InstPrint, IsVerboseAsm);
485 MCTargetStreamer *createAsmTargetStreamer(MCStreamer &S,
486 formatted_raw_ostream &OS,
487 MCInstPrinter *InstPrint,
488 bool IsVerboseAsm) const {
489 if (AsmTargetStreamerCtorFn)
490 return AsmTargetStreamerCtorFn(S, OS, InstPrint, IsVerboseAsm);
494 MCStreamer *createNullStreamer(MCContext &Ctx) const {
495 MCStreamer *S = llvm::createNullStreamer(Ctx);
496 createNullTargetStreamer(*S);
500 MCTargetStreamer *createNullTargetStreamer(MCStreamer &S) const {
501 if (NullTargetStreamerCtorFn)
502 return NullTargetStreamerCtorFn(S);
506 /// createMCRelocationInfo - Create a target specific MCRelocationInfo.
508 /// \param TT The target triple.
509 /// \param Ctx The target context.
511 createMCRelocationInfo(StringRef TT, MCContext &Ctx) const {
512 MCRelocationInfoCtorTy Fn = MCRelocationInfoCtorFn
513 ? MCRelocationInfoCtorFn
514 : llvm::createMCRelocationInfo;
518 /// createMCSymbolizer - Create a target specific MCSymbolizer.
520 /// \param TT The target triple.
521 /// \param GetOpInfo The function to get the symbolic information for operands.
522 /// \param SymbolLookUp The function to lookup a symbol name.
523 /// \param DisInfo The pointer to the block of symbolic information for above call
525 /// \param Ctx The target context.
526 /// \param RelInfo The relocation information for this target. Takes ownership.
528 createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
529 LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo,
531 std::unique_ptr<MCRelocationInfo> &&RelInfo) const {
532 MCSymbolizerCtorTy Fn =
533 MCSymbolizerCtorFn ? MCSymbolizerCtorFn : llvm::createMCSymbolizer;
534 return Fn(TT, GetOpInfo, SymbolLookUp, DisInfo, Ctx, std::move(RelInfo));
540 /// TargetRegistry - Generic interface to target specific features.
541 struct TargetRegistry {
543 const Target *Current;
544 explicit iterator(Target *T) : Current(T) {}
545 friend struct TargetRegistry;
547 iterator() : Current(nullptr) {}
549 bool operator==(const iterator &x) const {
550 return Current == x.Current;
552 bool operator!=(const iterator &x) const {
553 return !operator==(x);
556 // Iterator traversal: forward iteration only
557 iterator &operator++() { // Preincrement
558 assert(Current && "Cannot increment end iterator!");
559 Current = Current->getNext();
562 iterator operator++(int) { // Postincrement
563 iterator tmp = *this;
568 const Target &operator*() const {
569 assert(Current && "Cannot dereference end iterator!");
573 const Target *operator->() const {
578 /// printRegisteredTargetsForVersion - Print the registered targets
579 /// appropriately for inclusion in a tool's version output.
580 static void printRegisteredTargetsForVersion();
582 /// @name Registry Access
585 static iterator begin();
587 static iterator end() { return iterator(); }
589 /// lookupTarget - Lookup a target based on a target triple.
591 /// \param Triple - The triple to use for finding a target.
592 /// \param Error - On failure, an error string describing why no target was
594 static const Target *lookupTarget(const std::string &Triple,
597 /// lookupTarget - Lookup a target based on an architecture name
598 /// and a target triple. If the architecture name is non-empty,
599 /// then the lookup is done by architecture. Otherwise, the target
602 /// \param ArchName - The architecture to use for finding a target.
603 /// \param TheTriple - The triple to use for finding a target. The
604 /// triple is updated with canonical architecture name if a lookup
605 /// by architecture is done.
606 /// \param Error - On failure, an error string describing why no target was
608 static const Target *lookupTarget(const std::string &ArchName,
613 /// @name Target Registration
616 /// RegisterTarget - Register the given target. Attempts to register a
617 /// target which has already been registered will be ignored.
619 /// Clients are responsible for ensuring that registration doesn't occur
620 /// while another thread is attempting to access the registry. Typically
621 /// this is done by initializing all targets at program startup.
623 /// @param T - The target being registered.
624 /// @param Name - The target name. This should be a static string.
625 /// @param ShortDesc - A short target description. This should be a static
627 /// @param ArchMatchFn - The arch match checking function for this target.
628 /// @param HasJIT - Whether the target supports JIT code
630 static void RegisterTarget(Target &T,
632 const char *ShortDesc,
633 Target::ArchMatchFnTy ArchMatchFn,
634 bool HasJIT = false);
636 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
639 /// Clients are responsible for ensuring that registration doesn't occur
640 /// while another thread is attempting to access the registry. Typically
641 /// this is done by initializing all targets at program startup.
643 /// @param T - The target being registered.
644 /// @param Fn - A function to construct a MCAsmInfo for the target.
645 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
646 T.MCAsmInfoCtorFn = Fn;
649 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
652 /// Clients are responsible for ensuring that registration doesn't occur
653 /// while another thread is attempting to access the registry. Typically
654 /// this is done by initializing all targets at program startup.
656 /// @param T - The target being registered.
657 /// @param Fn - A function to construct a MCCodeGenInfo for the target.
658 static void RegisterMCCodeGenInfo(Target &T,
659 Target::MCCodeGenInfoCtorFnTy Fn) {
660 T.MCCodeGenInfoCtorFn = Fn;
663 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
666 /// Clients are responsible for ensuring that registration doesn't occur
667 /// while another thread is attempting to access the registry. Typically
668 /// this is done by initializing all targets at program startup.
670 /// @param T - The target being registered.
671 /// @param Fn - A function to construct a MCInstrInfo for the target.
672 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
673 T.MCInstrInfoCtorFn = Fn;
676 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
677 /// the given target.
678 static void RegisterMCInstrAnalysis(Target &T,
679 Target::MCInstrAnalysisCtorFnTy Fn) {
680 T.MCInstrAnalysisCtorFn = Fn;
683 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
686 /// Clients are responsible for ensuring that registration doesn't occur
687 /// while another thread is attempting to access the registry. Typically
688 /// this is done by initializing all targets at program startup.
690 /// @param T - The target being registered.
691 /// @param Fn - A function to construct a MCRegisterInfo for the target.
692 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
693 T.MCRegInfoCtorFn = Fn;
696 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
697 /// the given target.
699 /// Clients are responsible for ensuring that registration doesn't occur
700 /// while another thread is attempting to access the registry. Typically
701 /// this is done by initializing all targets at program startup.
703 /// @param T - The target being registered.
704 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
705 static void RegisterMCSubtargetInfo(Target &T,
706 Target::MCSubtargetInfoCtorFnTy Fn) {
707 T.MCSubtargetInfoCtorFn = Fn;
710 /// RegisterTargetMachine - Register a TargetMachine implementation for the
713 /// Clients are responsible for ensuring that registration doesn't occur
714 /// while another thread is attempting to access the registry. Typically
715 /// this is done by initializing all targets at program startup.
717 /// @param T - The target being registered.
718 /// @param Fn - A function to construct a TargetMachine for the target.
719 static void RegisterTargetMachine(Target &T,
720 Target::TargetMachineCtorTy Fn) {
721 T.TargetMachineCtorFn = Fn;
724 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
727 /// Clients are responsible for ensuring that registration doesn't occur
728 /// while another thread is attempting to access the registry. Typically
729 /// this is done by initializing all targets at program startup.
731 /// @param T - The target being registered.
732 /// @param Fn - A function to construct an AsmBackend for the target.
733 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
734 T.MCAsmBackendCtorFn = Fn;
737 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
738 /// the given target.
740 /// Clients are responsible for ensuring that registration doesn't occur
741 /// while another thread is attempting to access the registry. Typically
742 /// this is done by initializing all targets at program startup.
744 /// @param T - The target being registered.
745 /// @param Fn - A function to construct an MCTargetAsmParser for the target.
746 static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
747 T.MCAsmParserCtorFn = Fn;
750 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
753 /// Clients are responsible for ensuring that registration doesn't occur
754 /// while another thread is attempting to access the registry. Typically
755 /// this is done by initializing all targets at program startup.
757 /// @param T - The target being registered.
758 /// @param Fn - A function to construct an AsmPrinter for the target.
759 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
760 T.AsmPrinterCtorFn = Fn;
763 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
764 /// the given target.
766 /// Clients are responsible for ensuring that registration doesn't occur
767 /// while another thread is attempting to access the registry. Typically
768 /// this is done by initializing all targets at program startup.
770 /// @param T - The target being registered.
771 /// @param Fn - A function to construct an MCDisassembler for the target.
772 static void RegisterMCDisassembler(Target &T,
773 Target::MCDisassemblerCtorTy Fn) {
774 T.MCDisassemblerCtorFn = Fn;
777 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
780 /// Clients are responsible for ensuring that registration doesn't occur
781 /// while another thread is attempting to access the registry. Typically
782 /// this is done by initializing all targets at program startup.
784 /// @param T - The target being registered.
785 /// @param Fn - A function to construct an MCInstPrinter for the target.
786 static void RegisterMCInstPrinter(Target &T,
787 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,
801 Target::MCCodeEmitterCtorTy Fn) {
802 T.MCCodeEmitterCtorFn = Fn;
805 static void RegisterCOFFStreamer(Target &T, Target::COFFStreamerCtorTy Fn) {
806 T.COFFStreamerCtorFn = Fn;
809 static void RegisterMachOStreamer(Target &T,
810 Target::MachOStreamerCtorTy Fn) {
811 T.MachOStreamerCtorFn = Fn;
814 static void RegisterELFStreamer(Target &T, Target::ELFStreamerCtorTy Fn) {
815 T.ELFStreamerCtorFn = Fn;
819 RegisterNullTargetStreamer(Target &T, Target::NullTargetStreamerCtorTy Fn) {
820 T.NullTargetStreamerCtorFn = Fn;
823 static void RegisterAsmTargetStreamer(Target &T,
824 Target::AsmTargetStreamerCtorTy Fn) {
825 T.AsmTargetStreamerCtorFn = Fn;
829 RegisterObjectTargetStreamer(Target &T,
830 Target::ObjectTargetStreamerCtorTy Fn) {
831 T.ObjectTargetStreamerCtorFn = Fn;
834 /// RegisterMCRelocationInfo - Register an MCRelocationInfo
835 /// implementation for the given target.
837 /// Clients are responsible for ensuring that registration doesn't occur
838 /// while another thread is attempting to access the registry. Typically
839 /// this is done by initializing all targets at program startup.
841 /// @param T - The target being registered.
842 /// @param Fn - A function to construct an MCRelocationInfo for the target.
843 static void RegisterMCRelocationInfo(Target &T,
844 Target::MCRelocationInfoCtorTy Fn) {
845 T.MCRelocationInfoCtorFn = Fn;
848 /// RegisterMCSymbolizer - Register an MCSymbolizer
849 /// implementation for the given target.
851 /// Clients are responsible for ensuring that registration doesn't occur
852 /// while another thread is attempting to access the registry. Typically
853 /// this is done by initializing all targets at program startup.
855 /// @param T - The target being registered.
856 /// @param Fn - A function to construct an MCSymbolizer for the target.
857 static void RegisterMCSymbolizer(Target &T,
858 Target::MCSymbolizerCtorTy Fn) {
859 T.MCSymbolizerCtorFn = Fn;
866 //===--------------------------------------------------------------------===//
868 /// RegisterTarget - Helper template for registering a target, for use in the
869 /// target's initialization function. Usage:
872 /// Target TheFooTarget; // The global target instance.
874 /// extern "C" void LLVMInitializeFooTargetInfo() {
875 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
877 template<Triple::ArchType TargetArchType = Triple::UnknownArch,
879 struct RegisterTarget {
880 RegisterTarget(Target &T, const char *Name, const char *Desc) {
881 TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch, HasJIT);
884 static bool getArchMatch(Triple::ArchType Arch) {
885 return Arch == TargetArchType;
889 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
890 /// implementation. This invokes the static "Create" method on the class to
891 /// actually do the construction. Usage:
893 /// extern "C" void LLVMInitializeFooTarget() {
894 /// extern Target TheFooTarget;
895 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
897 template<class MCAsmInfoImpl>
898 struct RegisterMCAsmInfo {
899 RegisterMCAsmInfo(Target &T) {
900 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
903 static MCAsmInfo *Allocator(const MCRegisterInfo &/*MRI*/, StringRef TT) {
904 return new MCAsmInfoImpl(TT);
909 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
910 /// implementation. This invokes the specified function to do the
911 /// construction. Usage:
913 /// extern "C" void LLVMInitializeFooTarget() {
914 /// extern Target TheFooTarget;
915 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
917 struct RegisterMCAsmInfoFn {
918 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
919 TargetRegistry::RegisterMCAsmInfo(T, Fn);
923 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
924 /// implementation. This invokes the static "Create" method on the class
925 /// to actually do the construction. Usage:
927 /// extern "C" void LLVMInitializeFooTarget() {
928 /// extern Target TheFooTarget;
929 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
931 template<class MCCodeGenInfoImpl>
932 struct RegisterMCCodeGenInfo {
933 RegisterMCCodeGenInfo(Target &T) {
934 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
937 static MCCodeGenInfo *Allocator(StringRef /*TT*/, Reloc::Model /*RM*/,
938 CodeModel::Model /*CM*/,
939 CodeGenOpt::Level /*OL*/) {
940 return new MCCodeGenInfoImpl();
944 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
945 /// info implementation. This invokes the specified function to do the
946 /// construction. Usage:
948 /// extern "C" void LLVMInitializeFooTarget() {
949 /// extern Target TheFooTarget;
950 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
952 struct RegisterMCCodeGenInfoFn {
953 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
954 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
958 /// RegisterMCInstrInfo - Helper template for registering a target instruction
959 /// info implementation. This invokes the static "Create" method on the class
960 /// to actually do the construction. Usage:
962 /// extern "C" void LLVMInitializeFooTarget() {
963 /// extern Target TheFooTarget;
964 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
966 template<class MCInstrInfoImpl>
967 struct RegisterMCInstrInfo {
968 RegisterMCInstrInfo(Target &T) {
969 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
972 static MCInstrInfo *Allocator() {
973 return new MCInstrInfoImpl();
977 /// RegisterMCInstrInfoFn - Helper template for registering a target
978 /// instruction info implementation. This invokes the specified function to
979 /// do the construction. Usage:
981 /// extern "C" void LLVMInitializeFooTarget() {
982 /// extern Target TheFooTarget;
983 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
985 struct RegisterMCInstrInfoFn {
986 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
987 TargetRegistry::RegisterMCInstrInfo(T, Fn);
991 /// RegisterMCInstrAnalysis - Helper template for registering a target
992 /// instruction analyzer implementation. This invokes the static "Create"
993 /// method on the class to actually do the construction. Usage:
995 /// extern "C" void LLVMInitializeFooTarget() {
996 /// extern Target TheFooTarget;
997 /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
999 template<class MCInstrAnalysisImpl>
1000 struct RegisterMCInstrAnalysis {
1001 RegisterMCInstrAnalysis(Target &T) {
1002 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
1005 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
1006 return new MCInstrAnalysisImpl(Info);
1010 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
1011 /// instruction analyzer implementation. This invokes the specified function
1012 /// to do the construction. Usage:
1014 /// extern "C" void LLVMInitializeFooTarget() {
1015 /// extern Target TheFooTarget;
1016 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
1018 struct RegisterMCInstrAnalysisFn {
1019 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
1020 TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
1024 /// RegisterMCRegInfo - Helper template for registering a target register info
1025 /// implementation. This invokes the static "Create" method on the class to
1026 /// actually do the construction. Usage:
1028 /// extern "C" void LLVMInitializeFooTarget() {
1029 /// extern Target TheFooTarget;
1030 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
1032 template<class MCRegisterInfoImpl>
1033 struct RegisterMCRegInfo {
1034 RegisterMCRegInfo(Target &T) {
1035 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
1038 static MCRegisterInfo *Allocator(StringRef /*TT*/) {
1039 return new MCRegisterInfoImpl();
1043 /// RegisterMCRegInfoFn - Helper template for registering a target register
1044 /// info implementation. This invokes the specified function to do the
1045 /// construction. Usage:
1047 /// extern "C" void LLVMInitializeFooTarget() {
1048 /// extern Target TheFooTarget;
1049 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
1051 struct RegisterMCRegInfoFn {
1052 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
1053 TargetRegistry::RegisterMCRegInfo(T, Fn);
1057 /// RegisterMCSubtargetInfo - Helper template for registering a target
1058 /// subtarget info implementation. This invokes the static "Create" method
1059 /// on the class to actually do the construction. Usage:
1061 /// extern "C" void LLVMInitializeFooTarget() {
1062 /// extern Target TheFooTarget;
1063 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
1065 template<class MCSubtargetInfoImpl>
1066 struct RegisterMCSubtargetInfo {
1067 RegisterMCSubtargetInfo(Target &T) {
1068 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
1071 static MCSubtargetInfo *Allocator(StringRef /*TT*/, StringRef /*CPU*/,
1073 return new MCSubtargetInfoImpl();
1077 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
1078 /// subtarget info implementation. This invokes the specified function to
1079 /// do the construction. Usage:
1081 /// extern "C" void LLVMInitializeFooTarget() {
1082 /// extern Target TheFooTarget;
1083 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1085 struct RegisterMCSubtargetInfoFn {
1086 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
1087 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
1091 /// RegisterTargetMachine - Helper template for registering a target machine
1092 /// implementation, for use in the target machine initialization
1093 /// function. Usage:
1095 /// extern "C" void LLVMInitializeFooTarget() {
1096 /// extern Target TheFooTarget;
1097 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1099 template<class TargetMachineImpl>
1100 struct RegisterTargetMachine {
1101 RegisterTargetMachine(Target &T) {
1102 TargetRegistry::RegisterTargetMachine(T, &Allocator);
1106 static TargetMachine *Allocator(const Target &T, StringRef TT,
1107 StringRef CPU, StringRef FS,
1108 const TargetOptions &Options,
1110 CodeModel::Model CM,
1111 CodeGenOpt::Level OL) {
1112 return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
1116 /// RegisterMCAsmBackend - Helper template for registering a target specific
1117 /// assembler backend. Usage:
1119 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1120 /// extern Target TheFooTarget;
1121 /// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1123 template<class MCAsmBackendImpl>
1124 struct RegisterMCAsmBackend {
1125 RegisterMCAsmBackend(Target &T) {
1126 TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1130 static MCAsmBackend *Allocator(const Target &T,
1131 const MCRegisterInfo &MRI,
1132 StringRef Triple, StringRef CPU) {
1133 return new MCAsmBackendImpl(T, MRI, Triple, CPU);
1137 /// RegisterMCAsmParser - Helper template for registering a target specific
1138 /// assembly parser, for use in the target machine initialization
1139 /// function. Usage:
1141 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1142 /// extern Target TheFooTarget;
1143 /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1145 template<class MCAsmParserImpl>
1146 struct RegisterMCAsmParser {
1147 RegisterMCAsmParser(Target &T) {
1148 TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1152 static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P,
1153 const MCInstrInfo &MII,
1154 const MCTargetOptions &Options) {
1155 return new MCAsmParserImpl(STI, P, MII, Options);
1159 /// RegisterAsmPrinter - Helper template for registering a target specific
1160 /// assembly printer, for use in the target machine initialization
1161 /// function. Usage:
1163 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1164 /// extern Target TheFooTarget;
1165 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1167 template<class AsmPrinterImpl>
1168 struct RegisterAsmPrinter {
1169 RegisterAsmPrinter(Target &T) {
1170 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1174 static AsmPrinter *Allocator(TargetMachine &TM,
1175 std::unique_ptr<MCStreamer> &&Streamer) {
1176 return new AsmPrinterImpl(TM, std::move(Streamer));
1180 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1181 /// machine code emitter, for use in the target initialization
1182 /// function. Usage:
1184 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1185 /// extern Target TheFooTarget;
1186 /// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1188 template<class MCCodeEmitterImpl>
1189 struct RegisterMCCodeEmitter {
1190 RegisterMCCodeEmitter(Target &T) {
1191 TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1195 static MCCodeEmitter *Allocator(const MCInstrInfo & /*II*/,
1196 const MCRegisterInfo & /*MRI*/,
1197 MCContext & /*Ctx*/) {
1198 return new MCCodeEmitterImpl();