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 bool useDwarfDirectory,
54 MCInstPrinter *InstPrint,
59 /// Target - Wrapper for Target specific information.
61 /// For registration purposes, this is a POD type so that targets can be
62 /// registered without the use of static constructors.
64 /// Targets should implement a single global instance of this class (which
65 /// will be zero initialized), and pass that instance to the TargetRegistry as
66 /// part of their initialization.
69 friend struct TargetRegistry;
71 typedef unsigned (*TripleMatchQualityFnTy)(const std::string &TT);
73 typedef MCAsmInfo *(*MCAsmInfoCtorFnTy)(const Target &T,
75 typedef MCCodeGenInfo *(*MCCodeGenInfoCtorFnTy)(StringRef TT,
78 CodeGenOpt::Level OL);
79 typedef MCInstrInfo *(*MCInstrInfoCtorFnTy)(void);
80 typedef MCInstrAnalysis *(*MCInstrAnalysisCtorFnTy)(const MCInstrInfo*Info);
81 typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(StringRef TT);
82 typedef MCSubtargetInfo *(*MCSubtargetInfoCtorFnTy)(StringRef TT,
85 typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T,
91 CodeGenOpt::Level OL);
92 typedef AsmPrinter *(*AsmPrinterCtorTy)(TargetMachine &TM,
93 MCStreamer &Streamer);
94 typedef MCAsmBackend *(*MCAsmBackendCtorTy)(const Target &T, StringRef TT);
95 typedef MCTargetAsmLexer *(*MCAsmLexerCtorTy)(const Target &T,
96 const MCRegisterInfo &MRI,
97 const MCAsmInfo &MAI);
98 typedef MCTargetAsmParser *(*MCAsmParserCtorTy)(MCSubtargetInfo &STI,
100 typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T,
101 const MCSubtargetInfo &STI);
102 typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
103 unsigned SyntaxVariant,
104 const MCAsmInfo &MAI,
105 const MCSubtargetInfo &STI);
106 typedef MCCodeEmitter *(*MCCodeEmitterCtorTy)(const MCInstrInfo &II,
107 const MCSubtargetInfo &STI,
109 typedef MCStreamer *(*MCObjectStreamerCtorTy)(const Target &T,
114 MCCodeEmitter *_Emitter,
117 typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx,
118 formatted_raw_ostream &OS,
122 bool useDwarfDirectory,
123 MCInstPrinter *InstPrint,
129 /// Next - The next registered target in the linked list, maintained by the
133 /// TripleMatchQualityFn - The target function for rating the match quality
135 TripleMatchQualityFnTy TripleMatchQualityFn;
137 /// Name - The target name.
140 /// ShortDesc - A short description of the target.
141 const char *ShortDesc;
143 /// HasJIT - Whether this target supports the JIT.
146 /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
148 MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
150 /// MCCodeGenInfoCtorFn - Constructor function for this target's
151 /// MCCodeGenInfo, if registered.
152 MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn;
154 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
156 MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
158 /// MCInstrAnalysisCtorFn - Constructor function for this target's
159 /// MCInstrAnalysis, if registered.
160 MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
162 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
164 MCRegInfoCtorFnTy MCRegInfoCtorFn;
166 /// MCSubtargetInfoCtorFn - Constructor function for this target's
167 /// MCSubtargetInfo, if registered.
168 MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
170 /// TargetMachineCtorFn - Construction function for this target's
171 /// TargetMachine, if registered.
172 TargetMachineCtorTy TargetMachineCtorFn;
174 /// MCAsmBackendCtorFn - Construction function for this target's
175 /// MCAsmBackend, if registered.
176 MCAsmBackendCtorTy MCAsmBackendCtorFn;
178 /// MCAsmLexerCtorFn - Construction function for this target's
179 /// MCTargetAsmLexer, if registered.
180 MCAsmLexerCtorTy MCAsmLexerCtorFn;
182 /// MCAsmParserCtorFn - Construction function for this target's
183 /// MCTargetAsmParser, if registered.
184 MCAsmParserCtorTy MCAsmParserCtorFn;
186 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
188 AsmPrinterCtorTy AsmPrinterCtorFn;
190 /// MCDisassemblerCtorFn - Construction function for this target's
191 /// MCDisassembler, if registered.
192 MCDisassemblerCtorTy MCDisassemblerCtorFn;
194 /// MCInstPrinterCtorFn - Construction function for this target's
195 /// MCInstPrinter, if registered.
196 MCInstPrinterCtorTy MCInstPrinterCtorFn;
198 /// MCCodeEmitterCtorFn - Construction function for this target's
199 /// CodeEmitter, if registered.
200 MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
202 /// MCObjectStreamerCtorFn - Construction function for this target's
203 /// MCObjectStreamer, if registered.
204 MCObjectStreamerCtorTy MCObjectStreamerCtorFn;
206 /// AsmStreamerCtorFn - Construction function for this target's
207 /// AsmStreamer, if registered (default = llvm::createAsmStreamer).
208 AsmStreamerCtorTy AsmStreamerCtorFn;
211 Target() : AsmStreamerCtorFn(llvm::createAsmStreamer) {}
213 /// @name Target Information
216 // getNext - Return the next registered target.
217 const Target *getNext() const { return Next; }
219 /// getName - Get the target name.
220 const char *getName() const { return Name; }
222 /// getShortDescription - Get a short description of the target.
223 const char *getShortDescription() const { return ShortDesc; }
226 /// @name Feature Predicates
229 /// hasJIT - Check if this targets supports the just-in-time compilation.
230 bool hasJIT() const { return HasJIT; }
232 /// hasTargetMachine - Check if this target supports code generation.
233 bool hasTargetMachine() const { return TargetMachineCtorFn != 0; }
235 /// hasMCAsmBackend - Check if this target supports .o generation.
236 bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != 0; }
238 /// hasMCAsmLexer - Check if this target supports .s lexing.
239 bool hasMCAsmLexer() const { return MCAsmLexerCtorFn != 0; }
241 /// hasAsmParser - Check if this target supports .s parsing.
242 bool hasMCAsmParser() const { return MCAsmParserCtorFn != 0; }
244 /// hasAsmPrinter - Check if this target supports .s printing.
245 bool hasAsmPrinter() const { return AsmPrinterCtorFn != 0; }
247 /// hasMCDisassembler - Check if this target has a disassembler.
248 bool hasMCDisassembler() const { return MCDisassemblerCtorFn != 0; }
250 /// hasMCInstPrinter - Check if this target has an instruction printer.
251 bool hasMCInstPrinter() const { return MCInstPrinterCtorFn != 0; }
253 /// hasMCCodeEmitter - Check if this target supports instruction encoding.
254 bool hasMCCodeEmitter() const { return MCCodeEmitterCtorFn != 0; }
256 /// hasMCObjectStreamer - Check if this target supports streaming to files.
257 bool hasMCObjectStreamer() const { return MCObjectStreamerCtorFn != 0; }
259 /// hasAsmStreamer - Check if this target supports streaming to files.
260 bool hasAsmStreamer() const { return AsmStreamerCtorFn != 0; }
263 /// @name Feature Constructors
266 /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
269 /// \arg Triple - This argument is used to determine the target machine
270 /// feature set; it should always be provided. Generally this should be
271 /// either the target triple from the module, or the target triple of the
272 /// host if that does not exist.
273 MCAsmInfo *createMCAsmInfo(StringRef Triple) const {
274 if (!MCAsmInfoCtorFn)
276 return MCAsmInfoCtorFn(*this, Triple);
279 /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
281 MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model RM,
283 CodeGenOpt::Level OL) const {
284 if (!MCCodeGenInfoCtorFn)
286 return MCCodeGenInfoCtorFn(Triple, RM, CM, OL);
289 /// createMCInstrInfo - Create a MCInstrInfo implementation.
291 MCInstrInfo *createMCInstrInfo() const {
292 if (!MCInstrInfoCtorFn)
294 return MCInstrInfoCtorFn();
297 /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
299 MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
300 if (!MCInstrAnalysisCtorFn)
302 return MCInstrAnalysisCtorFn(Info);
305 /// createMCRegInfo - Create a MCRegisterInfo implementation.
307 MCRegisterInfo *createMCRegInfo(StringRef Triple) const {
308 if (!MCRegInfoCtorFn)
310 return MCRegInfoCtorFn(Triple);
313 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
315 /// \arg Triple - This argument is used to determine the target machine
316 /// feature set; it should always be provided. Generally this should be
317 /// either the target triple from the module, or the target triple of the
318 /// host if that does not exist.
319 /// \arg CPU - This specifies the name of the target CPU.
320 /// \arg Features - This specifies the string representation of the
321 /// additional target features.
322 MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU,
323 StringRef Features) const {
324 if (!MCSubtargetInfoCtorFn)
326 return MCSubtargetInfoCtorFn(Triple, CPU, Features);
329 /// createTargetMachine - Create a target specific machine implementation
330 /// for the specified \arg Triple.
332 /// \arg Triple - This argument is used to determine the target machine
333 /// feature set; it should always be provided. Generally this should be
334 /// either the target triple from the module, or the target triple of the
335 /// host if that does not exist.
336 TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU,
338 Reloc::Model RM = Reloc::Default,
339 CodeModel::Model CM = CodeModel::Default,
340 CodeGenOpt::Level OL = CodeGenOpt::Default) const {
341 if (!TargetMachineCtorFn)
343 return TargetMachineCtorFn(*this, Triple, CPU, Features, RM, CM, OL);
346 /// createMCAsmBackend - Create a target specific assembly parser.
348 /// \arg Triple - The target triple string.
349 /// \arg Backend - The target independent assembler object.
350 MCAsmBackend *createMCAsmBackend(StringRef Triple) const {
351 if (!MCAsmBackendCtorFn)
353 return MCAsmBackendCtorFn(*this, Triple);
356 /// createMCAsmLexer - Create a target specific assembly lexer.
358 MCTargetAsmLexer *createMCAsmLexer(const MCRegisterInfo &MRI,
359 const MCAsmInfo &MAI) const {
360 if (!MCAsmLexerCtorFn)
362 return MCAsmLexerCtorFn(*this, MRI, MAI);
365 /// createMCAsmParser - Create a target specific assembly parser.
367 /// \arg Parser - The target independent parser implementation to use for
368 /// parsing and lexing.
369 MCTargetAsmParser *createMCAsmParser(MCSubtargetInfo &STI,
370 MCAsmParser &Parser) const {
371 if (!MCAsmParserCtorFn)
373 return MCAsmParserCtorFn(STI, Parser);
376 /// createAsmPrinter - Create a target specific assembly printer pass. This
377 /// takes ownership of the MCStreamer object.
378 AsmPrinter *createAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) const{
379 if (!AsmPrinterCtorFn)
381 return AsmPrinterCtorFn(TM, Streamer);
384 MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI) const {
385 if (!MCDisassemblerCtorFn)
387 return MCDisassemblerCtorFn(*this, STI);
390 MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
391 const MCAsmInfo &MAI,
392 const MCSubtargetInfo &STI) const {
393 if (!MCInstPrinterCtorFn)
395 return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, STI);
399 /// createMCCodeEmitter - Create a target specific code emitter.
400 MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
401 const MCSubtargetInfo &STI,
402 MCContext &Ctx) const {
403 if (!MCCodeEmitterCtorFn)
405 return MCCodeEmitterCtorFn(II, STI, Ctx);
408 /// createMCObjectStreamer - Create a target specific MCStreamer.
410 /// \arg TT - The target triple.
411 /// \arg Ctx - The target context.
412 /// \arg TAB - The target assembler backend object. Takes ownership.
413 /// \arg _OS - The stream object.
414 /// \arg _Emitter - The target independent assembler object.Takes ownership.
415 /// \arg RelaxAll - Relax all fixups?
416 /// \arg NoExecStack - Mark file as not needing a executable stack.
417 MCStreamer *createMCObjectStreamer(StringRef TT, MCContext &Ctx,
420 MCCodeEmitter *_Emitter,
422 bool NoExecStack) const {
423 if (!MCObjectStreamerCtorFn)
425 return MCObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter,
426 RelaxAll, NoExecStack);
429 /// createAsmStreamer - Create a target specific MCStreamer.
430 MCStreamer *createAsmStreamer(MCContext &Ctx,
431 formatted_raw_ostream &OS,
435 bool useDwarfDirectory,
436 MCInstPrinter *InstPrint,
439 bool ShowInst) const {
440 // AsmStreamerCtorFn is default to llvm::createAsmStreamer
441 return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useLoc, useCFI,
442 useDwarfDirectory, InstPrint, CE, TAB, ShowInst);
448 /// TargetRegistry - Generic interface to target specific features.
449 struct TargetRegistry {
451 const Target *Current;
452 explicit iterator(Target *T) : Current(T) {}
453 friend struct TargetRegistry;
455 iterator(const iterator &I) : Current(I.Current) {}
456 iterator() : Current(0) {}
458 bool operator==(const iterator &x) const {
459 return Current == x.Current;
461 bool operator!=(const iterator &x) const {
462 return !operator==(x);
465 // Iterator traversal: forward iteration only
466 iterator &operator++() { // Preincrement
467 assert(Current && "Cannot increment end iterator!");
468 Current = Current->getNext();
471 iterator operator++(int) { // Postincrement
472 iterator tmp = *this;
477 const Target &operator*() const {
478 assert(Current && "Cannot dereference end iterator!");
482 const Target *operator->() const {
487 /// printRegisteredTargetsForVersion - Print the registered targets
488 /// appropriately for inclusion in a tool's version output.
489 static void printRegisteredTargetsForVersion();
491 /// @name Registry Access
494 static iterator begin();
496 static iterator end() { return iterator(); }
498 /// lookupTarget - Lookup a target based on a target triple.
500 /// \param Triple - The triple to use for finding a target.
501 /// \param Error - On failure, an error string describing why no target was
503 static const Target *lookupTarget(const std::string &Triple,
506 /// getClosestTargetForJIT - Pick the best target that is compatible with
507 /// the current host. If no close target can be found, this returns null
508 /// and sets the Error string to a reason.
510 /// Maintained for compatibility through 2.6.
511 static const Target *getClosestTargetForJIT(std::string &Error);
514 /// @name Target Registration
517 /// RegisterTarget - Register the given target. Attempts to register a
518 /// target which has already been registered will be ignored.
520 /// Clients are responsible for ensuring that registration doesn't occur
521 /// while another thread is attempting to access the registry. Typically
522 /// this is done by initializing all targets at program startup.
524 /// @param T - The target being registered.
525 /// @param Name - The target name. This should be a static string.
526 /// @param ShortDesc - A short target description. This should be a static
528 /// @param TQualityFn - The triple match quality computation function for
530 /// @param HasJIT - Whether the target supports JIT code
532 static void RegisterTarget(Target &T,
534 const char *ShortDesc,
535 Target::TripleMatchQualityFnTy TQualityFn,
536 bool HasJIT = false);
538 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
541 /// Clients are responsible for ensuring that registration doesn't occur
542 /// while another thread is attempting to access the registry. Typically
543 /// this is done by initializing all targets at program startup.
545 /// @param T - The target being registered.
546 /// @param Fn - A function to construct a MCAsmInfo for the target.
547 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
548 // Ignore duplicate registration.
549 if (!T.MCAsmInfoCtorFn)
550 T.MCAsmInfoCtorFn = Fn;
553 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
556 /// Clients are responsible for ensuring that registration doesn't occur
557 /// while another thread is attempting to access the registry. Typically
558 /// this is done by initializing all targets at program startup.
560 /// @param T - The target being registered.
561 /// @param Fn - A function to construct a MCCodeGenInfo for the target.
562 static void RegisterMCCodeGenInfo(Target &T,
563 Target::MCCodeGenInfoCtorFnTy Fn) {
564 // Ignore duplicate registration.
565 if (!T.MCCodeGenInfoCtorFn)
566 T.MCCodeGenInfoCtorFn = Fn;
569 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
572 /// Clients are responsible for ensuring that registration doesn't occur
573 /// while another thread is attempting to access the registry. Typically
574 /// this is done by initializing all targets at program startup.
576 /// @param T - The target being registered.
577 /// @param Fn - A function to construct a MCInstrInfo for the target.
578 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
579 // Ignore duplicate registration.
580 if (!T.MCInstrInfoCtorFn)
581 T.MCInstrInfoCtorFn = Fn;
584 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
585 /// the given target.
586 static void RegisterMCInstrAnalysis(Target &T,
587 Target::MCInstrAnalysisCtorFnTy Fn) {
588 // Ignore duplicate registration.
589 if (!T.MCInstrAnalysisCtorFn)
590 T.MCInstrAnalysisCtorFn = Fn;
593 /// RegisterMCRegInfo - Register a MCRegisterInfo 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 MCRegisterInfo for the target.
602 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
603 // Ignore duplicate registration.
604 if (!T.MCRegInfoCtorFn)
605 T.MCRegInfoCtorFn = Fn;
608 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
609 /// the given target.
611 /// Clients are responsible for ensuring that registration doesn't occur
612 /// while another thread is attempting to access the registry. Typically
613 /// this is done by initializing all targets at program startup.
615 /// @param T - The target being registered.
616 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
617 static void RegisterMCSubtargetInfo(Target &T,
618 Target::MCSubtargetInfoCtorFnTy Fn) {
619 // Ignore duplicate registration.
620 if (!T.MCSubtargetInfoCtorFn)
621 T.MCSubtargetInfoCtorFn = Fn;
624 /// RegisterTargetMachine - Register a TargetMachine implementation for the
627 /// Clients are responsible for ensuring that registration doesn't occur
628 /// while another thread is attempting to access the registry. Typically
629 /// this is done by initializing all targets at program startup.
631 /// @param T - The target being registered.
632 /// @param Fn - A function to construct a TargetMachine for the target.
633 static void RegisterTargetMachine(Target &T,
634 Target::TargetMachineCtorTy Fn) {
635 // Ignore duplicate registration.
636 if (!T.TargetMachineCtorFn)
637 T.TargetMachineCtorFn = Fn;
640 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
643 /// Clients are responsible for ensuring that registration doesn't occur
644 /// while another thread is attempting to access the registry. Typically
645 /// this is done by initializing all targets at program startup.
647 /// @param T - The target being registered.
648 /// @param Fn - A function to construct an AsmBackend for the target.
649 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
650 if (!T.MCAsmBackendCtorFn)
651 T.MCAsmBackendCtorFn = Fn;
654 /// RegisterMCAsmLexer - Register a MCTargetAsmLexer implementation for the
657 /// Clients are responsible for ensuring that registration doesn't occur
658 /// while another thread is attempting to access the registry. Typically
659 /// this is done by initializing all targets at program startup.
661 /// @param T - The target being registered.
662 /// @param Fn - A function to construct an MCAsmLexer for the target.
663 static void RegisterMCAsmLexer(Target &T, Target::MCAsmLexerCtorTy Fn) {
664 if (!T.MCAsmLexerCtorFn)
665 T.MCAsmLexerCtorFn = Fn;
668 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
669 /// the given target.
671 /// Clients are responsible for ensuring that registration doesn't occur
672 /// while another thread is attempting to access the registry. Typically
673 /// this is done by initializing all targets at program startup.
675 /// @param T - The target being registered.
676 /// @param Fn - A function to construct an MCTargetAsmParser for the target.
677 static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
678 if (!T.MCAsmParserCtorFn)
679 T.MCAsmParserCtorFn = Fn;
682 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
685 /// Clients are responsible for ensuring that registration doesn't occur
686 /// while another thread is attempting to access the registry. Typically
687 /// this is done by initializing all targets at program startup.
689 /// @param T - The target being registered.
690 /// @param Fn - A function to construct an AsmPrinter for the target.
691 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
692 // Ignore duplicate registration.
693 if (!T.AsmPrinterCtorFn)
694 T.AsmPrinterCtorFn = Fn;
697 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
698 /// the given target.
700 /// Clients are responsible for ensuring that registration doesn't occur
701 /// while another thread is attempting to access the registry. Typically
702 /// this is done by initializing all targets at program startup.
704 /// @param T - The target being registered.
705 /// @param Fn - A function to construct an MCDisassembler for the target.
706 static void RegisterMCDisassembler(Target &T,
707 Target::MCDisassemblerCtorTy Fn) {
708 if (!T.MCDisassemblerCtorFn)
709 T.MCDisassemblerCtorFn = Fn;
712 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
715 /// Clients are responsible for ensuring that registration doesn't occur
716 /// while another thread is attempting to access the registry. Typically
717 /// this is done by initializing all targets at program startup.
719 /// @param T - The target being registered.
720 /// @param Fn - A function to construct an MCInstPrinter for the target.
721 static void RegisterMCInstPrinter(Target &T,
722 Target::MCInstPrinterCtorTy Fn) {
723 if (!T.MCInstPrinterCtorFn)
724 T.MCInstPrinterCtorFn = Fn;
727 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
730 /// Clients are responsible for ensuring that registration doesn't occur
731 /// while another thread is attempting to access the registry. Typically
732 /// this is done by initializing all targets at program startup.
734 /// @param T - The target being registered.
735 /// @param Fn - A function to construct an MCCodeEmitter for the target.
736 static void RegisterMCCodeEmitter(Target &T,
737 Target::MCCodeEmitterCtorTy Fn) {
738 if (!T.MCCodeEmitterCtorFn)
739 T.MCCodeEmitterCtorFn = Fn;
742 /// RegisterMCObjectStreamer - Register a object code MCStreamer
743 /// implementation for the given target.
745 /// Clients are responsible for ensuring that registration doesn't occur
746 /// while another thread is attempting to access the registry. Typically
747 /// this is done by initializing all targets at program startup.
749 /// @param T - The target being registered.
750 /// @param Fn - A function to construct an MCStreamer for the target.
751 static void RegisterMCObjectStreamer(Target &T,
752 Target::MCObjectStreamerCtorTy Fn) {
753 if (!T.MCObjectStreamerCtorFn)
754 T.MCObjectStreamerCtorFn = Fn;
757 /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
758 /// for the given target.
760 /// Clients are responsible for ensuring that registration doesn't occur
761 /// while another thread is attempting to access the registry. Typically
762 /// this is done by initializing all targets at program startup.
764 /// @param T - The target being registered.
765 /// @param Fn - A function to construct an MCStreamer for the target.
766 static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
767 if (T.AsmStreamerCtorFn == createAsmStreamer)
768 T.AsmStreamerCtorFn = Fn;
775 //===--------------------------------------------------------------------===//
777 /// RegisterTarget - Helper template for registering a target, for use in the
778 /// target's initialization function. Usage:
781 /// Target TheFooTarget; // The global target instance.
783 /// extern "C" void LLVMInitializeFooTargetInfo() {
784 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
786 template<Triple::ArchType TargetArchType = Triple::InvalidArch,
788 struct RegisterTarget {
789 RegisterTarget(Target &T, const char *Name, const char *Desc) {
790 TargetRegistry::RegisterTarget(T, Name, Desc,
791 &getTripleMatchQuality,
795 static unsigned getTripleMatchQuality(const std::string &TT) {
796 if (Triple(TT).getArch() == TargetArchType)
802 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
803 /// implementation. This invokes the static "Create" method on the class to
804 /// actually do the construction. Usage:
806 /// extern "C" void LLVMInitializeFooTarget() {
807 /// extern Target TheFooTarget;
808 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
810 template<class MCAsmInfoImpl>
811 struct RegisterMCAsmInfo {
812 RegisterMCAsmInfo(Target &T) {
813 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
816 static MCAsmInfo *Allocator(const Target &T, StringRef TT) {
817 return new MCAsmInfoImpl(T, TT);
822 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
823 /// implementation. This invokes the specified function to do the
824 /// construction. Usage:
826 /// extern "C" void LLVMInitializeFooTarget() {
827 /// extern Target TheFooTarget;
828 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
830 struct RegisterMCAsmInfoFn {
831 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
832 TargetRegistry::RegisterMCAsmInfo(T, Fn);
836 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
837 /// implementation. This invokes the static "Create" method on the class
838 /// to actually do the construction. Usage:
840 /// extern "C" void LLVMInitializeFooTarget() {
841 /// extern Target TheFooTarget;
842 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
844 template<class MCCodeGenInfoImpl>
845 struct RegisterMCCodeGenInfo {
846 RegisterMCCodeGenInfo(Target &T) {
847 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
850 static MCCodeGenInfo *Allocator(StringRef TT, Reloc::Model RM,
851 CodeModel::Model CM, CodeGenOpt::Level OL) {
852 return new MCCodeGenInfoImpl();
856 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
857 /// info implementation. This invokes the specified function to do the
858 /// construction. Usage:
860 /// extern "C" void LLVMInitializeFooTarget() {
861 /// extern Target TheFooTarget;
862 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
864 struct RegisterMCCodeGenInfoFn {
865 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
866 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
870 /// RegisterMCInstrInfo - Helper template for registering a target instruction
871 /// info implementation. This invokes the static "Create" method on the class
872 /// to actually do the construction. Usage:
874 /// extern "C" void LLVMInitializeFooTarget() {
875 /// extern Target TheFooTarget;
876 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
878 template<class MCInstrInfoImpl>
879 struct RegisterMCInstrInfo {
880 RegisterMCInstrInfo(Target &T) {
881 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
884 static MCInstrInfo *Allocator() {
885 return new MCInstrInfoImpl();
889 /// RegisterMCInstrInfoFn - Helper template for registering a target
890 /// instruction info implementation. This invokes the specified function to
891 /// do the construction. Usage:
893 /// extern "C" void LLVMInitializeFooTarget() {
894 /// extern Target TheFooTarget;
895 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
897 struct RegisterMCInstrInfoFn {
898 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
899 TargetRegistry::RegisterMCInstrInfo(T, Fn);
903 /// RegisterMCInstrAnalysis - Helper template for registering a target
904 /// instruction analyzer implementation. This invokes the static "Create"
905 /// method on the class to actually do the construction. Usage:
907 /// extern "C" void LLVMInitializeFooTarget() {
908 /// extern Target TheFooTarget;
909 /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
911 template<class MCInstrAnalysisImpl>
912 struct RegisterMCInstrAnalysis {
913 RegisterMCInstrAnalysis(Target &T) {
914 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
917 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
918 return new MCInstrAnalysisImpl(Info);
922 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
923 /// instruction analyzer implementation. This invokes the specified function
924 /// to do the construction. Usage:
926 /// extern "C" void LLVMInitializeFooTarget() {
927 /// extern Target TheFooTarget;
928 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
930 struct RegisterMCInstrAnalysisFn {
931 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
932 TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
936 /// RegisterMCRegInfo - Helper template for registering a target register info
937 /// implementation. This invokes the static "Create" method on the class to
938 /// actually do the construction. Usage:
940 /// extern "C" void LLVMInitializeFooTarget() {
941 /// extern Target TheFooTarget;
942 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
944 template<class MCRegisterInfoImpl>
945 struct RegisterMCRegInfo {
946 RegisterMCRegInfo(Target &T) {
947 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
950 static MCRegisterInfo *Allocator(StringRef TT) {
951 return new MCRegisterInfoImpl();
955 /// RegisterMCRegInfoFn - Helper template for registering a target register
956 /// info implementation. This invokes the specified function to do the
957 /// construction. Usage:
959 /// extern "C" void LLVMInitializeFooTarget() {
960 /// extern Target TheFooTarget;
961 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
963 struct RegisterMCRegInfoFn {
964 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
965 TargetRegistry::RegisterMCRegInfo(T, Fn);
969 /// RegisterMCSubtargetInfo - Helper template for registering a target
970 /// subtarget info implementation. This invokes the static "Create" method
971 /// on the class to actually do the construction. Usage:
973 /// extern "C" void LLVMInitializeFooTarget() {
974 /// extern Target TheFooTarget;
975 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
977 template<class MCSubtargetInfoImpl>
978 struct RegisterMCSubtargetInfo {
979 RegisterMCSubtargetInfo(Target &T) {
980 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
983 static MCSubtargetInfo *Allocator(StringRef TT, StringRef CPU,
985 return new MCSubtargetInfoImpl();
989 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
990 /// subtarget info implementation. This invokes the specified function to
991 /// do the construction. Usage:
993 /// extern "C" void LLVMInitializeFooTarget() {
994 /// extern Target TheFooTarget;
995 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
997 struct RegisterMCSubtargetInfoFn {
998 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
999 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
1003 /// RegisterTargetMachine - Helper template for registering a target machine
1004 /// implementation, for use in the target machine initialization
1005 /// function. Usage:
1007 /// extern "C" void LLVMInitializeFooTarget() {
1008 /// extern Target TheFooTarget;
1009 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1011 template<class TargetMachineImpl>
1012 struct RegisterTargetMachine {
1013 RegisterTargetMachine(Target &T) {
1014 TargetRegistry::RegisterTargetMachine(T, &Allocator);
1018 static TargetMachine *Allocator(const Target &T, StringRef TT,
1019 StringRef CPU, StringRef FS,
1021 CodeModel::Model CM,
1022 CodeGenOpt::Level OL) {
1023 return new TargetMachineImpl(T, TT, CPU, FS, RM, CM, OL);
1027 /// RegisterMCAsmBackend - Helper template for registering a target specific
1028 /// assembler backend. Usage:
1030 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1031 /// extern Target TheFooTarget;
1032 /// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1034 template<class MCAsmBackendImpl>
1035 struct RegisterMCAsmBackend {
1036 RegisterMCAsmBackend(Target &T) {
1037 TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1041 static MCAsmBackend *Allocator(const Target &T, StringRef Triple) {
1042 return new MCAsmBackendImpl(T, Triple);
1046 /// RegisterMCAsmLexer - Helper template for registering a target specific
1047 /// assembly lexer, for use in the target machine initialization
1048 /// function. Usage:
1050 /// extern "C" void LLVMInitializeFooMCAsmLexer() {
1051 /// extern Target TheFooTarget;
1052 /// RegisterMCAsmLexer<FooMCAsmLexer> X(TheFooTarget);
1054 template<class MCAsmLexerImpl>
1055 struct RegisterMCAsmLexer {
1056 RegisterMCAsmLexer(Target &T) {
1057 TargetRegistry::RegisterMCAsmLexer(T, &Allocator);
1061 static MCTargetAsmLexer *Allocator(const Target &T,
1062 const MCRegisterInfo &MRI,
1063 const MCAsmInfo &MAI) {
1064 return new MCAsmLexerImpl(T, MRI, MAI);
1068 /// RegisterMCAsmParser - Helper template for registering a target specific
1069 /// assembly parser, for use in the target machine initialization
1070 /// function. Usage:
1072 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1073 /// extern Target TheFooTarget;
1074 /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1076 template<class MCAsmParserImpl>
1077 struct RegisterMCAsmParser {
1078 RegisterMCAsmParser(Target &T) {
1079 TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1083 static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P) {
1084 return new MCAsmParserImpl(STI, P);
1088 /// RegisterAsmPrinter - Helper template for registering a target specific
1089 /// assembly printer, for use in the target machine initialization
1090 /// function. Usage:
1092 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1093 /// extern Target TheFooTarget;
1094 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1096 template<class AsmPrinterImpl>
1097 struct RegisterAsmPrinter {
1098 RegisterAsmPrinter(Target &T) {
1099 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1103 static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) {
1104 return new AsmPrinterImpl(TM, Streamer);
1108 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1109 /// machine code emitter, for use in the target initialization
1110 /// function. Usage:
1112 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1113 /// extern Target TheFooTarget;
1114 /// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1116 template<class MCCodeEmitterImpl>
1117 struct RegisterMCCodeEmitter {
1118 RegisterMCCodeEmitter(Target &T) {
1119 TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1123 static MCCodeEmitter *Allocator(const MCInstrInfo &II,
1124 const MCSubtargetInfo &STI,
1126 return new MCCodeEmitterImpl();