1 //===-- Support/TargetRegistry.h - Target Registration ----------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 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. 13 // 14 // Target specific class implementations should register themselves using the 15 // appropriate TargetRegistry interfaces. 16 // 17 //===----------------------------------------------------------------------===// 18 19 #ifndef LLVM_SUPPORT_TARGETREGISTRY_H 20 #define LLVM_SUPPORT_TARGETREGISTRY_H 21 22 #include "llvm-c/Disassembler.h" 23 #include "llvm/ADT/Triple.h" 24 #include "llvm/Support/CodeGen.h" 25 #include <cassert> 26 #include <string> 27 28 namespace llvm { 29 class AsmPrinter; 30 class Module; 31 class MCAssembler; 32 class MCAsmBackend; 33 class MCAsmInfo; 34 class MCAsmParser; 35 class MCCodeEmitter; 36 class MCCodeGenInfo; 37 class MCContext; 38 class MCDisassembler; 39 class MCInstrAnalysis; 40 class MCInstPrinter; 41 class MCInstrInfo; 42 class MCRegisterInfo; 43 class MCStreamer; 44 class MCSubtargetInfo; 45 class MCSymbolizer; 46 class MCRelocationInfo; 47 class MCTargetAsmParser; 48 class MCTargetOptions; 49 class TargetMachine; 50 class TargetOptions; 51 class raw_ostream; 52 class formatted_raw_ostream; 53 54 MCStreamer *createNullStreamer(MCContext &Ctx); 55 MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS, 56 bool isVerboseAsm, bool useDwarfDirectory, 57 MCInstPrinter *InstPrint, MCCodeEmitter *CE, 58 MCAsmBackend *TAB, bool ShowInst); 59 60 MCRelocationInfo *createMCRelocationInfo(StringRef TT, MCContext &Ctx); 61 62 MCSymbolizer *createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo, 63 LLVMSymbolLookupCallback SymbolLookUp, 64 void *DisInfo, 65 MCContext *Ctx, 66 MCRelocationInfo *RelInfo); 67 68 /// Target - Wrapper for Target specific information. 69 /// 70 /// For registration purposes, this is a POD type so that targets can be 71 /// registered without the use of static constructors. 72 /// 73 /// Targets should implement a single global instance of this class (which 74 /// will be zero initialized), and pass that instance to the TargetRegistry as 75 /// part of their initialization. 76 class Target { 77 public: 78 friend struct TargetRegistry; 79 80 typedef bool (*ArchMatchFnTy)(Triple::ArchType Arch); 81 82 typedef MCAsmInfo *(*MCAsmInfoCtorFnTy)(const MCRegisterInfo &MRI, 83 StringRef TT); 84 typedef MCCodeGenInfo *(*MCCodeGenInfoCtorFnTy)(StringRef TT, 85 Reloc::Model RM, 86 CodeModel::Model CM, 87 CodeGenOpt::Level OL); 88 typedef MCInstrInfo *(*MCInstrInfoCtorFnTy)(void); 89 typedef MCInstrAnalysis *(*MCInstrAnalysisCtorFnTy)(const MCInstrInfo*Info); 90 typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(StringRef TT); 91 typedef MCSubtargetInfo *(*MCSubtargetInfoCtorFnTy)(StringRef TT, 92 StringRef CPU, 93 StringRef Features); 94 typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T, 95 StringRef TT, 96 StringRef CPU, 97 StringRef Features, 98 const TargetOptions &Options, 99 Reloc::Model RM, 100 CodeModel::Model CM, 101 CodeGenOpt::Level OL); 102 typedef AsmPrinter *(*AsmPrinterCtorTy)(TargetMachine &TM, 103 MCStreamer &Streamer); 104 typedef MCAsmBackend *(*MCAsmBackendCtorTy)(const Target &T, 105 const MCRegisterInfo &MRI, 106 StringRef TT, 107 StringRef CPU); 108 typedef MCTargetAsmParser *(*MCAsmParserCtorTy)( 109 MCSubtargetInfo &STI, 110 MCAsmParser &P, 111 const MCInstrInfo &MII, 112 const MCTargetOptions &Options); 113 typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T, 114 const MCSubtargetInfo &STI, 115 MCContext &Ctx); 116 typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T, 117 unsigned SyntaxVariant, 118 const MCAsmInfo &MAI, 119 const MCInstrInfo &MII, 120 const MCRegisterInfo &MRI, 121 const MCSubtargetInfo &STI); 122 typedef MCCodeEmitter *(*MCCodeEmitterCtorTy)(const MCInstrInfo &II, 123 const MCRegisterInfo &MRI, 124 const MCSubtargetInfo &STI, 125 MCContext &Ctx); 126 typedef MCStreamer *(*MCObjectStreamerCtorTy)( 127 const Target &T, StringRef TT, MCContext &Ctx, MCAsmBackend &TAB, 128 raw_ostream &_OS, MCCodeEmitter *_Emitter, const MCSubtargetInfo &STI, 129 bool RelaxAll); 130 typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx, 131 formatted_raw_ostream &OS, 132 bool isVerboseAsm, 133 bool useDwarfDirectory, 134 MCInstPrinter *InstPrint, 135 MCCodeEmitter *CE, 136 MCAsmBackend *TAB, 137 bool ShowInst); 138 typedef MCStreamer *(*NullStreamerCtorTy)(MCContext &Ctx); 139 typedef MCRelocationInfo *(*MCRelocationInfoCtorTy)(StringRef TT, 140 MCContext &Ctx); 141 typedef MCSymbolizer *(*MCSymbolizerCtorTy)(StringRef TT, 142 LLVMOpInfoCallback GetOpInfo, 143 LLVMSymbolLookupCallback SymbolLookUp, 144 void *DisInfo, 145 MCContext *Ctx, 146 MCRelocationInfo *RelInfo); 147 148 private: 149 /// Next - The next registered target in the linked list, maintained by the 150 /// TargetRegistry. 151 Target *Next; 152 153 /// The target function for checking if an architecture is supported. 154 ArchMatchFnTy ArchMatchFn; 155 156 /// Name - The target name. 157 const char *Name; 158 159 /// ShortDesc - A short description of the target. 160 const char *ShortDesc; 161 162 /// HasJIT - Whether this target supports the JIT. 163 bool HasJIT; 164 165 /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if 166 /// registered. 167 MCAsmInfoCtorFnTy MCAsmInfoCtorFn; 168 169 /// MCCodeGenInfoCtorFn - Constructor function for this target's 170 /// MCCodeGenInfo, if registered. 171 MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn; 172 173 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo, 174 /// if registered. 175 MCInstrInfoCtorFnTy MCInstrInfoCtorFn; 176 177 /// MCInstrAnalysisCtorFn - Constructor function for this target's 178 /// MCInstrAnalysis, if registered. 179 MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn; 180 181 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo, 182 /// if registered. 183 MCRegInfoCtorFnTy MCRegInfoCtorFn; 184 185 /// MCSubtargetInfoCtorFn - Constructor function for this target's 186 /// MCSubtargetInfo, if registered. 187 MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn; 188 189 /// TargetMachineCtorFn - Construction function for this target's 190 /// TargetMachine, if registered. 191 TargetMachineCtorTy TargetMachineCtorFn; 192 193 /// MCAsmBackendCtorFn - Construction function for this target's 194 /// MCAsmBackend, if registered. 195 MCAsmBackendCtorTy MCAsmBackendCtorFn; 196 197 /// MCAsmParserCtorFn - Construction function for this target's 198 /// MCTargetAsmParser, if registered. 199 MCAsmParserCtorTy MCAsmParserCtorFn; 200 201 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter, 202 /// if registered. 203 AsmPrinterCtorTy AsmPrinterCtorFn; 204 205 /// MCDisassemblerCtorFn - Construction function for this target's 206 /// MCDisassembler, if registered. 207 MCDisassemblerCtorTy MCDisassemblerCtorFn; 208 209 /// MCInstPrinterCtorFn - Construction function for this target's 210 /// MCInstPrinter, if registered. 211 MCInstPrinterCtorTy MCInstPrinterCtorFn; 212 213 /// MCCodeEmitterCtorFn - Construction function for this target's 214 /// CodeEmitter, if registered. 215 MCCodeEmitterCtorTy MCCodeEmitterCtorFn; 216 217 /// MCObjectStreamerCtorFn - Construction function for this target's 218 /// MCObjectStreamer, if registered. 219 MCObjectStreamerCtorTy MCObjectStreamerCtorFn; 220 221 /// AsmStreamerCtorFn - Construction function for this target's 222 /// AsmStreamer, if registered (default = llvm::createAsmStreamer). 223 AsmStreamerCtorTy AsmStreamerCtorFn; 224 225 /// Construction function for this target's NullStreamer, if registered 226 /// (default = llvm::createNullStreamer). 227 NullStreamerCtorTy NullStreamerCtorFn; 228 229 /// MCRelocationInfoCtorFn - Construction function for this target's 230 /// MCRelocationInfo, if registered (default = llvm::createMCRelocationInfo) 231 MCRelocationInfoCtorTy MCRelocationInfoCtorFn; 232 233 /// MCSymbolizerCtorFn - Construction function for this target's 234 /// MCSymbolizer, if registered (default = llvm::createMCSymbolizer) 235 MCSymbolizerCtorTy MCSymbolizerCtorFn; 236 237 public: Target()238 Target() 239 : AsmStreamerCtorFn(nullptr), NullStreamerCtorFn(nullptr), 240 MCRelocationInfoCtorFn(nullptr), MCSymbolizerCtorFn(nullptr) {} 241 242 /// @name Target Information 243 /// @{ 244 245 // getNext - Return the next registered target. getNext()246 const Target *getNext() const { return Next; } 247 248 /// getName - Get the target name. getName()249 const char *getName() const { return Name; } 250 251 /// getShortDescription - Get a short description of the target. getShortDescription()252 const char *getShortDescription() const { return ShortDesc; } 253 254 /// @} 255 /// @name Feature Predicates 256 /// @{ 257 258 /// hasJIT - Check if this targets supports the just-in-time compilation. hasJIT()259 bool hasJIT() const { return HasJIT; } 260 261 /// hasTargetMachine - Check if this target supports code generation. hasTargetMachine()262 bool hasTargetMachine() const { return TargetMachineCtorFn != nullptr; } 263 264 /// hasMCAsmBackend - Check if this target supports .o generation. hasMCAsmBackend()265 bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != nullptr; } 266 267 /// @} 268 /// @name Feature Constructors 269 /// @{ 270 271 /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified 272 /// target triple. 273 /// 274 /// \param Triple This argument is used to determine the target machine 275 /// feature set; it should always be provided. Generally this should be 276 /// either the target triple from the module, or the target triple of the 277 /// host if that does not exist. createMCAsmInfo(const MCRegisterInfo & MRI,StringRef Triple)278 MCAsmInfo *createMCAsmInfo(const MCRegisterInfo &MRI, 279 StringRef Triple) const { 280 if (!MCAsmInfoCtorFn) 281 return nullptr; 282 return MCAsmInfoCtorFn(MRI, Triple); 283 } 284 285 /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation. 286 /// createMCCodeGenInfo(StringRef Triple,Reloc::Model RM,CodeModel::Model CM,CodeGenOpt::Level OL)287 MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model RM, 288 CodeModel::Model CM, 289 CodeGenOpt::Level OL) const { 290 if (!MCCodeGenInfoCtorFn) 291 return nullptr; 292 return MCCodeGenInfoCtorFn(Triple, RM, CM, OL); 293 } 294 295 /// createMCInstrInfo - Create a MCInstrInfo implementation. 296 /// createMCInstrInfo()297 MCInstrInfo *createMCInstrInfo() const { 298 if (!MCInstrInfoCtorFn) 299 return nullptr; 300 return MCInstrInfoCtorFn(); 301 } 302 303 /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation. 304 /// createMCInstrAnalysis(const MCInstrInfo * Info)305 MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const { 306 if (!MCInstrAnalysisCtorFn) 307 return nullptr; 308 return MCInstrAnalysisCtorFn(Info); 309 } 310 311 /// createMCRegInfo - Create a MCRegisterInfo implementation. 312 /// createMCRegInfo(StringRef Triple)313 MCRegisterInfo *createMCRegInfo(StringRef Triple) const { 314 if (!MCRegInfoCtorFn) 315 return nullptr; 316 return MCRegInfoCtorFn(Triple); 317 } 318 319 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation. 320 /// 321 /// \param Triple This argument is used to determine the target machine 322 /// feature set; it should always be provided. Generally this should be 323 /// either the target triple from the module, or the target triple of the 324 /// host if that does not exist. 325 /// \param CPU This specifies the name of the target CPU. 326 /// \param Features This specifies the string representation of the 327 /// additional target features. createMCSubtargetInfo(StringRef Triple,StringRef CPU,StringRef Features)328 MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU, 329 StringRef Features) const { 330 if (!MCSubtargetInfoCtorFn) 331 return nullptr; 332 return MCSubtargetInfoCtorFn(Triple, CPU, Features); 333 } 334 335 /// createTargetMachine - Create a target specific machine implementation 336 /// for the specified \p Triple. 337 /// 338 /// \param Triple This argument is used to determine the target machine 339 /// feature set; it should always be provided. Generally this should be 340 /// either the target triple from the module, or the target triple of the 341 /// host if that does not exist. 342 TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU, 343 StringRef Features, const TargetOptions &Options, 344 Reloc::Model RM = Reloc::Default, 345 CodeModel::Model CM = CodeModel::Default, 346 CodeGenOpt::Level OL = CodeGenOpt::Default) const { 347 if (!TargetMachineCtorFn) 348 return nullptr; 349 return TargetMachineCtorFn(*this, Triple, CPU, Features, Options, 350 RM, CM, OL); 351 } 352 353 /// createMCAsmBackend - Create a target specific assembly parser. 354 /// 355 /// \param Triple The target triple string. createMCAsmBackend(const MCRegisterInfo & MRI,StringRef Triple,StringRef CPU)356 MCAsmBackend *createMCAsmBackend(const MCRegisterInfo &MRI, 357 StringRef Triple, StringRef CPU) const { 358 if (!MCAsmBackendCtorFn) 359 return nullptr; 360 return MCAsmBackendCtorFn(*this, MRI, Triple, CPU); 361 } 362 363 /// createMCAsmParser - Create a target specific assembly parser. 364 /// 365 /// \param Parser The target independent parser implementation to use for 366 /// parsing and lexing. createMCAsmParser(MCSubtargetInfo & STI,MCAsmParser & Parser,const MCInstrInfo & MII,const MCTargetOptions & Options)367 MCTargetAsmParser *createMCAsmParser( 368 MCSubtargetInfo &STI, 369 MCAsmParser &Parser, 370 const MCInstrInfo &MII, 371 const MCTargetOptions &Options) const { 372 if (!MCAsmParserCtorFn) 373 return nullptr; 374 return MCAsmParserCtorFn(STI, Parser, MII, Options); 375 } 376 377 /// createAsmPrinter - Create a target specific assembly printer pass. This 378 /// takes ownership of the MCStreamer object. createAsmPrinter(TargetMachine & TM,MCStreamer & Streamer)379 AsmPrinter *createAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) const{ 380 if (!AsmPrinterCtorFn) 381 return nullptr; 382 return AsmPrinterCtorFn(TM, Streamer); 383 } 384 createMCDisassembler(const MCSubtargetInfo & STI,MCContext & Ctx)385 MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI, 386 MCContext &Ctx) const { 387 if (!MCDisassemblerCtorFn) 388 return nullptr; 389 return MCDisassemblerCtorFn(*this, STI, Ctx); 390 } 391 createMCInstPrinter(unsigned SyntaxVariant,const MCAsmInfo & MAI,const MCInstrInfo & MII,const MCRegisterInfo & MRI,const MCSubtargetInfo & STI)392 MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant, 393 const MCAsmInfo &MAI, 394 const MCInstrInfo &MII, 395 const MCRegisterInfo &MRI, 396 const MCSubtargetInfo &STI) const { 397 if (!MCInstPrinterCtorFn) 398 return nullptr; 399 return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, MII, MRI, STI); 400 } 401 402 403 /// createMCCodeEmitter - Create a target specific code emitter. createMCCodeEmitter(const MCInstrInfo & II,const MCRegisterInfo & MRI,const MCSubtargetInfo & STI,MCContext & Ctx)404 MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II, 405 const MCRegisterInfo &MRI, 406 const MCSubtargetInfo &STI, 407 MCContext &Ctx) const { 408 if (!MCCodeEmitterCtorFn) 409 return nullptr; 410 return MCCodeEmitterCtorFn(II, MRI, STI, Ctx); 411 } 412 413 /// createMCObjectStreamer - Create a target specific MCStreamer. 414 /// 415 /// \param TT The target triple. 416 /// \param Ctx The target context. 417 /// \param TAB The target assembler backend object. Takes ownership. 418 /// \param _OS The stream object. 419 /// \param _Emitter The target independent assembler object.Takes ownership. 420 /// \param RelaxAll Relax all fixups? createMCObjectStreamer(StringRef TT,MCContext & Ctx,MCAsmBackend & TAB,raw_ostream & _OS,MCCodeEmitter * _Emitter,const MCSubtargetInfo & STI,bool RelaxAll)421 MCStreamer *createMCObjectStreamer(StringRef TT, MCContext &Ctx, 422 MCAsmBackend &TAB, raw_ostream &_OS, 423 MCCodeEmitter *_Emitter, 424 const MCSubtargetInfo &STI, 425 bool RelaxAll) const { 426 if (!MCObjectStreamerCtorFn) 427 return nullptr; 428 return MCObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter, STI, 429 RelaxAll); 430 } 431 432 /// createAsmStreamer - Create a target specific MCStreamer. createAsmStreamer(MCContext & Ctx,formatted_raw_ostream & OS,bool isVerboseAsm,bool useDwarfDirectory,MCInstPrinter * InstPrint,MCCodeEmitter * CE,MCAsmBackend * TAB,bool ShowInst)433 MCStreamer *createAsmStreamer(MCContext &Ctx, 434 formatted_raw_ostream &OS, 435 bool isVerboseAsm, 436 bool useDwarfDirectory, 437 MCInstPrinter *InstPrint, 438 MCCodeEmitter *CE, 439 MCAsmBackend *TAB, 440 bool ShowInst) const { 441 if (AsmStreamerCtorFn) 442 return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useDwarfDirectory, 443 InstPrint, CE, TAB, ShowInst); 444 return llvm::createAsmStreamer(Ctx, OS, isVerboseAsm, useDwarfDirectory, 445 InstPrint, CE, TAB, ShowInst); 446 } 447 createNullStreamer(MCContext & Ctx)448 MCStreamer *createNullStreamer(MCContext &Ctx) const { 449 if (NullStreamerCtorFn) 450 return NullStreamerCtorFn(Ctx); 451 return llvm::createNullStreamer(Ctx); 452 } 453 454 /// createMCRelocationInfo - Create a target specific MCRelocationInfo. 455 /// 456 /// \param TT The target triple. 457 /// \param Ctx The target context. 458 MCRelocationInfo * createMCRelocationInfo(StringRef TT,MCContext & Ctx)459 createMCRelocationInfo(StringRef TT, MCContext &Ctx) const { 460 MCRelocationInfoCtorTy Fn = MCRelocationInfoCtorFn 461 ? MCRelocationInfoCtorFn 462 : llvm::createMCRelocationInfo; 463 return Fn(TT, Ctx); 464 } 465 466 /// createMCSymbolizer - Create a target specific MCSymbolizer. 467 /// 468 /// \param TT The target triple. 469 /// \param GetOpInfo The function to get the symbolic information for operands. 470 /// \param SymbolLookUp The function to lookup a symbol name. 471 /// \param DisInfo The pointer to the block of symbolic information for above call 472 /// back. 473 /// \param Ctx The target context. 474 /// \param RelInfo The relocation information for this target. Takes ownership. 475 MCSymbolizer * createMCSymbolizer(StringRef TT,LLVMOpInfoCallback GetOpInfo,LLVMSymbolLookupCallback SymbolLookUp,void * DisInfo,MCContext * Ctx,MCRelocationInfo * RelInfo)476 createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo, 477 LLVMSymbolLookupCallback SymbolLookUp, 478 void *DisInfo, 479 MCContext *Ctx, MCRelocationInfo *RelInfo) const { 480 MCSymbolizerCtorTy Fn = 481 MCSymbolizerCtorFn ? MCSymbolizerCtorFn : llvm::createMCSymbolizer; 482 return Fn(TT, GetOpInfo, SymbolLookUp, DisInfo, Ctx, RelInfo); 483 } 484 485 /// @} 486 }; 487 488 /// TargetRegistry - Generic interface to target specific features. 489 struct TargetRegistry { 490 class iterator { 491 const Target *Current; iteratorTargetRegistry492 explicit iterator(Target *T) : Current(T) {} 493 friend struct TargetRegistry; 494 public: iteratorTargetRegistry495 iterator() : Current(nullptr) {} 496 497 bool operator==(const iterator &x) const { 498 return Current == x.Current; 499 } 500 bool operator!=(const iterator &x) const { 501 return !operator==(x); 502 } 503 504 // Iterator traversal: forward iteration only 505 iterator &operator++() { // Preincrement 506 assert(Current && "Cannot increment end iterator!"); 507 Current = Current->getNext(); 508 return *this; 509 } 510 iterator operator++(int) { // Postincrement 511 iterator tmp = *this; 512 ++*this; 513 return tmp; 514 } 515 516 const Target &operator*() const { 517 assert(Current && "Cannot dereference end iterator!"); 518 return *Current; 519 } 520 521 const Target *operator->() const { 522 return &operator*(); 523 } 524 }; 525 526 /// printRegisteredTargetsForVersion - Print the registered targets 527 /// appropriately for inclusion in a tool's version output. 528 static void printRegisteredTargetsForVersion(); 529 530 /// @name Registry Access 531 /// @{ 532 533 static iterator begin(); 534 endTargetRegistry535 static iterator end() { return iterator(); } 536 537 /// lookupTarget - Lookup a target based on a target triple. 538 /// 539 /// \param Triple - The triple to use for finding a target. 540 /// \param Error - On failure, an error string describing why no target was 541 /// found. 542 static const Target *lookupTarget(const std::string &Triple, 543 std::string &Error); 544 545 /// lookupTarget - Lookup a target based on an architecture name 546 /// and a target triple. If the architecture name is non-empty, 547 /// then the lookup is done by architecture. Otherwise, the target 548 /// triple is used. 549 /// 550 /// \param ArchName - The architecture to use for finding a target. 551 /// \param TheTriple - The triple to use for finding a target. The 552 /// triple is updated with canonical architecture name if a lookup 553 /// by architecture is done. 554 /// \param Error - On failure, an error string describing why no target was 555 /// found. 556 static const Target *lookupTarget(const std::string &ArchName, 557 Triple &TheTriple, 558 std::string &Error); 559 560 /// @} 561 /// @name Target Registration 562 /// @{ 563 564 /// RegisterTarget - Register the given target. Attempts to register a 565 /// target which has already been registered will be ignored. 566 /// 567 /// Clients are responsible for ensuring that registration doesn't occur 568 /// while another thread is attempting to access the registry. Typically 569 /// this is done by initializing all targets at program startup. 570 /// 571 /// @param T - The target being registered. 572 /// @param Name - The target name. This should be a static string. 573 /// @param ShortDesc - A short target description. This should be a static 574 /// string. 575 /// @param ArchMatchFn - The arch match checking function for this target. 576 /// @param HasJIT - Whether the target supports JIT code 577 /// generation. 578 static void RegisterTarget(Target &T, 579 const char *Name, 580 const char *ShortDesc, 581 Target::ArchMatchFnTy ArchMatchFn, 582 bool HasJIT = false); 583 584 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the 585 /// given target. 586 /// 587 /// Clients are responsible for ensuring that registration doesn't occur 588 /// while another thread is attempting to access the registry. Typically 589 /// this is done by initializing all targets at program startup. 590 /// 591 /// @param T - The target being registered. 592 /// @param Fn - A function to construct a MCAsmInfo for the target. RegisterMCAsmInfoTargetRegistry593 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) { 594 T.MCAsmInfoCtorFn = Fn; 595 } 596 597 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the 598 /// given target. 599 /// 600 /// Clients are responsible for ensuring that registration doesn't occur 601 /// while another thread is attempting to access the registry. Typically 602 /// this is done by initializing all targets at program startup. 603 /// 604 /// @param T - The target being registered. 605 /// @param Fn - A function to construct a MCCodeGenInfo for the target. RegisterMCCodeGenInfoTargetRegistry606 static void RegisterMCCodeGenInfo(Target &T, 607 Target::MCCodeGenInfoCtorFnTy Fn) { 608 T.MCCodeGenInfoCtorFn = Fn; 609 } 610 611 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the 612 /// given target. 613 /// 614 /// Clients are responsible for ensuring that registration doesn't occur 615 /// while another thread is attempting to access the registry. Typically 616 /// this is done by initializing all targets at program startup. 617 /// 618 /// @param T - The target being registered. 619 /// @param Fn - A function to construct a MCInstrInfo for the target. RegisterMCInstrInfoTargetRegistry620 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) { 621 T.MCInstrInfoCtorFn = Fn; 622 } 623 624 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for 625 /// the given target. RegisterMCInstrAnalysisTargetRegistry626 static void RegisterMCInstrAnalysis(Target &T, 627 Target::MCInstrAnalysisCtorFnTy Fn) { 628 T.MCInstrAnalysisCtorFn = Fn; 629 } 630 631 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the 632 /// given target. 633 /// 634 /// Clients are responsible for ensuring that registration doesn't occur 635 /// while another thread is attempting to access the registry. Typically 636 /// this is done by initializing all targets at program startup. 637 /// 638 /// @param T - The target being registered. 639 /// @param Fn - A function to construct a MCRegisterInfo for the target. RegisterMCRegInfoTargetRegistry640 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) { 641 T.MCRegInfoCtorFn = Fn; 642 } 643 644 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for 645 /// the given target. 646 /// 647 /// Clients are responsible for ensuring that registration doesn't occur 648 /// while another thread is attempting to access the registry. Typically 649 /// this is done by initializing all targets at program startup. 650 /// 651 /// @param T - The target being registered. 652 /// @param Fn - A function to construct a MCSubtargetInfo for the target. RegisterMCSubtargetInfoTargetRegistry653 static void RegisterMCSubtargetInfo(Target &T, 654 Target::MCSubtargetInfoCtorFnTy Fn) { 655 T.MCSubtargetInfoCtorFn = Fn; 656 } 657 658 /// RegisterTargetMachine - Register a TargetMachine implementation for the 659 /// given target. 660 /// 661 /// Clients are responsible for ensuring that registration doesn't occur 662 /// while another thread is attempting to access the registry. Typically 663 /// this is done by initializing all targets at program startup. 664 /// 665 /// @param T - The target being registered. 666 /// @param Fn - A function to construct a TargetMachine for the target. RegisterTargetMachineTargetRegistry667 static void RegisterTargetMachine(Target &T, 668 Target::TargetMachineCtorTy Fn) { 669 T.TargetMachineCtorFn = Fn; 670 } 671 672 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the 673 /// given target. 674 /// 675 /// Clients are responsible for ensuring that registration doesn't occur 676 /// while another thread is attempting to access the registry. Typically 677 /// this is done by initializing all targets at program startup. 678 /// 679 /// @param T - The target being registered. 680 /// @param Fn - A function to construct an AsmBackend for the target. RegisterMCAsmBackendTargetRegistry681 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) { 682 T.MCAsmBackendCtorFn = Fn; 683 } 684 685 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for 686 /// the given target. 687 /// 688 /// Clients are responsible for ensuring that registration doesn't occur 689 /// while another thread is attempting to access the registry. Typically 690 /// this is done by initializing all targets at program startup. 691 /// 692 /// @param T - The target being registered. 693 /// @param Fn - A function to construct an MCTargetAsmParser for the target. RegisterMCAsmParserTargetRegistry694 static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) { 695 T.MCAsmParserCtorFn = Fn; 696 } 697 698 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given 699 /// target. 700 /// 701 /// Clients are responsible for ensuring that registration doesn't occur 702 /// while another thread is attempting to access the registry. Typically 703 /// this is done by initializing all targets at program startup. 704 /// 705 /// @param T - The target being registered. 706 /// @param Fn - A function to construct an AsmPrinter for the target. RegisterAsmPrinterTargetRegistry707 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) { 708 T.AsmPrinterCtorFn = Fn; 709 } 710 711 /// RegisterMCDisassembler - Register a MCDisassembler implementation for 712 /// the given target. 713 /// 714 /// Clients are responsible for ensuring that registration doesn't occur 715 /// while another thread is attempting to access the registry. Typically 716 /// this is done by initializing all targets at program startup. 717 /// 718 /// @param T - The target being registered. 719 /// @param Fn - A function to construct an MCDisassembler for the target. RegisterMCDisassemblerTargetRegistry720 static void RegisterMCDisassembler(Target &T, 721 Target::MCDisassemblerCtorTy Fn) { 722 T.MCDisassemblerCtorFn = Fn; 723 } 724 725 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the 726 /// given target. 727 /// 728 /// Clients are responsible for ensuring that registration doesn't occur 729 /// while another thread is attempting to access the registry. Typically 730 /// this is done by initializing all targets at program startup. 731 /// 732 /// @param T - The target being registered. 733 /// @param Fn - A function to construct an MCInstPrinter for the target. RegisterMCInstPrinterTargetRegistry734 static void RegisterMCInstPrinter(Target &T, 735 Target::MCInstPrinterCtorTy Fn) { 736 T.MCInstPrinterCtorFn = Fn; 737 } 738 739 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the 740 /// given target. 741 /// 742 /// Clients are responsible for ensuring that registration doesn't occur 743 /// while another thread is attempting to access the registry. Typically 744 /// this is done by initializing all targets at program startup. 745 /// 746 /// @param T - The target being registered. 747 /// @param Fn - A function to construct an MCCodeEmitter for the target. RegisterMCCodeEmitterTargetRegistry748 static void RegisterMCCodeEmitter(Target &T, 749 Target::MCCodeEmitterCtorTy Fn) { 750 T.MCCodeEmitterCtorFn = Fn; 751 } 752 753 /// RegisterMCObjectStreamer - Register a object code MCStreamer 754 /// implementation for the given target. 755 /// 756 /// Clients are responsible for ensuring that registration doesn't occur 757 /// while another thread is attempting to access the registry. Typically 758 /// this is done by initializing all targets at program startup. 759 /// 760 /// @param T - The target being registered. 761 /// @param Fn - A function to construct an MCStreamer for the target. RegisterMCObjectStreamerTargetRegistry762 static void RegisterMCObjectStreamer(Target &T, 763 Target::MCObjectStreamerCtorTy Fn) { 764 T.MCObjectStreamerCtorFn = Fn; 765 } 766 767 /// RegisterAsmStreamer - Register an assembly MCStreamer implementation 768 /// for the given target. 769 /// 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. 773 /// 774 /// @param T - The target being registered. 775 /// @param Fn - A function to construct an MCStreamer for the target. RegisterAsmStreamerTargetRegistry776 static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) { 777 T.AsmStreamerCtorFn = Fn; 778 } 779 RegisterNullStreamerTargetRegistry780 static void RegisterNullStreamer(Target &T, Target::NullStreamerCtorTy Fn) { 781 T.NullStreamerCtorFn = Fn; 782 } 783 784 /// RegisterMCRelocationInfo - Register an MCRelocationInfo 785 /// implementation for the given target. 786 /// 787 /// Clients are responsible for ensuring that registration doesn't occur 788 /// while another thread is attempting to access the registry. Typically 789 /// this is done by initializing all targets at program startup. 790 /// 791 /// @param T - The target being registered. 792 /// @param Fn - A function to construct an MCRelocationInfo for the target. RegisterMCRelocationInfoTargetRegistry793 static void RegisterMCRelocationInfo(Target &T, 794 Target::MCRelocationInfoCtorTy Fn) { 795 T.MCRelocationInfoCtorFn = Fn; 796 } 797 798 /// RegisterMCSymbolizer - Register an MCSymbolizer 799 /// implementation for the given target. 800 /// 801 /// Clients are responsible for ensuring that registration doesn't occur 802 /// while another thread is attempting to access the registry. Typically 803 /// this is done by initializing all targets at program startup. 804 /// 805 /// @param T - The target being registered. 806 /// @param Fn - A function to construct an MCSymbolizer for the target. RegisterMCSymbolizerTargetRegistry807 static void RegisterMCSymbolizer(Target &T, 808 Target::MCSymbolizerCtorTy Fn) { 809 T.MCSymbolizerCtorFn = Fn; 810 } 811 812 /// @} 813 }; 814 815 816 //===--------------------------------------------------------------------===// 817 818 /// RegisterTarget - Helper template for registering a target, for use in the 819 /// target's initialization function. Usage: 820 /// 821 /// 822 /// Target TheFooTarget; // The global target instance. 823 /// 824 /// extern "C" void LLVMInitializeFooTargetInfo() { 825 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description"); 826 /// } 827 template<Triple::ArchType TargetArchType = Triple::UnknownArch, 828 bool HasJIT = false> 829 struct RegisterTarget { RegisterTargetRegisterTarget830 RegisterTarget(Target &T, const char *Name, const char *Desc) { 831 TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch, HasJIT); 832 } 833 getArchMatchRegisterTarget834 static bool getArchMatch(Triple::ArchType Arch) { 835 return Arch == TargetArchType; 836 } 837 }; 838 839 /// RegisterMCAsmInfo - Helper template for registering a target assembly info 840 /// implementation. This invokes the static "Create" method on the class to 841 /// actually do the construction. Usage: 842 /// 843 /// extern "C" void LLVMInitializeFooTarget() { 844 /// extern Target TheFooTarget; 845 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget); 846 /// } 847 template<class MCAsmInfoImpl> 848 struct RegisterMCAsmInfo { RegisterMCAsmInfoRegisterMCAsmInfo849 RegisterMCAsmInfo(Target &T) { 850 TargetRegistry::RegisterMCAsmInfo(T, &Allocator); 851 } 852 private: AllocatorRegisterMCAsmInfo853 static MCAsmInfo *Allocator(const MCRegisterInfo &/*MRI*/, StringRef TT) { 854 return new MCAsmInfoImpl(TT); 855 } 856 857 }; 858 859 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info 860 /// implementation. This invokes the specified function to do the 861 /// construction. Usage: 862 /// 863 /// extern "C" void LLVMInitializeFooTarget() { 864 /// extern Target TheFooTarget; 865 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction); 866 /// } 867 struct RegisterMCAsmInfoFn { RegisterMCAsmInfoFnRegisterMCAsmInfoFn868 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) { 869 TargetRegistry::RegisterMCAsmInfo(T, Fn); 870 } 871 }; 872 873 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info 874 /// implementation. This invokes the static "Create" method on the class 875 /// to actually do the construction. Usage: 876 /// 877 /// extern "C" void LLVMInitializeFooTarget() { 878 /// extern Target TheFooTarget; 879 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget); 880 /// } 881 template<class MCCodeGenInfoImpl> 882 struct RegisterMCCodeGenInfo { RegisterMCCodeGenInfoRegisterMCCodeGenInfo883 RegisterMCCodeGenInfo(Target &T) { 884 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator); 885 } 886 private: AllocatorRegisterMCCodeGenInfo887 static MCCodeGenInfo *Allocator(StringRef /*TT*/, Reloc::Model /*RM*/, 888 CodeModel::Model /*CM*/, 889 CodeGenOpt::Level /*OL*/) { 890 return new MCCodeGenInfoImpl(); 891 } 892 }; 893 894 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen 895 /// info implementation. This invokes the specified function to do the 896 /// construction. Usage: 897 /// 898 /// extern "C" void LLVMInitializeFooTarget() { 899 /// extern Target TheFooTarget; 900 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction); 901 /// } 902 struct RegisterMCCodeGenInfoFn { RegisterMCCodeGenInfoFnRegisterMCCodeGenInfoFn903 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) { 904 TargetRegistry::RegisterMCCodeGenInfo(T, Fn); 905 } 906 }; 907 908 /// RegisterMCInstrInfo - Helper template for registering a target instruction 909 /// info implementation. This invokes the static "Create" method on the class 910 /// to actually do the construction. Usage: 911 /// 912 /// extern "C" void LLVMInitializeFooTarget() { 913 /// extern Target TheFooTarget; 914 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget); 915 /// } 916 template<class MCInstrInfoImpl> 917 struct RegisterMCInstrInfo { RegisterMCInstrInfoRegisterMCInstrInfo918 RegisterMCInstrInfo(Target &T) { 919 TargetRegistry::RegisterMCInstrInfo(T, &Allocator); 920 } 921 private: AllocatorRegisterMCInstrInfo922 static MCInstrInfo *Allocator() { 923 return new MCInstrInfoImpl(); 924 } 925 }; 926 927 /// RegisterMCInstrInfoFn - Helper template for registering a target 928 /// instruction info implementation. This invokes the specified function to 929 /// do the construction. Usage: 930 /// 931 /// extern "C" void LLVMInitializeFooTarget() { 932 /// extern Target TheFooTarget; 933 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction); 934 /// } 935 struct RegisterMCInstrInfoFn { RegisterMCInstrInfoFnRegisterMCInstrInfoFn936 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) { 937 TargetRegistry::RegisterMCInstrInfo(T, Fn); 938 } 939 }; 940 941 /// RegisterMCInstrAnalysis - Helper template for registering a target 942 /// instruction analyzer implementation. This invokes the static "Create" 943 /// method on the class to actually do the construction. Usage: 944 /// 945 /// extern "C" void LLVMInitializeFooTarget() { 946 /// extern Target TheFooTarget; 947 /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget); 948 /// } 949 template<class MCInstrAnalysisImpl> 950 struct RegisterMCInstrAnalysis { RegisterMCInstrAnalysisRegisterMCInstrAnalysis951 RegisterMCInstrAnalysis(Target &T) { 952 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator); 953 } 954 private: AllocatorRegisterMCInstrAnalysis955 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) { 956 return new MCInstrAnalysisImpl(Info); 957 } 958 }; 959 960 /// RegisterMCInstrAnalysisFn - Helper template for registering a target 961 /// instruction analyzer implementation. This invokes the specified function 962 /// to do the construction. Usage: 963 /// 964 /// extern "C" void LLVMInitializeFooTarget() { 965 /// extern Target TheFooTarget; 966 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction); 967 /// } 968 struct RegisterMCInstrAnalysisFn { RegisterMCInstrAnalysisFnRegisterMCInstrAnalysisFn969 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) { 970 TargetRegistry::RegisterMCInstrAnalysis(T, Fn); 971 } 972 }; 973 974 /// RegisterMCRegInfo - Helper template for registering a target register info 975 /// implementation. This invokes the static "Create" method on the class to 976 /// actually do the construction. Usage: 977 /// 978 /// extern "C" void LLVMInitializeFooTarget() { 979 /// extern Target TheFooTarget; 980 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget); 981 /// } 982 template<class MCRegisterInfoImpl> 983 struct RegisterMCRegInfo { RegisterMCRegInfoRegisterMCRegInfo984 RegisterMCRegInfo(Target &T) { 985 TargetRegistry::RegisterMCRegInfo(T, &Allocator); 986 } 987 private: AllocatorRegisterMCRegInfo988 static MCRegisterInfo *Allocator(StringRef /*TT*/) { 989 return new MCRegisterInfoImpl(); 990 } 991 }; 992 993 /// RegisterMCRegInfoFn - Helper template for registering a target register 994 /// info implementation. This invokes the specified function to do the 995 /// construction. Usage: 996 /// 997 /// extern "C" void LLVMInitializeFooTarget() { 998 /// extern Target TheFooTarget; 999 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction); 1000 /// } 1001 struct RegisterMCRegInfoFn { RegisterMCRegInfoFnRegisterMCRegInfoFn1002 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) { 1003 TargetRegistry::RegisterMCRegInfo(T, Fn); 1004 } 1005 }; 1006 1007 /// RegisterMCSubtargetInfo - Helper template for registering a target 1008 /// subtarget info implementation. This invokes the static "Create" method 1009 /// on the class to actually do the construction. Usage: 1010 /// 1011 /// extern "C" void LLVMInitializeFooTarget() { 1012 /// extern Target TheFooTarget; 1013 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget); 1014 /// } 1015 template<class MCSubtargetInfoImpl> 1016 struct RegisterMCSubtargetInfo { RegisterMCSubtargetInfoRegisterMCSubtargetInfo1017 RegisterMCSubtargetInfo(Target &T) { 1018 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator); 1019 } 1020 private: AllocatorRegisterMCSubtargetInfo1021 static MCSubtargetInfo *Allocator(StringRef /*TT*/, StringRef /*CPU*/, 1022 StringRef /*FS*/) { 1023 return new MCSubtargetInfoImpl(); 1024 } 1025 }; 1026 1027 /// RegisterMCSubtargetInfoFn - Helper template for registering a target 1028 /// subtarget info implementation. This invokes the specified function to 1029 /// do the construction. Usage: 1030 /// 1031 /// extern "C" void LLVMInitializeFooTarget() { 1032 /// extern Target TheFooTarget; 1033 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction); 1034 /// } 1035 struct RegisterMCSubtargetInfoFn { RegisterMCSubtargetInfoFnRegisterMCSubtargetInfoFn1036 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) { 1037 TargetRegistry::RegisterMCSubtargetInfo(T, Fn); 1038 } 1039 }; 1040 1041 /// RegisterTargetMachine - Helper template for registering a target machine 1042 /// implementation, for use in the target machine initialization 1043 /// function. Usage: 1044 /// 1045 /// extern "C" void LLVMInitializeFooTarget() { 1046 /// extern Target TheFooTarget; 1047 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget); 1048 /// } 1049 template<class TargetMachineImpl> 1050 struct RegisterTargetMachine { RegisterTargetMachineRegisterTargetMachine1051 RegisterTargetMachine(Target &T) { 1052 TargetRegistry::RegisterTargetMachine(T, &Allocator); 1053 } 1054 1055 private: AllocatorRegisterTargetMachine1056 static TargetMachine *Allocator(const Target &T, StringRef TT, 1057 StringRef CPU, StringRef FS, 1058 const TargetOptions &Options, 1059 Reloc::Model RM, 1060 CodeModel::Model CM, 1061 CodeGenOpt::Level OL) { 1062 return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL); 1063 } 1064 }; 1065 1066 /// RegisterMCAsmBackend - Helper template for registering a target specific 1067 /// assembler backend. Usage: 1068 /// 1069 /// extern "C" void LLVMInitializeFooMCAsmBackend() { 1070 /// extern Target TheFooTarget; 1071 /// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget); 1072 /// } 1073 template<class MCAsmBackendImpl> 1074 struct RegisterMCAsmBackend { RegisterMCAsmBackendRegisterMCAsmBackend1075 RegisterMCAsmBackend(Target &T) { 1076 TargetRegistry::RegisterMCAsmBackend(T, &Allocator); 1077 } 1078 1079 private: AllocatorRegisterMCAsmBackend1080 static MCAsmBackend *Allocator(const Target &T, 1081 const MCRegisterInfo &MRI, 1082 StringRef Triple, StringRef CPU) { 1083 return new MCAsmBackendImpl(T, MRI, Triple, CPU); 1084 } 1085 }; 1086 1087 /// RegisterMCAsmParser - Helper template for registering a target specific 1088 /// assembly parser, for use in the target machine initialization 1089 /// function. Usage: 1090 /// 1091 /// extern "C" void LLVMInitializeFooMCAsmParser() { 1092 /// extern Target TheFooTarget; 1093 /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget); 1094 /// } 1095 template<class MCAsmParserImpl> 1096 struct RegisterMCAsmParser { RegisterMCAsmParserRegisterMCAsmParser1097 RegisterMCAsmParser(Target &T) { 1098 TargetRegistry::RegisterMCAsmParser(T, &Allocator); 1099 } 1100 1101 private: AllocatorRegisterMCAsmParser1102 static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P, 1103 const MCInstrInfo &MII, 1104 const MCTargetOptions &Options) { 1105 return new MCAsmParserImpl(STI, P, MII, Options); 1106 } 1107 }; 1108 1109 /// RegisterAsmPrinter - Helper template for registering a target specific 1110 /// assembly printer, for use in the target machine initialization 1111 /// function. Usage: 1112 /// 1113 /// extern "C" void LLVMInitializeFooAsmPrinter() { 1114 /// extern Target TheFooTarget; 1115 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget); 1116 /// } 1117 template<class AsmPrinterImpl> 1118 struct RegisterAsmPrinter { RegisterAsmPrinterRegisterAsmPrinter1119 RegisterAsmPrinter(Target &T) { 1120 TargetRegistry::RegisterAsmPrinter(T, &Allocator); 1121 } 1122 1123 private: AllocatorRegisterAsmPrinter1124 static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) { 1125 return new AsmPrinterImpl(TM, Streamer); 1126 } 1127 }; 1128 1129 /// RegisterMCCodeEmitter - Helper template for registering a target specific 1130 /// machine code emitter, for use in the target initialization 1131 /// function. Usage: 1132 /// 1133 /// extern "C" void LLVMInitializeFooMCCodeEmitter() { 1134 /// extern Target TheFooTarget; 1135 /// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget); 1136 /// } 1137 template<class MCCodeEmitterImpl> 1138 struct RegisterMCCodeEmitter { RegisterMCCodeEmitterRegisterMCCodeEmitter1139 RegisterMCCodeEmitter(Target &T) { 1140 TargetRegistry::RegisterMCCodeEmitter(T, &Allocator); 1141 } 1142 1143 private: AllocatorRegisterMCCodeEmitter1144 static MCCodeEmitter *Allocator(const MCInstrInfo &/*II*/, 1145 const MCRegisterInfo &/*MRI*/, 1146 const MCSubtargetInfo &/*STI*/, 1147 MCContext &/*Ctx*/) { 1148 return new MCCodeEmitterImpl(); 1149 } 1150 }; 1151 1152 } 1153 1154 #endif 1155