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,
99 typedef MCTargetAsmLexer *(*MCAsmLexerCtorTy)(const Target &T,
100 const MCRegisterInfo &MRI,
101 const MCAsmInfo &MAI);
102 typedef MCTargetAsmParser *(*MCAsmParserCtorTy)(MCSubtargetInfo &STI,
104 typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T,
105 const MCSubtargetInfo &STI);
106 typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
107 unsigned SyntaxVariant,
108 const MCAsmInfo &MAI,
109 const MCInstrInfo &MII,
110 const MCRegisterInfo &MRI,
111 const MCSubtargetInfo &STI);
112 typedef MCCodeEmitter *(*MCCodeEmitterCtorTy)(const MCInstrInfo &II,
113 const MCRegisterInfo &MRI,
114 const MCSubtargetInfo &STI,
116 typedef MCStreamer *(*MCObjectStreamerCtorTy)(const Target &T,
121 MCCodeEmitter *_Emitter,
124 typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx,
125 formatted_raw_ostream &OS,
129 bool useDwarfDirectory,
130 MCInstPrinter *InstPrint,
136 /// Next - The next registered target in the linked list, maintained by the
140 /// TripleMatchQualityFn - The target function for rating the match quality
142 TripleMatchQualityFnTy TripleMatchQualityFn;
144 /// Name - The target name.
147 /// ShortDesc - A short description of the target.
148 const char *ShortDesc;
150 /// HasJIT - Whether this target supports the JIT.
153 /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
155 MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
157 /// MCCodeGenInfoCtorFn - Constructor function for this target's
158 /// MCCodeGenInfo, if registered.
159 MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn;
161 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
163 MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
165 /// MCInstrAnalysisCtorFn - Constructor function for this target's
166 /// MCInstrAnalysis, if registered.
167 MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
169 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
171 MCRegInfoCtorFnTy MCRegInfoCtorFn;
173 /// MCSubtargetInfoCtorFn - Constructor function for this target's
174 /// MCSubtargetInfo, if registered.
175 MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
177 /// TargetMachineCtorFn - Construction function for this target's
178 /// TargetMachine, if registered.
179 TargetMachineCtorTy TargetMachineCtorFn;
181 /// MCAsmBackendCtorFn - Construction function for this target's
182 /// MCAsmBackend, if registered.
183 MCAsmBackendCtorTy MCAsmBackendCtorFn;
185 /// MCAsmLexerCtorFn - Construction function for this target's
186 /// MCTargetAsmLexer, if registered.
187 MCAsmLexerCtorTy MCAsmLexerCtorFn;
189 /// MCAsmParserCtorFn - Construction function for this target's
190 /// MCTargetAsmParser, if registered.
191 MCAsmParserCtorTy MCAsmParserCtorFn;
193 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
195 AsmPrinterCtorTy AsmPrinterCtorFn;
197 /// MCDisassemblerCtorFn - Construction function for this target's
198 /// MCDisassembler, if registered.
199 MCDisassemblerCtorTy MCDisassemblerCtorFn;
201 /// MCInstPrinterCtorFn - Construction function for this target's
202 /// MCInstPrinter, if registered.
203 MCInstPrinterCtorTy MCInstPrinterCtorFn;
205 /// MCCodeEmitterCtorFn - Construction function for this target's
206 /// CodeEmitter, if registered.
207 MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
209 /// MCObjectStreamerCtorFn - Construction function for this target's
210 /// MCObjectStreamer, if registered.
211 MCObjectStreamerCtorTy MCObjectStreamerCtorFn;
213 /// AsmStreamerCtorFn - Construction function for this target's
214 /// AsmStreamer, if registered (default = llvm::createAsmStreamer).
215 AsmStreamerCtorTy AsmStreamerCtorFn;
218 Target() : AsmStreamerCtorFn(llvm::createAsmStreamer) {}
220 /// @name Target Information
223 // getNext - Return the next registered target.
224 const Target *getNext() const { return Next; }
226 /// getName - Get the target name.
227 const char *getName() const { return Name; }
229 /// getShortDescription - Get a short description of the target.
230 const char *getShortDescription() const { return ShortDesc; }
233 /// @name Feature Predicates
236 /// hasJIT - Check if this targets supports the just-in-time compilation.
237 bool hasJIT() const { return HasJIT; }
239 /// hasTargetMachine - Check if this target supports code generation.
240 bool hasTargetMachine() const { return TargetMachineCtorFn != 0; }
242 /// hasMCAsmBackend - Check if this target supports .o generation.
243 bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != 0; }
245 /// hasMCAsmLexer - Check if this target supports .s lexing.
246 bool hasMCAsmLexer() const { return MCAsmLexerCtorFn != 0; }
248 /// hasAsmParser - Check if this target supports .s parsing.
249 bool hasMCAsmParser() const { return MCAsmParserCtorFn != 0; }
251 /// hasAsmPrinter - Check if this target supports .s printing.
252 bool hasAsmPrinter() const { return AsmPrinterCtorFn != 0; }
254 /// hasMCDisassembler - Check if this target has a disassembler.
255 bool hasMCDisassembler() const { return MCDisassemblerCtorFn != 0; }
257 /// hasMCInstPrinter - Check if this target has an instruction printer.
258 bool hasMCInstPrinter() const { return MCInstPrinterCtorFn != 0; }
260 /// hasMCCodeEmitter - Check if this target supports instruction encoding.
261 bool hasMCCodeEmitter() const { return MCCodeEmitterCtorFn != 0; }
263 /// hasMCObjectStreamer - Check if this target supports streaming to files.
264 bool hasMCObjectStreamer() const { return MCObjectStreamerCtorFn != 0; }
266 /// hasAsmStreamer - Check if this target supports streaming to files.
267 bool hasAsmStreamer() const { return AsmStreamerCtorFn != 0; }
270 /// @name Feature Constructors
273 /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
276 /// \param Triple This argument is used to determine the target machine
277 /// feature set; it should always be provided. Generally this should be
278 /// either the target triple from the module, or the target triple of the
279 /// host if that does not exist.
280 MCAsmInfo *createMCAsmInfo(StringRef Triple) const {
281 if (!MCAsmInfoCtorFn)
283 return MCAsmInfoCtorFn(*this, Triple);
286 /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
288 MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model RM,
290 CodeGenOpt::Level OL) const {
291 if (!MCCodeGenInfoCtorFn)
293 return MCCodeGenInfoCtorFn(Triple, RM, CM, OL);
296 /// createMCInstrInfo - Create a MCInstrInfo implementation.
298 MCInstrInfo *createMCInstrInfo() const {
299 if (!MCInstrInfoCtorFn)
301 return MCInstrInfoCtorFn();
304 /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
306 MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
307 if (!MCInstrAnalysisCtorFn)
309 return MCInstrAnalysisCtorFn(Info);
312 /// createMCRegInfo - Create a MCRegisterInfo implementation.
314 MCRegisterInfo *createMCRegInfo(StringRef Triple) const {
315 if (!MCRegInfoCtorFn)
317 return MCRegInfoCtorFn(Triple);
320 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
322 /// \param Triple This argument is used to determine the target machine
323 /// feature set; it should always be provided. Generally this should be
324 /// either the target triple from the module, or the target triple of the
325 /// host if that does not exist.
326 /// \param CPU This specifies the name of the target CPU.
327 /// \param Features This specifies the string representation of the
328 /// additional target features.
329 MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU,
330 StringRef Features) const {
331 if (!MCSubtargetInfoCtorFn)
333 return MCSubtargetInfoCtorFn(Triple, CPU, Features);
336 /// createTargetMachine - Create a target specific machine implementation
337 /// for the specified \p Triple.
339 /// \param Triple This argument is used to determine the target machine
340 /// feature set; it should always be provided. Generally this should be
341 /// either the target triple from the module, or the target triple of the
342 /// host if that does not exist.
343 TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU,
344 StringRef Features, const TargetOptions &Options,
345 Reloc::Model RM = Reloc::Default,
346 CodeModel::Model CM = CodeModel::Default,
347 CodeGenOpt::Level OL = CodeGenOpt::Default) const {
348 if (!TargetMachineCtorFn)
350 return TargetMachineCtorFn(*this, Triple, CPU, Features, Options,
354 /// createMCAsmBackend - Create a target specific assembly parser.
356 /// \param Triple The target triple string.
357 MCAsmBackend *createMCAsmBackend(StringRef Triple, StringRef CPU) const {
358 if (!MCAsmBackendCtorFn)
360 return MCAsmBackendCtorFn(*this, Triple, CPU);
363 /// createMCAsmLexer - Create a target specific assembly lexer.
365 MCTargetAsmLexer *createMCAsmLexer(const MCRegisterInfo &MRI,
366 const MCAsmInfo &MAI) const {
367 if (!MCAsmLexerCtorFn)
369 return MCAsmLexerCtorFn(*this, MRI, MAI);
372 /// createMCAsmParser - Create a target specific assembly parser.
374 /// \param Parser The target independent parser implementation to use for
375 /// parsing and lexing.
376 MCTargetAsmParser *createMCAsmParser(MCSubtargetInfo &STI,
377 MCAsmParser &Parser) const {
378 if (!MCAsmParserCtorFn)
380 return MCAsmParserCtorFn(STI, Parser);
383 /// createAsmPrinter - Create a target specific assembly printer pass. This
384 /// takes ownership of the MCStreamer object.
385 AsmPrinter *createAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) const{
386 if (!AsmPrinterCtorFn)
388 return AsmPrinterCtorFn(TM, Streamer);
391 MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI) const {
392 if (!MCDisassemblerCtorFn)
394 return MCDisassemblerCtorFn(*this, STI);
397 MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
398 const MCAsmInfo &MAI,
399 const MCInstrInfo &MII,
400 const MCRegisterInfo &MRI,
401 const MCSubtargetInfo &STI) const {
402 if (!MCInstPrinterCtorFn)
404 return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, MII, MRI, STI);
408 /// createMCCodeEmitter - Create a target specific code emitter.
409 MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
410 const MCRegisterInfo &MRI,
411 const MCSubtargetInfo &STI,
412 MCContext &Ctx) const {
413 if (!MCCodeEmitterCtorFn)
415 return MCCodeEmitterCtorFn(II, MRI, STI, Ctx);
418 /// createMCObjectStreamer - Create a target specific MCStreamer.
420 /// \param TT The target triple.
421 /// \param Ctx The target context.
422 /// \param TAB The target assembler backend object. Takes ownership.
423 /// \param _OS The stream object.
424 /// \param _Emitter The target independent assembler object.Takes ownership.
425 /// \param RelaxAll Relax all fixups?
426 /// \param NoExecStack Mark file as not needing a executable stack.
427 MCStreamer *createMCObjectStreamer(StringRef TT, MCContext &Ctx,
430 MCCodeEmitter *_Emitter,
432 bool NoExecStack) const {
433 if (!MCObjectStreamerCtorFn)
435 return MCObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter,
436 RelaxAll, NoExecStack);
439 /// createAsmStreamer - Create a target specific MCStreamer.
440 MCStreamer *createAsmStreamer(MCContext &Ctx,
441 formatted_raw_ostream &OS,
445 bool useDwarfDirectory,
446 MCInstPrinter *InstPrint,
449 bool ShowInst) const {
450 // AsmStreamerCtorFn is default to llvm::createAsmStreamer
451 return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useLoc, useCFI,
452 useDwarfDirectory, InstPrint, CE, TAB, ShowInst);
458 /// TargetRegistry - Generic interface to target specific features.
459 struct TargetRegistry {
461 const Target *Current;
462 explicit iterator(Target *T) : Current(T) {}
463 friend struct TargetRegistry;
465 iterator(const iterator &I) : Current(I.Current) {}
466 iterator() : Current(0) {}
468 bool operator==(const iterator &x) const {
469 return Current == x.Current;
471 bool operator!=(const iterator &x) const {
472 return !operator==(x);
475 // Iterator traversal: forward iteration only
476 iterator &operator++() { // Preincrement
477 assert(Current && "Cannot increment end iterator!");
478 Current = Current->getNext();
481 iterator operator++(int) { // Postincrement
482 iterator tmp = *this;
487 const Target &operator*() const {
488 assert(Current && "Cannot dereference end iterator!");
492 const Target *operator->() const {
497 /// printRegisteredTargetsForVersion - Print the registered targets
498 /// appropriately for inclusion in a tool's version output.
499 static void printRegisteredTargetsForVersion();
501 /// @name Registry Access
504 static iterator begin();
506 static iterator end() { return iterator(); }
508 /// lookupTarget - Lookup a target based on a target triple.
510 /// \param Triple - The triple to use for finding a target.
511 /// \param Error - On failure, an error string describing why no target was
513 static const Target *lookupTarget(const std::string &Triple,
516 /// lookupTarget - Lookup a target based on an architecture name
517 /// and a target triple. If the architecture name is non-empty,
518 /// then the lookup is done by architecture. Otherwise, the target
521 /// \param ArchName - The architecture to use for finding a target.
522 /// \param TheTriple - The triple to use for finding a target. The
523 /// triple is updated with canonical architecture name if a lookup
524 /// by architecture is done.
525 /// \param Error - On failure, an error string describing why no target was
527 static const Target *lookupTarget(const std::string &ArchName,
531 /// getClosestTargetForJIT - Pick the best target that is compatible with
532 /// the current host. If no close target can be found, this returns null
533 /// and sets the Error string to a reason.
535 /// Maintained for compatibility through 2.6.
536 static const Target *getClosestTargetForJIT(std::string &Error);
539 /// @name Target Registration
542 /// RegisterTarget - Register the given target. Attempts to register a
543 /// target which has already been registered will be ignored.
545 /// Clients are responsible for ensuring that registration doesn't occur
546 /// while another thread is attempting to access the registry. Typically
547 /// this is done by initializing all targets at program startup.
549 /// @param T - The target being registered.
550 /// @param Name - The target name. This should be a static string.
551 /// @param ShortDesc - A short target description. This should be a static
553 /// @param TQualityFn - The triple match quality computation function for
555 /// @param HasJIT - Whether the target supports JIT code
557 static void RegisterTarget(Target &T,
559 const char *ShortDesc,
560 Target::TripleMatchQualityFnTy TQualityFn,
561 bool HasJIT = false);
563 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
566 /// Clients are responsible for ensuring that registration doesn't occur
567 /// while another thread is attempting to access the registry. Typically
568 /// this is done by initializing all targets at program startup.
570 /// @param T - The target being registered.
571 /// @param Fn - A function to construct a MCAsmInfo for the target.
572 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
573 // Ignore duplicate registration.
574 if (!T.MCAsmInfoCtorFn)
575 T.MCAsmInfoCtorFn = Fn;
578 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
581 /// Clients are responsible for ensuring that registration doesn't occur
582 /// while another thread is attempting to access the registry. Typically
583 /// this is done by initializing all targets at program startup.
585 /// @param T - The target being registered.
586 /// @param Fn - A function to construct a MCCodeGenInfo for the target.
587 static void RegisterMCCodeGenInfo(Target &T,
588 Target::MCCodeGenInfoCtorFnTy Fn) {
589 // Ignore duplicate registration.
590 if (!T.MCCodeGenInfoCtorFn)
591 T.MCCodeGenInfoCtorFn = Fn;
594 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
597 /// Clients are responsible for ensuring that registration doesn't occur
598 /// while another thread is attempting to access the registry. Typically
599 /// this is done by initializing all targets at program startup.
601 /// @param T - The target being registered.
602 /// @param Fn - A function to construct a MCInstrInfo for the target.
603 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
604 // Ignore duplicate registration.
605 if (!T.MCInstrInfoCtorFn)
606 T.MCInstrInfoCtorFn = Fn;
609 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
610 /// the given target.
611 static void RegisterMCInstrAnalysis(Target &T,
612 Target::MCInstrAnalysisCtorFnTy Fn) {
613 // Ignore duplicate registration.
614 if (!T.MCInstrAnalysisCtorFn)
615 T.MCInstrAnalysisCtorFn = Fn;
618 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
621 /// Clients are responsible for ensuring that registration doesn't occur
622 /// while another thread is attempting to access the registry. Typically
623 /// this is done by initializing all targets at program startup.
625 /// @param T - The target being registered.
626 /// @param Fn - A function to construct a MCRegisterInfo for the target.
627 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
628 // Ignore duplicate registration.
629 if (!T.MCRegInfoCtorFn)
630 T.MCRegInfoCtorFn = Fn;
633 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
634 /// the given target.
636 /// Clients are responsible for ensuring that registration doesn't occur
637 /// while another thread is attempting to access the registry. Typically
638 /// this is done by initializing all targets at program startup.
640 /// @param T - The target being registered.
641 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
642 static void RegisterMCSubtargetInfo(Target &T,
643 Target::MCSubtargetInfoCtorFnTy Fn) {
644 // Ignore duplicate registration.
645 if (!T.MCSubtargetInfoCtorFn)
646 T.MCSubtargetInfoCtorFn = Fn;
649 /// RegisterTargetMachine - Register a TargetMachine implementation for the
652 /// Clients are responsible for ensuring that registration doesn't occur
653 /// while another thread is attempting to access the registry. Typically
654 /// this is done by initializing all targets at program startup.
656 /// @param T - The target being registered.
657 /// @param Fn - A function to construct a TargetMachine for the target.
658 static void RegisterTargetMachine(Target &T,
659 Target::TargetMachineCtorTy Fn) {
660 // Ignore duplicate registration.
661 if (!T.TargetMachineCtorFn)
662 T.TargetMachineCtorFn = Fn;
665 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
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 AsmBackend for the target.
674 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
675 if (!T.MCAsmBackendCtorFn)
676 T.MCAsmBackendCtorFn = Fn;
679 /// RegisterMCAsmLexer - Register a MCTargetAsmLexer implementation for the
682 /// Clients are responsible for ensuring that registration doesn't occur
683 /// while another thread is attempting to access the registry. Typically
684 /// this is done by initializing all targets at program startup.
686 /// @param T - The target being registered.
687 /// @param Fn - A function to construct an MCAsmLexer for the target.
688 static void RegisterMCAsmLexer(Target &T, Target::MCAsmLexerCtorTy Fn) {
689 if (!T.MCAsmLexerCtorFn)
690 T.MCAsmLexerCtorFn = Fn;
693 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
694 /// the given target.
696 /// Clients are responsible for ensuring that registration doesn't occur
697 /// while another thread is attempting to access the registry. Typically
698 /// this is done by initializing all targets at program startup.
700 /// @param T - The target being registered.
701 /// @param Fn - A function to construct an MCTargetAsmParser for the target.
702 static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
703 if (!T.MCAsmParserCtorFn)
704 T.MCAsmParserCtorFn = Fn;
707 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
710 /// Clients are responsible for ensuring that registration doesn't occur
711 /// while another thread is attempting to access the registry. Typically
712 /// this is done by initializing all targets at program startup.
714 /// @param T - The target being registered.
715 /// @param Fn - A function to construct an AsmPrinter for the target.
716 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
717 // Ignore duplicate registration.
718 if (!T.AsmPrinterCtorFn)
719 T.AsmPrinterCtorFn = Fn;
722 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
723 /// the given target.
725 /// Clients are responsible for ensuring that registration doesn't occur
726 /// while another thread is attempting to access the registry. Typically
727 /// this is done by initializing all targets at program startup.
729 /// @param T - The target being registered.
730 /// @param Fn - A function to construct an MCDisassembler for the target.
731 static void RegisterMCDisassembler(Target &T,
732 Target::MCDisassemblerCtorTy Fn) {
733 if (!T.MCDisassemblerCtorFn)
734 T.MCDisassemblerCtorFn = Fn;
737 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
740 /// Clients are responsible for ensuring that registration doesn't occur
741 /// while another thread is attempting to access the registry. Typically
742 /// this is done by initializing all targets at program startup.
744 /// @param T - The target being registered.
745 /// @param Fn - A function to construct an MCInstPrinter for the target.
746 static void RegisterMCInstPrinter(Target &T,
747 Target::MCInstPrinterCtorTy Fn) {
748 if (!T.MCInstPrinterCtorFn)
749 T.MCInstPrinterCtorFn = Fn;
752 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
755 /// Clients are responsible for ensuring that registration doesn't occur
756 /// while another thread is attempting to access the registry. Typically
757 /// this is done by initializing all targets at program startup.
759 /// @param T - The target being registered.
760 /// @param Fn - A function to construct an MCCodeEmitter for the target.
761 static void RegisterMCCodeEmitter(Target &T,
762 Target::MCCodeEmitterCtorTy Fn) {
763 if (!T.MCCodeEmitterCtorFn)
764 T.MCCodeEmitterCtorFn = Fn;
767 /// RegisterMCObjectStreamer - Register a object code MCStreamer
768 /// implementation for the given target.
770 /// Clients are responsible for ensuring that registration doesn't occur
771 /// while another thread is attempting to access the registry. Typically
772 /// this is done by initializing all targets at program startup.
774 /// @param T - The target being registered.
775 /// @param Fn - A function to construct an MCStreamer for the target.
776 static void RegisterMCObjectStreamer(Target &T,
777 Target::MCObjectStreamerCtorTy Fn) {
778 if (!T.MCObjectStreamerCtorFn)
779 T.MCObjectStreamerCtorFn = Fn;
782 /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
783 /// for the given target.
785 /// Clients are responsible for ensuring that registration doesn't occur
786 /// while another thread is attempting to access the registry. Typically
787 /// this is done by initializing all targets at program startup.
789 /// @param T - The target being registered.
790 /// @param Fn - A function to construct an MCStreamer for the target.
791 static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
792 if (T.AsmStreamerCtorFn == createAsmStreamer)
793 T.AsmStreamerCtorFn = Fn;
800 //===--------------------------------------------------------------------===//
802 /// RegisterTarget - Helper template for registering a target, for use in the
803 /// target's initialization function. Usage:
806 /// Target TheFooTarget; // The global target instance.
808 /// extern "C" void LLVMInitializeFooTargetInfo() {
809 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
811 template<Triple::ArchType TargetArchType = Triple::UnknownArch,
813 struct RegisterTarget {
814 RegisterTarget(Target &T, const char *Name, const char *Desc) {
815 TargetRegistry::RegisterTarget(T, Name, Desc,
816 &getTripleMatchQuality,
820 static unsigned getTripleMatchQuality(const std::string &TT) {
821 if (Triple(TT).getArch() == TargetArchType)
827 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
828 /// implementation. This invokes the static "Create" method on the class to
829 /// actually do the construction. Usage:
831 /// extern "C" void LLVMInitializeFooTarget() {
832 /// extern Target TheFooTarget;
833 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
835 template<class MCAsmInfoImpl>
836 struct RegisterMCAsmInfo {
837 RegisterMCAsmInfo(Target &T) {
838 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
841 static MCAsmInfo *Allocator(const Target &T, StringRef TT) {
842 return new MCAsmInfoImpl(T, TT);
847 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
848 /// implementation. This invokes the specified function to do the
849 /// construction. Usage:
851 /// extern "C" void LLVMInitializeFooTarget() {
852 /// extern Target TheFooTarget;
853 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
855 struct RegisterMCAsmInfoFn {
856 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
857 TargetRegistry::RegisterMCAsmInfo(T, Fn);
861 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
862 /// implementation. This invokes the static "Create" method on the class
863 /// to actually do the construction. Usage:
865 /// extern "C" void LLVMInitializeFooTarget() {
866 /// extern Target TheFooTarget;
867 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
869 template<class MCCodeGenInfoImpl>
870 struct RegisterMCCodeGenInfo {
871 RegisterMCCodeGenInfo(Target &T) {
872 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
875 static MCCodeGenInfo *Allocator(StringRef TT, Reloc::Model RM,
876 CodeModel::Model CM, CodeGenOpt::Level OL) {
877 return new MCCodeGenInfoImpl();
881 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
882 /// info implementation. This invokes the specified function to do the
883 /// construction. Usage:
885 /// extern "C" void LLVMInitializeFooTarget() {
886 /// extern Target TheFooTarget;
887 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
889 struct RegisterMCCodeGenInfoFn {
890 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
891 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
895 /// RegisterMCInstrInfo - Helper template for registering a target instruction
896 /// info implementation. This invokes the static "Create" method on the class
897 /// to actually do the construction. Usage:
899 /// extern "C" void LLVMInitializeFooTarget() {
900 /// extern Target TheFooTarget;
901 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
903 template<class MCInstrInfoImpl>
904 struct RegisterMCInstrInfo {
905 RegisterMCInstrInfo(Target &T) {
906 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
909 static MCInstrInfo *Allocator() {
910 return new MCInstrInfoImpl();
914 /// RegisterMCInstrInfoFn - Helper template for registering a target
915 /// instruction info implementation. This invokes the specified function to
916 /// do the construction. Usage:
918 /// extern "C" void LLVMInitializeFooTarget() {
919 /// extern Target TheFooTarget;
920 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
922 struct RegisterMCInstrInfoFn {
923 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
924 TargetRegistry::RegisterMCInstrInfo(T, Fn);
928 /// RegisterMCInstrAnalysis - Helper template for registering a target
929 /// instruction analyzer implementation. This invokes the static "Create"
930 /// method on the class to actually do the construction. Usage:
932 /// extern "C" void LLVMInitializeFooTarget() {
933 /// extern Target TheFooTarget;
934 /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
936 template<class MCInstrAnalysisImpl>
937 struct RegisterMCInstrAnalysis {
938 RegisterMCInstrAnalysis(Target &T) {
939 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
942 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
943 return new MCInstrAnalysisImpl(Info);
947 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
948 /// instruction analyzer implementation. This invokes the specified function
949 /// to do the construction. Usage:
951 /// extern "C" void LLVMInitializeFooTarget() {
952 /// extern Target TheFooTarget;
953 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
955 struct RegisterMCInstrAnalysisFn {
956 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
957 TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
961 /// RegisterMCRegInfo - Helper template for registering a target register info
962 /// implementation. This invokes the static "Create" method on the class to
963 /// actually do the construction. Usage:
965 /// extern "C" void LLVMInitializeFooTarget() {
966 /// extern Target TheFooTarget;
967 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
969 template<class MCRegisterInfoImpl>
970 struct RegisterMCRegInfo {
971 RegisterMCRegInfo(Target &T) {
972 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
975 static MCRegisterInfo *Allocator(StringRef TT) {
976 return new MCRegisterInfoImpl();
980 /// RegisterMCRegInfoFn - Helper template for registering a target register
981 /// info implementation. This invokes the specified function to do the
982 /// construction. Usage:
984 /// extern "C" void LLVMInitializeFooTarget() {
985 /// extern Target TheFooTarget;
986 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
988 struct RegisterMCRegInfoFn {
989 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
990 TargetRegistry::RegisterMCRegInfo(T, Fn);
994 /// RegisterMCSubtargetInfo - Helper template for registering a target
995 /// subtarget info implementation. This invokes the static "Create" method
996 /// on the class to actually do the construction. Usage:
998 /// extern "C" void LLVMInitializeFooTarget() {
999 /// extern Target TheFooTarget;
1000 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
1002 template<class MCSubtargetInfoImpl>
1003 struct RegisterMCSubtargetInfo {
1004 RegisterMCSubtargetInfo(Target &T) {
1005 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
1008 static MCSubtargetInfo *Allocator(StringRef TT, StringRef CPU,
1010 return new MCSubtargetInfoImpl();
1014 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
1015 /// subtarget info implementation. This invokes the specified function to
1016 /// do the construction. Usage:
1018 /// extern "C" void LLVMInitializeFooTarget() {
1019 /// extern Target TheFooTarget;
1020 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1022 struct RegisterMCSubtargetInfoFn {
1023 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
1024 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
1028 /// RegisterTargetMachine - Helper template for registering a target machine
1029 /// implementation, for use in the target machine initialization
1030 /// function. Usage:
1032 /// extern "C" void LLVMInitializeFooTarget() {
1033 /// extern Target TheFooTarget;
1034 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1036 template<class TargetMachineImpl>
1037 struct RegisterTargetMachine {
1038 RegisterTargetMachine(Target &T) {
1039 TargetRegistry::RegisterTargetMachine(T, &Allocator);
1043 static TargetMachine *Allocator(const Target &T, StringRef TT,
1044 StringRef CPU, StringRef FS,
1045 const TargetOptions &Options,
1047 CodeModel::Model CM,
1048 CodeGenOpt::Level OL) {
1049 return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
1053 /// RegisterMCAsmBackend - Helper template for registering a target specific
1054 /// assembler backend. Usage:
1056 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1057 /// extern Target TheFooTarget;
1058 /// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1060 template<class MCAsmBackendImpl>
1061 struct RegisterMCAsmBackend {
1062 RegisterMCAsmBackend(Target &T) {
1063 TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1067 static MCAsmBackend *Allocator(const Target &T, StringRef Triple,
1069 return new MCAsmBackendImpl(T, Triple, CPU);
1073 /// RegisterMCAsmLexer - Helper template for registering a target specific
1074 /// assembly lexer, for use in the target machine initialization
1075 /// function. Usage:
1077 /// extern "C" void LLVMInitializeFooMCAsmLexer() {
1078 /// extern Target TheFooTarget;
1079 /// RegisterMCAsmLexer<FooMCAsmLexer> X(TheFooTarget);
1081 template<class MCAsmLexerImpl>
1082 struct RegisterMCAsmLexer {
1083 RegisterMCAsmLexer(Target &T) {
1084 TargetRegistry::RegisterMCAsmLexer(T, &Allocator);
1088 static MCTargetAsmLexer *Allocator(const Target &T,
1089 const MCRegisterInfo &MRI,
1090 const MCAsmInfo &MAI) {
1091 return new MCAsmLexerImpl(T, MRI, MAI);
1095 /// RegisterMCAsmParser - Helper template for registering a target specific
1096 /// assembly parser, for use in the target machine initialization
1097 /// function. Usage:
1099 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1100 /// extern Target TheFooTarget;
1101 /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1103 template<class MCAsmParserImpl>
1104 struct RegisterMCAsmParser {
1105 RegisterMCAsmParser(Target &T) {
1106 TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1110 static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P) {
1111 return new MCAsmParserImpl(STI, P);
1115 /// RegisterAsmPrinter - Helper template for registering a target specific
1116 /// assembly printer, for use in the target machine initialization
1117 /// function. Usage:
1119 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1120 /// extern Target TheFooTarget;
1121 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1123 template<class AsmPrinterImpl>
1124 struct RegisterAsmPrinter {
1125 RegisterAsmPrinter(Target &T) {
1126 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1130 static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) {
1131 return new AsmPrinterImpl(TM, Streamer);
1135 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1136 /// machine code emitter, for use in the target initialization
1137 /// function. Usage:
1139 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1140 /// extern Target TheFooTarget;
1141 /// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1143 template<class MCCodeEmitterImpl>
1144 struct RegisterMCCodeEmitter {
1145 RegisterMCCodeEmitter(Target &T) {
1146 TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1150 static MCCodeEmitter *Allocator(const MCInstrInfo &II,
1151 const MCRegisterInfo &MRI,
1152 const MCSubtargetInfo &STI,
1154 return new MCCodeEmitterImpl();