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"
39 class MCInstrAnalysis;
44 class MCSubtargetInfo;
46 class MCRelocationInfo;
47 class MCTargetAsmParser;
51 class formatted_raw_ostream;
53 MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
54 bool isVerboseAsm, bool useCFI,
55 bool useDwarfDirectory,
56 MCInstPrinter *InstPrint, MCCodeEmitter *CE,
57 MCAsmBackend *TAB, bool ShowInst);
59 MCRelocationInfo *createMCRelocationInfo(StringRef TT, MCContext &Ctx);
61 MCSymbolizer *createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
62 LLVMSymbolLookupCallback SymbolLookUp,
65 MCRelocationInfo *RelInfo);
67 /// Target - Wrapper for Target specific information.
69 /// For registration purposes, this is a POD type so that targets can be
70 /// registered without the use of static constructors.
72 /// Targets should implement a single global instance of this class (which
73 /// will be zero initialized), and pass that instance to the TargetRegistry as
74 /// part of their initialization.
77 friend struct TargetRegistry;
79 typedef bool (*ArchMatchFnTy)(Triple::ArchType Arch);
81 typedef MCAsmInfo *(*MCAsmInfoCtorFnTy)(const MCRegisterInfo &MRI,
83 typedef MCCodeGenInfo *(*MCCodeGenInfoCtorFnTy)(StringRef TT,
86 CodeGenOpt::Level OL);
87 typedef MCInstrInfo *(*MCInstrInfoCtorFnTy)(void);
88 typedef MCInstrAnalysis *(*MCInstrAnalysisCtorFnTy)(const MCInstrInfo*Info);
89 typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(StringRef TT);
90 typedef MCSubtargetInfo *(*MCSubtargetInfoCtorFnTy)(StringRef TT,
93 typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T,
97 const TargetOptions &Options,
100 CodeGenOpt::Level OL);
101 typedef AsmPrinter *(*AsmPrinterCtorTy)(TargetMachine &TM,
102 MCStreamer &Streamer);
103 typedef MCAsmBackend *(*MCAsmBackendCtorTy)(const Target &T,
104 const MCRegisterInfo &MRI,
107 typedef MCTargetAsmParser *(*MCAsmParserCtorTy)(MCSubtargetInfo &STI,
109 const MCInstrInfo &MII);
110 typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T,
111 const MCSubtargetInfo &STI);
112 typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
113 unsigned SyntaxVariant,
114 const MCAsmInfo &MAI,
115 const MCInstrInfo &MII,
116 const MCRegisterInfo &MRI,
117 const MCSubtargetInfo &STI);
118 typedef MCCodeEmitter *(*MCCodeEmitterCtorTy)(const MCInstrInfo &II,
119 const MCRegisterInfo &MRI,
120 const MCSubtargetInfo &STI,
122 typedef MCStreamer *(*MCObjectStreamerCtorTy)(const Target &T,
127 MCCodeEmitter *_Emitter,
128 const MCSubtargetInfo &STI,
131 typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx,
132 formatted_raw_ostream &OS,
135 bool useDwarfDirectory,
136 MCInstPrinter *InstPrint,
140 typedef MCRelocationInfo *(*MCRelocationInfoCtorTy)(StringRef TT,
142 typedef MCSymbolizer *(*MCSymbolizerCtorTy)(StringRef TT,
143 LLVMOpInfoCallback GetOpInfo,
144 LLVMSymbolLookupCallback SymbolLookUp,
147 MCRelocationInfo *RelInfo);
150 /// Next - The next registered target in the linked list, maintained by the
154 /// The target function for checking if an architecture is supported.
155 ArchMatchFnTy ArchMatchFn;
157 /// Name - The target name.
160 /// ShortDesc - A short description of the target.
161 const char *ShortDesc;
163 /// HasJIT - Whether this target supports the JIT.
166 /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
168 MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
170 /// MCCodeGenInfoCtorFn - Constructor function for this target's
171 /// MCCodeGenInfo, if registered.
172 MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn;
174 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
176 MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
178 /// MCInstrAnalysisCtorFn - Constructor function for this target's
179 /// MCInstrAnalysis, if registered.
180 MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
182 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
184 MCRegInfoCtorFnTy MCRegInfoCtorFn;
186 /// MCSubtargetInfoCtorFn - Constructor function for this target's
187 /// MCSubtargetInfo, if registered.
188 MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
190 /// TargetMachineCtorFn - Construction function for this target's
191 /// TargetMachine, if registered.
192 TargetMachineCtorTy TargetMachineCtorFn;
194 /// MCAsmBackendCtorFn - Construction function for this target's
195 /// MCAsmBackend, if registered.
196 MCAsmBackendCtorTy MCAsmBackendCtorFn;
198 /// MCAsmParserCtorFn - Construction function for this target's
199 /// MCTargetAsmParser, if registered.
200 MCAsmParserCtorTy MCAsmParserCtorFn;
202 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
204 AsmPrinterCtorTy AsmPrinterCtorFn;
206 /// MCDisassemblerCtorFn - Construction function for this target's
207 /// MCDisassembler, if registered.
208 MCDisassemblerCtorTy MCDisassemblerCtorFn;
210 /// MCInstPrinterCtorFn - Construction function for this target's
211 /// MCInstPrinter, if registered.
212 MCInstPrinterCtorTy MCInstPrinterCtorFn;
214 /// MCCodeEmitterCtorFn - Construction function for this target's
215 /// CodeEmitter, if registered.
216 MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
218 /// MCObjectStreamerCtorFn - Construction function for this target's
219 /// MCObjectStreamer, if registered.
220 MCObjectStreamerCtorTy MCObjectStreamerCtorFn;
222 /// AsmStreamerCtorFn - Construction function for this target's
223 /// AsmStreamer, if registered (default = llvm::createAsmStreamer).
224 AsmStreamerCtorTy AsmStreamerCtorFn;
226 /// MCRelocationInfoCtorFn - Construction function for this target's
227 /// MCRelocationInfo, if registered (default = llvm::createMCRelocationInfo)
228 MCRelocationInfoCtorTy MCRelocationInfoCtorFn;
230 /// MCSymbolizerCtorFn - Construction function for this target's
231 /// MCSymbolizer, if registered (default = llvm::createMCSymbolizer)
232 MCSymbolizerCtorTy MCSymbolizerCtorFn;
236 : AsmStreamerCtorFn(0), MCRelocationInfoCtorFn(0),
237 MCSymbolizerCtorFn(0) {}
239 /// @name Target Information
242 // getNext - Return the next registered target.
243 const Target *getNext() const { return Next; }
245 /// getName - Get the target name.
246 const char *getName() const { return Name; }
248 /// getShortDescription - Get a short description of the target.
249 const char *getShortDescription() const { return ShortDesc; }
252 /// @name Feature Predicates
255 /// hasJIT - Check if this targets supports the just-in-time compilation.
256 bool hasJIT() const { return HasJIT; }
258 /// hasTargetMachine - Check if this target supports code generation.
259 bool hasTargetMachine() const { return TargetMachineCtorFn != 0; }
261 /// hasMCAsmBackend - Check if this target supports .o generation.
262 bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != 0; }
265 /// @name Feature Constructors
268 /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
271 /// \param Triple This argument is used to determine the target machine
272 /// feature set; it should always be provided. Generally this should be
273 /// either the target triple from the module, or the target triple of the
274 /// host if that does not exist.
275 MCAsmInfo *createMCAsmInfo(const MCRegisterInfo &MRI,
276 StringRef Triple) const {
277 if (!MCAsmInfoCtorFn)
279 return MCAsmInfoCtorFn(MRI, Triple);
282 /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
284 MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model RM,
286 CodeGenOpt::Level OL) const {
287 if (!MCCodeGenInfoCtorFn)
289 return MCCodeGenInfoCtorFn(Triple, RM, CM, OL);
292 /// createMCInstrInfo - Create a MCInstrInfo implementation.
294 MCInstrInfo *createMCInstrInfo() const {
295 if (!MCInstrInfoCtorFn)
297 return MCInstrInfoCtorFn();
300 /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
302 MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
303 if (!MCInstrAnalysisCtorFn)
305 return MCInstrAnalysisCtorFn(Info);
308 /// createMCRegInfo - Create a MCRegisterInfo implementation.
310 MCRegisterInfo *createMCRegInfo(StringRef Triple) const {
311 if (!MCRegInfoCtorFn)
313 return MCRegInfoCtorFn(Triple);
316 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
318 /// \param Triple This argument is used to determine the target machine
319 /// feature set; it should always be provided. Generally this should be
320 /// either the target triple from the module, or the target triple of the
321 /// host if that does not exist.
322 /// \param CPU This specifies the name of the target CPU.
323 /// \param Features This specifies the string representation of the
324 /// additional target features.
325 MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU,
326 StringRef Features) const {
327 if (!MCSubtargetInfoCtorFn)
329 return MCSubtargetInfoCtorFn(Triple, CPU, Features);
332 /// createTargetMachine - Create a target specific machine implementation
333 /// for the specified \p Triple.
335 /// \param Triple This argument is used to determine the target machine
336 /// feature set; it should always be provided. Generally this should be
337 /// either the target triple from the module, or the target triple of the
338 /// host if that does not exist.
339 TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU,
340 StringRef Features, const TargetOptions &Options,
341 Reloc::Model RM = Reloc::Default,
342 CodeModel::Model CM = CodeModel::Default,
343 CodeGenOpt::Level OL = CodeGenOpt::Default) const {
344 if (!TargetMachineCtorFn)
346 return TargetMachineCtorFn(*this, Triple, CPU, Features, Options,
350 /// createMCAsmBackend - Create a target specific assembly parser.
352 /// \param Triple The target triple string.
353 MCAsmBackend *createMCAsmBackend(const MCRegisterInfo &MRI,
354 StringRef Triple, StringRef CPU) const {
355 if (!MCAsmBackendCtorFn)
357 return MCAsmBackendCtorFn(*this, MRI, Triple, CPU);
360 /// createMCAsmParser - Create a target specific assembly parser.
362 /// \param Parser The target independent parser implementation to use for
363 /// parsing and lexing.
364 MCTargetAsmParser *createMCAsmParser(MCSubtargetInfo &STI,
366 const MCInstrInfo &MII) const {
367 if (!MCAsmParserCtorFn)
369 return MCAsmParserCtorFn(STI, Parser, MII);
372 /// createAsmPrinter - Create a target specific assembly printer pass. This
373 /// takes ownership of the MCStreamer object.
374 AsmPrinter *createAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) const{
375 if (!AsmPrinterCtorFn)
377 return AsmPrinterCtorFn(TM, Streamer);
380 MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI) const {
381 if (!MCDisassemblerCtorFn)
383 return MCDisassemblerCtorFn(*this, STI);
386 MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
387 const MCAsmInfo &MAI,
388 const MCInstrInfo &MII,
389 const MCRegisterInfo &MRI,
390 const MCSubtargetInfo &STI) const {
391 if (!MCInstPrinterCtorFn)
393 return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, MII, MRI, STI);
397 /// createMCCodeEmitter - Create a target specific code emitter.
398 MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
399 const MCRegisterInfo &MRI,
400 const MCSubtargetInfo &STI,
401 MCContext &Ctx) const {
402 if (!MCCodeEmitterCtorFn)
404 return MCCodeEmitterCtorFn(II, MRI, STI, Ctx);
407 /// createMCObjectStreamer - Create a target specific MCStreamer.
409 /// \param TT The target triple.
410 /// \param Ctx The target context.
411 /// \param TAB The target assembler backend object. Takes ownership.
412 /// \param _OS The stream object.
413 /// \param _Emitter The target independent assembler object.Takes ownership.
414 /// \param RelaxAll Relax all fixups?
415 /// \param NoExecStack Mark file as not needing a executable stack.
416 MCStreamer *createMCObjectStreamer(StringRef TT, MCContext &Ctx,
419 MCCodeEmitter *_Emitter,
420 const MCSubtargetInfo &STI,
422 bool NoExecStack) const {
423 if (!MCObjectStreamerCtorFn)
425 return MCObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter, STI,
426 RelaxAll, NoExecStack);
429 /// createAsmStreamer - Create a target specific MCStreamer.
430 MCStreamer *createAsmStreamer(MCContext &Ctx,
431 formatted_raw_ostream &OS,
434 bool useDwarfDirectory,
435 MCInstPrinter *InstPrint,
438 bool ShowInst) const {
439 if (AsmStreamerCtorFn)
440 return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useCFI,
441 useDwarfDirectory, InstPrint, CE, TAB,
443 return llvm::createAsmStreamer(Ctx, OS, isVerboseAsm, useCFI,
444 useDwarfDirectory, InstPrint, CE, TAB,
448 /// createMCRelocationInfo - Create a target specific MCRelocationInfo.
450 /// \param TT The target triple.
451 /// \param Ctx The target context.
453 createMCRelocationInfo(StringRef TT, MCContext &Ctx) const {
454 MCRelocationInfoCtorTy Fn = MCRelocationInfoCtorFn
455 ? MCRelocationInfoCtorFn
456 : llvm::createMCRelocationInfo;
460 /// createMCSymbolizer - Create a target specific MCSymbolizer.
462 /// \param TT The target triple.
463 /// \param GetOpInfo The function to get the symbolic information for operands.
464 /// \param SymbolLookUp The function to lookup a symbol name.
465 /// \param DisInfo The pointer to the block of symbolic information for above call
467 /// \param Ctx The target context.
468 /// \param RelInfo The relocation information for this target. Takes ownership.
470 createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
471 LLVMSymbolLookupCallback SymbolLookUp,
473 MCContext *Ctx, MCRelocationInfo *RelInfo) const {
474 MCSymbolizerCtorTy Fn =
475 MCSymbolizerCtorFn ? MCSymbolizerCtorFn : llvm::createMCSymbolizer;
476 return Fn(TT, GetOpInfo, SymbolLookUp, DisInfo, Ctx, RelInfo);
482 /// TargetRegistry - Generic interface to target specific features.
483 struct TargetRegistry {
485 const Target *Current;
486 explicit iterator(Target *T) : Current(T) {}
487 friend struct TargetRegistry;
489 iterator(const iterator &I) : Current(I.Current) {}
490 iterator() : Current(0) {}
492 bool operator==(const iterator &x) const {
493 return Current == x.Current;
495 bool operator!=(const iterator &x) const {
496 return !operator==(x);
499 // Iterator traversal: forward iteration only
500 iterator &operator++() { // Preincrement
501 assert(Current && "Cannot increment end iterator!");
502 Current = Current->getNext();
505 iterator operator++(int) { // Postincrement
506 iterator tmp = *this;
511 const Target &operator*() const {
512 assert(Current && "Cannot dereference end iterator!");
516 const Target *operator->() const {
521 /// printRegisteredTargetsForVersion - Print the registered targets
522 /// appropriately for inclusion in a tool's version output.
523 static void printRegisteredTargetsForVersion();
525 /// @name Registry Access
528 static iterator begin();
530 static iterator end() { return iterator(); }
532 /// lookupTarget - Lookup a target based on a target triple.
534 /// \param Triple - The triple to use for finding a target.
535 /// \param Error - On failure, an error string describing why no target was
537 static const Target *lookupTarget(const std::string &Triple,
540 /// lookupTarget - Lookup a target based on an architecture name
541 /// and a target triple. If the architecture name is non-empty,
542 /// then the lookup is done by architecture. Otherwise, the target
545 /// \param ArchName - The architecture to use for finding a target.
546 /// \param TheTriple - The triple to use for finding a target. The
547 /// triple is updated with canonical architecture name if a lookup
548 /// by architecture is done.
549 /// \param Error - On failure, an error string describing why no target was
551 static const Target *lookupTarget(const std::string &ArchName,
555 /// getClosestTargetForJIT - Pick the best target that is compatible with
556 /// the current host. If no close target can be found, this returns null
557 /// and sets the Error string to a reason.
559 /// Maintained for compatibility through 2.6.
560 static const Target *getClosestTargetForJIT(std::string &Error);
563 /// @name Target Registration
566 /// RegisterTarget - Register the given target. Attempts to register a
567 /// target which has already been registered will be ignored.
569 /// Clients are responsible for ensuring that registration doesn't occur
570 /// while another thread is attempting to access the registry. Typically
571 /// this is done by initializing all targets at program startup.
573 /// @param T - The target being registered.
574 /// @param Name - The target name. This should be a static string.
575 /// @param ShortDesc - A short target description. This should be a static
577 /// @param ArchMatchFn - The arch match checking function for this target.
578 /// @param HasJIT - Whether the target supports JIT code
580 static void RegisterTarget(Target &T,
582 const char *ShortDesc,
583 Target::ArchMatchFnTy ArchMatchFn,
584 bool HasJIT = false);
586 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
589 /// Clients are responsible for ensuring that registration doesn't occur
590 /// while another thread is attempting to access the registry. Typically
591 /// this is done by initializing all targets at program startup.
593 /// @param T - The target being registered.
594 /// @param Fn - A function to construct a MCAsmInfo for the target.
595 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
596 T.MCAsmInfoCtorFn = Fn;
599 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
602 /// Clients are responsible for ensuring that registration doesn't occur
603 /// while another thread is attempting to access the registry. Typically
604 /// this is done by initializing all targets at program startup.
606 /// @param T - The target being registered.
607 /// @param Fn - A function to construct a MCCodeGenInfo for the target.
608 static void RegisterMCCodeGenInfo(Target &T,
609 Target::MCCodeGenInfoCtorFnTy Fn) {
610 T.MCCodeGenInfoCtorFn = Fn;
613 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
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 Fn - A function to construct a MCInstrInfo for the target.
622 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
623 T.MCInstrInfoCtorFn = Fn;
626 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
627 /// the given target.
628 static void RegisterMCInstrAnalysis(Target &T,
629 Target::MCInstrAnalysisCtorFnTy Fn) {
630 T.MCInstrAnalysisCtorFn = Fn;
633 /// RegisterMCRegInfo - Register a MCRegisterInfo 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 MCRegisterInfo for the target.
642 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
643 T.MCRegInfoCtorFn = Fn;
646 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
647 /// the given target.
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 MCSubtargetInfo for the target.
655 static void RegisterMCSubtargetInfo(Target &T,
656 Target::MCSubtargetInfoCtorFnTy Fn) {
657 T.MCSubtargetInfoCtorFn = Fn;
660 /// RegisterTargetMachine - Register a TargetMachine 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 TargetMachine for the target.
669 static void RegisterTargetMachine(Target &T,
670 Target::TargetMachineCtorTy Fn) {
671 T.TargetMachineCtorFn = Fn;
674 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
677 /// Clients are responsible for ensuring that registration doesn't occur
678 /// while another thread is attempting to access the registry. Typically
679 /// this is done by initializing all targets at program startup.
681 /// @param T - The target being registered.
682 /// @param Fn - A function to construct an AsmBackend for the target.
683 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
684 T.MCAsmBackendCtorFn = Fn;
687 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
688 /// the given target.
690 /// Clients are responsible for ensuring that registration doesn't occur
691 /// while another thread is attempting to access the registry. Typically
692 /// this is done by initializing all targets at program startup.
694 /// @param T - The target being registered.
695 /// @param Fn - A function to construct an MCTargetAsmParser for the target.
696 static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
697 T.MCAsmParserCtorFn = Fn;
700 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
703 /// Clients are responsible for ensuring that registration doesn't occur
704 /// while another thread is attempting to access the registry. Typically
705 /// this is done by initializing all targets at program startup.
707 /// @param T - The target being registered.
708 /// @param Fn - A function to construct an AsmPrinter for the target.
709 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
710 T.AsmPrinterCtorFn = Fn;
713 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
714 /// the given target.
716 /// Clients are responsible for ensuring that registration doesn't occur
717 /// while another thread is attempting to access the registry. Typically
718 /// this is done by initializing all targets at program startup.
720 /// @param T - The target being registered.
721 /// @param Fn - A function to construct an MCDisassembler for the target.
722 static void RegisterMCDisassembler(Target &T,
723 Target::MCDisassemblerCtorTy Fn) {
724 T.MCDisassemblerCtorFn = Fn;
727 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
730 /// Clients are responsible for ensuring that registration doesn't occur
731 /// while another thread is attempting to access the registry. Typically
732 /// this is done by initializing all targets at program startup.
734 /// @param T - The target being registered.
735 /// @param Fn - A function to construct an MCInstPrinter for the target.
736 static void RegisterMCInstPrinter(Target &T,
737 Target::MCInstPrinterCtorTy Fn) {
738 T.MCInstPrinterCtorFn = Fn;
741 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
744 /// Clients are responsible for ensuring that registration doesn't occur
745 /// while another thread is attempting to access the registry. Typically
746 /// this is done by initializing all targets at program startup.
748 /// @param T - The target being registered.
749 /// @param Fn - A function to construct an MCCodeEmitter for the target.
750 static void RegisterMCCodeEmitter(Target &T,
751 Target::MCCodeEmitterCtorTy Fn) {
752 T.MCCodeEmitterCtorFn = Fn;
755 /// RegisterMCObjectStreamer - Register a object code MCStreamer
756 /// implementation for the given target.
758 /// Clients are responsible for ensuring that registration doesn't occur
759 /// while another thread is attempting to access the registry. Typically
760 /// this is done by initializing all targets at program startup.
762 /// @param T - The target being registered.
763 /// @param Fn - A function to construct an MCStreamer for the target.
764 static void RegisterMCObjectStreamer(Target &T,
765 Target::MCObjectStreamerCtorTy Fn) {
766 T.MCObjectStreamerCtorFn = Fn;
769 /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
770 /// for the given target.
772 /// Clients are responsible for ensuring that registration doesn't occur
773 /// while another thread is attempting to access the registry. Typically
774 /// this is done by initializing all targets at program startup.
776 /// @param T - The target being registered.
777 /// @param Fn - A function to construct an MCStreamer for the target.
778 static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
779 T.AsmStreamerCtorFn = Fn;
782 /// RegisterMCRelocationInfo - Register an MCRelocationInfo
783 /// implementation for the given target.
785 /// Clients are responsible for ensuring that registration doesn't occur
786 /// while another thread is attempting to access the registry. Typically
787 /// this is done by initializing all targets at program startup.
789 /// @param T - The target being registered.
790 /// @param Fn - A function to construct an MCRelocationInfo for the target.
791 static void RegisterMCRelocationInfo(Target &T,
792 Target::MCRelocationInfoCtorTy Fn) {
793 T.MCRelocationInfoCtorFn = Fn;
796 /// RegisterMCSymbolizer - Register an MCSymbolizer
797 /// implementation for the given target.
799 /// Clients are responsible for ensuring that registration doesn't occur
800 /// while another thread is attempting to access the registry. Typically
801 /// this is done by initializing all targets at program startup.
803 /// @param T - The target being registered.
804 /// @param Fn - A function to construct an MCSymbolizer for the target.
805 static void RegisterMCSymbolizer(Target &T,
806 Target::MCSymbolizerCtorTy Fn) {
807 T.MCSymbolizerCtorFn = Fn;
814 //===--------------------------------------------------------------------===//
816 /// RegisterTarget - Helper template for registering a target, for use in the
817 /// target's initialization function. Usage:
820 /// Target TheFooTarget; // The global target instance.
822 /// extern "C" void LLVMInitializeFooTargetInfo() {
823 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
825 template<Triple::ArchType TargetArchType = Triple::UnknownArch,
827 struct RegisterTarget {
828 RegisterTarget(Target &T, const char *Name, const char *Desc) {
829 TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch, HasJIT);
832 static bool getArchMatch(Triple::ArchType Arch) {
833 return Arch == TargetArchType;
837 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
838 /// implementation. This invokes the static "Create" method on the class to
839 /// actually do the construction. Usage:
841 /// extern "C" void LLVMInitializeFooTarget() {
842 /// extern Target TheFooTarget;
843 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
845 template<class MCAsmInfoImpl>
846 struct RegisterMCAsmInfo {
847 RegisterMCAsmInfo(Target &T) {
848 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
851 static MCAsmInfo *Allocator(const MCRegisterInfo &/*MRI*/, StringRef TT) {
852 return new MCAsmInfoImpl(TT);
857 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
858 /// implementation. This invokes the specified function to do the
859 /// construction. Usage:
861 /// extern "C" void LLVMInitializeFooTarget() {
862 /// extern Target TheFooTarget;
863 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
865 struct RegisterMCAsmInfoFn {
866 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
867 TargetRegistry::RegisterMCAsmInfo(T, Fn);
871 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
872 /// implementation. This invokes the static "Create" method on the class
873 /// to actually do the construction. Usage:
875 /// extern "C" void LLVMInitializeFooTarget() {
876 /// extern Target TheFooTarget;
877 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
879 template<class MCCodeGenInfoImpl>
880 struct RegisterMCCodeGenInfo {
881 RegisterMCCodeGenInfo(Target &T) {
882 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
885 static MCCodeGenInfo *Allocator(StringRef /*TT*/, Reloc::Model /*RM*/,
886 CodeModel::Model /*CM*/,
887 CodeGenOpt::Level /*OL*/) {
888 return new MCCodeGenInfoImpl();
892 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
893 /// info implementation. This invokes the specified function to do the
894 /// construction. Usage:
896 /// extern "C" void LLVMInitializeFooTarget() {
897 /// extern Target TheFooTarget;
898 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
900 struct RegisterMCCodeGenInfoFn {
901 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
902 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
906 /// RegisterMCInstrInfo - Helper template for registering a target instruction
907 /// info implementation. This invokes the static "Create" method on the class
908 /// to actually do the construction. Usage:
910 /// extern "C" void LLVMInitializeFooTarget() {
911 /// extern Target TheFooTarget;
912 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
914 template<class MCInstrInfoImpl>
915 struct RegisterMCInstrInfo {
916 RegisterMCInstrInfo(Target &T) {
917 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
920 static MCInstrInfo *Allocator() {
921 return new MCInstrInfoImpl();
925 /// RegisterMCInstrInfoFn - Helper template for registering a target
926 /// instruction info implementation. This invokes the specified function to
927 /// do the construction. Usage:
929 /// extern "C" void LLVMInitializeFooTarget() {
930 /// extern Target TheFooTarget;
931 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
933 struct RegisterMCInstrInfoFn {
934 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
935 TargetRegistry::RegisterMCInstrInfo(T, Fn);
939 /// RegisterMCInstrAnalysis - Helper template for registering a target
940 /// instruction analyzer implementation. This invokes the static "Create"
941 /// method on the class to actually do the construction. Usage:
943 /// extern "C" void LLVMInitializeFooTarget() {
944 /// extern Target TheFooTarget;
945 /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
947 template<class MCInstrAnalysisImpl>
948 struct RegisterMCInstrAnalysis {
949 RegisterMCInstrAnalysis(Target &T) {
950 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
953 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
954 return new MCInstrAnalysisImpl(Info);
958 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
959 /// instruction analyzer implementation. This invokes the specified function
960 /// to do the construction. Usage:
962 /// extern "C" void LLVMInitializeFooTarget() {
963 /// extern Target TheFooTarget;
964 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
966 struct RegisterMCInstrAnalysisFn {
967 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
968 TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
972 /// RegisterMCRegInfo - Helper template for registering a target register info
973 /// implementation. This invokes the static "Create" method on the class to
974 /// actually do the construction. Usage:
976 /// extern "C" void LLVMInitializeFooTarget() {
977 /// extern Target TheFooTarget;
978 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
980 template<class MCRegisterInfoImpl>
981 struct RegisterMCRegInfo {
982 RegisterMCRegInfo(Target &T) {
983 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
986 static MCRegisterInfo *Allocator(StringRef /*TT*/) {
987 return new MCRegisterInfoImpl();
991 /// RegisterMCRegInfoFn - Helper template for registering a target register
992 /// info implementation. This invokes the specified function to do the
993 /// construction. Usage:
995 /// extern "C" void LLVMInitializeFooTarget() {
996 /// extern Target TheFooTarget;
997 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
999 struct RegisterMCRegInfoFn {
1000 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
1001 TargetRegistry::RegisterMCRegInfo(T, Fn);
1005 /// RegisterMCSubtargetInfo - Helper template for registering a target
1006 /// subtarget info implementation. This invokes the static "Create" method
1007 /// on the class to actually do the construction. Usage:
1009 /// extern "C" void LLVMInitializeFooTarget() {
1010 /// extern Target TheFooTarget;
1011 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
1013 template<class MCSubtargetInfoImpl>
1014 struct RegisterMCSubtargetInfo {
1015 RegisterMCSubtargetInfo(Target &T) {
1016 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
1019 static MCSubtargetInfo *Allocator(StringRef /*TT*/, StringRef /*CPU*/,
1021 return new MCSubtargetInfoImpl();
1025 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
1026 /// subtarget info implementation. This invokes the specified function to
1027 /// do the construction. Usage:
1029 /// extern "C" void LLVMInitializeFooTarget() {
1030 /// extern Target TheFooTarget;
1031 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1033 struct RegisterMCSubtargetInfoFn {
1034 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
1035 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
1039 /// RegisterTargetMachine - Helper template for registering a target machine
1040 /// implementation, for use in the target machine initialization
1041 /// function. Usage:
1043 /// extern "C" void LLVMInitializeFooTarget() {
1044 /// extern Target TheFooTarget;
1045 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1047 template<class TargetMachineImpl>
1048 struct RegisterTargetMachine {
1049 RegisterTargetMachine(Target &T) {
1050 TargetRegistry::RegisterTargetMachine(T, &Allocator);
1054 static TargetMachine *Allocator(const Target &T, StringRef TT,
1055 StringRef CPU, StringRef FS,
1056 const TargetOptions &Options,
1058 CodeModel::Model CM,
1059 CodeGenOpt::Level OL) {
1060 return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
1064 /// RegisterMCAsmBackend - Helper template for registering a target specific
1065 /// assembler backend. Usage:
1067 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1068 /// extern Target TheFooTarget;
1069 /// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1071 template<class MCAsmBackendImpl>
1072 struct RegisterMCAsmBackend {
1073 RegisterMCAsmBackend(Target &T) {
1074 TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1078 static MCAsmBackend *Allocator(const Target &T,
1079 const MCRegisterInfo &MRI,
1080 StringRef Triple, StringRef CPU) {
1081 return new MCAsmBackendImpl(T, MRI, Triple, CPU);
1085 /// RegisterMCAsmParser - Helper template for registering a target specific
1086 /// assembly parser, for use in the target machine initialization
1087 /// function. Usage:
1089 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1090 /// extern Target TheFooTarget;
1091 /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1093 template<class MCAsmParserImpl>
1094 struct RegisterMCAsmParser {
1095 RegisterMCAsmParser(Target &T) {
1096 TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1100 static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P,
1101 const MCInstrInfo &MII) {
1102 return new MCAsmParserImpl(STI, P, MII);
1106 /// RegisterAsmPrinter - Helper template for registering a target specific
1107 /// assembly printer, for use in the target machine initialization
1108 /// function. Usage:
1110 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1111 /// extern Target TheFooTarget;
1112 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1114 template<class AsmPrinterImpl>
1115 struct RegisterAsmPrinter {
1116 RegisterAsmPrinter(Target &T) {
1117 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1121 static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) {
1122 return new AsmPrinterImpl(TM, Streamer);
1126 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1127 /// machine code emitter, for use in the target initialization
1128 /// function. Usage:
1130 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1131 /// extern Target TheFooTarget;
1132 /// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1134 template<class MCCodeEmitterImpl>
1135 struct RegisterMCCodeEmitter {
1136 RegisterMCCodeEmitter(Target &T) {
1137 TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1141 static MCCodeEmitter *Allocator(const MCInstrInfo &/*II*/,
1142 const MCRegisterInfo &/*MRI*/,
1143 const MCSubtargetInfo &/*STI*/,
1144 MCContext &/*Ctx*/) {
1145 return new MCCodeEmitterImpl();