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 formatted_raw_ostream;
55 MCStreamer *createNullStreamer(MCContext &Ctx);
56 MCStreamer *createAsmStreamer(MCContext &Ctx,
57 std::unique_ptr<formatted_raw_ostream> OS,
58 bool isVerboseAsm, bool useDwarfDirectory,
59 MCInstPrinter *InstPrint, MCCodeEmitter *CE,
60 MCAsmBackend *TAB, bool ShowInst);
62 /// Takes ownership of \p TAB and \p CE.
63 MCStreamer *createELFStreamer(MCContext &Ctx, MCAsmBackend &TAB,
64 raw_ostream &OS, MCCodeEmitter *CE,
66 MCStreamer *createMachOStreamer(MCContext &Ctx, MCAsmBackend &TAB,
67 raw_ostream &OS, MCCodeEmitter *CE,
68 bool RelaxAll, bool DWARFMustBeAtTheEnd,
69 bool LabelSections = false);
71 MCRelocationInfo *createMCRelocationInfo(StringRef TT, MCContext &Ctx);
73 MCSymbolizer *createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
74 LLVMSymbolLookupCallback SymbolLookUp,
75 void *DisInfo, MCContext *Ctx,
76 std::unique_ptr<MCRelocationInfo> &&RelInfo);
78 /// Target - Wrapper for Target specific information.
80 /// For registration purposes, this is a POD type so that targets can be
81 /// registered without the use of static constructors.
83 /// Targets should implement a single global instance of this class (which
84 /// will be zero initialized), and pass that instance to the TargetRegistry as
85 /// part of their initialization.
88 friend struct TargetRegistry;
90 typedef bool (*ArchMatchFnTy)(Triple::ArchType Arch);
92 typedef MCAsmInfo *(*MCAsmInfoCtorFnTy)(const MCRegisterInfo &MRI,
94 typedef MCCodeGenInfo *(*MCCodeGenInfoCtorFnTy)(StringRef TT,
97 CodeGenOpt::Level OL);
98 typedef MCInstrInfo *(*MCInstrInfoCtorFnTy)(void);
99 typedef MCInstrAnalysis *(*MCInstrAnalysisCtorFnTy)(const MCInstrInfo*Info);
100 typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(StringRef TT);
101 typedef MCSubtargetInfo *(*MCSubtargetInfoCtorFnTy)(StringRef TT,
104 typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T,
108 const TargetOptions &Options,
111 CodeGenOpt::Level OL);
112 // If it weren't for layering issues (this header is in llvm/Support, but
113 // depends on MC?) this should take the Streamer by value rather than rvalue
115 typedef AsmPrinter *(*AsmPrinterCtorTy)(
116 TargetMachine &TM, std::unique_ptr<MCStreamer> &&Streamer);
117 typedef MCAsmBackend *(*MCAsmBackendCtorTy)(const Target &T,
118 const MCRegisterInfo &MRI,
121 typedef MCTargetAsmParser *(*MCAsmParserCtorTy)(
122 MCSubtargetInfo &STI,
124 const MCInstrInfo &MII,
125 const MCTargetOptions &Options);
126 typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T,
127 const MCSubtargetInfo &STI,
129 typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Triple &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 Triple &T, MCContext &Ctx,
138 MCAsmBackend &TAB, raw_ostream &OS,
139 MCCodeEmitter *Emitter,
141 typedef MCStreamer *(*MachOStreamerCtorTy)(
142 MCContext &Ctx, MCAsmBackend &TAB, raw_ostream &OS,
143 MCCodeEmitter *Emitter, bool RelaxAll, bool DWARFMustBeAtTheEnd);
144 typedef MCStreamer *(*COFFStreamerCtorTy)(MCContext &Ctx, MCAsmBackend &TAB,
146 MCCodeEmitter *Emitter,
148 typedef MCTargetStreamer *(*NullTargetStreamerCtorTy)(MCStreamer &S);
149 typedef MCTargetStreamer *(*AsmTargetStreamerCtorTy)(
150 MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *InstPrint,
152 typedef MCTargetStreamer *(*ObjectTargetStreamerCtorTy)(
153 MCStreamer &S, const MCSubtargetInfo &STI);
154 typedef MCRelocationInfo *(*MCRelocationInfoCtorTy)(StringRef TT,
156 typedef MCSymbolizer *(*MCSymbolizerCtorTy)(
157 StringRef TT, LLVMOpInfoCallback GetOpInfo,
158 LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo, MCContext *Ctx,
159 std::unique_ptr<MCRelocationInfo> &&RelInfo);
162 /// Next - The next registered target in the linked list, maintained by the
166 /// The target function for checking if an architecture is supported.
167 ArchMatchFnTy ArchMatchFn;
169 /// Name - The target name.
172 /// ShortDesc - A short description of the target.
173 const char *ShortDesc;
175 /// HasJIT - Whether this target supports the JIT.
178 /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
180 MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
182 /// MCCodeGenInfoCtorFn - Constructor function for this target's
183 /// MCCodeGenInfo, if registered.
184 MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn;
186 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
188 MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
190 /// MCInstrAnalysisCtorFn - Constructor function for this target's
191 /// MCInstrAnalysis, if registered.
192 MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
194 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
196 MCRegInfoCtorFnTy MCRegInfoCtorFn;
198 /// MCSubtargetInfoCtorFn - Constructor function for this target's
199 /// MCSubtargetInfo, if registered.
200 MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
202 /// TargetMachineCtorFn - Construction function for this target's
203 /// TargetMachine, if registered.
204 TargetMachineCtorTy TargetMachineCtorFn;
206 /// MCAsmBackendCtorFn - Construction function for this target's
207 /// MCAsmBackend, if registered.
208 MCAsmBackendCtorTy MCAsmBackendCtorFn;
210 /// MCAsmParserCtorFn - Construction function for this target's
211 /// MCTargetAsmParser, if registered.
212 MCAsmParserCtorTy MCAsmParserCtorFn;
214 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
216 AsmPrinterCtorTy AsmPrinterCtorFn;
218 /// MCDisassemblerCtorFn - Construction function for this target's
219 /// MCDisassembler, if registered.
220 MCDisassemblerCtorTy MCDisassemblerCtorFn;
222 /// MCInstPrinterCtorFn - Construction function for this target's
223 /// MCInstPrinter, if registered.
224 MCInstPrinterCtorTy MCInstPrinterCtorFn;
226 /// MCCodeEmitterCtorFn - Construction function for this target's
227 /// CodeEmitter, if registered.
228 MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
230 // Construction functions for the various object formats, if registered.
231 COFFStreamerCtorTy COFFStreamerCtorFn;
232 MachOStreamerCtorTy MachOStreamerCtorFn;
233 ELFStreamerCtorTy ELFStreamerCtorFn;
235 /// Construction function for this target's null TargetStreamer, if
236 /// registered (default = nullptr).
237 NullTargetStreamerCtorTy NullTargetStreamerCtorFn;
239 /// Construction function for this target's asm TargetStreamer, if
240 /// registered (default = nullptr).
241 AsmTargetStreamerCtorTy AsmTargetStreamerCtorFn;
243 /// Construction function for this target's obj TargetStreamer, if
244 /// registered (default = nullptr).
245 ObjectTargetStreamerCtorTy ObjectTargetStreamerCtorFn;
247 /// MCRelocationInfoCtorFn - Construction function for this target's
248 /// MCRelocationInfo, if registered (default = llvm::createMCRelocationInfo)
249 MCRelocationInfoCtorTy MCRelocationInfoCtorFn;
251 /// MCSymbolizerCtorFn - Construction function for this target's
252 /// MCSymbolizer, if registered (default = llvm::createMCSymbolizer)
253 MCSymbolizerCtorTy MCSymbolizerCtorFn;
257 : COFFStreamerCtorFn(nullptr), MachOStreamerCtorFn(nullptr),
258 ELFStreamerCtorFn(nullptr), NullTargetStreamerCtorFn(nullptr),
259 AsmTargetStreamerCtorFn(nullptr), ObjectTargetStreamerCtorFn(nullptr),
260 MCRelocationInfoCtorFn(nullptr), MCSymbolizerCtorFn(nullptr) {}
262 /// @name Target Information
265 // getNext - Return the next registered target.
266 const Target *getNext() const { return Next; }
268 /// getName - Get the target name.
269 const char *getName() const { return Name; }
271 /// getShortDescription - Get a short description of the target.
272 const char *getShortDescription() const { return ShortDesc; }
275 /// @name Feature Predicates
278 /// hasJIT - Check if this targets supports the just-in-time compilation.
279 bool hasJIT() const { return HasJIT; }
281 /// hasTargetMachine - Check if this target supports code generation.
282 bool hasTargetMachine() const { return TargetMachineCtorFn != nullptr; }
284 /// hasMCAsmBackend - Check if this target supports .o generation.
285 bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != nullptr; }
288 /// @name Feature Constructors
291 /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
294 /// \param Triple This argument is used to determine the target machine
295 /// feature set; it should always be provided. Generally this should be
296 /// either the target triple from the module, or the target triple of the
297 /// host if that does not exist.
298 MCAsmInfo *createMCAsmInfo(const MCRegisterInfo &MRI,
299 StringRef Triple) const {
300 if (!MCAsmInfoCtorFn)
302 return MCAsmInfoCtorFn(MRI, Triple);
305 /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
307 MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model RM,
309 CodeGenOpt::Level OL) const {
310 if (!MCCodeGenInfoCtorFn)
312 return MCCodeGenInfoCtorFn(Triple, RM, CM, OL);
315 /// createMCInstrInfo - Create a MCInstrInfo implementation.
317 MCInstrInfo *createMCInstrInfo() const {
318 if (!MCInstrInfoCtorFn)
320 return MCInstrInfoCtorFn();
323 /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
325 MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
326 if (!MCInstrAnalysisCtorFn)
328 return MCInstrAnalysisCtorFn(Info);
331 /// createMCRegInfo - Create a MCRegisterInfo implementation.
333 MCRegisterInfo *createMCRegInfo(StringRef Triple) const {
334 if (!MCRegInfoCtorFn)
336 return MCRegInfoCtorFn(Triple);
339 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
341 /// \param Triple This argument is used to determine the target machine
342 /// feature set; it should always be provided. Generally this should be
343 /// either the target triple from the module, or the target triple of the
344 /// host if that does not exist.
345 /// \param CPU This specifies the name of the target CPU.
346 /// \param Features This specifies the string representation of the
347 /// additional target features.
348 MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU,
349 StringRef Features) const {
350 if (!MCSubtargetInfoCtorFn)
352 return MCSubtargetInfoCtorFn(Triple, CPU, Features);
355 /// createTargetMachine - Create a target specific machine implementation
356 /// for the specified \p Triple.
358 /// \param Triple This argument is used to determine the target machine
359 /// feature set; it should always be provided. Generally this should be
360 /// either the target triple from the module, or the target triple of the
361 /// host if that does not exist.
362 TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU,
363 StringRef Features, const TargetOptions &Options,
364 Reloc::Model RM = Reloc::Default,
365 CodeModel::Model CM = CodeModel::Default,
366 CodeGenOpt::Level OL = CodeGenOpt::Default) const {
367 if (!TargetMachineCtorFn)
369 return TargetMachineCtorFn(*this, Triple, CPU, Features, Options,
373 /// createMCAsmBackend - Create a target specific assembly parser.
375 /// \param Triple The target triple string.
376 MCAsmBackend *createMCAsmBackend(const MCRegisterInfo &MRI,
377 StringRef Triple, StringRef CPU) const {
378 if (!MCAsmBackendCtorFn)
380 return MCAsmBackendCtorFn(*this, MRI, Triple, CPU);
383 /// createMCAsmParser - Create a target specific assembly parser.
385 /// \param Parser The target independent parser implementation to use for
386 /// parsing and lexing.
387 MCTargetAsmParser *createMCAsmParser(
388 MCSubtargetInfo &STI,
390 const MCInstrInfo &MII,
391 const MCTargetOptions &Options) const {
392 if (!MCAsmParserCtorFn)
394 return MCAsmParserCtorFn(STI, Parser, MII, Options);
397 /// createAsmPrinter - Create a target specific assembly printer pass. This
398 /// takes ownership of the MCStreamer object.
399 AsmPrinter *createAsmPrinter(TargetMachine &TM,
400 std::unique_ptr<MCStreamer> &&Streamer) const {
401 if (!AsmPrinterCtorFn)
403 return AsmPrinterCtorFn(TM, std::move(Streamer));
406 MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI,
407 MCContext &Ctx) const {
408 if (!MCDisassemblerCtorFn)
410 return MCDisassemblerCtorFn(*this, STI, Ctx);
413 MCInstPrinter *createMCInstPrinter(const Triple &T, unsigned SyntaxVariant,
414 const MCAsmInfo &MAI,
415 const MCInstrInfo &MII,
416 const MCRegisterInfo &MRI) const {
417 if (!MCInstPrinterCtorFn)
419 return MCInstPrinterCtorFn(T, SyntaxVariant, MAI, MII, MRI);
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,
475 std::unique_ptr<formatted_raw_ostream> OS,
476 bool IsVerboseAsm, bool UseDwarfDirectory,
477 MCInstPrinter *InstPrint, MCCodeEmitter *CE,
478 MCAsmBackend *TAB, bool ShowInst) const {
479 formatted_raw_ostream &OSRef = *OS;
480 MCStreamer *S = llvm::createAsmStreamer(Ctx, std::move(OS), IsVerboseAsm,
481 UseDwarfDirectory, InstPrint, CE,
483 createAsmTargetStreamer(*S, OSRef, InstPrint, IsVerboseAsm);
487 MCTargetStreamer *createAsmTargetStreamer(MCStreamer &S,
488 formatted_raw_ostream &OS,
489 MCInstPrinter *InstPrint,
490 bool IsVerboseAsm) const {
491 if (AsmTargetStreamerCtorFn)
492 return AsmTargetStreamerCtorFn(S, OS, InstPrint, IsVerboseAsm);
496 MCStreamer *createNullStreamer(MCContext &Ctx) const {
497 MCStreamer *S = llvm::createNullStreamer(Ctx);
498 createNullTargetStreamer(*S);
502 MCTargetStreamer *createNullTargetStreamer(MCStreamer &S) const {
503 if (NullTargetStreamerCtorFn)
504 return NullTargetStreamerCtorFn(S);
508 /// createMCRelocationInfo - Create a target specific MCRelocationInfo.
510 /// \param TT The target triple.
511 /// \param Ctx The target context.
513 createMCRelocationInfo(StringRef TT, MCContext &Ctx) const {
514 MCRelocationInfoCtorTy Fn = MCRelocationInfoCtorFn
515 ? MCRelocationInfoCtorFn
516 : llvm::createMCRelocationInfo;
520 /// createMCSymbolizer - Create a target specific MCSymbolizer.
522 /// \param TT The target triple.
523 /// \param GetOpInfo The function to get the symbolic information for operands.
524 /// \param SymbolLookUp The function to lookup a symbol name.
525 /// \param DisInfo The pointer to the block of symbolic information for above call
527 /// \param Ctx The target context.
528 /// \param RelInfo The relocation information for this target. Takes ownership.
530 createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
531 LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo,
533 std::unique_ptr<MCRelocationInfo> &&RelInfo) const {
534 MCSymbolizerCtorTy Fn =
535 MCSymbolizerCtorFn ? MCSymbolizerCtorFn : llvm::createMCSymbolizer;
536 return Fn(TT, GetOpInfo, SymbolLookUp, DisInfo, Ctx, std::move(RelInfo));
542 /// TargetRegistry - Generic interface to target specific features.
543 struct TargetRegistry {
545 const Target *Current;
546 explicit iterator(Target *T) : Current(T) {}
547 friend struct TargetRegistry;
549 iterator() : Current(nullptr) {}
551 bool operator==(const iterator &x) const {
552 return Current == x.Current;
554 bool operator!=(const iterator &x) const {
555 return !operator==(x);
558 // Iterator traversal: forward iteration only
559 iterator &operator++() { // Preincrement
560 assert(Current && "Cannot increment end iterator!");
561 Current = Current->getNext();
564 iterator operator++(int) { // Postincrement
565 iterator tmp = *this;
570 const Target &operator*() const {
571 assert(Current && "Cannot dereference end iterator!");
575 const Target *operator->() const {
580 /// printRegisteredTargetsForVersion - Print the registered targets
581 /// appropriately for inclusion in a tool's version output.
582 static void printRegisteredTargetsForVersion();
584 /// @name Registry Access
587 static iterator begin();
589 static iterator end() { return iterator(); }
591 /// lookupTarget - Lookup a target based on a target triple.
593 /// \param Triple - The triple to use for finding a target.
594 /// \param Error - On failure, an error string describing why no target was
596 static const Target *lookupTarget(const std::string &Triple,
599 /// lookupTarget - Lookup a target based on an architecture name
600 /// and a target triple. If the architecture name is non-empty,
601 /// then the lookup is done by architecture. Otherwise, the target
604 /// \param ArchName - The architecture to use for finding a target.
605 /// \param TheTriple - The triple to use for finding a target. The
606 /// triple is updated with canonical architecture name if a lookup
607 /// by architecture is done.
608 /// \param Error - On failure, an error string describing why no target was
610 static const Target *lookupTarget(const std::string &ArchName,
615 /// @name Target Registration
618 /// RegisterTarget - Register the given target. Attempts to register a
619 /// target which has already been registered will be ignored.
621 /// Clients are responsible for ensuring that registration doesn't occur
622 /// while another thread is attempting to access the registry. Typically
623 /// this is done by initializing all targets at program startup.
625 /// @param T - The target being registered.
626 /// @param Name - The target name. This should be a static string.
627 /// @param ShortDesc - A short target description. This should be a static
629 /// @param ArchMatchFn - The arch match checking function for this target.
630 /// @param HasJIT - Whether the target supports JIT code
632 static void RegisterTarget(Target &T,
634 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,
722 Target::TargetMachineCtorTy Fn) {
723 T.TargetMachineCtorFn = Fn;
726 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
729 /// Clients are responsible for ensuring that registration doesn't occur
730 /// while another thread is attempting to access the registry. Typically
731 /// this is done by initializing all targets at program startup.
733 /// @param T - The target being registered.
734 /// @param Fn - A function to construct an AsmBackend for the target.
735 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
736 T.MCAsmBackendCtorFn = Fn;
739 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
740 /// the given target.
742 /// Clients are responsible for ensuring that registration doesn't occur
743 /// while another thread is attempting to access the registry. Typically
744 /// this is done by initializing all targets at program startup.
746 /// @param T - The target being registered.
747 /// @param Fn - A function to construct an MCTargetAsmParser for the target.
748 static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
749 T.MCAsmParserCtorFn = Fn;
752 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
755 /// Clients are responsible for ensuring that registration doesn't occur
756 /// while another thread is attempting to access the registry. Typically
757 /// this is done by initializing all targets at program startup.
759 /// @param T - The target being registered.
760 /// @param Fn - A function to construct an AsmPrinter for the target.
761 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
762 T.AsmPrinterCtorFn = Fn;
765 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
766 /// the given target.
768 /// Clients are responsible for ensuring that registration doesn't occur
769 /// while another thread is attempting to access the registry. Typically
770 /// this is done by initializing all targets at program startup.
772 /// @param T - The target being registered.
773 /// @param Fn - A function to construct an MCDisassembler for the target.
774 static void RegisterMCDisassembler(Target &T,
775 Target::MCDisassemblerCtorTy Fn) {
776 T.MCDisassemblerCtorFn = Fn;
779 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
782 /// Clients are responsible for ensuring that registration doesn't occur
783 /// while another thread is attempting to access the registry. Typically
784 /// this is done by initializing all targets at program startup.
786 /// @param T - The target being registered.
787 /// @param Fn - A function to construct an MCInstPrinter for the target.
788 static void RegisterMCInstPrinter(Target &T,
789 Target::MCInstPrinterCtorTy Fn) {
790 T.MCInstPrinterCtorFn = Fn;
793 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
796 /// Clients are responsible for ensuring that registration doesn't occur
797 /// while another thread is attempting to access the registry. Typically
798 /// this is done by initializing all targets at program startup.
800 /// @param T - The target being registered.
801 /// @param Fn - A function to construct an MCCodeEmitter for the target.
802 static void RegisterMCCodeEmitter(Target &T,
803 Target::MCCodeEmitterCtorTy Fn) {
804 T.MCCodeEmitterCtorFn = Fn;
807 static void RegisterCOFFStreamer(Target &T, Target::COFFStreamerCtorTy Fn) {
808 T.COFFStreamerCtorFn = Fn;
811 static void RegisterMachOStreamer(Target &T,
812 Target::MachOStreamerCtorTy Fn) {
813 T.MachOStreamerCtorFn = Fn;
816 static void RegisterELFStreamer(Target &T, Target::ELFStreamerCtorTy Fn) {
817 T.ELFStreamerCtorFn = Fn;
821 RegisterNullTargetStreamer(Target &T, Target::NullTargetStreamerCtorTy Fn) {
822 T.NullTargetStreamerCtorFn = Fn;
825 static void RegisterAsmTargetStreamer(Target &T,
826 Target::AsmTargetStreamerCtorTy Fn) {
827 T.AsmTargetStreamerCtorFn = Fn;
831 RegisterObjectTargetStreamer(Target &T,
832 Target::ObjectTargetStreamerCtorTy Fn) {
833 T.ObjectTargetStreamerCtorFn = Fn;
836 /// RegisterMCRelocationInfo - Register an MCRelocationInfo
837 /// implementation for the given target.
839 /// Clients are responsible for ensuring that registration doesn't occur
840 /// while another thread is attempting to access the registry. Typically
841 /// this is done by initializing all targets at program startup.
843 /// @param T - The target being registered.
844 /// @param Fn - A function to construct an MCRelocationInfo for the target.
845 static void RegisterMCRelocationInfo(Target &T,
846 Target::MCRelocationInfoCtorTy Fn) {
847 T.MCRelocationInfoCtorFn = Fn;
850 /// RegisterMCSymbolizer - Register an MCSymbolizer
851 /// implementation for the given target.
853 /// Clients are responsible for ensuring that registration doesn't occur
854 /// while another thread is attempting to access the registry. Typically
855 /// this is done by initializing all targets at program startup.
857 /// @param T - The target being registered.
858 /// @param Fn - A function to construct an MCSymbolizer for the target.
859 static void RegisterMCSymbolizer(Target &T,
860 Target::MCSymbolizerCtorTy Fn) {
861 T.MCSymbolizerCtorFn = Fn;
868 //===--------------------------------------------------------------------===//
870 /// RegisterTarget - Helper template for registering a target, for use in the
871 /// target's initialization function. Usage:
874 /// Target TheFooTarget; // The global target instance.
876 /// extern "C" void LLVMInitializeFooTargetInfo() {
877 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
879 template<Triple::ArchType TargetArchType = Triple::UnknownArch,
881 struct RegisterTarget {
882 RegisterTarget(Target &T, const char *Name, const char *Desc) {
883 TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch, HasJIT);
886 static bool getArchMatch(Triple::ArchType Arch) {
887 return Arch == TargetArchType;
891 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
892 /// implementation. This invokes the static "Create" method on the class to
893 /// actually do the construction. Usage:
895 /// extern "C" void LLVMInitializeFooTarget() {
896 /// extern Target TheFooTarget;
897 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
899 template<class MCAsmInfoImpl>
900 struct RegisterMCAsmInfo {
901 RegisterMCAsmInfo(Target &T) {
902 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
905 static MCAsmInfo *Allocator(const MCRegisterInfo &/*MRI*/, StringRef TT) {
906 return new MCAsmInfoImpl(TT);
911 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
912 /// implementation. This invokes the specified function to do the
913 /// construction. Usage:
915 /// extern "C" void LLVMInitializeFooTarget() {
916 /// extern Target TheFooTarget;
917 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
919 struct RegisterMCAsmInfoFn {
920 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
921 TargetRegistry::RegisterMCAsmInfo(T, Fn);
925 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
926 /// implementation. This invokes the static "Create" method on the class
927 /// to actually do the construction. Usage:
929 /// extern "C" void LLVMInitializeFooTarget() {
930 /// extern Target TheFooTarget;
931 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
933 template<class MCCodeGenInfoImpl>
934 struct RegisterMCCodeGenInfo {
935 RegisterMCCodeGenInfo(Target &T) {
936 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
939 static MCCodeGenInfo *Allocator(StringRef /*TT*/, Reloc::Model /*RM*/,
940 CodeModel::Model /*CM*/,
941 CodeGenOpt::Level /*OL*/) {
942 return new MCCodeGenInfoImpl();
946 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
947 /// info implementation. This invokes the specified function to do the
948 /// construction. Usage:
950 /// extern "C" void LLVMInitializeFooTarget() {
951 /// extern Target TheFooTarget;
952 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
954 struct RegisterMCCodeGenInfoFn {
955 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
956 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
960 /// RegisterMCInstrInfo - Helper template for registering a target instruction
961 /// info implementation. This invokes the static "Create" method on the class
962 /// to actually do the construction. Usage:
964 /// extern "C" void LLVMInitializeFooTarget() {
965 /// extern Target TheFooTarget;
966 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
968 template<class MCInstrInfoImpl>
969 struct RegisterMCInstrInfo {
970 RegisterMCInstrInfo(Target &T) {
971 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
974 static MCInstrInfo *Allocator() {
975 return new MCInstrInfoImpl();
979 /// RegisterMCInstrInfoFn - Helper template for registering a target
980 /// instruction info implementation. This invokes the specified function to
981 /// do the construction. Usage:
983 /// extern "C" void LLVMInitializeFooTarget() {
984 /// extern Target TheFooTarget;
985 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
987 struct RegisterMCInstrInfoFn {
988 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
989 TargetRegistry::RegisterMCInstrInfo(T, Fn);
993 /// RegisterMCInstrAnalysis - Helper template for registering a target
994 /// instruction analyzer implementation. This invokes the static "Create"
995 /// method on the class to actually do the construction. Usage:
997 /// extern "C" void LLVMInitializeFooTarget() {
998 /// extern Target TheFooTarget;
999 /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
1001 template<class MCInstrAnalysisImpl>
1002 struct RegisterMCInstrAnalysis {
1003 RegisterMCInstrAnalysis(Target &T) {
1004 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
1007 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
1008 return new MCInstrAnalysisImpl(Info);
1012 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
1013 /// instruction analyzer implementation. This invokes the specified function
1014 /// to do the construction. Usage:
1016 /// extern "C" void LLVMInitializeFooTarget() {
1017 /// extern Target TheFooTarget;
1018 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
1020 struct RegisterMCInstrAnalysisFn {
1021 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
1022 TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
1026 /// RegisterMCRegInfo - Helper template for registering a target register info
1027 /// implementation. This invokes the static "Create" method on the class to
1028 /// actually do the construction. Usage:
1030 /// extern "C" void LLVMInitializeFooTarget() {
1031 /// extern Target TheFooTarget;
1032 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
1034 template<class MCRegisterInfoImpl>
1035 struct RegisterMCRegInfo {
1036 RegisterMCRegInfo(Target &T) {
1037 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
1040 static MCRegisterInfo *Allocator(StringRef /*TT*/) {
1041 return new MCRegisterInfoImpl();
1045 /// RegisterMCRegInfoFn - Helper template for registering a target register
1046 /// info implementation. This invokes the specified function to do the
1047 /// construction. Usage:
1049 /// extern "C" void LLVMInitializeFooTarget() {
1050 /// extern Target TheFooTarget;
1051 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
1053 struct RegisterMCRegInfoFn {
1054 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
1055 TargetRegistry::RegisterMCRegInfo(T, Fn);
1059 /// RegisterMCSubtargetInfo - Helper template for registering a target
1060 /// subtarget info implementation. This invokes the static "Create" method
1061 /// on the class to actually do the construction. Usage:
1063 /// extern "C" void LLVMInitializeFooTarget() {
1064 /// extern Target TheFooTarget;
1065 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
1067 template<class MCSubtargetInfoImpl>
1068 struct RegisterMCSubtargetInfo {
1069 RegisterMCSubtargetInfo(Target &T) {
1070 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
1073 static MCSubtargetInfo *Allocator(StringRef /*TT*/, StringRef /*CPU*/,
1075 return new MCSubtargetInfoImpl();
1079 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
1080 /// subtarget info implementation. This invokes the specified function to
1081 /// do the construction. Usage:
1083 /// extern "C" void LLVMInitializeFooTarget() {
1084 /// extern Target TheFooTarget;
1085 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1087 struct RegisterMCSubtargetInfoFn {
1088 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
1089 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
1093 /// RegisterTargetMachine - Helper template for registering a target machine
1094 /// implementation, for use in the target machine initialization
1095 /// function. Usage:
1097 /// extern "C" void LLVMInitializeFooTarget() {
1098 /// extern Target TheFooTarget;
1099 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1101 template<class TargetMachineImpl>
1102 struct RegisterTargetMachine {
1103 RegisterTargetMachine(Target &T) {
1104 TargetRegistry::RegisterTargetMachine(T, &Allocator);
1108 static TargetMachine *Allocator(const Target &T, StringRef TT,
1109 StringRef CPU, StringRef FS,
1110 const TargetOptions &Options,
1112 CodeModel::Model CM,
1113 CodeGenOpt::Level OL) {
1114 return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
1118 /// RegisterMCAsmBackend - Helper template for registering a target specific
1119 /// assembler backend. Usage:
1121 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1122 /// extern Target TheFooTarget;
1123 /// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1125 template<class MCAsmBackendImpl>
1126 struct RegisterMCAsmBackend {
1127 RegisterMCAsmBackend(Target &T) {
1128 TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1132 static MCAsmBackend *Allocator(const Target &T,
1133 const MCRegisterInfo &MRI,
1134 StringRef Triple, StringRef CPU) {
1135 return new MCAsmBackendImpl(T, MRI, Triple, CPU);
1139 /// RegisterMCAsmParser - Helper template for registering a target specific
1140 /// assembly parser, for use in the target machine initialization
1141 /// function. Usage:
1143 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1144 /// extern Target TheFooTarget;
1145 /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1147 template<class MCAsmParserImpl>
1148 struct RegisterMCAsmParser {
1149 RegisterMCAsmParser(Target &T) {
1150 TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1154 static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P,
1155 const MCInstrInfo &MII,
1156 const MCTargetOptions &Options) {
1157 return new MCAsmParserImpl(STI, P, MII, Options);
1161 /// RegisterAsmPrinter - Helper template for registering a target specific
1162 /// assembly printer, for use in the target machine initialization
1163 /// function. Usage:
1165 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1166 /// extern Target TheFooTarget;
1167 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1169 template<class AsmPrinterImpl>
1170 struct RegisterAsmPrinter {
1171 RegisterAsmPrinter(Target &T) {
1172 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1176 static AsmPrinter *Allocator(TargetMachine &TM,
1177 std::unique_ptr<MCStreamer> &&Streamer) {
1178 return new AsmPrinterImpl(TM, std::move(Streamer));
1182 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1183 /// machine code emitter, for use in the target initialization
1184 /// function. Usage:
1186 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1187 /// extern Target TheFooTarget;
1188 /// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1190 template<class MCCodeEmitterImpl>
1191 struct RegisterMCCodeEmitter {
1192 RegisterMCCodeEmitter(Target &T) {
1193 TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1197 static MCCodeEmitter *Allocator(const MCInstrInfo & /*II*/,
1198 const MCRegisterInfo & /*MRI*/,
1199 MCContext & /*Ctx*/) {
1200 return new MCCodeEmitterImpl();