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/MC/MCCodeGenInfo.h"
23 #include "llvm/ADT/Triple.h"
40 class MCSubtargetInfo;
42 class TargetAsmBackend;
44 class TargetAsmParser;
47 class formatted_raw_ostream;
49 MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
51 bool useLoc, bool useCFI,
52 MCInstPrinter *InstPrint,
54 TargetAsmBackend *TAB,
57 /// Target - Wrapper for Target specific information.
59 /// For registration purposes, this is a POD type so that targets can be
60 /// registered without the use of static constructors.
62 /// Targets should implement a single global instance of this class (which
63 /// will be zero initialized), and pass that instance to the TargetRegistry as
64 /// part of their initialization.
67 friend struct TargetRegistry;
69 typedef unsigned (*TripleMatchQualityFnTy)(const std::string &TT);
71 typedef MCAsmInfo *(*MCAsmInfoCtorFnTy)(const Target &T,
73 typedef MCCodeGenInfo *(*MCCodeGenInfoCtorFnTy)(StringRef TT, Reloc::Model M);
74 typedef MCInstrInfo *(*MCInstrInfoCtorFnTy)(void);
75 typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(StringRef TT);
76 typedef MCSubtargetInfo *(*MCSubtargetInfoCtorFnTy)(StringRef TT,
79 typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T,
84 typedef AsmPrinter *(*AsmPrinterCtorTy)(TargetMachine &TM,
85 MCStreamer &Streamer);
86 typedef TargetAsmBackend *(*AsmBackendCtorTy)(const Target &T,
87 const std::string &TT);
88 typedef TargetAsmLexer *(*AsmLexerCtorTy)(const Target &T,
89 const MCAsmInfo &MAI);
90 typedef TargetAsmParser *(*AsmParserCtorTy)(MCSubtargetInfo &STI,
92 typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T);
93 typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
94 unsigned SyntaxVariant,
95 const MCAsmInfo &MAI);
96 typedef MCCodeEmitter *(*CodeEmitterCtorTy)(const MCInstrInfo &II,
97 const MCSubtargetInfo &STI,
99 typedef MCStreamer *(*ObjectStreamerCtorTy)(const Target &T,
100 const std::string &TT,
102 TargetAsmBackend &TAB,
104 MCCodeEmitter *_Emitter,
107 typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx,
108 formatted_raw_ostream &OS,
112 MCInstPrinter *InstPrint,
114 TargetAsmBackend *TAB,
118 /// Next - The next registered target in the linked list, maintained by the
122 /// TripleMatchQualityFn - The target function for rating the match quality
124 TripleMatchQualityFnTy TripleMatchQualityFn;
126 /// Name - The target name.
129 /// ShortDesc - A short description of the target.
130 const char *ShortDesc;
132 /// HasJIT - Whether this target supports the JIT.
135 /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
137 MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
139 /// MCCodeGenInfoCtorFn - Constructor function for this target's MCCodeGenInfo,
141 MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn;
143 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
145 MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
147 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
149 MCRegInfoCtorFnTy MCRegInfoCtorFn;
151 /// MCSubtargetInfoCtorFn - Constructor function for this target's
152 /// MCSubtargetInfo, if registered.
153 MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
155 /// TargetMachineCtorFn - Construction function for this target's
156 /// TargetMachine, if registered.
157 TargetMachineCtorTy TargetMachineCtorFn;
159 /// AsmBackendCtorFn - Construction function for this target's
160 /// TargetAsmBackend, if registered.
161 AsmBackendCtorTy AsmBackendCtorFn;
163 /// AsmLexerCtorFn - Construction function for this target's TargetAsmLexer,
165 AsmLexerCtorTy AsmLexerCtorFn;
167 /// AsmParserCtorFn - Construction function for this target's
168 /// TargetAsmParser, if registered.
169 AsmParserCtorTy AsmParserCtorFn;
171 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
173 AsmPrinterCtorTy AsmPrinterCtorFn;
175 /// MCDisassemblerCtorFn - Construction function for this target's
176 /// MCDisassembler, if registered.
177 MCDisassemblerCtorTy MCDisassemblerCtorFn;
179 /// MCInstPrinterCtorFn - Construction function for this target's
180 /// MCInstPrinter, if registered.
181 MCInstPrinterCtorTy MCInstPrinterCtorFn;
183 /// CodeEmitterCtorFn - Construction function for this target's CodeEmitter,
185 CodeEmitterCtorTy CodeEmitterCtorFn;
187 /// ObjectStreamerCtorFn - Construction function for this target's
188 /// ObjectStreamer, if registered.
189 ObjectStreamerCtorTy ObjectStreamerCtorFn;
191 /// AsmStreamerCtorFn - Construction function for this target's
192 /// AsmStreamer, if registered (default = llvm::createAsmStreamer).
193 AsmStreamerCtorTy AsmStreamerCtorFn;
196 Target() : AsmStreamerCtorFn(llvm::createAsmStreamer) {}
198 /// @name Target Information
201 // getNext - Return the next registered target.
202 const Target *getNext() const { return Next; }
204 /// getName - Get the target name.
205 const char *getName() const { return Name; }
207 /// getShortDescription - Get a short description of the target.
208 const char *getShortDescription() const { return ShortDesc; }
211 /// @name Feature Predicates
214 /// hasJIT - Check if this targets supports the just-in-time compilation.
215 bool hasJIT() const { return HasJIT; }
217 /// hasTargetMachine - Check if this target supports code generation.
218 bool hasTargetMachine() const { return TargetMachineCtorFn != 0; }
220 /// hasAsmBackend - Check if this target supports .o generation.
221 bool hasAsmBackend() const { return AsmBackendCtorFn != 0; }
223 /// hasAsmLexer - Check if this target supports .s lexing.
224 bool hasAsmLexer() const { return AsmLexerCtorFn != 0; }
226 /// hasAsmParser - Check if this target supports .s parsing.
227 bool hasAsmParser() const { return AsmParserCtorFn != 0; }
229 /// hasAsmPrinter - Check if this target supports .s printing.
230 bool hasAsmPrinter() const { return AsmPrinterCtorFn != 0; }
232 /// hasMCDisassembler - Check if this target has a disassembler.
233 bool hasMCDisassembler() const { return MCDisassemblerCtorFn != 0; }
235 /// hasMCInstPrinter - Check if this target has an instruction printer.
236 bool hasMCInstPrinter() const { return MCInstPrinterCtorFn != 0; }
238 /// hasCodeEmitter - Check if this target supports instruction encoding.
239 bool hasCodeEmitter() const { return CodeEmitterCtorFn != 0; }
241 /// hasObjectStreamer - Check if this target supports streaming to files.
242 bool hasObjectStreamer() const { return ObjectStreamerCtorFn != 0; }
244 /// hasAsmStreamer - Check if this target supports streaming to files.
245 bool hasAsmStreamer() const { return AsmStreamerCtorFn != 0; }
248 /// @name Feature Constructors
251 /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
254 /// \arg Triple - This argument is used to determine the target machine
255 /// feature set; it should always be provided. Generally this should be
256 /// either the target triple from the module, or the target triple of the
257 /// host if that does not exist.
258 MCAsmInfo *createMCAsmInfo(StringRef Triple) const {
259 if (!MCAsmInfoCtorFn)
261 return MCAsmInfoCtorFn(*this, Triple);
264 /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
266 MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model M) const {
267 if (!MCCodeGenInfoCtorFn)
269 return MCCodeGenInfoCtorFn(Triple, M);
272 /// createMCInstrInfo - Create a MCInstrInfo implementation.
274 MCInstrInfo *createMCInstrInfo() const {
275 if (!MCInstrInfoCtorFn)
277 return MCInstrInfoCtorFn();
280 /// createMCRegInfo - Create a MCRegisterInfo implementation.
282 MCRegisterInfo *createMCRegInfo(StringRef Triple) const {
283 if (!MCRegInfoCtorFn)
285 return MCRegInfoCtorFn(Triple);
288 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
290 /// \arg Triple - This argument is used to determine the target machine
291 /// feature set; it should always be provided. Generally this should be
292 /// either the target triple from the module, or the target triple of the
293 /// host if that does not exist.
294 /// \arg CPU - This specifies the name of the target CPU.
295 /// \arg Features - This specifies the string representation of the
296 /// additional target features.
297 MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU,
298 StringRef Features) const {
299 if (!MCSubtargetInfoCtorFn)
301 return MCSubtargetInfoCtorFn(Triple, CPU, Features);
304 /// createTargetMachine - Create a target specific machine implementation
305 /// for the specified \arg Triple.
307 /// \arg Triple - This argument is used to determine the target machine
308 /// feature set; it should always be provided. Generally this should be
309 /// either the target triple from the module, or the target triple of the
310 /// host if that does not exist.
311 TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU,
313 Reloc::Model RM = Reloc::Default) const {
314 if (!TargetMachineCtorFn)
316 return TargetMachineCtorFn(*this, Triple, CPU, Features, RM);
319 /// createAsmBackend - Create a target specific assembly parser.
321 /// \arg Triple - The target triple string.
322 /// \arg Backend - The target independent assembler object.
323 TargetAsmBackend *createAsmBackend(const std::string &Triple) const {
324 if (!AsmBackendCtorFn)
326 return AsmBackendCtorFn(*this, Triple);
329 /// createAsmLexer - Create a target specific assembly lexer.
331 TargetAsmLexer *createAsmLexer(const MCAsmInfo &MAI) const {
334 return AsmLexerCtorFn(*this, MAI);
337 /// createAsmParser - Create a target specific assembly parser.
339 /// \arg Parser - The target independent parser implementation to use for
340 /// parsing and lexing.
341 TargetAsmParser *createAsmParser(MCSubtargetInfo &STI,
342 MCAsmParser &Parser) const {
343 if (!AsmParserCtorFn)
345 return AsmParserCtorFn(STI, Parser);
348 /// createAsmPrinter - Create a target specific assembly printer pass. This
349 /// takes ownership of the MCStreamer object.
350 AsmPrinter *createAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) const{
351 if (!AsmPrinterCtorFn)
353 return AsmPrinterCtorFn(TM, Streamer);
356 MCDisassembler *createMCDisassembler() const {
357 if (!MCDisassemblerCtorFn)
359 return MCDisassemblerCtorFn(*this);
362 MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
363 const MCAsmInfo &MAI) const {
364 if (!MCInstPrinterCtorFn)
366 return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI);
370 /// createCodeEmitter - Create a target specific code emitter.
371 MCCodeEmitter *createCodeEmitter(const MCInstrInfo &II,
372 const MCSubtargetInfo &STI,
373 MCContext &Ctx) const {
374 if (!CodeEmitterCtorFn)
376 return CodeEmitterCtorFn(II, STI, Ctx);
379 /// createObjectStreamer - Create a target specific MCStreamer.
381 /// \arg TT - The target triple.
382 /// \arg Ctx - The target context.
383 /// \arg TAB - The target assembler backend object. Takes ownership.
384 /// \arg _OS - The stream object.
385 /// \arg _Emitter - The target independent assembler object.Takes ownership.
386 /// \arg RelaxAll - Relax all fixups?
387 /// \arg NoExecStack - Mark file as not needing a executable stack.
388 MCStreamer *createObjectStreamer(const std::string &TT, MCContext &Ctx,
389 TargetAsmBackend &TAB,
391 MCCodeEmitter *_Emitter,
393 bool NoExecStack) const {
394 if (!ObjectStreamerCtorFn)
396 return ObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter, RelaxAll,
400 /// createAsmStreamer - Create a target specific MCStreamer.
401 MCStreamer *createAsmStreamer(MCContext &Ctx,
402 formatted_raw_ostream &OS,
406 MCInstPrinter *InstPrint,
408 TargetAsmBackend *TAB,
409 bool ShowInst) const {
410 // AsmStreamerCtorFn is default to llvm::createAsmStreamer
411 return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useLoc, useCFI,
412 InstPrint, CE, TAB, ShowInst);
418 /// TargetRegistry - Generic interface to target specific features.
419 struct TargetRegistry {
421 const Target *Current;
422 explicit iterator(Target *T) : Current(T) {}
423 friend struct TargetRegistry;
425 iterator(const iterator &I) : Current(I.Current) {}
426 iterator() : Current(0) {}
428 bool operator==(const iterator &x) const {
429 return Current == x.Current;
431 bool operator!=(const iterator &x) const {
432 return !operator==(x);
435 // Iterator traversal: forward iteration only
436 iterator &operator++() { // Preincrement
437 assert(Current && "Cannot increment end iterator!");
438 Current = Current->getNext();
441 iterator operator++(int) { // Postincrement
442 iterator tmp = *this;
447 const Target &operator*() const {
448 assert(Current && "Cannot dereference end iterator!");
452 const Target *operator->() const {
457 /// @name Registry Access
460 static iterator begin();
462 static iterator end() { return iterator(); }
464 /// lookupTarget - Lookup a target based on a target triple.
466 /// \param Triple - The triple to use for finding a target.
467 /// \param Error - On failure, an error string describing why no target was
469 static const Target *lookupTarget(const std::string &Triple,
472 /// getClosestTargetForJIT - Pick the best target that is compatible with
473 /// the current host. If no close target can be found, this returns null
474 /// and sets the Error string to a reason.
476 /// Maintained for compatibility through 2.6.
477 static const Target *getClosestTargetForJIT(std::string &Error);
480 /// @name Target Registration
483 /// RegisterTarget - Register the given target. Attempts to register a
484 /// target which has already been registered will be ignored.
486 /// Clients are responsible for ensuring that registration doesn't occur
487 /// while another thread is attempting to access the registry. Typically
488 /// this is done by initializing all targets at program startup.
490 /// @param T - The target being registered.
491 /// @param Name - The target name. This should be a static string.
492 /// @param ShortDesc - A short target description. This should be a static
494 /// @param TQualityFn - The triple match quality computation function for
496 /// @param HasJIT - Whether the target supports JIT code
498 static void RegisterTarget(Target &T,
500 const char *ShortDesc,
501 Target::TripleMatchQualityFnTy TQualityFn,
502 bool HasJIT = false);
504 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
507 /// Clients are responsible for ensuring that registration doesn't occur
508 /// while another thread is attempting to access the registry. Typically
509 /// this is done by initializing all targets at program startup.
511 /// @param T - The target being registered.
512 /// @param Fn - A function to construct a MCAsmInfo for the target.
513 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
514 // Ignore duplicate registration.
515 if (!T.MCAsmInfoCtorFn)
516 T.MCAsmInfoCtorFn = Fn;
519 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
522 /// Clients are responsible for ensuring that registration doesn't occur
523 /// while another thread is attempting to access the registry. Typically
524 /// this is done by initializing all targets at program startup.
526 /// @param T - The target being registered.
527 /// @param Fn - A function to construct a MCCodeGenInfo for the target.
528 static void RegisterMCCodeGenInfo(Target &T,
529 Target::MCCodeGenInfoCtorFnTy Fn) {
530 // Ignore duplicate registration.
531 if (!T.MCCodeGenInfoCtorFn)
532 T.MCCodeGenInfoCtorFn = Fn;
535 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
538 /// Clients are responsible for ensuring that registration doesn't occur
539 /// while another thread is attempting to access the registry. Typically
540 /// this is done by initializing all targets at program startup.
542 /// @param T - The target being registered.
543 /// @param Fn - A function to construct a MCInstrInfo for the target.
544 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
545 // Ignore duplicate registration.
546 if (!T.MCInstrInfoCtorFn)
547 T.MCInstrInfoCtorFn = Fn;
550 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
553 /// Clients are responsible for ensuring that registration doesn't occur
554 /// while another thread is attempting to access the registry. Typically
555 /// this is done by initializing all targets at program startup.
557 /// @param T - The target being registered.
558 /// @param Fn - A function to construct a MCRegisterInfo for the target.
559 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
560 // Ignore duplicate registration.
561 if (!T.MCRegInfoCtorFn)
562 T.MCRegInfoCtorFn = Fn;
565 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
566 /// the given target.
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 a MCSubtargetInfo for the target.
574 static void RegisterMCSubtargetInfo(Target &T,
575 Target::MCSubtargetInfoCtorFnTy Fn) {
576 // Ignore duplicate registration.
577 if (!T.MCSubtargetInfoCtorFn)
578 T.MCSubtargetInfoCtorFn = Fn;
581 /// RegisterTargetMachine - Register a TargetMachine implementation for the
584 /// Clients are responsible for ensuring that registration doesn't occur
585 /// while another thread is attempting to access the registry. Typically
586 /// this is done by initializing all targets at program startup.
588 /// @param T - The target being registered.
589 /// @param Fn - A function to construct a TargetMachine for the target.
590 static void RegisterTargetMachine(Target &T,
591 Target::TargetMachineCtorTy Fn) {
592 // Ignore duplicate registration.
593 if (!T.TargetMachineCtorFn)
594 T.TargetMachineCtorFn = Fn;
597 /// RegisterAsmBackend - Register a TargetAsmBackend implementation for the
600 /// Clients are responsible for ensuring that registration doesn't occur
601 /// while another thread is attempting to access the registry. Typically
602 /// this is done by initializing all targets at program startup.
604 /// @param T - The target being registered.
605 /// @param Fn - A function to construct an AsmBackend for the target.
606 static void RegisterAsmBackend(Target &T, Target::AsmBackendCtorTy Fn) {
607 if (!T.AsmBackendCtorFn)
608 T.AsmBackendCtorFn = Fn;
611 /// RegisterAsmLexer - Register a TargetAsmLexer implementation for the
614 /// Clients are responsible for ensuring that registration doesn't occur
615 /// while another thread is attempting to access the registry. Typically
616 /// this is done by initializing all targets at program startup.
618 /// @param T - The target being registered.
619 /// @param Fn - A function to construct an AsmLexer for the target.
620 static void RegisterAsmLexer(Target &T, Target::AsmLexerCtorTy Fn) {
621 if (!T.AsmLexerCtorFn)
622 T.AsmLexerCtorFn = Fn;
625 /// RegisterAsmParser - Register a TargetAsmParser implementation for the
628 /// Clients are responsible for ensuring that registration doesn't occur
629 /// while another thread is attempting to access the registry. Typically
630 /// this is done by initializing all targets at program startup.
632 /// @param T - The target being registered.
633 /// @param Fn - A function to construct an AsmParser for the target.
634 static void RegisterAsmParser(Target &T, Target::AsmParserCtorTy Fn) {
635 if (!T.AsmParserCtorFn)
636 T.AsmParserCtorFn = Fn;
639 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
642 /// Clients are responsible for ensuring that registration doesn't occur
643 /// while another thread is attempting to access the registry. Typically
644 /// this is done by initializing all targets at program startup.
646 /// @param T - The target being registered.
647 /// @param Fn - A function to construct an AsmPrinter for the target.
648 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
649 // Ignore duplicate registration.
650 if (!T.AsmPrinterCtorFn)
651 T.AsmPrinterCtorFn = Fn;
654 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
655 /// the given target.
657 /// Clients are responsible for ensuring that registration doesn't occur
658 /// while another thread is attempting to access the registry. Typically
659 /// this is done by initializing all targets at program startup.
661 /// @param T - The target being registered.
662 /// @param Fn - A function to construct an MCDisassembler for the target.
663 static void RegisterMCDisassembler(Target &T,
664 Target::MCDisassemblerCtorTy Fn) {
665 if (!T.MCDisassemblerCtorFn)
666 T.MCDisassemblerCtorFn = Fn;
669 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
672 /// Clients are responsible for ensuring that registration doesn't occur
673 /// while another thread is attempting to access the registry. Typically
674 /// this is done by initializing all targets at program startup.
676 /// @param T - The target being registered.
677 /// @param Fn - A function to construct an MCInstPrinter for the target.
678 static void RegisterMCInstPrinter(Target &T,
679 Target::MCInstPrinterCtorTy Fn) {
680 if (!T.MCInstPrinterCtorFn)
681 T.MCInstPrinterCtorFn = Fn;
684 /// RegisterCodeEmitter - Register a MCCodeEmitter implementation for the
687 /// Clients are responsible for ensuring that registration doesn't occur
688 /// while another thread is attempting to access the registry. Typically
689 /// this is done by initializing all targets at program startup.
691 /// @param T - The target being registered.
692 /// @param Fn - A function to construct an MCCodeEmitter for the target.
693 static void RegisterCodeEmitter(Target &T, Target::CodeEmitterCtorTy Fn) {
694 if (!T.CodeEmitterCtorFn)
695 T.CodeEmitterCtorFn = Fn;
698 /// RegisterObjectStreamer - Register a object code MCStreamer implementation
699 /// for the given target.
701 /// Clients are responsible for ensuring that registration doesn't occur
702 /// while another thread is attempting to access the registry. Typically
703 /// this is done by initializing all targets at program startup.
705 /// @param T - The target being registered.
706 /// @param Fn - A function to construct an MCStreamer for the target.
707 static void RegisterObjectStreamer(Target &T, Target::ObjectStreamerCtorTy Fn) {
708 if (!T.ObjectStreamerCtorFn)
709 T.ObjectStreamerCtorFn = Fn;
712 /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
713 /// for the given target.
715 /// Clients are responsible for ensuring that registration doesn't occur
716 /// while another thread is attempting to access the registry. Typically
717 /// this is done by initializing all targets at program startup.
719 /// @param T - The target being registered.
720 /// @param Fn - A function to construct an MCStreamer for the target.
721 static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
722 if (T.AsmStreamerCtorFn == createAsmStreamer)
723 T.AsmStreamerCtorFn = Fn;
730 //===--------------------------------------------------------------------===//
732 /// RegisterTarget - Helper template for registering a target, for use in the
733 /// target's initialization function. Usage:
736 /// Target TheFooTarget; // The global target instance.
738 /// extern "C" void LLVMInitializeFooTargetInfo() {
739 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
741 template<Triple::ArchType TargetArchType = Triple::InvalidArch,
743 struct RegisterTarget {
744 RegisterTarget(Target &T, const char *Name, const char *Desc) {
745 TargetRegistry::RegisterTarget(T, Name, Desc,
746 &getTripleMatchQuality,
750 static unsigned getTripleMatchQuality(const std::string &TT) {
751 if (Triple(TT).getArch() == TargetArchType)
757 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
758 /// implementation. This invokes the static "Create" method on the class to
759 /// actually do the construction. Usage:
761 /// extern "C" void LLVMInitializeFooTarget() {
762 /// extern Target TheFooTarget;
763 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
765 template<class MCAsmInfoImpl>
766 struct RegisterMCAsmInfo {
767 RegisterMCAsmInfo(Target &T) {
768 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
771 static MCAsmInfo *Allocator(const Target &T, StringRef TT) {
772 return new MCAsmInfoImpl(T, TT);
777 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
778 /// implementation. This invokes the specified function to do the
779 /// construction. Usage:
781 /// extern "C" void LLVMInitializeFooTarget() {
782 /// extern Target TheFooTarget;
783 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
785 struct RegisterMCAsmInfoFn {
786 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
787 TargetRegistry::RegisterMCAsmInfo(T, Fn);
791 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
792 /// implementation. This invokes the static "Create" method on the class
793 /// to actually do the construction. Usage:
795 /// extern "C" void LLVMInitializeFooTarget() {
796 /// extern Target TheFooTarget;
797 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
799 template<class MCCodeGenInfoImpl>
800 struct RegisterMCCodeGenInfo {
801 RegisterMCCodeGenInfo(Target &T) {
802 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
805 static MCCodeGenInfo *Allocator(StringRef TT, Reloc::Model M) {
806 return new MCCodeGenInfoImpl();
810 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
811 /// info implementation. This invokes the specified function to do the
812 /// construction. Usage:
814 /// extern "C" void LLVMInitializeFooTarget() {
815 /// extern Target TheFooTarget;
816 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
818 struct RegisterMCCodeGenInfoFn {
819 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
820 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
824 /// RegisterMCInstrInfo - Helper template for registering a target instruction
825 /// info implementation. This invokes the static "Create" method on the class
826 /// to actually do the construction. Usage:
828 /// extern "C" void LLVMInitializeFooTarget() {
829 /// extern Target TheFooTarget;
830 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
832 template<class MCInstrInfoImpl>
833 struct RegisterMCInstrInfo {
834 RegisterMCInstrInfo(Target &T) {
835 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
838 static MCInstrInfo *Allocator() {
839 return new MCInstrInfoImpl();
843 /// RegisterMCInstrInfoFn - Helper template for registering a target
844 /// instruction info implementation. This invokes the specified function to
845 /// do the construction. Usage:
847 /// extern "C" void LLVMInitializeFooTarget() {
848 /// extern Target TheFooTarget;
849 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
851 struct RegisterMCInstrInfoFn {
852 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
853 TargetRegistry::RegisterMCInstrInfo(T, Fn);
857 /// RegisterMCRegInfo - Helper template for registering a target register info
858 /// implementation. This invokes the static "Create" method on the class to
859 /// actually do the construction. Usage:
861 /// extern "C" void LLVMInitializeFooTarget() {
862 /// extern Target TheFooTarget;
863 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
865 template<class MCRegisterInfoImpl>
866 struct RegisterMCRegInfo {
867 RegisterMCRegInfo(Target &T) {
868 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
871 static MCRegisterInfo *Allocator(StringRef TT) {
872 return new MCRegisterInfoImpl();
876 /// RegisterMCRegInfoFn - Helper template for registering a target register
877 /// info implementation. This invokes the specified function to do the
878 /// construction. Usage:
880 /// extern "C" void LLVMInitializeFooTarget() {
881 /// extern Target TheFooTarget;
882 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
884 struct RegisterMCRegInfoFn {
885 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
886 TargetRegistry::RegisterMCRegInfo(T, Fn);
890 /// RegisterMCSubtargetInfo - Helper template for registering a target
891 /// subtarget info implementation. This invokes the static "Create" method
892 /// on the class to actually do the construction. Usage:
894 /// extern "C" void LLVMInitializeFooTarget() {
895 /// extern Target TheFooTarget;
896 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
898 template<class MCSubtargetInfoImpl>
899 struct RegisterMCSubtargetInfo {
900 RegisterMCSubtargetInfo(Target &T) {
901 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
904 static MCSubtargetInfo *Allocator(StringRef TT, StringRef CPU,
906 return new MCSubtargetInfoImpl();
910 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
911 /// subtarget info implementation. This invokes the specified function to
912 /// do the construction. Usage:
914 /// extern "C" void LLVMInitializeFooTarget() {
915 /// extern Target TheFooTarget;
916 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
918 struct RegisterMCSubtargetInfoFn {
919 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
920 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
924 /// RegisterTargetMachine - Helper template for registering a target machine
925 /// implementation, for use in the target machine initialization
928 /// extern "C" void LLVMInitializeFooTarget() {
929 /// extern Target TheFooTarget;
930 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
932 template<class TargetMachineImpl>
933 struct RegisterTargetMachine {
934 RegisterTargetMachine(Target &T) {
935 TargetRegistry::RegisterTargetMachine(T, &Allocator);
939 static TargetMachine *Allocator(const Target &T, StringRef TT,
940 StringRef CPU, StringRef FS,
942 return new TargetMachineImpl(T, TT, CPU, FS, RM);
946 /// RegisterAsmBackend - Helper template for registering a target specific
947 /// assembler backend. Usage:
949 /// extern "C" void LLVMInitializeFooAsmBackend() {
950 /// extern Target TheFooTarget;
951 /// RegisterAsmBackend<FooAsmLexer> X(TheFooTarget);
953 template<class AsmBackendImpl>
954 struct RegisterAsmBackend {
955 RegisterAsmBackend(Target &T) {
956 TargetRegistry::RegisterAsmBackend(T, &Allocator);
960 static TargetAsmBackend *Allocator(const Target &T,
961 const std::string &Triple) {
962 return new AsmBackendImpl(T, Triple);
966 /// RegisterAsmLexer - Helper template for registering a target specific
967 /// assembly lexer, for use in the target machine initialization
970 /// extern "C" void LLVMInitializeFooAsmLexer() {
971 /// extern Target TheFooTarget;
972 /// RegisterAsmLexer<FooAsmLexer> X(TheFooTarget);
974 template<class AsmLexerImpl>
975 struct RegisterAsmLexer {
976 RegisterAsmLexer(Target &T) {
977 TargetRegistry::RegisterAsmLexer(T, &Allocator);
981 static TargetAsmLexer *Allocator(const Target &T, const MCAsmInfo &MAI) {
982 return new AsmLexerImpl(T, MAI);
986 /// RegisterAsmParser - Helper template for registering a target specific
987 /// assembly parser, for use in the target machine initialization
990 /// extern "C" void LLVMInitializeFooAsmParser() {
991 /// extern Target TheFooTarget;
992 /// RegisterAsmParser<FooAsmParser> X(TheFooTarget);
994 template<class AsmParserImpl>
995 struct RegisterAsmParser {
996 RegisterAsmParser(Target &T) {
997 TargetRegistry::RegisterAsmParser(T, &Allocator);
1001 static TargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P) {
1002 return new AsmParserImpl(STI, P);
1006 /// RegisterAsmPrinter - Helper template for registering a target specific
1007 /// assembly printer, for use in the target machine initialization
1008 /// function. Usage:
1010 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1011 /// extern Target TheFooTarget;
1012 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1014 template<class AsmPrinterImpl>
1015 struct RegisterAsmPrinter {
1016 RegisterAsmPrinter(Target &T) {
1017 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1021 static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) {
1022 return new AsmPrinterImpl(TM, Streamer);
1026 /// RegisterCodeEmitter - Helper template for registering a target specific
1027 /// machine code emitter, for use in the target initialization
1028 /// function. Usage:
1030 /// extern "C" void LLVMInitializeFooCodeEmitter() {
1031 /// extern Target TheFooTarget;
1032 /// RegisterCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1034 template<class CodeEmitterImpl>
1035 struct RegisterCodeEmitter {
1036 RegisterCodeEmitter(Target &T) {
1037 TargetRegistry::RegisterCodeEmitter(T, &Allocator);
1041 static MCCodeEmitter *Allocator(const MCInstrInfo &II,
1042 const MCSubtargetInfo &STI,
1044 return new CodeEmitterImpl();