1 //===-- Support/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_SUPPORT_TARGETREGISTRY_H
20 #define LLVM_SUPPORT_TARGETREGISTRY_H
22 #include "llvm/Support/CodeGen.h"
23 #include "llvm/ADT/Triple.h"
38 class MCInstrAnalysis;
43 class MCSubtargetInfo;
44 class MCTargetAsmLexer;
45 class MCTargetAsmParser;
48 class formatted_raw_ostream;
50 MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
52 bool useLoc, bool useCFI,
53 MCInstPrinter *InstPrint,
58 /// Target - Wrapper for Target specific information.
60 /// For registration purposes, this is a POD type so that targets can be
61 /// registered without the use of static constructors.
63 /// Targets should implement a single global instance of this class (which
64 /// will be zero initialized), and pass that instance to the TargetRegistry as
65 /// part of their initialization.
68 friend struct TargetRegistry;
70 typedef unsigned (*TripleMatchQualityFnTy)(const std::string &TT);
72 typedef MCAsmInfo *(*MCAsmInfoCtorFnTy)(const Target &T,
74 typedef MCCodeGenInfo *(*MCCodeGenInfoCtorFnTy)(StringRef TT,
77 typedef MCInstrInfo *(*MCInstrInfoCtorFnTy)(void);
78 typedef MCInstrAnalysis *(*MCInstrAnalysisCtorFnTy)(const MCInstrInfo*Info);
79 typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(StringRef TT);
80 typedef MCSubtargetInfo *(*MCSubtargetInfoCtorFnTy)(StringRef TT,
83 typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T,
89 typedef AsmPrinter *(*AsmPrinterCtorTy)(TargetMachine &TM,
90 MCStreamer &Streamer);
91 typedef MCAsmBackend *(*MCAsmBackendCtorTy)(const Target &T, StringRef TT);
92 typedef MCTargetAsmLexer *(*MCAsmLexerCtorTy)(const Target &T,
93 const MCRegisterInfo &MRI,
94 const MCAsmInfo &MAI);
95 typedef MCTargetAsmParser *(*MCAsmParserCtorTy)(MCSubtargetInfo &STI,
97 typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T);
98 typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
99 unsigned SyntaxVariant,
100 const MCAsmInfo &MAI);
101 typedef MCCodeEmitter *(*MCCodeEmitterCtorTy)(const MCInstrInfo &II,
102 const MCSubtargetInfo &STI,
104 typedef MCStreamer *(*MCObjectStreamerCtorTy)(const Target &T,
109 MCCodeEmitter *_Emitter,
112 typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx,
113 formatted_raw_ostream &OS,
117 MCInstPrinter *InstPrint,
123 /// Next - The next registered target in the linked list, maintained by the
127 /// TripleMatchQualityFn - The target function for rating the match quality
129 TripleMatchQualityFnTy TripleMatchQualityFn;
131 /// Name - The target name.
134 /// ShortDesc - A short description of the target.
135 const char *ShortDesc;
137 /// HasJIT - Whether this target supports the JIT.
140 /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
142 MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
144 /// MCCodeGenInfoCtorFn - Constructor function for this target's MCCodeGenInfo,
146 MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn;
148 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
150 MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
152 /// MCInstrAnalysisCtorFn - Constructor function for this target's
153 /// MCInstrAnalysis, if registered.
154 MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
156 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
158 MCRegInfoCtorFnTy MCRegInfoCtorFn;
160 /// MCSubtargetInfoCtorFn - Constructor function for this target's
161 /// MCSubtargetInfo, if registered.
162 MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
164 /// TargetMachineCtorFn - Construction function for this target's
165 /// TargetMachine, if registered.
166 TargetMachineCtorTy TargetMachineCtorFn;
168 /// MCAsmBackendCtorFn - Construction function for this target's
169 /// MCAsmBackend, if registered.
170 MCAsmBackendCtorTy MCAsmBackendCtorFn;
172 /// MCAsmLexerCtorFn - Construction function for this target's
173 /// MCTargetAsmLexer, if registered.
174 MCAsmLexerCtorTy MCAsmLexerCtorFn;
176 /// MCAsmParserCtorFn - Construction function for this target's
177 /// MCTargetAsmParser, if registered.
178 MCAsmParserCtorTy MCAsmParserCtorFn;
180 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
182 AsmPrinterCtorTy AsmPrinterCtorFn;
184 /// MCDisassemblerCtorFn - Construction function for this target's
185 /// MCDisassembler, if registered.
186 MCDisassemblerCtorTy MCDisassemblerCtorFn;
188 /// MCInstPrinterCtorFn - Construction function for this target's
189 /// MCInstPrinter, if registered.
190 MCInstPrinterCtorTy MCInstPrinterCtorFn;
192 /// MCCodeEmitterCtorFn - Construction function for this target's
193 /// CodeEmitter, if registered.
194 MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
196 /// MCObjectStreamerCtorFn - Construction function for this target's
197 /// MCObjectStreamer, if registered.
198 MCObjectStreamerCtorTy MCObjectStreamerCtorFn;
200 /// AsmStreamerCtorFn - Construction function for this target's
201 /// AsmStreamer, if registered (default = llvm::createAsmStreamer).
202 AsmStreamerCtorTy AsmStreamerCtorFn;
205 Target() : AsmStreamerCtorFn(llvm::createAsmStreamer) {}
207 /// @name Target Information
210 // getNext - Return the next registered target.
211 const Target *getNext() const { return Next; }
213 /// getName - Get the target name.
214 const char *getName() const { return Name; }
216 /// getShortDescription - Get a short description of the target.
217 const char *getShortDescription() const { return ShortDesc; }
220 /// @name Feature Predicates
223 /// hasJIT - Check if this targets supports the just-in-time compilation.
224 bool hasJIT() const { return HasJIT; }
226 /// hasTargetMachine - Check if this target supports code generation.
227 bool hasTargetMachine() const { return TargetMachineCtorFn != 0; }
229 /// hasMCAsmBackend - Check if this target supports .o generation.
230 bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != 0; }
232 /// hasMCAsmLexer - Check if this target supports .s lexing.
233 bool hasMCAsmLexer() const { return MCAsmLexerCtorFn != 0; }
235 /// hasAsmParser - Check if this target supports .s parsing.
236 bool hasMCAsmParser() const { return MCAsmParserCtorFn != 0; }
238 /// hasAsmPrinter - Check if this target supports .s printing.
239 bool hasAsmPrinter() const { return AsmPrinterCtorFn != 0; }
241 /// hasMCDisassembler - Check if this target has a disassembler.
242 bool hasMCDisassembler() const { return MCDisassemblerCtorFn != 0; }
244 /// hasMCInstPrinter - Check if this target has an instruction printer.
245 bool hasMCInstPrinter() const { return MCInstPrinterCtorFn != 0; }
247 /// hasMCCodeEmitter - Check if this target supports instruction encoding.
248 bool hasMCCodeEmitter() const { return MCCodeEmitterCtorFn != 0; }
250 /// hasMCObjectStreamer - Check if this target supports streaming to files.
251 bool hasMCObjectStreamer() const { return MCObjectStreamerCtorFn != 0; }
253 /// hasAsmStreamer - Check if this target supports streaming to files.
254 bool hasAsmStreamer() const { return AsmStreamerCtorFn != 0; }
257 /// @name Feature Constructors
260 /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
263 /// \arg Triple - This argument is used to determine the target machine
264 /// feature set; it should always be provided. Generally this should be
265 /// either the target triple from the module, or the target triple of the
266 /// host if that does not exist.
267 MCAsmInfo *createMCAsmInfo(StringRef Triple) const {
268 if (!MCAsmInfoCtorFn)
270 return MCAsmInfoCtorFn(*this, Triple);
273 /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
275 MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model RM,
276 CodeModel::Model CM) const {
277 if (!MCCodeGenInfoCtorFn)
279 return MCCodeGenInfoCtorFn(Triple, RM, CM);
282 /// createMCInstrInfo - Create a MCInstrInfo implementation.
284 MCInstrInfo *createMCInstrInfo() const {
285 if (!MCInstrInfoCtorFn)
287 return MCInstrInfoCtorFn();
290 /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
292 MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
293 if (!MCInstrAnalysisCtorFn)
295 return MCInstrAnalysisCtorFn(Info);
298 /// createMCRegInfo - Create a MCRegisterInfo implementation.
300 MCRegisterInfo *createMCRegInfo(StringRef Triple) const {
301 if (!MCRegInfoCtorFn)
303 return MCRegInfoCtorFn(Triple);
306 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
308 /// \arg Triple - This argument is used to determine the target machine
309 /// feature set; it should always be provided. Generally this should be
310 /// either the target triple from the module, or the target triple of the
311 /// host if that does not exist.
312 /// \arg CPU - This specifies the name of the target CPU.
313 /// \arg Features - This specifies the string representation of the
314 /// additional target features.
315 MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU,
316 StringRef Features) const {
317 if (!MCSubtargetInfoCtorFn)
319 return MCSubtargetInfoCtorFn(Triple, CPU, Features);
322 /// createTargetMachine - Create a target specific machine implementation
323 /// for the specified \arg Triple.
325 /// \arg Triple - This argument is used to determine the target machine
326 /// feature set; it should always be provided. Generally this should be
327 /// either the target triple from the module, or the target triple of the
328 /// host if that does not exist.
329 TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU,
331 Reloc::Model RM = Reloc::Default,
332 CodeModel::Model CM = CodeModel::Default) const {
333 if (!TargetMachineCtorFn)
335 return TargetMachineCtorFn(*this, Triple, CPU, Features, RM, CM);
338 /// createMCAsmBackend - Create a target specific assembly parser.
340 /// \arg Triple - The target triple string.
341 /// \arg Backend - The target independent assembler object.
342 MCAsmBackend *createMCAsmBackend(StringRef Triple) const {
343 if (!MCAsmBackendCtorFn)
345 return MCAsmBackendCtorFn(*this, Triple);
348 /// createMCAsmLexer - Create a target specific assembly lexer.
350 MCTargetAsmLexer *createMCAsmLexer(const MCRegisterInfo &MRI,
351 const MCAsmInfo &MAI) const {
352 if (!MCAsmLexerCtorFn)
354 return MCAsmLexerCtorFn(*this, MRI, MAI);
357 /// createMCAsmParser - Create a target specific assembly parser.
359 /// \arg Parser - The target independent parser implementation to use for
360 /// parsing and lexing.
361 MCTargetAsmParser *createMCAsmParser(MCSubtargetInfo &STI,
362 MCAsmParser &Parser) const {
363 if (!MCAsmParserCtorFn)
365 return MCAsmParserCtorFn(STI, Parser);
368 /// createAsmPrinter - Create a target specific assembly printer pass. This
369 /// takes ownership of the MCStreamer object.
370 AsmPrinter *createAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) const{
371 if (!AsmPrinterCtorFn)
373 return AsmPrinterCtorFn(TM, Streamer);
376 MCDisassembler *createMCDisassembler() const {
377 if (!MCDisassemblerCtorFn)
379 return MCDisassemblerCtorFn(*this);
382 MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
383 const MCAsmInfo &MAI) const {
384 if (!MCInstPrinterCtorFn)
386 return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI);
390 /// createMCCodeEmitter - Create a target specific code emitter.
391 MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
392 const MCSubtargetInfo &STI,
393 MCContext &Ctx) const {
394 if (!MCCodeEmitterCtorFn)
396 return MCCodeEmitterCtorFn(II, STI, Ctx);
399 /// createMCObjectStreamer - Create a target specific MCStreamer.
401 /// \arg TT - The target triple.
402 /// \arg Ctx - The target context.
403 /// \arg TAB - The target assembler backend object. Takes ownership.
404 /// \arg _OS - The stream object.
405 /// \arg _Emitter - The target independent assembler object.Takes ownership.
406 /// \arg RelaxAll - Relax all fixups?
407 /// \arg NoExecStack - Mark file as not needing a executable stack.
408 MCStreamer *createMCObjectStreamer(StringRef TT, MCContext &Ctx,
411 MCCodeEmitter *_Emitter,
413 bool NoExecStack) const {
414 if (!MCObjectStreamerCtorFn)
416 return MCObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter,
417 RelaxAll, NoExecStack);
420 /// createAsmStreamer - Create a target specific MCStreamer.
421 MCStreamer *createAsmStreamer(MCContext &Ctx,
422 formatted_raw_ostream &OS,
426 MCInstPrinter *InstPrint,
429 bool ShowInst) const {
430 // AsmStreamerCtorFn is default to llvm::createAsmStreamer
431 return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useLoc, useCFI,
432 InstPrint, CE, TAB, ShowInst);
438 /// TargetRegistry - Generic interface to target specific features.
439 struct TargetRegistry {
441 const Target *Current;
442 explicit iterator(Target *T) : Current(T) {}
443 friend struct TargetRegistry;
445 iterator(const iterator &I) : Current(I.Current) {}
446 iterator() : Current(0) {}
448 bool operator==(const iterator &x) const {
449 return Current == x.Current;
451 bool operator!=(const iterator &x) const {
452 return !operator==(x);
455 // Iterator traversal: forward iteration only
456 iterator &operator++() { // Preincrement
457 assert(Current && "Cannot increment end iterator!");
458 Current = Current->getNext();
461 iterator operator++(int) { // Postincrement
462 iterator tmp = *this;
467 const Target &operator*() const {
468 assert(Current && "Cannot dereference end iterator!");
472 const Target *operator->() const {
477 /// printRegisteredTargetsForVersion - Print the registered targets
478 /// appropriately for inclusion in a tool's version output.
479 static void printRegisteredTargetsForVersion();
481 /// @name Registry Access
484 static iterator begin();
486 static iterator end() { return iterator(); }
488 /// lookupTarget - Lookup a target based on a target triple.
490 /// \param Triple - The triple to use for finding a target.
491 /// \param Error - On failure, an error string describing why no target was
493 static const Target *lookupTarget(const std::string &Triple,
496 /// getClosestTargetForJIT - Pick the best target that is compatible with
497 /// the current host. If no close target can be found, this returns null
498 /// and sets the Error string to a reason.
500 /// Maintained for compatibility through 2.6.
501 static const Target *getClosestTargetForJIT(std::string &Error);
504 /// @name Target Registration
507 /// RegisterTarget - Register the given target. Attempts to register a
508 /// target which has already been registered will be ignored.
510 /// Clients are responsible for ensuring that registration doesn't occur
511 /// while another thread is attempting to access the registry. Typically
512 /// this is done by initializing all targets at program startup.
514 /// @param T - The target being registered.
515 /// @param Name - The target name. This should be a static string.
516 /// @param ShortDesc - A short target description. This should be a static
518 /// @param TQualityFn - The triple match quality computation function for
520 /// @param HasJIT - Whether the target supports JIT code
522 static void RegisterTarget(Target &T,
524 const char *ShortDesc,
525 Target::TripleMatchQualityFnTy TQualityFn,
526 bool HasJIT = false);
528 /// RegisterMCAsmInfo - Register a MCAsmInfo 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 MCAsmInfo for the target.
537 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
538 // Ignore duplicate registration.
539 if (!T.MCAsmInfoCtorFn)
540 T.MCAsmInfoCtorFn = Fn;
543 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
546 /// Clients are responsible for ensuring that registration doesn't occur
547 /// while another thread is attempting to access the registry. Typically
548 /// this is done by initializing all targets at program startup.
550 /// @param T - The target being registered.
551 /// @param Fn - A function to construct a MCCodeGenInfo for the target.
552 static void RegisterMCCodeGenInfo(Target &T,
553 Target::MCCodeGenInfoCtorFnTy Fn) {
554 // Ignore duplicate registration.
555 if (!T.MCCodeGenInfoCtorFn)
556 T.MCCodeGenInfoCtorFn = Fn;
559 /// RegisterMCInstrInfo - Register a MCInstrInfo 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 MCInstrInfo for the target.
568 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
569 // Ignore duplicate registration.
570 if (!T.MCInstrInfoCtorFn)
571 T.MCInstrInfoCtorFn = Fn;
574 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
575 /// the given target.
576 static void RegisterMCInstrAnalysis(Target &T,
577 Target::MCInstrAnalysisCtorFnTy Fn) {
578 // Ignore duplicate registration.
579 if (!T.MCInstrAnalysisCtorFn)
580 T.MCInstrAnalysisCtorFn = Fn;
583 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
586 /// Clients are responsible for ensuring that registration doesn't occur
587 /// while another thread is attempting to access the registry. Typically
588 /// this is done by initializing all targets at program startup.
590 /// @param T - The target being registered.
591 /// @param Fn - A function to construct a MCRegisterInfo for the target.
592 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
593 // Ignore duplicate registration.
594 if (!T.MCRegInfoCtorFn)
595 T.MCRegInfoCtorFn = Fn;
598 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
599 /// the given target.
601 /// Clients are responsible for ensuring that registration doesn't occur
602 /// while another thread is attempting to access the registry. Typically
603 /// this is done by initializing all targets at program startup.
605 /// @param T - The target being registered.
606 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
607 static void RegisterMCSubtargetInfo(Target &T,
608 Target::MCSubtargetInfoCtorFnTy Fn) {
609 // Ignore duplicate registration.
610 if (!T.MCSubtargetInfoCtorFn)
611 T.MCSubtargetInfoCtorFn = Fn;
614 /// RegisterTargetMachine - Register a TargetMachine implementation for the
617 /// Clients are responsible for ensuring that registration doesn't occur
618 /// while another thread is attempting to access the registry. Typically
619 /// this is done by initializing all targets at program startup.
621 /// @param T - The target being registered.
622 /// @param Fn - A function to construct a TargetMachine for the target.
623 static void RegisterTargetMachine(Target &T,
624 Target::TargetMachineCtorTy Fn) {
625 // Ignore duplicate registration.
626 if (!T.TargetMachineCtorFn)
627 T.TargetMachineCtorFn = Fn;
630 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
633 /// Clients are responsible for ensuring that registration doesn't occur
634 /// while another thread is attempting to access the registry. Typically
635 /// this is done by initializing all targets at program startup.
637 /// @param T - The target being registered.
638 /// @param Fn - A function to construct an AsmBackend for the target.
639 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
640 if (!T.MCAsmBackendCtorFn)
641 T.MCAsmBackendCtorFn = Fn;
644 /// RegisterMCAsmLexer - Register a MCTargetAsmLexer implementation for the
647 /// Clients are responsible for ensuring that registration doesn't occur
648 /// while another thread is attempting to access the registry. Typically
649 /// this is done by initializing all targets at program startup.
651 /// @param T - The target being registered.
652 /// @param Fn - A function to construct an MCAsmLexer for the target.
653 static void RegisterMCAsmLexer(Target &T, Target::MCAsmLexerCtorTy Fn) {
654 if (!T.MCAsmLexerCtorFn)
655 T.MCAsmLexerCtorFn = Fn;
658 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
659 /// the given target.
661 /// Clients are responsible for ensuring that registration doesn't occur
662 /// while another thread is attempting to access the registry. Typically
663 /// this is done by initializing all targets at program startup.
665 /// @param T - The target being registered.
666 /// @param Fn - A function to construct an MCTargetAsmParser for the target.
667 static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
668 if (!T.MCAsmParserCtorFn)
669 T.MCAsmParserCtorFn = Fn;
672 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
675 /// Clients are responsible for ensuring that registration doesn't occur
676 /// while another thread is attempting to access the registry. Typically
677 /// this is done by initializing all targets at program startup.
679 /// @param T - The target being registered.
680 /// @param Fn - A function to construct an AsmPrinter for the target.
681 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
682 // Ignore duplicate registration.
683 if (!T.AsmPrinterCtorFn)
684 T.AsmPrinterCtorFn = Fn;
687 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
688 /// the given target.
690 /// Clients are responsible for ensuring that registration doesn't occur
691 /// while another thread is attempting to access the registry. Typically
692 /// this is done by initializing all targets at program startup.
694 /// @param T - The target being registered.
695 /// @param Fn - A function to construct an MCDisassembler for the target.
696 static void RegisterMCDisassembler(Target &T,
697 Target::MCDisassemblerCtorTy Fn) {
698 if (!T.MCDisassemblerCtorFn)
699 T.MCDisassemblerCtorFn = Fn;
702 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
705 /// Clients are responsible for ensuring that registration doesn't occur
706 /// while another thread is attempting to access the registry. Typically
707 /// this is done by initializing all targets at program startup.
709 /// @param T - The target being registered.
710 /// @param Fn - A function to construct an MCInstPrinter for the target.
711 static void RegisterMCInstPrinter(Target &T,
712 Target::MCInstPrinterCtorTy Fn) {
713 if (!T.MCInstPrinterCtorFn)
714 T.MCInstPrinterCtorFn = Fn;
717 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
720 /// Clients are responsible for ensuring that registration doesn't occur
721 /// while another thread is attempting to access the registry. Typically
722 /// this is done by initializing all targets at program startup.
724 /// @param T - The target being registered.
725 /// @param Fn - A function to construct an MCCodeEmitter for the target.
726 static void RegisterMCCodeEmitter(Target &T,
727 Target::MCCodeEmitterCtorTy Fn) {
728 if (!T.MCCodeEmitterCtorFn)
729 T.MCCodeEmitterCtorFn = Fn;
732 /// RegisterMCObjectStreamer - Register a object code MCStreamer
733 /// implementation for the given target.
735 /// Clients are responsible for ensuring that registration doesn't occur
736 /// while another thread is attempting to access the registry. Typically
737 /// this is done by initializing all targets at program startup.
739 /// @param T - The target being registered.
740 /// @param Fn - A function to construct an MCStreamer for the target.
741 static void RegisterMCObjectStreamer(Target &T,
742 Target::MCObjectStreamerCtorTy Fn) {
743 if (!T.MCObjectStreamerCtorFn)
744 T.MCObjectStreamerCtorFn = Fn;
747 /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
748 /// for the given target.
750 /// Clients are responsible for ensuring that registration doesn't occur
751 /// while another thread is attempting to access the registry. Typically
752 /// this is done by initializing all targets at program startup.
754 /// @param T - The target being registered.
755 /// @param Fn - A function to construct an MCStreamer for the target.
756 static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
757 if (T.AsmStreamerCtorFn == createAsmStreamer)
758 T.AsmStreamerCtorFn = Fn;
765 //===--------------------------------------------------------------------===//
767 /// RegisterTarget - Helper template for registering a target, for use in the
768 /// target's initialization function. Usage:
771 /// Target TheFooTarget; // The global target instance.
773 /// extern "C" void LLVMInitializeFooTargetInfo() {
774 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
776 template<Triple::ArchType TargetArchType = Triple::InvalidArch,
778 struct RegisterTarget {
779 RegisterTarget(Target &T, const char *Name, const char *Desc) {
780 TargetRegistry::RegisterTarget(T, Name, Desc,
781 &getTripleMatchQuality,
785 static unsigned getTripleMatchQuality(const std::string &TT) {
786 if (Triple(TT).getArch() == TargetArchType)
792 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
793 /// implementation. This invokes the static "Create" method on the class to
794 /// actually do the construction. Usage:
796 /// extern "C" void LLVMInitializeFooTarget() {
797 /// extern Target TheFooTarget;
798 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
800 template<class MCAsmInfoImpl>
801 struct RegisterMCAsmInfo {
802 RegisterMCAsmInfo(Target &T) {
803 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
806 static MCAsmInfo *Allocator(const Target &T, StringRef TT) {
807 return new MCAsmInfoImpl(T, TT);
812 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
813 /// implementation. This invokes the specified function to do the
814 /// construction. Usage:
816 /// extern "C" void LLVMInitializeFooTarget() {
817 /// extern Target TheFooTarget;
818 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
820 struct RegisterMCAsmInfoFn {
821 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
822 TargetRegistry::RegisterMCAsmInfo(T, Fn);
826 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
827 /// implementation. This invokes the static "Create" method on the class
828 /// to actually do the construction. Usage:
830 /// extern "C" void LLVMInitializeFooTarget() {
831 /// extern Target TheFooTarget;
832 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
834 template<class MCCodeGenInfoImpl>
835 struct RegisterMCCodeGenInfo {
836 RegisterMCCodeGenInfo(Target &T) {
837 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
840 static MCCodeGenInfo *Allocator(StringRef TT,
841 Reloc::Model RM, CodeModel::Model CM) {
842 return new MCCodeGenInfoImpl();
846 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
847 /// info implementation. This invokes the specified function to do the
848 /// construction. Usage:
850 /// extern "C" void LLVMInitializeFooTarget() {
851 /// extern Target TheFooTarget;
852 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
854 struct RegisterMCCodeGenInfoFn {
855 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
856 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
860 /// RegisterMCInstrInfo - Helper template for registering a target instruction
861 /// info implementation. This invokes the static "Create" method on the class
862 /// to actually do the construction. Usage:
864 /// extern "C" void LLVMInitializeFooTarget() {
865 /// extern Target TheFooTarget;
866 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
868 template<class MCInstrInfoImpl>
869 struct RegisterMCInstrInfo {
870 RegisterMCInstrInfo(Target &T) {
871 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
874 static MCInstrInfo *Allocator() {
875 return new MCInstrInfoImpl();
879 /// RegisterMCInstrInfoFn - Helper template for registering a target
880 /// instruction info implementation. This invokes the specified function to
881 /// do the construction. Usage:
883 /// extern "C" void LLVMInitializeFooTarget() {
884 /// extern Target TheFooTarget;
885 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
887 struct RegisterMCInstrInfoFn {
888 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
889 TargetRegistry::RegisterMCInstrInfo(T, Fn);
893 /// RegisterMCInstrAnalysis - Helper template for registering a target
894 /// instruction analyzer implementation. This invokes the static "Create"
895 /// method on the class to actually do the construction. Usage:
897 /// extern "C" void LLVMInitializeFooTarget() {
898 /// extern Target TheFooTarget;
899 /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
901 template<class MCInstrAnalysisImpl>
902 struct RegisterMCInstrAnalysis {
903 RegisterMCInstrAnalysis(Target &T) {
904 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
907 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
908 return new MCInstrAnalysisImpl(Info);
912 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
913 /// instruction analyzer implementation. This invokes the specified function
914 /// to do the construction. Usage:
916 /// extern "C" void LLVMInitializeFooTarget() {
917 /// extern Target TheFooTarget;
918 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
920 struct RegisterMCInstrAnalysisFn {
921 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
922 TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
926 /// RegisterMCRegInfo - Helper template for registering a target register info
927 /// implementation. This invokes the static "Create" method on the class to
928 /// actually do the construction. Usage:
930 /// extern "C" void LLVMInitializeFooTarget() {
931 /// extern Target TheFooTarget;
932 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
934 template<class MCRegisterInfoImpl>
935 struct RegisterMCRegInfo {
936 RegisterMCRegInfo(Target &T) {
937 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
940 static MCRegisterInfo *Allocator(StringRef TT) {
941 return new MCRegisterInfoImpl();
945 /// RegisterMCRegInfoFn - Helper template for registering a target register
946 /// info implementation. This invokes the specified function to do the
947 /// construction. Usage:
949 /// extern "C" void LLVMInitializeFooTarget() {
950 /// extern Target TheFooTarget;
951 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
953 struct RegisterMCRegInfoFn {
954 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
955 TargetRegistry::RegisterMCRegInfo(T, Fn);
959 /// RegisterMCSubtargetInfo - Helper template for registering a target
960 /// subtarget info implementation. This invokes the static "Create" method
961 /// on the class to actually do the construction. Usage:
963 /// extern "C" void LLVMInitializeFooTarget() {
964 /// extern Target TheFooTarget;
965 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
967 template<class MCSubtargetInfoImpl>
968 struct RegisterMCSubtargetInfo {
969 RegisterMCSubtargetInfo(Target &T) {
970 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
973 static MCSubtargetInfo *Allocator(StringRef TT, StringRef CPU,
975 return new MCSubtargetInfoImpl();
979 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
980 /// subtarget info implementation. This invokes the specified function to
981 /// do the construction. Usage:
983 /// extern "C" void LLVMInitializeFooTarget() {
984 /// extern Target TheFooTarget;
985 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
987 struct RegisterMCSubtargetInfoFn {
988 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
989 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
993 /// RegisterTargetMachine - Helper template for registering a target machine
994 /// implementation, for use in the target machine initialization
997 /// extern "C" void LLVMInitializeFooTarget() {
998 /// extern Target TheFooTarget;
999 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1001 template<class TargetMachineImpl>
1002 struct RegisterTargetMachine {
1003 RegisterTargetMachine(Target &T) {
1004 TargetRegistry::RegisterTargetMachine(T, &Allocator);
1008 static TargetMachine *Allocator(const Target &T, StringRef TT,
1009 StringRef CPU, StringRef FS,
1011 CodeModel::Model CM) {
1012 return new TargetMachineImpl(T, TT, CPU, FS, RM, CM);
1016 /// RegisterMCAsmBackend - Helper template for registering a target specific
1017 /// assembler backend. Usage:
1019 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1020 /// extern Target TheFooTarget;
1021 /// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1023 template<class MCAsmBackendImpl>
1024 struct RegisterMCAsmBackend {
1025 RegisterMCAsmBackend(Target &T) {
1026 TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1030 static MCAsmBackend *Allocator(const Target &T, StringRef Triple) {
1031 return new MCAsmBackendImpl(T, Triple);
1035 /// RegisterMCAsmLexer - Helper template for registering a target specific
1036 /// assembly lexer, for use in the target machine initialization
1037 /// function. Usage:
1039 /// extern "C" void LLVMInitializeFooMCAsmLexer() {
1040 /// extern Target TheFooTarget;
1041 /// RegisterMCAsmLexer<FooMCAsmLexer> X(TheFooTarget);
1043 template<class MCAsmLexerImpl>
1044 struct RegisterMCAsmLexer {
1045 RegisterMCAsmLexer(Target &T) {
1046 TargetRegistry::RegisterMCAsmLexer(T, &Allocator);
1050 static MCTargetAsmLexer *Allocator(const Target &T,
1051 const MCRegisterInfo &MRI,
1052 const MCAsmInfo &MAI) {
1053 return new MCAsmLexerImpl(T, MRI, MAI);
1057 /// RegisterMCAsmParser - Helper template for registering a target specific
1058 /// assembly parser, for use in the target machine initialization
1059 /// function. Usage:
1061 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1062 /// extern Target TheFooTarget;
1063 /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1065 template<class MCAsmParserImpl>
1066 struct RegisterMCAsmParser {
1067 RegisterMCAsmParser(Target &T) {
1068 TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1072 static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P) {
1073 return new MCAsmParserImpl(STI, P);
1077 /// RegisterAsmPrinter - Helper template for registering a target specific
1078 /// assembly printer, for use in the target machine initialization
1079 /// function. Usage:
1081 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1082 /// extern Target TheFooTarget;
1083 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1085 template<class AsmPrinterImpl>
1086 struct RegisterAsmPrinter {
1087 RegisterAsmPrinter(Target &T) {
1088 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1092 static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) {
1093 return new AsmPrinterImpl(TM, Streamer);
1097 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1098 /// machine code emitter, for use in the target initialization
1099 /// function. Usage:
1101 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1102 /// extern Target TheFooTarget;
1103 /// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1105 template<class MCCodeEmitterImpl>
1106 struct RegisterMCCodeEmitter {
1107 RegisterMCCodeEmitter(Target &T) {
1108 TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1112 static MCCodeEmitter *Allocator(const MCInstrInfo &II,
1113 const MCSubtargetInfo &STI,
1115 return new MCCodeEmitterImpl();