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 MCRegisterInfo &MRI,
108
const MCSubtargetInfo &STI);
109
typedef MCCodeEmitter *(*MCCodeEmitterCtorTy)(const MCInstrInfo &II,
110
const MCSubtargetInfo &STI,
112
typedef MCStreamer *(*MCObjectStreamerCtorTy)(const Target &T,
117
MCCodeEmitter *_Emitter,
120
typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx,
121
formatted_raw_ostream &OS,
125
bool useDwarfDirectory,
126
MCInstPrinter *InstPrint,
132
/// Next - The next registered target in the linked list, maintained by the
136
/// TripleMatchQualityFn - The target function for rating the match quality
138
TripleMatchQualityFnTy TripleMatchQualityFn;
140
/// Name - The target name.
143
/// ShortDesc - A short description of the target.
144
const char *ShortDesc;
146
/// HasJIT - Whether this target supports the JIT.
149
/// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
151
MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
153
/// MCCodeGenInfoCtorFn - Constructor function for this target's
154
/// MCCodeGenInfo, if registered.
155
MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn;
157
/// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
159
MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
161
/// MCInstrAnalysisCtorFn - Constructor function for this target's
162
/// MCInstrAnalysis, if registered.
163
MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
165
/// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
167
MCRegInfoCtorFnTy MCRegInfoCtorFn;
169
/// MCSubtargetInfoCtorFn - Constructor function for this target's
170
/// MCSubtargetInfo, if registered.
171
MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
173
/// TargetMachineCtorFn - Construction function for this target's
174
/// TargetMachine, if registered.
175
TargetMachineCtorTy TargetMachineCtorFn;
177
/// MCAsmBackendCtorFn - Construction function for this target's
178
/// MCAsmBackend, if registered.
179
MCAsmBackendCtorTy MCAsmBackendCtorFn;
181
/// MCAsmLexerCtorFn - Construction function for this target's
182
/// MCTargetAsmLexer, if registered.
183
MCAsmLexerCtorTy MCAsmLexerCtorFn;
185
/// MCAsmParserCtorFn - Construction function for this target's
186
/// MCTargetAsmParser, if registered.
187
MCAsmParserCtorTy MCAsmParserCtorFn;
189
/// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
191
AsmPrinterCtorTy AsmPrinterCtorFn;
193
/// MCDisassemblerCtorFn - Construction function for this target's
194
/// MCDisassembler, if registered.
195
MCDisassemblerCtorTy MCDisassemblerCtorFn;
197
/// MCInstPrinterCtorFn - Construction function for this target's
198
/// MCInstPrinter, if registered.
199
MCInstPrinterCtorTy MCInstPrinterCtorFn;
201
/// MCCodeEmitterCtorFn - Construction function for this target's
202
/// CodeEmitter, if registered.
203
MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
205
/// MCObjectStreamerCtorFn - Construction function for this target's
206
/// MCObjectStreamer, if registered.
207
MCObjectStreamerCtorTy MCObjectStreamerCtorFn;
209
/// AsmStreamerCtorFn - Construction function for this target's
210
/// AsmStreamer, if registered (default = llvm::createAsmStreamer).
211
AsmStreamerCtorTy AsmStreamerCtorFn;
214
Target() : AsmStreamerCtorFn(llvm::createAsmStreamer) {}
216
/// @name Target Information
219
// getNext - Return the next registered target.
220
const Target *getNext() const { return Next; }
222
/// getName - Get the target name.
223
const char *getName() const { return Name; }
225
/// getShortDescription - Get a short description of the target.
226
const char *getShortDescription() const { return ShortDesc; }
229
/// @name Feature Predicates
232
/// hasJIT - Check if this targets supports the just-in-time compilation.
233
bool hasJIT() const { return HasJIT; }
235
/// hasTargetMachine - Check if this target supports code generation.
236
bool hasTargetMachine() const { return TargetMachineCtorFn != 0; }
238
/// hasMCAsmBackend - Check if this target supports .o generation.
239
bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != 0; }
241
/// hasMCAsmLexer - Check if this target supports .s lexing.
242
bool hasMCAsmLexer() const { return MCAsmLexerCtorFn != 0; }
244
/// hasAsmParser - Check if this target supports .s parsing.
245
bool hasMCAsmParser() const { return MCAsmParserCtorFn != 0; }
247
/// hasAsmPrinter - Check if this target supports .s printing.
248
bool hasAsmPrinter() const { return AsmPrinterCtorFn != 0; }
250
/// hasMCDisassembler - Check if this target has a disassembler.
251
bool hasMCDisassembler() const { return MCDisassemblerCtorFn != 0; }
253
/// hasMCInstPrinter - Check if this target has an instruction printer.
254
bool hasMCInstPrinter() const { return MCInstPrinterCtorFn != 0; }
256
/// hasMCCodeEmitter - Check if this target supports instruction encoding.
257
bool hasMCCodeEmitter() const { return MCCodeEmitterCtorFn != 0; }
259
/// hasMCObjectStreamer - Check if this target supports streaming to files.
260
bool hasMCObjectStreamer() const { return MCObjectStreamerCtorFn != 0; }
262
/// hasAsmStreamer - Check if this target supports streaming to files.
263
bool hasAsmStreamer() const { return AsmStreamerCtorFn != 0; }
266
/// @name Feature Constructors
269
/// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
272
/// \arg Triple - This argument is used to determine the target machine
273
/// feature set; it should always be provided. Generally this should be
274
/// either the target triple from the module, or the target triple of the
275
/// host if that does not exist.
276
MCAsmInfo *createMCAsmInfo(StringRef Triple) const {
277
if (!MCAsmInfoCtorFn)
279
return MCAsmInfoCtorFn(*this, Triple);
282
/// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
284
MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model RM,
286
CodeGenOpt::Level OL) const {
287
if (!MCCodeGenInfoCtorFn)
289
return MCCodeGenInfoCtorFn(Triple, RM, CM, OL);
292
/// createMCInstrInfo - Create a MCInstrInfo implementation.
294
MCInstrInfo *createMCInstrInfo() const {
295
if (!MCInstrInfoCtorFn)
297
return MCInstrInfoCtorFn();
300
/// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
302
MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
303
if (!MCInstrAnalysisCtorFn)
305
return MCInstrAnalysisCtorFn(Info);
308
/// createMCRegInfo - Create a MCRegisterInfo implementation.
310
MCRegisterInfo *createMCRegInfo(StringRef Triple) const {
311
if (!MCRegInfoCtorFn)
313
return MCRegInfoCtorFn(Triple);
316
/// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
318
/// \arg Triple - This argument is used to determine the target machine
319
/// feature set; it should always be provided. Generally this should be
320
/// either the target triple from the module, or the target triple of the
321
/// host if that does not exist.
322
/// \arg CPU - This specifies the name of the target CPU.
323
/// \arg Features - This specifies the string representation of the
324
/// additional target features.
325
MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU,
326
StringRef Features) const {
327
if (!MCSubtargetInfoCtorFn)
329
return MCSubtargetInfoCtorFn(Triple, CPU, Features);
332
/// createTargetMachine - Create a target specific machine implementation
333
/// for the specified \arg Triple.
335
/// \arg Triple - This argument is used to determine the target machine
336
/// feature set; it should always be provided. Generally this should be
337
/// either the target triple from the module, or the target triple of the
338
/// host if that does not exist.
339
TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU,
340
StringRef Features, const TargetOptions &Options,
341
Reloc::Model RM = Reloc::Default,
342
CodeModel::Model CM = CodeModel::Default,
343
CodeGenOpt::Level OL = CodeGenOpt::Default) const {
344
if (!TargetMachineCtorFn)
346
return TargetMachineCtorFn(*this, Triple, CPU, Features, Options,
350
/// createMCAsmBackend - Create a target specific assembly parser.
352
/// \arg Triple - The target triple string.
353
/// \arg Backend - The target independent assembler object.
354
MCAsmBackend *createMCAsmBackend(StringRef Triple) const {
355
if (!MCAsmBackendCtorFn)
357
return MCAsmBackendCtorFn(*this, Triple);
360
/// createMCAsmLexer - Create a target specific assembly lexer.
362
MCTargetAsmLexer *createMCAsmLexer(const MCRegisterInfo &MRI,
363
const MCAsmInfo &MAI) const {
364
if (!MCAsmLexerCtorFn)
366
return MCAsmLexerCtorFn(*this, MRI, MAI);
369
/// createMCAsmParser - Create a target specific assembly parser.
371
/// \arg Parser - The target independent parser implementation to use for
372
/// parsing and lexing.
373
MCTargetAsmParser *createMCAsmParser(MCSubtargetInfo &STI,
374
MCAsmParser &Parser) const {
375
if (!MCAsmParserCtorFn)
377
return MCAsmParserCtorFn(STI, Parser);
380
/// createAsmPrinter - Create a target specific assembly printer pass. This
381
/// takes ownership of the MCStreamer object.
382
AsmPrinter *createAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) const{
383
if (!AsmPrinterCtorFn)
385
return AsmPrinterCtorFn(TM, Streamer);
388
MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI) const {
389
if (!MCDisassemblerCtorFn)
391
return MCDisassemblerCtorFn(*this, STI);
394
MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
395
const MCAsmInfo &MAI,
396
const MCRegisterInfo &MRI,
397
const MCSubtargetInfo &STI) const {
398
if (!MCInstPrinterCtorFn)
400
return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, MRI, STI);
404
/// createMCCodeEmitter - Create a target specific code emitter.
405
MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
406
const MCSubtargetInfo &STI,
407
MCContext &Ctx) const {
408
if (!MCCodeEmitterCtorFn)
410
return MCCodeEmitterCtorFn(II, STI, Ctx);
413
/// createMCObjectStreamer - Create a target specific MCStreamer.
415
/// \arg TT - The target triple.
416
/// \arg Ctx - The target context.
417
/// \arg TAB - The target assembler backend object. Takes ownership.
418
/// \arg _OS - The stream object.
419
/// \arg _Emitter - The target independent assembler object.Takes ownership.
420
/// \arg RelaxAll - Relax all fixups?
421
/// \arg NoExecStack - Mark file as not needing a executable stack.
422
MCStreamer *createMCObjectStreamer(StringRef TT, MCContext &Ctx,
425
MCCodeEmitter *_Emitter,
427
bool NoExecStack) const {
428
if (!MCObjectStreamerCtorFn)
430
return MCObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter,
431
RelaxAll, NoExecStack);
434
/// createAsmStreamer - Create a target specific MCStreamer.
435
MCStreamer *createAsmStreamer(MCContext &Ctx,
436
formatted_raw_ostream &OS,
440
bool useDwarfDirectory,
441
MCInstPrinter *InstPrint,
444
bool ShowInst) const {
445
// AsmStreamerCtorFn is default to llvm::createAsmStreamer
446
return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useLoc, useCFI,
447
useDwarfDirectory, InstPrint, CE, TAB, ShowInst);
453
/// TargetRegistry - Generic interface to target specific features.
454
struct TargetRegistry {
456
const Target *Current;
457
explicit iterator(Target *T) : Current(T) {}
458
friend struct TargetRegistry;
460
iterator(const iterator &I) : Current(I.Current) {}
461
iterator() : Current(0) {}
463
bool operator==(const iterator &x) const {
464
return Current == x.Current;
466
bool operator!=(const iterator &x) const {
467
return !operator==(x);
470
// Iterator traversal: forward iteration only
471
iterator &operator++() { // Preincrement
472
assert(Current && "Cannot increment end iterator!");
473
Current = Current->getNext();
476
iterator operator++(int) { // Postincrement
477
iterator tmp = *this;
482
const Target &operator*() const {
483
assert(Current && "Cannot dereference end iterator!");
487
const Target *operator->() const {
492
/// printRegisteredTargetsForVersion - Print the registered targets
493
/// appropriately for inclusion in a tool's version output.
494
static void printRegisteredTargetsForVersion();
496
/// @name Registry Access
499
static iterator begin();
501
static iterator end() { return iterator(); }
503
/// lookupTarget - Lookup a target based on a target triple.
505
/// \param Triple - The triple to use for finding a target.
506
/// \param Error - On failure, an error string describing why no target was
508
static const Target *lookupTarget(const std::string &Triple,
511
/// getClosestTargetForJIT - Pick the best target that is compatible with
512
/// the current host. If no close target can be found, this returns null
513
/// and sets the Error string to a reason.
515
/// Maintained for compatibility through 2.6.
516
static const Target *getClosestTargetForJIT(std::string &Error);
519
/// @name Target Registration
522
/// RegisterTarget - Register the given target. Attempts to register a
523
/// target which has already been registered will be ignored.
525
/// Clients are responsible for ensuring that registration doesn't occur
526
/// while another thread is attempting to access the registry. Typically
527
/// this is done by initializing all targets at program startup.
529
/// @param T - The target being registered.
530
/// @param Name - The target name. This should be a static string.
531
/// @param ShortDesc - A short target description. This should be a static
533
/// @param TQualityFn - The triple match quality computation function for
535
/// @param HasJIT - Whether the target supports JIT code
537
static void RegisterTarget(Target &T,
539
const char *ShortDesc,
540
Target::TripleMatchQualityFnTy TQualityFn,
541
bool HasJIT = false);
543
/// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
546
/// Clients are responsible for ensuring that registration doesn't occur
547
/// while another thread is attempting to access the registry. Typically
548
/// this is done by initializing all targets at program startup.
550
/// @param T - The target being registered.
551
/// @param Fn - A function to construct a MCAsmInfo for the target.
552
static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
553
// Ignore duplicate registration.
554
if (!T.MCAsmInfoCtorFn)
555
T.MCAsmInfoCtorFn = Fn;
558
/// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
561
/// Clients are responsible for ensuring that registration doesn't occur
562
/// while another thread is attempting to access the registry. Typically
563
/// this is done by initializing all targets at program startup.
565
/// @param T - The target being registered.
566
/// @param Fn - A function to construct a MCCodeGenInfo for the target.
567
static void RegisterMCCodeGenInfo(Target &T,
568
Target::MCCodeGenInfoCtorFnTy Fn) {
569
// Ignore duplicate registration.
570
if (!T.MCCodeGenInfoCtorFn)
571
T.MCCodeGenInfoCtorFn = Fn;
574
/// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
577
/// Clients are responsible for ensuring that registration doesn't occur
578
/// while another thread is attempting to access the registry. Typically
579
/// this is done by initializing all targets at program startup.
581
/// @param T - The target being registered.
582
/// @param Fn - A function to construct a MCInstrInfo for the target.
583
static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
584
// Ignore duplicate registration.
585
if (!T.MCInstrInfoCtorFn)
586
T.MCInstrInfoCtorFn = Fn;
589
/// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
590
/// the given target.
591
static void RegisterMCInstrAnalysis(Target &T,
592
Target::MCInstrAnalysisCtorFnTy Fn) {
593
// Ignore duplicate registration.
594
if (!T.MCInstrAnalysisCtorFn)
595
T.MCInstrAnalysisCtorFn = Fn;
598
/// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
601
/// Clients are responsible for ensuring that registration doesn't occur
602
/// while another thread is attempting to access the registry. Typically
603
/// this is done by initializing all targets at program startup.
605
/// @param T - The target being registered.
606
/// @param Fn - A function to construct a MCRegisterInfo for the target.
607
static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
608
// Ignore duplicate registration.
609
if (!T.MCRegInfoCtorFn)
610
T.MCRegInfoCtorFn = Fn;
613
/// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
614
/// the given target.
616
/// Clients are responsible for ensuring that registration doesn't occur
617
/// while another thread is attempting to access the registry. Typically
618
/// this is done by initializing all targets at program startup.
620
/// @param T - The target being registered.
621
/// @param Fn - A function to construct a MCSubtargetInfo for the target.
622
static void RegisterMCSubtargetInfo(Target &T,
623
Target::MCSubtargetInfoCtorFnTy Fn) {
624
// Ignore duplicate registration.
625
if (!T.MCSubtargetInfoCtorFn)
626
T.MCSubtargetInfoCtorFn = Fn;
629
/// RegisterTargetMachine - Register a TargetMachine implementation for the
632
/// Clients are responsible for ensuring that registration doesn't occur
633
/// while another thread is attempting to access the registry. Typically
634
/// this is done by initializing all targets at program startup.
636
/// @param T - The target being registered.
637
/// @param Fn - A function to construct a TargetMachine for the target.
638
static void RegisterTargetMachine(Target &T,
639
Target::TargetMachineCtorTy Fn) {
640
// Ignore duplicate registration.
641
if (!T.TargetMachineCtorFn)
642
T.TargetMachineCtorFn = Fn;
645
/// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
648
/// Clients are responsible for ensuring that registration doesn't occur
649
/// while another thread is attempting to access the registry. Typically
650
/// this is done by initializing all targets at program startup.
652
/// @param T - The target being registered.
653
/// @param Fn - A function to construct an AsmBackend for the target.
654
static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
655
if (!T.MCAsmBackendCtorFn)
656
T.MCAsmBackendCtorFn = Fn;
659
/// RegisterMCAsmLexer - Register a MCTargetAsmLexer implementation for the
662
/// Clients are responsible for ensuring that registration doesn't occur
663
/// while another thread is attempting to access the registry. Typically
664
/// this is done by initializing all targets at program startup.
666
/// @param T - The target being registered.
667
/// @param Fn - A function to construct an MCAsmLexer for the target.
668
static void RegisterMCAsmLexer(Target &T, Target::MCAsmLexerCtorTy Fn) {
669
if (!T.MCAsmLexerCtorFn)
670
T.MCAsmLexerCtorFn = Fn;
673
/// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
674
/// the given target.
676
/// Clients are responsible for ensuring that registration doesn't occur
677
/// while another thread is attempting to access the registry. Typically
678
/// this is done by initializing all targets at program startup.
680
/// @param T - The target being registered.
681
/// @param Fn - A function to construct an MCTargetAsmParser for the target.
682
static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
683
if (!T.MCAsmParserCtorFn)
684
T.MCAsmParserCtorFn = Fn;
687
/// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
690
/// Clients are responsible for ensuring that registration doesn't occur
691
/// while another thread is attempting to access the registry. Typically
692
/// this is done by initializing all targets at program startup.
694
/// @param T - The target being registered.
695
/// @param Fn - A function to construct an AsmPrinter for the target.
696
static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
697
// Ignore duplicate registration.
698
if (!T.AsmPrinterCtorFn)
699
T.AsmPrinterCtorFn = Fn;
702
/// RegisterMCDisassembler - Register a MCDisassembler implementation for
703
/// the given target.
705
/// Clients are responsible for ensuring that registration doesn't occur
706
/// while another thread is attempting to access the registry. Typically
707
/// this is done by initializing all targets at program startup.
709
/// @param T - The target being registered.
710
/// @param Fn - A function to construct an MCDisassembler for the target.
711
static void RegisterMCDisassembler(Target &T,
712
Target::MCDisassemblerCtorTy Fn) {
713
if (!T.MCDisassemblerCtorFn)
714
T.MCDisassemblerCtorFn = Fn;
717
/// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
720
/// Clients are responsible for ensuring that registration doesn't occur
721
/// while another thread is attempting to access the registry. Typically
722
/// this is done by initializing all targets at program startup.
724
/// @param T - The target being registered.
725
/// @param Fn - A function to construct an MCInstPrinter for the target.
726
static void RegisterMCInstPrinter(Target &T,
727
Target::MCInstPrinterCtorTy Fn) {
728
if (!T.MCInstPrinterCtorFn)
729
T.MCInstPrinterCtorFn = Fn;
732
/// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
735
/// Clients are responsible for ensuring that registration doesn't occur
736
/// while another thread is attempting to access the registry. Typically
737
/// this is done by initializing all targets at program startup.
739
/// @param T - The target being registered.
740
/// @param Fn - A function to construct an MCCodeEmitter for the target.
741
static void RegisterMCCodeEmitter(Target &T,
742
Target::MCCodeEmitterCtorTy Fn) {
743
if (!T.MCCodeEmitterCtorFn)
744
T.MCCodeEmitterCtorFn = Fn;
747
/// RegisterMCObjectStreamer - Register a object code MCStreamer
748
/// implementation for the given target.
750
/// Clients are responsible for ensuring that registration doesn't occur
751
/// while another thread is attempting to access the registry. Typically
752
/// this is done by initializing all targets at program startup.
754
/// @param T - The target being registered.
755
/// @param Fn - A function to construct an MCStreamer for the target.
756
static void RegisterMCObjectStreamer(Target &T,
757
Target::MCObjectStreamerCtorTy Fn) {
758
if (!T.MCObjectStreamerCtorFn)
759
T.MCObjectStreamerCtorFn = Fn;
762
/// RegisterAsmStreamer - Register an assembly MCStreamer implementation
763
/// for the given target.
765
/// Clients are responsible for ensuring that registration doesn't occur
766
/// while another thread is attempting to access the registry. Typically
767
/// this is done by initializing all targets at program startup.
769
/// @param T - The target being registered.
770
/// @param Fn - A function to construct an MCStreamer for the target.
771
static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
772
if (T.AsmStreamerCtorFn == createAsmStreamer)
773
T.AsmStreamerCtorFn = Fn;
780
//===--------------------------------------------------------------------===//
782
/// RegisterTarget - Helper template for registering a target, for use in the
783
/// target's initialization function. Usage:
786
/// Target TheFooTarget; // The global target instance.
788
/// extern "C" void LLVMInitializeFooTargetInfo() {
789
/// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
791
template<Triple::ArchType TargetArchType = Triple::UnknownArch,
793
struct RegisterTarget {
794
RegisterTarget(Target &T, const char *Name, const char *Desc) {
795
TargetRegistry::RegisterTarget(T, Name, Desc,
796
&getTripleMatchQuality,
800
static unsigned getTripleMatchQuality(const std::string &TT) {
801
if (Triple(TT).getArch() == TargetArchType)
807
/// RegisterMCAsmInfo - Helper template for registering a target assembly info
808
/// implementation. This invokes the static "Create" method on the class to
809
/// actually do the construction. Usage:
811
/// extern "C" void LLVMInitializeFooTarget() {
812
/// extern Target TheFooTarget;
813
/// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
815
template<class MCAsmInfoImpl>
816
struct RegisterMCAsmInfo {
817
RegisterMCAsmInfo(Target &T) {
818
TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
821
static MCAsmInfo *Allocator(const Target &T, StringRef TT) {
822
return new MCAsmInfoImpl(T, TT);
827
/// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
828
/// implementation. This invokes the specified function to do the
829
/// construction. Usage:
831
/// extern "C" void LLVMInitializeFooTarget() {
832
/// extern Target TheFooTarget;
833
/// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
835
struct RegisterMCAsmInfoFn {
836
RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
837
TargetRegistry::RegisterMCAsmInfo(T, Fn);
841
/// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
842
/// implementation. This invokes the static "Create" method on the class
843
/// to actually do the construction. Usage:
845
/// extern "C" void LLVMInitializeFooTarget() {
846
/// extern Target TheFooTarget;
847
/// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
849
template<class MCCodeGenInfoImpl>
850
struct RegisterMCCodeGenInfo {
851
RegisterMCCodeGenInfo(Target &T) {
852
TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
855
static MCCodeGenInfo *Allocator(StringRef TT, Reloc::Model RM,
856
CodeModel::Model CM, CodeGenOpt::Level OL) {
857
return new MCCodeGenInfoImpl();
861
/// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
862
/// info implementation. This invokes the specified function to do the
863
/// construction. Usage:
865
/// extern "C" void LLVMInitializeFooTarget() {
866
/// extern Target TheFooTarget;
867
/// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
869
struct RegisterMCCodeGenInfoFn {
870
RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
871
TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
875
/// RegisterMCInstrInfo - Helper template for registering a target instruction
876
/// info implementation. This invokes the static "Create" method on the class
877
/// to actually do the construction. Usage:
879
/// extern "C" void LLVMInitializeFooTarget() {
880
/// extern Target TheFooTarget;
881
/// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
883
template<class MCInstrInfoImpl>
884
struct RegisterMCInstrInfo {
885
RegisterMCInstrInfo(Target &T) {
886
TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
889
static MCInstrInfo *Allocator() {
890
return new MCInstrInfoImpl();
894
/// RegisterMCInstrInfoFn - Helper template for registering a target
895
/// instruction info implementation. This invokes the specified function to
896
/// do the construction. Usage:
898
/// extern "C" void LLVMInitializeFooTarget() {
899
/// extern Target TheFooTarget;
900
/// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
902
struct RegisterMCInstrInfoFn {
903
RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
904
TargetRegistry::RegisterMCInstrInfo(T, Fn);
908
/// RegisterMCInstrAnalysis - Helper template for registering a target
909
/// instruction analyzer implementation. This invokes the static "Create"
910
/// method on the class to actually do the construction. Usage:
912
/// extern "C" void LLVMInitializeFooTarget() {
913
/// extern Target TheFooTarget;
914
/// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
916
template<class MCInstrAnalysisImpl>
917
struct RegisterMCInstrAnalysis {
918
RegisterMCInstrAnalysis(Target &T) {
919
TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
922
static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
923
return new MCInstrAnalysisImpl(Info);
927
/// RegisterMCInstrAnalysisFn - Helper template for registering a target
928
/// instruction analyzer implementation. This invokes the specified function
929
/// to do the construction. Usage:
931
/// extern "C" void LLVMInitializeFooTarget() {
932
/// extern Target TheFooTarget;
933
/// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
935
struct RegisterMCInstrAnalysisFn {
936
RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
937
TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
941
/// RegisterMCRegInfo - Helper template for registering a target register info
942
/// implementation. This invokes the static "Create" method on the class to
943
/// actually do the construction. Usage:
945
/// extern "C" void LLVMInitializeFooTarget() {
946
/// extern Target TheFooTarget;
947
/// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
949
template<class MCRegisterInfoImpl>
950
struct RegisterMCRegInfo {
951
RegisterMCRegInfo(Target &T) {
952
TargetRegistry::RegisterMCRegInfo(T, &Allocator);
955
static MCRegisterInfo *Allocator(StringRef TT) {
956
return new MCRegisterInfoImpl();
960
/// RegisterMCRegInfoFn - Helper template for registering a target register
961
/// info implementation. This invokes the specified function to do the
962
/// construction. Usage:
964
/// extern "C" void LLVMInitializeFooTarget() {
965
/// extern Target TheFooTarget;
966
/// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
968
struct RegisterMCRegInfoFn {
969
RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
970
TargetRegistry::RegisterMCRegInfo(T, Fn);
974
/// RegisterMCSubtargetInfo - Helper template for registering a target
975
/// subtarget info implementation. This invokes the static "Create" method
976
/// on the class to actually do the construction. Usage:
978
/// extern "C" void LLVMInitializeFooTarget() {
979
/// extern Target TheFooTarget;
980
/// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
982
template<class MCSubtargetInfoImpl>
983
struct RegisterMCSubtargetInfo {
984
RegisterMCSubtargetInfo(Target &T) {
985
TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
988
static MCSubtargetInfo *Allocator(StringRef TT, StringRef CPU,
990
return new MCSubtargetInfoImpl();
994
/// RegisterMCSubtargetInfoFn - Helper template for registering a target
995
/// subtarget info implementation. This invokes the specified function to
996
/// do the construction. Usage:
998
/// extern "C" void LLVMInitializeFooTarget() {
999
/// extern Target TheFooTarget;
1000
/// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1002
struct RegisterMCSubtargetInfoFn {
1003
RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
1004
TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
1008
/// RegisterTargetMachine - Helper template for registering a target machine
1009
/// implementation, for use in the target machine initialization
1010
/// function. Usage:
1012
/// extern "C" void LLVMInitializeFooTarget() {
1013
/// extern Target TheFooTarget;
1014
/// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1016
template<class TargetMachineImpl>
1017
struct RegisterTargetMachine {
1018
RegisterTargetMachine(Target &T) {
1019
TargetRegistry::RegisterTargetMachine(T, &Allocator);
1023
static TargetMachine *Allocator(const Target &T, StringRef TT,
1024
StringRef CPU, StringRef FS,
1025
const TargetOptions &Options,
1027
CodeModel::Model CM,
1028
CodeGenOpt::Level OL) {
1029
return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
1033
/// RegisterMCAsmBackend - Helper template for registering a target specific
1034
/// assembler backend. Usage:
1036
/// extern "C" void LLVMInitializeFooMCAsmBackend() {
1037
/// extern Target TheFooTarget;
1038
/// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1040
template<class MCAsmBackendImpl>
1041
struct RegisterMCAsmBackend {
1042
RegisterMCAsmBackend(Target &T) {
1043
TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1047
static MCAsmBackend *Allocator(const Target &T, StringRef Triple) {
1048
return new MCAsmBackendImpl(T, Triple);
1052
/// RegisterMCAsmLexer - Helper template for registering a target specific
1053
/// assembly lexer, for use in the target machine initialization
1054
/// function. Usage:
1056
/// extern "C" void LLVMInitializeFooMCAsmLexer() {
1057
/// extern Target TheFooTarget;
1058
/// RegisterMCAsmLexer<FooMCAsmLexer> X(TheFooTarget);
1060
template<class MCAsmLexerImpl>
1061
struct RegisterMCAsmLexer {
1062
RegisterMCAsmLexer(Target &T) {
1063
TargetRegistry::RegisterMCAsmLexer(T, &Allocator);
1067
static MCTargetAsmLexer *Allocator(const Target &T,
1068
const MCRegisterInfo &MRI,
1069
const MCAsmInfo &MAI) {
1070
return new MCAsmLexerImpl(T, MRI, MAI);
1074
/// RegisterMCAsmParser - Helper template for registering a target specific
1075
/// assembly parser, for use in the target machine initialization
1076
/// function. Usage:
1078
/// extern "C" void LLVMInitializeFooMCAsmParser() {
1079
/// extern Target TheFooTarget;
1080
/// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1082
template<class MCAsmParserImpl>
1083
struct RegisterMCAsmParser {
1084
RegisterMCAsmParser(Target &T) {
1085
TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1089
static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P) {
1090
return new MCAsmParserImpl(STI, P);
1094
/// RegisterAsmPrinter - Helper template for registering a target specific
1095
/// assembly printer, for use in the target machine initialization
1096
/// function. Usage:
1098
/// extern "C" void LLVMInitializeFooAsmPrinter() {
1099
/// extern Target TheFooTarget;
1100
/// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1102
template<class AsmPrinterImpl>
1103
struct RegisterAsmPrinter {
1104
RegisterAsmPrinter(Target &T) {
1105
TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1109
static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) {
1110
return new AsmPrinterImpl(TM, Streamer);
1114
/// RegisterMCCodeEmitter - Helper template for registering a target specific
1115
/// machine code emitter, for use in the target initialization
1116
/// function. Usage:
1118
/// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1119
/// extern Target TheFooTarget;
1120
/// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1122
template<class MCCodeEmitterImpl>
1123
struct RegisterMCCodeEmitter {
1124
RegisterMCCodeEmitter(Target &T) {
1125
TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1129
static MCCodeEmitter *Allocator(const MCInstrInfo &II,
1130
const MCSubtargetInfo &STI,
1132
return new MCCodeEmitterImpl();