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 MCRegisterInfo &MRI,
93 const MCAsmInfo &MAI);
94 typedef TargetAsmParser *(*AsmParserCtorTy)(MCSubtargetInfo &STI,
96 typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T);
97 typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
98 unsigned SyntaxVariant,
99 const MCAsmInfo &MAI);
100 typedef MCCodeEmitter *(*CodeEmitterCtorTy)(const MCInstrInfo &II,
101 const MCSubtargetInfo &STI,
103 typedef MCStreamer *(*ObjectStreamerCtorTy)(const Target &T,
104 const std::string &TT,
106 TargetAsmBackend &TAB,
108 MCCodeEmitter *_Emitter,
111 typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx,
112 formatted_raw_ostream &OS,
116 MCInstPrinter *InstPrint,
118 TargetAsmBackend *TAB,
122 /// Next - The next registered target in the linked list, maintained by the
126 /// TripleMatchQualityFn - The target function for rating the match quality
128 TripleMatchQualityFnTy TripleMatchQualityFn;
130 /// Name - The target name.
133 /// ShortDesc - A short description of the target.
134 const char *ShortDesc;
136 /// HasJIT - Whether this target supports the JIT.
139 /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
141 MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
143 /// MCCodeGenInfoCtorFn - Constructor function for this target's MCCodeGenInfo,
145 MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn;
147 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
149 MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
151 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
153 MCRegInfoCtorFnTy MCRegInfoCtorFn;
155 /// MCSubtargetInfoCtorFn - Constructor function for this target's
156 /// MCSubtargetInfo, if registered.
157 MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
159 /// TargetMachineCtorFn - Construction function for this target's
160 /// TargetMachine, if registered.
161 TargetMachineCtorTy TargetMachineCtorFn;
163 /// AsmBackendCtorFn - Construction function for this target's
164 /// TargetAsmBackend, if registered.
165 AsmBackendCtorTy AsmBackendCtorFn;
167 /// AsmLexerCtorFn - Construction function for this target's TargetAsmLexer,
169 AsmLexerCtorTy AsmLexerCtorFn;
171 /// AsmParserCtorFn - Construction function for this target's
172 /// TargetAsmParser, if registered.
173 AsmParserCtorTy AsmParserCtorFn;
175 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
177 AsmPrinterCtorTy AsmPrinterCtorFn;
179 /// MCDisassemblerCtorFn - Construction function for this target's
180 /// MCDisassembler, if registered.
181 MCDisassemblerCtorTy MCDisassemblerCtorFn;
183 /// MCInstPrinterCtorFn - Construction function for this target's
184 /// MCInstPrinter, if registered.
185 MCInstPrinterCtorTy MCInstPrinterCtorFn;
187 /// CodeEmitterCtorFn - Construction function for this target's CodeEmitter,
189 CodeEmitterCtorTy CodeEmitterCtorFn;
191 /// ObjectStreamerCtorFn - Construction function for this target's
192 /// ObjectStreamer, if registered.
193 ObjectStreamerCtorTy ObjectStreamerCtorFn;
195 /// AsmStreamerCtorFn - Construction function for this target's
196 /// AsmStreamer, if registered (default = llvm::createAsmStreamer).
197 AsmStreamerCtorTy AsmStreamerCtorFn;
200 Target() : AsmStreamerCtorFn(llvm::createAsmStreamer) {}
202 /// @name Target Information
205 // getNext - Return the next registered target.
206 const Target *getNext() const { return Next; }
208 /// getName - Get the target name.
209 const char *getName() const { return Name; }
211 /// getShortDescription - Get a short description of the target.
212 const char *getShortDescription() const { return ShortDesc; }
215 /// @name Feature Predicates
218 /// hasJIT - Check if this targets supports the just-in-time compilation.
219 bool hasJIT() const { return HasJIT; }
221 /// hasTargetMachine - Check if this target supports code generation.
222 bool hasTargetMachine() const { return TargetMachineCtorFn != 0; }
224 /// hasAsmBackend - Check if this target supports .o generation.
225 bool hasAsmBackend() const { return AsmBackendCtorFn != 0; }
227 /// hasAsmLexer - Check if this target supports .s lexing.
228 bool hasAsmLexer() const { return AsmLexerCtorFn != 0; }
230 /// hasAsmParser - Check if this target supports .s parsing.
231 bool hasAsmParser() const { return AsmParserCtorFn != 0; }
233 /// hasAsmPrinter - Check if this target supports .s printing.
234 bool hasAsmPrinter() const { return AsmPrinterCtorFn != 0; }
236 /// hasMCDisassembler - Check if this target has a disassembler.
237 bool hasMCDisassembler() const { return MCDisassemblerCtorFn != 0; }
239 /// hasMCInstPrinter - Check if this target has an instruction printer.
240 bool hasMCInstPrinter() const { return MCInstPrinterCtorFn != 0; }
242 /// hasCodeEmitter - Check if this target supports instruction encoding.
243 bool hasCodeEmitter() const { return CodeEmitterCtorFn != 0; }
245 /// hasObjectStreamer - Check if this target supports streaming to files.
246 bool hasObjectStreamer() const { return ObjectStreamerCtorFn != 0; }
248 /// hasAsmStreamer - Check if this target supports streaming to files.
249 bool hasAsmStreamer() const { return AsmStreamerCtorFn != 0; }
252 /// @name Feature Constructors
255 /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
258 /// \arg Triple - This argument is used to determine the target machine
259 /// feature set; it should always be provided. Generally this should be
260 /// either the target triple from the module, or the target triple of the
261 /// host if that does not exist.
262 MCAsmInfo *createMCAsmInfo(StringRef Triple) const {
263 if (!MCAsmInfoCtorFn)
265 return MCAsmInfoCtorFn(*this, Triple);
268 /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
270 MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model RM,
271 CodeModel::Model CM) const {
272 if (!MCCodeGenInfoCtorFn)
274 return MCCodeGenInfoCtorFn(Triple, RM, CM);
277 /// createMCInstrInfo - Create a MCInstrInfo implementation.
279 MCInstrInfo *createMCInstrInfo() const {
280 if (!MCInstrInfoCtorFn)
282 return MCInstrInfoCtorFn();
285 /// createMCRegInfo - Create a MCRegisterInfo implementation.
287 MCRegisterInfo *createMCRegInfo(StringRef Triple) const {
288 if (!MCRegInfoCtorFn)
290 return MCRegInfoCtorFn(Triple);
293 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
295 /// \arg Triple - This argument is used to determine the target machine
296 /// feature set; it should always be provided. Generally this should be
297 /// either the target triple from the module, or the target triple of the
298 /// host if that does not exist.
299 /// \arg CPU - This specifies the name of the target CPU.
300 /// \arg Features - This specifies the string representation of the
301 /// additional target features.
302 MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU,
303 StringRef Features) const {
304 if (!MCSubtargetInfoCtorFn)
306 return MCSubtargetInfoCtorFn(Triple, CPU, Features);
309 /// createTargetMachine - Create a target specific machine implementation
310 /// for the specified \arg Triple.
312 /// \arg Triple - This argument is used to determine the target machine
313 /// feature set; it should always be provided. Generally this should be
314 /// either the target triple from the module, or the target triple of the
315 /// host if that does not exist.
316 TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU,
318 Reloc::Model RM = Reloc::Default,
319 CodeModel::Model CM = CodeModel::Default) const {
320 if (!TargetMachineCtorFn)
322 return TargetMachineCtorFn(*this, Triple, CPU, Features, RM, CM);
325 /// createAsmBackend - Create a target specific assembly parser.
327 /// \arg Triple - The target triple string.
328 /// \arg Backend - The target independent assembler object.
329 TargetAsmBackend *createAsmBackend(const std::string &Triple) const {
330 if (!AsmBackendCtorFn)
332 return AsmBackendCtorFn(*this, Triple);
335 /// createAsmLexer - Create a target specific assembly lexer.
337 TargetAsmLexer *createAsmLexer(const MCRegisterInfo &MRI,
338 const MCAsmInfo &MAI) const {
341 return AsmLexerCtorFn(*this, MRI, MAI);
344 /// createAsmParser - Create a target specific assembly parser.
346 /// \arg Parser - The target independent parser implementation to use for
347 /// parsing and lexing.
348 TargetAsmParser *createAsmParser(MCSubtargetInfo &STI,
349 MCAsmParser &Parser) const {
350 if (!AsmParserCtorFn)
352 return AsmParserCtorFn(STI, Parser);
355 /// createAsmPrinter - Create a target specific assembly printer pass. This
356 /// takes ownership of the MCStreamer object.
357 AsmPrinter *createAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) const{
358 if (!AsmPrinterCtorFn)
360 return AsmPrinterCtorFn(TM, Streamer);
363 MCDisassembler *createMCDisassembler() const {
364 if (!MCDisassemblerCtorFn)
366 return MCDisassemblerCtorFn(*this);
369 MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
370 const MCAsmInfo &MAI) const {
371 if (!MCInstPrinterCtorFn)
373 return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI);
377 /// createCodeEmitter - Create a target specific code emitter.
378 MCCodeEmitter *createCodeEmitter(const MCInstrInfo &II,
379 const MCSubtargetInfo &STI,
380 MCContext &Ctx) const {
381 if (!CodeEmitterCtorFn)
383 return CodeEmitterCtorFn(II, STI, Ctx);
386 /// createObjectStreamer - Create a target specific MCStreamer.
388 /// \arg TT - The target triple.
389 /// \arg Ctx - The target context.
390 /// \arg TAB - The target assembler backend object. Takes ownership.
391 /// \arg _OS - The stream object.
392 /// \arg _Emitter - The target independent assembler object.Takes ownership.
393 /// \arg RelaxAll - Relax all fixups?
394 /// \arg NoExecStack - Mark file as not needing a executable stack.
395 MCStreamer *createObjectStreamer(const std::string &TT, MCContext &Ctx,
396 TargetAsmBackend &TAB,
398 MCCodeEmitter *_Emitter,
400 bool NoExecStack) const {
401 if (!ObjectStreamerCtorFn)
403 return ObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter, RelaxAll,
407 /// createAsmStreamer - Create a target specific MCStreamer.
408 MCStreamer *createAsmStreamer(MCContext &Ctx,
409 formatted_raw_ostream &OS,
413 MCInstPrinter *InstPrint,
415 TargetAsmBackend *TAB,
416 bool ShowInst) const {
417 // AsmStreamerCtorFn is default to llvm::createAsmStreamer
418 return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useLoc, useCFI,
419 InstPrint, CE, TAB, ShowInst);
425 /// TargetRegistry - Generic interface to target specific features.
426 struct TargetRegistry {
428 const Target *Current;
429 explicit iterator(Target *T) : Current(T) {}
430 friend struct TargetRegistry;
432 iterator(const iterator &I) : Current(I.Current) {}
433 iterator() : Current(0) {}
435 bool operator==(const iterator &x) const {
436 return Current == x.Current;
438 bool operator!=(const iterator &x) const {
439 return !operator==(x);
442 // Iterator traversal: forward iteration only
443 iterator &operator++() { // Preincrement
444 assert(Current && "Cannot increment end iterator!");
445 Current = Current->getNext();
448 iterator operator++(int) { // Postincrement
449 iterator tmp = *this;
454 const Target &operator*() const {
455 assert(Current && "Cannot dereference end iterator!");
459 const Target *operator->() const {
464 /// printRegisteredTargetsForVersion - Print the registered targets
465 /// appropriately for inclusion in a tool's version output.
466 static void printRegisteredTargetsForVersion();
468 /// @name Registry Access
471 static iterator begin();
473 static iterator end() { return iterator(); }
475 /// lookupTarget - Lookup a target based on a target triple.
477 /// \param Triple - The triple to use for finding a target.
478 /// \param Error - On failure, an error string describing why no target was
480 static const Target *lookupTarget(const std::string &Triple,
483 /// getClosestTargetForJIT - Pick the best target that is compatible with
484 /// the current host. If no close target can be found, this returns null
485 /// and sets the Error string to a reason.
487 /// Maintained for compatibility through 2.6.
488 static const Target *getClosestTargetForJIT(std::string &Error);
491 /// @name Target Registration
494 /// RegisterTarget - Register the given target. Attempts to register a
495 /// target which has already been registered will be ignored.
497 /// Clients are responsible for ensuring that registration doesn't occur
498 /// while another thread is attempting to access the registry. Typically
499 /// this is done by initializing all targets at program startup.
501 /// @param T - The target being registered.
502 /// @param Name - The target name. This should be a static string.
503 /// @param ShortDesc - A short target description. This should be a static
505 /// @param TQualityFn - The triple match quality computation function for
507 /// @param HasJIT - Whether the target supports JIT code
509 static void RegisterTarget(Target &T,
511 const char *ShortDesc,
512 Target::TripleMatchQualityFnTy TQualityFn,
513 bool HasJIT = false);
515 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
518 /// Clients are responsible for ensuring that registration doesn't occur
519 /// while another thread is attempting to access the registry. Typically
520 /// this is done by initializing all targets at program startup.
522 /// @param T - The target being registered.
523 /// @param Fn - A function to construct a MCAsmInfo for the target.
524 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
525 // Ignore duplicate registration.
526 if (!T.MCAsmInfoCtorFn)
527 T.MCAsmInfoCtorFn = Fn;
530 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
533 /// Clients are responsible for ensuring that registration doesn't occur
534 /// while another thread is attempting to access the registry. Typically
535 /// this is done by initializing all targets at program startup.
537 /// @param T - The target being registered.
538 /// @param Fn - A function to construct a MCCodeGenInfo for the target.
539 static void RegisterMCCodeGenInfo(Target &T,
540 Target::MCCodeGenInfoCtorFnTy Fn) {
541 // Ignore duplicate registration.
542 if (!T.MCCodeGenInfoCtorFn)
543 T.MCCodeGenInfoCtorFn = Fn;
546 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
549 /// Clients are responsible for ensuring that registration doesn't occur
550 /// while another thread is attempting to access the registry. Typically
551 /// this is done by initializing all targets at program startup.
553 /// @param T - The target being registered.
554 /// @param Fn - A function to construct a MCInstrInfo for the target.
555 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
556 // Ignore duplicate registration.
557 if (!T.MCInstrInfoCtorFn)
558 T.MCInstrInfoCtorFn = Fn;
561 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
564 /// Clients are responsible for ensuring that registration doesn't occur
565 /// while another thread is attempting to access the registry. Typically
566 /// this is done by initializing all targets at program startup.
568 /// @param T - The target being registered.
569 /// @param Fn - A function to construct a MCRegisterInfo for the target.
570 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
571 // Ignore duplicate registration.
572 if (!T.MCRegInfoCtorFn)
573 T.MCRegInfoCtorFn = Fn;
576 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
577 /// the given target.
579 /// Clients are responsible for ensuring that registration doesn't occur
580 /// while another thread is attempting to access the registry. Typically
581 /// this is done by initializing all targets at program startup.
583 /// @param T - The target being registered.
584 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
585 static void RegisterMCSubtargetInfo(Target &T,
586 Target::MCSubtargetInfoCtorFnTy Fn) {
587 // Ignore duplicate registration.
588 if (!T.MCSubtargetInfoCtorFn)
589 T.MCSubtargetInfoCtorFn = Fn;
592 /// RegisterTargetMachine - Register a TargetMachine implementation for the
595 /// Clients are responsible for ensuring that registration doesn't occur
596 /// while another thread is attempting to access the registry. Typically
597 /// this is done by initializing all targets at program startup.
599 /// @param T - The target being registered.
600 /// @param Fn - A function to construct a TargetMachine for the target.
601 static void RegisterTargetMachine(Target &T,
602 Target::TargetMachineCtorTy Fn) {
603 // Ignore duplicate registration.
604 if (!T.TargetMachineCtorFn)
605 T.TargetMachineCtorFn = Fn;
608 /// RegisterAsmBackend - Register a TargetAsmBackend implementation for the
611 /// Clients are responsible for ensuring that registration doesn't occur
612 /// while another thread is attempting to access the registry. Typically
613 /// this is done by initializing all targets at program startup.
615 /// @param T - The target being registered.
616 /// @param Fn - A function to construct an AsmBackend for the target.
617 static void RegisterAsmBackend(Target &T, Target::AsmBackendCtorTy Fn) {
618 if (!T.AsmBackendCtorFn)
619 T.AsmBackendCtorFn = Fn;
622 /// RegisterAsmLexer - Register a TargetAsmLexer implementation for the
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 AsmLexer for the target.
631 static void RegisterAsmLexer(Target &T, Target::AsmLexerCtorTy Fn) {
632 if (!T.AsmLexerCtorFn)
633 T.AsmLexerCtorFn = Fn;
636 /// RegisterAsmParser - Register a TargetAsmParser implementation for the
639 /// Clients are responsible for ensuring that registration doesn't occur
640 /// while another thread is attempting to access the registry. Typically
641 /// this is done by initializing all targets at program startup.
643 /// @param T - The target being registered.
644 /// @param Fn - A function to construct an AsmParser for the target.
645 static void RegisterAsmParser(Target &T, Target::AsmParserCtorTy Fn) {
646 if (!T.AsmParserCtorFn)
647 T.AsmParserCtorFn = Fn;
650 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
653 /// Clients are responsible for ensuring that registration doesn't occur
654 /// while another thread is attempting to access the registry. Typically
655 /// this is done by initializing all targets at program startup.
657 /// @param T - The target being registered.
658 /// @param Fn - A function to construct an AsmPrinter for the target.
659 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
660 // Ignore duplicate registration.
661 if (!T.AsmPrinterCtorFn)
662 T.AsmPrinterCtorFn = Fn;
665 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
666 /// the given target.
668 /// Clients are responsible for ensuring that registration doesn't occur
669 /// while another thread is attempting to access the registry. Typically
670 /// this is done by initializing all targets at program startup.
672 /// @param T - The target being registered.
673 /// @param Fn - A function to construct an MCDisassembler for the target.
674 static void RegisterMCDisassembler(Target &T,
675 Target::MCDisassemblerCtorTy Fn) {
676 if (!T.MCDisassemblerCtorFn)
677 T.MCDisassemblerCtorFn = Fn;
680 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
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 MCInstPrinter for the target.
689 static void RegisterMCInstPrinter(Target &T,
690 Target::MCInstPrinterCtorTy Fn) {
691 if (!T.MCInstPrinterCtorFn)
692 T.MCInstPrinterCtorFn = Fn;
695 /// RegisterCodeEmitter - Register a MCCodeEmitter implementation for the
698 /// Clients are responsible for ensuring that registration doesn't occur
699 /// while another thread is attempting to access the registry. Typically
700 /// this is done by initializing all targets at program startup.
702 /// @param T - The target being registered.
703 /// @param Fn - A function to construct an MCCodeEmitter for the target.
704 static void RegisterCodeEmitter(Target &T, Target::CodeEmitterCtorTy Fn) {
705 if (!T.CodeEmitterCtorFn)
706 T.CodeEmitterCtorFn = Fn;
709 /// RegisterObjectStreamer - Register a object code MCStreamer implementation
710 /// for the given target.
712 /// Clients are responsible for ensuring that registration doesn't occur
713 /// while another thread is attempting to access the registry. Typically
714 /// this is done by initializing all targets at program startup.
716 /// @param T - The target being registered.
717 /// @param Fn - A function to construct an MCStreamer for the target.
718 static void RegisterObjectStreamer(Target &T, Target::ObjectStreamerCtorTy Fn) {
719 if (!T.ObjectStreamerCtorFn)
720 T.ObjectStreamerCtorFn = Fn;
723 /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
724 /// for the given target.
726 /// Clients are responsible for ensuring that registration doesn't occur
727 /// while another thread is attempting to access the registry. Typically
728 /// this is done by initializing all targets at program startup.
730 /// @param T - The target being registered.
731 /// @param Fn - A function to construct an MCStreamer for the target.
732 static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
733 if (T.AsmStreamerCtorFn == createAsmStreamer)
734 T.AsmStreamerCtorFn = Fn;
741 //===--------------------------------------------------------------------===//
743 /// RegisterTarget - Helper template for registering a target, for use in the
744 /// target's initialization function. Usage:
747 /// Target TheFooTarget; // The global target instance.
749 /// extern "C" void LLVMInitializeFooTargetInfo() {
750 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
752 template<Triple::ArchType TargetArchType = Triple::InvalidArch,
754 struct RegisterTarget {
755 RegisterTarget(Target &T, const char *Name, const char *Desc) {
756 TargetRegistry::RegisterTarget(T, Name, Desc,
757 &getTripleMatchQuality,
761 static unsigned getTripleMatchQuality(const std::string &TT) {
762 if (Triple(TT).getArch() == TargetArchType)
768 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
769 /// implementation. This invokes the static "Create" method on the class to
770 /// actually do the construction. Usage:
772 /// extern "C" void LLVMInitializeFooTarget() {
773 /// extern Target TheFooTarget;
774 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
776 template<class MCAsmInfoImpl>
777 struct RegisterMCAsmInfo {
778 RegisterMCAsmInfo(Target &T) {
779 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
782 static MCAsmInfo *Allocator(const Target &T, StringRef TT) {
783 return new MCAsmInfoImpl(T, TT);
788 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
789 /// implementation. This invokes the specified function to do the
790 /// construction. Usage:
792 /// extern "C" void LLVMInitializeFooTarget() {
793 /// extern Target TheFooTarget;
794 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
796 struct RegisterMCAsmInfoFn {
797 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
798 TargetRegistry::RegisterMCAsmInfo(T, Fn);
802 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
803 /// implementation. This invokes the static "Create" method on the class
804 /// to actually do the construction. Usage:
806 /// extern "C" void LLVMInitializeFooTarget() {
807 /// extern Target TheFooTarget;
808 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
810 template<class MCCodeGenInfoImpl>
811 struct RegisterMCCodeGenInfo {
812 RegisterMCCodeGenInfo(Target &T) {
813 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
816 static MCCodeGenInfo *Allocator(StringRef TT,
817 Reloc::Model RM, CodeModel::Model CM) {
818 return new MCCodeGenInfoImpl();
822 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
823 /// info implementation. This invokes the specified function to do the
824 /// construction. Usage:
826 /// extern "C" void LLVMInitializeFooTarget() {
827 /// extern Target TheFooTarget;
828 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
830 struct RegisterMCCodeGenInfoFn {
831 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
832 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
836 /// RegisterMCInstrInfo - Helper template for registering a target instruction
837 /// info implementation. This invokes the static "Create" method on the class
838 /// to actually do the construction. Usage:
840 /// extern "C" void LLVMInitializeFooTarget() {
841 /// extern Target TheFooTarget;
842 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
844 template<class MCInstrInfoImpl>
845 struct RegisterMCInstrInfo {
846 RegisterMCInstrInfo(Target &T) {
847 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
850 static MCInstrInfo *Allocator() {
851 return new MCInstrInfoImpl();
855 /// RegisterMCInstrInfoFn - Helper template for registering a target
856 /// instruction info implementation. This invokes the specified function to
857 /// do the construction. Usage:
859 /// extern "C" void LLVMInitializeFooTarget() {
860 /// extern Target TheFooTarget;
861 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
863 struct RegisterMCInstrInfoFn {
864 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
865 TargetRegistry::RegisterMCInstrInfo(T, Fn);
869 /// RegisterMCRegInfo - Helper template for registering a target register info
870 /// implementation. This invokes the static "Create" method on the class to
871 /// actually do the construction. Usage:
873 /// extern "C" void LLVMInitializeFooTarget() {
874 /// extern Target TheFooTarget;
875 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
877 template<class MCRegisterInfoImpl>
878 struct RegisterMCRegInfo {
879 RegisterMCRegInfo(Target &T) {
880 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
883 static MCRegisterInfo *Allocator(StringRef TT) {
884 return new MCRegisterInfoImpl();
888 /// RegisterMCRegInfoFn - Helper template for registering a target register
889 /// info implementation. This invokes the specified function to do the
890 /// construction. Usage:
892 /// extern "C" void LLVMInitializeFooTarget() {
893 /// extern Target TheFooTarget;
894 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
896 struct RegisterMCRegInfoFn {
897 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
898 TargetRegistry::RegisterMCRegInfo(T, Fn);
902 /// RegisterMCSubtargetInfo - Helper template for registering a target
903 /// subtarget info implementation. This invokes the static "Create" method
904 /// on the class to actually do the construction. Usage:
906 /// extern "C" void LLVMInitializeFooTarget() {
907 /// extern Target TheFooTarget;
908 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
910 template<class MCSubtargetInfoImpl>
911 struct RegisterMCSubtargetInfo {
912 RegisterMCSubtargetInfo(Target &T) {
913 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
916 static MCSubtargetInfo *Allocator(StringRef TT, StringRef CPU,
918 return new MCSubtargetInfoImpl();
922 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
923 /// subtarget info implementation. This invokes the specified function to
924 /// do the construction. Usage:
926 /// extern "C" void LLVMInitializeFooTarget() {
927 /// extern Target TheFooTarget;
928 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
930 struct RegisterMCSubtargetInfoFn {
931 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
932 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
936 /// RegisterTargetMachine - Helper template for registering a target machine
937 /// implementation, for use in the target machine initialization
940 /// extern "C" void LLVMInitializeFooTarget() {
941 /// extern Target TheFooTarget;
942 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
944 template<class TargetMachineImpl>
945 struct RegisterTargetMachine {
946 RegisterTargetMachine(Target &T) {
947 TargetRegistry::RegisterTargetMachine(T, &Allocator);
951 static TargetMachine *Allocator(const Target &T, StringRef TT,
952 StringRef CPU, StringRef FS,
954 CodeModel::Model CM) {
955 return new TargetMachineImpl(T, TT, CPU, FS, RM, CM);
959 /// RegisterAsmBackend - Helper template for registering a target specific
960 /// assembler backend. Usage:
962 /// extern "C" void LLVMInitializeFooAsmBackend() {
963 /// extern Target TheFooTarget;
964 /// RegisterAsmBackend<FooAsmLexer> X(TheFooTarget);
966 template<class AsmBackendImpl>
967 struct RegisterAsmBackend {
968 RegisterAsmBackend(Target &T) {
969 TargetRegistry::RegisterAsmBackend(T, &Allocator);
973 static TargetAsmBackend *Allocator(const Target &T,
974 const std::string &Triple) {
975 return new AsmBackendImpl(T, Triple);
979 /// RegisterAsmLexer - Helper template for registering a target specific
980 /// assembly lexer, for use in the target machine initialization
983 /// extern "C" void LLVMInitializeFooAsmLexer() {
984 /// extern Target TheFooTarget;
985 /// RegisterAsmLexer<FooAsmLexer> X(TheFooTarget);
987 template<class AsmLexerImpl>
988 struct RegisterAsmLexer {
989 RegisterAsmLexer(Target &T) {
990 TargetRegistry::RegisterAsmLexer(T, &Allocator);
994 static TargetAsmLexer *Allocator(const Target &T, const MCRegisterInfo &MRI,
995 const MCAsmInfo &MAI) {
996 return new AsmLexerImpl(T, MRI, MAI);
1000 /// RegisterAsmParser - Helper template for registering a target specific
1001 /// assembly parser, for use in the target machine initialization
1002 /// function. Usage:
1004 /// extern "C" void LLVMInitializeFooAsmParser() {
1005 /// extern Target TheFooTarget;
1006 /// RegisterAsmParser<FooAsmParser> X(TheFooTarget);
1008 template<class AsmParserImpl>
1009 struct RegisterAsmParser {
1010 RegisterAsmParser(Target &T) {
1011 TargetRegistry::RegisterAsmParser(T, &Allocator);
1015 static TargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P) {
1016 return new AsmParserImpl(STI, P);
1020 /// RegisterAsmPrinter - Helper template for registering a target specific
1021 /// assembly printer, for use in the target machine initialization
1022 /// function. Usage:
1024 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1025 /// extern Target TheFooTarget;
1026 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1028 template<class AsmPrinterImpl>
1029 struct RegisterAsmPrinter {
1030 RegisterAsmPrinter(Target &T) {
1031 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1035 static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) {
1036 return new AsmPrinterImpl(TM, Streamer);
1040 /// RegisterCodeEmitter - Helper template for registering a target specific
1041 /// machine code emitter, for use in the target initialization
1042 /// function. Usage:
1044 /// extern "C" void LLVMInitializeFooCodeEmitter() {
1045 /// extern Target TheFooTarget;
1046 /// RegisterCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1048 template<class CodeEmitterImpl>
1049 struct RegisterCodeEmitter {
1050 RegisterCodeEmitter(Target &T) {
1051 TargetRegistry::RegisterCodeEmitter(T, &Allocator);
1055 static MCCodeEmitter *Allocator(const MCInstrInfo &II,
1056 const MCSubtargetInfo &STI,
1058 return new CodeEmitterImpl();