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"
39 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 *(*MCAsmInfoCtorFnTy)(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)(MCSubtargetInfo &STI,
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 MCInstrInfo &II,
93 const MCSubtargetInfo &STI,
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 /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
133 MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
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 /// createMCAsmInfo - 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 *createMCAsmInfo(StringRef Triple) const {
251 if (!MCAsmInfoCtorFn)
253 return MCAsmInfoCtorFn(*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(MCSubtargetInfo &STI,
326 MCAsmParser &Parser) const {
327 if (!AsmParserCtorFn)
329 return AsmParserCtorFn(STI, Parser);
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(const MCInstrInfo &II,
356 const MCSubtargetInfo &STI,
357 MCContext &Ctx) const {
358 if (!CodeEmitterCtorFn)
360 return CodeEmitterCtorFn(II, STI, Ctx);
363 /// createObjectStreamer - Create a target specific MCStreamer.
365 /// \arg TT - The target triple.
366 /// \arg Ctx - The target context.
367 /// \arg TAB - The target assembler backend object. Takes ownership.
368 /// \arg _OS - The stream object.
369 /// \arg _Emitter - The target independent assembler object.Takes ownership.
370 /// \arg RelaxAll - Relax all fixups?
371 /// \arg NoExecStack - Mark file as not needing a executable stack.
372 MCStreamer *createObjectStreamer(const std::string &TT, MCContext &Ctx,
373 TargetAsmBackend &TAB,
375 MCCodeEmitter *_Emitter,
377 bool NoExecStack) const {
378 if (!ObjectStreamerCtorFn)
380 return ObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter, RelaxAll,
384 /// createAsmStreamer - Create a target specific MCStreamer.
385 MCStreamer *createAsmStreamer(MCContext &Ctx,
386 formatted_raw_ostream &OS,
390 MCInstPrinter *InstPrint,
392 TargetAsmBackend *TAB,
393 bool ShowInst) const {
394 // AsmStreamerCtorFn is default to llvm::createAsmStreamer
395 return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useLoc, useCFI,
396 InstPrint, CE, TAB, ShowInst);
402 /// TargetRegistry - Generic interface to target specific features.
403 struct TargetRegistry {
405 const Target *Current;
406 explicit iterator(Target *T) : Current(T) {}
407 friend struct TargetRegistry;
409 iterator(const iterator &I) : Current(I.Current) {}
410 iterator() : Current(0) {}
412 bool operator==(const iterator &x) const {
413 return Current == x.Current;
415 bool operator!=(const iterator &x) const {
416 return !operator==(x);
419 // Iterator traversal: forward iteration only
420 iterator &operator++() { // Preincrement
421 assert(Current && "Cannot increment end iterator!");
422 Current = Current->getNext();
425 iterator operator++(int) { // Postincrement
426 iterator tmp = *this;
431 const Target &operator*() const {
432 assert(Current && "Cannot dereference end iterator!");
436 const Target *operator->() const {
441 /// @name Registry Access
444 static iterator begin();
446 static iterator end() { return iterator(); }
448 /// lookupTarget - Lookup a target based on a target triple.
450 /// \param Triple - The triple to use for finding a target.
451 /// \param Error - On failure, an error string describing why no target was
453 static const Target *lookupTarget(const std::string &Triple,
456 /// getClosestTargetForJIT - Pick the best target that is compatible with
457 /// the current host. If no close target can be found, this returns null
458 /// and sets the Error string to a reason.
460 /// Maintained for compatibility through 2.6.
461 static const Target *getClosestTargetForJIT(std::string &Error);
464 /// @name Target Registration
467 /// RegisterTarget - Register the given target. Attempts to register a
468 /// target which has already been registered will be ignored.
470 /// Clients are responsible for ensuring that registration doesn't occur
471 /// while another thread is attempting to access the registry. Typically
472 /// this is done by initializing all targets at program startup.
474 /// @param T - The target being registered.
475 /// @param Name - The target name. This should be a static string.
476 /// @param ShortDesc - A short target description. This should be a static
478 /// @param TQualityFn - The triple match quality computation function for
480 /// @param HasJIT - Whether the target supports JIT code
482 static void RegisterTarget(Target &T,
484 const char *ShortDesc,
485 Target::TripleMatchQualityFnTy TQualityFn,
486 bool HasJIT = false);
488 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
491 /// Clients are responsible for ensuring that registration doesn't occur
492 /// while another thread is attempting to access the registry. Typically
493 /// this is done by initializing all targets at program startup.
495 /// @param T - The target being registered.
496 /// @param Fn - A function to construct a MCAsmInfo for the target.
497 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
498 // Ignore duplicate registration.
499 if (!T.MCAsmInfoCtorFn)
500 T.MCAsmInfoCtorFn = Fn;
503 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
506 /// Clients are responsible for ensuring that registration doesn't occur
507 /// while another thread is attempting to access the registry. Typically
508 /// this is done by initializing all targets at program startup.
510 /// @param T - The target being registered.
511 /// @param Fn - A function to construct a MCInstrInfo for the target.
512 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
513 // Ignore duplicate registration.
514 if (!T.MCInstrInfoCtorFn)
515 T.MCInstrInfoCtorFn = Fn;
518 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
521 /// Clients are responsible for ensuring that registration doesn't occur
522 /// while another thread is attempting to access the registry. Typically
523 /// this is done by initializing all targets at program startup.
525 /// @param T - The target being registered.
526 /// @param Fn - A function to construct a MCRegisterInfo for the target.
527 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
528 // Ignore duplicate registration.
529 if (!T.MCRegInfoCtorFn)
530 T.MCRegInfoCtorFn = Fn;
533 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
534 /// the given target.
536 /// Clients are responsible for ensuring that registration doesn't occur
537 /// while another thread is attempting to access the registry. Typically
538 /// this is done by initializing all targets at program startup.
540 /// @param T - The target being registered.
541 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
542 static void RegisterMCSubtargetInfo(Target &T,
543 Target::MCSubtargetInfoCtorFnTy Fn) {
544 // Ignore duplicate registration.
545 if (!T.MCSubtargetInfoCtorFn)
546 T.MCSubtargetInfoCtorFn = Fn;
549 /// RegisterTargetMachine - Register a TargetMachine implementation for the
552 /// Clients are responsible for ensuring that registration doesn't occur
553 /// while another thread is attempting to access the registry. Typically
554 /// this is done by initializing all targets at program startup.
556 /// @param T - The target being registered.
557 /// @param Fn - A function to construct a TargetMachine for the target.
558 static void RegisterTargetMachine(Target &T,
559 Target::TargetMachineCtorTy Fn) {
560 // Ignore duplicate registration.
561 if (!T.TargetMachineCtorFn)
562 T.TargetMachineCtorFn = Fn;
565 /// RegisterAsmBackend - Register a TargetAsmBackend implementation for the
568 /// Clients are responsible for ensuring that registration doesn't occur
569 /// while another thread is attempting to access the registry. Typically
570 /// this is done by initializing all targets at program startup.
572 /// @param T - The target being registered.
573 /// @param Fn - A function to construct an AsmBackend for the target.
574 static void RegisterAsmBackend(Target &T, Target::AsmBackendCtorTy Fn) {
575 if (!T.AsmBackendCtorFn)
576 T.AsmBackendCtorFn = Fn;
579 /// RegisterAsmLexer - Register a TargetAsmLexer implementation for the
582 /// Clients are responsible for ensuring that registration doesn't occur
583 /// while another thread is attempting to access the registry. Typically
584 /// this is done by initializing all targets at program startup.
586 /// @param T - The target being registered.
587 /// @param Fn - A function to construct an AsmLexer for the target.
588 static void RegisterAsmLexer(Target &T, Target::AsmLexerCtorTy Fn) {
589 if (!T.AsmLexerCtorFn)
590 T.AsmLexerCtorFn = Fn;
593 /// RegisterAsmParser - Register a TargetAsmParser implementation for the
596 /// Clients are responsible for ensuring that registration doesn't occur
597 /// while another thread is attempting to access the registry. Typically
598 /// this is done by initializing all targets at program startup.
600 /// @param T - The target being registered.
601 /// @param Fn - A function to construct an AsmParser for the target.
602 static void RegisterAsmParser(Target &T, Target::AsmParserCtorTy Fn) {
603 if (!T.AsmParserCtorFn)
604 T.AsmParserCtorFn = Fn;
607 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
610 /// Clients are responsible for ensuring that registration doesn't occur
611 /// while another thread is attempting to access the registry. Typically
612 /// this is done by initializing all targets at program startup.
614 /// @param T - The target being registered.
615 /// @param Fn - A function to construct an AsmPrinter for the target.
616 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
617 // Ignore duplicate registration.
618 if (!T.AsmPrinterCtorFn)
619 T.AsmPrinterCtorFn = Fn;
622 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
623 /// the given target.
625 /// Clients are responsible for ensuring that registration doesn't occur
626 /// while another thread is attempting to access the registry. Typically
627 /// this is done by initializing all targets at program startup.
629 /// @param T - The target being registered.
630 /// @param Fn - A function to construct an MCDisassembler for the target.
631 static void RegisterMCDisassembler(Target &T,
632 Target::MCDisassemblerCtorTy Fn) {
633 if (!T.MCDisassemblerCtorFn)
634 T.MCDisassemblerCtorFn = Fn;
637 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
640 /// Clients are responsible for ensuring that registration doesn't occur
641 /// while another thread is attempting to access the registry. Typically
642 /// this is done by initializing all targets at program startup.
644 /// @param T - The target being registered.
645 /// @param Fn - A function to construct an MCInstPrinter for the target.
646 static void RegisterMCInstPrinter(Target &T,
647 Target::MCInstPrinterCtorTy Fn) {
648 if (!T.MCInstPrinterCtorFn)
649 T.MCInstPrinterCtorFn = Fn;
652 /// RegisterCodeEmitter - Register a MCCodeEmitter implementation for the
655 /// Clients are responsible for ensuring that registration doesn't occur
656 /// while another thread is attempting to access the registry. Typically
657 /// this is done by initializing all targets at program startup.
659 /// @param T - The target being registered.
660 /// @param Fn - A function to construct an MCCodeEmitter for the target.
661 static void RegisterCodeEmitter(Target &T, Target::CodeEmitterCtorTy Fn) {
662 if (!T.CodeEmitterCtorFn)
663 T.CodeEmitterCtorFn = Fn;
666 /// RegisterObjectStreamer - Register a object code MCStreamer implementation
667 /// for the given target.
669 /// Clients are responsible for ensuring that registration doesn't occur
670 /// while another thread is attempting to access the registry. Typically
671 /// this is done by initializing all targets at program startup.
673 /// @param T - The target being registered.
674 /// @param Fn - A function to construct an MCStreamer for the target.
675 static void RegisterObjectStreamer(Target &T, Target::ObjectStreamerCtorTy Fn) {
676 if (!T.ObjectStreamerCtorFn)
677 T.ObjectStreamerCtorFn = Fn;
680 /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
681 /// for the given target.
683 /// Clients are responsible for ensuring that registration doesn't occur
684 /// while another thread is attempting to access the registry. Typically
685 /// this is done by initializing all targets at program startup.
687 /// @param T - The target being registered.
688 /// @param Fn - A function to construct an MCStreamer for the target.
689 static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
690 if (T.AsmStreamerCtorFn == createAsmStreamer)
691 T.AsmStreamerCtorFn = Fn;
698 //===--------------------------------------------------------------------===//
700 /// RegisterTarget - Helper template for registering a target, for use in the
701 /// target's initialization function. Usage:
704 /// Target TheFooTarget; // The global target instance.
706 /// extern "C" void LLVMInitializeFooTargetInfo() {
707 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
709 template<Triple::ArchType TargetArchType = Triple::InvalidArch,
711 struct RegisterTarget {
712 RegisterTarget(Target &T, const char *Name, const char *Desc) {
713 TargetRegistry::RegisterTarget(T, Name, Desc,
714 &getTripleMatchQuality,
718 static unsigned getTripleMatchQuality(const std::string &TT) {
719 if (Triple(TT).getArch() == TargetArchType)
725 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
726 /// implementation. This invokes the static "Create" method on the class to
727 /// actually do the construction. Usage:
729 /// extern "C" void LLVMInitializeFooTarget() {
730 /// extern Target TheFooTarget;
731 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
733 template<class MCAsmInfoImpl>
734 struct RegisterMCAsmInfo {
735 RegisterMCAsmInfo(Target &T) {
736 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
739 static MCAsmInfo *Allocator(const Target &T, StringRef TT) {
740 return new MCAsmInfoImpl(T, TT);
745 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
746 /// implementation. This invokes the specified function to do the
747 /// construction. Usage:
749 /// extern "C" void LLVMInitializeFooTarget() {
750 /// extern Target TheFooTarget;
751 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
753 struct RegisterMCAsmInfoFn {
754 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
755 TargetRegistry::RegisterMCAsmInfo(T, Fn);
759 /// RegisterMCInstrInfo - Helper template for registering a target instruction
760 /// info implementation. This invokes the static "Create" method on the class
761 /// to actually do the construction. Usage:
763 /// extern "C" void LLVMInitializeFooTarget() {
764 /// extern Target TheFooTarget;
765 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
767 template<class MCInstrInfoImpl>
768 struct RegisterMCInstrInfo {
769 RegisterMCInstrInfo(Target &T) {
770 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
773 static MCInstrInfo *Allocator() {
774 return new MCInstrInfoImpl();
778 /// RegisterMCInstrInfoFn - Helper template for registering a target
779 /// instruction info implementation. This invokes the specified function to
780 /// do the construction. Usage:
782 /// extern "C" void LLVMInitializeFooTarget() {
783 /// extern Target TheFooTarget;
784 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
786 struct RegisterMCInstrInfoFn {
787 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
788 TargetRegistry::RegisterMCInstrInfo(T, Fn);
792 /// RegisterMCRegInfo - Helper template for registering a target register info
793 /// implementation. This invokes the static "Create" method on the class to
794 /// actually do the construction. Usage:
796 /// extern "C" void LLVMInitializeFooTarget() {
797 /// extern Target TheFooTarget;
798 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
800 template<class MCRegisterInfoImpl>
801 struct RegisterMCRegInfo {
802 RegisterMCRegInfo(Target &T) {
803 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
806 static MCRegisterInfo *Allocator() {
807 return new MCRegisterInfoImpl();
811 /// RegisterMCRegInfoFn - Helper template for registering a target register
812 /// info implementation. This invokes the specified function to do the
813 /// construction. Usage:
815 /// extern "C" void LLVMInitializeFooTarget() {
816 /// extern Target TheFooTarget;
817 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
819 struct RegisterMCRegInfoFn {
820 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
821 TargetRegistry::RegisterMCRegInfo(T, Fn);
825 /// RegisterMCSubtargetInfo - Helper template for registering a target
826 /// subtarget info implementation. This invokes the static "Create" method
827 /// on the class to actually do the construction. Usage:
829 /// extern "C" void LLVMInitializeFooTarget() {
830 /// extern Target TheFooTarget;
831 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
833 template<class MCSubtargetInfoImpl>
834 struct RegisterMCSubtargetInfo {
835 RegisterMCSubtargetInfo(Target &T) {
836 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
839 static MCSubtargetInfo *Allocator(StringRef TT, StringRef CPU,
841 return new MCSubtargetInfoImpl();
845 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
846 /// subtarget info implementation. This invokes the specified function to
847 /// do the construction. Usage:
849 /// extern "C" void LLVMInitializeFooTarget() {
850 /// extern Target TheFooTarget;
851 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
853 struct RegisterMCSubtargetInfoFn {
854 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
855 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
859 /// RegisterTargetMachine - Helper template for registering a target machine
860 /// implementation, for use in the target machine initialization
863 /// extern "C" void LLVMInitializeFooTarget() {
864 /// extern Target TheFooTarget;
865 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
867 template<class TargetMachineImpl>
868 struct RegisterTargetMachine {
869 RegisterTargetMachine(Target &T) {
870 TargetRegistry::RegisterTargetMachine(T, &Allocator);
874 static TargetMachine *Allocator(const Target &T, const std::string &TT,
875 const std::string &CPU,
876 const std::string &FS) {
877 return new TargetMachineImpl(T, TT, CPU, FS);
881 /// RegisterAsmBackend - Helper template for registering a target specific
882 /// assembler backend. Usage:
884 /// extern "C" void LLVMInitializeFooAsmBackend() {
885 /// extern Target TheFooTarget;
886 /// RegisterAsmBackend<FooAsmLexer> X(TheFooTarget);
888 template<class AsmBackendImpl>
889 struct RegisterAsmBackend {
890 RegisterAsmBackend(Target &T) {
891 TargetRegistry::RegisterAsmBackend(T, &Allocator);
895 static TargetAsmBackend *Allocator(const Target &T,
896 const std::string &Triple) {
897 return new AsmBackendImpl(T, Triple);
901 /// RegisterAsmLexer - Helper template for registering a target specific
902 /// assembly lexer, for use in the target machine initialization
905 /// extern "C" void LLVMInitializeFooAsmLexer() {
906 /// extern Target TheFooTarget;
907 /// RegisterAsmLexer<FooAsmLexer> X(TheFooTarget);
909 template<class AsmLexerImpl>
910 struct RegisterAsmLexer {
911 RegisterAsmLexer(Target &T) {
912 TargetRegistry::RegisterAsmLexer(T, &Allocator);
916 static TargetAsmLexer *Allocator(const Target &T, const MCAsmInfo &MAI) {
917 return new AsmLexerImpl(T, MAI);
921 /// RegisterAsmParser - Helper template for registering a target specific
922 /// assembly parser, for use in the target machine initialization
925 /// extern "C" void LLVMInitializeFooAsmParser() {
926 /// extern Target TheFooTarget;
927 /// RegisterAsmParser<FooAsmParser> X(TheFooTarget);
929 template<class AsmParserImpl>
930 struct RegisterAsmParser {
931 RegisterAsmParser(Target &T) {
932 TargetRegistry::RegisterAsmParser(T, &Allocator);
936 static TargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P) {
937 return new AsmParserImpl(STI, P);
941 /// RegisterAsmPrinter - Helper template for registering a target specific
942 /// assembly printer, for use in the target machine initialization
945 /// extern "C" void LLVMInitializeFooAsmPrinter() {
946 /// extern Target TheFooTarget;
947 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
949 template<class AsmPrinterImpl>
950 struct RegisterAsmPrinter {
951 RegisterAsmPrinter(Target &T) {
952 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
956 static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) {
957 return new AsmPrinterImpl(TM, Streamer);
961 /// RegisterCodeEmitter - Helper template for registering a target specific
962 /// machine code emitter, for use in the target initialization
965 /// extern "C" void LLVMInitializeFooCodeEmitter() {
966 /// extern Target TheFooTarget;
967 /// RegisterCodeEmitter<FooCodeEmitter> X(TheFooTarget);
969 template<class CodeEmitterImpl>
970 struct RegisterCodeEmitter {
971 RegisterCodeEmitter(Target &T) {
972 TargetRegistry::RegisterCodeEmitter(T, &Allocator);
976 static MCCodeEmitter *Allocator(const MCInstrInfo &II,
977 const MCSubtargetInfo &STI,
979 return new CodeEmitterImpl();