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;
49 class formatted_raw_ostream;
51 MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
53 bool useLoc, bool useCFI,
54 bool useDwarfDirectory,
55 MCInstPrinter *InstPrint,
60 /// Target - Wrapper for Target specific information.
62 /// For registration purposes, this is a POD type so that targets can be
63 /// registered without the use of static constructors.
65 /// Targets should implement a single global instance of this class (which
66 /// will be zero initialized), and pass that instance to the TargetRegistry as
67 /// part of their initialization.
70 friend struct TargetRegistry;
72 typedef unsigned (*TripleMatchQualityFnTy)(const std::string &TT);
74 typedef MCAsmInfo *(*MCAsmInfoCtorFnTy)(const Target &T,
76 typedef MCCodeGenInfo *(*MCCodeGenInfoCtorFnTy)(StringRef TT,
79 CodeGenOpt::Level OL);
80 typedef MCInstrInfo *(*MCInstrInfoCtorFnTy)(void);
81 typedef MCInstrAnalysis *(*MCInstrAnalysisCtorFnTy)(const MCInstrInfo*Info);
82 typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(StringRef TT);
83 typedef MCSubtargetInfo *(*MCSubtargetInfoCtorFnTy)(StringRef TT,
86 typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T,
90 const TargetOptions &Options,
93 CodeGenOpt::Level OL);
94 typedef AsmPrinter *(*AsmPrinterCtorTy)(TargetMachine &TM,
95 MCStreamer &Streamer);
96 typedef MCAsmBackend *(*MCAsmBackendCtorTy)(const Target &T, StringRef TT);
97 typedef MCTargetAsmLexer *(*MCAsmLexerCtorTy)(const Target &T,
98 const MCRegisterInfo &MRI,
99 const MCAsmInfo &MAI);
100 typedef MCTargetAsmParser *(*MCAsmParserCtorTy)(MCSubtargetInfo &STI,
102 typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T,
103 const MCSubtargetInfo &STI);
104 typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
105 unsigned SyntaxVariant,
106 const MCAsmInfo &MAI,
107 const MCInstrInfo &MII,
108 const MCRegisterInfo &MRI,
109 const MCSubtargetInfo &STI);
110 typedef MCCodeEmitter *(*MCCodeEmitterCtorTy)(const MCInstrInfo &II,
111 const MCRegisterInfo &MRI,
112 const MCSubtargetInfo &STI,
114 typedef MCStreamer *(*MCObjectStreamerCtorTy)(const Target &T,
119 MCCodeEmitter *_Emitter,
122 typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx,
123 formatted_raw_ostream &OS,
127 bool useDwarfDirectory,
128 MCInstPrinter *InstPrint,
134 /// Next - The next registered target in the linked list, maintained by the
138 /// TripleMatchQualityFn - The target function for rating the match quality
140 TripleMatchQualityFnTy TripleMatchQualityFn;
142 /// Name - The target name.
145 /// ShortDesc - A short description of the target.
146 const char *ShortDesc;
148 /// HasJIT - Whether this target supports the JIT.
151 /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
153 MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
155 /// MCCodeGenInfoCtorFn - Constructor function for this target's
156 /// MCCodeGenInfo, if registered.
157 MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn;
159 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
161 MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
163 /// MCInstrAnalysisCtorFn - Constructor function for this target's
164 /// MCInstrAnalysis, if registered.
165 MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
167 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
169 MCRegInfoCtorFnTy MCRegInfoCtorFn;
171 /// MCSubtargetInfoCtorFn - Constructor function for this target's
172 /// MCSubtargetInfo, if registered.
173 MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
175 /// TargetMachineCtorFn - Construction function for this target's
176 /// TargetMachine, if registered.
177 TargetMachineCtorTy TargetMachineCtorFn;
179 /// MCAsmBackendCtorFn - Construction function for this target's
180 /// MCAsmBackend, if registered.
181 MCAsmBackendCtorTy MCAsmBackendCtorFn;
183 /// MCAsmLexerCtorFn - Construction function for this target's
184 /// MCTargetAsmLexer, if registered.
185 MCAsmLexerCtorTy MCAsmLexerCtorFn;
187 /// MCAsmParserCtorFn - Construction function for this target's
188 /// MCTargetAsmParser, if registered.
189 MCAsmParserCtorTy MCAsmParserCtorFn;
191 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
193 AsmPrinterCtorTy AsmPrinterCtorFn;
195 /// MCDisassemblerCtorFn - Construction function for this target's
196 /// MCDisassembler, if registered.
197 MCDisassemblerCtorTy MCDisassemblerCtorFn;
199 /// MCInstPrinterCtorFn - Construction function for this target's
200 /// MCInstPrinter, if registered.
201 MCInstPrinterCtorTy MCInstPrinterCtorFn;
203 /// MCCodeEmitterCtorFn - Construction function for this target's
204 /// CodeEmitter, if registered.
205 MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
207 /// MCObjectStreamerCtorFn - Construction function for this target's
208 /// MCObjectStreamer, if registered.
209 MCObjectStreamerCtorTy MCObjectStreamerCtorFn;
211 /// AsmStreamerCtorFn - Construction function for this target's
212 /// AsmStreamer, if registered (default = llvm::createAsmStreamer).
213 AsmStreamerCtorTy AsmStreamerCtorFn;
216 Target() : AsmStreamerCtorFn(llvm::createAsmStreamer) {}
218 /// @name Target Information
221 // getNext - Return the next registered target.
222 const Target *getNext() const { return Next; }
224 /// getName - Get the target name.
225 const char *getName() const { return Name; }
227 /// getShortDescription - Get a short description of the target.
228 const char *getShortDescription() const { return ShortDesc; }
231 /// @name Feature Predicates
234 /// hasJIT - Check if this targets supports the just-in-time compilation.
235 bool hasJIT() const { return HasJIT; }
237 /// hasTargetMachine - Check if this target supports code generation.
238 bool hasTargetMachine() const { return TargetMachineCtorFn != 0; }
240 /// hasMCAsmBackend - Check if this target supports .o generation.
241 bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != 0; }
243 /// hasMCAsmLexer - Check if this target supports .s lexing.
244 bool hasMCAsmLexer() const { return MCAsmLexerCtorFn != 0; }
246 /// hasAsmParser - Check if this target supports .s parsing.
247 bool hasMCAsmParser() const { return MCAsmParserCtorFn != 0; }
249 /// hasAsmPrinter - Check if this target supports .s printing.
250 bool hasAsmPrinter() const { return AsmPrinterCtorFn != 0; }
252 /// hasMCDisassembler - Check if this target has a disassembler.
253 bool hasMCDisassembler() const { return MCDisassemblerCtorFn != 0; }
255 /// hasMCInstPrinter - Check if this target has an instruction printer.
256 bool hasMCInstPrinter() const { return MCInstPrinterCtorFn != 0; }
258 /// hasMCCodeEmitter - Check if this target supports instruction encoding.
259 bool hasMCCodeEmitter() const { return MCCodeEmitterCtorFn != 0; }
261 /// hasMCObjectStreamer - Check if this target supports streaming to files.
262 bool hasMCObjectStreamer() const { return MCObjectStreamerCtorFn != 0; }
264 /// hasAsmStreamer - Check if this target supports streaming to files.
265 bool hasAsmStreamer() const { return AsmStreamerCtorFn != 0; }
268 /// @name Feature Constructors
271 /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
274 /// \arg Triple - This argument is used to determine the target machine
275 /// feature set; it should always be provided. Generally this should be
276 /// either the target triple from the module, or the target triple of the
277 /// host if that does not exist.
278 MCAsmInfo *createMCAsmInfo(StringRef Triple) const {
279 if (!MCAsmInfoCtorFn)
281 return MCAsmInfoCtorFn(*this, Triple);
284 /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
286 MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model RM,
288 CodeGenOpt::Level OL) const {
289 if (!MCCodeGenInfoCtorFn)
291 return MCCodeGenInfoCtorFn(Triple, RM, CM, OL);
294 /// createMCInstrInfo - Create a MCInstrInfo implementation.
296 MCInstrInfo *createMCInstrInfo() const {
297 if (!MCInstrInfoCtorFn)
299 return MCInstrInfoCtorFn();
302 /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
304 MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
305 if (!MCInstrAnalysisCtorFn)
307 return MCInstrAnalysisCtorFn(Info);
310 /// createMCRegInfo - Create a MCRegisterInfo implementation.
312 MCRegisterInfo *createMCRegInfo(StringRef Triple) const {
313 if (!MCRegInfoCtorFn)
315 return MCRegInfoCtorFn(Triple);
318 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
320 /// \arg Triple - This argument is used to determine the target machine
321 /// feature set; it should always be provided. Generally this should be
322 /// either the target triple from the module, or the target triple of the
323 /// host if that does not exist.
324 /// \arg CPU - This specifies the name of the target CPU.
325 /// \arg Features - This specifies the string representation of the
326 /// additional target features.
327 MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU,
328 StringRef Features) const {
329 if (!MCSubtargetInfoCtorFn)
331 return MCSubtargetInfoCtorFn(Triple, CPU, Features);
334 /// createTargetMachine - Create a target specific machine implementation
335 /// for the specified \arg Triple.
337 /// \arg Triple - This argument is used to determine the target machine
338 /// feature set; it should always be provided. Generally this should be
339 /// either the target triple from the module, or the target triple of the
340 /// host if that does not exist.
341 TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU,
342 StringRef Features, const TargetOptions &Options,
343 Reloc::Model RM = Reloc::Default,
344 CodeModel::Model CM = CodeModel::Default,
345 CodeGenOpt::Level OL = CodeGenOpt::Default) const {
346 if (!TargetMachineCtorFn)
348 return TargetMachineCtorFn(*this, Triple, CPU, Features, Options,
352 /// createMCAsmBackend - Create a target specific assembly parser.
354 /// \arg Triple - The target triple string.
355 /// \arg Backend - The target independent assembler object.
356 MCAsmBackend *createMCAsmBackend(StringRef Triple) const {
357 if (!MCAsmBackendCtorFn)
359 return MCAsmBackendCtorFn(*this, Triple);
362 /// createMCAsmLexer - Create a target specific assembly lexer.
364 MCTargetAsmLexer *createMCAsmLexer(const MCRegisterInfo &MRI,
365 const MCAsmInfo &MAI) const {
366 if (!MCAsmLexerCtorFn)
368 return MCAsmLexerCtorFn(*this, MRI, MAI);
371 /// createMCAsmParser - Create a target specific assembly parser.
373 /// \arg Parser - The target independent parser implementation to use for
374 /// parsing and lexing.
375 MCTargetAsmParser *createMCAsmParser(MCSubtargetInfo &STI,
376 MCAsmParser &Parser) const {
377 if (!MCAsmParserCtorFn)
379 return MCAsmParserCtorFn(STI, Parser);
382 /// createAsmPrinter - Create a target specific assembly printer pass. This
383 /// takes ownership of the MCStreamer object.
384 AsmPrinter *createAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) const{
385 if (!AsmPrinterCtorFn)
387 return AsmPrinterCtorFn(TM, Streamer);
390 MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI) const {
391 if (!MCDisassemblerCtorFn)
393 return MCDisassemblerCtorFn(*this, STI);
396 MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
397 const MCAsmInfo &MAI,
398 const MCInstrInfo &MII,
399 const MCRegisterInfo &MRI,
400 const MCSubtargetInfo &STI) const {
401 if (!MCInstPrinterCtorFn)
403 return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, MII, MRI, STI);
407 /// createMCCodeEmitter - Create a target specific code emitter.
408 MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
409 const MCRegisterInfo &MRI,
410 const MCSubtargetInfo &STI,
411 MCContext &Ctx) const {
412 if (!MCCodeEmitterCtorFn)
414 return MCCodeEmitterCtorFn(II, MRI, STI, Ctx);
417 /// createMCObjectStreamer - Create a target specific MCStreamer.
419 /// \arg TT - The target triple.
420 /// \arg Ctx - The target context.
421 /// \arg TAB - The target assembler backend object. Takes ownership.
422 /// \arg _OS - The stream object.
423 /// \arg _Emitter - The target independent assembler object.Takes ownership.
424 /// \arg RelaxAll - Relax all fixups?
425 /// \arg NoExecStack - Mark file as not needing a executable stack.
426 MCStreamer *createMCObjectStreamer(StringRef TT, MCContext &Ctx,
429 MCCodeEmitter *_Emitter,
431 bool NoExecStack) const {
432 if (!MCObjectStreamerCtorFn)
434 return MCObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter,
435 RelaxAll, NoExecStack);
438 /// createAsmStreamer - Create a target specific MCStreamer.
439 MCStreamer *createAsmStreamer(MCContext &Ctx,
440 formatted_raw_ostream &OS,
444 bool useDwarfDirectory,
445 MCInstPrinter *InstPrint,
448 bool ShowInst) const {
449 // AsmStreamerCtorFn is default to llvm::createAsmStreamer
450 return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useLoc, useCFI,
451 useDwarfDirectory, InstPrint, CE, TAB, ShowInst);
457 /// TargetRegistry - Generic interface to target specific features.
458 struct TargetRegistry {
460 const Target *Current;
461 explicit iterator(Target *T) : Current(T) {}
462 friend struct TargetRegistry;
464 iterator(const iterator &I) : Current(I.Current) {}
465 iterator() : Current(0) {}
467 bool operator==(const iterator &x) const {
468 return Current == x.Current;
470 bool operator!=(const iterator &x) const {
471 return !operator==(x);
474 // Iterator traversal: forward iteration only
475 iterator &operator++() { // Preincrement
476 assert(Current && "Cannot increment end iterator!");
477 Current = Current->getNext();
480 iterator operator++(int) { // Postincrement
481 iterator tmp = *this;
486 const Target &operator*() const {
487 assert(Current && "Cannot dereference end iterator!");
491 const Target *operator->() const {
496 /// printRegisteredTargetsForVersion - Print the registered targets
497 /// appropriately for inclusion in a tool's version output.
498 static void printRegisteredTargetsForVersion();
500 /// @name Registry Access
503 static iterator begin();
505 static iterator end() { return iterator(); }
507 /// lookupTarget - Lookup a target based on a target triple.
509 /// \param Triple - The triple to use for finding a target.
510 /// \param Error - On failure, an error string describing why no target was
512 static const Target *lookupTarget(const std::string &Triple,
515 /// lookupTarget - Lookup a target based on an architecture name
516 /// and a target triple. If the architecture name is non-empty,
517 /// then the lookup is done by architecture. Otherwise, the target
520 /// \param ArchName - The architecture to use for finding a target.
521 /// \param TheTriple - The triple to use for finding a target. The
522 /// triple is updated with canonical architecture name if a lookup
523 /// by architecture is done.
524 /// \param Error - On failure, an error string describing why no target was
526 static const Target *lookupTarget(const std::string &ArchName,
530 /// getClosestTargetForJIT - Pick the best target that is compatible with
531 /// the current host. If no close target can be found, this returns null
532 /// and sets the Error string to a reason.
534 /// Maintained for compatibility through 2.6.
535 static const Target *getClosestTargetForJIT(std::string &Error);
538 /// @name Target Registration
541 /// RegisterTarget - Register the given target. Attempts to register a
542 /// target which has already been registered will be ignored.
544 /// Clients are responsible for ensuring that registration doesn't occur
545 /// while another thread is attempting to access the registry. Typically
546 /// this is done by initializing all targets at program startup.
548 /// @param T - The target being registered.
549 /// @param Name - The target name. This should be a static string.
550 /// @param ShortDesc - A short target description. This should be a static
552 /// @param TQualityFn - The triple match quality computation function for
554 /// @param HasJIT - Whether the target supports JIT code
556 static void RegisterTarget(Target &T,
558 const char *ShortDesc,
559 Target::TripleMatchQualityFnTy TQualityFn,
560 bool HasJIT = false);
562 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
565 /// Clients are responsible for ensuring that registration doesn't occur
566 /// while another thread is attempting to access the registry. Typically
567 /// this is done by initializing all targets at program startup.
569 /// @param T - The target being registered.
570 /// @param Fn - A function to construct a MCAsmInfo for the target.
571 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
572 // Ignore duplicate registration.
573 if (!T.MCAsmInfoCtorFn)
574 T.MCAsmInfoCtorFn = Fn;
577 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
580 /// Clients are responsible for ensuring that registration doesn't occur
581 /// while another thread is attempting to access the registry. Typically
582 /// this is done by initializing all targets at program startup.
584 /// @param T - The target being registered.
585 /// @param Fn - A function to construct a MCCodeGenInfo for the target.
586 static void RegisterMCCodeGenInfo(Target &T,
587 Target::MCCodeGenInfoCtorFnTy Fn) {
588 // Ignore duplicate registration.
589 if (!T.MCCodeGenInfoCtorFn)
590 T.MCCodeGenInfoCtorFn = Fn;
593 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
596 /// Clients are responsible for ensuring that registration doesn't occur
597 /// while another thread is attempting to access the registry. Typically
598 /// this is done by initializing all targets at program startup.
600 /// @param T - The target being registered.
601 /// @param Fn - A function to construct a MCInstrInfo for the target.
602 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
603 // Ignore duplicate registration.
604 if (!T.MCInstrInfoCtorFn)
605 T.MCInstrInfoCtorFn = Fn;
608 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
609 /// the given target.
610 static void RegisterMCInstrAnalysis(Target &T,
611 Target::MCInstrAnalysisCtorFnTy Fn) {
612 // Ignore duplicate registration.
613 if (!T.MCInstrAnalysisCtorFn)
614 T.MCInstrAnalysisCtorFn = Fn;
617 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
620 /// Clients are responsible for ensuring that registration doesn't occur
621 /// while another thread is attempting to access the registry. Typically
622 /// this is done by initializing all targets at program startup.
624 /// @param T - The target being registered.
625 /// @param Fn - A function to construct a MCRegisterInfo for the target.
626 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
627 // Ignore duplicate registration.
628 if (!T.MCRegInfoCtorFn)
629 T.MCRegInfoCtorFn = Fn;
632 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
633 /// the given target.
635 /// Clients are responsible for ensuring that registration doesn't occur
636 /// while another thread is attempting to access the registry. Typically
637 /// this is done by initializing all targets at program startup.
639 /// @param T - The target being registered.
640 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
641 static void RegisterMCSubtargetInfo(Target &T,
642 Target::MCSubtargetInfoCtorFnTy Fn) {
643 // Ignore duplicate registration.
644 if (!T.MCSubtargetInfoCtorFn)
645 T.MCSubtargetInfoCtorFn = Fn;
648 /// RegisterTargetMachine - Register a TargetMachine implementation for the
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 a TargetMachine for the target.
657 static void RegisterTargetMachine(Target &T,
658 Target::TargetMachineCtorTy Fn) {
659 // Ignore duplicate registration.
660 if (!T.TargetMachineCtorFn)
661 T.TargetMachineCtorFn = Fn;
664 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
667 /// Clients are responsible for ensuring that registration doesn't occur
668 /// while another thread is attempting to access the registry. Typically
669 /// this is done by initializing all targets at program startup.
671 /// @param T - The target being registered.
672 /// @param Fn - A function to construct an AsmBackend for the target.
673 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
674 if (!T.MCAsmBackendCtorFn)
675 T.MCAsmBackendCtorFn = Fn;
678 /// RegisterMCAsmLexer - Register a MCTargetAsmLexer 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 MCAsmLexer for the target.
687 static void RegisterMCAsmLexer(Target &T, Target::MCAsmLexerCtorTy Fn) {
688 if (!T.MCAsmLexerCtorFn)
689 T.MCAsmLexerCtorFn = Fn;
692 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
693 /// the given target.
695 /// Clients are responsible for ensuring that registration doesn't occur
696 /// while another thread is attempting to access the registry. Typically
697 /// this is done by initializing all targets at program startup.
699 /// @param T - The target being registered.
700 /// @param Fn - A function to construct an MCTargetAsmParser for the target.
701 static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
702 if (!T.MCAsmParserCtorFn)
703 T.MCAsmParserCtorFn = Fn;
706 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
709 /// Clients are responsible for ensuring that registration doesn't occur
710 /// while another thread is attempting to access the registry. Typically
711 /// this is done by initializing all targets at program startup.
713 /// @param T - The target being registered.
714 /// @param Fn - A function to construct an AsmPrinter for the target.
715 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
716 // Ignore duplicate registration.
717 if (!T.AsmPrinterCtorFn)
718 T.AsmPrinterCtorFn = Fn;
721 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
722 /// 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 MCDisassembler for the target.
730 static void RegisterMCDisassembler(Target &T,
731 Target::MCDisassemblerCtorTy Fn) {
732 if (!T.MCDisassemblerCtorFn)
733 T.MCDisassemblerCtorFn = Fn;
736 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
739 /// Clients are responsible for ensuring that registration doesn't occur
740 /// while another thread is attempting to access the registry. Typically
741 /// this is done by initializing all targets at program startup.
743 /// @param T - The target being registered.
744 /// @param Fn - A function to construct an MCInstPrinter for the target.
745 static void RegisterMCInstPrinter(Target &T,
746 Target::MCInstPrinterCtorTy Fn) {
747 if (!T.MCInstPrinterCtorFn)
748 T.MCInstPrinterCtorFn = Fn;
751 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
754 /// Clients are responsible for ensuring that registration doesn't occur
755 /// while another thread is attempting to access the registry. Typically
756 /// this is done by initializing all targets at program startup.
758 /// @param T - The target being registered.
759 /// @param Fn - A function to construct an MCCodeEmitter for the target.
760 static void RegisterMCCodeEmitter(Target &T,
761 Target::MCCodeEmitterCtorTy Fn) {
762 if (!T.MCCodeEmitterCtorFn)
763 T.MCCodeEmitterCtorFn = Fn;
766 /// RegisterMCObjectStreamer - Register a object code MCStreamer
767 /// implementation for the given target.
769 /// Clients are responsible for ensuring that registration doesn't occur
770 /// while another thread is attempting to access the registry. Typically
771 /// this is done by initializing all targets at program startup.
773 /// @param T - The target being registered.
774 /// @param Fn - A function to construct an MCStreamer for the target.
775 static void RegisterMCObjectStreamer(Target &T,
776 Target::MCObjectStreamerCtorTy Fn) {
777 if (!T.MCObjectStreamerCtorFn)
778 T.MCObjectStreamerCtorFn = Fn;
781 /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
782 /// for the given target.
784 /// Clients are responsible for ensuring that registration doesn't occur
785 /// while another thread is attempting to access the registry. Typically
786 /// this is done by initializing all targets at program startup.
788 /// @param T - The target being registered.
789 /// @param Fn - A function to construct an MCStreamer for the target.
790 static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
791 if (T.AsmStreamerCtorFn == createAsmStreamer)
792 T.AsmStreamerCtorFn = Fn;
799 //===--------------------------------------------------------------------===//
801 /// RegisterTarget - Helper template for registering a target, for use in the
802 /// target's initialization function. Usage:
805 /// Target TheFooTarget; // The global target instance.
807 /// extern "C" void LLVMInitializeFooTargetInfo() {
808 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
810 template<Triple::ArchType TargetArchType = Triple::UnknownArch,
812 struct RegisterTarget {
813 RegisterTarget(Target &T, const char *Name, const char *Desc) {
814 TargetRegistry::RegisterTarget(T, Name, Desc,
815 &getTripleMatchQuality,
819 static unsigned getTripleMatchQuality(const std::string &TT) {
820 if (Triple(TT).getArch() == TargetArchType)
826 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
827 /// implementation. This invokes the static "Create" method on the class to
828 /// actually do the construction. Usage:
830 /// extern "C" void LLVMInitializeFooTarget() {
831 /// extern Target TheFooTarget;
832 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
834 template<class MCAsmInfoImpl>
835 struct RegisterMCAsmInfo {
836 RegisterMCAsmInfo(Target &T) {
837 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
840 static MCAsmInfo *Allocator(const Target &T, StringRef TT) {
841 return new MCAsmInfoImpl(T, TT);
846 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
847 /// implementation. This invokes the specified function to do the
848 /// construction. Usage:
850 /// extern "C" void LLVMInitializeFooTarget() {
851 /// extern Target TheFooTarget;
852 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
854 struct RegisterMCAsmInfoFn {
855 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
856 TargetRegistry::RegisterMCAsmInfo(T, Fn);
860 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
861 /// 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 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
868 template<class MCCodeGenInfoImpl>
869 struct RegisterMCCodeGenInfo {
870 RegisterMCCodeGenInfo(Target &T) {
871 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
874 static MCCodeGenInfo *Allocator(StringRef TT, Reloc::Model RM,
875 CodeModel::Model CM, CodeGenOpt::Level OL) {
876 return new MCCodeGenInfoImpl();
880 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
881 /// info implementation. This invokes the specified function to do the
882 /// construction. Usage:
884 /// extern "C" void LLVMInitializeFooTarget() {
885 /// extern Target TheFooTarget;
886 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
888 struct RegisterMCCodeGenInfoFn {
889 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
890 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
894 /// RegisterMCInstrInfo - Helper template for registering a target instruction
895 /// info implementation. This invokes the static "Create" method on the class
896 /// to actually do the construction. Usage:
898 /// extern "C" void LLVMInitializeFooTarget() {
899 /// extern Target TheFooTarget;
900 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
902 template<class MCInstrInfoImpl>
903 struct RegisterMCInstrInfo {
904 RegisterMCInstrInfo(Target &T) {
905 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
908 static MCInstrInfo *Allocator() {
909 return new MCInstrInfoImpl();
913 /// RegisterMCInstrInfoFn - Helper template for registering a target
914 /// instruction info implementation. This invokes the specified function to
915 /// do the construction. Usage:
917 /// extern "C" void LLVMInitializeFooTarget() {
918 /// extern Target TheFooTarget;
919 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
921 struct RegisterMCInstrInfoFn {
922 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
923 TargetRegistry::RegisterMCInstrInfo(T, Fn);
927 /// RegisterMCInstrAnalysis - Helper template for registering a target
928 /// instruction analyzer implementation. This invokes the static "Create"
929 /// method on the class to actually do the construction. Usage:
931 /// extern "C" void LLVMInitializeFooTarget() {
932 /// extern Target TheFooTarget;
933 /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
935 template<class MCInstrAnalysisImpl>
936 struct RegisterMCInstrAnalysis {
937 RegisterMCInstrAnalysis(Target &T) {
938 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
941 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
942 return new MCInstrAnalysisImpl(Info);
946 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
947 /// instruction analyzer implementation. This invokes the specified function
948 /// to do the construction. Usage:
950 /// extern "C" void LLVMInitializeFooTarget() {
951 /// extern Target TheFooTarget;
952 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
954 struct RegisterMCInstrAnalysisFn {
955 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
956 TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
960 /// RegisterMCRegInfo - Helper template for registering a target register info
961 /// implementation. This invokes the static "Create" method on the class to
962 /// actually do the construction. Usage:
964 /// extern "C" void LLVMInitializeFooTarget() {
965 /// extern Target TheFooTarget;
966 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
968 template<class MCRegisterInfoImpl>
969 struct RegisterMCRegInfo {
970 RegisterMCRegInfo(Target &T) {
971 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
974 static MCRegisterInfo *Allocator(StringRef TT) {
975 return new MCRegisterInfoImpl();
979 /// RegisterMCRegInfoFn - Helper template for registering a target register
980 /// info implementation. This invokes the specified function to do the
981 /// construction. Usage:
983 /// extern "C" void LLVMInitializeFooTarget() {
984 /// extern Target TheFooTarget;
985 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
987 struct RegisterMCRegInfoFn {
988 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
989 TargetRegistry::RegisterMCRegInfo(T, Fn);
993 /// RegisterMCSubtargetInfo - Helper template for registering a target
994 /// subtarget info implementation. This invokes the static "Create" method
995 /// on the class to actually do the construction. Usage:
997 /// extern "C" void LLVMInitializeFooTarget() {
998 /// extern Target TheFooTarget;
999 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
1001 template<class MCSubtargetInfoImpl>
1002 struct RegisterMCSubtargetInfo {
1003 RegisterMCSubtargetInfo(Target &T) {
1004 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
1007 static MCSubtargetInfo *Allocator(StringRef TT, StringRef CPU,
1009 return new MCSubtargetInfoImpl();
1013 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
1014 /// subtarget info implementation. This invokes the specified function to
1015 /// do the construction. Usage:
1017 /// extern "C" void LLVMInitializeFooTarget() {
1018 /// extern Target TheFooTarget;
1019 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1021 struct RegisterMCSubtargetInfoFn {
1022 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
1023 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
1027 /// RegisterTargetMachine - Helper template for registering a target machine
1028 /// implementation, for use in the target machine initialization
1029 /// function. Usage:
1031 /// extern "C" void LLVMInitializeFooTarget() {
1032 /// extern Target TheFooTarget;
1033 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1035 template<class TargetMachineImpl>
1036 struct RegisterTargetMachine {
1037 RegisterTargetMachine(Target &T) {
1038 TargetRegistry::RegisterTargetMachine(T, &Allocator);
1042 static TargetMachine *Allocator(const Target &T, StringRef TT,
1043 StringRef CPU, StringRef FS,
1044 const TargetOptions &Options,
1046 CodeModel::Model CM,
1047 CodeGenOpt::Level OL) {
1048 return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
1052 /// RegisterMCAsmBackend - Helper template for registering a target specific
1053 /// assembler backend. Usage:
1055 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1056 /// extern Target TheFooTarget;
1057 /// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1059 template<class MCAsmBackendImpl>
1060 struct RegisterMCAsmBackend {
1061 RegisterMCAsmBackend(Target &T) {
1062 TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1066 static MCAsmBackend *Allocator(const Target &T, StringRef Triple) {
1067 return new MCAsmBackendImpl(T, Triple);
1071 /// RegisterMCAsmLexer - Helper template for registering a target specific
1072 /// assembly lexer, for use in the target machine initialization
1073 /// function. Usage:
1075 /// extern "C" void LLVMInitializeFooMCAsmLexer() {
1076 /// extern Target TheFooTarget;
1077 /// RegisterMCAsmLexer<FooMCAsmLexer> X(TheFooTarget);
1079 template<class MCAsmLexerImpl>
1080 struct RegisterMCAsmLexer {
1081 RegisterMCAsmLexer(Target &T) {
1082 TargetRegistry::RegisterMCAsmLexer(T, &Allocator);
1086 static MCTargetAsmLexer *Allocator(const Target &T,
1087 const MCRegisterInfo &MRI,
1088 const MCAsmInfo &MAI) {
1089 return new MCAsmLexerImpl(T, MRI, MAI);
1093 /// RegisterMCAsmParser - Helper template for registering a target specific
1094 /// assembly parser, for use in the target machine initialization
1095 /// function. Usage:
1097 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1098 /// extern Target TheFooTarget;
1099 /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1101 template<class MCAsmParserImpl>
1102 struct RegisterMCAsmParser {
1103 RegisterMCAsmParser(Target &T) {
1104 TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1108 static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P) {
1109 return new MCAsmParserImpl(STI, P);
1113 /// RegisterAsmPrinter - Helper template for registering a target specific
1114 /// assembly printer, for use in the target machine initialization
1115 /// function. Usage:
1117 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1118 /// extern Target TheFooTarget;
1119 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1121 template<class AsmPrinterImpl>
1122 struct RegisterAsmPrinter {
1123 RegisterAsmPrinter(Target &T) {
1124 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1128 static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) {
1129 return new AsmPrinterImpl(TM, Streamer);
1133 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1134 /// machine code emitter, for use in the target initialization
1135 /// function. Usage:
1137 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1138 /// extern Target TheFooTarget;
1139 /// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1141 template<class MCCodeEmitterImpl>
1142 struct RegisterMCCodeEmitter {
1143 RegisterMCCodeEmitter(Target &T) {
1144 TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1148 static MCCodeEmitter *Allocator(const MCInstrInfo &II,
1149 const MCRegisterInfo &MRI,
1150 const MCSubtargetInfo &STI,
1152 return new MCCodeEmitterImpl();