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"
38 class MCInstrAnalysis;
43 class MCSubtargetInfo;
44 class MCTargetAsmParser;
48 class formatted_raw_ostream;
50 MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
52 bool useLoc, bool useCFI,
53 bool useDwarfDirectory,
54 MCInstPrinter *InstPrint,
59 /// Target - Wrapper for Target specific information.
61 /// For registration purposes, this is a POD type so that targets can be
62 /// registered without the use of static constructors.
64 /// Targets should implement a single global instance of this class (which
65 /// will be zero initialized), and pass that instance to the TargetRegistry as
66 /// part of their initialization.
69 friend struct TargetRegistry;
71 typedef unsigned (*TripleMatchQualityFnTy)(const std::string &TT);
73 typedef MCAsmInfo *(*MCAsmInfoCtorFnTy)(const MCRegisterInfo &MRI,
75 typedef MCCodeGenInfo *(*MCCodeGenInfoCtorFnTy)(StringRef TT,
78 CodeGenOpt::Level OL);
79 typedef MCInstrInfo *(*MCInstrInfoCtorFnTy)(void);
80 typedef MCInstrAnalysis *(*MCInstrAnalysisCtorFnTy)(const MCInstrInfo*Info);
81 typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(StringRef TT);
82 typedef MCSubtargetInfo *(*MCSubtargetInfoCtorFnTy)(StringRef TT,
85 typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T,
89 const TargetOptions &Options,
92 CodeGenOpt::Level OL);
93 typedef AsmPrinter *(*AsmPrinterCtorTy)(TargetMachine &TM,
94 MCStreamer &Streamer);
95 typedef MCAsmBackend *(*MCAsmBackendCtorTy)(const Target &T,
98 typedef MCTargetAsmParser *(*MCAsmParserCtorTy)(MCSubtargetInfo &STI,
100 typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T,
101 const MCSubtargetInfo &STI);
102 typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
103 unsigned SyntaxVariant,
104 const MCAsmInfo &MAI,
105 const MCInstrInfo &MII,
106 const MCRegisterInfo &MRI,
107 const MCSubtargetInfo &STI);
108 typedef MCCodeEmitter *(*MCCodeEmitterCtorTy)(const MCInstrInfo &II,
109 const MCRegisterInfo &MRI,
110 const MCSubtargetInfo &STI,
112 typedef MCStreamer *(*MCObjectStreamerCtorTy)(const Target &T,
117 MCCodeEmitter *_Emitter,
120 typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx,
121 formatted_raw_ostream &OS,
125 bool useDwarfDirectory,
126 MCInstPrinter *InstPrint,
132 /// Next - The next registered target in the linked list, maintained by the
136 /// TripleMatchQualityFn - The target function for rating the match quality
138 TripleMatchQualityFnTy TripleMatchQualityFn;
140 /// Name - The target name.
143 /// ShortDesc - A short description of the target.
144 const char *ShortDesc;
146 /// HasJIT - Whether this target supports the JIT.
149 /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
151 MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
153 /// MCCodeGenInfoCtorFn - Constructor function for this target's
154 /// MCCodeGenInfo, if registered.
155 MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn;
157 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
159 MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
161 /// MCInstrAnalysisCtorFn - Constructor function for this target's
162 /// MCInstrAnalysis, if registered.
163 MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
165 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
167 MCRegInfoCtorFnTy MCRegInfoCtorFn;
169 /// MCSubtargetInfoCtorFn - Constructor function for this target's
170 /// MCSubtargetInfo, if registered.
171 MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
173 /// TargetMachineCtorFn - Construction function for this target's
174 /// TargetMachine, if registered.
175 TargetMachineCtorTy TargetMachineCtorFn;
177 /// MCAsmBackendCtorFn - Construction function for this target's
178 /// MCAsmBackend, if registered.
179 MCAsmBackendCtorTy MCAsmBackendCtorFn;
181 /// MCAsmParserCtorFn - Construction function for this target's
182 /// MCTargetAsmParser, if registered.
183 MCAsmParserCtorTy MCAsmParserCtorFn;
185 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
187 AsmPrinterCtorTy AsmPrinterCtorFn;
189 /// MCDisassemblerCtorFn - Construction function for this target's
190 /// MCDisassembler, if registered.
191 MCDisassemblerCtorTy MCDisassemblerCtorFn;
193 /// MCInstPrinterCtorFn - Construction function for this target's
194 /// MCInstPrinter, if registered.
195 MCInstPrinterCtorTy MCInstPrinterCtorFn;
197 /// MCCodeEmitterCtorFn - Construction function for this target's
198 /// CodeEmitter, if registered.
199 MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
201 /// MCObjectStreamerCtorFn - Construction function for this target's
202 /// MCObjectStreamer, if registered.
203 MCObjectStreamerCtorTy MCObjectStreamerCtorFn;
205 /// AsmStreamerCtorFn - Construction function for this target's
206 /// AsmStreamer, if registered (default = llvm::createAsmStreamer).
207 AsmStreamerCtorTy AsmStreamerCtorFn;
210 Target() : AsmStreamerCtorFn(llvm::createAsmStreamer) {}
212 /// @name Target Information
215 // getNext - Return the next registered target.
216 const Target *getNext() const { return Next; }
218 /// getName - Get the target name.
219 const char *getName() const { return Name; }
221 /// getShortDescription - Get a short description of the target.
222 const char *getShortDescription() const { return ShortDesc; }
225 /// @name Feature Predicates
228 /// hasJIT - Check if this targets supports the just-in-time compilation.
229 bool hasJIT() const { return HasJIT; }
231 /// hasTargetMachine - Check if this target supports code generation.
232 bool hasTargetMachine() const { return TargetMachineCtorFn != 0; }
234 /// hasMCAsmBackend - Check if this target supports .o generation.
235 bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != 0; }
237 /// hasAsmParser - Check if this target supports .s parsing.
238 bool hasMCAsmParser() const { return MCAsmParserCtorFn != 0; }
240 /// hasAsmPrinter - Check if this target supports .s printing.
241 bool hasAsmPrinter() const { return AsmPrinterCtorFn != 0; }
243 /// hasMCDisassembler - Check if this target has a disassembler.
244 bool hasMCDisassembler() const { return MCDisassemblerCtorFn != 0; }
246 /// hasMCInstPrinter - Check if this target has an instruction printer.
247 bool hasMCInstPrinter() const { return MCInstPrinterCtorFn != 0; }
249 /// hasMCCodeEmitter - Check if this target supports instruction encoding.
250 bool hasMCCodeEmitter() const { return MCCodeEmitterCtorFn != 0; }
252 /// hasMCObjectStreamer - Check if this target supports streaming to files.
253 bool hasMCObjectStreamer() const { return MCObjectStreamerCtorFn != 0; }
255 /// hasAsmStreamer - Check if this target supports streaming to files.
256 bool hasAsmStreamer() const { return AsmStreamerCtorFn != 0; }
259 /// @name Feature Constructors
262 /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
265 /// \param Triple This argument is used to determine the target machine
266 /// feature set; it should always be provided. Generally this should be
267 /// either the target triple from the module, or the target triple of the
268 /// host if that does not exist.
269 MCAsmInfo *createMCAsmInfo(const MCRegisterInfo &MRI,
270 StringRef Triple) const {
271 if (!MCAsmInfoCtorFn)
273 return MCAsmInfoCtorFn(MRI, Triple);
276 /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
278 MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model RM,
280 CodeGenOpt::Level OL) const {
281 if (!MCCodeGenInfoCtorFn)
283 return MCCodeGenInfoCtorFn(Triple, RM, CM, OL);
286 /// createMCInstrInfo - Create a MCInstrInfo implementation.
288 MCInstrInfo *createMCInstrInfo() const {
289 if (!MCInstrInfoCtorFn)
291 return MCInstrInfoCtorFn();
294 /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
296 MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
297 if (!MCInstrAnalysisCtorFn)
299 return MCInstrAnalysisCtorFn(Info);
302 /// createMCRegInfo - Create a MCRegisterInfo implementation.
304 MCRegisterInfo *createMCRegInfo(StringRef Triple) const {
305 if (!MCRegInfoCtorFn)
307 return MCRegInfoCtorFn(Triple);
310 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
312 /// \param Triple This argument is used to determine the target machine
313 /// feature set; it should always be provided. Generally this should be
314 /// either the target triple from the module, or the target triple of the
315 /// host if that does not exist.
316 /// \param CPU This specifies the name of the target CPU.
317 /// \param Features This specifies the string representation of the
318 /// additional target features.
319 MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU,
320 StringRef Features) const {
321 if (!MCSubtargetInfoCtorFn)
323 return MCSubtargetInfoCtorFn(Triple, CPU, Features);
326 /// createTargetMachine - Create a target specific machine implementation
327 /// for the specified \p Triple.
329 /// \param Triple This argument is used to determine the target machine
330 /// feature set; it should always be provided. Generally this should be
331 /// either the target triple from the module, or the target triple of the
332 /// host if that does not exist.
333 TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU,
334 StringRef Features, const TargetOptions &Options,
335 Reloc::Model RM = Reloc::Default,
336 CodeModel::Model CM = CodeModel::Default,
337 CodeGenOpt::Level OL = CodeGenOpt::Default) const {
338 if (!TargetMachineCtorFn)
340 return TargetMachineCtorFn(*this, Triple, CPU, Features, Options,
344 /// createMCAsmBackend - Create a target specific assembly parser.
346 /// \param Triple The target triple string.
347 MCAsmBackend *createMCAsmBackend(StringRef Triple, StringRef CPU) const {
348 if (!MCAsmBackendCtorFn)
350 return MCAsmBackendCtorFn(*this, Triple, CPU);
353 /// createMCAsmParser - Create a target specific assembly parser.
355 /// \param Parser The target independent parser implementation to use for
356 /// parsing and lexing.
357 MCTargetAsmParser *createMCAsmParser(MCSubtargetInfo &STI,
358 MCAsmParser &Parser) const {
359 if (!MCAsmParserCtorFn)
361 return MCAsmParserCtorFn(STI, Parser);
364 /// createAsmPrinter - Create a target specific assembly printer pass. This
365 /// takes ownership of the MCStreamer object.
366 AsmPrinter *createAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) const{
367 if (!AsmPrinterCtorFn)
369 return AsmPrinterCtorFn(TM, Streamer);
372 MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI) const {
373 if (!MCDisassemblerCtorFn)
375 return MCDisassemblerCtorFn(*this, STI);
378 MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
379 const MCAsmInfo &MAI,
380 const MCInstrInfo &MII,
381 const MCRegisterInfo &MRI,
382 const MCSubtargetInfo &STI) const {
383 if (!MCInstPrinterCtorFn)
385 return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, MII, MRI, STI);
389 /// createMCCodeEmitter - Create a target specific code emitter.
390 MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
391 const MCRegisterInfo &MRI,
392 const MCSubtargetInfo &STI,
393 MCContext &Ctx) const {
394 if (!MCCodeEmitterCtorFn)
396 return MCCodeEmitterCtorFn(II, MRI, STI, Ctx);
399 /// createMCObjectStreamer - Create a target specific MCStreamer.
401 /// \param TT The target triple.
402 /// \param Ctx The target context.
403 /// \param TAB The target assembler backend object. Takes ownership.
404 /// \param _OS The stream object.
405 /// \param _Emitter The target independent assembler object.Takes ownership.
406 /// \param RelaxAll Relax all fixups?
407 /// \param NoExecStack Mark file as not needing a executable stack.
408 MCStreamer *createMCObjectStreamer(StringRef TT, MCContext &Ctx,
411 MCCodeEmitter *_Emitter,
413 bool NoExecStack) const {
414 if (!MCObjectStreamerCtorFn)
416 return MCObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter,
417 RelaxAll, NoExecStack);
420 /// createAsmStreamer - Create a target specific MCStreamer.
421 MCStreamer *createAsmStreamer(MCContext &Ctx,
422 formatted_raw_ostream &OS,
426 bool useDwarfDirectory,
427 MCInstPrinter *InstPrint,
430 bool ShowInst) const {
431 // AsmStreamerCtorFn is default to llvm::createAsmStreamer
432 return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useLoc, useCFI,
433 useDwarfDirectory, InstPrint, CE, TAB, ShowInst);
439 /// TargetRegistry - Generic interface to target specific features.
440 struct TargetRegistry {
442 const Target *Current;
443 explicit iterator(Target *T) : Current(T) {}
444 friend struct TargetRegistry;
446 iterator(const iterator &I) : Current(I.Current) {}
447 iterator() : Current(0) {}
449 bool operator==(const iterator &x) const {
450 return Current == x.Current;
452 bool operator!=(const iterator &x) const {
453 return !operator==(x);
456 // Iterator traversal: forward iteration only
457 iterator &operator++() { // Preincrement
458 assert(Current && "Cannot increment end iterator!");
459 Current = Current->getNext();
462 iterator operator++(int) { // Postincrement
463 iterator tmp = *this;
468 const Target &operator*() const {
469 assert(Current && "Cannot dereference end iterator!");
473 const Target *operator->() const {
478 /// printRegisteredTargetsForVersion - Print the registered targets
479 /// appropriately for inclusion in a tool's version output.
480 static void printRegisteredTargetsForVersion();
482 /// @name Registry Access
485 static iterator begin();
487 static iterator end() { return iterator(); }
489 /// lookupTarget - Lookup a target based on a target triple.
491 /// \param Triple - The triple to use for finding a target.
492 /// \param Error - On failure, an error string describing why no target was
494 static const Target *lookupTarget(const std::string &Triple,
497 /// lookupTarget - Lookup a target based on an architecture name
498 /// and a target triple. If the architecture name is non-empty,
499 /// then the lookup is done by architecture. Otherwise, the target
502 /// \param ArchName - The architecture to use for finding a target.
503 /// \param TheTriple - The triple to use for finding a target. The
504 /// triple is updated with canonical architecture name if a lookup
505 /// by architecture is done.
506 /// \param Error - On failure, an error string describing why no target was
508 static const Target *lookupTarget(const std::string &ArchName,
512 /// getClosestTargetForJIT - Pick the best target that is compatible with
513 /// the current host. If no close target can be found, this returns null
514 /// and sets the Error string to a reason.
516 /// Maintained for compatibility through 2.6.
517 static const Target *getClosestTargetForJIT(std::string &Error);
520 /// @name Target Registration
523 /// RegisterTarget - Register the given target. Attempts to register a
524 /// target which has already been registered will be ignored.
526 /// Clients are responsible for ensuring that registration doesn't occur
527 /// while another thread is attempting to access the registry. Typically
528 /// this is done by initializing all targets at program startup.
530 /// @param T - The target being registered.
531 /// @param Name - The target name. This should be a static string.
532 /// @param ShortDesc - A short target description. This should be a static
534 /// @param TQualityFn - The triple match quality computation function for
536 /// @param HasJIT - Whether the target supports JIT code
538 static void RegisterTarget(Target &T,
540 const char *ShortDesc,
541 Target::TripleMatchQualityFnTy TQualityFn,
542 bool HasJIT = false);
544 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
547 /// Clients are responsible for ensuring that registration doesn't occur
548 /// while another thread is attempting to access the registry. Typically
549 /// this is done by initializing all targets at program startup.
551 /// @param T - The target being registered.
552 /// @param Fn - A function to construct a MCAsmInfo for the target.
553 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
554 // Ignore duplicate registration.
555 if (!T.MCAsmInfoCtorFn)
556 T.MCAsmInfoCtorFn = Fn;
559 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
562 /// Clients are responsible for ensuring that registration doesn't occur
563 /// while another thread is attempting to access the registry. Typically
564 /// this is done by initializing all targets at program startup.
566 /// @param T - The target being registered.
567 /// @param Fn - A function to construct a MCCodeGenInfo for the target.
568 static void RegisterMCCodeGenInfo(Target &T,
569 Target::MCCodeGenInfoCtorFnTy Fn) {
570 // Ignore duplicate registration.
571 if (!T.MCCodeGenInfoCtorFn)
572 T.MCCodeGenInfoCtorFn = Fn;
575 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
578 /// Clients are responsible for ensuring that registration doesn't occur
579 /// while another thread is attempting to access the registry. Typically
580 /// this is done by initializing all targets at program startup.
582 /// @param T - The target being registered.
583 /// @param Fn - A function to construct a MCInstrInfo for the target.
584 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
585 // Ignore duplicate registration.
586 if (!T.MCInstrInfoCtorFn)
587 T.MCInstrInfoCtorFn = Fn;
590 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
591 /// the given target.
592 static void RegisterMCInstrAnalysis(Target &T,
593 Target::MCInstrAnalysisCtorFnTy Fn) {
594 // Ignore duplicate registration.
595 if (!T.MCInstrAnalysisCtorFn)
596 T.MCInstrAnalysisCtorFn = Fn;
599 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
602 /// Clients are responsible for ensuring that registration doesn't occur
603 /// while another thread is attempting to access the registry. Typically
604 /// this is done by initializing all targets at program startup.
606 /// @param T - The target being registered.
607 /// @param Fn - A function to construct a MCRegisterInfo for the target.
608 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
609 // Ignore duplicate registration.
610 if (!T.MCRegInfoCtorFn)
611 T.MCRegInfoCtorFn = Fn;
614 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
615 /// the given target.
617 /// Clients are responsible for ensuring that registration doesn't occur
618 /// while another thread is attempting to access the registry. Typically
619 /// this is done by initializing all targets at program startup.
621 /// @param T - The target being registered.
622 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
623 static void RegisterMCSubtargetInfo(Target &T,
624 Target::MCSubtargetInfoCtorFnTy Fn) {
625 // Ignore duplicate registration.
626 if (!T.MCSubtargetInfoCtorFn)
627 T.MCSubtargetInfoCtorFn = Fn;
630 /// RegisterTargetMachine - Register a TargetMachine implementation for the
633 /// Clients are responsible for ensuring that registration doesn't occur
634 /// while another thread is attempting to access the registry. Typically
635 /// this is done by initializing all targets at program startup.
637 /// @param T - The target being registered.
638 /// @param Fn - A function to construct a TargetMachine for the target.
639 static void RegisterTargetMachine(Target &T,
640 Target::TargetMachineCtorTy Fn) {
641 // Ignore duplicate registration.
642 if (!T.TargetMachineCtorFn)
643 T.TargetMachineCtorFn = Fn;
646 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
649 /// Clients are responsible for ensuring that registration doesn't occur
650 /// while another thread is attempting to access the registry. Typically
651 /// this is done by initializing all targets at program startup.
653 /// @param T - The target being registered.
654 /// @param Fn - A function to construct an AsmBackend for the target.
655 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
656 if (!T.MCAsmBackendCtorFn)
657 T.MCAsmBackendCtorFn = Fn;
660 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
661 /// the given target.
663 /// Clients are responsible for ensuring that registration doesn't occur
664 /// while another thread is attempting to access the registry. Typically
665 /// this is done by initializing all targets at program startup.
667 /// @param T - The target being registered.
668 /// @param Fn - A function to construct an MCTargetAsmParser for the target.
669 static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
670 if (!T.MCAsmParserCtorFn)
671 T.MCAsmParserCtorFn = Fn;
674 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
677 /// Clients are responsible for ensuring that registration doesn't occur
678 /// while another thread is attempting to access the registry. Typically
679 /// this is done by initializing all targets at program startup.
681 /// @param T - The target being registered.
682 /// @param Fn - A function to construct an AsmPrinter for the target.
683 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
684 // Ignore duplicate registration.
685 if (!T.AsmPrinterCtorFn)
686 T.AsmPrinterCtorFn = Fn;
689 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
690 /// the given target.
692 /// Clients are responsible for ensuring that registration doesn't occur
693 /// while another thread is attempting to access the registry. Typically
694 /// this is done by initializing all targets at program startup.
696 /// @param T - The target being registered.
697 /// @param Fn - A function to construct an MCDisassembler for the target.
698 static void RegisterMCDisassembler(Target &T,
699 Target::MCDisassemblerCtorTy Fn) {
700 if (!T.MCDisassemblerCtorFn)
701 T.MCDisassemblerCtorFn = Fn;
704 /// RegisterMCInstPrinter - Register a MCInstPrinter 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 MCInstPrinter for the target.
713 static void RegisterMCInstPrinter(Target &T,
714 Target::MCInstPrinterCtorTy Fn) {
715 if (!T.MCInstPrinterCtorFn)
716 T.MCInstPrinterCtorFn = Fn;
719 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
722 /// Clients are responsible for ensuring that registration doesn't occur
723 /// while another thread is attempting to access the registry. Typically
724 /// this is done by initializing all targets at program startup.
726 /// @param T - The target being registered.
727 /// @param Fn - A function to construct an MCCodeEmitter for the target.
728 static void RegisterMCCodeEmitter(Target &T,
729 Target::MCCodeEmitterCtorTy Fn) {
730 if (!T.MCCodeEmitterCtorFn)
731 T.MCCodeEmitterCtorFn = Fn;
734 /// RegisterMCObjectStreamer - Register a object code MCStreamer
735 /// implementation for the given target.
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 MCStreamer for the target.
743 static void RegisterMCObjectStreamer(Target &T,
744 Target::MCObjectStreamerCtorTy Fn) {
745 if (!T.MCObjectStreamerCtorFn)
746 T.MCObjectStreamerCtorFn = Fn;
749 /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
750 /// for 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 MCStreamer for the target.
758 static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
759 if (T.AsmStreamerCtorFn == createAsmStreamer)
760 T.AsmStreamerCtorFn = Fn;
767 //===--------------------------------------------------------------------===//
769 /// RegisterTarget - Helper template for registering a target, for use in the
770 /// target's initialization function. Usage:
773 /// Target TheFooTarget; // The global target instance.
775 /// extern "C" void LLVMInitializeFooTargetInfo() {
776 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
778 template<Triple::ArchType TargetArchType = Triple::UnknownArch,
780 struct RegisterTarget {
781 RegisterTarget(Target &T, const char *Name, const char *Desc) {
782 TargetRegistry::RegisterTarget(T, Name, Desc,
783 &getTripleMatchQuality,
787 static unsigned getTripleMatchQuality(const std::string &TT) {
788 if (Triple(TT).getArch() == TargetArchType)
794 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
795 /// implementation. This invokes the static "Create" method on the class to
796 /// actually do the construction. Usage:
798 /// extern "C" void LLVMInitializeFooTarget() {
799 /// extern Target TheFooTarget;
800 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
802 template<class MCAsmInfoImpl>
803 struct RegisterMCAsmInfo {
804 RegisterMCAsmInfo(Target &T) {
805 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
808 static MCAsmInfo *Allocator(const MCRegisterInfo &MRI, StringRef TT) {
809 return new MCAsmInfoImpl(TT);
814 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
815 /// implementation. This invokes the specified function to do the
816 /// construction. Usage:
818 /// extern "C" void LLVMInitializeFooTarget() {
819 /// extern Target TheFooTarget;
820 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
822 struct RegisterMCAsmInfoFn {
823 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
824 TargetRegistry::RegisterMCAsmInfo(T, Fn);
828 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
829 /// implementation. This invokes the static "Create" method on the class
830 /// to actually do the construction. Usage:
832 /// extern "C" void LLVMInitializeFooTarget() {
833 /// extern Target TheFooTarget;
834 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
836 template<class MCCodeGenInfoImpl>
837 struct RegisterMCCodeGenInfo {
838 RegisterMCCodeGenInfo(Target &T) {
839 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
842 static MCCodeGenInfo *Allocator(StringRef TT, Reloc::Model RM,
843 CodeModel::Model CM, CodeGenOpt::Level OL) {
844 return new MCCodeGenInfoImpl();
848 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
849 /// info implementation. This invokes the specified function to do the
850 /// construction. Usage:
852 /// extern "C" void LLVMInitializeFooTarget() {
853 /// extern Target TheFooTarget;
854 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
856 struct RegisterMCCodeGenInfoFn {
857 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
858 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
862 /// RegisterMCInstrInfo - Helper template for registering a target instruction
863 /// info implementation. This invokes the static "Create" method on the class
864 /// to actually do the construction. Usage:
866 /// extern "C" void LLVMInitializeFooTarget() {
867 /// extern Target TheFooTarget;
868 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
870 template<class MCInstrInfoImpl>
871 struct RegisterMCInstrInfo {
872 RegisterMCInstrInfo(Target &T) {
873 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
876 static MCInstrInfo *Allocator() {
877 return new MCInstrInfoImpl();
881 /// RegisterMCInstrInfoFn - Helper template for registering a target
882 /// instruction info implementation. This invokes the specified function to
883 /// do the construction. Usage:
885 /// extern "C" void LLVMInitializeFooTarget() {
886 /// extern Target TheFooTarget;
887 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
889 struct RegisterMCInstrInfoFn {
890 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
891 TargetRegistry::RegisterMCInstrInfo(T, Fn);
895 /// RegisterMCInstrAnalysis - Helper template for registering a target
896 /// instruction analyzer implementation. This invokes the static "Create"
897 /// method on the class to actually do the construction. Usage:
899 /// extern "C" void LLVMInitializeFooTarget() {
900 /// extern Target TheFooTarget;
901 /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
903 template<class MCInstrAnalysisImpl>
904 struct RegisterMCInstrAnalysis {
905 RegisterMCInstrAnalysis(Target &T) {
906 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
909 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
910 return new MCInstrAnalysisImpl(Info);
914 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
915 /// instruction analyzer implementation. This invokes the specified function
916 /// to do the construction. Usage:
918 /// extern "C" void LLVMInitializeFooTarget() {
919 /// extern Target TheFooTarget;
920 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
922 struct RegisterMCInstrAnalysisFn {
923 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
924 TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
928 /// RegisterMCRegInfo - Helper template for registering a target register info
929 /// implementation. This invokes the static "Create" method on the class to
930 /// actually do the construction. Usage:
932 /// extern "C" void LLVMInitializeFooTarget() {
933 /// extern Target TheFooTarget;
934 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
936 template<class MCRegisterInfoImpl>
937 struct RegisterMCRegInfo {
938 RegisterMCRegInfo(Target &T) {
939 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
942 static MCRegisterInfo *Allocator(StringRef TT) {
943 return new MCRegisterInfoImpl();
947 /// RegisterMCRegInfoFn - Helper template for registering a target register
948 /// info implementation. This invokes the specified function to do the
949 /// construction. Usage:
951 /// extern "C" void LLVMInitializeFooTarget() {
952 /// extern Target TheFooTarget;
953 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
955 struct RegisterMCRegInfoFn {
956 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
957 TargetRegistry::RegisterMCRegInfo(T, Fn);
961 /// RegisterMCSubtargetInfo - Helper template for registering a target
962 /// subtarget info implementation. This invokes the static "Create" method
963 /// on the class to actually do the construction. Usage:
965 /// extern "C" void LLVMInitializeFooTarget() {
966 /// extern Target TheFooTarget;
967 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
969 template<class MCSubtargetInfoImpl>
970 struct RegisterMCSubtargetInfo {
971 RegisterMCSubtargetInfo(Target &T) {
972 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
975 static MCSubtargetInfo *Allocator(StringRef TT, StringRef CPU,
977 return new MCSubtargetInfoImpl();
981 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
982 /// subtarget info implementation. This invokes the specified function to
983 /// do the construction. Usage:
985 /// extern "C" void LLVMInitializeFooTarget() {
986 /// extern Target TheFooTarget;
987 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
989 struct RegisterMCSubtargetInfoFn {
990 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
991 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
995 /// RegisterTargetMachine - Helper template for registering a target machine
996 /// implementation, for use in the target machine initialization
999 /// extern "C" void LLVMInitializeFooTarget() {
1000 /// extern Target TheFooTarget;
1001 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1003 template<class TargetMachineImpl>
1004 struct RegisterTargetMachine {
1005 RegisterTargetMachine(Target &T) {
1006 TargetRegistry::RegisterTargetMachine(T, &Allocator);
1010 static TargetMachine *Allocator(const Target &T, StringRef TT,
1011 StringRef CPU, StringRef FS,
1012 const TargetOptions &Options,
1014 CodeModel::Model CM,
1015 CodeGenOpt::Level OL) {
1016 return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
1020 /// RegisterMCAsmBackend - Helper template for registering a target specific
1021 /// assembler backend. Usage:
1023 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1024 /// extern Target TheFooTarget;
1025 /// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1027 template<class MCAsmBackendImpl>
1028 struct RegisterMCAsmBackend {
1029 RegisterMCAsmBackend(Target &T) {
1030 TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1034 static MCAsmBackend *Allocator(const Target &T, StringRef Triple,
1036 return new MCAsmBackendImpl(T, Triple, CPU);
1040 /// RegisterMCAsmParser - Helper template for registering a target specific
1041 /// assembly parser, for use in the target machine initialization
1042 /// function. Usage:
1044 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1045 /// extern Target TheFooTarget;
1046 /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1048 template<class MCAsmParserImpl>
1049 struct RegisterMCAsmParser {
1050 RegisterMCAsmParser(Target &T) {
1051 TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1055 static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P) {
1056 return new MCAsmParserImpl(STI, P);
1060 /// RegisterAsmPrinter - Helper template for registering a target specific
1061 /// assembly printer, for use in the target machine initialization
1062 /// function. Usage:
1064 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1065 /// extern Target TheFooTarget;
1066 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1068 template<class AsmPrinterImpl>
1069 struct RegisterAsmPrinter {
1070 RegisterAsmPrinter(Target &T) {
1071 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1075 static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) {
1076 return new AsmPrinterImpl(TM, Streamer);
1080 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1081 /// machine code emitter, for use in the target initialization
1082 /// function. Usage:
1084 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1085 /// extern Target TheFooTarget;
1086 /// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1088 template<class MCCodeEmitterImpl>
1089 struct RegisterMCCodeEmitter {
1090 RegisterMCCodeEmitter(Target &T) {
1091 TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1095 static MCCodeEmitter *Allocator(const MCInstrInfo &II,
1096 const MCRegisterInfo &MRI,
1097 const MCSubtargetInfo &STI,
1099 return new MCCodeEmitterImpl();