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(const Triple &TT, MCContext &Ctx);
74 MCSymbolizer *createMCSymbolizer(const Triple &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)(const Triple &TT,
98 CodeGenOpt::Level OL);
99 typedef MCInstrInfo *(*MCInstrInfoCtorFnTy)(void);
100 typedef MCInstrAnalysis *(*MCInstrAnalysisCtorFnTy)(const MCInstrInfo *Info);
101 typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(const Triple &TT);
102 typedef MCSubtargetInfo *(*MCSubtargetInfoCtorFnTy)(const Triple &TT,
105 typedef TargetMachine *(*TargetMachineCtorTy)(
106 const Target &T, const Triple &TT, StringRef CPU, StringRef Features,
107 const TargetOptions &Options, Reloc::Model RM, CodeModel::Model CM,
108 CodeGenOpt::Level OL);
109 // If it weren't for layering issues (this header is in llvm/Support, but
110 // depends on MC?) this should take the Streamer by value rather than rvalue
112 typedef AsmPrinter *(*AsmPrinterCtorTy)(
113 TargetMachine &TM, std::unique_ptr<MCStreamer> &&Streamer);
114 typedef MCAsmBackend *(*MCAsmBackendCtorTy)(const Target &T,
115 const MCRegisterInfo &MRI,
116 const Triple &TT, StringRef CPU);
117 typedef MCTargetAsmParser *(*MCAsmParserCtorTy)(
118 MCSubtargetInfo &STI, MCAsmParser &P, const MCInstrInfo &MII,
119 const MCTargetOptions &Options);
120 typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T,
121 const MCSubtargetInfo &STI,
123 typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Triple &T,
124 unsigned SyntaxVariant,
125 const MCAsmInfo &MAI,
126 const MCInstrInfo &MII,
127 const MCRegisterInfo &MRI);
128 typedef MCCodeEmitter *(*MCCodeEmitterCtorTy)(const MCInstrInfo &II,
129 const MCRegisterInfo &MRI,
131 typedef MCStreamer *(*ELFStreamerCtorTy)(const Triple &T, MCContext &Ctx,
133 raw_pwrite_stream &OS,
134 MCCodeEmitter *Emitter,
136 typedef MCStreamer *(*MachOStreamerCtorTy)(MCContext &Ctx, MCAsmBackend &TAB,
137 raw_pwrite_stream &OS,
138 MCCodeEmitter *Emitter,
140 bool DWARFMustBeAtTheEnd);
141 typedef MCStreamer *(*COFFStreamerCtorTy)(MCContext &Ctx, MCAsmBackend &TAB,
142 raw_pwrite_stream &OS,
143 MCCodeEmitter *Emitter,
145 typedef MCTargetStreamer *(*NullTargetStreamerCtorTy)(MCStreamer &S);
146 typedef MCTargetStreamer *(*AsmTargetStreamerCtorTy)(
147 MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *InstPrint,
149 typedef MCTargetStreamer *(*ObjectTargetStreamerCtorTy)(
150 MCStreamer &S, const MCSubtargetInfo &STI);
151 typedef MCRelocationInfo *(*MCRelocationInfoCtorTy)(const Triple &TT,
153 typedef MCSymbolizer *(*MCSymbolizerCtorTy)(
154 const Triple &TT, LLVMOpInfoCallback GetOpInfo,
155 LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo, MCContext *Ctx,
156 std::unique_ptr<MCRelocationInfo> &&RelInfo);
159 /// Next - The next registered target in the linked list, maintained by the
163 /// The target function for checking if an architecture is supported.
164 ArchMatchFnTy ArchMatchFn;
166 /// Name - The target name.
169 /// ShortDesc - A short description of the target.
170 const char *ShortDesc;
172 /// HasJIT - Whether this target supports the JIT.
175 /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
177 MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
179 /// MCCodeGenInfoCtorFn - Constructor function for this target's
180 /// MCCodeGenInfo, if registered.
181 MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn;
183 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
185 MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
187 /// MCInstrAnalysisCtorFn - Constructor function for this target's
188 /// MCInstrAnalysis, if registered.
189 MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
191 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
193 MCRegInfoCtorFnTy MCRegInfoCtorFn;
195 /// MCSubtargetInfoCtorFn - Constructor function for this target's
196 /// MCSubtargetInfo, if registered.
197 MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
199 /// TargetMachineCtorFn - Construction function for this target's
200 /// TargetMachine, if registered.
201 TargetMachineCtorTy TargetMachineCtorFn;
203 /// MCAsmBackendCtorFn - Construction function for this target's
204 /// MCAsmBackend, if registered.
205 MCAsmBackendCtorTy MCAsmBackendCtorFn;
207 /// MCAsmParserCtorFn - Construction function for this target's
208 /// MCTargetAsmParser, if registered.
209 MCAsmParserCtorTy MCAsmParserCtorFn;
211 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
213 AsmPrinterCtorTy AsmPrinterCtorFn;
215 /// MCDisassemblerCtorFn - Construction function for this target's
216 /// MCDisassembler, if registered.
217 MCDisassemblerCtorTy MCDisassemblerCtorFn;
219 /// MCInstPrinterCtorFn - Construction function for this target's
220 /// MCInstPrinter, if registered.
221 MCInstPrinterCtorTy MCInstPrinterCtorFn;
223 /// MCCodeEmitterCtorFn - Construction function for this target's
224 /// CodeEmitter, if registered.
225 MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
227 // Construction functions for the various object formats, if registered.
228 COFFStreamerCtorTy COFFStreamerCtorFn;
229 MachOStreamerCtorTy MachOStreamerCtorFn;
230 ELFStreamerCtorTy ELFStreamerCtorFn;
232 /// Construction function for this target's null TargetStreamer, if
233 /// registered (default = nullptr).
234 NullTargetStreamerCtorTy NullTargetStreamerCtorFn;
236 /// Construction function for this target's asm TargetStreamer, if
237 /// registered (default = nullptr).
238 AsmTargetStreamerCtorTy AsmTargetStreamerCtorFn;
240 /// Construction function for this target's obj TargetStreamer, if
241 /// registered (default = nullptr).
242 ObjectTargetStreamerCtorTy ObjectTargetStreamerCtorFn;
244 /// MCRelocationInfoCtorFn - Construction function for this target's
245 /// MCRelocationInfo, if registered (default = llvm::createMCRelocationInfo)
246 MCRelocationInfoCtorTy MCRelocationInfoCtorFn;
248 /// MCSymbolizerCtorFn - Construction function for this target's
249 /// MCSymbolizer, if registered (default = llvm::createMCSymbolizer)
250 MCSymbolizerCtorTy MCSymbolizerCtorFn;
254 : COFFStreamerCtorFn(nullptr), MachOStreamerCtorFn(nullptr),
255 ELFStreamerCtorFn(nullptr), NullTargetStreamerCtorFn(nullptr),
256 AsmTargetStreamerCtorFn(nullptr), ObjectTargetStreamerCtorFn(nullptr),
257 MCRelocationInfoCtorFn(nullptr), MCSymbolizerCtorFn(nullptr) {}
259 /// @name Target Information
262 // getNext - Return the next registered target.
263 const Target *getNext() const { return Next; }
265 /// getName - Get the target name.
266 const char *getName() const { return Name; }
268 /// getShortDescription - Get a short description of the target.
269 const char *getShortDescription() const { return ShortDesc; }
272 /// @name Feature Predicates
275 /// hasJIT - Check if this targets supports the just-in-time compilation.
276 bool hasJIT() const { return HasJIT; }
278 /// hasTargetMachine - Check if this target supports code generation.
279 bool hasTargetMachine() const { return TargetMachineCtorFn != nullptr; }
281 /// hasMCAsmBackend - Check if this target supports .o generation.
282 bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != nullptr; }
285 /// @name Feature Constructors
288 /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
291 /// \param TheTriple This argument is used to determine the target machine
292 /// feature set; it should always be provided. Generally this should be
293 /// either the target triple from the module, or the target triple of the
294 /// host if that does not exist.
295 MCAsmInfo *createMCAsmInfo(const MCRegisterInfo &MRI,
296 StringRef TheTriple) const {
297 if (!MCAsmInfoCtorFn)
299 return MCAsmInfoCtorFn(MRI, Triple(TheTriple));
302 /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
304 MCCodeGenInfo *createMCCodeGenInfo(StringRef TT, Reloc::Model RM,
306 CodeGenOpt::Level OL) const {
307 if (!MCCodeGenInfoCtorFn)
309 return MCCodeGenInfoCtorFn(Triple(TT), RM, CM, OL);
312 /// createMCInstrInfo - Create a MCInstrInfo implementation.
314 MCInstrInfo *createMCInstrInfo() const {
315 if (!MCInstrInfoCtorFn)
317 return MCInstrInfoCtorFn();
320 /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
322 MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
323 if (!MCInstrAnalysisCtorFn)
325 return MCInstrAnalysisCtorFn(Info);
328 /// createMCRegInfo - Create a MCRegisterInfo implementation.
330 MCRegisterInfo *createMCRegInfo(StringRef TT) const {
331 if (!MCRegInfoCtorFn)
333 return MCRegInfoCtorFn(Triple(TT));
336 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
338 /// \param TheTriple This argument is used to determine the target machine
339 /// feature set; it should always be provided. Generally this should be
340 /// either the target triple from the module, or the target triple of the
341 /// host if that does not exist.
342 /// \param CPU This specifies the name of the target CPU.
343 /// \param Features This specifies the string representation of the
344 /// additional target features.
345 MCSubtargetInfo *createMCSubtargetInfo(StringRef TheTriple, StringRef CPU,
346 StringRef Features) const {
347 if (!MCSubtargetInfoCtorFn)
349 return MCSubtargetInfoCtorFn(Triple(TheTriple), CPU, Features);
352 /// createTargetMachine - Create a target specific machine implementation
353 /// for the specified \p Triple.
355 /// \param TT This argument is used to determine the target machine
356 /// feature set; it should always be provided. Generally this should be
357 /// either the target triple from the module, or the target triple of the
358 /// host if that does not exist.
360 createTargetMachine(StringRef TT, StringRef CPU, StringRef Features,
361 const TargetOptions &Options,
362 Reloc::Model RM = Reloc::Default,
363 CodeModel::Model CM = CodeModel::Default,
364 CodeGenOpt::Level OL = CodeGenOpt::Default) const {
365 if (!TargetMachineCtorFn)
367 return TargetMachineCtorFn(*this, Triple(TT), CPU, Features, Options, RM,
371 /// createMCAsmBackend - Create a target specific assembly parser.
373 /// \param TheTriple The target triple string.
374 MCAsmBackend *createMCAsmBackend(const MCRegisterInfo &MRI,
375 StringRef TheTriple, StringRef CPU) const {
376 if (!MCAsmBackendCtorFn)
378 return MCAsmBackendCtorFn(*this, MRI, Triple(TheTriple), CPU);
381 /// createMCAsmParser - Create a target specific assembly parser.
383 /// \param Parser The target independent parser implementation to use for
384 /// parsing and lexing.
385 MCTargetAsmParser *createMCAsmParser(MCSubtargetInfo &STI,
387 const MCInstrInfo &MII,
388 const MCTargetOptions &Options) const {
389 if (!MCAsmParserCtorFn)
391 return MCAsmParserCtorFn(STI, Parser, MII, Options);
394 /// createAsmPrinter - Create a target specific assembly printer pass. This
395 /// takes ownership of the MCStreamer object.
396 AsmPrinter *createAsmPrinter(TargetMachine &TM,
397 std::unique_ptr<MCStreamer> &&Streamer) const {
398 if (!AsmPrinterCtorFn)
400 return AsmPrinterCtorFn(TM, std::move(Streamer));
403 MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI,
404 MCContext &Ctx) const {
405 if (!MCDisassemblerCtorFn)
407 return MCDisassemblerCtorFn(*this, STI, Ctx);
410 MCInstPrinter *createMCInstPrinter(const Triple &T, unsigned SyntaxVariant,
411 const MCAsmInfo &MAI,
412 const MCInstrInfo &MII,
413 const MCRegisterInfo &MRI) const {
414 if (!MCInstPrinterCtorFn)
416 return MCInstPrinterCtorFn(T, SyntaxVariant, MAI, MII, MRI);
419 /// createMCCodeEmitter - Create a target specific code emitter.
420 MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
421 const MCRegisterInfo &MRI,
422 MCContext &Ctx) const {
423 if (!MCCodeEmitterCtorFn)
425 return MCCodeEmitterCtorFn(II, MRI, Ctx);
428 /// Create a target specific MCStreamer.
430 /// \param T The target triple.
431 /// \param Ctx The target context.
432 /// \param TAB The target assembler backend object. Takes ownership.
433 /// \param OS The stream object.
434 /// \param Emitter The target independent assembler object.Takes ownership.
435 /// \param RelaxAll Relax all fixups?
436 MCStreamer *createMCObjectStreamer(const Triple &T, MCContext &Ctx,
437 MCAsmBackend &TAB, raw_pwrite_stream &OS,
438 MCCodeEmitter *Emitter,
439 const MCSubtargetInfo &STI, bool RelaxAll,
440 bool DWARFMustBeAtTheEnd) const {
442 switch (T.getObjectFormat()) {
444 llvm_unreachable("Unknown object format");
446 assert(T.isOSWindows() && "only Windows COFF is supported");
447 S = COFFStreamerCtorFn(Ctx, TAB, OS, Emitter, RelaxAll);
450 if (MachOStreamerCtorFn)
451 S = MachOStreamerCtorFn(Ctx, TAB, OS, Emitter, RelaxAll,
452 DWARFMustBeAtTheEnd);
454 S = createMachOStreamer(Ctx, TAB, OS, Emitter, RelaxAll,
455 DWARFMustBeAtTheEnd);
458 if (ELFStreamerCtorFn)
459 S = ELFStreamerCtorFn(T, Ctx, TAB, OS, Emitter, RelaxAll);
461 S = createELFStreamer(Ctx, TAB, OS, Emitter, RelaxAll);
464 if (ObjectTargetStreamerCtorFn)
465 ObjectTargetStreamerCtorFn(*S, STI);
469 MCStreamer *createAsmStreamer(MCContext &Ctx,
470 std::unique_ptr<formatted_raw_ostream> OS,
471 bool IsVerboseAsm, bool UseDwarfDirectory,
472 MCInstPrinter *InstPrint, MCCodeEmitter *CE,
473 MCAsmBackend *TAB, bool ShowInst) const {
474 formatted_raw_ostream &OSRef = *OS;
475 MCStreamer *S = llvm::createAsmStreamer(Ctx, std::move(OS), IsVerboseAsm,
476 UseDwarfDirectory, InstPrint, CE,
478 createAsmTargetStreamer(*S, OSRef, InstPrint, IsVerboseAsm);
482 MCTargetStreamer *createAsmTargetStreamer(MCStreamer &S,
483 formatted_raw_ostream &OS,
484 MCInstPrinter *InstPrint,
485 bool IsVerboseAsm) const {
486 if (AsmTargetStreamerCtorFn)
487 return AsmTargetStreamerCtorFn(S, OS, InstPrint, IsVerboseAsm);
491 MCStreamer *createNullStreamer(MCContext &Ctx) const {
492 MCStreamer *S = llvm::createNullStreamer(Ctx);
493 createNullTargetStreamer(*S);
497 MCTargetStreamer *createNullTargetStreamer(MCStreamer &S) const {
498 if (NullTargetStreamerCtorFn)
499 return NullTargetStreamerCtorFn(S);
503 /// createMCRelocationInfo - Create a target specific MCRelocationInfo.
505 /// \param TT The target triple.
506 /// \param Ctx The target context.
507 MCRelocationInfo *createMCRelocationInfo(StringRef TT, MCContext &Ctx) const {
508 MCRelocationInfoCtorTy Fn = MCRelocationInfoCtorFn
509 ? MCRelocationInfoCtorFn
510 : llvm::createMCRelocationInfo;
511 return Fn(Triple(TT), Ctx);
514 /// createMCSymbolizer - Create a target specific MCSymbolizer.
516 /// \param TT The target triple.
517 /// \param GetOpInfo The function to get the symbolic information for
519 /// \param SymbolLookUp The function to lookup a symbol name.
520 /// \param DisInfo The pointer to the block of symbolic information for above
523 /// \param Ctx The target context.
524 /// \param RelInfo The relocation information for this target. Takes
527 createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
528 LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo,
530 std::unique_ptr<MCRelocationInfo> &&RelInfo) const {
531 MCSymbolizerCtorTy Fn =
532 MCSymbolizerCtorFn ? MCSymbolizerCtorFn : llvm::createMCSymbolizer;
533 return Fn(Triple(TT), GetOpInfo, SymbolLookUp, DisInfo, Ctx,
540 /// TargetRegistry - Generic interface to target specific features.
541 struct TargetRegistry {
542 // FIXME: Make this a namespace, probably just move all the Register*
543 // functions into Target (currently they all just set members on the Target
544 // anyway, and Target friends this class so those functions can...
546 TargetRegistry() = delete;
549 : public std::iterator<std::forward_iterator_tag, Target, ptrdiff_t> {
550 const Target *Current;
551 explicit iterator(Target *T) : Current(T) {}
552 friend struct TargetRegistry;
555 iterator() : Current(nullptr) {}
557 bool operator==(const iterator &x) const { return Current == x.Current; }
558 bool operator!=(const iterator &x) const { 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 { return &operator*(); }
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_range<iterator> targets();
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,
609 Triple &TheTriple, std::string &Error);
612 /// @name Target Registration
615 /// RegisterTarget - Register the given target. Attempts to register a
616 /// target which has already been registered will be ignored.
618 /// Clients are responsible for ensuring that registration doesn't occur
619 /// while another thread is attempting to access the registry. Typically
620 /// this is done by initializing all targets at program startup.
622 /// @param T - The target being registered.
623 /// @param Name - The target name. This should be a static string.
624 /// @param ShortDesc - A short target description. This should be a static
626 /// @param ArchMatchFn - The arch match checking function for this target.
627 /// @param HasJIT - Whether the target supports JIT code
629 static void RegisterTarget(Target &T, const char *Name, const char *ShortDesc,
630 Target::ArchMatchFnTy ArchMatchFn,
631 bool HasJIT = false);
633 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
636 /// Clients are responsible for ensuring that registration doesn't occur
637 /// while another thread is attempting to access the registry. Typically
638 /// this is done by initializing all targets at program startup.
640 /// @param T - The target being registered.
641 /// @param Fn - A function to construct a MCAsmInfo for the target.
642 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
643 T.MCAsmInfoCtorFn = Fn;
646 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
649 /// Clients are responsible for ensuring that registration doesn't occur
650 /// while another thread is attempting to access the registry. Typically
651 /// this is done by initializing all targets at program startup.
653 /// @param T - The target being registered.
654 /// @param Fn - A function to construct a MCCodeGenInfo for the target.
655 static void RegisterMCCodeGenInfo(Target &T,
656 Target::MCCodeGenInfoCtorFnTy Fn) {
657 T.MCCodeGenInfoCtorFn = Fn;
660 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
663 /// Clients are responsible for ensuring that registration doesn't occur
664 /// while another thread is attempting to access the registry. Typically
665 /// this is done by initializing all targets at program startup.
667 /// @param T - The target being registered.
668 /// @param Fn - A function to construct a MCInstrInfo for the target.
669 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
670 T.MCInstrInfoCtorFn = Fn;
673 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
674 /// the given target.
675 static void RegisterMCInstrAnalysis(Target &T,
676 Target::MCInstrAnalysisCtorFnTy Fn) {
677 T.MCInstrAnalysisCtorFn = Fn;
680 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
683 /// Clients are responsible for ensuring that registration doesn't occur
684 /// while another thread is attempting to access the registry. Typically
685 /// this is done by initializing all targets at program startup.
687 /// @param T - The target being registered.
688 /// @param Fn - A function to construct a MCRegisterInfo for the target.
689 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
690 T.MCRegInfoCtorFn = Fn;
693 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
694 /// the given target.
696 /// Clients are responsible for ensuring that registration doesn't occur
697 /// while another thread is attempting to access the registry. Typically
698 /// this is done by initializing all targets at program startup.
700 /// @param T - The target being registered.
701 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
702 static void RegisterMCSubtargetInfo(Target &T,
703 Target::MCSubtargetInfoCtorFnTy Fn) {
704 T.MCSubtargetInfoCtorFn = Fn;
707 /// RegisterTargetMachine - Register a TargetMachine implementation for the
710 /// Clients are responsible for ensuring that registration doesn't occur
711 /// while another thread is attempting to access the registry. Typically
712 /// this is done by initializing all targets at program startup.
714 /// @param T - The target being registered.
715 /// @param Fn - A function to construct a TargetMachine for the target.
716 static void RegisterTargetMachine(Target &T, Target::TargetMachineCtorTy Fn) {
717 T.TargetMachineCtorFn = Fn;
720 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
723 /// Clients are responsible for ensuring that registration doesn't occur
724 /// while another thread is attempting to access the registry. Typically
725 /// this is done by initializing all targets at program startup.
727 /// @param T - The target being registered.
728 /// @param Fn - A function to construct an AsmBackend for the target.
729 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
730 T.MCAsmBackendCtorFn = Fn;
733 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
734 /// the given target.
736 /// Clients are responsible for ensuring that registration doesn't occur
737 /// while another thread is attempting to access the registry. Typically
738 /// this is done by initializing all targets at program startup.
740 /// @param T - The target being registered.
741 /// @param Fn - A function to construct an MCTargetAsmParser for the target.
742 static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
743 T.MCAsmParserCtorFn = Fn;
746 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
749 /// Clients are responsible for ensuring that registration doesn't occur
750 /// while another thread is attempting to access the registry. Typically
751 /// this is done by initializing all targets at program startup.
753 /// @param T - The target being registered.
754 /// @param Fn - A function to construct an AsmPrinter for the target.
755 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
756 T.AsmPrinterCtorFn = Fn;
759 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
760 /// the given target.
762 /// Clients are responsible for ensuring that registration doesn't occur
763 /// while another thread is attempting to access the registry. Typically
764 /// this is done by initializing all targets at program startup.
766 /// @param T - The target being registered.
767 /// @param Fn - A function to construct an MCDisassembler for the target.
768 static void RegisterMCDisassembler(Target &T,
769 Target::MCDisassemblerCtorTy Fn) {
770 T.MCDisassemblerCtorFn = Fn;
773 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
776 /// Clients are responsible for ensuring that registration doesn't occur
777 /// while another thread is attempting to access the registry. Typically
778 /// this is done by initializing all targets at program startup.
780 /// @param T - The target being registered.
781 /// @param Fn - A function to construct an MCInstPrinter for the target.
782 static void RegisterMCInstPrinter(Target &T, Target::MCInstPrinterCtorTy Fn) {
783 T.MCInstPrinterCtorFn = Fn;
786 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
789 /// Clients are responsible for ensuring that registration doesn't occur
790 /// while another thread is attempting to access the registry. Typically
791 /// this is done by initializing all targets at program startup.
793 /// @param T - The target being registered.
794 /// @param Fn - A function to construct an MCCodeEmitter for the target.
795 static void RegisterMCCodeEmitter(Target &T, Target::MCCodeEmitterCtorTy Fn) {
796 T.MCCodeEmitterCtorFn = Fn;
799 static void RegisterCOFFStreamer(Target &T, Target::COFFStreamerCtorTy Fn) {
800 T.COFFStreamerCtorFn = Fn;
803 static void RegisterMachOStreamer(Target &T, Target::MachOStreamerCtorTy Fn) {
804 T.MachOStreamerCtorFn = Fn;
807 static void RegisterELFStreamer(Target &T, Target::ELFStreamerCtorTy Fn) {
808 T.ELFStreamerCtorFn = Fn;
811 static void RegisterNullTargetStreamer(Target &T,
812 Target::NullTargetStreamerCtorTy Fn) {
813 T.NullTargetStreamerCtorFn = Fn;
816 static void RegisterAsmTargetStreamer(Target &T,
817 Target::AsmTargetStreamerCtorTy Fn) {
818 T.AsmTargetStreamerCtorFn = Fn;
822 RegisterObjectTargetStreamer(Target &T,
823 Target::ObjectTargetStreamerCtorTy Fn) {
824 T.ObjectTargetStreamerCtorFn = Fn;
827 /// RegisterMCRelocationInfo - Register an MCRelocationInfo
828 /// implementation for the given target.
830 /// Clients are responsible for ensuring that registration doesn't occur
831 /// while another thread is attempting to access the registry. Typically
832 /// this is done by initializing all targets at program startup.
834 /// @param T - The target being registered.
835 /// @param Fn - A function to construct an MCRelocationInfo for the target.
836 static void RegisterMCRelocationInfo(Target &T,
837 Target::MCRelocationInfoCtorTy Fn) {
838 T.MCRelocationInfoCtorFn = Fn;
841 /// RegisterMCSymbolizer - Register an MCSymbolizer
842 /// implementation for the given target.
844 /// Clients are responsible for ensuring that registration doesn't occur
845 /// while another thread is attempting to access the registry. Typically
846 /// this is done by initializing all targets at program startup.
848 /// @param T - The target being registered.
849 /// @param Fn - A function to construct an MCSymbolizer for the target.
850 static void RegisterMCSymbolizer(Target &T, Target::MCSymbolizerCtorTy Fn) {
851 T.MCSymbolizerCtorFn = Fn;
857 //===--------------------------------------------------------------------===//
859 /// RegisterTarget - Helper template for registering a target, for use in the
860 /// target's initialization function. Usage:
863 /// Target TheFooTarget; // The global target instance.
865 /// extern "C" void LLVMInitializeFooTargetInfo() {
866 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
868 template <Triple::ArchType TargetArchType = Triple::UnknownArch,
870 struct RegisterTarget {
871 RegisterTarget(Target &T, const char *Name, const char *Desc) {
872 TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch, HasJIT);
875 static bool getArchMatch(Triple::ArchType Arch) {
876 return Arch == TargetArchType;
880 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
881 /// implementation. This invokes the static "Create" method on the class to
882 /// actually do the construction. Usage:
884 /// extern "C" void LLVMInitializeFooTarget() {
885 /// extern Target TheFooTarget;
886 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
888 template <class MCAsmInfoImpl> struct RegisterMCAsmInfo {
889 RegisterMCAsmInfo(Target &T) {
890 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
894 static MCAsmInfo *Allocator(const MCRegisterInfo & /*MRI*/,
896 return new MCAsmInfoImpl(TT);
900 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
901 /// implementation. This invokes the specified function to do the
902 /// construction. Usage:
904 /// extern "C" void LLVMInitializeFooTarget() {
905 /// extern Target TheFooTarget;
906 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
908 struct RegisterMCAsmInfoFn {
909 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
910 TargetRegistry::RegisterMCAsmInfo(T, Fn);
914 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen
916 /// implementation. This invokes the static "Create" method on the class
917 /// to actually do the construction. Usage:
919 /// extern "C" void LLVMInitializeFooTarget() {
920 /// extern Target TheFooTarget;
921 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
923 template <class MCCodeGenInfoImpl> struct RegisterMCCodeGenInfo {
924 RegisterMCCodeGenInfo(Target &T) {
925 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
929 static MCCodeGenInfo *Allocator(const Triple & /*TT*/, Reloc::Model /*RM*/,
930 CodeModel::Model /*CM*/,
931 CodeGenOpt::Level /*OL*/) {
932 return new MCCodeGenInfoImpl();
936 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
937 /// info implementation. This invokes the specified function to do the
938 /// construction. Usage:
940 /// extern "C" void LLVMInitializeFooTarget() {
941 /// extern Target TheFooTarget;
942 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
944 struct RegisterMCCodeGenInfoFn {
945 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
946 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
950 /// RegisterMCInstrInfo - Helper template for registering a target instruction
951 /// info implementation. This invokes the static "Create" method on the class
952 /// to actually do the construction. Usage:
954 /// extern "C" void LLVMInitializeFooTarget() {
955 /// extern Target TheFooTarget;
956 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
958 template <class MCInstrInfoImpl> struct RegisterMCInstrInfo {
959 RegisterMCInstrInfo(Target &T) {
960 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
964 static MCInstrInfo *Allocator() { return new MCInstrInfoImpl(); }
967 /// RegisterMCInstrInfoFn - Helper template for registering a target
968 /// instruction info implementation. This invokes the specified function to
969 /// do the construction. Usage:
971 /// extern "C" void LLVMInitializeFooTarget() {
972 /// extern Target TheFooTarget;
973 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
975 struct RegisterMCInstrInfoFn {
976 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
977 TargetRegistry::RegisterMCInstrInfo(T, Fn);
981 /// RegisterMCInstrAnalysis - Helper template for registering a target
982 /// instruction analyzer implementation. This invokes the static "Create"
983 /// method on the class to actually do the construction. Usage:
985 /// extern "C" void LLVMInitializeFooTarget() {
986 /// extern Target TheFooTarget;
987 /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
989 template <class MCInstrAnalysisImpl> struct RegisterMCInstrAnalysis {
990 RegisterMCInstrAnalysis(Target &T) {
991 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
995 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
996 return new MCInstrAnalysisImpl(Info);
1000 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
1001 /// instruction analyzer implementation. This invokes the specified function
1002 /// to do the construction. Usage:
1004 /// extern "C" void LLVMInitializeFooTarget() {
1005 /// extern Target TheFooTarget;
1006 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
1008 struct RegisterMCInstrAnalysisFn {
1009 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
1010 TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
1014 /// RegisterMCRegInfo - Helper template for registering a target register info
1015 /// implementation. This invokes the static "Create" method on the class to
1016 /// actually do the construction. Usage:
1018 /// extern "C" void LLVMInitializeFooTarget() {
1019 /// extern Target TheFooTarget;
1020 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
1022 template <class MCRegisterInfoImpl> struct RegisterMCRegInfo {
1023 RegisterMCRegInfo(Target &T) {
1024 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
1028 static MCRegisterInfo *Allocator(const Triple & /*TT*/) {
1029 return new MCRegisterInfoImpl();
1033 /// RegisterMCRegInfoFn - Helper template for registering a target register
1034 /// info implementation. This invokes the specified function to do the
1035 /// construction. Usage:
1037 /// extern "C" void LLVMInitializeFooTarget() {
1038 /// extern Target TheFooTarget;
1039 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
1041 struct RegisterMCRegInfoFn {
1042 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
1043 TargetRegistry::RegisterMCRegInfo(T, Fn);
1047 /// RegisterMCSubtargetInfo - Helper template for registering a target
1048 /// subtarget info implementation. This invokes the static "Create" method
1049 /// on the class to actually do the construction. Usage:
1051 /// extern "C" void LLVMInitializeFooTarget() {
1052 /// extern Target TheFooTarget;
1053 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
1055 template <class MCSubtargetInfoImpl> struct RegisterMCSubtargetInfo {
1056 RegisterMCSubtargetInfo(Target &T) {
1057 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
1061 static MCSubtargetInfo *Allocator(const Triple & /*TT*/, StringRef /*CPU*/,
1063 return new MCSubtargetInfoImpl();
1067 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
1068 /// subtarget info implementation. This invokes the specified function to
1069 /// do the construction. Usage:
1071 /// extern "C" void LLVMInitializeFooTarget() {
1072 /// extern Target TheFooTarget;
1073 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1075 struct RegisterMCSubtargetInfoFn {
1076 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
1077 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
1081 /// RegisterTargetMachine - Helper template for registering a target machine
1082 /// implementation, for use in the target machine initialization
1083 /// function. Usage:
1085 /// extern "C" void LLVMInitializeFooTarget() {
1086 /// extern Target TheFooTarget;
1087 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1089 template <class TargetMachineImpl> struct RegisterTargetMachine {
1090 RegisterTargetMachine(Target &T) {
1091 TargetRegistry::RegisterTargetMachine(T, &Allocator);
1095 static TargetMachine *Allocator(const Target &T, const Triple &TT,
1096 StringRef CPU, StringRef FS,
1097 const TargetOptions &Options, Reloc::Model RM,
1098 CodeModel::Model CM, CodeGenOpt::Level OL) {
1099 return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
1103 /// RegisterMCAsmBackend - Helper template for registering a target specific
1104 /// assembler backend. Usage:
1106 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1107 /// extern Target TheFooTarget;
1108 /// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1110 template <class MCAsmBackendImpl> struct RegisterMCAsmBackend {
1111 RegisterMCAsmBackend(Target &T) {
1112 TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1116 static MCAsmBackend *Allocator(const Target &T, const MCRegisterInfo &MRI,
1117 const Triple &TheTriple, StringRef CPU) {
1118 return new MCAsmBackendImpl(T, MRI, TheTriple, CPU);
1122 /// RegisterMCAsmParser - Helper template for registering a target specific
1123 /// assembly parser, for use in the target machine initialization
1124 /// function. Usage:
1126 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1127 /// extern Target TheFooTarget;
1128 /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1130 template <class MCAsmParserImpl> struct RegisterMCAsmParser {
1131 RegisterMCAsmParser(Target &T) {
1132 TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1136 static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P,
1137 const MCInstrInfo &MII,
1138 const MCTargetOptions &Options) {
1139 return new MCAsmParserImpl(STI, P, MII, Options);
1143 /// RegisterAsmPrinter - Helper template for registering a target specific
1144 /// assembly printer, for use in the target machine initialization
1145 /// function. Usage:
1147 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1148 /// extern Target TheFooTarget;
1149 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1151 template <class AsmPrinterImpl> struct RegisterAsmPrinter {
1152 RegisterAsmPrinter(Target &T) {
1153 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1157 static AsmPrinter *Allocator(TargetMachine &TM,
1158 std::unique_ptr<MCStreamer> &&Streamer) {
1159 return new AsmPrinterImpl(TM, std::move(Streamer));
1163 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1164 /// machine code emitter, for use in the target initialization
1165 /// function. Usage:
1167 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1168 /// extern Target TheFooTarget;
1169 /// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1171 template <class MCCodeEmitterImpl> struct RegisterMCCodeEmitter {
1172 RegisterMCCodeEmitter(Target &T) {
1173 TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1177 static MCCodeEmitter *Allocator(const MCInstrInfo & /*II*/,
1178 const MCRegisterInfo & /*MRI*/,
1179 MCContext & /*Ctx*/) {
1180 return new MCCodeEmitterImpl();