Recommit [NFC] Better encapsulation of llvm::Optional Storage
[llvm-complete.git] / include / llvm / Support / TargetRegistry.h
blob5854d57fba933c768f21844fe7474eecbc22afff
1 //===- Support/TargetRegistry.h - Target Registration -----------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file exposes the TargetRegistry interface, which tools can use to access
10 // the appropriate target specific classes (TargetMachine, AsmPrinter, etc.)
11 // which have been registered.
13 // Target specific class implementations should register themselves using the
14 // appropriate TargetRegistry interfaces.
16 //===----------------------------------------------------------------------===//
18 #ifndef LLVM_SUPPORT_TARGETREGISTRY_H
19 #define LLVM_SUPPORT_TARGETREGISTRY_H
21 #include "llvm-c/DisassemblerTypes.h"
22 #include "llvm/ADT/Optional.h"
23 #include "llvm/ADT/StringRef.h"
24 #include "llvm/ADT/Triple.h"
25 #include "llvm/ADT/iterator_range.h"
26 #include "llvm/Support/CodeGen.h"
27 #include "llvm/Support/ErrorHandling.h"
28 #include "llvm/Support/FormattedStream.h"
29 #include <algorithm>
30 #include <cassert>
31 #include <cstddef>
32 #include <iterator>
33 #include <memory>
34 #include <string>
36 namespace llvm {
38 class AsmPrinter;
39 class MCAsmBackend;
40 class MCAsmInfo;
41 class MCAsmParser;
42 class MCCodeEmitter;
43 class MCContext;
44 class MCDisassembler;
45 class MCInstPrinter;
46 class MCInstrAnalysis;
47 class MCInstrInfo;
48 class MCObjectWriter;
49 class MCRegisterInfo;
50 class MCRelocationInfo;
51 class MCStreamer;
52 class MCSubtargetInfo;
53 class MCSymbolizer;
54 class MCTargetAsmParser;
55 class MCTargetOptions;
56 class MCTargetStreamer;
57 class raw_ostream;
58 class raw_pwrite_stream;
59 class TargetMachine;
60 class TargetOptions;
62 MCStreamer *createNullStreamer(MCContext &Ctx);
63 // Takes ownership of \p TAB and \p CE.
65 /// Create a machine code streamer which will print out assembly for the native
66 /// target, suitable for compiling with a native assembler.
67 ///
68 /// \param InstPrint - If given, the instruction printer to use. If not given
69 /// the MCInst representation will be printed. This method takes ownership of
70 /// InstPrint.
71 ///
72 /// \param CE - If given, a code emitter to use to show the instruction
73 /// encoding inline with the assembly. This method takes ownership of \p CE.
74 ///
75 /// \param TAB - If given, a target asm backend to use to show the fixup
76 /// information in conjunction with encoding information. This method takes
77 /// ownership of \p TAB.
78 ///
79 /// \param ShowInst - Whether to show the MCInst representation inline with
80 /// the assembly.
81 MCStreamer *
82 createAsmStreamer(MCContext &Ctx, std::unique_ptr<formatted_raw_ostream> OS,
83 bool isVerboseAsm, bool useDwarfDirectory,
84 MCInstPrinter *InstPrint, std::unique_ptr<MCCodeEmitter> &&CE,
85 std::unique_ptr<MCAsmBackend> &&TAB, bool ShowInst);
87 MCStreamer *createELFStreamer(MCContext &Ctx,
88 std::unique_ptr<MCAsmBackend> &&TAB,
89 std::unique_ptr<MCObjectWriter> &&OW,
90 std::unique_ptr<MCCodeEmitter> &&CE,
91 bool RelaxAll);
92 MCStreamer *createMachOStreamer(MCContext &Ctx,
93 std::unique_ptr<MCAsmBackend> &&TAB,
94 std::unique_ptr<MCObjectWriter> &&OW,
95 std::unique_ptr<MCCodeEmitter> &&CE,
96 bool RelaxAll, bool DWARFMustBeAtTheEnd,
97 bool LabelSections = false);
98 MCStreamer *createWasmStreamer(MCContext &Ctx,
99 std::unique_ptr<MCAsmBackend> &&TAB,
100 std::unique_ptr<MCObjectWriter> &&OW,
101 std::unique_ptr<MCCodeEmitter> &&CE,
102 bool RelaxAll);
104 MCRelocationInfo *createMCRelocationInfo(const Triple &TT, MCContext &Ctx);
106 MCSymbolizer *createMCSymbolizer(const Triple &TT, LLVMOpInfoCallback GetOpInfo,
107 LLVMSymbolLookupCallback SymbolLookUp,
108 void *DisInfo, MCContext *Ctx,
109 std::unique_ptr<MCRelocationInfo> &&RelInfo);
111 /// Target - Wrapper for Target specific information.
113 /// For registration purposes, this is a POD type so that targets can be
114 /// registered without the use of static constructors.
116 /// Targets should implement a single global instance of this class (which
117 /// will be zero initialized), and pass that instance to the TargetRegistry as
118 /// part of their initialization.
119 class Target {
120 public:
121 friend struct TargetRegistry;
123 using ArchMatchFnTy = bool (*)(Triple::ArchType Arch);
125 using MCAsmInfoCtorFnTy = MCAsmInfo *(*)(const MCRegisterInfo &MRI,
126 const Triple &TT);
127 using MCInstrInfoCtorFnTy = MCInstrInfo *(*)();
128 using MCInstrAnalysisCtorFnTy = MCInstrAnalysis *(*)(const MCInstrInfo *Info);
129 using MCRegInfoCtorFnTy = MCRegisterInfo *(*)(const Triple &TT);
130 using MCSubtargetInfoCtorFnTy = MCSubtargetInfo *(*)(const Triple &TT,
131 StringRef CPU,
132 StringRef Features);
133 using TargetMachineCtorTy = TargetMachine
134 *(*)(const Target &T, const Triple &TT, StringRef CPU, StringRef Features,
135 const TargetOptions &Options, Optional<Reloc::Model> RM,
136 Optional<CodeModel::Model> CM, CodeGenOpt::Level OL, bool JIT);
137 // If it weren't for layering issues (this header is in llvm/Support, but
138 // depends on MC?) this should take the Streamer by value rather than rvalue
139 // reference.
140 using AsmPrinterCtorTy = AsmPrinter *(*)(
141 TargetMachine &TM, std::unique_ptr<MCStreamer> &&Streamer);
142 using MCAsmBackendCtorTy = MCAsmBackend *(*)(const Target &T,
143 const MCSubtargetInfo &STI,
144 const MCRegisterInfo &MRI,
145 const MCTargetOptions &Options);
146 using MCAsmParserCtorTy = MCTargetAsmParser *(*)(
147 const MCSubtargetInfo &STI, MCAsmParser &P, const MCInstrInfo &MII,
148 const MCTargetOptions &Options);
149 using MCDisassemblerCtorTy = MCDisassembler *(*)(const Target &T,
150 const MCSubtargetInfo &STI,
151 MCContext &Ctx);
152 using MCInstPrinterCtorTy = MCInstPrinter *(*)(const Triple &T,
153 unsigned SyntaxVariant,
154 const MCAsmInfo &MAI,
155 const MCInstrInfo &MII,
156 const MCRegisterInfo &MRI);
157 using MCCodeEmitterCtorTy = MCCodeEmitter *(*)(const MCInstrInfo &II,
158 const MCRegisterInfo &MRI,
159 MCContext &Ctx);
160 using ELFStreamerCtorTy =
161 MCStreamer *(*)(const Triple &T, MCContext &Ctx,
162 std::unique_ptr<MCAsmBackend> &&TAB,
163 std::unique_ptr<MCObjectWriter> &&OW,
164 std::unique_ptr<MCCodeEmitter> &&Emitter, bool RelaxAll);
165 using MachOStreamerCtorTy =
166 MCStreamer *(*)(MCContext &Ctx, std::unique_ptr<MCAsmBackend> &&TAB,
167 std::unique_ptr<MCObjectWriter> &&OW,
168 std::unique_ptr<MCCodeEmitter> &&Emitter, bool RelaxAll,
169 bool DWARFMustBeAtTheEnd);
170 using COFFStreamerCtorTy =
171 MCStreamer *(*)(MCContext &Ctx, std::unique_ptr<MCAsmBackend> &&TAB,
172 std::unique_ptr<MCObjectWriter> &&OW,
173 std::unique_ptr<MCCodeEmitter> &&Emitter, bool RelaxAll,
174 bool IncrementalLinkerCompatible);
175 using WasmStreamerCtorTy =
176 MCStreamer *(*)(const Triple &T, MCContext &Ctx,
177 std::unique_ptr<MCAsmBackend> &&TAB,
178 std::unique_ptr<MCObjectWriter> &&OW,
179 std::unique_ptr<MCCodeEmitter> &&Emitter, bool RelaxAll);
180 using NullTargetStreamerCtorTy = MCTargetStreamer *(*)(MCStreamer &S);
181 using AsmTargetStreamerCtorTy = MCTargetStreamer *(*)(
182 MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *InstPrint,
183 bool IsVerboseAsm);
184 using ObjectTargetStreamerCtorTy = MCTargetStreamer *(*)(
185 MCStreamer &S, const MCSubtargetInfo &STI);
186 using MCRelocationInfoCtorTy = MCRelocationInfo *(*)(const Triple &TT,
187 MCContext &Ctx);
188 using MCSymbolizerCtorTy = MCSymbolizer *(*)(
189 const Triple &TT, LLVMOpInfoCallback GetOpInfo,
190 LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo, MCContext *Ctx,
191 std::unique_ptr<MCRelocationInfo> &&RelInfo);
193 private:
194 /// Next - The next registered target in the linked list, maintained by the
195 /// TargetRegistry.
196 Target *Next;
198 /// The target function for checking if an architecture is supported.
199 ArchMatchFnTy ArchMatchFn;
201 /// Name - The target name.
202 const char *Name;
204 /// ShortDesc - A short description of the target.
205 const char *ShortDesc;
207 /// BackendName - The name of the backend implementation. This must match the
208 /// name of the 'def X : Target ...' in TableGen.
209 const char *BackendName;
211 /// HasJIT - Whether this target supports the JIT.
212 bool HasJIT;
214 /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
215 /// registered.
216 MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
218 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
219 /// if registered.
220 MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
222 /// MCInstrAnalysisCtorFn - Constructor function for this target's
223 /// MCInstrAnalysis, if registered.
224 MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
226 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
227 /// if registered.
228 MCRegInfoCtorFnTy MCRegInfoCtorFn;
230 /// MCSubtargetInfoCtorFn - Constructor function for this target's
231 /// MCSubtargetInfo, if registered.
232 MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
234 /// TargetMachineCtorFn - Construction function for this target's
235 /// TargetMachine, if registered.
236 TargetMachineCtorTy TargetMachineCtorFn;
238 /// MCAsmBackendCtorFn - Construction function for this target's
239 /// MCAsmBackend, if registered.
240 MCAsmBackendCtorTy MCAsmBackendCtorFn;
242 /// MCAsmParserCtorFn - Construction function for this target's
243 /// MCTargetAsmParser, if registered.
244 MCAsmParserCtorTy MCAsmParserCtorFn;
246 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
247 /// if registered.
248 AsmPrinterCtorTy AsmPrinterCtorFn;
250 /// MCDisassemblerCtorFn - Construction function for this target's
251 /// MCDisassembler, if registered.
252 MCDisassemblerCtorTy MCDisassemblerCtorFn;
254 /// MCInstPrinterCtorFn - Construction function for this target's
255 /// MCInstPrinter, if registered.
256 MCInstPrinterCtorTy MCInstPrinterCtorFn;
258 /// MCCodeEmitterCtorFn - Construction function for this target's
259 /// CodeEmitter, if registered.
260 MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
262 // Construction functions for the various object formats, if registered.
263 COFFStreamerCtorTy COFFStreamerCtorFn = nullptr;
264 MachOStreamerCtorTy MachOStreamerCtorFn = nullptr;
265 ELFStreamerCtorTy ELFStreamerCtorFn = nullptr;
266 WasmStreamerCtorTy WasmStreamerCtorFn = nullptr;
268 /// Construction function for this target's null TargetStreamer, if
269 /// registered (default = nullptr).
270 NullTargetStreamerCtorTy NullTargetStreamerCtorFn = nullptr;
272 /// Construction function for this target's asm TargetStreamer, if
273 /// registered (default = nullptr).
274 AsmTargetStreamerCtorTy AsmTargetStreamerCtorFn = nullptr;
276 /// Construction function for this target's obj TargetStreamer, if
277 /// registered (default = nullptr).
278 ObjectTargetStreamerCtorTy ObjectTargetStreamerCtorFn = nullptr;
280 /// MCRelocationInfoCtorFn - Construction function for this target's
281 /// MCRelocationInfo, if registered (default = llvm::createMCRelocationInfo)
282 MCRelocationInfoCtorTy MCRelocationInfoCtorFn = nullptr;
284 /// MCSymbolizerCtorFn - Construction function for this target's
285 /// MCSymbolizer, if registered (default = llvm::createMCSymbolizer)
286 MCSymbolizerCtorTy MCSymbolizerCtorFn = nullptr;
288 public:
289 Target() = default;
291 /// @name Target Information
292 /// @{
294 // getNext - Return the next registered target.
295 const Target *getNext() const { return Next; }
297 /// getName - Get the target name.
298 const char *getName() const { return Name; }
300 /// getShortDescription - Get a short description of the target.
301 const char *getShortDescription() const { return ShortDesc; }
303 /// getBackendName - Get the backend name.
304 const char *getBackendName() const { return BackendName; }
306 /// @}
307 /// @name Feature Predicates
308 /// @{
310 /// hasJIT - Check if this targets supports the just-in-time compilation.
311 bool hasJIT() const { return HasJIT; }
313 /// hasTargetMachine - Check if this target supports code generation.
314 bool hasTargetMachine() const { return TargetMachineCtorFn != nullptr; }
316 /// hasMCAsmBackend - Check if this target supports .o generation.
317 bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != nullptr; }
319 /// hasMCAsmParser - Check if this target supports assembly parsing.
320 bool hasMCAsmParser() const { return MCAsmParserCtorFn != nullptr; }
322 /// @}
323 /// @name Feature Constructors
324 /// @{
326 /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
327 /// target triple.
329 /// \param TheTriple This argument is used to determine the target machine
330 /// feature set; it should always be provided. Generally this should be
331 /// either the target triple from the module, or the target triple of the
332 /// host if that does not exist.
333 MCAsmInfo *createMCAsmInfo(const MCRegisterInfo &MRI,
334 StringRef TheTriple) const {
335 if (!MCAsmInfoCtorFn)
336 return nullptr;
337 return MCAsmInfoCtorFn(MRI, Triple(TheTriple));
340 /// createMCInstrInfo - Create a MCInstrInfo implementation.
342 MCInstrInfo *createMCInstrInfo() const {
343 if (!MCInstrInfoCtorFn)
344 return nullptr;
345 return MCInstrInfoCtorFn();
348 /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
350 MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
351 if (!MCInstrAnalysisCtorFn)
352 return nullptr;
353 return MCInstrAnalysisCtorFn(Info);
356 /// createMCRegInfo - Create a MCRegisterInfo implementation.
358 MCRegisterInfo *createMCRegInfo(StringRef TT) const {
359 if (!MCRegInfoCtorFn)
360 return nullptr;
361 return MCRegInfoCtorFn(Triple(TT));
364 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
366 /// \param TheTriple This argument is used to determine the target machine
367 /// feature set; it should always be provided. Generally this should be
368 /// either the target triple from the module, or the target triple of the
369 /// host if that does not exist.
370 /// \param CPU This specifies the name of the target CPU.
371 /// \param Features This specifies the string representation of the
372 /// additional target features.
373 MCSubtargetInfo *createMCSubtargetInfo(StringRef TheTriple, StringRef CPU,
374 StringRef Features) const {
375 if (!MCSubtargetInfoCtorFn)
376 return nullptr;
377 return MCSubtargetInfoCtorFn(Triple(TheTriple), CPU, Features);
380 /// createTargetMachine - Create a target specific machine implementation
381 /// for the specified \p Triple.
383 /// \param TT This argument is used to determine the target machine
384 /// feature set; it should always be provided. Generally this should be
385 /// either the target triple from the module, or the target triple of the
386 /// host if that does not exist.
387 TargetMachine *createTargetMachine(StringRef TT, StringRef CPU,
388 StringRef Features,
389 const TargetOptions &Options,
390 Optional<Reloc::Model> RM,
391 Optional<CodeModel::Model> CM = None,
392 CodeGenOpt::Level OL = CodeGenOpt::Default,
393 bool JIT = false) const {
394 if (!TargetMachineCtorFn)
395 return nullptr;
396 return TargetMachineCtorFn(*this, Triple(TT), CPU, Features, Options, RM,
397 CM, OL, JIT);
400 /// createMCAsmBackend - Create a target specific assembly parser.
401 MCAsmBackend *createMCAsmBackend(const MCSubtargetInfo &STI,
402 const MCRegisterInfo &MRI,
403 const MCTargetOptions &Options) const {
404 if (!MCAsmBackendCtorFn)
405 return nullptr;
406 return MCAsmBackendCtorFn(*this, STI, MRI, Options);
409 /// createMCAsmParser - Create a target specific assembly parser.
411 /// \param Parser The target independent parser implementation to use for
412 /// parsing and lexing.
413 MCTargetAsmParser *createMCAsmParser(const MCSubtargetInfo &STI,
414 MCAsmParser &Parser,
415 const MCInstrInfo &MII,
416 const MCTargetOptions &Options) const {
417 if (!MCAsmParserCtorFn)
418 return nullptr;
419 return MCAsmParserCtorFn(STI, Parser, MII, Options);
422 /// createAsmPrinter - Create a target specific assembly printer pass. This
423 /// takes ownership of the MCStreamer object.
424 AsmPrinter *createAsmPrinter(TargetMachine &TM,
425 std::unique_ptr<MCStreamer> &&Streamer) const {
426 if (!AsmPrinterCtorFn)
427 return nullptr;
428 return AsmPrinterCtorFn(TM, std::move(Streamer));
431 MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI,
432 MCContext &Ctx) const {
433 if (!MCDisassemblerCtorFn)
434 return nullptr;
435 return MCDisassemblerCtorFn(*this, STI, Ctx);
438 MCInstPrinter *createMCInstPrinter(const Triple &T, unsigned SyntaxVariant,
439 const MCAsmInfo &MAI,
440 const MCInstrInfo &MII,
441 const MCRegisterInfo &MRI) const {
442 if (!MCInstPrinterCtorFn)
443 return nullptr;
444 return MCInstPrinterCtorFn(T, SyntaxVariant, MAI, MII, MRI);
447 /// createMCCodeEmitter - Create a target specific code emitter.
448 MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
449 const MCRegisterInfo &MRI,
450 MCContext &Ctx) const {
451 if (!MCCodeEmitterCtorFn)
452 return nullptr;
453 return MCCodeEmitterCtorFn(II, MRI, Ctx);
456 /// Create a target specific MCStreamer.
458 /// \param T The target triple.
459 /// \param Ctx The target context.
460 /// \param TAB The target assembler backend object. Takes ownership.
461 /// \param OW The stream object.
462 /// \param Emitter The target independent assembler object.Takes ownership.
463 /// \param RelaxAll Relax all fixups?
464 MCStreamer *createMCObjectStreamer(const Triple &T, MCContext &Ctx,
465 std::unique_ptr<MCAsmBackend> &&TAB,
466 std::unique_ptr<MCObjectWriter> &&OW,
467 std::unique_ptr<MCCodeEmitter> &&Emitter,
468 const MCSubtargetInfo &STI, bool RelaxAll,
469 bool IncrementalLinkerCompatible,
470 bool DWARFMustBeAtTheEnd) const {
471 MCStreamer *S;
472 switch (T.getObjectFormat()) {
473 default:
474 llvm_unreachable("Unknown object format");
475 case Triple::COFF:
476 assert(T.isOSWindows() && "only Windows COFF is supported");
477 S = COFFStreamerCtorFn(Ctx, std::move(TAB), std::move(OW),
478 std::move(Emitter), RelaxAll,
479 IncrementalLinkerCompatible);
480 break;
481 case Triple::MachO:
482 if (MachOStreamerCtorFn)
483 S = MachOStreamerCtorFn(Ctx, std::move(TAB), std::move(OW),
484 std::move(Emitter), RelaxAll,
485 DWARFMustBeAtTheEnd);
486 else
487 S = createMachOStreamer(Ctx, std::move(TAB), std::move(OW),
488 std::move(Emitter), RelaxAll,
489 DWARFMustBeAtTheEnd);
490 break;
491 case Triple::ELF:
492 if (ELFStreamerCtorFn)
493 S = ELFStreamerCtorFn(T, Ctx, std::move(TAB), std::move(OW),
494 std::move(Emitter), RelaxAll);
495 else
496 S = createELFStreamer(Ctx, std::move(TAB), std::move(OW),
497 std::move(Emitter), RelaxAll);
498 break;
499 case Triple::Wasm:
500 if (WasmStreamerCtorFn)
501 S = WasmStreamerCtorFn(T, Ctx, std::move(TAB), std::move(OW),
502 std::move(Emitter), RelaxAll);
503 else
504 S = createWasmStreamer(Ctx, std::move(TAB), std::move(OW),
505 std::move(Emitter), RelaxAll);
506 break;
508 if (ObjectTargetStreamerCtorFn)
509 ObjectTargetStreamerCtorFn(*S, STI);
510 return S;
513 MCStreamer *createAsmStreamer(MCContext &Ctx,
514 std::unique_ptr<formatted_raw_ostream> OS,
515 bool IsVerboseAsm, bool UseDwarfDirectory,
516 MCInstPrinter *InstPrint,
517 std::unique_ptr<MCCodeEmitter> &&CE,
518 std::unique_ptr<MCAsmBackend> &&TAB,
519 bool ShowInst) const {
520 formatted_raw_ostream &OSRef = *OS;
521 MCStreamer *S = llvm::createAsmStreamer(
522 Ctx, std::move(OS), IsVerboseAsm, UseDwarfDirectory, InstPrint,
523 std::move(CE), std::move(TAB), ShowInst);
524 createAsmTargetStreamer(*S, OSRef, InstPrint, IsVerboseAsm);
525 return S;
528 MCTargetStreamer *createAsmTargetStreamer(MCStreamer &S,
529 formatted_raw_ostream &OS,
530 MCInstPrinter *InstPrint,
531 bool IsVerboseAsm) const {
532 if (AsmTargetStreamerCtorFn)
533 return AsmTargetStreamerCtorFn(S, OS, InstPrint, IsVerboseAsm);
534 return nullptr;
537 MCStreamer *createNullStreamer(MCContext &Ctx) const {
538 MCStreamer *S = llvm::createNullStreamer(Ctx);
539 createNullTargetStreamer(*S);
540 return S;
543 MCTargetStreamer *createNullTargetStreamer(MCStreamer &S) const {
544 if (NullTargetStreamerCtorFn)
545 return NullTargetStreamerCtorFn(S);
546 return nullptr;
549 /// createMCRelocationInfo - Create a target specific MCRelocationInfo.
551 /// \param TT The target triple.
552 /// \param Ctx The target context.
553 MCRelocationInfo *createMCRelocationInfo(StringRef TT, MCContext &Ctx) const {
554 MCRelocationInfoCtorTy Fn = MCRelocationInfoCtorFn
555 ? MCRelocationInfoCtorFn
556 : llvm::createMCRelocationInfo;
557 return Fn(Triple(TT), Ctx);
560 /// createMCSymbolizer - Create a target specific MCSymbolizer.
562 /// \param TT The target triple.
563 /// \param GetOpInfo The function to get the symbolic information for
564 /// operands.
565 /// \param SymbolLookUp The function to lookup a symbol name.
566 /// \param DisInfo The pointer to the block of symbolic information for above
567 /// call
568 /// back.
569 /// \param Ctx The target context.
570 /// \param RelInfo The relocation information for this target. Takes
571 /// ownership.
572 MCSymbolizer *
573 createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
574 LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo,
575 MCContext *Ctx,
576 std::unique_ptr<MCRelocationInfo> &&RelInfo) const {
577 MCSymbolizerCtorTy Fn =
578 MCSymbolizerCtorFn ? MCSymbolizerCtorFn : llvm::createMCSymbolizer;
579 return Fn(Triple(TT), GetOpInfo, SymbolLookUp, DisInfo, Ctx,
580 std::move(RelInfo));
583 /// @}
586 /// TargetRegistry - Generic interface to target specific features.
587 struct TargetRegistry {
588 // FIXME: Make this a namespace, probably just move all the Register*
589 // functions into Target (currently they all just set members on the Target
590 // anyway, and Target friends this class so those functions can...
591 // function).
592 TargetRegistry() = delete;
594 class iterator
595 : public std::iterator<std::forward_iterator_tag, Target, ptrdiff_t> {
596 friend struct TargetRegistry;
598 const Target *Current = nullptr;
600 explicit iterator(Target *T) : Current(T) {}
602 public:
603 iterator() = default;
605 bool operator==(const iterator &x) const { return Current == x.Current; }
606 bool operator!=(const iterator &x) const { return !operator==(x); }
608 // Iterator traversal: forward iteration only
609 iterator &operator++() { // Preincrement
610 assert(Current && "Cannot increment end iterator!");
611 Current = Current->getNext();
612 return *this;
614 iterator operator++(int) { // Postincrement
615 iterator tmp = *this;
616 ++*this;
617 return tmp;
620 const Target &operator*() const {
621 assert(Current && "Cannot dereference end iterator!");
622 return *Current;
625 const Target *operator->() const { return &operator*(); }
628 /// printRegisteredTargetsForVersion - Print the registered targets
629 /// appropriately for inclusion in a tool's version output.
630 static void printRegisteredTargetsForVersion(raw_ostream &OS);
632 /// @name Registry Access
633 /// @{
635 static iterator_range<iterator> targets();
637 /// lookupTarget - Lookup a target based on a target triple.
639 /// \param Triple - The triple to use for finding a target.
640 /// \param Error - On failure, an error string describing why no target was
641 /// found.
642 static const Target *lookupTarget(const std::string &Triple,
643 std::string &Error);
645 /// lookupTarget - Lookup a target based on an architecture name
646 /// and a target triple. If the architecture name is non-empty,
647 /// then the lookup is done by architecture. Otherwise, the target
648 /// triple is used.
650 /// \param ArchName - The architecture to use for finding a target.
651 /// \param TheTriple - The triple to use for finding a target. The
652 /// triple is updated with canonical architecture name if a lookup
653 /// by architecture is done.
654 /// \param Error - On failure, an error string describing why no target was
655 /// found.
656 static const Target *lookupTarget(const std::string &ArchName,
657 Triple &TheTriple, std::string &Error);
659 /// @}
660 /// @name Target Registration
661 /// @{
663 /// RegisterTarget - Register the given target. Attempts to register a
664 /// target which has already been registered will be ignored.
666 /// Clients are responsible for ensuring that registration doesn't occur
667 /// while another thread is attempting to access the registry. Typically
668 /// this is done by initializing all targets at program startup.
670 /// @param T - The target being registered.
671 /// @param Name - The target name. This should be a static string.
672 /// @param ShortDesc - A short target description. This should be a static
673 /// string.
674 /// @param BackendName - The name of the backend. This should be a static
675 /// string that is the same for all targets that share a backend
676 /// implementation and must match the name used in the 'def X : Target ...' in
677 /// TableGen.
678 /// @param ArchMatchFn - The arch match checking function for this target.
679 /// @param HasJIT - Whether the target supports JIT code
680 /// generation.
681 static void RegisterTarget(Target &T, const char *Name, const char *ShortDesc,
682 const char *BackendName,
683 Target::ArchMatchFnTy ArchMatchFn,
684 bool HasJIT = false);
686 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
687 /// given target.
689 /// Clients are responsible for ensuring that registration doesn't occur
690 /// while another thread is attempting to access the registry. Typically
691 /// this is done by initializing all targets at program startup.
693 /// @param T - The target being registered.
694 /// @param Fn - A function to construct a MCAsmInfo for the target.
695 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
696 T.MCAsmInfoCtorFn = Fn;
699 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
700 /// given target.
702 /// Clients are responsible for ensuring that registration doesn't occur
703 /// while another thread is attempting to access the registry. Typically
704 /// this is done by initializing all targets at program startup.
706 /// @param T - The target being registered.
707 /// @param Fn - A function to construct a MCInstrInfo for the target.
708 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
709 T.MCInstrInfoCtorFn = Fn;
712 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
713 /// the given target.
714 static void RegisterMCInstrAnalysis(Target &T,
715 Target::MCInstrAnalysisCtorFnTy Fn) {
716 T.MCInstrAnalysisCtorFn = Fn;
719 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
720 /// given target.
722 /// Clients are responsible for ensuring that registration doesn't occur
723 /// while another thread is attempting to access the registry. Typically
724 /// this is done by initializing all targets at program startup.
726 /// @param T - The target being registered.
727 /// @param Fn - A function to construct a MCRegisterInfo for the target.
728 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
729 T.MCRegInfoCtorFn = Fn;
732 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
733 /// the given target.
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 a MCSubtargetInfo for the target.
741 static void RegisterMCSubtargetInfo(Target &T,
742 Target::MCSubtargetInfoCtorFnTy Fn) {
743 T.MCSubtargetInfoCtorFn = Fn;
746 /// RegisterTargetMachine - Register a TargetMachine implementation for the
747 /// given target.
749 /// Clients are responsible for ensuring that registration doesn't occur
750 /// while another thread is attempting to access the registry. Typically
751 /// this is done by initializing all targets at program startup.
753 /// @param T - The target being registered.
754 /// @param Fn - A function to construct a TargetMachine for the target.
755 static void RegisterTargetMachine(Target &T, Target::TargetMachineCtorTy Fn) {
756 T.TargetMachineCtorFn = Fn;
759 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
760 /// given target.
762 /// Clients are responsible for ensuring that registration doesn't occur
763 /// while another thread is attempting to access the registry. Typically
764 /// this is done by initializing all targets at program startup.
766 /// @param T - The target being registered.
767 /// @param Fn - A function to construct an AsmBackend for the target.
768 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
769 T.MCAsmBackendCtorFn = Fn;
772 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
773 /// the given target.
775 /// Clients are responsible for ensuring that registration doesn't occur
776 /// while another thread is attempting to access the registry. Typically
777 /// this is done by initializing all targets at program startup.
779 /// @param T - The target being registered.
780 /// @param Fn - A function to construct an MCTargetAsmParser for the target.
781 static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
782 T.MCAsmParserCtorFn = Fn;
785 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
786 /// target.
788 /// Clients are responsible for ensuring that registration doesn't occur
789 /// while another thread is attempting to access the registry. Typically
790 /// this is done by initializing all targets at program startup.
792 /// @param T - The target being registered.
793 /// @param Fn - A function to construct an AsmPrinter for the target.
794 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
795 T.AsmPrinterCtorFn = Fn;
798 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
799 /// the given target.
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.
805 /// @param T - The target being registered.
806 /// @param Fn - A function to construct an MCDisassembler for the target.
807 static void RegisterMCDisassembler(Target &T,
808 Target::MCDisassemblerCtorTy Fn) {
809 T.MCDisassemblerCtorFn = Fn;
812 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
813 /// given target.
815 /// Clients are responsible for ensuring that registration doesn't occur
816 /// while another thread is attempting to access the registry. Typically
817 /// this is done by initializing all targets at program startup.
819 /// @param T - The target being registered.
820 /// @param Fn - A function to construct an MCInstPrinter for the target.
821 static void RegisterMCInstPrinter(Target &T, Target::MCInstPrinterCtorTy Fn) {
822 T.MCInstPrinterCtorFn = Fn;
825 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
826 /// given target.
828 /// Clients are responsible for ensuring that registration doesn't occur
829 /// while another thread is attempting to access the registry. Typically
830 /// this is done by initializing all targets at program startup.
832 /// @param T - The target being registered.
833 /// @param Fn - A function to construct an MCCodeEmitter for the target.
834 static void RegisterMCCodeEmitter(Target &T, Target::MCCodeEmitterCtorTy Fn) {
835 T.MCCodeEmitterCtorFn = Fn;
838 static void RegisterCOFFStreamer(Target &T, Target::COFFStreamerCtorTy Fn) {
839 T.COFFStreamerCtorFn = Fn;
842 static void RegisterMachOStreamer(Target &T, Target::MachOStreamerCtorTy Fn) {
843 T.MachOStreamerCtorFn = Fn;
846 static void RegisterELFStreamer(Target &T, Target::ELFStreamerCtorTy Fn) {
847 T.ELFStreamerCtorFn = Fn;
850 static void RegisterWasmStreamer(Target &T, Target::WasmStreamerCtorTy Fn) {
851 T.WasmStreamerCtorFn = Fn;
854 static void RegisterNullTargetStreamer(Target &T,
855 Target::NullTargetStreamerCtorTy Fn) {
856 T.NullTargetStreamerCtorFn = Fn;
859 static void RegisterAsmTargetStreamer(Target &T,
860 Target::AsmTargetStreamerCtorTy Fn) {
861 T.AsmTargetStreamerCtorFn = Fn;
864 static void
865 RegisterObjectTargetStreamer(Target &T,
866 Target::ObjectTargetStreamerCtorTy Fn) {
867 T.ObjectTargetStreamerCtorFn = Fn;
870 /// RegisterMCRelocationInfo - Register an MCRelocationInfo
871 /// implementation for the given target.
873 /// Clients are responsible for ensuring that registration doesn't occur
874 /// while another thread is attempting to access the registry. Typically
875 /// this is done by initializing all targets at program startup.
877 /// @param T - The target being registered.
878 /// @param Fn - A function to construct an MCRelocationInfo for the target.
879 static void RegisterMCRelocationInfo(Target &T,
880 Target::MCRelocationInfoCtorTy Fn) {
881 T.MCRelocationInfoCtorFn = Fn;
884 /// RegisterMCSymbolizer - Register an MCSymbolizer
885 /// implementation for the given target.
887 /// Clients are responsible for ensuring that registration doesn't occur
888 /// while another thread is attempting to access the registry. Typically
889 /// this is done by initializing all targets at program startup.
891 /// @param T - The target being registered.
892 /// @param Fn - A function to construct an MCSymbolizer for the target.
893 static void RegisterMCSymbolizer(Target &T, Target::MCSymbolizerCtorTy Fn) {
894 T.MCSymbolizerCtorFn = Fn;
897 /// @}
900 //===--------------------------------------------------------------------===//
902 /// RegisterTarget - Helper template for registering a target, for use in the
903 /// target's initialization function. Usage:
906 /// Target &getTheFooTarget() { // The global target instance.
907 /// static Target TheFooTarget;
908 /// return TheFooTarget;
909 /// }
910 /// extern "C" void LLVMInitializeFooTargetInfo() {
911 /// RegisterTarget<Triple::foo> X(getTheFooTarget(), "foo", "Foo
912 /// description", "Foo" /* Backend Name */);
913 /// }
914 template <Triple::ArchType TargetArchType = Triple::UnknownArch,
915 bool HasJIT = false>
916 struct RegisterTarget {
917 RegisterTarget(Target &T, const char *Name, const char *Desc,
918 const char *BackendName) {
919 TargetRegistry::RegisterTarget(T, Name, Desc, BackendName, &getArchMatch,
920 HasJIT);
923 static bool getArchMatch(Triple::ArchType Arch) {
924 return Arch == TargetArchType;
928 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
929 /// implementation. This invokes the static "Create" method on the class to
930 /// actually do the construction. Usage:
932 /// extern "C" void LLVMInitializeFooTarget() {
933 /// extern Target TheFooTarget;
934 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
935 /// }
936 template <class MCAsmInfoImpl> struct RegisterMCAsmInfo {
937 RegisterMCAsmInfo(Target &T) {
938 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
941 private:
942 static MCAsmInfo *Allocator(const MCRegisterInfo & /*MRI*/,
943 const Triple &TT) {
944 return new MCAsmInfoImpl(TT);
948 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
949 /// implementation. This invokes the specified function to do the
950 /// construction. Usage:
952 /// extern "C" void LLVMInitializeFooTarget() {
953 /// extern Target TheFooTarget;
954 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
955 /// }
956 struct RegisterMCAsmInfoFn {
957 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
958 TargetRegistry::RegisterMCAsmInfo(T, Fn);
962 /// RegisterMCInstrInfo - Helper template for registering a target instruction
963 /// info implementation. This invokes the static "Create" method on the class
964 /// to actually do the construction. Usage:
966 /// extern "C" void LLVMInitializeFooTarget() {
967 /// extern Target TheFooTarget;
968 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
969 /// }
970 template <class MCInstrInfoImpl> struct RegisterMCInstrInfo {
971 RegisterMCInstrInfo(Target &T) {
972 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
975 private:
976 static MCInstrInfo *Allocator() { return new MCInstrInfoImpl(); }
979 /// RegisterMCInstrInfoFn - Helper template for registering a target
980 /// instruction info implementation. This invokes the specified function to
981 /// do the construction. Usage:
983 /// extern "C" void LLVMInitializeFooTarget() {
984 /// extern Target TheFooTarget;
985 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
986 /// }
987 struct RegisterMCInstrInfoFn {
988 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
989 TargetRegistry::RegisterMCInstrInfo(T, Fn);
993 /// RegisterMCInstrAnalysis - Helper template for registering a target
994 /// instruction analyzer implementation. This invokes the static "Create"
995 /// method on the class to actually do the construction. Usage:
997 /// extern "C" void LLVMInitializeFooTarget() {
998 /// extern Target TheFooTarget;
999 /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
1000 /// }
1001 template <class MCInstrAnalysisImpl> struct RegisterMCInstrAnalysis {
1002 RegisterMCInstrAnalysis(Target &T) {
1003 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
1006 private:
1007 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
1008 return new MCInstrAnalysisImpl(Info);
1012 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
1013 /// instruction analyzer implementation. This invokes the specified function
1014 /// to do the construction. Usage:
1016 /// extern "C" void LLVMInitializeFooTarget() {
1017 /// extern Target TheFooTarget;
1018 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
1019 /// }
1020 struct RegisterMCInstrAnalysisFn {
1021 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
1022 TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
1026 /// RegisterMCRegInfo - Helper template for registering a target register info
1027 /// implementation. This invokes the static "Create" method on the class to
1028 /// actually do the construction. Usage:
1030 /// extern "C" void LLVMInitializeFooTarget() {
1031 /// extern Target TheFooTarget;
1032 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
1033 /// }
1034 template <class MCRegisterInfoImpl> struct RegisterMCRegInfo {
1035 RegisterMCRegInfo(Target &T) {
1036 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
1039 private:
1040 static MCRegisterInfo *Allocator(const Triple & /*TT*/) {
1041 return new MCRegisterInfoImpl();
1045 /// RegisterMCRegInfoFn - Helper template for registering a target register
1046 /// info implementation. This invokes the specified function to do the
1047 /// construction. Usage:
1049 /// extern "C" void LLVMInitializeFooTarget() {
1050 /// extern Target TheFooTarget;
1051 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
1052 /// }
1053 struct RegisterMCRegInfoFn {
1054 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
1055 TargetRegistry::RegisterMCRegInfo(T, Fn);
1059 /// RegisterMCSubtargetInfo - Helper template for registering a target
1060 /// subtarget info implementation. This invokes the static "Create" method
1061 /// on the class to actually do the construction. Usage:
1063 /// extern "C" void LLVMInitializeFooTarget() {
1064 /// extern Target TheFooTarget;
1065 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
1066 /// }
1067 template <class MCSubtargetInfoImpl> struct RegisterMCSubtargetInfo {
1068 RegisterMCSubtargetInfo(Target &T) {
1069 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
1072 private:
1073 static MCSubtargetInfo *Allocator(const Triple & /*TT*/, StringRef /*CPU*/,
1074 StringRef /*FS*/) {
1075 return new MCSubtargetInfoImpl();
1079 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
1080 /// subtarget info implementation. This invokes the specified function to
1081 /// do the construction. Usage:
1083 /// extern "C" void LLVMInitializeFooTarget() {
1084 /// extern Target TheFooTarget;
1085 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1086 /// }
1087 struct RegisterMCSubtargetInfoFn {
1088 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
1089 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
1093 /// RegisterTargetMachine - Helper template for registering a target machine
1094 /// implementation, for use in the target machine initialization
1095 /// function. Usage:
1097 /// extern "C" void LLVMInitializeFooTarget() {
1098 /// extern Target TheFooTarget;
1099 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1100 /// }
1101 template <class TargetMachineImpl> struct RegisterTargetMachine {
1102 RegisterTargetMachine(Target &T) {
1103 TargetRegistry::RegisterTargetMachine(T, &Allocator);
1106 private:
1107 static TargetMachine *
1108 Allocator(const Target &T, const Triple &TT, StringRef CPU, StringRef FS,
1109 const TargetOptions &Options, Optional<Reloc::Model> RM,
1110 Optional<CodeModel::Model> CM, CodeGenOpt::Level OL, bool JIT) {
1111 return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL, JIT);
1115 /// RegisterMCAsmBackend - Helper template for registering a target specific
1116 /// assembler backend. Usage:
1118 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1119 /// extern Target TheFooTarget;
1120 /// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1121 /// }
1122 template <class MCAsmBackendImpl> struct RegisterMCAsmBackend {
1123 RegisterMCAsmBackend(Target &T) {
1124 TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1127 private:
1128 static MCAsmBackend *Allocator(const Target &T, const MCSubtargetInfo &STI,
1129 const MCRegisterInfo &MRI,
1130 const MCTargetOptions &Options) {
1131 return new MCAsmBackendImpl(T, STI, MRI);
1135 /// RegisterMCAsmParser - Helper template for registering a target specific
1136 /// assembly parser, for use in the target machine initialization
1137 /// function. Usage:
1139 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1140 /// extern Target TheFooTarget;
1141 /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1142 /// }
1143 template <class MCAsmParserImpl> struct RegisterMCAsmParser {
1144 RegisterMCAsmParser(Target &T) {
1145 TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1148 private:
1149 static MCTargetAsmParser *Allocator(const MCSubtargetInfo &STI,
1150 MCAsmParser &P, const MCInstrInfo &MII,
1151 const MCTargetOptions &Options) {
1152 return new MCAsmParserImpl(STI, P, MII, Options);
1156 /// RegisterAsmPrinter - Helper template for registering a target specific
1157 /// assembly printer, for use in the target machine initialization
1158 /// function. Usage:
1160 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1161 /// extern Target TheFooTarget;
1162 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1163 /// }
1164 template <class AsmPrinterImpl> struct RegisterAsmPrinter {
1165 RegisterAsmPrinter(Target &T) {
1166 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1169 private:
1170 static AsmPrinter *Allocator(TargetMachine &TM,
1171 std::unique_ptr<MCStreamer> &&Streamer) {
1172 return new AsmPrinterImpl(TM, std::move(Streamer));
1176 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1177 /// machine code emitter, for use in the target initialization
1178 /// function. Usage:
1180 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1181 /// extern Target TheFooTarget;
1182 /// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1183 /// }
1184 template <class MCCodeEmitterImpl> struct RegisterMCCodeEmitter {
1185 RegisterMCCodeEmitter(Target &T) {
1186 TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1189 private:
1190 static MCCodeEmitter *Allocator(const MCInstrInfo & /*II*/,
1191 const MCRegisterInfo & /*MRI*/,
1192 MCContext & /*Ctx*/) {
1193 return new MCCodeEmitterImpl();
1197 } // end namespace llvm
1199 #endif // LLVM_SUPPORT_TARGETREGISTRY_H