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 const MCInstrInfo &MII);
113 typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T,
114 const MCSubtargetInfo &STI);
115 typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
116 unsigned SyntaxVariant,
117 const MCAsmInfo &MAI,
118 const MCInstrInfo &MII,
119 const MCRegisterInfo &MRI,
120 const MCSubtargetInfo &STI);
121 typedef MCCodeEmitter *(*MCCodeEmitterCtorTy)(const MCInstrInfo &II,
122 const MCRegisterInfo &MRI,
123 const MCSubtargetInfo &STI,
125 typedef MCStreamer *(*MCObjectStreamerCtorTy)(const Target &T,
130 MCCodeEmitter *_Emitter,
133 typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx,
134 formatted_raw_ostream &OS,
138 bool useDwarfDirectory,
139 MCInstPrinter *InstPrint,
143 typedef MCRelocationInfo *(*MCRelocationInfoCtorTy)(StringRef TT,
145 typedef MCSymbolizer *(*MCSymbolizerCtorTy)(StringRef TT,
146 LLVMOpInfoCallback GetOpInfo,
147 LLVMSymbolLookupCallback SymbolLookUp,
150 MCRelocationInfo *RelInfo);
153 /// Next - The next registered target in the linked list, maintained by the
157 /// TripleMatchQualityFn - The target function for rating the match quality
159 TripleMatchQualityFnTy TripleMatchQualityFn;
161 /// Name - The target name.
164 /// ShortDesc - A short description of the target.
165 const char *ShortDesc;
167 /// HasJIT - Whether this target supports the JIT.
170 /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
172 MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
174 /// MCCodeGenInfoCtorFn - Constructor function for this target's
175 /// MCCodeGenInfo, if registered.
176 MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn;
178 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
180 MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
182 /// MCInstrAnalysisCtorFn - Constructor function for this target's
183 /// MCInstrAnalysis, if registered.
184 MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
186 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
188 MCRegInfoCtorFnTy MCRegInfoCtorFn;
190 /// MCSubtargetInfoCtorFn - Constructor function for this target's
191 /// MCSubtargetInfo, if registered.
192 MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
194 /// TargetMachineCtorFn - Construction function for this target's
195 /// TargetMachine, if registered.
196 TargetMachineCtorTy TargetMachineCtorFn;
198 /// MCAsmBackendCtorFn - Construction function for this target's
199 /// MCAsmBackend, if registered.
200 MCAsmBackendCtorTy MCAsmBackendCtorFn;
202 /// MCAsmParserCtorFn - Construction function for this target's
203 /// MCTargetAsmParser, if registered.
204 MCAsmParserCtorTy MCAsmParserCtorFn;
206 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
208 AsmPrinterCtorTy AsmPrinterCtorFn;
210 /// MCDisassemblerCtorFn - Construction function for this target's
211 /// MCDisassembler, if registered.
212 MCDisassemblerCtorTy MCDisassemblerCtorFn;
214 /// MCInstPrinterCtorFn - Construction function for this target's
215 /// MCInstPrinter, if registered.
216 MCInstPrinterCtorTy MCInstPrinterCtorFn;
218 /// MCCodeEmitterCtorFn - Construction function for this target's
219 /// CodeEmitter, if registered.
220 MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
222 /// MCObjectStreamerCtorFn - Construction function for this target's
223 /// MCObjectStreamer, if registered.
224 MCObjectStreamerCtorTy MCObjectStreamerCtorFn;
226 /// AsmStreamerCtorFn - Construction function for this target's
227 /// AsmStreamer, if registered (default = llvm::createAsmStreamer).
228 AsmStreamerCtorTy AsmStreamerCtorFn;
230 /// MCRelocationInfoCtorFn - Construction function for this target's
231 /// MCRelocationInfo, if registered (default = llvm::createMCRelocationInfo)
232 MCRelocationInfoCtorTy MCRelocationInfoCtorFn;
234 /// MCSymbolizerCtorFn - Construction function for this target's
235 /// MCSymbolizer, if registered (default = llvm::createMCSymbolizer)
236 MCSymbolizerCtorTy MCSymbolizerCtorFn;
239 Target() : AsmStreamerCtorFn(llvm::createAsmStreamer),
240 MCRelocationInfoCtorFn(llvm::createMCRelocationInfo),
241 MCSymbolizerCtorFn(llvm::createMCSymbolizer) {}
243 /// @name Target Information
246 // getNext - Return the next registered target.
247 const Target *getNext() const { return Next; }
249 /// getName - Get the target name.
250 const char *getName() const { return Name; }
252 /// getShortDescription - Get a short description of the target.
253 const char *getShortDescription() const { return ShortDesc; }
256 /// @name Feature Predicates
259 /// hasJIT - Check if this targets supports the just-in-time compilation.
260 bool hasJIT() const { return HasJIT; }
262 /// hasTargetMachine - Check if this target supports code generation.
263 bool hasTargetMachine() const { return TargetMachineCtorFn != 0; }
265 /// hasMCAsmBackend - Check if this target supports .o generation.
266 bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != 0; }
268 /// hasAsmParser - Check if this target supports .s parsing.
269 bool hasMCAsmParser() const { return MCAsmParserCtorFn != 0; }
271 /// hasAsmPrinter - Check if this target supports .s printing.
272 bool hasAsmPrinter() const { return AsmPrinterCtorFn != 0; }
274 /// hasMCDisassembler - Check if this target has a disassembler.
275 bool hasMCDisassembler() const { return MCDisassemblerCtorFn != 0; }
277 /// hasMCInstPrinter - Check if this target has an instruction printer.
278 bool hasMCInstPrinter() const { return MCInstPrinterCtorFn != 0; }
280 /// hasMCCodeEmitter - Check if this target supports instruction encoding.
281 bool hasMCCodeEmitter() const { return MCCodeEmitterCtorFn != 0; }
283 /// hasMCObjectStreamer - Check if this target supports streaming to files.
284 bool hasMCObjectStreamer() const { return MCObjectStreamerCtorFn != 0; }
286 /// hasAsmStreamer - Check if this target supports streaming to files.
287 bool hasAsmStreamer() const { return AsmStreamerCtorFn != 0; }
290 /// @name Feature Constructors
293 /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
296 /// \param Triple This argument is used to determine the target machine
297 /// feature set; it should always be provided. Generally this should be
298 /// either the target triple from the module, or the target triple of the
299 /// host if that does not exist.
300 MCAsmInfo *createMCAsmInfo(const MCRegisterInfo &MRI,
301 StringRef Triple) const {
302 if (!MCAsmInfoCtorFn)
304 return MCAsmInfoCtorFn(MRI, Triple);
307 /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
309 MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model RM,
311 CodeGenOpt::Level OL) const {
312 if (!MCCodeGenInfoCtorFn)
314 return MCCodeGenInfoCtorFn(Triple, RM, CM, OL);
317 /// createMCInstrInfo - Create a MCInstrInfo implementation.
319 MCInstrInfo *createMCInstrInfo() const {
320 if (!MCInstrInfoCtorFn)
322 return MCInstrInfoCtorFn();
325 /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
327 MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
328 if (!MCInstrAnalysisCtorFn)
330 return MCInstrAnalysisCtorFn(Info);
333 /// createMCRegInfo - Create a MCRegisterInfo implementation.
335 MCRegisterInfo *createMCRegInfo(StringRef Triple) const {
336 if (!MCRegInfoCtorFn)
338 return MCRegInfoCtorFn(Triple);
341 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
343 /// \param Triple This argument is used to determine the target machine
344 /// feature set; it should always be provided. Generally this should be
345 /// either the target triple from the module, or the target triple of the
346 /// host if that does not exist.
347 /// \param CPU This specifies the name of the target CPU.
348 /// \param Features This specifies the string representation of the
349 /// additional target features.
350 MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU,
351 StringRef Features) const {
352 if (!MCSubtargetInfoCtorFn)
354 return MCSubtargetInfoCtorFn(Triple, CPU, Features);
357 /// createTargetMachine - Create a target specific machine implementation
358 /// for the specified \p Triple.
360 /// \param Triple This argument is used to determine the target machine
361 /// feature set; it should always be provided. Generally this should be
362 /// either the target triple from the module, or the target triple of the
363 /// host if that does not exist.
364 TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU,
365 StringRef Features, const TargetOptions &Options,
366 Reloc::Model RM = Reloc::Default,
367 CodeModel::Model CM = CodeModel::Default,
368 CodeGenOpt::Level OL = CodeGenOpt::Default) const {
369 if (!TargetMachineCtorFn)
371 return TargetMachineCtorFn(*this, Triple, CPU, Features, Options,
375 /// createMCAsmBackend - Create a target specific assembly parser.
377 /// \param Triple The target triple string.
378 MCAsmBackend *createMCAsmBackend(const MCRegisterInfo &MRI,
379 StringRef Triple, StringRef CPU) const {
380 if (!MCAsmBackendCtorFn)
382 return MCAsmBackendCtorFn(*this, MRI, Triple, CPU);
385 /// createMCAsmParser - Create a target specific assembly parser.
387 /// \param Parser The target independent parser implementation to use for
388 /// parsing and lexing.
389 MCTargetAsmParser *createMCAsmParser(MCSubtargetInfo &STI,
391 const MCInstrInfo &MII) const {
392 if (!MCAsmParserCtorFn)
394 return MCAsmParserCtorFn(STI, Parser, MII);
397 /// createAsmPrinter - Create a target specific assembly printer pass. This
398 /// takes ownership of the MCStreamer object.
399 AsmPrinter *createAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) const{
400 if (!AsmPrinterCtorFn)
402 return AsmPrinterCtorFn(TM, Streamer);
405 MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI) const {
406 if (!MCDisassemblerCtorFn)
408 return MCDisassemblerCtorFn(*this, STI);
411 MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
412 const MCAsmInfo &MAI,
413 const MCInstrInfo &MII,
414 const MCRegisterInfo &MRI,
415 const MCSubtargetInfo &STI) const {
416 if (!MCInstPrinterCtorFn)
418 return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, MII, MRI, STI);
422 /// createMCCodeEmitter - Create a target specific code emitter.
423 MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
424 const MCRegisterInfo &MRI,
425 const MCSubtargetInfo &STI,
426 MCContext &Ctx) const {
427 if (!MCCodeEmitterCtorFn)
429 return MCCodeEmitterCtorFn(II, MRI, STI, Ctx);
432 /// createMCObjectStreamer - Create a target specific MCStreamer.
434 /// \param TT The target triple.
435 /// \param Ctx The target context.
436 /// \param TAB The target assembler backend object. Takes ownership.
437 /// \param _OS The stream object.
438 /// \param _Emitter The target independent assembler object.Takes ownership.
439 /// \param RelaxAll Relax all fixups?
440 /// \param NoExecStack Mark file as not needing a executable stack.
441 MCStreamer *createMCObjectStreamer(StringRef TT, MCContext &Ctx,
444 MCCodeEmitter *_Emitter,
446 bool NoExecStack) const {
447 if (!MCObjectStreamerCtorFn)
449 return MCObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter,
450 RelaxAll, NoExecStack);
453 /// createAsmStreamer - Create a target specific MCStreamer.
454 MCStreamer *createAsmStreamer(MCContext &Ctx,
455 formatted_raw_ostream &OS,
459 bool useDwarfDirectory,
460 MCInstPrinter *InstPrint,
463 bool ShowInst) const {
464 // AsmStreamerCtorFn is default to llvm::createAsmStreamer
465 return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useLoc, useCFI,
466 useDwarfDirectory, InstPrint, CE, TAB, ShowInst);
469 /// createMCRelocationInfo - Create a target specific MCRelocationInfo.
471 /// \param TT The target triple.
472 /// \param Ctx The target context.
474 createMCRelocationInfo(StringRef TT, MCContext &Ctx) const {
475 return MCRelocationInfoCtorFn(TT, Ctx);
478 /// createMCSymbolizer - Create a target specific MCSymbolizer.
480 /// \param TT The target triple.
481 /// \param GetOpInfo The function to get the symbolic information for operands.
482 /// \param SymbolLookUp The function to lookup a symbol name.
483 /// \param DisInfo The pointer to the block of symbolic information for above call
485 /// \param Ctx The target context.
486 /// \param RelInfo The relocation information for this target. Takes ownership.
488 createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
489 LLVMSymbolLookupCallback SymbolLookUp,
491 MCContext *Ctx, MCRelocationInfo *RelInfo) const {
492 return MCSymbolizerCtorFn(TT, GetOpInfo, SymbolLookUp, DisInfo,
499 /// TargetRegistry - Generic interface to target specific features.
500 struct TargetRegistry {
502 const Target *Current;
503 explicit iterator(Target *T) : Current(T) {}
504 friend struct TargetRegistry;
506 iterator(const iterator &I) : Current(I.Current) {}
507 iterator() : Current(0) {}
509 bool operator==(const iterator &x) const {
510 return Current == x.Current;
512 bool operator!=(const iterator &x) const {
513 return !operator==(x);
516 // Iterator traversal: forward iteration only
517 iterator &operator++() { // Preincrement
518 assert(Current && "Cannot increment end iterator!");
519 Current = Current->getNext();
522 iterator operator++(int) { // Postincrement
523 iterator tmp = *this;
528 const Target &operator*() const {
529 assert(Current && "Cannot dereference end iterator!");
533 const Target *operator->() const {
538 /// printRegisteredTargetsForVersion - Print the registered targets
539 /// appropriately for inclusion in a tool's version output.
540 static void printRegisteredTargetsForVersion();
542 /// @name Registry Access
545 static iterator begin();
547 static iterator end() { return iterator(); }
549 /// lookupTarget - Lookup a target based on a target triple.
551 /// \param Triple - The triple to use for finding a target.
552 /// \param Error - On failure, an error string describing why no target was
554 static const Target *lookupTarget(const std::string &Triple,
557 /// lookupTarget - Lookup a target based on an architecture name
558 /// and a target triple. If the architecture name is non-empty,
559 /// then the lookup is done by architecture. Otherwise, the target
562 /// \param ArchName - The architecture to use for finding a target.
563 /// \param TheTriple - The triple to use for finding a target. The
564 /// triple is updated with canonical architecture name if a lookup
565 /// by architecture is done.
566 /// \param Error - On failure, an error string describing why no target was
568 static const Target *lookupTarget(const std::string &ArchName,
572 /// getClosestTargetForJIT - Pick the best target that is compatible with
573 /// the current host. If no close target can be found, this returns null
574 /// and sets the Error string to a reason.
576 /// Maintained for compatibility through 2.6.
577 static const Target *getClosestTargetForJIT(std::string &Error);
580 /// @name Target Registration
583 /// RegisterTarget - Register the given target. Attempts to register a
584 /// target which has already been registered will be ignored.
586 /// Clients are responsible for ensuring that registration doesn't occur
587 /// while another thread is attempting to access the registry. Typically
588 /// this is done by initializing all targets at program startup.
590 /// @param T - The target being registered.
591 /// @param Name - The target name. This should be a static string.
592 /// @param ShortDesc - A short target description. This should be a static
594 /// @param TQualityFn - The triple match quality computation function for
596 /// @param HasJIT - Whether the target supports JIT code
598 static void RegisterTarget(Target &T,
600 const char *ShortDesc,
601 Target::TripleMatchQualityFnTy TQualityFn,
602 bool HasJIT = false);
604 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
607 /// Clients are responsible for ensuring that registration doesn't occur
608 /// while another thread is attempting to access the registry. Typically
609 /// this is done by initializing all targets at program startup.
611 /// @param T - The target being registered.
612 /// @param Fn - A function to construct a MCAsmInfo for the target.
613 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
614 // Ignore duplicate registration.
615 if (!T.MCAsmInfoCtorFn)
616 T.MCAsmInfoCtorFn = Fn;
619 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
622 /// Clients are responsible for ensuring that registration doesn't occur
623 /// while another thread is attempting to access the registry. Typically
624 /// this is done by initializing all targets at program startup.
626 /// @param T - The target being registered.
627 /// @param Fn - A function to construct a MCCodeGenInfo for the target.
628 static void RegisterMCCodeGenInfo(Target &T,
629 Target::MCCodeGenInfoCtorFnTy Fn) {
630 // Ignore duplicate registration.
631 if (!T.MCCodeGenInfoCtorFn)
632 T.MCCodeGenInfoCtorFn = Fn;
635 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
638 /// Clients are responsible for ensuring that registration doesn't occur
639 /// while another thread is attempting to access the registry. Typically
640 /// this is done by initializing all targets at program startup.
642 /// @param T - The target being registered.
643 /// @param Fn - A function to construct a MCInstrInfo for the target.
644 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
645 // Ignore duplicate registration.
646 if (!T.MCInstrInfoCtorFn)
647 T.MCInstrInfoCtorFn = Fn;
650 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
651 /// the given target.
652 static void RegisterMCInstrAnalysis(Target &T,
653 Target::MCInstrAnalysisCtorFnTy Fn) {
654 // Ignore duplicate registration.
655 if (!T.MCInstrAnalysisCtorFn)
656 T.MCInstrAnalysisCtorFn = Fn;
659 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
662 /// Clients are responsible for ensuring that registration doesn't occur
663 /// while another thread is attempting to access the registry. Typically
664 /// this is done by initializing all targets at program startup.
666 /// @param T - The target being registered.
667 /// @param Fn - A function to construct a MCRegisterInfo for the target.
668 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
669 // Ignore duplicate registration.
670 if (!T.MCRegInfoCtorFn)
671 T.MCRegInfoCtorFn = Fn;
674 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
675 /// the given target.
677 /// Clients are responsible for ensuring that registration doesn't occur
678 /// while another thread is attempting to access the registry. Typically
679 /// this is done by initializing all targets at program startup.
681 /// @param T - The target being registered.
682 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
683 static void RegisterMCSubtargetInfo(Target &T,
684 Target::MCSubtargetInfoCtorFnTy Fn) {
685 // Ignore duplicate registration.
686 if (!T.MCSubtargetInfoCtorFn)
687 T.MCSubtargetInfoCtorFn = Fn;
690 /// RegisterTargetMachine - Register a TargetMachine implementation for the
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 a TargetMachine for the target.
699 static void RegisterTargetMachine(Target &T,
700 Target::TargetMachineCtorTy Fn) {
701 // Ignore duplicate registration.
702 if (!T.TargetMachineCtorFn)
703 T.TargetMachineCtorFn = Fn;
706 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
709 /// Clients are responsible for ensuring that registration doesn't occur
710 /// while another thread is attempting to access the registry. Typically
711 /// this is done by initializing all targets at program startup.
713 /// @param T - The target being registered.
714 /// @param Fn - A function to construct an AsmBackend for the target.
715 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
716 if (!T.MCAsmBackendCtorFn)
717 T.MCAsmBackendCtorFn = Fn;
720 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
721 /// the given target.
723 /// Clients are responsible for ensuring that registration doesn't occur
724 /// while another thread is attempting to access the registry. Typically
725 /// this is done by initializing all targets at program startup.
727 /// @param T - The target being registered.
728 /// @param Fn - A function to construct an MCTargetAsmParser for the target.
729 static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
730 if (!T.MCAsmParserCtorFn)
731 T.MCAsmParserCtorFn = Fn;
734 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
737 /// Clients are responsible for ensuring that registration doesn't occur
738 /// while another thread is attempting to access the registry. Typically
739 /// this is done by initializing all targets at program startup.
741 /// @param T - The target being registered.
742 /// @param Fn - A function to construct an AsmPrinter for the target.
743 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
744 // Ignore duplicate registration.
745 if (!T.AsmPrinterCtorFn)
746 T.AsmPrinterCtorFn = Fn;
749 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
750 /// the given target.
752 /// Clients are responsible for ensuring that registration doesn't occur
753 /// while another thread is attempting to access the registry. Typically
754 /// this is done by initializing all targets at program startup.
756 /// @param T - The target being registered.
757 /// @param Fn - A function to construct an MCDisassembler for the target.
758 static void RegisterMCDisassembler(Target &T,
759 Target::MCDisassemblerCtorTy Fn) {
760 if (!T.MCDisassemblerCtorFn)
761 T.MCDisassemblerCtorFn = Fn;
764 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
767 /// Clients are responsible for ensuring that registration doesn't occur
768 /// while another thread is attempting to access the registry. Typically
769 /// this is done by initializing all targets at program startup.
771 /// @param T - The target being registered.
772 /// @param Fn - A function to construct an MCInstPrinter for the target.
773 static void RegisterMCInstPrinter(Target &T,
774 Target::MCInstPrinterCtorTy Fn) {
775 if (!T.MCInstPrinterCtorFn)
776 T.MCInstPrinterCtorFn = Fn;
779 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
782 /// Clients are responsible for ensuring that registration doesn't occur
783 /// while another thread is attempting to access the registry. Typically
784 /// this is done by initializing all targets at program startup.
786 /// @param T - The target being registered.
787 /// @param Fn - A function to construct an MCCodeEmitter for the target.
788 static void RegisterMCCodeEmitter(Target &T,
789 Target::MCCodeEmitterCtorTy Fn) {
790 if (!T.MCCodeEmitterCtorFn)
791 T.MCCodeEmitterCtorFn = Fn;
794 /// RegisterMCObjectStreamer - Register a object code MCStreamer
795 /// implementation for the given target.
797 /// Clients are responsible for ensuring that registration doesn't occur
798 /// while another thread is attempting to access the registry. Typically
799 /// this is done by initializing all targets at program startup.
801 /// @param T - The target being registered.
802 /// @param Fn - A function to construct an MCStreamer for the target.
803 static void RegisterMCObjectStreamer(Target &T,
804 Target::MCObjectStreamerCtorTy Fn) {
805 if (!T.MCObjectStreamerCtorFn)
806 T.MCObjectStreamerCtorFn = Fn;
809 /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
810 /// for the given target.
812 /// Clients are responsible for ensuring that registration doesn't occur
813 /// while another thread is attempting to access the registry. Typically
814 /// this is done by initializing all targets at program startup.
816 /// @param T - The target being registered.
817 /// @param Fn - A function to construct an MCStreamer for the target.
818 static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
819 if (T.AsmStreamerCtorFn == createAsmStreamer)
820 T.AsmStreamerCtorFn = Fn;
823 /// RegisterMCRelocationInfo - Register an MCRelocationInfo
824 /// implementation for the given target.
826 /// Clients are responsible for ensuring that registration doesn't occur
827 /// while another thread is attempting to access the registry. Typically
828 /// this is done by initializing all targets at program startup.
830 /// @param T - The target being registered.
831 /// @param Fn - A function to construct an MCRelocationInfo for the target.
832 static void RegisterMCRelocationInfo(Target &T,
833 Target::MCRelocationInfoCtorTy Fn) {
834 if (T.MCRelocationInfoCtorFn == llvm::createMCRelocationInfo)
835 T.MCRelocationInfoCtorFn = Fn;
838 /// RegisterMCSymbolizer - Register an MCSymbolizer
839 /// implementation for the given target.
841 /// Clients are responsible for ensuring that registration doesn't occur
842 /// while another thread is attempting to access the registry. Typically
843 /// this is done by initializing all targets at program startup.
845 /// @param T - The target being registered.
846 /// @param Fn - A function to construct an MCSymbolizer for the target.
847 static void RegisterMCSymbolizer(Target &T,
848 Target::MCSymbolizerCtorTy Fn) {
849 if (T.MCSymbolizerCtorFn == llvm::createMCSymbolizer)
850 T.MCSymbolizerCtorFn = Fn;
857 //===--------------------------------------------------------------------===//
859 /// RegisterTarget - Helper template for registering a target, for use in the
860 /// target's initialization function. Usage:
863 /// Target TheFooTarget; // The global target instance.
865 /// extern "C" void LLVMInitializeFooTargetInfo() {
866 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
868 template<Triple::ArchType TargetArchType = Triple::UnknownArch,
870 struct RegisterTarget {
871 RegisterTarget(Target &T, const char *Name, const char *Desc) {
872 TargetRegistry::RegisterTarget(T, Name, Desc,
873 &getTripleMatchQuality,
877 static unsigned getTripleMatchQuality(const std::string &TT) {
878 if (Triple(TT).getArch() == TargetArchType)
884 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
885 /// implementation. This invokes the static "Create" method on the class to
886 /// actually do the construction. Usage:
888 /// extern "C" void LLVMInitializeFooTarget() {
889 /// extern Target TheFooTarget;
890 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
892 template<class MCAsmInfoImpl>
893 struct RegisterMCAsmInfo {
894 RegisterMCAsmInfo(Target &T) {
895 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
898 static MCAsmInfo *Allocator(const MCRegisterInfo &/*MRI*/, StringRef TT) {
899 return new MCAsmInfoImpl(TT);
904 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
905 /// implementation. This invokes the specified function to do the
906 /// construction. Usage:
908 /// extern "C" void LLVMInitializeFooTarget() {
909 /// extern Target TheFooTarget;
910 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
912 struct RegisterMCAsmInfoFn {
913 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
914 TargetRegistry::RegisterMCAsmInfo(T, Fn);
918 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
919 /// implementation. This invokes the static "Create" method on the class
920 /// to actually do the construction. Usage:
922 /// extern "C" void LLVMInitializeFooTarget() {
923 /// extern Target TheFooTarget;
924 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
926 template<class MCCodeGenInfoImpl>
927 struct RegisterMCCodeGenInfo {
928 RegisterMCCodeGenInfo(Target &T) {
929 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
932 static MCCodeGenInfo *Allocator(StringRef /*TT*/, Reloc::Model /*RM*/,
933 CodeModel::Model /*CM*/,
934 CodeGenOpt::Level /*OL*/) {
935 return new MCCodeGenInfoImpl();
939 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
940 /// info implementation. This invokes the specified function to do the
941 /// construction. Usage:
943 /// extern "C" void LLVMInitializeFooTarget() {
944 /// extern Target TheFooTarget;
945 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
947 struct RegisterMCCodeGenInfoFn {
948 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
949 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
953 /// RegisterMCInstrInfo - Helper template for registering a target instruction
954 /// info implementation. This invokes the static "Create" method on the class
955 /// to actually do the construction. Usage:
957 /// extern "C" void LLVMInitializeFooTarget() {
958 /// extern Target TheFooTarget;
959 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
961 template<class MCInstrInfoImpl>
962 struct RegisterMCInstrInfo {
963 RegisterMCInstrInfo(Target &T) {
964 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
967 static MCInstrInfo *Allocator() {
968 return new MCInstrInfoImpl();
972 /// RegisterMCInstrInfoFn - Helper template for registering a target
973 /// instruction info implementation. This invokes the specified function to
974 /// do the construction. Usage:
976 /// extern "C" void LLVMInitializeFooTarget() {
977 /// extern Target TheFooTarget;
978 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
980 struct RegisterMCInstrInfoFn {
981 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
982 TargetRegistry::RegisterMCInstrInfo(T, Fn);
986 /// RegisterMCInstrAnalysis - Helper template for registering a target
987 /// instruction analyzer implementation. This invokes the static "Create"
988 /// method on the class to actually do the construction. Usage:
990 /// extern "C" void LLVMInitializeFooTarget() {
991 /// extern Target TheFooTarget;
992 /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
994 template<class MCInstrAnalysisImpl>
995 struct RegisterMCInstrAnalysis {
996 RegisterMCInstrAnalysis(Target &T) {
997 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
1000 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
1001 return new MCInstrAnalysisImpl(Info);
1005 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
1006 /// instruction analyzer implementation. This invokes the specified function
1007 /// to do the construction. Usage:
1009 /// extern "C" void LLVMInitializeFooTarget() {
1010 /// extern Target TheFooTarget;
1011 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
1013 struct RegisterMCInstrAnalysisFn {
1014 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
1015 TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
1019 /// RegisterMCRegInfo - Helper template for registering a target register info
1020 /// implementation. This invokes the static "Create" method on the class to
1021 /// actually do the construction. Usage:
1023 /// extern "C" void LLVMInitializeFooTarget() {
1024 /// extern Target TheFooTarget;
1025 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
1027 template<class MCRegisterInfoImpl>
1028 struct RegisterMCRegInfo {
1029 RegisterMCRegInfo(Target &T) {
1030 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
1033 static MCRegisterInfo *Allocator(StringRef /*TT*/) {
1034 return new MCRegisterInfoImpl();
1038 /// RegisterMCRegInfoFn - Helper template for registering a target register
1039 /// info implementation. This invokes the specified function to do the
1040 /// construction. Usage:
1042 /// extern "C" void LLVMInitializeFooTarget() {
1043 /// extern Target TheFooTarget;
1044 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
1046 struct RegisterMCRegInfoFn {
1047 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
1048 TargetRegistry::RegisterMCRegInfo(T, Fn);
1052 /// RegisterMCSubtargetInfo - Helper template for registering a target
1053 /// subtarget info implementation. This invokes the static "Create" method
1054 /// on the class to actually do the construction. Usage:
1056 /// extern "C" void LLVMInitializeFooTarget() {
1057 /// extern Target TheFooTarget;
1058 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
1060 template<class MCSubtargetInfoImpl>
1061 struct RegisterMCSubtargetInfo {
1062 RegisterMCSubtargetInfo(Target &T) {
1063 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
1066 static MCSubtargetInfo *Allocator(StringRef /*TT*/, StringRef /*CPU*/,
1068 return new MCSubtargetInfoImpl();
1072 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
1073 /// subtarget info implementation. This invokes the specified function to
1074 /// do the construction. Usage:
1076 /// extern "C" void LLVMInitializeFooTarget() {
1077 /// extern Target TheFooTarget;
1078 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1080 struct RegisterMCSubtargetInfoFn {
1081 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
1082 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
1086 /// RegisterTargetMachine - Helper template for registering a target machine
1087 /// implementation, for use in the target machine initialization
1088 /// function. Usage:
1090 /// extern "C" void LLVMInitializeFooTarget() {
1091 /// extern Target TheFooTarget;
1092 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1094 template<class TargetMachineImpl>
1095 struct RegisterTargetMachine {
1096 RegisterTargetMachine(Target &T) {
1097 TargetRegistry::RegisterTargetMachine(T, &Allocator);
1101 static TargetMachine *Allocator(const Target &T, StringRef TT,
1102 StringRef CPU, StringRef FS,
1103 const TargetOptions &Options,
1105 CodeModel::Model CM,
1106 CodeGenOpt::Level OL) {
1107 return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
1111 /// RegisterMCAsmBackend - Helper template for registering a target specific
1112 /// assembler backend. Usage:
1114 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1115 /// extern Target TheFooTarget;
1116 /// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1118 template<class MCAsmBackendImpl>
1119 struct RegisterMCAsmBackend {
1120 RegisterMCAsmBackend(Target &T) {
1121 TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1125 static MCAsmBackend *Allocator(const Target &T,
1126 const MCRegisterInfo &MRI,
1127 StringRef Triple, StringRef CPU) {
1128 return new MCAsmBackendImpl(T, MRI, Triple, CPU);
1132 /// RegisterMCAsmParser - Helper template for registering a target specific
1133 /// assembly parser, for use in the target machine initialization
1134 /// function. Usage:
1136 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1137 /// extern Target TheFooTarget;
1138 /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1140 template<class MCAsmParserImpl>
1141 struct RegisterMCAsmParser {
1142 RegisterMCAsmParser(Target &T) {
1143 TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1147 static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P,
1148 const MCInstrInfo &MII) {
1149 return new MCAsmParserImpl(STI, P, MII);
1153 /// RegisterAsmPrinter - Helper template for registering a target specific
1154 /// assembly printer, for use in the target machine initialization
1155 /// function. Usage:
1157 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1158 /// extern Target TheFooTarget;
1159 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1161 template<class AsmPrinterImpl>
1162 struct RegisterAsmPrinter {
1163 RegisterAsmPrinter(Target &T) {
1164 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1168 static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) {
1169 return new AsmPrinterImpl(TM, Streamer);
1173 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1174 /// machine code emitter, for use in the target initialization
1175 /// function. Usage:
1177 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1178 /// extern Target TheFooTarget;
1179 /// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1181 template<class MCCodeEmitterImpl>
1182 struct RegisterMCCodeEmitter {
1183 RegisterMCCodeEmitter(Target &T) {
1184 TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1188 static MCCodeEmitter *Allocator(const MCInstrInfo &/*II*/,
1189 const MCRegisterInfo &/*MRI*/,
1190 const MCSubtargetInfo &/*STI*/,
1191 MCContext &/*Ctx*/) {
1192 return new MCCodeEmitterImpl();