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/ADT/Triple.h"
23 #include "llvm/Support/CodeGen.h"
24 #include "llvm-c/Disassembler.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,
55 bool useLoc, bool useCFI,
56 bool useDwarfDirectory,
57 MCInstPrinter *InstPrint,
62 MCRelocationInfo *createMCRelocationInfo(StringRef TT, MCContext &Ctx);
64 MCSymbolizer *createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
65 LLVMSymbolLookupCallback SymbolLookUp,
68 MCRelocationInfo *RelInfo);
70 /// Target - Wrapper for Target specific information.
72 /// For registration purposes, this is a POD type so that targets can be
73 /// registered without the use of static constructors.
75 /// Targets should implement a single global instance of this class (which
76 /// will be zero initialized), and pass that instance to the TargetRegistry as
77 /// part of their initialization.
80 friend struct TargetRegistry;
82 typedef unsigned (*TripleMatchQualityFnTy)(const std::string &TT);
84 typedef MCAsmInfo *(*MCAsmInfoCtorFnTy)(const MCRegisterInfo &MRI,
86 typedef MCCodeGenInfo *(*MCCodeGenInfoCtorFnTy)(StringRef TT,
89 CodeGenOpt::Level OL);
90 typedef MCInstrInfo *(*MCInstrInfoCtorFnTy)(void);
91 typedef MCInstrAnalysis *(*MCInstrAnalysisCtorFnTy)(const MCInstrInfo*Info);
92 typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(StringRef TT);
93 typedef MCSubtargetInfo *(*MCSubtargetInfoCtorFnTy)(StringRef TT,
96 typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T,
100 const TargetOptions &Options,
103 CodeGenOpt::Level OL);
104 typedef AsmPrinter *(*AsmPrinterCtorTy)(TargetMachine &TM,
105 MCStreamer &Streamer);
106 typedef MCAsmBackend *(*MCAsmBackendCtorTy)(const Target &T,
109 typedef MCTargetAsmParser *(*MCAsmParserCtorTy)(MCSubtargetInfo &STI,
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,
131 typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx,
132 formatted_raw_ostream &OS,
136 bool useDwarfDirectory,
137 MCInstPrinter *InstPrint,
141 typedef MCRelocationInfo *(*MCRelocationInfoCtorTy)(StringRef TT,
143 typedef MCSymbolizer *(*MCSymbolizerCtorTy)(StringRef TT,
144 LLVMOpInfoCallback GetOpInfo,
145 LLVMSymbolLookupCallback SymbolLookUp,
148 MCRelocationInfo *RelInfo);
151 /// Next - The next registered target in the linked list, maintained by the
155 /// TripleMatchQualityFn - The target function for rating the match quality
157 TripleMatchQualityFnTy TripleMatchQualityFn;
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;
237 Target() : AsmStreamerCtorFn(llvm::createAsmStreamer),
238 MCRelocationInfoCtorFn(llvm::createMCRelocationInfo),
239 MCSymbolizerCtorFn(llvm::createMCSymbolizer) {}
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; }
266 /// hasAsmParser - Check if this target supports .s parsing.
267 bool hasMCAsmParser() const { return MCAsmParserCtorFn != 0; }
269 /// hasAsmPrinter - Check if this target supports .s printing.
270 bool hasAsmPrinter() const { return AsmPrinterCtorFn != 0; }
272 /// hasMCDisassembler - Check if this target has a disassembler.
273 bool hasMCDisassembler() const { return MCDisassemblerCtorFn != 0; }
275 /// hasMCInstPrinter - Check if this target has an instruction printer.
276 bool hasMCInstPrinter() const { return MCInstPrinterCtorFn != 0; }
278 /// hasMCCodeEmitter - Check if this target supports instruction encoding.
279 bool hasMCCodeEmitter() const { return MCCodeEmitterCtorFn != 0; }
281 /// hasMCObjectStreamer - Check if this target supports streaming to files.
282 bool hasMCObjectStreamer() const { return MCObjectStreamerCtorFn != 0; }
284 /// hasAsmStreamer - Check if this target supports streaming to files.
285 bool hasAsmStreamer() const { return AsmStreamerCtorFn != 0; }
288 /// @name Feature Constructors
291 /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
294 /// \param Triple This argument is used to determine the target machine
295 /// feature set; it should always be provided. Generally this should be
296 /// either the target triple from the module, or the target triple of the
297 /// host if that does not exist.
298 MCAsmInfo *createMCAsmInfo(const MCRegisterInfo &MRI,
299 StringRef Triple) const {
300 if (!MCAsmInfoCtorFn)
302 return MCAsmInfoCtorFn(MRI, Triple);
305 /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
307 MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model RM,
309 CodeGenOpt::Level OL) const {
310 if (!MCCodeGenInfoCtorFn)
312 return MCCodeGenInfoCtorFn(Triple, RM, CM, OL);
315 /// createMCInstrInfo - Create a MCInstrInfo implementation.
317 MCInstrInfo *createMCInstrInfo() const {
318 if (!MCInstrInfoCtorFn)
320 return MCInstrInfoCtorFn();
323 /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
325 MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
326 if (!MCInstrAnalysisCtorFn)
328 return MCInstrAnalysisCtorFn(Info);
331 /// createMCRegInfo - Create a MCRegisterInfo implementation.
333 MCRegisterInfo *createMCRegInfo(StringRef Triple) const {
334 if (!MCRegInfoCtorFn)
336 return MCRegInfoCtorFn(Triple);
339 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
341 /// \param Triple This argument is used to determine the target machine
342 /// feature set; it should always be provided. Generally this should be
343 /// either the target triple from the module, or the target triple of the
344 /// host if that does not exist.
345 /// \param CPU This specifies the name of the target CPU.
346 /// \param Features This specifies the string representation of the
347 /// additional target features.
348 MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU,
349 StringRef Features) const {
350 if (!MCSubtargetInfoCtorFn)
352 return MCSubtargetInfoCtorFn(Triple, CPU, Features);
355 /// createTargetMachine - Create a target specific machine implementation
356 /// for the specified \p Triple.
358 /// \param Triple This argument is used to determine the target machine
359 /// feature set; it should always be provided. Generally this should be
360 /// either the target triple from the module, or the target triple of the
361 /// host if that does not exist.
362 TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU,
363 StringRef Features, const TargetOptions &Options,
364 Reloc::Model RM = Reloc::Default,
365 CodeModel::Model CM = CodeModel::Default,
366 CodeGenOpt::Level OL = CodeGenOpt::Default) const {
367 if (!TargetMachineCtorFn)
369 return TargetMachineCtorFn(*this, Triple, CPU, Features, Options,
373 /// createMCAsmBackend - Create a target specific assembly parser.
375 /// \param Triple The target triple string.
376 MCAsmBackend *createMCAsmBackend(StringRef Triple, StringRef CPU) const {
377 if (!MCAsmBackendCtorFn)
379 return MCAsmBackendCtorFn(*this, Triple, CPU);
382 /// createMCAsmParser - Create a target specific assembly parser.
384 /// \param Parser The target independent parser implementation to use for
385 /// parsing and lexing.
386 MCTargetAsmParser *createMCAsmParser(MCSubtargetInfo &STI,
387 MCAsmParser &Parser) const {
388 if (!MCAsmParserCtorFn)
390 return MCAsmParserCtorFn(STI, Parser);
393 /// createAsmPrinter - Create a target specific assembly printer pass. This
394 /// takes ownership of the MCStreamer object.
395 AsmPrinter *createAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) const{
396 if (!AsmPrinterCtorFn)
398 return AsmPrinterCtorFn(TM, Streamer);
401 MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI) const {
402 if (!MCDisassemblerCtorFn)
404 return MCDisassemblerCtorFn(*this, STI);
407 MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
408 const MCAsmInfo &MAI,
409 const MCInstrInfo &MII,
410 const MCRegisterInfo &MRI,
411 const MCSubtargetInfo &STI) const {
412 if (!MCInstPrinterCtorFn)
414 return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, MII, MRI, STI);
418 /// createMCCodeEmitter - Create a target specific code emitter.
419 MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
420 const MCRegisterInfo &MRI,
421 const MCSubtargetInfo &STI,
422 MCContext &Ctx) const {
423 if (!MCCodeEmitterCtorFn)
425 return MCCodeEmitterCtorFn(II, MRI, STI, Ctx);
428 /// createMCObjectStreamer - Create a target specific MCStreamer.
430 /// \param TT The target triple.
431 /// \param Ctx The target context.
432 /// \param TAB The target assembler backend object. Takes ownership.
433 /// \param _OS The stream object.
434 /// \param _Emitter The target independent assembler object.Takes ownership.
435 /// \param RelaxAll Relax all fixups?
436 /// \param NoExecStack Mark file as not needing a executable stack.
437 MCStreamer *createMCObjectStreamer(StringRef TT, MCContext &Ctx,
440 MCCodeEmitter *_Emitter,
442 bool NoExecStack) const {
443 if (!MCObjectStreamerCtorFn)
445 return MCObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter,
446 RelaxAll, NoExecStack);
449 /// createAsmStreamer - Create a target specific MCStreamer.
450 MCStreamer *createAsmStreamer(MCContext &Ctx,
451 formatted_raw_ostream &OS,
455 bool useDwarfDirectory,
456 MCInstPrinter *InstPrint,
459 bool ShowInst) const {
460 // AsmStreamerCtorFn is default to llvm::createAsmStreamer
461 return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useLoc, useCFI,
462 useDwarfDirectory, InstPrint, CE, TAB, ShowInst);
465 /// createMCRelocationInfo - Create a target specific MCRelocationInfo.
467 /// \param TT The target triple.
468 /// \param Ctx The target context.
470 createMCRelocationInfo(StringRef TT, MCContext &Ctx) const {
471 return MCRelocationInfoCtorFn(TT, Ctx);
474 /// createMCSymbolizer - Create a target specific MCSymbolizer.
476 /// \param TT The target triple.
477 /// \param GetOpInfo The function to get the symbolic information for operands.
478 /// \param SymbolLookUp The function to lookup a symbol name.
479 /// \param DisInfo The pointer to the block of symbolic information for above call
481 /// \param Ctx The target context.
482 /// \param RelInfo The relocation information for this target. Takes ownership.
484 createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
485 LLVMSymbolLookupCallback SymbolLookUp,
487 MCContext *Ctx, MCRelocationInfo *RelInfo) const {
488 return MCSymbolizerCtorFn(TT, GetOpInfo, SymbolLookUp, DisInfo,
495 /// TargetRegistry - Generic interface to target specific features.
496 struct TargetRegistry {
498 const Target *Current;
499 explicit iterator(Target *T) : Current(T) {}
500 friend struct TargetRegistry;
502 iterator(const iterator &I) : Current(I.Current) {}
503 iterator() : Current(0) {}
505 bool operator==(const iterator &x) const {
506 return Current == x.Current;
508 bool operator!=(const iterator &x) const {
509 return !operator==(x);
512 // Iterator traversal: forward iteration only
513 iterator &operator++() { // Preincrement
514 assert(Current && "Cannot increment end iterator!");
515 Current = Current->getNext();
518 iterator operator++(int) { // Postincrement
519 iterator tmp = *this;
524 const Target &operator*() const {
525 assert(Current && "Cannot dereference end iterator!");
529 const Target *operator->() const {
534 /// printRegisteredTargetsForVersion - Print the registered targets
535 /// appropriately for inclusion in a tool's version output.
536 static void printRegisteredTargetsForVersion();
538 /// @name Registry Access
541 static iterator begin();
543 static iterator end() { return iterator(); }
545 /// lookupTarget - Lookup a target based on a target triple.
547 /// \param Triple - The triple to use for finding a target.
548 /// \param Error - On failure, an error string describing why no target was
550 static const Target *lookupTarget(const std::string &Triple,
553 /// lookupTarget - Lookup a target based on an architecture name
554 /// and a target triple. If the architecture name is non-empty,
555 /// then the lookup is done by architecture. Otherwise, the target
558 /// \param ArchName - The architecture to use for finding a target.
559 /// \param TheTriple - The triple to use for finding a target. The
560 /// triple is updated with canonical architecture name if a lookup
561 /// by architecture is done.
562 /// \param Error - On failure, an error string describing why no target was
564 static const Target *lookupTarget(const std::string &ArchName,
568 /// getClosestTargetForJIT - Pick the best target that is compatible with
569 /// the current host. If no close target can be found, this returns null
570 /// and sets the Error string to a reason.
572 /// Maintained for compatibility through 2.6.
573 static const Target *getClosestTargetForJIT(std::string &Error);
576 /// @name Target Registration
579 /// RegisterTarget - Register the given target. Attempts to register a
580 /// target which has already been registered will be ignored.
582 /// Clients are responsible for ensuring that registration doesn't occur
583 /// while another thread is attempting to access the registry. Typically
584 /// this is done by initializing all targets at program startup.
586 /// @param T - The target being registered.
587 /// @param Name - The target name. This should be a static string.
588 /// @param ShortDesc - A short target description. This should be a static
590 /// @param TQualityFn - The triple match quality computation function for
592 /// @param HasJIT - Whether the target supports JIT code
594 static void RegisterTarget(Target &T,
596 const char *ShortDesc,
597 Target::TripleMatchQualityFnTy TQualityFn,
598 bool HasJIT = false);
600 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
603 /// Clients are responsible for ensuring that registration doesn't occur
604 /// while another thread is attempting to access the registry. Typically
605 /// this is done by initializing all targets at program startup.
607 /// @param T - The target being registered.
608 /// @param Fn - A function to construct a MCAsmInfo for the target.
609 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
610 // Ignore duplicate registration.
611 if (!T.MCAsmInfoCtorFn)
612 T.MCAsmInfoCtorFn = Fn;
615 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
618 /// Clients are responsible for ensuring that registration doesn't occur
619 /// while another thread is attempting to access the registry. Typically
620 /// this is done by initializing all targets at program startup.
622 /// @param T - The target being registered.
623 /// @param Fn - A function to construct a MCCodeGenInfo for the target.
624 static void RegisterMCCodeGenInfo(Target &T,
625 Target::MCCodeGenInfoCtorFnTy Fn) {
626 // Ignore duplicate registration.
627 if (!T.MCCodeGenInfoCtorFn)
628 T.MCCodeGenInfoCtorFn = Fn;
631 /// RegisterMCInstrInfo - Register a MCInstrInfo 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 MCInstrInfo for the target.
640 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
641 // Ignore duplicate registration.
642 if (!T.MCInstrInfoCtorFn)
643 T.MCInstrInfoCtorFn = Fn;
646 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
647 /// the given target.
648 static void RegisterMCInstrAnalysis(Target &T,
649 Target::MCInstrAnalysisCtorFnTy Fn) {
650 // Ignore duplicate registration.
651 if (!T.MCInstrAnalysisCtorFn)
652 T.MCInstrAnalysisCtorFn = Fn;
655 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
658 /// Clients are responsible for ensuring that registration doesn't occur
659 /// while another thread is attempting to access the registry. Typically
660 /// this is done by initializing all targets at program startup.
662 /// @param T - The target being registered.
663 /// @param Fn - A function to construct a MCRegisterInfo for the target.
664 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
665 // Ignore duplicate registration.
666 if (!T.MCRegInfoCtorFn)
667 T.MCRegInfoCtorFn = Fn;
670 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
671 /// the given target.
673 /// Clients are responsible for ensuring that registration doesn't occur
674 /// while another thread is attempting to access the registry. Typically
675 /// this is done by initializing all targets at program startup.
677 /// @param T - The target being registered.
678 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
679 static void RegisterMCSubtargetInfo(Target &T,
680 Target::MCSubtargetInfoCtorFnTy Fn) {
681 // Ignore duplicate registration.
682 if (!T.MCSubtargetInfoCtorFn)
683 T.MCSubtargetInfoCtorFn = Fn;
686 /// RegisterTargetMachine - Register a TargetMachine implementation for the
689 /// Clients are responsible for ensuring that registration doesn't occur
690 /// while another thread is attempting to access the registry. Typically
691 /// this is done by initializing all targets at program startup.
693 /// @param T - The target being registered.
694 /// @param Fn - A function to construct a TargetMachine for the target.
695 static void RegisterTargetMachine(Target &T,
696 Target::TargetMachineCtorTy Fn) {
697 // Ignore duplicate registration.
698 if (!T.TargetMachineCtorFn)
699 T.TargetMachineCtorFn = Fn;
702 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
705 /// Clients are responsible for ensuring that registration doesn't occur
706 /// while another thread is attempting to access the registry. Typically
707 /// this is done by initializing all targets at program startup.
709 /// @param T - The target being registered.
710 /// @param Fn - A function to construct an AsmBackend for the target.
711 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
712 if (!T.MCAsmBackendCtorFn)
713 T.MCAsmBackendCtorFn = Fn;
716 /// RegisterMCAsmParser - Register a MCTargetAsmParser 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 MCTargetAsmParser for the target.
725 static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
726 if (!T.MCAsmParserCtorFn)
727 T.MCAsmParserCtorFn = Fn;
730 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
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 AsmPrinter for the target.
739 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
740 // Ignore duplicate registration.
741 if (!T.AsmPrinterCtorFn)
742 T.AsmPrinterCtorFn = Fn;
745 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
746 /// the given target.
748 /// Clients are responsible for ensuring that registration doesn't occur
749 /// while another thread is attempting to access the registry. Typically
750 /// this is done by initializing all targets at program startup.
752 /// @param T - The target being registered.
753 /// @param Fn - A function to construct an MCDisassembler for the target.
754 static void RegisterMCDisassembler(Target &T,
755 Target::MCDisassemblerCtorTy Fn) {
756 if (!T.MCDisassemblerCtorFn)
757 T.MCDisassemblerCtorFn = Fn;
760 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
763 /// Clients are responsible for ensuring that registration doesn't occur
764 /// while another thread is attempting to access the registry. Typically
765 /// this is done by initializing all targets at program startup.
767 /// @param T - The target being registered.
768 /// @param Fn - A function to construct an MCInstPrinter for the target.
769 static void RegisterMCInstPrinter(Target &T,
770 Target::MCInstPrinterCtorTy Fn) {
771 if (!T.MCInstPrinterCtorFn)
772 T.MCInstPrinterCtorFn = Fn;
775 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
778 /// Clients are responsible for ensuring that registration doesn't occur
779 /// while another thread is attempting to access the registry. Typically
780 /// this is done by initializing all targets at program startup.
782 /// @param T - The target being registered.
783 /// @param Fn - A function to construct an MCCodeEmitter for the target.
784 static void RegisterMCCodeEmitter(Target &T,
785 Target::MCCodeEmitterCtorTy Fn) {
786 if (!T.MCCodeEmitterCtorFn)
787 T.MCCodeEmitterCtorFn = Fn;
790 /// RegisterMCObjectStreamer - Register a object code MCStreamer
791 /// implementation for the given target.
793 /// Clients are responsible for ensuring that registration doesn't occur
794 /// while another thread is attempting to access the registry. Typically
795 /// this is done by initializing all targets at program startup.
797 /// @param T - The target being registered.
798 /// @param Fn - A function to construct an MCStreamer for the target.
799 static void RegisterMCObjectStreamer(Target &T,
800 Target::MCObjectStreamerCtorTy Fn) {
801 if (!T.MCObjectStreamerCtorFn)
802 T.MCObjectStreamerCtorFn = Fn;
805 /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
806 /// for the given target.
808 /// Clients are responsible for ensuring that registration doesn't occur
809 /// while another thread is attempting to access the registry. Typically
810 /// this is done by initializing all targets at program startup.
812 /// @param T - The target being registered.
813 /// @param Fn - A function to construct an MCStreamer for the target.
814 static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
815 if (T.AsmStreamerCtorFn == createAsmStreamer)
816 T.AsmStreamerCtorFn = Fn;
819 /// RegisterMCRelocationInfo - Register an MCRelocationInfo
820 /// implementation for the given target.
822 /// Clients are responsible for ensuring that registration doesn't occur
823 /// while another thread is attempting to access the registry. Typically
824 /// this is done by initializing all targets at program startup.
826 /// @param T - The target being registered.
827 /// @param Fn - A function to construct an MCRelocationInfo for the target.
828 static void RegisterMCRelocationInfo(Target &T,
829 Target::MCRelocationInfoCtorTy Fn) {
830 if (T.MCRelocationInfoCtorFn == llvm::createMCRelocationInfo)
831 T.MCRelocationInfoCtorFn = Fn;
834 /// RegisterMCSymbolizer - Register an MCSymbolizer
835 /// implementation for the given target.
837 /// Clients are responsible for ensuring that registration doesn't occur
838 /// while another thread is attempting to access the registry. Typically
839 /// this is done by initializing all targets at program startup.
841 /// @param T - The target being registered.
842 /// @param Fn - A function to construct an MCSymbolizer for the target.
843 static void RegisterMCSymbolizer(Target &T,
844 Target::MCSymbolizerCtorTy Fn) {
845 if (T.MCSymbolizerCtorFn == llvm::createMCSymbolizer)
846 T.MCSymbolizerCtorFn = Fn;
853 //===--------------------------------------------------------------------===//
855 /// RegisterTarget - Helper template for registering a target, for use in the
856 /// target's initialization function. Usage:
859 /// Target TheFooTarget; // The global target instance.
861 /// extern "C" void LLVMInitializeFooTargetInfo() {
862 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
864 template<Triple::ArchType TargetArchType = Triple::UnknownArch,
866 struct RegisterTarget {
867 RegisterTarget(Target &T, const char *Name, const char *Desc) {
868 TargetRegistry::RegisterTarget(T, Name, Desc,
869 &getTripleMatchQuality,
873 static unsigned getTripleMatchQuality(const std::string &TT) {
874 if (Triple(TT).getArch() == TargetArchType)
880 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
881 /// implementation. This invokes the static "Create" method on the class to
882 /// actually do the construction. Usage:
884 /// extern "C" void LLVMInitializeFooTarget() {
885 /// extern Target TheFooTarget;
886 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
888 template<class MCAsmInfoImpl>
889 struct RegisterMCAsmInfo {
890 RegisterMCAsmInfo(Target &T) {
891 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
894 static MCAsmInfo *Allocator(const MCRegisterInfo &/*MRI*/, StringRef TT) {
895 return new MCAsmInfoImpl(TT);
900 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
901 /// implementation. This invokes the specified function to do the
902 /// construction. Usage:
904 /// extern "C" void LLVMInitializeFooTarget() {
905 /// extern Target TheFooTarget;
906 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
908 struct RegisterMCAsmInfoFn {
909 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
910 TargetRegistry::RegisterMCAsmInfo(T, Fn);
914 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
915 /// implementation. This invokes the static "Create" method on the class
916 /// to actually do the construction. Usage:
918 /// extern "C" void LLVMInitializeFooTarget() {
919 /// extern Target TheFooTarget;
920 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
922 template<class MCCodeGenInfoImpl>
923 struct RegisterMCCodeGenInfo {
924 RegisterMCCodeGenInfo(Target &T) {
925 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
928 static MCCodeGenInfo *Allocator(StringRef /*TT*/, Reloc::Model /*RM*/,
929 CodeModel::Model /*CM*/,
930 CodeGenOpt::Level /*OL*/) {
931 return new MCCodeGenInfoImpl();
935 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
936 /// info implementation. This invokes the specified function to do the
937 /// construction. Usage:
939 /// extern "C" void LLVMInitializeFooTarget() {
940 /// extern Target TheFooTarget;
941 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
943 struct RegisterMCCodeGenInfoFn {
944 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
945 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
949 /// RegisterMCInstrInfo - Helper template for registering a target instruction
950 /// info implementation. This invokes the static "Create" method on the class
951 /// to actually do the construction. Usage:
953 /// extern "C" void LLVMInitializeFooTarget() {
954 /// extern Target TheFooTarget;
955 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
957 template<class MCInstrInfoImpl>
958 struct RegisterMCInstrInfo {
959 RegisterMCInstrInfo(Target &T) {
960 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
963 static MCInstrInfo *Allocator() {
964 return new MCInstrInfoImpl();
968 /// RegisterMCInstrInfoFn - Helper template for registering a target
969 /// instruction info implementation. This invokes the specified function to
970 /// do the construction. Usage:
972 /// extern "C" void LLVMInitializeFooTarget() {
973 /// extern Target TheFooTarget;
974 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
976 struct RegisterMCInstrInfoFn {
977 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
978 TargetRegistry::RegisterMCInstrInfo(T, Fn);
982 /// RegisterMCInstrAnalysis - Helper template for registering a target
983 /// instruction analyzer implementation. This invokes the static "Create"
984 /// method on the class to actually do the construction. Usage:
986 /// extern "C" void LLVMInitializeFooTarget() {
987 /// extern Target TheFooTarget;
988 /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
990 template<class MCInstrAnalysisImpl>
991 struct RegisterMCInstrAnalysis {
992 RegisterMCInstrAnalysis(Target &T) {
993 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
996 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
997 return new MCInstrAnalysisImpl(Info);
1001 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
1002 /// instruction analyzer implementation. This invokes the specified function
1003 /// to do the construction. Usage:
1005 /// extern "C" void LLVMInitializeFooTarget() {
1006 /// extern Target TheFooTarget;
1007 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
1009 struct RegisterMCInstrAnalysisFn {
1010 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
1011 TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
1015 /// RegisterMCRegInfo - Helper template for registering a target register info
1016 /// implementation. This invokes the static "Create" method on the class to
1017 /// actually do the construction. Usage:
1019 /// extern "C" void LLVMInitializeFooTarget() {
1020 /// extern Target TheFooTarget;
1021 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
1023 template<class MCRegisterInfoImpl>
1024 struct RegisterMCRegInfo {
1025 RegisterMCRegInfo(Target &T) {
1026 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
1029 static MCRegisterInfo *Allocator(StringRef /*TT*/) {
1030 return new MCRegisterInfoImpl();
1034 /// RegisterMCRegInfoFn - Helper template for registering a target register
1035 /// info implementation. This invokes the specified function to do the
1036 /// construction. Usage:
1038 /// extern "C" void LLVMInitializeFooTarget() {
1039 /// extern Target TheFooTarget;
1040 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
1042 struct RegisterMCRegInfoFn {
1043 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
1044 TargetRegistry::RegisterMCRegInfo(T, Fn);
1048 /// RegisterMCSubtargetInfo - Helper template for registering a target
1049 /// subtarget info implementation. This invokes the static "Create" method
1050 /// on the class to actually do the construction. Usage:
1052 /// extern "C" void LLVMInitializeFooTarget() {
1053 /// extern Target TheFooTarget;
1054 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
1056 template<class MCSubtargetInfoImpl>
1057 struct RegisterMCSubtargetInfo {
1058 RegisterMCSubtargetInfo(Target &T) {
1059 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
1062 static MCSubtargetInfo *Allocator(StringRef /*TT*/, StringRef /*CPU*/,
1064 return new MCSubtargetInfoImpl();
1068 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
1069 /// subtarget info implementation. This invokes the specified function to
1070 /// do the construction. Usage:
1072 /// extern "C" void LLVMInitializeFooTarget() {
1073 /// extern Target TheFooTarget;
1074 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1076 struct RegisterMCSubtargetInfoFn {
1077 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
1078 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
1082 /// RegisterTargetMachine - Helper template for registering a target machine
1083 /// implementation, for use in the target machine initialization
1084 /// function. Usage:
1086 /// extern "C" void LLVMInitializeFooTarget() {
1087 /// extern Target TheFooTarget;
1088 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1090 template<class TargetMachineImpl>
1091 struct RegisterTargetMachine {
1092 RegisterTargetMachine(Target &T) {
1093 TargetRegistry::RegisterTargetMachine(T, &Allocator);
1097 static TargetMachine *Allocator(const Target &T, StringRef TT,
1098 StringRef CPU, StringRef FS,
1099 const TargetOptions &Options,
1101 CodeModel::Model CM,
1102 CodeGenOpt::Level OL) {
1103 return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
1107 /// RegisterMCAsmBackend - Helper template for registering a target specific
1108 /// assembler backend. Usage:
1110 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1111 /// extern Target TheFooTarget;
1112 /// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1114 template<class MCAsmBackendImpl>
1115 struct RegisterMCAsmBackend {
1116 RegisterMCAsmBackend(Target &T) {
1117 TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1121 static MCAsmBackend *Allocator(const Target &T, StringRef Triple,
1123 return new MCAsmBackendImpl(T, Triple, CPU);
1127 /// RegisterMCAsmParser - Helper template for registering a target specific
1128 /// assembly parser, for use in the target machine initialization
1129 /// function. Usage:
1131 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1132 /// extern Target TheFooTarget;
1133 /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1135 template<class MCAsmParserImpl>
1136 struct RegisterMCAsmParser {
1137 RegisterMCAsmParser(Target &T) {
1138 TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1142 static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P) {
1143 return new MCAsmParserImpl(STI, P);
1147 /// RegisterAsmPrinter - Helper template for registering a target specific
1148 /// assembly printer, for use in the target machine initialization
1149 /// function. Usage:
1151 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1152 /// extern Target TheFooTarget;
1153 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1155 template<class AsmPrinterImpl>
1156 struct RegisterAsmPrinter {
1157 RegisterAsmPrinter(Target &T) {
1158 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1162 static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) {
1163 return new AsmPrinterImpl(TM, Streamer);
1167 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1168 /// machine code emitter, for use in the target initialization
1169 /// function. Usage:
1171 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1172 /// extern Target TheFooTarget;
1173 /// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1175 template<class MCCodeEmitterImpl>
1176 struct RegisterMCCodeEmitter {
1177 RegisterMCCodeEmitter(Target &T) {
1178 TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1182 static MCCodeEmitter *Allocator(const MCInstrInfo &/*II*/,
1183 const MCRegisterInfo &/*MRI*/,
1184 const MCSubtargetInfo &/*STI*/,
1185 MCContext &/*Ctx*/) {
1186 return new MCCodeEmitterImpl();