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,
76 typedef MCInstrInfo *(*MCInstrInfoCtorFnTy)(void);
77 typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(StringRef TT);
78 typedef MCSubtargetInfo *(*MCSubtargetInfoCtorFnTy)(StringRef TT,
81 typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T,
87 typedef AsmPrinter *(*AsmPrinterCtorTy)(TargetMachine &TM,
88 MCStreamer &Streamer);
89 typedef TargetAsmBackend *(*AsmBackendCtorTy)(const Target &T,
90 const std::string &TT);
91 typedef TargetAsmLexer *(*AsmLexerCtorTy)(const Target &T,
92 const MCAsmInfo &MAI);
93 typedef TargetAsmParser *(*AsmParserCtorTy)(MCSubtargetInfo &STI,
95 typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T);
96 typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
97 unsigned SyntaxVariant,
98 const MCAsmInfo &MAI);
99 typedef MCCodeEmitter *(*CodeEmitterCtorTy)(const MCInstrInfo &II,
100 const MCSubtargetInfo &STI,
102 typedef MCStreamer *(*ObjectStreamerCtorTy)(const Target &T,
103 const std::string &TT,
105 TargetAsmBackend &TAB,
107 MCCodeEmitter *_Emitter,
110 typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx,
111 formatted_raw_ostream &OS,
115 MCInstPrinter *InstPrint,
117 TargetAsmBackend *TAB,
121 /// Next - The next registered target in the linked list, maintained by the
125 /// TripleMatchQualityFn - The target function for rating the match quality
127 TripleMatchQualityFnTy TripleMatchQualityFn;
129 /// Name - The target name.
132 /// ShortDesc - A short description of the target.
133 const char *ShortDesc;
135 /// HasJIT - Whether this target supports the JIT.
138 /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
140 MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
142 /// MCCodeGenInfoCtorFn - Constructor function for this target's MCCodeGenInfo,
144 MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn;
146 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
148 MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
150 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
152 MCRegInfoCtorFnTy MCRegInfoCtorFn;
154 /// MCSubtargetInfoCtorFn - Constructor function for this target's
155 /// MCSubtargetInfo, if registered.
156 MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
158 /// TargetMachineCtorFn - Construction function for this target's
159 /// TargetMachine, if registered.
160 TargetMachineCtorTy TargetMachineCtorFn;
162 /// AsmBackendCtorFn - Construction function for this target's
163 /// TargetAsmBackend, if registered.
164 AsmBackendCtorTy AsmBackendCtorFn;
166 /// AsmLexerCtorFn - Construction function for this target's TargetAsmLexer,
168 AsmLexerCtorTy AsmLexerCtorFn;
170 /// AsmParserCtorFn - Construction function for this target's
171 /// TargetAsmParser, if registered.
172 AsmParserCtorTy AsmParserCtorFn;
174 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
176 AsmPrinterCtorTy AsmPrinterCtorFn;
178 /// MCDisassemblerCtorFn - Construction function for this target's
179 /// MCDisassembler, if registered.
180 MCDisassemblerCtorTy MCDisassemblerCtorFn;
182 /// MCInstPrinterCtorFn - Construction function for this target's
183 /// MCInstPrinter, if registered.
184 MCInstPrinterCtorTy MCInstPrinterCtorFn;
186 /// CodeEmitterCtorFn - Construction function for this target's CodeEmitter,
188 CodeEmitterCtorTy CodeEmitterCtorFn;
190 /// ObjectStreamerCtorFn - Construction function for this target's
191 /// ObjectStreamer, if registered.
192 ObjectStreamerCtorTy ObjectStreamerCtorFn;
194 /// AsmStreamerCtorFn - Construction function for this target's
195 /// AsmStreamer, if registered (default = llvm::createAsmStreamer).
196 AsmStreamerCtorTy AsmStreamerCtorFn;
199 Target() : AsmStreamerCtorFn(llvm::createAsmStreamer) {}
201 /// @name Target Information
204 // getNext - Return the next registered target.
205 const Target *getNext() const { return Next; }
207 /// getName - Get the target name.
208 const char *getName() const { return Name; }
210 /// getShortDescription - Get a short description of the target.
211 const char *getShortDescription() const { return ShortDesc; }
214 /// @name Feature Predicates
217 /// hasJIT - Check if this targets supports the just-in-time compilation.
218 bool hasJIT() const { return HasJIT; }
220 /// hasTargetMachine - Check if this target supports code generation.
221 bool hasTargetMachine() const { return TargetMachineCtorFn != 0; }
223 /// hasAsmBackend - Check if this target supports .o generation.
224 bool hasAsmBackend() const { return AsmBackendCtorFn != 0; }
226 /// hasAsmLexer - Check if this target supports .s lexing.
227 bool hasAsmLexer() const { return AsmLexerCtorFn != 0; }
229 /// hasAsmParser - Check if this target supports .s parsing.
230 bool hasAsmParser() const { return AsmParserCtorFn != 0; }
232 /// hasAsmPrinter - Check if this target supports .s printing.
233 bool hasAsmPrinter() const { return AsmPrinterCtorFn != 0; }
235 /// hasMCDisassembler - Check if this target has a disassembler.
236 bool hasMCDisassembler() const { return MCDisassemblerCtorFn != 0; }
238 /// hasMCInstPrinter - Check if this target has an instruction printer.
239 bool hasMCInstPrinter() const { return MCInstPrinterCtorFn != 0; }
241 /// hasCodeEmitter - Check if this target supports instruction encoding.
242 bool hasCodeEmitter() const { return CodeEmitterCtorFn != 0; }
244 /// hasObjectStreamer - Check if this target supports streaming to files.
245 bool hasObjectStreamer() const { return ObjectStreamerCtorFn != 0; }
247 /// hasAsmStreamer - Check if this target supports streaming to files.
248 bool hasAsmStreamer() const { return AsmStreamerCtorFn != 0; }
251 /// @name Feature Constructors
254 /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
257 /// \arg Triple - This argument is used to determine the target machine
258 /// feature set; it should always be provided. Generally this should be
259 /// either the target triple from the module, or the target triple of the
260 /// host if that does not exist.
261 MCAsmInfo *createMCAsmInfo(StringRef Triple) const {
262 if (!MCAsmInfoCtorFn)
264 return MCAsmInfoCtorFn(*this, Triple);
267 /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
269 MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model RM,
270 CodeModel::Model CM) const {
271 if (!MCCodeGenInfoCtorFn)
273 return MCCodeGenInfoCtorFn(Triple, RM, CM);
276 /// createMCInstrInfo - Create a MCInstrInfo implementation.
278 MCInstrInfo *createMCInstrInfo() const {
279 if (!MCInstrInfoCtorFn)
281 return MCInstrInfoCtorFn();
284 /// createMCRegInfo - Create a MCRegisterInfo implementation.
286 MCRegisterInfo *createMCRegInfo(StringRef Triple) const {
287 if (!MCRegInfoCtorFn)
289 return MCRegInfoCtorFn(Triple);
292 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
294 /// \arg Triple - This argument is used to determine the target machine
295 /// feature set; it should always be provided. Generally this should be
296 /// either the target triple from the module, or the target triple of the
297 /// host if that does not exist.
298 /// \arg CPU - This specifies the name of the target CPU.
299 /// \arg Features - This specifies the string representation of the
300 /// additional target features.
301 MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU,
302 StringRef Features) const {
303 if (!MCSubtargetInfoCtorFn)
305 return MCSubtargetInfoCtorFn(Triple, CPU, Features);
308 /// createTargetMachine - Create a target specific machine implementation
309 /// for the specified \arg Triple.
311 /// \arg Triple - This argument is used to determine the target machine
312 /// feature set; it should always be provided. Generally this should be
313 /// either the target triple from the module, or the target triple of the
314 /// host if that does not exist.
315 TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU,
317 Reloc::Model RM = Reloc::Default,
318 CodeModel::Model CM = CodeModel::Default) const {
319 if (!TargetMachineCtorFn)
321 return TargetMachineCtorFn(*this, Triple, CPU, Features, RM, CM);
324 /// createAsmBackend - Create a target specific assembly parser.
326 /// \arg Triple - The target triple string.
327 /// \arg Backend - The target independent assembler object.
328 TargetAsmBackend *createAsmBackend(const std::string &Triple) const {
329 if (!AsmBackendCtorFn)
331 return AsmBackendCtorFn(*this, Triple);
334 /// createAsmLexer - Create a target specific assembly lexer.
336 TargetAsmLexer *createAsmLexer(const MCAsmInfo &MAI) const {
339 return AsmLexerCtorFn(*this, MAI);
342 /// createAsmParser - Create a target specific assembly parser.
344 /// \arg Parser - The target independent parser implementation to use for
345 /// parsing and lexing.
346 TargetAsmParser *createAsmParser(MCSubtargetInfo &STI,
347 MCAsmParser &Parser) const {
348 if (!AsmParserCtorFn)
350 return AsmParserCtorFn(STI, Parser);
353 /// createAsmPrinter - Create a target specific assembly printer pass. This
354 /// takes ownership of the MCStreamer object.
355 AsmPrinter *createAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) const{
356 if (!AsmPrinterCtorFn)
358 return AsmPrinterCtorFn(TM, Streamer);
361 MCDisassembler *createMCDisassembler() const {
362 if (!MCDisassemblerCtorFn)
364 return MCDisassemblerCtorFn(*this);
367 MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
368 const MCAsmInfo &MAI) const {
369 if (!MCInstPrinterCtorFn)
371 return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI);
375 /// createCodeEmitter - Create a target specific code emitter.
376 MCCodeEmitter *createCodeEmitter(const MCInstrInfo &II,
377 const MCSubtargetInfo &STI,
378 MCContext &Ctx) const {
379 if (!CodeEmitterCtorFn)
381 return CodeEmitterCtorFn(II, STI, Ctx);
384 /// createObjectStreamer - Create a target specific MCStreamer.
386 /// \arg TT - The target triple.
387 /// \arg Ctx - The target context.
388 /// \arg TAB - The target assembler backend object. Takes ownership.
389 /// \arg _OS - The stream object.
390 /// \arg _Emitter - The target independent assembler object.Takes ownership.
391 /// \arg RelaxAll - Relax all fixups?
392 /// \arg NoExecStack - Mark file as not needing a executable stack.
393 MCStreamer *createObjectStreamer(const std::string &TT, MCContext &Ctx,
394 TargetAsmBackend &TAB,
396 MCCodeEmitter *_Emitter,
398 bool NoExecStack) const {
399 if (!ObjectStreamerCtorFn)
401 return ObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter, RelaxAll,
405 /// createAsmStreamer - Create a target specific MCStreamer.
406 MCStreamer *createAsmStreamer(MCContext &Ctx,
407 formatted_raw_ostream &OS,
411 MCInstPrinter *InstPrint,
413 TargetAsmBackend *TAB,
414 bool ShowInst) const {
415 // AsmStreamerCtorFn is default to llvm::createAsmStreamer
416 return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useLoc, useCFI,
417 InstPrint, CE, TAB, ShowInst);
423 /// TargetRegistry - Generic interface to target specific features.
424 struct TargetRegistry {
426 const Target *Current;
427 explicit iterator(Target *T) : Current(T) {}
428 friend struct TargetRegistry;
430 iterator(const iterator &I) : Current(I.Current) {}
431 iterator() : Current(0) {}
433 bool operator==(const iterator &x) const {
434 return Current == x.Current;
436 bool operator!=(const iterator &x) const {
437 return !operator==(x);
440 // Iterator traversal: forward iteration only
441 iterator &operator++() { // Preincrement
442 assert(Current && "Cannot increment end iterator!");
443 Current = Current->getNext();
446 iterator operator++(int) { // Postincrement
447 iterator tmp = *this;
452 const Target &operator*() const {
453 assert(Current && "Cannot dereference end iterator!");
457 const Target *operator->() const {
462 /// printRegisteredTargetsForVersion - Print the registered targets
463 /// appropriately for inclusion in a tool's version output.
464 static void printRegisteredTargetsForVersion();
466 /// @name Registry Access
469 static iterator begin();
471 static iterator end() { return iterator(); }
473 /// lookupTarget - Lookup a target based on a target triple.
475 /// \param Triple - The triple to use for finding a target.
476 /// \param Error - On failure, an error string describing why no target was
478 static const Target *lookupTarget(const std::string &Triple,
481 /// getClosestTargetForJIT - Pick the best target that is compatible with
482 /// the current host. If no close target can be found, this returns null
483 /// and sets the Error string to a reason.
485 /// Maintained for compatibility through 2.6.
486 static const Target *getClosestTargetForJIT(std::string &Error);
489 /// @name Target Registration
492 /// RegisterTarget - Register the given target. Attempts to register a
493 /// target which has already been registered will be ignored.
495 /// Clients are responsible for ensuring that registration doesn't occur
496 /// while another thread is attempting to access the registry. Typically
497 /// this is done by initializing all targets at program startup.
499 /// @param T - The target being registered.
500 /// @param Name - The target name. This should be a static string.
501 /// @param ShortDesc - A short target description. This should be a static
503 /// @param TQualityFn - The triple match quality computation function for
505 /// @param HasJIT - Whether the target supports JIT code
507 static void RegisterTarget(Target &T,
509 const char *ShortDesc,
510 Target::TripleMatchQualityFnTy TQualityFn,
511 bool HasJIT = false);
513 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
516 /// Clients are responsible for ensuring that registration doesn't occur
517 /// while another thread is attempting to access the registry. Typically
518 /// this is done by initializing all targets at program startup.
520 /// @param T - The target being registered.
521 /// @param Fn - A function to construct a MCAsmInfo for the target.
522 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
523 // Ignore duplicate registration.
524 if (!T.MCAsmInfoCtorFn)
525 T.MCAsmInfoCtorFn = Fn;
528 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
531 /// Clients are responsible for ensuring that registration doesn't occur
532 /// while another thread is attempting to access the registry. Typically
533 /// this is done by initializing all targets at program startup.
535 /// @param T - The target being registered.
536 /// @param Fn - A function to construct a MCCodeGenInfo for the target.
537 static void RegisterMCCodeGenInfo(Target &T,
538 Target::MCCodeGenInfoCtorFnTy Fn) {
539 // Ignore duplicate registration.
540 if (!T.MCCodeGenInfoCtorFn)
541 T.MCCodeGenInfoCtorFn = Fn;
544 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
547 /// Clients are responsible for ensuring that registration doesn't occur
548 /// while another thread is attempting to access the registry. Typically
549 /// this is done by initializing all targets at program startup.
551 /// @param T - The target being registered.
552 /// @param Fn - A function to construct a MCInstrInfo for the target.
553 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
554 // Ignore duplicate registration.
555 if (!T.MCInstrInfoCtorFn)
556 T.MCInstrInfoCtorFn = Fn;
559 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
562 /// Clients are responsible for ensuring that registration doesn't occur
563 /// while another thread is attempting to access the registry. Typically
564 /// this is done by initializing all targets at program startup.
566 /// @param T - The target being registered.
567 /// @param Fn - A function to construct a MCRegisterInfo for the target.
568 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
569 // Ignore duplicate registration.
570 if (!T.MCRegInfoCtorFn)
571 T.MCRegInfoCtorFn = Fn;
574 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
575 /// the given target.
577 /// Clients are responsible for ensuring that registration doesn't occur
578 /// while another thread is attempting to access the registry. Typically
579 /// this is done by initializing all targets at program startup.
581 /// @param T - The target being registered.
582 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
583 static void RegisterMCSubtargetInfo(Target &T,
584 Target::MCSubtargetInfoCtorFnTy Fn) {
585 // Ignore duplicate registration.
586 if (!T.MCSubtargetInfoCtorFn)
587 T.MCSubtargetInfoCtorFn = Fn;
590 /// RegisterTargetMachine - Register a TargetMachine implementation for the
593 /// Clients are responsible for ensuring that registration doesn't occur
594 /// while another thread is attempting to access the registry. Typically
595 /// this is done by initializing all targets at program startup.
597 /// @param T - The target being registered.
598 /// @param Fn - A function to construct a TargetMachine for the target.
599 static void RegisterTargetMachine(Target &T,
600 Target::TargetMachineCtorTy Fn) {
601 // Ignore duplicate registration.
602 if (!T.TargetMachineCtorFn)
603 T.TargetMachineCtorFn = Fn;
606 /// RegisterAsmBackend - Register a TargetAsmBackend implementation for the
609 /// Clients are responsible for ensuring that registration doesn't occur
610 /// while another thread is attempting to access the registry. Typically
611 /// this is done by initializing all targets at program startup.
613 /// @param T - The target being registered.
614 /// @param Fn - A function to construct an AsmBackend for the target.
615 static void RegisterAsmBackend(Target &T, Target::AsmBackendCtorTy Fn) {
616 if (!T.AsmBackendCtorFn)
617 T.AsmBackendCtorFn = Fn;
620 /// RegisterAsmLexer - Register a TargetAsmLexer implementation for the
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 AsmLexer for the target.
629 static void RegisterAsmLexer(Target &T, Target::AsmLexerCtorTy Fn) {
630 if (!T.AsmLexerCtorFn)
631 T.AsmLexerCtorFn = Fn;
634 /// RegisterAsmParser - Register a TargetAsmParser implementation for the
637 /// Clients are responsible for ensuring that registration doesn't occur
638 /// while another thread is attempting to access the registry. Typically
639 /// this is done by initializing all targets at program startup.
641 /// @param T - The target being registered.
642 /// @param Fn - A function to construct an AsmParser for the target.
643 static void RegisterAsmParser(Target &T, Target::AsmParserCtorTy Fn) {
644 if (!T.AsmParserCtorFn)
645 T.AsmParserCtorFn = Fn;
648 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
651 /// Clients are responsible for ensuring that registration doesn't occur
652 /// while another thread is attempting to access the registry. Typically
653 /// this is done by initializing all targets at program startup.
655 /// @param T - The target being registered.
656 /// @param Fn - A function to construct an AsmPrinter for the target.
657 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
658 // Ignore duplicate registration.
659 if (!T.AsmPrinterCtorFn)
660 T.AsmPrinterCtorFn = Fn;
663 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
664 /// the given target.
666 /// Clients are responsible for ensuring that registration doesn't occur
667 /// while another thread is attempting to access the registry. Typically
668 /// this is done by initializing all targets at program startup.
670 /// @param T - The target being registered.
671 /// @param Fn - A function to construct an MCDisassembler for the target.
672 static void RegisterMCDisassembler(Target &T,
673 Target::MCDisassemblerCtorTy Fn) {
674 if (!T.MCDisassemblerCtorFn)
675 T.MCDisassemblerCtorFn = Fn;
678 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
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 MCInstPrinter for the target.
687 static void RegisterMCInstPrinter(Target &T,
688 Target::MCInstPrinterCtorTy Fn) {
689 if (!T.MCInstPrinterCtorFn)
690 T.MCInstPrinterCtorFn = Fn;
693 /// RegisterCodeEmitter - Register a MCCodeEmitter implementation for the
696 /// Clients are responsible for ensuring that registration doesn't occur
697 /// while another thread is attempting to access the registry. Typically
698 /// this is done by initializing all targets at program startup.
700 /// @param T - The target being registered.
701 /// @param Fn - A function to construct an MCCodeEmitter for the target.
702 static void RegisterCodeEmitter(Target &T, Target::CodeEmitterCtorTy Fn) {
703 if (!T.CodeEmitterCtorFn)
704 T.CodeEmitterCtorFn = Fn;
707 /// RegisterObjectStreamer - Register a object code MCStreamer implementation
708 /// for the given target.
710 /// Clients are responsible for ensuring that registration doesn't occur
711 /// while another thread is attempting to access the registry. Typically
712 /// this is done by initializing all targets at program startup.
714 /// @param T - The target being registered.
715 /// @param Fn - A function to construct an MCStreamer for the target.
716 static void RegisterObjectStreamer(Target &T, Target::ObjectStreamerCtorTy Fn) {
717 if (!T.ObjectStreamerCtorFn)
718 T.ObjectStreamerCtorFn = Fn;
721 /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
722 /// for the given target.
724 /// Clients are responsible for ensuring that registration doesn't occur
725 /// while another thread is attempting to access the registry. Typically
726 /// this is done by initializing all targets at program startup.
728 /// @param T - The target being registered.
729 /// @param Fn - A function to construct an MCStreamer for the target.
730 static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
731 if (T.AsmStreamerCtorFn == createAsmStreamer)
732 T.AsmStreamerCtorFn = Fn;
739 //===--------------------------------------------------------------------===//
741 /// RegisterTarget - Helper template for registering a target, for use in the
742 /// target's initialization function. Usage:
745 /// Target TheFooTarget; // The global target instance.
747 /// extern "C" void LLVMInitializeFooTargetInfo() {
748 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
750 template<Triple::ArchType TargetArchType = Triple::InvalidArch,
752 struct RegisterTarget {
753 RegisterTarget(Target &T, const char *Name, const char *Desc) {
754 TargetRegistry::RegisterTarget(T, Name, Desc,
755 &getTripleMatchQuality,
759 static unsigned getTripleMatchQuality(const std::string &TT) {
760 if (Triple(TT).getArch() == TargetArchType)
766 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
767 /// implementation. This invokes the static "Create" method on the class to
768 /// actually do the construction. Usage:
770 /// extern "C" void LLVMInitializeFooTarget() {
771 /// extern Target TheFooTarget;
772 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
774 template<class MCAsmInfoImpl>
775 struct RegisterMCAsmInfo {
776 RegisterMCAsmInfo(Target &T) {
777 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
780 static MCAsmInfo *Allocator(const Target &T, StringRef TT) {
781 return new MCAsmInfoImpl(T, TT);
786 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
787 /// implementation. This invokes the specified function to do the
788 /// construction. Usage:
790 /// extern "C" void LLVMInitializeFooTarget() {
791 /// extern Target TheFooTarget;
792 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
794 struct RegisterMCAsmInfoFn {
795 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
796 TargetRegistry::RegisterMCAsmInfo(T, Fn);
800 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
801 /// implementation. This invokes the static "Create" method on the class
802 /// to actually do the construction. Usage:
804 /// extern "C" void LLVMInitializeFooTarget() {
805 /// extern Target TheFooTarget;
806 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
808 template<class MCCodeGenInfoImpl>
809 struct RegisterMCCodeGenInfo {
810 RegisterMCCodeGenInfo(Target &T) {
811 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
814 static MCCodeGenInfo *Allocator(StringRef TT,
815 Reloc::Model RM, CodeModel::Model CM) {
816 return new MCCodeGenInfoImpl();
820 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
821 /// info implementation. This invokes the specified function to do the
822 /// construction. Usage:
824 /// extern "C" void LLVMInitializeFooTarget() {
825 /// extern Target TheFooTarget;
826 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
828 struct RegisterMCCodeGenInfoFn {
829 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
830 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
834 /// RegisterMCInstrInfo - Helper template for registering a target instruction
835 /// info implementation. This invokes the static "Create" method on the class
836 /// to actually do the construction. Usage:
838 /// extern "C" void LLVMInitializeFooTarget() {
839 /// extern Target TheFooTarget;
840 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
842 template<class MCInstrInfoImpl>
843 struct RegisterMCInstrInfo {
844 RegisterMCInstrInfo(Target &T) {
845 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
848 static MCInstrInfo *Allocator() {
849 return new MCInstrInfoImpl();
853 /// RegisterMCInstrInfoFn - Helper template for registering a target
854 /// instruction info implementation. This invokes the specified function to
855 /// do the construction. Usage:
857 /// extern "C" void LLVMInitializeFooTarget() {
858 /// extern Target TheFooTarget;
859 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
861 struct RegisterMCInstrInfoFn {
862 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
863 TargetRegistry::RegisterMCInstrInfo(T, Fn);
867 /// RegisterMCRegInfo - Helper template for registering a target register info
868 /// implementation. This invokes the static "Create" method on the class to
869 /// actually do the construction. Usage:
871 /// extern "C" void LLVMInitializeFooTarget() {
872 /// extern Target TheFooTarget;
873 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
875 template<class MCRegisterInfoImpl>
876 struct RegisterMCRegInfo {
877 RegisterMCRegInfo(Target &T) {
878 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
881 static MCRegisterInfo *Allocator(StringRef TT) {
882 return new MCRegisterInfoImpl();
886 /// RegisterMCRegInfoFn - Helper template for registering a target register
887 /// info implementation. This invokes the specified function to do the
888 /// construction. Usage:
890 /// extern "C" void LLVMInitializeFooTarget() {
891 /// extern Target TheFooTarget;
892 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
894 struct RegisterMCRegInfoFn {
895 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
896 TargetRegistry::RegisterMCRegInfo(T, Fn);
900 /// RegisterMCSubtargetInfo - Helper template for registering a target
901 /// subtarget info implementation. This invokes the static "Create" method
902 /// on the class to actually do the construction. Usage:
904 /// extern "C" void LLVMInitializeFooTarget() {
905 /// extern Target TheFooTarget;
906 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
908 template<class MCSubtargetInfoImpl>
909 struct RegisterMCSubtargetInfo {
910 RegisterMCSubtargetInfo(Target &T) {
911 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
914 static MCSubtargetInfo *Allocator(StringRef TT, StringRef CPU,
916 return new MCSubtargetInfoImpl();
920 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
921 /// subtarget info implementation. This invokes the specified function to
922 /// do the construction. Usage:
924 /// extern "C" void LLVMInitializeFooTarget() {
925 /// extern Target TheFooTarget;
926 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
928 struct RegisterMCSubtargetInfoFn {
929 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
930 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
934 /// RegisterTargetMachine - Helper template for registering a target machine
935 /// implementation, for use in the target machine initialization
938 /// extern "C" void LLVMInitializeFooTarget() {
939 /// extern Target TheFooTarget;
940 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
942 template<class TargetMachineImpl>
943 struct RegisterTargetMachine {
944 RegisterTargetMachine(Target &T) {
945 TargetRegistry::RegisterTargetMachine(T, &Allocator);
949 static TargetMachine *Allocator(const Target &T, StringRef TT,
950 StringRef CPU, StringRef FS,
952 CodeModel::Model CM) {
953 return new TargetMachineImpl(T, TT, CPU, FS, RM, CM);
957 /// RegisterAsmBackend - Helper template for registering a target specific
958 /// assembler backend. Usage:
960 /// extern "C" void LLVMInitializeFooAsmBackend() {
961 /// extern Target TheFooTarget;
962 /// RegisterAsmBackend<FooAsmLexer> X(TheFooTarget);
964 template<class AsmBackendImpl>
965 struct RegisterAsmBackend {
966 RegisterAsmBackend(Target &T) {
967 TargetRegistry::RegisterAsmBackend(T, &Allocator);
971 static TargetAsmBackend *Allocator(const Target &T,
972 const std::string &Triple) {
973 return new AsmBackendImpl(T, Triple);
977 /// RegisterAsmLexer - Helper template for registering a target specific
978 /// assembly lexer, for use in the target machine initialization
981 /// extern "C" void LLVMInitializeFooAsmLexer() {
982 /// extern Target TheFooTarget;
983 /// RegisterAsmLexer<FooAsmLexer> X(TheFooTarget);
985 template<class AsmLexerImpl>
986 struct RegisterAsmLexer {
987 RegisterAsmLexer(Target &T) {
988 TargetRegistry::RegisterAsmLexer(T, &Allocator);
992 static TargetAsmLexer *Allocator(const Target &T, const MCAsmInfo &MAI) {
993 return new AsmLexerImpl(T, MAI);
997 /// RegisterAsmParser - Helper template for registering a target specific
998 /// assembly parser, for use in the target machine initialization
1001 /// extern "C" void LLVMInitializeFooAsmParser() {
1002 /// extern Target TheFooTarget;
1003 /// RegisterAsmParser<FooAsmParser> X(TheFooTarget);
1005 template<class AsmParserImpl>
1006 struct RegisterAsmParser {
1007 RegisterAsmParser(Target &T) {
1008 TargetRegistry::RegisterAsmParser(T, &Allocator);
1012 static TargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P) {
1013 return new AsmParserImpl(STI, P);
1017 /// RegisterAsmPrinter - Helper template for registering a target specific
1018 /// assembly printer, for use in the target machine initialization
1019 /// function. Usage:
1021 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1022 /// extern Target TheFooTarget;
1023 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1025 template<class AsmPrinterImpl>
1026 struct RegisterAsmPrinter {
1027 RegisterAsmPrinter(Target &T) {
1028 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1032 static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) {
1033 return new AsmPrinterImpl(TM, Streamer);
1037 /// RegisterCodeEmitter - Helper template for registering a target specific
1038 /// machine code emitter, for use in the target initialization
1039 /// function. Usage:
1041 /// extern "C" void LLVMInitializeFooCodeEmitter() {
1042 /// extern Target TheFooTarget;
1043 /// RegisterCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1045 template<class CodeEmitterImpl>
1046 struct RegisterCodeEmitter {
1047 RegisterCodeEmitter(Target &T) {
1048 TargetRegistry::RegisterCodeEmitter(T, &Allocator);
1052 static MCCodeEmitter *Allocator(const MCInstrInfo &II,
1053 const MCSubtargetInfo &STI,
1055 return new CodeEmitterImpl();