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,
107 const MCRegisterInfo &MRI,
110 typedef MCTargetAsmParser *(*MCAsmParserCtorTy)(MCSubtargetInfo &STI,
112 typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T,
113 const MCSubtargetInfo &STI);
114 typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
115 unsigned SyntaxVariant,
116 const MCAsmInfo &MAI,
117 const MCInstrInfo &MII,
118 const MCRegisterInfo &MRI,
119 const MCSubtargetInfo &STI);
120 typedef MCCodeEmitter *(*MCCodeEmitterCtorTy)(const MCInstrInfo &II,
121 const MCRegisterInfo &MRI,
122 const MCSubtargetInfo &STI,
124 typedef MCStreamer *(*MCObjectStreamerCtorTy)(const Target &T,
129 MCCodeEmitter *_Emitter,
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 /// TripleMatchQualityFn - The target function for rating the match quality
158 TripleMatchQualityFnTy TripleMatchQualityFn;
160 /// Name - The target name.
163 /// ShortDesc - A short description of the target.
164 const char *ShortDesc;
166 /// HasJIT - Whether this target supports the JIT.
169 /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
171 MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
173 /// MCCodeGenInfoCtorFn - Constructor function for this target's
174 /// MCCodeGenInfo, if registered.
175 MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn;
177 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
179 MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
181 /// MCInstrAnalysisCtorFn - Constructor function for this target's
182 /// MCInstrAnalysis, if registered.
183 MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
185 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
187 MCRegInfoCtorFnTy MCRegInfoCtorFn;
189 /// MCSubtargetInfoCtorFn - Constructor function for this target's
190 /// MCSubtargetInfo, if registered.
191 MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
193 /// TargetMachineCtorFn - Construction function for this target's
194 /// TargetMachine, if registered.
195 TargetMachineCtorTy TargetMachineCtorFn;
197 /// MCAsmBackendCtorFn - Construction function for this target's
198 /// MCAsmBackend, if registered.
199 MCAsmBackendCtorTy MCAsmBackendCtorFn;
201 /// MCAsmParserCtorFn - Construction function for this target's
202 /// MCTargetAsmParser, if registered.
203 MCAsmParserCtorTy MCAsmParserCtorFn;
205 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
207 AsmPrinterCtorTy AsmPrinterCtorFn;
209 /// MCDisassemblerCtorFn - Construction function for this target's
210 /// MCDisassembler, if registered.
211 MCDisassemblerCtorTy MCDisassemblerCtorFn;
213 /// MCInstPrinterCtorFn - Construction function for this target's
214 /// MCInstPrinter, if registered.
215 MCInstPrinterCtorTy MCInstPrinterCtorFn;
217 /// MCCodeEmitterCtorFn - Construction function for this target's
218 /// CodeEmitter, if registered.
219 MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
221 /// MCObjectStreamerCtorFn - Construction function for this target's
222 /// MCObjectStreamer, if registered.
223 MCObjectStreamerCtorTy MCObjectStreamerCtorFn;
225 /// AsmStreamerCtorFn - Construction function for this target's
226 /// AsmStreamer, if registered (default = llvm::createAsmStreamer).
227 AsmStreamerCtorTy AsmStreamerCtorFn;
229 /// MCRelocationInfoCtorFn - Construction function for this target's
230 /// MCRelocationInfo, if registered (default = llvm::createMCRelocationInfo)
231 MCRelocationInfoCtorTy MCRelocationInfoCtorFn;
233 /// MCSymbolizerCtorFn - Construction function for this target's
234 /// MCSymbolizer, if registered (default = llvm::createMCSymbolizer)
235 MCSymbolizerCtorTy MCSymbolizerCtorFn;
238 Target() : AsmStreamerCtorFn(llvm::createAsmStreamer),
239 MCRelocationInfoCtorFn(llvm::createMCRelocationInfo),
240 MCSymbolizerCtorFn(llvm::createMCSymbolizer) {}
242 /// @name Target Information
245 // getNext - Return the next registered target.
246 const Target *getNext() const { return Next; }
248 /// getName - Get the target name.
249 const char *getName() const { return Name; }
251 /// getShortDescription - Get a short description of the target.
252 const char *getShortDescription() const { return ShortDesc; }
255 /// @name Feature Predicates
258 /// hasJIT - Check if this targets supports the just-in-time compilation.
259 bool hasJIT() const { return HasJIT; }
261 /// hasTargetMachine - Check if this target supports code generation.
262 bool hasTargetMachine() const { return TargetMachineCtorFn != 0; }
264 /// hasMCAsmBackend - Check if this target supports .o generation.
265 bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != 0; }
267 /// hasAsmParser - Check if this target supports .s parsing.
268 bool hasMCAsmParser() const { return MCAsmParserCtorFn != 0; }
270 /// hasAsmPrinter - Check if this target supports .s printing.
271 bool hasAsmPrinter() const { return AsmPrinterCtorFn != 0; }
273 /// hasMCDisassembler - Check if this target has a disassembler.
274 bool hasMCDisassembler() const { return MCDisassemblerCtorFn != 0; }
276 /// hasMCInstPrinter - Check if this target has an instruction printer.
277 bool hasMCInstPrinter() const { return MCInstPrinterCtorFn != 0; }
279 /// hasMCCodeEmitter - Check if this target supports instruction encoding.
280 bool hasMCCodeEmitter() const { return MCCodeEmitterCtorFn != 0; }
282 /// hasMCObjectStreamer - Check if this target supports streaming to files.
283 bool hasMCObjectStreamer() const { return MCObjectStreamerCtorFn != 0; }
285 /// hasAsmStreamer - Check if this target supports streaming to files.
286 bool hasAsmStreamer() const { return AsmStreamerCtorFn != 0; }
289 /// @name Feature Constructors
292 /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
295 /// \param Triple This argument is used to determine the target machine
296 /// feature set; it should always be provided. Generally this should be
297 /// either the target triple from the module, or the target triple of the
298 /// host if that does not exist.
299 MCAsmInfo *createMCAsmInfo(const MCRegisterInfo &MRI,
300 StringRef Triple) const {
301 if (!MCAsmInfoCtorFn)
303 return MCAsmInfoCtorFn(MRI, Triple);
306 /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
308 MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model RM,
310 CodeGenOpt::Level OL) const {
311 if (!MCCodeGenInfoCtorFn)
313 return MCCodeGenInfoCtorFn(Triple, RM, CM, OL);
316 /// createMCInstrInfo - Create a MCInstrInfo implementation.
318 MCInstrInfo *createMCInstrInfo() const {
319 if (!MCInstrInfoCtorFn)
321 return MCInstrInfoCtorFn();
324 /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
326 MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
327 if (!MCInstrAnalysisCtorFn)
329 return MCInstrAnalysisCtorFn(Info);
332 /// createMCRegInfo - Create a MCRegisterInfo implementation.
334 MCRegisterInfo *createMCRegInfo(StringRef Triple) const {
335 if (!MCRegInfoCtorFn)
337 return MCRegInfoCtorFn(Triple);
340 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
342 /// \param Triple This argument is used to determine the target machine
343 /// feature set; it should always be provided. Generally this should be
344 /// either the target triple from the module, or the target triple of the
345 /// host if that does not exist.
346 /// \param CPU This specifies the name of the target CPU.
347 /// \param Features This specifies the string representation of the
348 /// additional target features.
349 MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU,
350 StringRef Features) const {
351 if (!MCSubtargetInfoCtorFn)
353 return MCSubtargetInfoCtorFn(Triple, CPU, Features);
356 /// createTargetMachine - Create a target specific machine implementation
357 /// for the specified \p Triple.
359 /// \param Triple This argument is used to determine the target machine
360 /// feature set; it should always be provided. Generally this should be
361 /// either the target triple from the module, or the target triple of the
362 /// host if that does not exist.
363 TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU,
364 StringRef Features, const TargetOptions &Options,
365 Reloc::Model RM = Reloc::Default,
366 CodeModel::Model CM = CodeModel::Default,
367 CodeGenOpt::Level OL = CodeGenOpt::Default) const {
368 if (!TargetMachineCtorFn)
370 return TargetMachineCtorFn(*this, Triple, CPU, Features, Options,
374 /// createMCAsmBackend - Create a target specific assembly parser.
376 /// \param Triple The target triple string.
377 MCAsmBackend *createMCAsmBackend(const MCRegisterInfo &MRI,
378 StringRef Triple, StringRef CPU) const {
379 if (!MCAsmBackendCtorFn)
381 return MCAsmBackendCtorFn(*this, MRI, Triple, CPU);
384 /// createMCAsmParser - Create a target specific assembly parser.
386 /// \param Parser The target independent parser implementation to use for
387 /// parsing and lexing.
388 MCTargetAsmParser *createMCAsmParser(MCSubtargetInfo &STI,
389 MCAsmParser &Parser) const {
390 if (!MCAsmParserCtorFn)
392 return MCAsmParserCtorFn(STI, Parser);
395 /// createAsmPrinter - Create a target specific assembly printer pass. This
396 /// takes ownership of the MCStreamer object.
397 AsmPrinter *createAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) const{
398 if (!AsmPrinterCtorFn)
400 return AsmPrinterCtorFn(TM, Streamer);
403 MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI) const {
404 if (!MCDisassemblerCtorFn)
406 return MCDisassemblerCtorFn(*this, STI);
409 MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
410 const MCAsmInfo &MAI,
411 const MCInstrInfo &MII,
412 const MCRegisterInfo &MRI,
413 const MCSubtargetInfo &STI) const {
414 if (!MCInstPrinterCtorFn)
416 return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, MII, MRI, STI);
420 /// createMCCodeEmitter - Create a target specific code emitter.
421 MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
422 const MCRegisterInfo &MRI,
423 const MCSubtargetInfo &STI,
424 MCContext &Ctx) const {
425 if (!MCCodeEmitterCtorFn)
427 return MCCodeEmitterCtorFn(II, MRI, STI, Ctx);
430 /// createMCObjectStreamer - Create a target specific MCStreamer.
432 /// \param TT The target triple.
433 /// \param Ctx The target context.
434 /// \param TAB The target assembler backend object. Takes ownership.
435 /// \param _OS The stream object.
436 /// \param _Emitter The target independent assembler object.Takes ownership.
437 /// \param RelaxAll Relax all fixups?
438 /// \param NoExecStack Mark file as not needing a executable stack.
439 MCStreamer *createMCObjectStreamer(StringRef TT, MCContext &Ctx,
442 MCCodeEmitter *_Emitter,
444 bool NoExecStack) const {
445 if (!MCObjectStreamerCtorFn)
447 return MCObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter,
448 RelaxAll, NoExecStack);
451 /// createAsmStreamer - Create a target specific MCStreamer.
452 MCStreamer *createAsmStreamer(MCContext &Ctx,
453 formatted_raw_ostream &OS,
457 bool useDwarfDirectory,
458 MCInstPrinter *InstPrint,
461 bool ShowInst) const {
462 // AsmStreamerCtorFn is default to llvm::createAsmStreamer
463 return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useLoc, useCFI,
464 useDwarfDirectory, InstPrint, CE, TAB, ShowInst);
467 /// createMCRelocationInfo - Create a target specific MCRelocationInfo.
469 /// \param TT The target triple.
470 /// \param Ctx The target context.
472 createMCRelocationInfo(StringRef TT, MCContext &Ctx) const {
473 return MCRelocationInfoCtorFn(TT, Ctx);
476 /// createMCSymbolizer - Create a target specific MCSymbolizer.
478 /// \param TT The target triple.
479 /// \param GetOpInfo The function to get the symbolic information for operands.
480 /// \param SymbolLookUp The function to lookup a symbol name.
481 /// \param DisInfo The pointer to the block of symbolic information for above call
483 /// \param Ctx The target context.
484 /// \param RelInfo The relocation information for this target. Takes ownership.
486 createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
487 LLVMSymbolLookupCallback SymbolLookUp,
489 MCContext *Ctx, MCRelocationInfo *RelInfo) const {
490 return MCSymbolizerCtorFn(TT, GetOpInfo, SymbolLookUp, DisInfo,
497 /// TargetRegistry - Generic interface to target specific features.
498 struct TargetRegistry {
500 const Target *Current;
501 explicit iterator(Target *T) : Current(T) {}
502 friend struct TargetRegistry;
504 iterator(const iterator &I) : Current(I.Current) {}
505 iterator() : Current(0) {}
507 bool operator==(const iterator &x) const {
508 return Current == x.Current;
510 bool operator!=(const iterator &x) const {
511 return !operator==(x);
514 // Iterator traversal: forward iteration only
515 iterator &operator++() { // Preincrement
516 assert(Current && "Cannot increment end iterator!");
517 Current = Current->getNext();
520 iterator operator++(int) { // Postincrement
521 iterator tmp = *this;
526 const Target &operator*() const {
527 assert(Current && "Cannot dereference end iterator!");
531 const Target *operator->() const {
536 /// printRegisteredTargetsForVersion - Print the registered targets
537 /// appropriately for inclusion in a tool's version output.
538 static void printRegisteredTargetsForVersion();
540 /// @name Registry Access
543 static iterator begin();
545 static iterator end() { return iterator(); }
547 /// lookupTarget - Lookup a target based on a target triple.
549 /// \param Triple - The triple to use for finding a target.
550 /// \param Error - On failure, an error string describing why no target was
552 static const Target *lookupTarget(const std::string &Triple,
555 /// lookupTarget - Lookup a target based on an architecture name
556 /// and a target triple. If the architecture name is non-empty,
557 /// then the lookup is done by architecture. Otherwise, the target
560 /// \param ArchName - The architecture to use for finding a target.
561 /// \param TheTriple - The triple to use for finding a target. The
562 /// triple is updated with canonical architecture name if a lookup
563 /// by architecture is done.
564 /// \param Error - On failure, an error string describing why no target was
566 static const Target *lookupTarget(const std::string &ArchName,
570 /// getClosestTargetForJIT - Pick the best target that is compatible with
571 /// the current host. If no close target can be found, this returns null
572 /// and sets the Error string to a reason.
574 /// Maintained for compatibility through 2.6.
575 static const Target *getClosestTargetForJIT(std::string &Error);
578 /// @name Target Registration
581 /// RegisterTarget - Register the given target. Attempts to register a
582 /// target which has already been registered will be ignored.
584 /// Clients are responsible for ensuring that registration doesn't occur
585 /// while another thread is attempting to access the registry. Typically
586 /// this is done by initializing all targets at program startup.
588 /// @param T - The target being registered.
589 /// @param Name - The target name. This should be a static string.
590 /// @param ShortDesc - A short target description. This should be a static
592 /// @param TQualityFn - The triple match quality computation function for
594 /// @param HasJIT - Whether the target supports JIT code
596 static void RegisterTarget(Target &T,
598 const char *ShortDesc,
599 Target::TripleMatchQualityFnTy TQualityFn,
600 bool HasJIT = false);
602 /// RegisterMCAsmInfo - Register a MCAsmInfo 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 MCAsmInfo for the target.
611 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
612 // Ignore duplicate registration.
613 if (!T.MCAsmInfoCtorFn)
614 T.MCAsmInfoCtorFn = Fn;
617 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
620 /// Clients are responsible for ensuring that registration doesn't occur
621 /// while another thread is attempting to access the registry. Typically
622 /// this is done by initializing all targets at program startup.
624 /// @param T - The target being registered.
625 /// @param Fn - A function to construct a MCCodeGenInfo for the target.
626 static void RegisterMCCodeGenInfo(Target &T,
627 Target::MCCodeGenInfoCtorFnTy Fn) {
628 // Ignore duplicate registration.
629 if (!T.MCCodeGenInfoCtorFn)
630 T.MCCodeGenInfoCtorFn = Fn;
633 /// RegisterMCInstrInfo - Register a MCInstrInfo 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 MCInstrInfo for the target.
642 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
643 // Ignore duplicate registration.
644 if (!T.MCInstrInfoCtorFn)
645 T.MCInstrInfoCtorFn = Fn;
648 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
649 /// the given target.
650 static void RegisterMCInstrAnalysis(Target &T,
651 Target::MCInstrAnalysisCtorFnTy Fn) {
652 // Ignore duplicate registration.
653 if (!T.MCInstrAnalysisCtorFn)
654 T.MCInstrAnalysisCtorFn = Fn;
657 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
660 /// Clients are responsible for ensuring that registration doesn't occur
661 /// while another thread is attempting to access the registry. Typically
662 /// this is done by initializing all targets at program startup.
664 /// @param T - The target being registered.
665 /// @param Fn - A function to construct a MCRegisterInfo for the target.
666 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
667 // Ignore duplicate registration.
668 if (!T.MCRegInfoCtorFn)
669 T.MCRegInfoCtorFn = Fn;
672 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
673 /// the given target.
675 /// Clients are responsible for ensuring that registration doesn't occur
676 /// while another thread is attempting to access the registry. Typically
677 /// this is done by initializing all targets at program startup.
679 /// @param T - The target being registered.
680 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
681 static void RegisterMCSubtargetInfo(Target &T,
682 Target::MCSubtargetInfoCtorFnTy Fn) {
683 // Ignore duplicate registration.
684 if (!T.MCSubtargetInfoCtorFn)
685 T.MCSubtargetInfoCtorFn = Fn;
688 /// RegisterTargetMachine - Register a TargetMachine implementation for the
691 /// Clients are responsible for ensuring that registration doesn't occur
692 /// while another thread is attempting to access the registry. Typically
693 /// this is done by initializing all targets at program startup.
695 /// @param T - The target being registered.
696 /// @param Fn - A function to construct a TargetMachine for the target.
697 static void RegisterTargetMachine(Target &T,
698 Target::TargetMachineCtorTy Fn) {
699 // Ignore duplicate registration.
700 if (!T.TargetMachineCtorFn)
701 T.TargetMachineCtorFn = Fn;
704 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
707 /// Clients are responsible for ensuring that registration doesn't occur
708 /// while another thread is attempting to access the registry. Typically
709 /// this is done by initializing all targets at program startup.
711 /// @param T - The target being registered.
712 /// @param Fn - A function to construct an AsmBackend for the target.
713 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
714 if (!T.MCAsmBackendCtorFn)
715 T.MCAsmBackendCtorFn = Fn;
718 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
719 /// the given target.
721 /// Clients are responsible for ensuring that registration doesn't occur
722 /// while another thread is attempting to access the registry. Typically
723 /// this is done by initializing all targets at program startup.
725 /// @param T - The target being registered.
726 /// @param Fn - A function to construct an MCTargetAsmParser for the target.
727 static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
728 if (!T.MCAsmParserCtorFn)
729 T.MCAsmParserCtorFn = Fn;
732 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
735 /// Clients are responsible for ensuring that registration doesn't occur
736 /// while another thread is attempting to access the registry. Typically
737 /// this is done by initializing all targets at program startup.
739 /// @param T - The target being registered.
740 /// @param Fn - A function to construct an AsmPrinter for the target.
741 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
742 // Ignore duplicate registration.
743 if (!T.AsmPrinterCtorFn)
744 T.AsmPrinterCtorFn = Fn;
747 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
748 /// the given target.
750 /// Clients are responsible for ensuring that registration doesn't occur
751 /// while another thread is attempting to access the registry. Typically
752 /// this is done by initializing all targets at program startup.
754 /// @param T - The target being registered.
755 /// @param Fn - A function to construct an MCDisassembler for the target.
756 static void RegisterMCDisassembler(Target &T,
757 Target::MCDisassemblerCtorTy Fn) {
758 if (!T.MCDisassemblerCtorFn)
759 T.MCDisassemblerCtorFn = Fn;
762 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
765 /// Clients are responsible for ensuring that registration doesn't occur
766 /// while another thread is attempting to access the registry. Typically
767 /// this is done by initializing all targets at program startup.
769 /// @param T - The target being registered.
770 /// @param Fn - A function to construct an MCInstPrinter for the target.
771 static void RegisterMCInstPrinter(Target &T,
772 Target::MCInstPrinterCtorTy Fn) {
773 if (!T.MCInstPrinterCtorFn)
774 T.MCInstPrinterCtorFn = Fn;
777 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
780 /// Clients are responsible for ensuring that registration doesn't occur
781 /// while another thread is attempting to access the registry. Typically
782 /// this is done by initializing all targets at program startup.
784 /// @param T - The target being registered.
785 /// @param Fn - A function to construct an MCCodeEmitter for the target.
786 static void RegisterMCCodeEmitter(Target &T,
787 Target::MCCodeEmitterCtorTy Fn) {
788 if (!T.MCCodeEmitterCtorFn)
789 T.MCCodeEmitterCtorFn = Fn;
792 /// RegisterMCObjectStreamer - Register a object code MCStreamer
793 /// implementation for the given target.
795 /// Clients are responsible for ensuring that registration doesn't occur
796 /// while another thread is attempting to access the registry. Typically
797 /// this is done by initializing all targets at program startup.
799 /// @param T - The target being registered.
800 /// @param Fn - A function to construct an MCStreamer for the target.
801 static void RegisterMCObjectStreamer(Target &T,
802 Target::MCObjectStreamerCtorTy Fn) {
803 if (!T.MCObjectStreamerCtorFn)
804 T.MCObjectStreamerCtorFn = Fn;
807 /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
808 /// for the given target.
810 /// Clients are responsible for ensuring that registration doesn't occur
811 /// while another thread is attempting to access the registry. Typically
812 /// this is done by initializing all targets at program startup.
814 /// @param T - The target being registered.
815 /// @param Fn - A function to construct an MCStreamer for the target.
816 static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
817 if (T.AsmStreamerCtorFn == createAsmStreamer)
818 T.AsmStreamerCtorFn = Fn;
821 /// RegisterMCRelocationInfo - Register an MCRelocationInfo
822 /// implementation for the given target.
824 /// Clients are responsible for ensuring that registration doesn't occur
825 /// while another thread is attempting to access the registry. Typically
826 /// this is done by initializing all targets at program startup.
828 /// @param T - The target being registered.
829 /// @param Fn - A function to construct an MCRelocationInfo for the target.
830 static void RegisterMCRelocationInfo(Target &T,
831 Target::MCRelocationInfoCtorTy Fn) {
832 if (T.MCRelocationInfoCtorFn == llvm::createMCRelocationInfo)
833 T.MCRelocationInfoCtorFn = Fn;
836 /// RegisterMCSymbolizer - Register an MCSymbolizer
837 /// implementation for the given target.
839 /// Clients are responsible for ensuring that registration doesn't occur
840 /// while another thread is attempting to access the registry. Typically
841 /// this is done by initializing all targets at program startup.
843 /// @param T - The target being registered.
844 /// @param Fn - A function to construct an MCSymbolizer for the target.
845 static void RegisterMCSymbolizer(Target &T,
846 Target::MCSymbolizerCtorTy Fn) {
847 if (T.MCSymbolizerCtorFn == llvm::createMCSymbolizer)
848 T.MCSymbolizerCtorFn = Fn;
855 //===--------------------------------------------------------------------===//
857 /// RegisterTarget - Helper template for registering a target, for use in the
858 /// target's initialization function. Usage:
861 /// Target TheFooTarget; // The global target instance.
863 /// extern "C" void LLVMInitializeFooTargetInfo() {
864 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
866 template<Triple::ArchType TargetArchType = Triple::UnknownArch,
868 struct RegisterTarget {
869 RegisterTarget(Target &T, const char *Name, const char *Desc) {
870 TargetRegistry::RegisterTarget(T, Name, Desc,
871 &getTripleMatchQuality,
875 static unsigned getTripleMatchQuality(const std::string &TT) {
876 if (Triple(TT).getArch() == TargetArchType)
882 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
883 /// implementation. This invokes the static "Create" method on the class to
884 /// actually do the construction. Usage:
886 /// extern "C" void LLVMInitializeFooTarget() {
887 /// extern Target TheFooTarget;
888 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
890 template<class MCAsmInfoImpl>
891 struct RegisterMCAsmInfo {
892 RegisterMCAsmInfo(Target &T) {
893 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
896 static MCAsmInfo *Allocator(const MCRegisterInfo &/*MRI*/, StringRef TT) {
897 return new MCAsmInfoImpl(TT);
902 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
903 /// implementation. This invokes the specified function to do the
904 /// construction. Usage:
906 /// extern "C" void LLVMInitializeFooTarget() {
907 /// extern Target TheFooTarget;
908 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
910 struct RegisterMCAsmInfoFn {
911 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
912 TargetRegistry::RegisterMCAsmInfo(T, Fn);
916 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
917 /// implementation. This invokes the static "Create" method on the class
918 /// to actually do the construction. Usage:
920 /// extern "C" void LLVMInitializeFooTarget() {
921 /// extern Target TheFooTarget;
922 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
924 template<class MCCodeGenInfoImpl>
925 struct RegisterMCCodeGenInfo {
926 RegisterMCCodeGenInfo(Target &T) {
927 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
930 static MCCodeGenInfo *Allocator(StringRef /*TT*/, Reloc::Model /*RM*/,
931 CodeModel::Model /*CM*/,
932 CodeGenOpt::Level /*OL*/) {
933 return new MCCodeGenInfoImpl();
937 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
938 /// info implementation. This invokes the specified function to do the
939 /// construction. Usage:
941 /// extern "C" void LLVMInitializeFooTarget() {
942 /// extern Target TheFooTarget;
943 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
945 struct RegisterMCCodeGenInfoFn {
946 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
947 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
951 /// RegisterMCInstrInfo - Helper template for registering a target instruction
952 /// info implementation. This invokes the static "Create" method on the class
953 /// to actually do the construction. Usage:
955 /// extern "C" void LLVMInitializeFooTarget() {
956 /// extern Target TheFooTarget;
957 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
959 template<class MCInstrInfoImpl>
960 struct RegisterMCInstrInfo {
961 RegisterMCInstrInfo(Target &T) {
962 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
965 static MCInstrInfo *Allocator() {
966 return new MCInstrInfoImpl();
970 /// RegisterMCInstrInfoFn - Helper template for registering a target
971 /// instruction info implementation. This invokes the specified function to
972 /// do the construction. Usage:
974 /// extern "C" void LLVMInitializeFooTarget() {
975 /// extern Target TheFooTarget;
976 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
978 struct RegisterMCInstrInfoFn {
979 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
980 TargetRegistry::RegisterMCInstrInfo(T, Fn);
984 /// RegisterMCInstrAnalysis - Helper template for registering a target
985 /// instruction analyzer implementation. This invokes the static "Create"
986 /// method on the class to actually do the construction. Usage:
988 /// extern "C" void LLVMInitializeFooTarget() {
989 /// extern Target TheFooTarget;
990 /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
992 template<class MCInstrAnalysisImpl>
993 struct RegisterMCInstrAnalysis {
994 RegisterMCInstrAnalysis(Target &T) {
995 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
998 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
999 return new MCInstrAnalysisImpl(Info);
1003 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
1004 /// instruction analyzer implementation. This invokes the specified function
1005 /// to do the construction. Usage:
1007 /// extern "C" void LLVMInitializeFooTarget() {
1008 /// extern Target TheFooTarget;
1009 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
1011 struct RegisterMCInstrAnalysisFn {
1012 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
1013 TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
1017 /// RegisterMCRegInfo - Helper template for registering a target register info
1018 /// implementation. This invokes the static "Create" method on the class to
1019 /// actually do the construction. Usage:
1021 /// extern "C" void LLVMInitializeFooTarget() {
1022 /// extern Target TheFooTarget;
1023 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
1025 template<class MCRegisterInfoImpl>
1026 struct RegisterMCRegInfo {
1027 RegisterMCRegInfo(Target &T) {
1028 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
1031 static MCRegisterInfo *Allocator(StringRef /*TT*/) {
1032 return new MCRegisterInfoImpl();
1036 /// RegisterMCRegInfoFn - Helper template for registering a target register
1037 /// info implementation. This invokes the specified function to do the
1038 /// construction. Usage:
1040 /// extern "C" void LLVMInitializeFooTarget() {
1041 /// extern Target TheFooTarget;
1042 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
1044 struct RegisterMCRegInfoFn {
1045 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
1046 TargetRegistry::RegisterMCRegInfo(T, Fn);
1050 /// RegisterMCSubtargetInfo - Helper template for registering a target
1051 /// subtarget info implementation. This invokes the static "Create" method
1052 /// on the class to actually do the construction. Usage:
1054 /// extern "C" void LLVMInitializeFooTarget() {
1055 /// extern Target TheFooTarget;
1056 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
1058 template<class MCSubtargetInfoImpl>
1059 struct RegisterMCSubtargetInfo {
1060 RegisterMCSubtargetInfo(Target &T) {
1061 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
1064 static MCSubtargetInfo *Allocator(StringRef /*TT*/, StringRef /*CPU*/,
1066 return new MCSubtargetInfoImpl();
1070 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
1071 /// subtarget info implementation. This invokes the specified function to
1072 /// do the construction. Usage:
1074 /// extern "C" void LLVMInitializeFooTarget() {
1075 /// extern Target TheFooTarget;
1076 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1078 struct RegisterMCSubtargetInfoFn {
1079 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
1080 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
1084 /// RegisterTargetMachine - Helper template for registering a target machine
1085 /// implementation, for use in the target machine initialization
1086 /// function. Usage:
1088 /// extern "C" void LLVMInitializeFooTarget() {
1089 /// extern Target TheFooTarget;
1090 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1092 template<class TargetMachineImpl>
1093 struct RegisterTargetMachine {
1094 RegisterTargetMachine(Target &T) {
1095 TargetRegistry::RegisterTargetMachine(T, &Allocator);
1099 static TargetMachine *Allocator(const Target &T, StringRef TT,
1100 StringRef CPU, StringRef FS,
1101 const TargetOptions &Options,
1103 CodeModel::Model CM,
1104 CodeGenOpt::Level OL) {
1105 return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
1109 /// RegisterMCAsmBackend - Helper template for registering a target specific
1110 /// assembler backend. Usage:
1112 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1113 /// extern Target TheFooTarget;
1114 /// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1116 template<class MCAsmBackendImpl>
1117 struct RegisterMCAsmBackend {
1118 RegisterMCAsmBackend(Target &T) {
1119 TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1123 static MCAsmBackend *Allocator(const Target &T,
1124 const MCRegisterInfo &MRI,
1125 StringRef Triple, StringRef CPU) {
1126 return new MCAsmBackendImpl(T, MRI, Triple, CPU);
1130 /// RegisterMCAsmParser - Helper template for registering a target specific
1131 /// assembly parser, for use in the target machine initialization
1132 /// function. Usage:
1134 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1135 /// extern Target TheFooTarget;
1136 /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1138 template<class MCAsmParserImpl>
1139 struct RegisterMCAsmParser {
1140 RegisterMCAsmParser(Target &T) {
1141 TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1145 static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P) {
1146 return new MCAsmParserImpl(STI, P);
1150 /// RegisterAsmPrinter - Helper template for registering a target specific
1151 /// assembly printer, for use in the target machine initialization
1152 /// function. Usage:
1154 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1155 /// extern Target TheFooTarget;
1156 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1158 template<class AsmPrinterImpl>
1159 struct RegisterAsmPrinter {
1160 RegisterAsmPrinter(Target &T) {
1161 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1165 static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) {
1166 return new AsmPrinterImpl(TM, Streamer);
1170 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1171 /// machine code emitter, for use in the target initialization
1172 /// function. Usage:
1174 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1175 /// extern Target TheFooTarget;
1176 /// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1178 template<class MCCodeEmitterImpl>
1179 struct RegisterMCCodeEmitter {
1180 RegisterMCCodeEmitter(Target &T) {
1181 TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1185 static MCCodeEmitter *Allocator(const MCInstrInfo &/*II*/,
1186 const MCRegisterInfo &/*MRI*/,
1187 const MCSubtargetInfo &/*STI*/,
1188 MCContext &/*Ctx*/) {
1189 return new MCCodeEmitterImpl();