1 //===-- Target/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_TARGET_TARGETREGISTRY_H
20 #define LLVM_TARGET_TARGETREGISTRY_H
22 #include "llvm/ADT/Triple.h"
38 class MCSubtargetInfo;
40 class TargetAsmBackend;
42 class TargetAsmParser;
45 class formatted_raw_ostream;
47 MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
49 bool useLoc, bool useCFI,
50 MCInstPrinter *InstPrint,
52 TargetAsmBackend *TAB,
55 /// Target - Wrapper for Target specific information.
57 /// For registration purposes, this is a POD type so that targets can be
58 /// registered without the use of static constructors.
60 /// Targets should implement a single global instance of this class (which
61 /// will be zero initialized), and pass that instance to the TargetRegistry as
62 /// part of their initialization.
65 friend struct TargetRegistry;
67 typedef unsigned (*TripleMatchQualityFnTy)(const std::string &TT);
69 typedef MCAsmInfo *(*AsmInfoCtorFnTy)(const Target &T,
71 typedef MCInstrInfo *(*MCInstrInfoCtorFnTy)(void);
72 typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(void);
73 typedef MCSubtargetInfo *(*MCSubtargetInfoCtorFnTy)(StringRef TT,
76 typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T,
77 const std::string &TT,
78 const std::string &CPU,
79 const std::string &Features);
80 typedef AsmPrinter *(*AsmPrinterCtorTy)(TargetMachine &TM,
81 MCStreamer &Streamer);
82 typedef TargetAsmBackend *(*AsmBackendCtorTy)(const Target &T,
83 const std::string &TT);
84 typedef TargetAsmLexer *(*AsmLexerCtorTy)(const Target &T,
85 const MCAsmInfo &MAI);
86 typedef TargetAsmParser *(*AsmParserCtorTy)(const Target &T,MCAsmParser &P,
88 typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T);
89 typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
90 unsigned SyntaxVariant,
91 const MCAsmInfo &MAI);
92 typedef MCCodeEmitter *(*CodeEmitterCtorTy)(const Target &T,
95 typedef MCStreamer *(*ObjectStreamerCtorTy)(const Target &T,
96 const std::string &TT,
98 TargetAsmBackend &TAB,
100 MCCodeEmitter *_Emitter,
103 typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx,
104 formatted_raw_ostream &OS,
108 MCInstPrinter *InstPrint,
110 TargetAsmBackend *TAB,
114 /// Next - The next registered target in the linked list, maintained by the
118 /// TripleMatchQualityFn - The target function for rating the match quality
120 TripleMatchQualityFnTy TripleMatchQualityFn;
122 /// Name - The target name.
125 /// ShortDesc - A short description of the target.
126 const char *ShortDesc;
128 /// HasJIT - Whether this target supports the JIT.
131 /// AsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
133 AsmInfoCtorFnTy AsmInfoCtorFn;
135 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
137 MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
139 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
141 MCRegInfoCtorFnTy MCRegInfoCtorFn;
143 /// MCSubtargetInfoCtorFn - Constructor function for this target's
144 /// MCSubtargetInfo, if registered.
145 MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
147 /// TargetMachineCtorFn - Construction function for this target's
148 /// TargetMachine, if registered.
149 TargetMachineCtorTy TargetMachineCtorFn;
151 /// AsmBackendCtorFn - Construction function for this target's
152 /// TargetAsmBackend, if registered.
153 AsmBackendCtorTy AsmBackendCtorFn;
155 /// AsmLexerCtorFn - Construction function for this target's TargetAsmLexer,
157 AsmLexerCtorTy AsmLexerCtorFn;
159 /// AsmParserCtorFn - Construction function for this target's
160 /// TargetAsmParser, if registered.
161 AsmParserCtorTy AsmParserCtorFn;
163 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
165 AsmPrinterCtorTy AsmPrinterCtorFn;
167 /// MCDisassemblerCtorFn - Construction function for this target's
168 /// MCDisassembler, if registered.
169 MCDisassemblerCtorTy MCDisassemblerCtorFn;
171 /// MCInstPrinterCtorFn - Construction function for this target's
172 /// MCInstPrinter, if registered.
173 MCInstPrinterCtorTy MCInstPrinterCtorFn;
175 /// CodeEmitterCtorFn - Construction function for this target's CodeEmitter,
177 CodeEmitterCtorTy CodeEmitterCtorFn;
179 /// ObjectStreamerCtorFn - Construction function for this target's
180 /// ObjectStreamer, if registered.
181 ObjectStreamerCtorTy ObjectStreamerCtorFn;
183 /// AsmStreamerCtorFn - Construction function for this target's
184 /// AsmStreamer, if registered (default = llvm::createAsmStreamer).
185 AsmStreamerCtorTy AsmStreamerCtorFn;
188 Target() : AsmStreamerCtorFn(llvm::createAsmStreamer) {}
190 /// @name Target Information
193 // getNext - Return the next registered target.
194 const Target *getNext() const { return Next; }
196 /// getName - Get the target name.
197 const char *getName() const { return Name; }
199 /// getShortDescription - Get a short description of the target.
200 const char *getShortDescription() const { return ShortDesc; }
203 /// @name Feature Predicates
206 /// hasJIT - Check if this targets supports the just-in-time compilation.
207 bool hasJIT() const { return HasJIT; }
209 /// hasTargetMachine - Check if this target supports code generation.
210 bool hasTargetMachine() const { return TargetMachineCtorFn != 0; }
212 /// hasAsmBackend - Check if this target supports .o generation.
213 bool hasAsmBackend() const { return AsmBackendCtorFn != 0; }
215 /// hasAsmLexer - Check if this target supports .s lexing.
216 bool hasAsmLexer() const { return AsmLexerCtorFn != 0; }
218 /// hasAsmParser - Check if this target supports .s parsing.
219 bool hasAsmParser() const { return AsmParserCtorFn != 0; }
221 /// hasAsmPrinter - Check if this target supports .s printing.
222 bool hasAsmPrinter() const { return AsmPrinterCtorFn != 0; }
224 /// hasMCDisassembler - Check if this target has a disassembler.
225 bool hasMCDisassembler() const { return MCDisassemblerCtorFn != 0; }
227 /// hasMCInstPrinter - Check if this target has an instruction printer.
228 bool hasMCInstPrinter() const { return MCInstPrinterCtorFn != 0; }
230 /// hasCodeEmitter - Check if this target supports instruction encoding.
231 bool hasCodeEmitter() const { return CodeEmitterCtorFn != 0; }
233 /// hasObjectStreamer - Check if this target supports streaming to files.
234 bool hasObjectStreamer() const { return ObjectStreamerCtorFn != 0; }
236 /// hasAsmStreamer - Check if this target supports streaming to files.
237 bool hasAsmStreamer() const { return AsmStreamerCtorFn != 0; }
240 /// @name Feature Constructors
243 /// createAsmInfo - Create a MCAsmInfo implementation for the specified
246 /// \arg Triple - This argument is used to determine the target machine
247 /// feature set; it should always be provided. Generally this should be
248 /// either the target triple from the module, or the target triple of the
249 /// host if that does not exist.
250 MCAsmInfo *createAsmInfo(StringRef Triple) const {
253 return AsmInfoCtorFn(*this, Triple);
256 /// createMCInstrInfo - Create a MCInstrInfo implementation.
258 MCInstrInfo *createMCInstrInfo() const {
259 if (!MCInstrInfoCtorFn)
261 return MCInstrInfoCtorFn();
264 /// createMCRegInfo - Create a MCRegisterInfo implementation.
266 MCRegisterInfo *createMCRegInfo() const {
267 if (!MCRegInfoCtorFn)
269 return MCRegInfoCtorFn();
272 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
274 /// \arg Triple - This argument is used to determine the target machine
275 /// feature set; it should always be provided. Generally this should be
276 /// either the target triple from the module, or the target triple of the
277 /// host if that does not exist.
278 /// \arg CPU - This specifies the name of the target CPU.
279 /// \arg Features - This specifies the string representation of the
280 /// additional target features.
281 MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU,
282 StringRef Features) const {
283 if (!MCSubtargetInfoCtorFn)
285 return MCSubtargetInfoCtorFn(Triple, CPU, Features);
288 /// createTargetMachine - Create a target specific machine implementation
289 /// for the specified \arg Triple.
291 /// \arg Triple - This argument is used to determine the target machine
292 /// feature set; it should always be provided. Generally this should be
293 /// either the target triple from the module, or the target triple of the
294 /// host if that does not exist.
295 TargetMachine *createTargetMachine(const std::string &Triple,
296 const std::string &CPU,
297 const std::string &Features) const {
298 if (!TargetMachineCtorFn)
300 return TargetMachineCtorFn(*this, Triple, CPU, Features);
303 /// createAsmBackend - Create a target specific assembly parser.
305 /// \arg Triple - The target triple string.
306 /// \arg Backend - The target independent assembler object.
307 TargetAsmBackend *createAsmBackend(const std::string &Triple) const {
308 if (!AsmBackendCtorFn)
310 return AsmBackendCtorFn(*this, Triple);
313 /// createAsmLexer - Create a target specific assembly lexer.
315 TargetAsmLexer *createAsmLexer(const MCAsmInfo &MAI) const {
318 return AsmLexerCtorFn(*this, MAI);
321 /// createAsmParser - Create a target specific assembly parser.
323 /// \arg Parser - The target independent parser implementation to use for
324 /// parsing and lexing.
325 TargetAsmParser *createAsmParser(MCAsmParser &Parser,
326 TargetMachine &TM) const {
327 if (!AsmParserCtorFn)
329 return AsmParserCtorFn(*this, Parser, TM);
332 /// createAsmPrinter - Create a target specific assembly printer pass. This
333 /// takes ownership of the MCStreamer object.
334 AsmPrinter *createAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) const{
335 if (!AsmPrinterCtorFn)
337 return AsmPrinterCtorFn(TM, Streamer);
340 MCDisassembler *createMCDisassembler() const {
341 if (!MCDisassemblerCtorFn)
343 return MCDisassemblerCtorFn(*this);
346 MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
347 const MCAsmInfo &MAI) const {
348 if (!MCInstPrinterCtorFn)
350 return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI);
354 /// createCodeEmitter - Create a target specific code emitter.
355 MCCodeEmitter *createCodeEmitter(TargetMachine &TM, MCContext &Ctx) const {
356 if (!CodeEmitterCtorFn)
358 return CodeEmitterCtorFn(*this, TM, Ctx);
361 /// createObjectStreamer - Create a target specific MCStreamer.
363 /// \arg TT - The target triple.
364 /// \arg Ctx - The target context.
365 /// \arg TAB - The target assembler backend object. Takes ownership.
366 /// \arg _OS - The stream object.
367 /// \arg _Emitter - The target independent assembler object.Takes ownership.
368 /// \arg RelaxAll - Relax all fixups?
369 /// \arg NoExecStack - Mark file as not needing a executable stack.
370 MCStreamer *createObjectStreamer(const std::string &TT, MCContext &Ctx,
371 TargetAsmBackend &TAB,
373 MCCodeEmitter *_Emitter,
375 bool NoExecStack) const {
376 if (!ObjectStreamerCtorFn)
378 return ObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter, RelaxAll,
382 /// createAsmStreamer - Create a target specific MCStreamer.
383 MCStreamer *createAsmStreamer(MCContext &Ctx,
384 formatted_raw_ostream &OS,
388 MCInstPrinter *InstPrint,
390 TargetAsmBackend *TAB,
391 bool ShowInst) const {
392 // AsmStreamerCtorFn is default to llvm::createAsmStreamer
393 return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useLoc, useCFI,
394 InstPrint, CE, TAB, ShowInst);
400 /// TargetRegistry - Generic interface to target specific features.
401 struct TargetRegistry {
403 const Target *Current;
404 explicit iterator(Target *T) : Current(T) {}
405 friend struct TargetRegistry;
407 iterator(const iterator &I) : Current(I.Current) {}
408 iterator() : Current(0) {}
410 bool operator==(const iterator &x) const {
411 return Current == x.Current;
413 bool operator!=(const iterator &x) const {
414 return !operator==(x);
417 // Iterator traversal: forward iteration only
418 iterator &operator++() { // Preincrement
419 assert(Current && "Cannot increment end iterator!");
420 Current = Current->getNext();
423 iterator operator++(int) { // Postincrement
424 iterator tmp = *this;
429 const Target &operator*() const {
430 assert(Current && "Cannot dereference end iterator!");
434 const Target *operator->() const {
439 /// @name Registry Access
442 static iterator begin();
444 static iterator end() { return iterator(); }
446 /// lookupTarget - Lookup a target based on a target triple.
448 /// \param Triple - The triple to use for finding a target.
449 /// \param Error - On failure, an error string describing why no target was
451 static const Target *lookupTarget(const std::string &Triple,
454 /// getClosestTargetForJIT - Pick the best target that is compatible with
455 /// the current host. If no close target can be found, this returns null
456 /// and sets the Error string to a reason.
458 /// Maintained for compatibility through 2.6.
459 static const Target *getClosestTargetForJIT(std::string &Error);
462 /// @name Target Registration
465 /// RegisterTarget - Register the given target. Attempts to register a
466 /// target which has already been registered will be ignored.
468 /// Clients are responsible for ensuring that registration doesn't occur
469 /// while another thread is attempting to access the registry. Typically
470 /// this is done by initializing all targets at program startup.
472 /// @param T - The target being registered.
473 /// @param Name - The target name. This should be a static string.
474 /// @param ShortDesc - A short target description. This should be a static
476 /// @param TQualityFn - The triple match quality computation function for
478 /// @param HasJIT - Whether the target supports JIT code
480 static void RegisterTarget(Target &T,
482 const char *ShortDesc,
483 Target::TripleMatchQualityFnTy TQualityFn,
484 bool HasJIT = false);
486 /// RegisterAsmInfo - Register a MCAsmInfo implementation for the
489 /// Clients are responsible for ensuring that registration doesn't occur
490 /// while another thread is attempting to access the registry. Typically
491 /// this is done by initializing all targets at program startup.
493 /// @param T - The target being registered.
494 /// @param Fn - A function to construct a MCAsmInfo for the target.
495 static void RegisterAsmInfo(Target &T, Target::AsmInfoCtorFnTy Fn) {
496 // Ignore duplicate registration.
497 if (!T.AsmInfoCtorFn)
498 T.AsmInfoCtorFn = Fn;
501 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
504 /// Clients are responsible for ensuring that registration doesn't occur
505 /// while another thread is attempting to access the registry. Typically
506 /// this is done by initializing all targets at program startup.
508 /// @param T - The target being registered.
509 /// @param Fn - A function to construct a MCInstrInfo for the target.
510 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
511 // Ignore duplicate registration.
512 if (!T.MCInstrInfoCtorFn)
513 T.MCInstrInfoCtorFn = Fn;
516 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
519 /// Clients are responsible for ensuring that registration doesn't occur
520 /// while another thread is attempting to access the registry. Typically
521 /// this is done by initializing all targets at program startup.
523 /// @param T - The target being registered.
524 /// @param Fn - A function to construct a MCRegisterInfo for the target.
525 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
526 // Ignore duplicate registration.
527 if (!T.MCRegInfoCtorFn)
528 T.MCRegInfoCtorFn = Fn;
531 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
532 /// the given target.
534 /// Clients are responsible for ensuring that registration doesn't occur
535 /// while another thread is attempting to access the registry. Typically
536 /// this is done by initializing all targets at program startup.
538 /// @param T - The target being registered.
539 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
540 static void RegisterMCSubtargetInfo(Target &T,
541 Target::MCSubtargetInfoCtorFnTy Fn) {
542 // Ignore duplicate registration.
543 if (!T.MCSubtargetInfoCtorFn)
544 T.MCSubtargetInfoCtorFn = Fn;
547 /// RegisterTargetMachine - Register a TargetMachine implementation for the
550 /// Clients are responsible for ensuring that registration doesn't occur
551 /// while another thread is attempting to access the registry. Typically
552 /// this is done by initializing all targets at program startup.
554 /// @param T - The target being registered.
555 /// @param Fn - A function to construct a TargetMachine for the target.
556 static void RegisterTargetMachine(Target &T,
557 Target::TargetMachineCtorTy Fn) {
558 // Ignore duplicate registration.
559 if (!T.TargetMachineCtorFn)
560 T.TargetMachineCtorFn = Fn;
563 /// RegisterAsmBackend - Register a TargetAsmBackend implementation for the
566 /// Clients are responsible for ensuring that registration doesn't occur
567 /// while another thread is attempting to access the registry. Typically
568 /// this is done by initializing all targets at program startup.
570 /// @param T - The target being registered.
571 /// @param Fn - A function to construct an AsmBackend for the target.
572 static void RegisterAsmBackend(Target &T, Target::AsmBackendCtorTy Fn) {
573 if (!T.AsmBackendCtorFn)
574 T.AsmBackendCtorFn = Fn;
577 /// RegisterAsmLexer - Register a TargetAsmLexer implementation for the
580 /// Clients are responsible for ensuring that registration doesn't occur
581 /// while another thread is attempting to access the registry. Typically
582 /// this is done by initializing all targets at program startup.
584 /// @param T - The target being registered.
585 /// @param Fn - A function to construct an AsmLexer for the target.
586 static void RegisterAsmLexer(Target &T, Target::AsmLexerCtorTy Fn) {
587 if (!T.AsmLexerCtorFn)
588 T.AsmLexerCtorFn = Fn;
591 /// RegisterAsmParser - Register a TargetAsmParser implementation for the
594 /// Clients are responsible for ensuring that registration doesn't occur
595 /// while another thread is attempting to access the registry. Typically
596 /// this is done by initializing all targets at program startup.
598 /// @param T - The target being registered.
599 /// @param Fn - A function to construct an AsmParser for the target.
600 static void RegisterAsmParser(Target &T, Target::AsmParserCtorTy Fn) {
601 if (!T.AsmParserCtorFn)
602 T.AsmParserCtorFn = Fn;
605 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
608 /// Clients are responsible for ensuring that registration doesn't occur
609 /// while another thread is attempting to access the registry. Typically
610 /// this is done by initializing all targets at program startup.
612 /// @param T - The target being registered.
613 /// @param Fn - A function to construct an AsmPrinter for the target.
614 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
615 // Ignore duplicate registration.
616 if (!T.AsmPrinterCtorFn)
617 T.AsmPrinterCtorFn = Fn;
620 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
621 /// the given target.
623 /// Clients are responsible for ensuring that registration doesn't occur
624 /// while another thread is attempting to access the registry. Typically
625 /// this is done by initializing all targets at program startup.
627 /// @param T - The target being registered.
628 /// @param Fn - A function to construct an MCDisassembler for the target.
629 static void RegisterMCDisassembler(Target &T,
630 Target::MCDisassemblerCtorTy Fn) {
631 if (!T.MCDisassemblerCtorFn)
632 T.MCDisassemblerCtorFn = Fn;
635 /// RegisterMCInstPrinter - Register a MCInstPrinter 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 an MCInstPrinter for the target.
644 static void RegisterMCInstPrinter(Target &T,
645 Target::MCInstPrinterCtorTy Fn) {
646 if (!T.MCInstPrinterCtorFn)
647 T.MCInstPrinterCtorFn = Fn;
650 /// RegisterCodeEmitter - Register a MCCodeEmitter implementation for the
653 /// Clients are responsible for ensuring that registration doesn't occur
654 /// while another thread is attempting to access the registry. Typically
655 /// this is done by initializing all targets at program startup.
657 /// @param T - The target being registered.
658 /// @param Fn - A function to construct an MCCodeEmitter for the target.
659 static void RegisterCodeEmitter(Target &T, Target::CodeEmitterCtorTy Fn) {
660 if (!T.CodeEmitterCtorFn)
661 T.CodeEmitterCtorFn = Fn;
664 /// RegisterObjectStreamer - Register a object code MCStreamer implementation
665 /// for the given target.
667 /// Clients are responsible for ensuring that registration doesn't occur
668 /// while another thread is attempting to access the registry. Typically
669 /// this is done by initializing all targets at program startup.
671 /// @param T - The target being registered.
672 /// @param Fn - A function to construct an MCStreamer for the target.
673 static void RegisterObjectStreamer(Target &T, Target::ObjectStreamerCtorTy Fn) {
674 if (!T.ObjectStreamerCtorFn)
675 T.ObjectStreamerCtorFn = Fn;
678 /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
679 /// for the given target.
681 /// Clients are responsible for ensuring that registration doesn't occur
682 /// while another thread is attempting to access the registry. Typically
683 /// this is done by initializing all targets at program startup.
685 /// @param T - The target being registered.
686 /// @param Fn - A function to construct an MCStreamer for the target.
687 static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
688 if (T.AsmStreamerCtorFn == createAsmStreamer)
689 T.AsmStreamerCtorFn = Fn;
696 //===--------------------------------------------------------------------===//
698 /// RegisterTarget - Helper template for registering a target, for use in the
699 /// target's initialization function. Usage:
702 /// Target TheFooTarget; // The global target instance.
704 /// extern "C" void LLVMInitializeFooTargetInfo() {
705 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
707 template<Triple::ArchType TargetArchType = Triple::InvalidArch,
709 struct RegisterTarget {
710 RegisterTarget(Target &T, const char *Name, const char *Desc) {
711 TargetRegistry::RegisterTarget(T, Name, Desc,
712 &getTripleMatchQuality,
716 static unsigned getTripleMatchQuality(const std::string &TT) {
717 if (Triple(TT).getArch() == TargetArchType)
723 /// RegisterAsmInfo - Helper template for registering a target assembly info
724 /// implementation. This invokes the static "Create" method on the class to
725 /// actually do the construction. Usage:
727 /// extern "C" void LLVMInitializeFooTarget() {
728 /// extern Target TheFooTarget;
729 /// RegisterAsmInfo<FooMCAsmInfo> X(TheFooTarget);
731 template<class MCAsmInfoImpl>
732 struct RegisterAsmInfo {
733 RegisterAsmInfo(Target &T) {
734 TargetRegistry::RegisterAsmInfo(T, &Allocator);
737 static MCAsmInfo *Allocator(const Target &T, StringRef TT) {
738 return new MCAsmInfoImpl(T, TT);
743 /// RegisterAsmInfoFn - Helper template for registering a target assembly info
744 /// implementation. This invokes the specified function to do the
745 /// construction. Usage:
747 /// extern "C" void LLVMInitializeFooTarget() {
748 /// extern Target TheFooTarget;
749 /// RegisterAsmInfoFn X(TheFooTarget, TheFunction);
751 struct RegisterAsmInfoFn {
752 RegisterAsmInfoFn(Target &T, Target::AsmInfoCtorFnTy Fn) {
753 TargetRegistry::RegisterAsmInfo(T, Fn);
757 /// RegisterMCInstrInfo - Helper template for registering a target instruction
758 /// info implementation. This invokes the static "Create" method on the class
759 /// to actually do the construction. Usage:
761 /// extern "C" void LLVMInitializeFooTarget() {
762 /// extern Target TheFooTarget;
763 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
765 template<class MCInstrInfoImpl>
766 struct RegisterMCInstrInfo {
767 RegisterMCInstrInfo(Target &T) {
768 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
771 static MCInstrInfo *Allocator() {
772 return new MCInstrInfoImpl();
776 /// RegisterMCInstrInfoFn - Helper template for registering a target
777 /// instruction info implementation. This invokes the specified function to
778 /// do the construction. Usage:
780 /// extern "C" void LLVMInitializeFooTarget() {
781 /// extern Target TheFooTarget;
782 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
784 struct RegisterMCInstrInfoFn {
785 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
786 TargetRegistry::RegisterMCInstrInfo(T, Fn);
790 /// RegisterMCRegInfo - Helper template for registering a target register info
791 /// implementation. This invokes the static "Create" method on the class to
792 /// actually do the construction. Usage:
794 /// extern "C" void LLVMInitializeFooTarget() {
795 /// extern Target TheFooTarget;
796 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
798 template<class MCRegisterInfoImpl>
799 struct RegisterMCRegInfo {
800 RegisterMCRegInfo(Target &T) {
801 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
804 static MCRegisterInfo *Allocator() {
805 return new MCRegisterInfoImpl();
809 /// RegisterMCRegInfoFn - Helper template for registering a target register
810 /// info implementation. This invokes the specified function to do the
811 /// construction. Usage:
813 /// extern "C" void LLVMInitializeFooTarget() {
814 /// extern Target TheFooTarget;
815 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
817 struct RegisterMCRegInfoFn {
818 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
819 TargetRegistry::RegisterMCRegInfo(T, Fn);
823 /// RegisterMCSubtargetInfo - Helper template for registering a target
824 /// subtarget info implementation. This invokes the static "Create" method
825 /// on the class to actually do the construction. Usage:
827 /// extern "C" void LLVMInitializeFooTarget() {
828 /// extern Target TheFooTarget;
829 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
831 template<class MCSubtargetInfoImpl>
832 struct RegisterMCSubtargetInfo {
833 RegisterMCSubtargetInfo(Target &T) {
834 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
837 static MCSubtargetInfo *Allocator(StringRef TT, StringRef CPU,
839 return new MCSubtargetInfoImpl();
843 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
844 /// subtarget info implementation. This invokes the specified function to
845 /// do the construction. Usage:
847 /// extern "C" void LLVMInitializeFooTarget() {
848 /// extern Target TheFooTarget;
849 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
851 struct RegisterMCSubtargetInfoFn {
852 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
853 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
857 /// RegisterTargetMachine - Helper template for registering a target machine
858 /// implementation, for use in the target machine initialization
861 /// extern "C" void LLVMInitializeFooTarget() {
862 /// extern Target TheFooTarget;
863 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
865 template<class TargetMachineImpl>
866 struct RegisterTargetMachine {
867 RegisterTargetMachine(Target &T) {
868 TargetRegistry::RegisterTargetMachine(T, &Allocator);
872 static TargetMachine *Allocator(const Target &T, const std::string &TT,
873 const std::string &CPU,
874 const std::string &FS) {
875 return new TargetMachineImpl(T, TT, CPU, FS);
879 /// RegisterAsmBackend - Helper template for registering a target specific
880 /// assembler backend. Usage:
882 /// extern "C" void LLVMInitializeFooAsmBackend() {
883 /// extern Target TheFooTarget;
884 /// RegisterAsmBackend<FooAsmLexer> X(TheFooTarget);
886 template<class AsmBackendImpl>
887 struct RegisterAsmBackend {
888 RegisterAsmBackend(Target &T) {
889 TargetRegistry::RegisterAsmBackend(T, &Allocator);
893 static TargetAsmBackend *Allocator(const Target &T,
894 const std::string &Triple) {
895 return new AsmBackendImpl(T, Triple);
899 /// RegisterAsmLexer - Helper template for registering a target specific
900 /// assembly lexer, for use in the target machine initialization
903 /// extern "C" void LLVMInitializeFooAsmLexer() {
904 /// extern Target TheFooTarget;
905 /// RegisterAsmLexer<FooAsmLexer> X(TheFooTarget);
907 template<class AsmLexerImpl>
908 struct RegisterAsmLexer {
909 RegisterAsmLexer(Target &T) {
910 TargetRegistry::RegisterAsmLexer(T, &Allocator);
914 static TargetAsmLexer *Allocator(const Target &T, const MCAsmInfo &MAI) {
915 return new AsmLexerImpl(T, MAI);
919 /// RegisterAsmParser - Helper template for registering a target specific
920 /// assembly parser, for use in the target machine initialization
923 /// extern "C" void LLVMInitializeFooAsmParser() {
924 /// extern Target TheFooTarget;
925 /// RegisterAsmParser<FooAsmParser> X(TheFooTarget);
927 template<class AsmParserImpl>
928 struct RegisterAsmParser {
929 RegisterAsmParser(Target &T) {
930 TargetRegistry::RegisterAsmParser(T, &Allocator);
934 static TargetAsmParser *Allocator(const Target &T, MCAsmParser &P,
936 return new AsmParserImpl(T, P, TM);
940 /// RegisterAsmPrinter - Helper template for registering a target specific
941 /// assembly printer, for use in the target machine initialization
944 /// extern "C" void LLVMInitializeFooAsmPrinter() {
945 /// extern Target TheFooTarget;
946 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
948 template<class AsmPrinterImpl>
949 struct RegisterAsmPrinter {
950 RegisterAsmPrinter(Target &T) {
951 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
955 static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) {
956 return new AsmPrinterImpl(TM, Streamer);
960 /// RegisterCodeEmitter - Helper template for registering a target specific
961 /// machine code emitter, for use in the target initialization
964 /// extern "C" void LLVMInitializeFooCodeEmitter() {
965 /// extern Target TheFooTarget;
966 /// RegisterCodeEmitter<FooCodeEmitter> X(TheFooTarget);
968 template<class CodeEmitterImpl>
969 struct RegisterCodeEmitter {
970 RegisterCodeEmitter(Target &T) {
971 TargetRegistry::RegisterCodeEmitter(T, &Allocator);
975 static MCCodeEmitter *Allocator(const Target &T, TargetMachine &TM,
977 return new CodeEmitterImpl(T, TM, Ctx);