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(StringRef TT, LLVMOpInfoCallback GetOpInfo,
75 LLVMSymbolLookupCallback SymbolLookUp,
76 void *DisInfo, MCContext *Ctx,
77 std::unique_ptr<MCRelocationInfo> &&RelInfo);
79 /// Target - Wrapper for Target specific information.
81 /// For registration purposes, this is a POD type so that targets can be
82 /// registered without the use of static constructors.
84 /// Targets should implement a single global instance of this class (which
85 /// will be zero initialized), and pass that instance to the TargetRegistry as
86 /// part of their initialization.
89 friend struct TargetRegistry;
91 typedef bool (*ArchMatchFnTy)(Triple::ArchType Arch);
93 typedef MCAsmInfo *(*MCAsmInfoCtorFnTy)(const MCRegisterInfo &MRI,
95 typedef MCCodeGenInfo *(*MCCodeGenInfoCtorFnTy)(StringRef TT, Reloc::Model RM,
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)(const Triple &TT,
104 typedef TargetMachine *(*TargetMachineCtorTy)(
105 const Target &T, StringRef TT, StringRef CPU, StringRef Features,
106 const TargetOptions &Options, Reloc::Model RM, CodeModel::Model CM,
107 CodeGenOpt::Level OL);
108 // If it weren't for layering issues (this header is in llvm/Support, but
109 // depends on MC?) this should take the Streamer by value rather than rvalue
111 typedef AsmPrinter *(*AsmPrinterCtorTy)(
112 TargetMachine &TM, std::unique_ptr<MCStreamer> &&Streamer);
113 typedef MCAsmBackend *(*MCAsmBackendCtorTy)(const Target &T,
114 const MCRegisterInfo &MRI,
115 const Triple &TT, StringRef CPU);
116 typedef MCTargetAsmParser *(*MCAsmParserCtorTy)(
117 MCSubtargetInfo &STI, MCAsmParser &P, const MCInstrInfo &MII,
118 const MCTargetOptions &Options);
119 typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T,
120 const MCSubtargetInfo &STI,
122 typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Triple &T,
123 unsigned SyntaxVariant,
124 const MCAsmInfo &MAI,
125 const MCInstrInfo &MII,
126 const MCRegisterInfo &MRI);
127 typedef MCCodeEmitter *(*MCCodeEmitterCtorTy)(const MCInstrInfo &II,
128 const MCRegisterInfo &MRI,
130 typedef MCStreamer *(*ELFStreamerCtorTy)(const Triple &T, MCContext &Ctx,
132 raw_pwrite_stream &OS,
133 MCCodeEmitter *Emitter,
135 typedef MCStreamer *(*MachOStreamerCtorTy)(MCContext &Ctx, MCAsmBackend &TAB,
136 raw_pwrite_stream &OS,
137 MCCodeEmitter *Emitter,
139 bool DWARFMustBeAtTheEnd);
140 typedef MCStreamer *(*COFFStreamerCtorTy)(MCContext &Ctx, MCAsmBackend &TAB,
141 raw_pwrite_stream &OS,
142 MCCodeEmitter *Emitter,
144 typedef MCTargetStreamer *(*NullTargetStreamerCtorTy)(MCStreamer &S);
145 typedef MCTargetStreamer *(*AsmTargetStreamerCtorTy)(
146 MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *InstPrint,
148 typedef MCTargetStreamer *(*ObjectTargetStreamerCtorTy)(
149 MCStreamer &S, const MCSubtargetInfo &STI);
150 typedef MCRelocationInfo *(*MCRelocationInfoCtorTy)(const Triple &TT,
152 typedef MCSymbolizer *(*MCSymbolizerCtorTy)(
153 StringRef TT, LLVMOpInfoCallback GetOpInfo,
154 LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo, MCContext *Ctx,
155 std::unique_ptr<MCRelocationInfo> &&RelInfo);
158 /// Next - The next registered target in the linked list, maintained by the
162 /// The target function for checking if an architecture is supported.
163 ArchMatchFnTy ArchMatchFn;
165 /// Name - The target name.
168 /// ShortDesc - A short description of the target.
169 const char *ShortDesc;
171 /// HasJIT - Whether this target supports the JIT.
174 /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
176 MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
178 /// MCCodeGenInfoCtorFn - Constructor function for this target's
179 /// MCCodeGenInfo, if registered.
180 MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn;
182 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
184 MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
186 /// MCInstrAnalysisCtorFn - Constructor function for this target's
187 /// MCInstrAnalysis, if registered.
188 MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
190 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
192 MCRegInfoCtorFnTy MCRegInfoCtorFn;
194 /// MCSubtargetInfoCtorFn - Constructor function for this target's
195 /// MCSubtargetInfo, if registered.
196 MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
198 /// TargetMachineCtorFn - Construction function for this target's
199 /// TargetMachine, if registered.
200 TargetMachineCtorTy TargetMachineCtorFn;
202 /// MCAsmBackendCtorFn - Construction function for this target's
203 /// MCAsmBackend, if registered.
204 MCAsmBackendCtorTy MCAsmBackendCtorFn;
206 /// MCAsmParserCtorFn - Construction function for this target's
207 /// MCTargetAsmParser, if registered.
208 MCAsmParserCtorTy MCAsmParserCtorFn;
210 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
212 AsmPrinterCtorTy AsmPrinterCtorFn;
214 /// MCDisassemblerCtorFn - Construction function for this target's
215 /// MCDisassembler, if registered.
216 MCDisassemblerCtorTy MCDisassemblerCtorFn;
218 /// MCInstPrinterCtorFn - Construction function for this target's
219 /// MCInstPrinter, if registered.
220 MCInstPrinterCtorTy MCInstPrinterCtorFn;
222 /// MCCodeEmitterCtorFn - Construction function for this target's
223 /// CodeEmitter, if registered.
224 MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
226 // Construction functions for the various object formats, if registered.
227 COFFStreamerCtorTy COFFStreamerCtorFn;
228 MachOStreamerCtorTy MachOStreamerCtorFn;
229 ELFStreamerCtorTy ELFStreamerCtorFn;
231 /// Construction function for this target's null TargetStreamer, if
232 /// registered (default = nullptr).
233 NullTargetStreamerCtorTy NullTargetStreamerCtorFn;
235 /// Construction function for this target's asm TargetStreamer, if
236 /// registered (default = nullptr).
237 AsmTargetStreamerCtorTy AsmTargetStreamerCtorFn;
239 /// Construction function for this target's obj TargetStreamer, if
240 /// registered (default = nullptr).
241 ObjectTargetStreamerCtorTy ObjectTargetStreamerCtorFn;
243 /// MCRelocationInfoCtorFn - Construction function for this target's
244 /// MCRelocationInfo, if registered (default = llvm::createMCRelocationInfo)
245 MCRelocationInfoCtorTy MCRelocationInfoCtorFn;
247 /// MCSymbolizerCtorFn - Construction function for this target's
248 /// MCSymbolizer, if registered (default = llvm::createMCSymbolizer)
249 MCSymbolizerCtorTy MCSymbolizerCtorFn;
253 : COFFStreamerCtorFn(nullptr), MachOStreamerCtorFn(nullptr),
254 ELFStreamerCtorFn(nullptr), NullTargetStreamerCtorFn(nullptr),
255 AsmTargetStreamerCtorFn(nullptr), ObjectTargetStreamerCtorFn(nullptr),
256 MCRelocationInfoCtorFn(nullptr), MCSymbolizerCtorFn(nullptr) {}
258 /// @name Target Information
261 // getNext - Return the next registered target.
262 const Target *getNext() const { return Next; }
264 /// getName - Get the target name.
265 const char *getName() const { return Name; }
267 /// getShortDescription - Get a short description of the target.
268 const char *getShortDescription() const { return ShortDesc; }
271 /// @name Feature Predicates
274 /// hasJIT - Check if this targets supports the just-in-time compilation.
275 bool hasJIT() const { return HasJIT; }
277 /// hasTargetMachine - Check if this target supports code generation.
278 bool hasTargetMachine() const { return TargetMachineCtorFn != nullptr; }
280 /// hasMCAsmBackend - Check if this target supports .o generation.
281 bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != nullptr; }
284 /// @name Feature Constructors
287 /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
290 /// \param TheTriple This argument is used to determine the target machine
291 /// feature set; it should always be provided. Generally this should be
292 /// either the target triple from the module, or the target triple of the
293 /// host if that does not exist.
294 MCAsmInfo *createMCAsmInfo(const MCRegisterInfo &MRI,
295 StringRef TheTriple) const {
296 if (!MCAsmInfoCtorFn)
298 return MCAsmInfoCtorFn(MRI, Triple(TheTriple));
301 /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
303 MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model RM,
305 CodeGenOpt::Level OL) const {
306 if (!MCCodeGenInfoCtorFn)
308 return MCCodeGenInfoCtorFn(Triple, RM, CM, OL);
311 /// createMCInstrInfo - Create a MCInstrInfo implementation.
313 MCInstrInfo *createMCInstrInfo() const {
314 if (!MCInstrInfoCtorFn)
316 return MCInstrInfoCtorFn();
319 /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
321 MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
322 if (!MCInstrAnalysisCtorFn)
324 return MCInstrAnalysisCtorFn(Info);
327 /// createMCRegInfo - Create a MCRegisterInfo implementation.
329 MCRegisterInfo *createMCRegInfo(StringRef Triple) const {
330 if (!MCRegInfoCtorFn)
332 return MCRegInfoCtorFn(Triple);
335 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
337 /// \param TheTriple This argument is used to determine the target machine
338 /// feature set; it should always be provided. Generally this should be
339 /// either the target triple from the module, or the target triple of the
340 /// host if that does not exist.
341 /// \param CPU This specifies the name of the target CPU.
342 /// \param Features This specifies the string representation of the
343 /// additional target features.
344 MCSubtargetInfo *createMCSubtargetInfo(StringRef TheTriple, StringRef CPU,
345 StringRef Features) const {
346 if (!MCSubtargetInfoCtorFn)
348 return MCSubtargetInfoCtorFn(Triple(TheTriple), CPU, Features);
351 /// createTargetMachine - Create a target specific machine implementation
352 /// for the specified \p Triple.
354 /// \param Triple This argument is used to determine the target machine
355 /// feature set; it should always be provided. Generally this should be
356 /// either the target triple from the module, or the target triple of the
357 /// host if that does not exist.
359 createTargetMachine(StringRef Triple, StringRef CPU, StringRef Features,
360 const TargetOptions &Options,
361 Reloc::Model RM = Reloc::Default,
362 CodeModel::Model CM = CodeModel::Default,
363 CodeGenOpt::Level OL = CodeGenOpt::Default) const {
364 if (!TargetMachineCtorFn)
366 return TargetMachineCtorFn(*this, Triple, CPU, Features, Options, RM, CM,
370 /// createMCAsmBackend - Create a target specific assembly parser.
372 /// \param TheTriple The target triple string.
373 MCAsmBackend *createMCAsmBackend(const MCRegisterInfo &MRI,
374 StringRef TheTriple, StringRef CPU) const {
375 if (!MCAsmBackendCtorFn)
377 return MCAsmBackendCtorFn(*this, MRI, Triple(TheTriple), CPU);
380 /// createMCAsmParser - Create a target specific assembly parser.
382 /// \param Parser The target independent parser implementation to use for
383 /// parsing and lexing.
384 MCTargetAsmParser *createMCAsmParser(MCSubtargetInfo &STI,
386 const MCInstrInfo &MII,
387 const MCTargetOptions &Options) const {
388 if (!MCAsmParserCtorFn)
390 return MCAsmParserCtorFn(STI, Parser, MII, Options);
393 /// createAsmPrinter - Create a target specific assembly printer pass. This
394 /// takes ownership of the MCStreamer object.
395 AsmPrinter *createAsmPrinter(TargetMachine &TM,
396 std::unique_ptr<MCStreamer> &&Streamer) const {
397 if (!AsmPrinterCtorFn)
399 return AsmPrinterCtorFn(TM, std::move(Streamer));
402 MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI,
403 MCContext &Ctx) const {
404 if (!MCDisassemblerCtorFn)
406 return MCDisassemblerCtorFn(*this, STI, Ctx);
409 MCInstPrinter *createMCInstPrinter(const Triple &T, unsigned SyntaxVariant,
410 const MCAsmInfo &MAI,
411 const MCInstrInfo &MII,
412 const MCRegisterInfo &MRI) const {
413 if (!MCInstPrinterCtorFn)
415 return MCInstPrinterCtorFn(T, SyntaxVariant, MAI, MII, MRI);
418 /// createMCCodeEmitter - Create a target specific code emitter.
419 MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
420 const MCRegisterInfo &MRI,
421 MCContext &Ctx) const {
422 if (!MCCodeEmitterCtorFn)
424 return MCCodeEmitterCtorFn(II, MRI, Ctx);
427 /// Create a target specific MCStreamer.
429 /// \param T The target triple.
430 /// \param Ctx The target context.
431 /// \param TAB The target assembler backend object. Takes ownership.
432 /// \param OS The stream object.
433 /// \param Emitter The target independent assembler object.Takes ownership.
434 /// \param RelaxAll Relax all fixups?
435 MCStreamer *createMCObjectStreamer(const Triple &T, MCContext &Ctx,
436 MCAsmBackend &TAB, raw_pwrite_stream &OS,
437 MCCodeEmitter *Emitter,
438 const MCSubtargetInfo &STI, bool RelaxAll,
439 bool DWARFMustBeAtTheEnd) const {
441 switch (T.getObjectFormat()) {
443 llvm_unreachable("Unknown object format");
445 assert(T.isOSWindows() && "only Windows COFF is supported");
446 S = COFFStreamerCtorFn(Ctx, TAB, OS, Emitter, RelaxAll);
449 if (MachOStreamerCtorFn)
450 S = MachOStreamerCtorFn(Ctx, TAB, OS, Emitter, RelaxAll,
451 DWARFMustBeAtTheEnd);
453 S = createMachOStreamer(Ctx, TAB, OS, Emitter, RelaxAll,
454 DWARFMustBeAtTheEnd);
457 if (ELFStreamerCtorFn)
458 S = ELFStreamerCtorFn(T, Ctx, TAB, OS, Emitter, RelaxAll);
460 S = createELFStreamer(Ctx, TAB, OS, Emitter, RelaxAll);
463 if (ObjectTargetStreamerCtorFn)
464 ObjectTargetStreamerCtorFn(*S, STI);
468 MCStreamer *createAsmStreamer(MCContext &Ctx,
469 std::unique_ptr<formatted_raw_ostream> OS,
470 bool IsVerboseAsm, bool UseDwarfDirectory,
471 MCInstPrinter *InstPrint, MCCodeEmitter *CE,
472 MCAsmBackend *TAB, bool ShowInst) const {
473 formatted_raw_ostream &OSRef = *OS;
474 MCStreamer *S = llvm::createAsmStreamer(Ctx, std::move(OS), IsVerboseAsm,
475 UseDwarfDirectory, InstPrint, CE,
477 createAsmTargetStreamer(*S, OSRef, InstPrint, IsVerboseAsm);
481 MCTargetStreamer *createAsmTargetStreamer(MCStreamer &S,
482 formatted_raw_ostream &OS,
483 MCInstPrinter *InstPrint,
484 bool IsVerboseAsm) const {
485 if (AsmTargetStreamerCtorFn)
486 return AsmTargetStreamerCtorFn(S, OS, InstPrint, IsVerboseAsm);
490 MCStreamer *createNullStreamer(MCContext &Ctx) const {
491 MCStreamer *S = llvm::createNullStreamer(Ctx);
492 createNullTargetStreamer(*S);
496 MCTargetStreamer *createNullTargetStreamer(MCStreamer &S) const {
497 if (NullTargetStreamerCtorFn)
498 return NullTargetStreamerCtorFn(S);
502 /// createMCRelocationInfo - Create a target specific MCRelocationInfo.
504 /// \param TT The target triple.
505 /// \param Ctx The target context.
506 MCRelocationInfo *createMCRelocationInfo(StringRef TT, MCContext &Ctx) const {
507 MCRelocationInfoCtorTy Fn = MCRelocationInfoCtorFn
508 ? MCRelocationInfoCtorFn
509 : llvm::createMCRelocationInfo;
510 return Fn(Triple(TT), Ctx);
513 /// createMCSymbolizer - Create a target specific MCSymbolizer.
515 /// \param TT The target triple.
516 /// \param GetOpInfo The function to get the symbolic information for
518 /// \param SymbolLookUp The function to lookup a symbol name.
519 /// \param DisInfo The pointer to the block of symbolic information for above
522 /// \param Ctx The target context.
523 /// \param RelInfo The relocation information for this target. Takes
526 createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
527 LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo,
529 std::unique_ptr<MCRelocationInfo> &&RelInfo) const {
530 MCSymbolizerCtorTy Fn =
531 MCSymbolizerCtorFn ? MCSymbolizerCtorFn : llvm::createMCSymbolizer;
532 return Fn(TT, GetOpInfo, SymbolLookUp, DisInfo, Ctx, std::move(RelInfo));
538 /// TargetRegistry - Generic interface to target specific features.
539 struct TargetRegistry {
540 // FIXME: Make this a namespace, probably just move all the Register*
541 // functions into Target (currently they all just set members on the Target
542 // anyway, and Target friends this class so those functions can...
544 TargetRegistry() = delete;
547 : public std::iterator<std::forward_iterator_tag, Target, ptrdiff_t> {
548 const Target *Current;
549 explicit iterator(Target *T) : Current(T) {}
550 friend struct TargetRegistry;
553 iterator() : Current(nullptr) {}
555 bool operator==(const iterator &x) const { return Current == x.Current; }
556 bool operator!=(const iterator &x) const { 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 { return &operator*(); }
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_range<iterator> targets();
587 /// lookupTarget - Lookup a target based on a target triple.
589 /// \param Triple - The triple to use for finding a target.
590 /// \param Error - On failure, an error string describing why no target was
592 static const Target *lookupTarget(const std::string &Triple,
595 /// lookupTarget - Lookup a target based on an architecture name
596 /// and a target triple. If the architecture name is non-empty,
597 /// then the lookup is done by architecture. Otherwise, the target
600 /// \param ArchName - The architecture to use for finding a target.
601 /// \param TheTriple - The triple to use for finding a target. The
602 /// triple is updated with canonical architecture name if a lookup
603 /// by architecture is done.
604 /// \param Error - On failure, an error string describing why no target was
606 static const Target *lookupTarget(const std::string &ArchName,
607 Triple &TheTriple, std::string &Error);
610 /// @name Target Registration
613 /// RegisterTarget - Register the given target. Attempts to register a
614 /// target which has already been registered will be ignored.
616 /// Clients are responsible for ensuring that registration doesn't occur
617 /// while another thread is attempting to access the registry. Typically
618 /// this is done by initializing all targets at program startup.
620 /// @param T - The target being registered.
621 /// @param Name - The target name. This should be a static string.
622 /// @param ShortDesc - A short target description. This should be a static
624 /// @param ArchMatchFn - The arch match checking function for this target.
625 /// @param HasJIT - Whether the target supports JIT code
627 static void RegisterTarget(Target &T, const char *Name, const char *ShortDesc,
628 Target::ArchMatchFnTy ArchMatchFn,
629 bool HasJIT = false);
631 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
634 /// Clients are responsible for ensuring that registration doesn't occur
635 /// while another thread is attempting to access the registry. Typically
636 /// this is done by initializing all targets at program startup.
638 /// @param T - The target being registered.
639 /// @param Fn - A function to construct a MCAsmInfo for the target.
640 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
641 T.MCAsmInfoCtorFn = Fn;
644 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
647 /// Clients are responsible for ensuring that registration doesn't occur
648 /// while another thread is attempting to access the registry. Typically
649 /// this is done by initializing all targets at program startup.
651 /// @param T - The target being registered.
652 /// @param Fn - A function to construct a MCCodeGenInfo for the target.
653 static void RegisterMCCodeGenInfo(Target &T,
654 Target::MCCodeGenInfoCtorFnTy Fn) {
655 T.MCCodeGenInfoCtorFn = Fn;
658 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
661 /// Clients are responsible for ensuring that registration doesn't occur
662 /// while another thread is attempting to access the registry. Typically
663 /// this is done by initializing all targets at program startup.
665 /// @param T - The target being registered.
666 /// @param Fn - A function to construct a MCInstrInfo for the target.
667 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
668 T.MCInstrInfoCtorFn = Fn;
671 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
672 /// the given target.
673 static void RegisterMCInstrAnalysis(Target &T,
674 Target::MCInstrAnalysisCtorFnTy Fn) {
675 T.MCInstrAnalysisCtorFn = Fn;
678 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
681 /// Clients are responsible for ensuring that registration doesn't occur
682 /// while another thread is attempting to access the registry. Typically
683 /// this is done by initializing all targets at program startup.
685 /// @param T - The target being registered.
686 /// @param Fn - A function to construct a MCRegisterInfo for the target.
687 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
688 T.MCRegInfoCtorFn = Fn;
691 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
692 /// the given target.
694 /// Clients are responsible for ensuring that registration doesn't occur
695 /// while another thread is attempting to access the registry. Typically
696 /// this is done by initializing all targets at program startup.
698 /// @param T - The target being registered.
699 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
700 static void RegisterMCSubtargetInfo(Target &T,
701 Target::MCSubtargetInfoCtorFnTy Fn) {
702 T.MCSubtargetInfoCtorFn = Fn;
705 /// RegisterTargetMachine - Register a TargetMachine implementation for the
708 /// Clients are responsible for ensuring that registration doesn't occur
709 /// while another thread is attempting to access the registry. Typically
710 /// this is done by initializing all targets at program startup.
712 /// @param T - The target being registered.
713 /// @param Fn - A function to construct a TargetMachine for the target.
714 static void RegisterTargetMachine(Target &T, Target::TargetMachineCtorTy Fn) {
715 T.TargetMachineCtorFn = Fn;
718 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
721 /// Clients are responsible for ensuring that registration doesn't occur
722 /// while another thread is attempting to access the registry. Typically
723 /// this is done by initializing all targets at program startup.
725 /// @param T - The target being registered.
726 /// @param Fn - A function to construct an AsmBackend for the target.
727 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
728 T.MCAsmBackendCtorFn = Fn;
731 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
732 /// the given target.
734 /// Clients are responsible for ensuring that registration doesn't occur
735 /// while another thread is attempting to access the registry. Typically
736 /// this is done by initializing all targets at program startup.
738 /// @param T - The target being registered.
739 /// @param Fn - A function to construct an MCTargetAsmParser for the target.
740 static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
741 T.MCAsmParserCtorFn = Fn;
744 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
747 /// Clients are responsible for ensuring that registration doesn't occur
748 /// while another thread is attempting to access the registry. Typically
749 /// this is done by initializing all targets at program startup.
751 /// @param T - The target being registered.
752 /// @param Fn - A function to construct an AsmPrinter for the target.
753 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
754 T.AsmPrinterCtorFn = Fn;
757 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
758 /// the given target.
760 /// Clients are responsible for ensuring that registration doesn't occur
761 /// while another thread is attempting to access the registry. Typically
762 /// this is done by initializing all targets at program startup.
764 /// @param T - The target being registered.
765 /// @param Fn - A function to construct an MCDisassembler for the target.
766 static void RegisterMCDisassembler(Target &T,
767 Target::MCDisassemblerCtorTy Fn) {
768 T.MCDisassemblerCtorFn = Fn;
771 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
774 /// Clients are responsible for ensuring that registration doesn't occur
775 /// while another thread is attempting to access the registry. Typically
776 /// this is done by initializing all targets at program startup.
778 /// @param T - The target being registered.
779 /// @param Fn - A function to construct an MCInstPrinter for the target.
780 static void RegisterMCInstPrinter(Target &T, Target::MCInstPrinterCtorTy Fn) {
781 T.MCInstPrinterCtorFn = Fn;
784 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
787 /// Clients are responsible for ensuring that registration doesn't occur
788 /// while another thread is attempting to access the registry. Typically
789 /// this is done by initializing all targets at program startup.
791 /// @param T - The target being registered.
792 /// @param Fn - A function to construct an MCCodeEmitter for the target.
793 static void RegisterMCCodeEmitter(Target &T, Target::MCCodeEmitterCtorTy Fn) {
794 T.MCCodeEmitterCtorFn = Fn;
797 static void RegisterCOFFStreamer(Target &T, Target::COFFStreamerCtorTy Fn) {
798 T.COFFStreamerCtorFn = Fn;
801 static void RegisterMachOStreamer(Target &T, Target::MachOStreamerCtorTy Fn) {
802 T.MachOStreamerCtorFn = Fn;
805 static void RegisterELFStreamer(Target &T, Target::ELFStreamerCtorTy Fn) {
806 T.ELFStreamerCtorFn = Fn;
809 static void RegisterNullTargetStreamer(Target &T,
810 Target::NullTargetStreamerCtorTy Fn) {
811 T.NullTargetStreamerCtorFn = Fn;
814 static void RegisterAsmTargetStreamer(Target &T,
815 Target::AsmTargetStreamerCtorTy Fn) {
816 T.AsmTargetStreamerCtorFn = Fn;
820 RegisterObjectTargetStreamer(Target &T,
821 Target::ObjectTargetStreamerCtorTy Fn) {
822 T.ObjectTargetStreamerCtorFn = Fn;
825 /// RegisterMCRelocationInfo - Register an MCRelocationInfo
826 /// implementation for the given target.
828 /// Clients are responsible for ensuring that registration doesn't occur
829 /// while another thread is attempting to access the registry. Typically
830 /// this is done by initializing all targets at program startup.
832 /// @param T - The target being registered.
833 /// @param Fn - A function to construct an MCRelocationInfo for the target.
834 static void RegisterMCRelocationInfo(Target &T,
835 Target::MCRelocationInfoCtorTy Fn) {
836 T.MCRelocationInfoCtorFn = Fn;
839 /// RegisterMCSymbolizer - Register an MCSymbolizer
840 /// implementation for the given target.
842 /// Clients are responsible for ensuring that registration doesn't occur
843 /// while another thread is attempting to access the registry. Typically
844 /// this is done by initializing all targets at program startup.
846 /// @param T - The target being registered.
847 /// @param Fn - A function to construct an MCSymbolizer for the target.
848 static void RegisterMCSymbolizer(Target &T, Target::MCSymbolizerCtorTy Fn) {
849 T.MCSymbolizerCtorFn = Fn;
855 //===--------------------------------------------------------------------===//
857 /// RegisterTarget - Helper template for registering a target, for use in the
858 /// target's initialization function. Usage:
861 /// Target TheFooTarget; // The global target instance.
863 /// extern "C" void LLVMInitializeFooTargetInfo() {
864 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
866 template <Triple::ArchType TargetArchType = Triple::UnknownArch,
868 struct RegisterTarget {
869 RegisterTarget(Target &T, const char *Name, const char *Desc) {
870 TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch, HasJIT);
873 static bool getArchMatch(Triple::ArchType Arch) {
874 return Arch == TargetArchType;
878 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
879 /// implementation. This invokes the static "Create" method on the class to
880 /// actually do the construction. Usage:
882 /// extern "C" void LLVMInitializeFooTarget() {
883 /// extern Target TheFooTarget;
884 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
886 template <class MCAsmInfoImpl> struct RegisterMCAsmInfo {
887 RegisterMCAsmInfo(Target &T) {
888 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
892 static MCAsmInfo *Allocator(const MCRegisterInfo & /*MRI*/,
894 return new MCAsmInfoImpl(TT);
898 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
899 /// implementation. This invokes the specified function to do the
900 /// construction. Usage:
902 /// extern "C" void LLVMInitializeFooTarget() {
903 /// extern Target TheFooTarget;
904 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
906 struct RegisterMCAsmInfoFn {
907 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
908 TargetRegistry::RegisterMCAsmInfo(T, Fn);
912 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen
914 /// implementation. This invokes the static "Create" method on the class
915 /// to actually do the construction. Usage:
917 /// extern "C" void LLVMInitializeFooTarget() {
918 /// extern Target TheFooTarget;
919 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
921 template <class MCCodeGenInfoImpl> struct RegisterMCCodeGenInfo {
922 RegisterMCCodeGenInfo(Target &T) {
923 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
927 static MCCodeGenInfo *Allocator(StringRef /*TT*/, Reloc::Model /*RM*/,
928 CodeModel::Model /*CM*/,
929 CodeGenOpt::Level /*OL*/) {
930 return new MCCodeGenInfoImpl();
934 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
935 /// info implementation. This invokes the specified function to do the
936 /// construction. Usage:
938 /// extern "C" void LLVMInitializeFooTarget() {
939 /// extern Target TheFooTarget;
940 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
942 struct RegisterMCCodeGenInfoFn {
943 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
944 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
948 /// RegisterMCInstrInfo - Helper template for registering a target instruction
949 /// info implementation. This invokes the static "Create" method on the class
950 /// to actually do the construction. Usage:
952 /// extern "C" void LLVMInitializeFooTarget() {
953 /// extern Target TheFooTarget;
954 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
956 template <class MCInstrInfoImpl> struct RegisterMCInstrInfo {
957 RegisterMCInstrInfo(Target &T) {
958 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
962 static MCInstrInfo *Allocator() { return new MCInstrInfoImpl(); }
965 /// RegisterMCInstrInfoFn - Helper template for registering a target
966 /// instruction info implementation. This invokes the specified function to
967 /// do the construction. Usage:
969 /// extern "C" void LLVMInitializeFooTarget() {
970 /// extern Target TheFooTarget;
971 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
973 struct RegisterMCInstrInfoFn {
974 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
975 TargetRegistry::RegisterMCInstrInfo(T, Fn);
979 /// RegisterMCInstrAnalysis - Helper template for registering a target
980 /// instruction analyzer implementation. This invokes the static "Create"
981 /// method on the class to actually do the construction. Usage:
983 /// extern "C" void LLVMInitializeFooTarget() {
984 /// extern Target TheFooTarget;
985 /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
987 template <class MCInstrAnalysisImpl> struct RegisterMCInstrAnalysis {
988 RegisterMCInstrAnalysis(Target &T) {
989 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
993 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
994 return new MCInstrAnalysisImpl(Info);
998 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
999 /// instruction analyzer implementation. This invokes the specified function
1000 /// to do the construction. Usage:
1002 /// extern "C" void LLVMInitializeFooTarget() {
1003 /// extern Target TheFooTarget;
1004 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
1006 struct RegisterMCInstrAnalysisFn {
1007 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
1008 TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
1012 /// RegisterMCRegInfo - Helper template for registering a target register info
1013 /// implementation. This invokes the static "Create" method on the class to
1014 /// actually do the construction. Usage:
1016 /// extern "C" void LLVMInitializeFooTarget() {
1017 /// extern Target TheFooTarget;
1018 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
1020 template <class MCRegisterInfoImpl> struct RegisterMCRegInfo {
1021 RegisterMCRegInfo(Target &T) {
1022 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
1026 static MCRegisterInfo *Allocator(StringRef /*TT*/) {
1027 return new MCRegisterInfoImpl();
1031 /// RegisterMCRegInfoFn - Helper template for registering a target register
1032 /// info implementation. This invokes the specified function to do the
1033 /// construction. Usage:
1035 /// extern "C" void LLVMInitializeFooTarget() {
1036 /// extern Target TheFooTarget;
1037 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
1039 struct RegisterMCRegInfoFn {
1040 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
1041 TargetRegistry::RegisterMCRegInfo(T, Fn);
1045 /// RegisterMCSubtargetInfo - Helper template for registering a target
1046 /// subtarget info implementation. This invokes the static "Create" method
1047 /// on the class to actually do the construction. Usage:
1049 /// extern "C" void LLVMInitializeFooTarget() {
1050 /// extern Target TheFooTarget;
1051 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
1053 template <class MCSubtargetInfoImpl> struct RegisterMCSubtargetInfo {
1054 RegisterMCSubtargetInfo(Target &T) {
1055 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
1059 static MCSubtargetInfo *Allocator(const Triple & /*TT*/, StringRef /*CPU*/,
1061 return new MCSubtargetInfoImpl();
1065 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
1066 /// subtarget info implementation. This invokes the specified function to
1067 /// do the construction. Usage:
1069 /// extern "C" void LLVMInitializeFooTarget() {
1070 /// extern Target TheFooTarget;
1071 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1073 struct RegisterMCSubtargetInfoFn {
1074 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
1075 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
1079 /// RegisterTargetMachine - Helper template for registering a target machine
1080 /// implementation, for use in the target machine initialization
1081 /// function. Usage:
1083 /// extern "C" void LLVMInitializeFooTarget() {
1084 /// extern Target TheFooTarget;
1085 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1087 template <class TargetMachineImpl> struct RegisterTargetMachine {
1088 RegisterTargetMachine(Target &T) {
1089 TargetRegistry::RegisterTargetMachine(T, &Allocator);
1093 static TargetMachine *Allocator(const Target &T, StringRef TT, StringRef CPU,
1094 StringRef FS, const TargetOptions &Options,
1095 Reloc::Model RM, CodeModel::Model CM,
1096 CodeGenOpt::Level OL) {
1097 return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
1101 /// RegisterMCAsmBackend - Helper template for registering a target specific
1102 /// assembler backend. Usage:
1104 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1105 /// extern Target TheFooTarget;
1106 /// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1108 template <class MCAsmBackendImpl> struct RegisterMCAsmBackend {
1109 RegisterMCAsmBackend(Target &T) {
1110 TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1114 static MCAsmBackend *Allocator(const Target &T, const MCRegisterInfo &MRI,
1115 const Triple &TheTriple, StringRef CPU) {
1116 return new MCAsmBackendImpl(T, MRI, TheTriple, CPU);
1120 /// RegisterMCAsmParser - Helper template for registering a target specific
1121 /// assembly parser, for use in the target machine initialization
1122 /// function. Usage:
1124 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1125 /// extern Target TheFooTarget;
1126 /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1128 template <class MCAsmParserImpl> struct RegisterMCAsmParser {
1129 RegisterMCAsmParser(Target &T) {
1130 TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1134 static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P,
1135 const MCInstrInfo &MII,
1136 const MCTargetOptions &Options) {
1137 return new MCAsmParserImpl(STI, P, MII, Options);
1141 /// RegisterAsmPrinter - Helper template for registering a target specific
1142 /// assembly printer, for use in the target machine initialization
1143 /// function. Usage:
1145 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1146 /// extern Target TheFooTarget;
1147 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1149 template <class AsmPrinterImpl> struct RegisterAsmPrinter {
1150 RegisterAsmPrinter(Target &T) {
1151 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1155 static AsmPrinter *Allocator(TargetMachine &TM,
1156 std::unique_ptr<MCStreamer> &&Streamer) {
1157 return new AsmPrinterImpl(TM, std::move(Streamer));
1161 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1162 /// machine code emitter, for use in the target initialization
1163 /// function. Usage:
1165 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1166 /// extern Target TheFooTarget;
1167 /// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1169 template <class MCCodeEmitterImpl> struct RegisterMCCodeEmitter {
1170 RegisterMCCodeEmitter(Target &T) {
1171 TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1175 static MCCodeEmitter *Allocator(const MCInstrInfo & /*II*/,
1176 const MCRegisterInfo & /*MRI*/,
1177 MCContext & /*Ctx*/) {
1178 return new MCCodeEmitterImpl();