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,
54 formatted_raw_ostream &OS, bool isVerboseAsm,
55 bool useLoc, bool useCFI,
56 bool useDwarfDirectory,
57 MCInstPrinter *InstPrint, MCCodeEmitter *CE,
58 MCAsmBackend *TAB, bool ShowInst);
60 MCRelocationInfo *createMCRelocationInfo(StringRef TT, MCContext &Ctx);
62 MCSymbolizer *createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
63 LLVMSymbolLookupCallback SymbolLookUp,
66 MCRelocationInfo *RelInfo);
68 /// Target - Wrapper for Target specific information.
70 /// For registration purposes, this is a POD type so that targets can be
71 /// registered without the use of static constructors.
73 /// Targets should implement a single global instance of this class (which
74 /// will be zero initialized), and pass that instance to the TargetRegistry as
75 /// part of their initialization.
78 friend struct TargetRegistry;
80 typedef bool (*ArchMatchFnTy)(Triple::ArchType Arch);
82 typedef MCAsmInfo *(*MCAsmInfoCtorFnTy)(const MCRegisterInfo &MRI,
84 typedef MCCodeGenInfo *(*MCCodeGenInfoCtorFnTy)(StringRef TT,
87 CodeGenOpt::Level OL);
88 typedef MCInstrInfo *(*MCInstrInfoCtorFnTy)(void);
89 typedef MCInstrAnalysis *(*MCInstrAnalysisCtorFnTy)(const MCInstrInfo*Info);
90 typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(StringRef TT);
91 typedef MCSubtargetInfo *(*MCSubtargetInfoCtorFnTy)(StringRef TT,
94 typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T,
98 const TargetOptions &Options,
101 CodeGenOpt::Level OL);
102 typedef AsmPrinter *(*AsmPrinterCtorTy)(TargetMachine &TM,
103 MCStreamer &Streamer);
104 typedef MCAsmBackend *(*MCAsmBackendCtorTy)(const Target &T,
105 const MCRegisterInfo &MRI,
108 typedef MCTargetAsmParser *(*MCAsmParserCtorTy)(MCSubtargetInfo &STI,
110 const MCInstrInfo &MII);
111 typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T,
112 const MCSubtargetInfo &STI);
113 typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
114 unsigned SyntaxVariant,
115 const MCAsmInfo &MAI,
116 const MCInstrInfo &MII,
117 const MCRegisterInfo &MRI,
118 const MCSubtargetInfo &STI);
119 typedef MCCodeEmitter *(*MCCodeEmitterCtorTy)(const MCInstrInfo &II,
120 const MCRegisterInfo &MRI,
121 const MCSubtargetInfo &STI,
123 typedef MCStreamer *(*MCObjectStreamerCtorTy)(const Target &T,
128 MCCodeEmitter *_Emitter,
129 const MCSubtargetInfo &STI,
132 typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx,
133 formatted_raw_ostream &OS,
137 bool useDwarfDirectory,
138 MCInstPrinter *InstPrint,
142 typedef MCRelocationInfo *(*MCRelocationInfoCtorTy)(StringRef TT,
144 typedef MCSymbolizer *(*MCSymbolizerCtorTy)(StringRef TT,
145 LLVMOpInfoCallback GetOpInfo,
146 LLVMSymbolLookupCallback SymbolLookUp,
149 MCRelocationInfo *RelInfo);
152 /// Next - The next registered target in the linked list, maintained by the
156 /// The target function for checking if an architecture is supported.
157 ArchMatchFnTy ArchMatchFn;
159 /// Name - The target name.
162 /// ShortDesc - A short description of the target.
163 const char *ShortDesc;
165 /// HasJIT - Whether this target supports the JIT.
168 /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
170 MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
172 /// MCCodeGenInfoCtorFn - Constructor function for this target's
173 /// MCCodeGenInfo, if registered.
174 MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn;
176 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
178 MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
180 /// MCInstrAnalysisCtorFn - Constructor function for this target's
181 /// MCInstrAnalysis, if registered.
182 MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
184 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
186 MCRegInfoCtorFnTy MCRegInfoCtorFn;
188 /// MCSubtargetInfoCtorFn - Constructor function for this target's
189 /// MCSubtargetInfo, if registered.
190 MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
192 /// TargetMachineCtorFn - Construction function for this target's
193 /// TargetMachine, if registered.
194 TargetMachineCtorTy TargetMachineCtorFn;
196 /// MCAsmBackendCtorFn - Construction function for this target's
197 /// MCAsmBackend, if registered.
198 MCAsmBackendCtorTy MCAsmBackendCtorFn;
200 /// MCAsmParserCtorFn - Construction function for this target's
201 /// MCTargetAsmParser, if registered.
202 MCAsmParserCtorTy MCAsmParserCtorFn;
204 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
206 AsmPrinterCtorTy AsmPrinterCtorFn;
208 /// MCDisassemblerCtorFn - Construction function for this target's
209 /// MCDisassembler, if registered.
210 MCDisassemblerCtorTy MCDisassemblerCtorFn;
212 /// MCInstPrinterCtorFn - Construction function for this target's
213 /// MCInstPrinter, if registered.
214 MCInstPrinterCtorTy MCInstPrinterCtorFn;
216 /// MCCodeEmitterCtorFn - Construction function for this target's
217 /// CodeEmitter, if registered.
218 MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
220 /// MCObjectStreamerCtorFn - Construction function for this target's
221 /// MCObjectStreamer, if registered.
222 MCObjectStreamerCtorTy MCObjectStreamerCtorFn;
224 /// AsmStreamerCtorFn - Construction function for this target's
225 /// AsmStreamer, if registered (default = llvm::createAsmStreamer).
226 AsmStreamerCtorTy AsmStreamerCtorFn;
228 /// MCRelocationInfoCtorFn - Construction function for this target's
229 /// MCRelocationInfo, if registered (default = llvm::createMCRelocationInfo)
230 MCRelocationInfoCtorTy MCRelocationInfoCtorFn;
232 /// MCSymbolizerCtorFn - Construction function for this target's
233 /// MCSymbolizer, if registered (default = llvm::createMCSymbolizer)
234 MCSymbolizerCtorTy MCSymbolizerCtorFn;
238 : AsmStreamerCtorFn(0), MCRelocationInfoCtorFn(0),
239 MCSymbolizerCtorFn(0) {}
241 /// @name Target Information
244 // getNext - Return the next registered target.
245 const Target *getNext() const { return Next; }
247 /// getName - Get the target name.
248 const char *getName() const { return Name; }
250 /// getShortDescription - Get a short description of the target.
251 const char *getShortDescription() const { return ShortDesc; }
254 /// @name Feature Predicates
257 /// hasJIT - Check if this targets supports the just-in-time compilation.
258 bool hasJIT() const { return HasJIT; }
260 /// hasTargetMachine - Check if this target supports code generation.
261 bool hasTargetMachine() const { return TargetMachineCtorFn != 0; }
263 /// hasMCAsmBackend - Check if this target supports .o generation.
264 bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != 0; }
267 /// @name Feature Constructors
270 /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
273 /// \param Triple This argument is used to determine the target machine
274 /// feature set; it should always be provided. Generally this should be
275 /// either the target triple from the module, or the target triple of the
276 /// host if that does not exist.
277 MCAsmInfo *createMCAsmInfo(const MCRegisterInfo &MRI,
278 StringRef Triple) const {
279 if (!MCAsmInfoCtorFn)
281 return MCAsmInfoCtorFn(MRI, Triple);
284 /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
286 MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model RM,
288 CodeGenOpt::Level OL) const {
289 if (!MCCodeGenInfoCtorFn)
291 return MCCodeGenInfoCtorFn(Triple, RM, CM, OL);
294 /// createMCInstrInfo - Create a MCInstrInfo implementation.
296 MCInstrInfo *createMCInstrInfo() const {
297 if (!MCInstrInfoCtorFn)
299 return MCInstrInfoCtorFn();
302 /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
304 MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
305 if (!MCInstrAnalysisCtorFn)
307 return MCInstrAnalysisCtorFn(Info);
310 /// createMCRegInfo - Create a MCRegisterInfo implementation.
312 MCRegisterInfo *createMCRegInfo(StringRef Triple) const {
313 if (!MCRegInfoCtorFn)
315 return MCRegInfoCtorFn(Triple);
318 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
320 /// \param Triple This argument is used to determine the target machine
321 /// feature set; it should always be provided. Generally this should be
322 /// either the target triple from the module, or the target triple of the
323 /// host if that does not exist.
324 /// \param CPU This specifies the name of the target CPU.
325 /// \param Features This specifies the string representation of the
326 /// additional target features.
327 MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU,
328 StringRef Features) const {
329 if (!MCSubtargetInfoCtorFn)
331 return MCSubtargetInfoCtorFn(Triple, CPU, Features);
334 /// createTargetMachine - Create a target specific machine implementation
335 /// for the specified \p Triple.
337 /// \param Triple 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 TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU,
342 StringRef Features, const TargetOptions &Options,
343 Reloc::Model RM = Reloc::Default,
344 CodeModel::Model CM = CodeModel::Default,
345 CodeGenOpt::Level OL = CodeGenOpt::Default) const {
346 if (!TargetMachineCtorFn)
348 return TargetMachineCtorFn(*this, Triple, CPU, Features, Options,
352 /// createMCAsmBackend - Create a target specific assembly parser.
354 /// \param Triple The target triple string.
355 MCAsmBackend *createMCAsmBackend(const MCRegisterInfo &MRI,
356 StringRef Triple, StringRef CPU) const {
357 if (!MCAsmBackendCtorFn)
359 return MCAsmBackendCtorFn(*this, MRI, Triple, CPU);
362 /// createMCAsmParser - Create a target specific assembly parser.
364 /// \param Parser The target independent parser implementation to use for
365 /// parsing and lexing.
366 MCTargetAsmParser *createMCAsmParser(MCSubtargetInfo &STI,
368 const MCInstrInfo &MII) const {
369 if (!MCAsmParserCtorFn)
371 return MCAsmParserCtorFn(STI, Parser, MII);
374 /// createAsmPrinter - Create a target specific assembly printer pass. This
375 /// takes ownership of the MCStreamer object.
376 AsmPrinter *createAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) const{
377 if (!AsmPrinterCtorFn)
379 return AsmPrinterCtorFn(TM, Streamer);
382 MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI) const {
383 if (!MCDisassemblerCtorFn)
385 return MCDisassemblerCtorFn(*this, STI);
388 MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
389 const MCAsmInfo &MAI,
390 const MCInstrInfo &MII,
391 const MCRegisterInfo &MRI,
392 const MCSubtargetInfo &STI) const {
393 if (!MCInstPrinterCtorFn)
395 return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, MII, MRI, STI);
399 /// createMCCodeEmitter - Create a target specific code emitter.
400 MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
401 const MCRegisterInfo &MRI,
402 const MCSubtargetInfo &STI,
403 MCContext &Ctx) const {
404 if (!MCCodeEmitterCtorFn)
406 return MCCodeEmitterCtorFn(II, MRI, STI, Ctx);
409 /// createMCObjectStreamer - Create a target specific MCStreamer.
411 /// \param TT The target triple.
412 /// \param Ctx The target context.
413 /// \param TAB The target assembler backend object. Takes ownership.
414 /// \param _OS The stream object.
415 /// \param _Emitter The target independent assembler object.Takes ownership.
416 /// \param RelaxAll Relax all fixups?
417 /// \param NoExecStack Mark file as not needing a executable stack.
418 MCStreamer *createMCObjectStreamer(StringRef TT, MCContext &Ctx,
421 MCCodeEmitter *_Emitter,
422 const MCSubtargetInfo &STI,
424 bool NoExecStack) const {
425 if (!MCObjectStreamerCtorFn)
427 return MCObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter, STI,
428 RelaxAll, NoExecStack);
431 /// createAsmStreamer - Create a target specific MCStreamer.
432 MCStreamer *createAsmStreamer(MCContext &Ctx,
433 formatted_raw_ostream &OS,
437 bool useDwarfDirectory,
438 MCInstPrinter *InstPrint,
441 bool ShowInst) const {
442 if (AsmStreamerCtorFn)
443 return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useLoc, useCFI,
444 useDwarfDirectory, InstPrint, CE, TAB,
446 return llvm::createAsmStreamer(Ctx, OS, isVerboseAsm, useLoc, useCFI,
447 useDwarfDirectory, InstPrint, CE, TAB,
451 /// createMCRelocationInfo - Create a target specific MCRelocationInfo.
453 /// \param TT The target triple.
454 /// \param Ctx The target context.
456 createMCRelocationInfo(StringRef TT, MCContext &Ctx) const {
457 MCRelocationInfoCtorTy Fn = MCRelocationInfoCtorFn
458 ? MCRelocationInfoCtorFn
459 : llvm::createMCRelocationInfo;
463 /// createMCSymbolizer - Create a target specific MCSymbolizer.
465 /// \param TT The target triple.
466 /// \param GetOpInfo The function to get the symbolic information for operands.
467 /// \param SymbolLookUp The function to lookup a symbol name.
468 /// \param DisInfo The pointer to the block of symbolic information for above call
470 /// \param Ctx The target context.
471 /// \param RelInfo The relocation information for this target. Takes ownership.
473 createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
474 LLVMSymbolLookupCallback SymbolLookUp,
476 MCContext *Ctx, MCRelocationInfo *RelInfo) const {
477 MCSymbolizerCtorTy Fn =
478 MCSymbolizerCtorFn ? MCSymbolizerCtorFn : llvm::createMCSymbolizer;
479 return Fn(TT, GetOpInfo, SymbolLookUp, DisInfo, Ctx, RelInfo);
485 /// TargetRegistry - Generic interface to target specific features.
486 struct TargetRegistry {
488 const Target *Current;
489 explicit iterator(Target *T) : Current(T) {}
490 friend struct TargetRegistry;
492 iterator(const iterator &I) : Current(I.Current) {}
493 iterator() : Current(0) {}
495 bool operator==(const iterator &x) const {
496 return Current == x.Current;
498 bool operator!=(const iterator &x) const {
499 return !operator==(x);
502 // Iterator traversal: forward iteration only
503 iterator &operator++() { // Preincrement
504 assert(Current && "Cannot increment end iterator!");
505 Current = Current->getNext();
508 iterator operator++(int) { // Postincrement
509 iterator tmp = *this;
514 const Target &operator*() const {
515 assert(Current && "Cannot dereference end iterator!");
519 const Target *operator->() const {
524 /// printRegisteredTargetsForVersion - Print the registered targets
525 /// appropriately for inclusion in a tool's version output.
526 static void printRegisteredTargetsForVersion();
528 /// @name Registry Access
531 static iterator begin();
533 static iterator end() { return iterator(); }
535 /// lookupTarget - Lookup a target based on a target triple.
537 /// \param Triple - The triple to use for finding a target.
538 /// \param Error - On failure, an error string describing why no target was
540 static const Target *lookupTarget(const std::string &Triple,
543 /// lookupTarget - Lookup a target based on an architecture name
544 /// and a target triple. If the architecture name is non-empty,
545 /// then the lookup is done by architecture. Otherwise, the target
548 /// \param ArchName - The architecture to use for finding a target.
549 /// \param TheTriple - The triple to use for finding a target. The
550 /// triple is updated with canonical architecture name if a lookup
551 /// by architecture is done.
552 /// \param Error - On failure, an error string describing why no target was
554 static const Target *lookupTarget(const std::string &ArchName,
558 /// getClosestTargetForJIT - Pick the best target that is compatible with
559 /// the current host. If no close target can be found, this returns null
560 /// and sets the Error string to a reason.
562 /// Maintained for compatibility through 2.6.
563 static const Target *getClosestTargetForJIT(std::string &Error);
566 /// @name Target Registration
569 /// RegisterTarget - Register the given target. Attempts to register a
570 /// target which has already been registered will be ignored.
572 /// Clients are responsible for ensuring that registration doesn't occur
573 /// while another thread is attempting to access the registry. Typically
574 /// this is done by initializing all targets at program startup.
576 /// @param T - The target being registered.
577 /// @param Name - The target name. This should be a static string.
578 /// @param ShortDesc - A short target description. This should be a static
580 /// @param ArchMatchFn - The arch match checking function for this target.
581 /// @param HasJIT - Whether the target supports JIT code
583 static void RegisterTarget(Target &T,
585 const char *ShortDesc,
586 Target::ArchMatchFnTy ArchMatchFn,
587 bool HasJIT = false);
589 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
592 /// Clients are responsible for ensuring that registration doesn't occur
593 /// while another thread is attempting to access the registry. Typically
594 /// this is done by initializing all targets at program startup.
596 /// @param T - The target being registered.
597 /// @param Fn - A function to construct a MCAsmInfo for the target.
598 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
599 T.MCAsmInfoCtorFn = Fn;
602 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
605 /// Clients are responsible for ensuring that registration doesn't occur
606 /// while another thread is attempting to access the registry. Typically
607 /// this is done by initializing all targets at program startup.
609 /// @param T - The target being registered.
610 /// @param Fn - A function to construct a MCCodeGenInfo for the target.
611 static void RegisterMCCodeGenInfo(Target &T,
612 Target::MCCodeGenInfoCtorFnTy Fn) {
613 T.MCCodeGenInfoCtorFn = Fn;
616 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
619 /// Clients are responsible for ensuring that registration doesn't occur
620 /// while another thread is attempting to access the registry. Typically
621 /// this is done by initializing all targets at program startup.
623 /// @param T - The target being registered.
624 /// @param Fn - A function to construct a MCInstrInfo for the target.
625 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
626 T.MCInstrInfoCtorFn = Fn;
629 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
630 /// the given target.
631 static void RegisterMCInstrAnalysis(Target &T,
632 Target::MCInstrAnalysisCtorFnTy Fn) {
633 T.MCInstrAnalysisCtorFn = Fn;
636 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
639 /// Clients are responsible for ensuring that registration doesn't occur
640 /// while another thread is attempting to access the registry. Typically
641 /// this is done by initializing all targets at program startup.
643 /// @param T - The target being registered.
644 /// @param Fn - A function to construct a MCRegisterInfo for the target.
645 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
646 T.MCRegInfoCtorFn = Fn;
649 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
650 /// the given target.
652 /// Clients are responsible for ensuring that registration doesn't occur
653 /// while another thread is attempting to access the registry. Typically
654 /// this is done by initializing all targets at program startup.
656 /// @param T - The target being registered.
657 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
658 static void RegisterMCSubtargetInfo(Target &T,
659 Target::MCSubtargetInfoCtorFnTy Fn) {
660 T.MCSubtargetInfoCtorFn = Fn;
663 /// RegisterTargetMachine - Register a TargetMachine implementation for the
666 /// Clients are responsible for ensuring that registration doesn't occur
667 /// while another thread is attempting to access the registry. Typically
668 /// this is done by initializing all targets at program startup.
670 /// @param T - The target being registered.
671 /// @param Fn - A function to construct a TargetMachine for the target.
672 static void RegisterTargetMachine(Target &T,
673 Target::TargetMachineCtorTy Fn) {
674 T.TargetMachineCtorFn = Fn;
677 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
680 /// Clients are responsible for ensuring that registration doesn't occur
681 /// while another thread is attempting to access the registry. Typically
682 /// this is done by initializing all targets at program startup.
684 /// @param T - The target being registered.
685 /// @param Fn - A function to construct an AsmBackend for the target.
686 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
687 T.MCAsmBackendCtorFn = Fn;
690 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
691 /// the given target.
693 /// Clients are responsible for ensuring that registration doesn't occur
694 /// while another thread is attempting to access the registry. Typically
695 /// this is done by initializing all targets at program startup.
697 /// @param T - The target being registered.
698 /// @param Fn - A function to construct an MCTargetAsmParser for the target.
699 static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
700 T.MCAsmParserCtorFn = Fn;
703 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
706 /// Clients are responsible for ensuring that registration doesn't occur
707 /// while another thread is attempting to access the registry. Typically
708 /// this is done by initializing all targets at program startup.
710 /// @param T - The target being registered.
711 /// @param Fn - A function to construct an AsmPrinter for the target.
712 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
713 T.AsmPrinterCtorFn = Fn;
716 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
717 /// the given target.
719 /// Clients are responsible for ensuring that registration doesn't occur
720 /// while another thread is attempting to access the registry. Typically
721 /// this is done by initializing all targets at program startup.
723 /// @param T - The target being registered.
724 /// @param Fn - A function to construct an MCDisassembler for the target.
725 static void RegisterMCDisassembler(Target &T,
726 Target::MCDisassemblerCtorTy Fn) {
727 T.MCDisassemblerCtorFn = Fn;
730 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
733 /// Clients are responsible for ensuring that registration doesn't occur
734 /// while another thread is attempting to access the registry. Typically
735 /// this is done by initializing all targets at program startup.
737 /// @param T - The target being registered.
738 /// @param Fn - A function to construct an MCInstPrinter for the target.
739 static void RegisterMCInstPrinter(Target &T,
740 Target::MCInstPrinterCtorTy Fn) {
741 T.MCInstPrinterCtorFn = Fn;
744 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
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 MCCodeEmitter for the target.
753 static void RegisterMCCodeEmitter(Target &T,
754 Target::MCCodeEmitterCtorTy Fn) {
755 T.MCCodeEmitterCtorFn = Fn;
758 /// RegisterMCObjectStreamer - Register a object code MCStreamer
759 /// implementation for the given target.
761 /// Clients are responsible for ensuring that registration doesn't occur
762 /// while another thread is attempting to access the registry. Typically
763 /// this is done by initializing all targets at program startup.
765 /// @param T - The target being registered.
766 /// @param Fn - A function to construct an MCStreamer for the target.
767 static void RegisterMCObjectStreamer(Target &T,
768 Target::MCObjectStreamerCtorTy Fn) {
769 T.MCObjectStreamerCtorFn = Fn;
772 /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
773 /// for the given target.
775 /// Clients are responsible for ensuring that registration doesn't occur
776 /// while another thread is attempting to access the registry. Typically
777 /// this is done by initializing all targets at program startup.
779 /// @param T - The target being registered.
780 /// @param Fn - A function to construct an MCStreamer for the target.
781 static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
782 T.AsmStreamerCtorFn = Fn;
785 /// RegisterMCRelocationInfo - Register an MCRelocationInfo
786 /// implementation for the given target.
788 /// Clients are responsible for ensuring that registration doesn't occur
789 /// while another thread is attempting to access the registry. Typically
790 /// this is done by initializing all targets at program startup.
792 /// @param T - The target being registered.
793 /// @param Fn - A function to construct an MCRelocationInfo for the target.
794 static void RegisterMCRelocationInfo(Target &T,
795 Target::MCRelocationInfoCtorTy Fn) {
796 T.MCRelocationInfoCtorFn = Fn;
799 /// RegisterMCSymbolizer - Register an MCSymbolizer
800 /// implementation for the given target.
802 /// Clients are responsible for ensuring that registration doesn't occur
803 /// while another thread is attempting to access the registry. Typically
804 /// this is done by initializing all targets at program startup.
806 /// @param T - The target being registered.
807 /// @param Fn - A function to construct an MCSymbolizer for the target.
808 static void RegisterMCSymbolizer(Target &T,
809 Target::MCSymbolizerCtorTy Fn) {
810 T.MCSymbolizerCtorFn = Fn;
817 //===--------------------------------------------------------------------===//
819 /// RegisterTarget - Helper template for registering a target, for use in the
820 /// target's initialization function. Usage:
823 /// Target TheFooTarget; // The global target instance.
825 /// extern "C" void LLVMInitializeFooTargetInfo() {
826 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
828 template<Triple::ArchType TargetArchType = Triple::UnknownArch,
830 struct RegisterTarget {
831 RegisterTarget(Target &T, const char *Name, const char *Desc) {
832 TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch, HasJIT);
835 static bool getArchMatch(Triple::ArchType Arch) {
836 return Arch == TargetArchType;
840 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
841 /// implementation. This invokes the static "Create" method on the class to
842 /// actually do the construction. Usage:
844 /// extern "C" void LLVMInitializeFooTarget() {
845 /// extern Target TheFooTarget;
846 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
848 template<class MCAsmInfoImpl>
849 struct RegisterMCAsmInfo {
850 RegisterMCAsmInfo(Target &T) {
851 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
854 static MCAsmInfo *Allocator(const MCRegisterInfo &/*MRI*/, StringRef TT) {
855 return new MCAsmInfoImpl(TT);
860 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
861 /// implementation. This invokes the specified function to do the
862 /// construction. Usage:
864 /// extern "C" void LLVMInitializeFooTarget() {
865 /// extern Target TheFooTarget;
866 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
868 struct RegisterMCAsmInfoFn {
869 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
870 TargetRegistry::RegisterMCAsmInfo(T, Fn);
874 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
875 /// implementation. This invokes the static "Create" method on the class
876 /// to actually do the construction. Usage:
878 /// extern "C" void LLVMInitializeFooTarget() {
879 /// extern Target TheFooTarget;
880 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
882 template<class MCCodeGenInfoImpl>
883 struct RegisterMCCodeGenInfo {
884 RegisterMCCodeGenInfo(Target &T) {
885 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
888 static MCCodeGenInfo *Allocator(StringRef /*TT*/, Reloc::Model /*RM*/,
889 CodeModel::Model /*CM*/,
890 CodeGenOpt::Level /*OL*/) {
891 return new MCCodeGenInfoImpl();
895 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
896 /// info implementation. This invokes the specified function to do the
897 /// construction. Usage:
899 /// extern "C" void LLVMInitializeFooTarget() {
900 /// extern Target TheFooTarget;
901 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
903 struct RegisterMCCodeGenInfoFn {
904 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
905 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
909 /// RegisterMCInstrInfo - Helper template for registering a target instruction
910 /// info implementation. This invokes the static "Create" method on the class
911 /// to actually do the construction. Usage:
913 /// extern "C" void LLVMInitializeFooTarget() {
914 /// extern Target TheFooTarget;
915 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
917 template<class MCInstrInfoImpl>
918 struct RegisterMCInstrInfo {
919 RegisterMCInstrInfo(Target &T) {
920 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
923 static MCInstrInfo *Allocator() {
924 return new MCInstrInfoImpl();
928 /// RegisterMCInstrInfoFn - Helper template for registering a target
929 /// instruction info implementation. This invokes the specified function to
930 /// do the construction. Usage:
932 /// extern "C" void LLVMInitializeFooTarget() {
933 /// extern Target TheFooTarget;
934 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
936 struct RegisterMCInstrInfoFn {
937 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
938 TargetRegistry::RegisterMCInstrInfo(T, Fn);
942 /// RegisterMCInstrAnalysis - Helper template for registering a target
943 /// instruction analyzer implementation. This invokes the static "Create"
944 /// method on the class to actually do the construction. Usage:
946 /// extern "C" void LLVMInitializeFooTarget() {
947 /// extern Target TheFooTarget;
948 /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
950 template<class MCInstrAnalysisImpl>
951 struct RegisterMCInstrAnalysis {
952 RegisterMCInstrAnalysis(Target &T) {
953 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
956 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
957 return new MCInstrAnalysisImpl(Info);
961 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
962 /// instruction analyzer implementation. This invokes the specified function
963 /// to do the construction. Usage:
965 /// extern "C" void LLVMInitializeFooTarget() {
966 /// extern Target TheFooTarget;
967 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
969 struct RegisterMCInstrAnalysisFn {
970 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
971 TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
975 /// RegisterMCRegInfo - Helper template for registering a target register info
976 /// implementation. This invokes the static "Create" method on the class to
977 /// actually do the construction. Usage:
979 /// extern "C" void LLVMInitializeFooTarget() {
980 /// extern Target TheFooTarget;
981 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
983 template<class MCRegisterInfoImpl>
984 struct RegisterMCRegInfo {
985 RegisterMCRegInfo(Target &T) {
986 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
989 static MCRegisterInfo *Allocator(StringRef /*TT*/) {
990 return new MCRegisterInfoImpl();
994 /// RegisterMCRegInfoFn - Helper template for registering a target register
995 /// info implementation. This invokes the specified function to do the
996 /// construction. Usage:
998 /// extern "C" void LLVMInitializeFooTarget() {
999 /// extern Target TheFooTarget;
1000 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
1002 struct RegisterMCRegInfoFn {
1003 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
1004 TargetRegistry::RegisterMCRegInfo(T, Fn);
1008 /// RegisterMCSubtargetInfo - Helper template for registering a target
1009 /// subtarget info implementation. This invokes the static "Create" method
1010 /// on the class to actually do the construction. Usage:
1012 /// extern "C" void LLVMInitializeFooTarget() {
1013 /// extern Target TheFooTarget;
1014 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
1016 template<class MCSubtargetInfoImpl>
1017 struct RegisterMCSubtargetInfo {
1018 RegisterMCSubtargetInfo(Target &T) {
1019 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
1022 static MCSubtargetInfo *Allocator(StringRef /*TT*/, StringRef /*CPU*/,
1024 return new MCSubtargetInfoImpl();
1028 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
1029 /// subtarget info implementation. This invokes the specified function to
1030 /// do the construction. Usage:
1032 /// extern "C" void LLVMInitializeFooTarget() {
1033 /// extern Target TheFooTarget;
1034 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1036 struct RegisterMCSubtargetInfoFn {
1037 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
1038 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
1042 /// RegisterTargetMachine - Helper template for registering a target machine
1043 /// implementation, for use in the target machine initialization
1044 /// function. Usage:
1046 /// extern "C" void LLVMInitializeFooTarget() {
1047 /// extern Target TheFooTarget;
1048 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1050 template<class TargetMachineImpl>
1051 struct RegisterTargetMachine {
1052 RegisterTargetMachine(Target &T) {
1053 TargetRegistry::RegisterTargetMachine(T, &Allocator);
1057 static TargetMachine *Allocator(const Target &T, StringRef TT,
1058 StringRef CPU, StringRef FS,
1059 const TargetOptions &Options,
1061 CodeModel::Model CM,
1062 CodeGenOpt::Level OL) {
1063 return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
1067 /// RegisterMCAsmBackend - Helper template for registering a target specific
1068 /// assembler backend. Usage:
1070 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1071 /// extern Target TheFooTarget;
1072 /// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1074 template<class MCAsmBackendImpl>
1075 struct RegisterMCAsmBackend {
1076 RegisterMCAsmBackend(Target &T) {
1077 TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1081 static MCAsmBackend *Allocator(const Target &T,
1082 const MCRegisterInfo &MRI,
1083 StringRef Triple, StringRef CPU) {
1084 return new MCAsmBackendImpl(T, MRI, Triple, CPU);
1088 /// RegisterMCAsmParser - Helper template for registering a target specific
1089 /// assembly parser, for use in the target machine initialization
1090 /// function. Usage:
1092 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1093 /// extern Target TheFooTarget;
1094 /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1096 template<class MCAsmParserImpl>
1097 struct RegisterMCAsmParser {
1098 RegisterMCAsmParser(Target &T) {
1099 TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1103 static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P,
1104 const MCInstrInfo &MII) {
1105 return new MCAsmParserImpl(STI, P, MII);
1109 /// RegisterAsmPrinter - Helper template for registering a target specific
1110 /// assembly printer, for use in the target machine initialization
1111 /// function. Usage:
1113 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1114 /// extern Target TheFooTarget;
1115 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1117 template<class AsmPrinterImpl>
1118 struct RegisterAsmPrinter {
1119 RegisterAsmPrinter(Target &T) {
1120 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1124 static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) {
1125 return new AsmPrinterImpl(TM, Streamer);
1129 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1130 /// machine code emitter, for use in the target initialization
1131 /// function. Usage:
1133 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1134 /// extern Target TheFooTarget;
1135 /// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1137 template<class MCCodeEmitterImpl>
1138 struct RegisterMCCodeEmitter {
1139 RegisterMCCodeEmitter(Target &T) {
1140 TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1144 static MCCodeEmitter *Allocator(const MCInstrInfo &/*II*/,
1145 const MCRegisterInfo &/*MRI*/,
1146 const MCSubtargetInfo &/*STI*/,
1147 MCContext &/*Ctx*/) {
1148 return new MCCodeEmitterImpl();