LLVM  10.0.0
TargetRegistry.h
Go to the documentation of this file.
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.
12 //
13 // Target specific class implementations should register themselves using the
14 // appropriate TargetRegistry interfaces.
15 //
16 //===----------------------------------------------------------------------===//
17 
18 #ifndef LLVM_SUPPORT_TARGETREGISTRY_H
19 #define LLVM_SUPPORT_TARGETREGISTRY_H
20 
22 #include "llvm/ADT/Optional.h"
23 #include "llvm/ADT/StringRef.h"
24 #include "llvm/ADT/Triple.h"
26 #include "llvm/Support/CodeGen.h"
29 #include <algorithm>
30 #include <cassert>
31 #include <cstddef>
32 #include <iterator>
33 #include <memory>
34 #include <string>
35 
36 namespace llvm {
37 
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;
61 
62 MCStreamer *createNullStreamer(MCContext &Ctx);
63 // Takes ownership of \p TAB and \p CE.
64 
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);
86 
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);
103 MCStreamer *createXCOFFStreamer(MCContext &Ctx,
104  std::unique_ptr<MCAsmBackend> &&TAB,
105  std::unique_ptr<MCObjectWriter> &&OW,
106  std::unique_ptr<MCCodeEmitter> &&CE,
107  bool RelaxAll);
108 
109 MCRelocationInfo *createMCRelocationInfo(const Triple &TT, MCContext &Ctx);
110 
111 MCSymbolizer *createMCSymbolizer(const Triple &TT, LLVMOpInfoCallback GetOpInfo,
112  LLVMSymbolLookupCallback SymbolLookUp,
113  void *DisInfo, MCContext *Ctx,
114  std::unique_ptr<MCRelocationInfo> &&RelInfo);
115 
116 /// Target - Wrapper for Target specific information.
117 ///
118 /// For registration purposes, this is a POD type so that targets can be
119 /// registered without the use of static constructors.
120 ///
121 /// Targets should implement a single global instance of this class (which
122 /// will be zero initialized), and pass that instance to the TargetRegistry as
123 /// part of their initialization.
124 class Target {
125 public:
126  friend struct TargetRegistry;
127 
129 
130  using MCAsmInfoCtorFnTy = MCAsmInfo *(*)(const MCRegisterInfo &MRI,
131  const Triple &TT,
132  const MCTargetOptions &Options);
136  using MCSubtargetInfoCtorFnTy = MCSubtargetInfo *(*)(const Triple &TT,
137  StringRef CPU,
138  StringRef Features);
140  *(*)(const Target &T, const Triple &TT, StringRef CPU, StringRef Features,
141  const TargetOptions &Options, Optional<Reloc::Model> RM,
143  // If it weren't for layering issues (this header is in llvm/Support, but
144  // depends on MC?) this should take the Streamer by value rather than rvalue
145  // reference.
146  using AsmPrinterCtorTy = AsmPrinter *(*)(
147  TargetMachine &TM, std::unique_ptr<MCStreamer> &&Streamer);
148  using MCAsmBackendCtorTy = MCAsmBackend *(*)(const Target &T,
149  const MCSubtargetInfo &STI,
150  const MCRegisterInfo &MRI,
151  const MCTargetOptions &Options);
153  const MCSubtargetInfo &STI, MCAsmParser &P, const MCInstrInfo &MII,
154  const MCTargetOptions &Options);
155  using MCDisassemblerCtorTy = MCDisassembler *(*)(const Target &T,
156  const MCSubtargetInfo &STI,
157  MCContext &Ctx);
158  using MCInstPrinterCtorTy = MCInstPrinter *(*)(const Triple &T,
159  unsigned SyntaxVariant,
160  const MCAsmInfo &MAI,
161  const MCInstrInfo &MII,
163  using MCCodeEmitterCtorTy = MCCodeEmitter *(*)(const MCInstrInfo &II,
164  const MCRegisterInfo &MRI,
165  MCContext &Ctx);
166  using ELFStreamerCtorTy =
167  MCStreamer *(*)(const Triple &T, MCContext &Ctx,
168  std::unique_ptr<MCAsmBackend> &&TAB,
169  std::unique_ptr<MCObjectWriter> &&OW,
170  std::unique_ptr<MCCodeEmitter> &&Emitter, bool RelaxAll);
171  using MachOStreamerCtorTy =
172  MCStreamer *(*)(MCContext &Ctx, std::unique_ptr<MCAsmBackend> &&TAB,
173  std::unique_ptr<MCObjectWriter> &&OW,
174  std::unique_ptr<MCCodeEmitter> &&Emitter, bool RelaxAll,
175  bool DWARFMustBeAtTheEnd);
176  using COFFStreamerCtorTy =
177  MCStreamer *(*)(MCContext &Ctx, std::unique_ptr<MCAsmBackend> &&TAB,
178  std::unique_ptr<MCObjectWriter> &&OW,
179  std::unique_ptr<MCCodeEmitter> &&Emitter, bool RelaxAll,
180  bool IncrementalLinkerCompatible);
181  using WasmStreamerCtorTy =
182  MCStreamer *(*)(const Triple &T, MCContext &Ctx,
183  std::unique_ptr<MCAsmBackend> &&TAB,
184  std::unique_ptr<MCObjectWriter> &&OW,
185  std::unique_ptr<MCCodeEmitter> &&Emitter, bool RelaxAll);
188  MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *InstPrint,
189  bool IsVerboseAsm);
191  MCStreamer &S, const MCSubtargetInfo &STI);
192  using MCRelocationInfoCtorTy = MCRelocationInfo *(*)(const Triple &TT,
193  MCContext &Ctx);
194  using MCSymbolizerCtorTy = MCSymbolizer *(*)(
195  const Triple &TT, LLVMOpInfoCallback GetOpInfo,
196  LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo, MCContext *Ctx,
197  std::unique_ptr<MCRelocationInfo> &&RelInfo);
198 
199 private:
200  /// Next - The next registered target in the linked list, maintained by the
201  /// TargetRegistry.
202  Target *Next;
203 
204  /// The target function for checking if an architecture is supported.
205  ArchMatchFnTy ArchMatchFn;
206 
207  /// Name - The target name.
208  const char *Name;
209 
210  /// ShortDesc - A short description of the target.
211  const char *ShortDesc;
212 
213  /// BackendName - The name of the backend implementation. This must match the
214  /// name of the 'def X : Target ...' in TableGen.
215  const char *BackendName;
216 
217  /// HasJIT - Whether this target supports the JIT.
218  bool HasJIT;
219 
220  /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
221  /// registered.
222  MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
223 
224  /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
225  /// if registered.
226  MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
227 
228  /// MCInstrAnalysisCtorFn - Constructor function for this target's
229  /// MCInstrAnalysis, if registered.
230  MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
231 
232  /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
233  /// if registered.
234  MCRegInfoCtorFnTy MCRegInfoCtorFn;
235 
236  /// MCSubtargetInfoCtorFn - Constructor function for this target's
237  /// MCSubtargetInfo, if registered.
238  MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
239 
240  /// TargetMachineCtorFn - Construction function for this target's
241  /// TargetMachine, if registered.
242  TargetMachineCtorTy TargetMachineCtorFn;
243 
244  /// MCAsmBackendCtorFn - Construction function for this target's
245  /// MCAsmBackend, if registered.
246  MCAsmBackendCtorTy MCAsmBackendCtorFn;
247 
248  /// MCAsmParserCtorFn - Construction function for this target's
249  /// MCTargetAsmParser, if registered.
250  MCAsmParserCtorTy MCAsmParserCtorFn;
251 
252  /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
253  /// if registered.
254  AsmPrinterCtorTy AsmPrinterCtorFn;
255 
256  /// MCDisassemblerCtorFn - Construction function for this target's
257  /// MCDisassembler, if registered.
258  MCDisassemblerCtorTy MCDisassemblerCtorFn;
259 
260  /// MCInstPrinterCtorFn - Construction function for this target's
261  /// MCInstPrinter, if registered.
262  MCInstPrinterCtorTy MCInstPrinterCtorFn;
263 
264  /// MCCodeEmitterCtorFn - Construction function for this target's
265  /// CodeEmitter, if registered.
266  MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
267 
268  // Construction functions for the various object formats, if registered.
269  COFFStreamerCtorTy COFFStreamerCtorFn = nullptr;
270  MachOStreamerCtorTy MachOStreamerCtorFn = nullptr;
271  ELFStreamerCtorTy ELFStreamerCtorFn = nullptr;
272  WasmStreamerCtorTy WasmStreamerCtorFn = nullptr;
273 
274  /// Construction function for this target's null TargetStreamer, if
275  /// registered (default = nullptr).
276  NullTargetStreamerCtorTy NullTargetStreamerCtorFn = nullptr;
277 
278  /// Construction function for this target's asm TargetStreamer, if
279  /// registered (default = nullptr).
280  AsmTargetStreamerCtorTy AsmTargetStreamerCtorFn = nullptr;
281 
282  /// Construction function for this target's obj TargetStreamer, if
283  /// registered (default = nullptr).
284  ObjectTargetStreamerCtorTy ObjectTargetStreamerCtorFn = nullptr;
285 
286  /// MCRelocationInfoCtorFn - Construction function for this target's
287  /// MCRelocationInfo, if registered (default = llvm::createMCRelocationInfo)
288  MCRelocationInfoCtorTy MCRelocationInfoCtorFn = nullptr;
289 
290  /// MCSymbolizerCtorFn - Construction function for this target's
291  /// MCSymbolizer, if registered (default = llvm::createMCSymbolizer)
292  MCSymbolizerCtorTy MCSymbolizerCtorFn = nullptr;
293 
294 public:
295  Target() = default;
296 
297  /// @name Target Information
298  /// @{
299 
300  // getNext - Return the next registered target.
301  const Target *getNext() const { return Next; }
302 
303  /// getName - Get the target name.
304  const char *getName() const { return Name; }
305 
306  /// getShortDescription - Get a short description of the target.
307  const char *getShortDescription() const { return ShortDesc; }
308 
309  /// getBackendName - Get the backend name.
310  const char *getBackendName() const { return BackendName; }
311 
312  /// @}
313  /// @name Feature Predicates
314  /// @{
315 
316  /// hasJIT - Check if this targets supports the just-in-time compilation.
317  bool hasJIT() const { return HasJIT; }
318 
319  /// hasTargetMachine - Check if this target supports code generation.
320  bool hasTargetMachine() const { return TargetMachineCtorFn != nullptr; }
321 
322  /// hasMCAsmBackend - Check if this target supports .o generation.
323  bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != nullptr; }
324 
325  /// hasMCAsmParser - Check if this target supports assembly parsing.
326  bool hasMCAsmParser() const { return MCAsmParserCtorFn != nullptr; }
327 
328  /// @}
329  /// @name Feature Constructors
330  /// @{
331 
332  /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
333  /// target triple.
334  ///
335  /// \param TheTriple 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.
340  const MCTargetOptions &Options) const {
341  if (!MCAsmInfoCtorFn)
342  return nullptr;
343  return MCAsmInfoCtorFn(MRI, Triple(TheTriple), Options);
344  }
345 
346  /// createMCInstrInfo - Create a MCInstrInfo implementation.
347  ///
349  if (!MCInstrInfoCtorFn)
350  return nullptr;
351  return MCInstrInfoCtorFn();
352  }
353 
354  /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
355  ///
357  if (!MCInstrAnalysisCtorFn)
358  return nullptr;
359  return MCInstrAnalysisCtorFn(Info);
360  }
361 
362  /// createMCRegInfo - Create a MCRegisterInfo implementation.
363  ///
365  if (!MCRegInfoCtorFn)
366  return nullptr;
367  return MCRegInfoCtorFn(Triple(TT));
368  }
369 
370  /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
371  ///
372  /// \param TheTriple This argument is used to determine the target machine
373  /// feature set; it should always be provided. Generally this should be
374  /// either the target triple from the module, or the target triple of the
375  /// host if that does not exist.
376  /// \param CPU This specifies the name of the target CPU.
377  /// \param Features This specifies the string representation of the
378  /// additional target features.
380  StringRef Features) const {
381  if (!MCSubtargetInfoCtorFn)
382  return nullptr;
383  return MCSubtargetInfoCtorFn(Triple(TheTriple), CPU, Features);
384  }
385 
386  /// createTargetMachine - Create a target specific machine implementation
387  /// for the specified \p Triple.
388  ///
389  /// \param TT This argument is used to determine the target machine
390  /// feature set; it should always be provided. Generally this should be
391  /// either the target triple from the module, or the target triple of the
392  /// host if that does not exist.
394  StringRef Features,
395  const TargetOptions &Options,
399  bool JIT = false) const {
400  if (!TargetMachineCtorFn)
401  return nullptr;
402  return TargetMachineCtorFn(*this, Triple(TT), CPU, Features, Options, RM,
403  CM, OL, JIT);
404  }
405 
406  /// createMCAsmBackend - Create a target specific assembly parser.
408  const MCRegisterInfo &MRI,
409  const MCTargetOptions &Options) const {
410  if (!MCAsmBackendCtorFn)
411  return nullptr;
412  return MCAsmBackendCtorFn(*this, STI, MRI, Options);
413  }
414 
415  /// createMCAsmParser - Create a target specific assembly parser.
416  ///
417  /// \param Parser The target independent parser implementation to use for
418  /// parsing and lexing.
420  MCAsmParser &Parser,
421  const MCInstrInfo &MII,
422  const MCTargetOptions &Options) const {
423  if (!MCAsmParserCtorFn)
424  return nullptr;
425  return MCAsmParserCtorFn(STI, Parser, MII, Options);
426  }
427 
428  /// createAsmPrinter - Create a target specific assembly printer pass. This
429  /// takes ownership of the MCStreamer object.
431  std::unique_ptr<MCStreamer> &&Streamer) const {
432  if (!AsmPrinterCtorFn)
433  return nullptr;
434  return AsmPrinterCtorFn(TM, std::move(Streamer));
435  }
436 
438  MCContext &Ctx) const {
439  if (!MCDisassemblerCtorFn)
440  return nullptr;
441  return MCDisassemblerCtorFn(*this, STI, Ctx);
442  }
443 
444  MCInstPrinter *createMCInstPrinter(const Triple &T, unsigned SyntaxVariant,
445  const MCAsmInfo &MAI,
446  const MCInstrInfo &MII,
447  const MCRegisterInfo &MRI) const {
448  if (!MCInstPrinterCtorFn)
449  return nullptr;
450  return MCInstPrinterCtorFn(T, SyntaxVariant, MAI, MII, MRI);
451  }
452 
453  /// createMCCodeEmitter - Create a target specific code emitter.
455  const MCRegisterInfo &MRI,
456  MCContext &Ctx) const {
457  if (!MCCodeEmitterCtorFn)
458  return nullptr;
459  return MCCodeEmitterCtorFn(II, MRI, Ctx);
460  }
461 
462  /// Create a target specific MCStreamer.
463  ///
464  /// \param T The target triple.
465  /// \param Ctx The target context.
466  /// \param TAB The target assembler backend object. Takes ownership.
467  /// \param OW The stream object.
468  /// \param Emitter The target independent assembler object.Takes ownership.
469  /// \param RelaxAll Relax all fixups?
471  std::unique_ptr<MCAsmBackend> &&TAB,
472  std::unique_ptr<MCObjectWriter> &&OW,
473  std::unique_ptr<MCCodeEmitter> &&Emitter,
474  const MCSubtargetInfo &STI, bool RelaxAll,
475  bool IncrementalLinkerCompatible,
476  bool DWARFMustBeAtTheEnd) const {
477  MCStreamer *S = nullptr;
478  switch (T.getObjectFormat()) {
480  llvm_unreachable("Unknown object format");
481  case Triple::COFF:
482  assert(T.isOSWindows() && "only Windows COFF is supported");
483  S = COFFStreamerCtorFn(Ctx, std::move(TAB), std::move(OW),
484  std::move(Emitter), RelaxAll,
485  IncrementalLinkerCompatible);
486  break;
487  case Triple::MachO:
488  if (MachOStreamerCtorFn)
489  S = MachOStreamerCtorFn(Ctx, std::move(TAB), std::move(OW),
490  std::move(Emitter), RelaxAll,
491  DWARFMustBeAtTheEnd);
492  else
493  S = createMachOStreamer(Ctx, std::move(TAB), std::move(OW),
494  std::move(Emitter), RelaxAll,
495  DWARFMustBeAtTheEnd);
496  break;
497  case Triple::ELF:
498  if (ELFStreamerCtorFn)
499  S = ELFStreamerCtorFn(T, Ctx, std::move(TAB), std::move(OW),
500  std::move(Emitter), RelaxAll);
501  else
502  S = createELFStreamer(Ctx, std::move(TAB), std::move(OW),
503  std::move(Emitter), RelaxAll);
504  break;
505  case Triple::Wasm:
506  if (WasmStreamerCtorFn)
507  S = WasmStreamerCtorFn(T, Ctx, std::move(TAB), std::move(OW),
508  std::move(Emitter), RelaxAll);
509  else
510  S = createWasmStreamer(Ctx, std::move(TAB), std::move(OW),
511  std::move(Emitter), RelaxAll);
512  break;
513  case Triple::XCOFF:
514  S = createXCOFFStreamer(Ctx, std::move(TAB), std::move(OW),
515  std::move(Emitter), RelaxAll);
516  break;
517  }
518  if (ObjectTargetStreamerCtorFn)
519  ObjectTargetStreamerCtorFn(*S, STI);
520  return S;
521  }
522 
524  std::unique_ptr<formatted_raw_ostream> OS,
525  bool IsVerboseAsm, bool UseDwarfDirectory,
526  MCInstPrinter *InstPrint,
527  std::unique_ptr<MCCodeEmitter> &&CE,
528  std::unique_ptr<MCAsmBackend> &&TAB,
529  bool ShowInst) const {
530  formatted_raw_ostream &OSRef = *OS;
532  Ctx, std::move(OS), IsVerboseAsm, UseDwarfDirectory, InstPrint,
533  std::move(CE), std::move(TAB), ShowInst);
534  createAsmTargetStreamer(*S, OSRef, InstPrint, IsVerboseAsm);
535  return S;
536  }
537 
540  MCInstPrinter *InstPrint,
541  bool IsVerboseAsm) const {
542  if (AsmTargetStreamerCtorFn)
543  return AsmTargetStreamerCtorFn(S, OS, InstPrint, IsVerboseAsm);
544  return nullptr;
545  }
546 
550  return S;
551  }
552 
554  if (NullTargetStreamerCtorFn)
555  return NullTargetStreamerCtorFn(S);
556  return nullptr;
557  }
558 
559  /// createMCRelocationInfo - Create a target specific MCRelocationInfo.
560  ///
561  /// \param TT The target triple.
562  /// \param Ctx The target context.
564  MCRelocationInfoCtorTy Fn = MCRelocationInfoCtorFn
565  ? MCRelocationInfoCtorFn
567  return Fn(Triple(TT), Ctx);
568  }
569 
570  /// createMCSymbolizer - Create a target specific MCSymbolizer.
571  ///
572  /// \param TT The target triple.
573  /// \param GetOpInfo The function to get the symbolic information for
574  /// operands.
575  /// \param SymbolLookUp The function to lookup a symbol name.
576  /// \param DisInfo The pointer to the block of symbolic information for above
577  /// call
578  /// back.
579  /// \param Ctx The target context.
580  /// \param RelInfo The relocation information for this target. Takes
581  /// ownership.
582  MCSymbolizer *
584  LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo,
585  MCContext *Ctx,
586  std::unique_ptr<MCRelocationInfo> &&RelInfo) const {
587  MCSymbolizerCtorTy Fn =
588  MCSymbolizerCtorFn ? MCSymbolizerCtorFn : llvm::createMCSymbolizer;
589  return Fn(Triple(TT), GetOpInfo, SymbolLookUp, DisInfo, Ctx,
590  std::move(RelInfo));
591  }
592 
593  /// @}
594 };
595 
596 /// TargetRegistry - Generic interface to target specific features.
598  // FIXME: Make this a namespace, probably just move all the Register*
599  // functions into Target (currently they all just set members on the Target
600  // anyway, and Target friends this class so those functions can...
601  // function).
602  TargetRegistry() = delete;
603 
604  class iterator
605  : public std::iterator<std::forward_iterator_tag, Target, ptrdiff_t> {
606  friend struct TargetRegistry;
607 
608  const Target *Current = nullptr;
609 
610  explicit iterator(Target *T) : Current(T) {}
611 
612  public:
613  iterator() = default;
614 
615  bool operator==(const iterator &x) const { return Current == x.Current; }
616  bool operator!=(const iterator &x) const { return !operator==(x); }
617 
618  // Iterator traversal: forward iteration only
619  iterator &operator++() { // Preincrement
620  assert(Current && "Cannot increment end iterator!");
621  Current = Current->getNext();
622  return *this;
623  }
624  iterator operator++(int) { // Postincrement
625  iterator tmp = *this;
626  ++*this;
627  return tmp;
628  }
629 
630  const Target &operator*() const {
631  assert(Current && "Cannot dereference end iterator!");
632  return *Current;
633  }
634 
635  const Target *operator->() const { return &operator*(); }
636  };
637 
638  /// printRegisteredTargetsForVersion - Print the registered targets
639  /// appropriately for inclusion in a tool's version output.
640  static void printRegisteredTargetsForVersion(raw_ostream &OS);
641 
642  /// @name Registry Access
643  /// @{
644 
645  static iterator_range<iterator> targets();
646 
647  /// lookupTarget - Lookup a target based on a target triple.
648  ///
649  /// \param Triple - The triple to use for finding a target.
650  /// \param Error - On failure, an error string describing why no target was
651  /// found.
652  static const Target *lookupTarget(const std::string &Triple,
653  std::string &Error);
654 
655  /// lookupTarget - Lookup a target based on an architecture name
656  /// and a target triple. If the architecture name is non-empty,
657  /// then the lookup is done by architecture. Otherwise, the target
658  /// triple is used.
659  ///
660  /// \param ArchName - The architecture to use for finding a target.
661  /// \param TheTriple - The triple to use for finding a target. The
662  /// triple is updated with canonical architecture name if a lookup
663  /// by architecture is done.
664  /// \param Error - On failure, an error string describing why no target was
665  /// found.
666  static const Target *lookupTarget(const std::string &ArchName,
667  Triple &TheTriple, std::string &Error);
668 
669  /// @}
670  /// @name Target Registration
671  /// @{
672 
673  /// RegisterTarget - Register the given target. Attempts to register a
674  /// target which has already been registered will be ignored.
675  ///
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.
679  ///
680  /// @param T - The target being registered.
681  /// @param Name - The target name. This should be a static string.
682  /// @param ShortDesc - A short target description. This should be a static
683  /// string.
684  /// @param BackendName - The name of the backend. This should be a static
685  /// string that is the same for all targets that share a backend
686  /// implementation and must match the name used in the 'def X : Target ...' in
687  /// TableGen.
688  /// @param ArchMatchFn - The arch match checking function for this target.
689  /// @param HasJIT - Whether the target supports JIT code
690  /// generation.
691  static void RegisterTarget(Target &T, const char *Name, const char *ShortDesc,
692  const char *BackendName,
693  Target::ArchMatchFnTy ArchMatchFn,
694  bool HasJIT = false);
695 
696  /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
697  /// given target.
698  ///
699  /// Clients are responsible for ensuring that registration doesn't occur
700  /// while another thread is attempting to access the registry. Typically
701  /// this is done by initializing all targets at program startup.
702  ///
703  /// @param T - The target being registered.
704  /// @param Fn - A function to construct a MCAsmInfo for the target.
706  T.MCAsmInfoCtorFn = Fn;
707  }
708 
709  /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
710  /// given target.
711  ///
712  /// Clients are responsible for ensuring that registration doesn't occur
713  /// while another thread is attempting to access the registry. Typically
714  /// this is done by initializing all targets at program startup.
715  ///
716  /// @param T - The target being registered.
717  /// @param Fn - A function to construct a MCInstrInfo for the target.
719  T.MCInstrInfoCtorFn = Fn;
720  }
721 
722  /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
723  /// the given target.
726  T.MCInstrAnalysisCtorFn = Fn;
727  }
728 
729  /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
730  /// given target.
731  ///
732  /// Clients are responsible for ensuring that registration doesn't occur
733  /// while another thread is attempting to access the registry. Typically
734  /// this is done by initializing all targets at program startup.
735  ///
736  /// @param T - The target being registered.
737  /// @param Fn - A function to construct a MCRegisterInfo for the target.
739  T.MCRegInfoCtorFn = Fn;
740  }
741 
742  /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
743  /// the given target.
744  ///
745  /// Clients are responsible for ensuring that registration doesn't occur
746  /// while another thread is attempting to access the registry. Typically
747  /// this is done by initializing all targets at program startup.
748  ///
749  /// @param T - The target being registered.
750  /// @param Fn - A function to construct a MCSubtargetInfo for the target.
753  T.MCSubtargetInfoCtorFn = Fn;
754  }
755 
756  /// RegisterTargetMachine - Register a TargetMachine implementation for the
757  /// given target.
758  ///
759  /// Clients are responsible for ensuring that registration doesn't occur
760  /// while another thread is attempting to access the registry. Typically
761  /// this is done by initializing all targets at program startup.
762  ///
763  /// @param T - The target being registered.
764  /// @param Fn - A function to construct a TargetMachine for the target.
766  T.TargetMachineCtorFn = Fn;
767  }
768 
769  /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
770  /// given target.
771  ///
772  /// Clients are responsible for ensuring that registration doesn't occur
773  /// while another thread is attempting to access the registry. Typically
774  /// this is done by initializing all targets at program startup.
775  ///
776  /// @param T - The target being registered.
777  /// @param Fn - A function to construct an AsmBackend for the target.
779  T.MCAsmBackendCtorFn = Fn;
780  }
781 
782  /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
783  /// the given target.
784  ///
785  /// Clients are responsible for ensuring that registration doesn't occur
786  /// while another thread is attempting to access the registry. Typically
787  /// this is done by initializing all targets at program startup.
788  ///
789  /// @param T - The target being registered.
790  /// @param Fn - A function to construct an MCTargetAsmParser for the target.
792  T.MCAsmParserCtorFn = Fn;
793  }
794 
795  /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
796  /// target.
797  ///
798  /// Clients are responsible for ensuring that registration doesn't occur
799  /// while another thread is attempting to access the registry. Typically
800  /// this is done by initializing all targets at program startup.
801  ///
802  /// @param T - The target being registered.
803  /// @param Fn - A function to construct an AsmPrinter for the target.
805  T.AsmPrinterCtorFn = Fn;
806  }
807 
808  /// RegisterMCDisassembler - Register a MCDisassembler implementation for
809  /// the given target.
810  ///
811  /// Clients are responsible for ensuring that registration doesn't occur
812  /// while another thread is attempting to access the registry. Typically
813  /// this is done by initializing all targets at program startup.
814  ///
815  /// @param T - The target being registered.
816  /// @param Fn - A function to construct an MCDisassembler for the target.
819  T.MCDisassemblerCtorFn = Fn;
820  }
821 
822  /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
823  /// given target.
824  ///
825  /// Clients are responsible for ensuring that registration doesn't occur
826  /// while another thread is attempting to access the registry. Typically
827  /// this is done by initializing all targets at program startup.
828  ///
829  /// @param T - The target being registered.
830  /// @param Fn - A function to construct an MCInstPrinter for the target.
832  T.MCInstPrinterCtorFn = Fn;
833  }
834 
835  /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
836  /// given target.
837  ///
838  /// Clients are responsible for ensuring that registration doesn't occur
839  /// while another thread is attempting to access the registry. Typically
840  /// this is done by initializing all targets at program startup.
841  ///
842  /// @param T - The target being registered.
843  /// @param Fn - A function to construct an MCCodeEmitter for the target.
845  T.MCCodeEmitterCtorFn = Fn;
846  }
847 
849  T.COFFStreamerCtorFn = Fn;
850  }
851 
853  T.MachOStreamerCtorFn = Fn;
854  }
855 
857  T.ELFStreamerCtorFn = Fn;
858  }
859 
861  T.WasmStreamerCtorFn = Fn;
862  }
863 
866  T.NullTargetStreamerCtorFn = Fn;
867  }
868 
871  T.AsmTargetStreamerCtorFn = Fn;
872  }
873 
874  static void
877  T.ObjectTargetStreamerCtorFn = Fn;
878  }
879 
880  /// RegisterMCRelocationInfo - Register an MCRelocationInfo
881  /// implementation for the given target.
882  ///
883  /// Clients are responsible for ensuring that registration doesn't occur
884  /// while another thread is attempting to access the registry. Typically
885  /// this is done by initializing all targets at program startup.
886  ///
887  /// @param T - The target being registered.
888  /// @param Fn - A function to construct an MCRelocationInfo for the target.
891  T.MCRelocationInfoCtorFn = Fn;
892  }
893 
894  /// RegisterMCSymbolizer - Register an MCSymbolizer
895  /// implementation for the given target.
896  ///
897  /// Clients are responsible for ensuring that registration doesn't occur
898  /// while another thread is attempting to access the registry. Typically
899  /// this is done by initializing all targets at program startup.
900  ///
901  /// @param T - The target being registered.
902  /// @param Fn - A function to construct an MCSymbolizer for the target.
904  T.MCSymbolizerCtorFn = Fn;
905  }
906 
907  /// @}
908 };
909 
910 //===--------------------------------------------------------------------===//
911 
912 /// RegisterTarget - Helper template for registering a target, for use in the
913 /// target's initialization function. Usage:
914 ///
915 ///
916 /// Target &getTheFooTarget() { // The global target instance.
917 /// static Target TheFooTarget;
918 /// return TheFooTarget;
919 /// }
920 /// extern "C" void LLVMInitializeFooTargetInfo() {
921 /// RegisterTarget<Triple::foo> X(getTheFooTarget(), "foo", "Foo
922 /// description", "Foo" /* Backend Name */);
923 /// }
924 template <Triple::ArchType TargetArchType = Triple::UnknownArch,
925  bool HasJIT = false>
927  RegisterTarget(Target &T, const char *Name, const char *Desc,
928  const char *BackendName) {
929  TargetRegistry::RegisterTarget(T, Name, Desc, BackendName, &getArchMatch,
930  HasJIT);
931  }
932 
933  static bool getArchMatch(Triple::ArchType Arch) {
934  return Arch == TargetArchType;
935  }
936 };
937 
938 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
939 /// implementation. This invokes the static "Create" method on the class to
940 /// actually do the construction. Usage:
941 ///
942 /// extern "C" void LLVMInitializeFooTarget() {
943 /// extern Target TheFooTarget;
944 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
945 /// }
946 template <class MCAsmInfoImpl> struct RegisterMCAsmInfo {
949  }
950 
951 private:
952  static MCAsmInfo *Allocator(const MCRegisterInfo & /*MRI*/, const Triple &TT,
953  const MCTargetOptions &Options) {
954  return new MCAsmInfoImpl(TT, Options);
955  }
956 };
957 
958 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
959 /// implementation. This invokes the specified function to do the
960 /// construction. Usage:
961 ///
962 /// extern "C" void LLVMInitializeFooTarget() {
963 /// extern Target TheFooTarget;
964 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
965 /// }
969  }
970 };
971 
972 /// RegisterMCInstrInfo - Helper template for registering a target instruction
973 /// info implementation. This invokes the static "Create" method on the class
974 /// to actually do the construction. Usage:
975 ///
976 /// extern "C" void LLVMInitializeFooTarget() {
977 /// extern Target TheFooTarget;
978 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
979 /// }
980 template <class MCInstrInfoImpl> struct RegisterMCInstrInfo {
983  }
984 
985 private:
986  static MCInstrInfo *Allocator() { return new MCInstrInfoImpl(); }
987 };
988 
989 /// RegisterMCInstrInfoFn - Helper template for registering a target
990 /// instruction info implementation. This invokes the specified function to
991 /// do the construction. Usage:
992 ///
993 /// extern "C" void LLVMInitializeFooTarget() {
994 /// extern Target TheFooTarget;
995 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
996 /// }
1000  }
1001 };
1002 
1003 /// RegisterMCInstrAnalysis - Helper template for registering a target
1004 /// instruction analyzer implementation. This invokes the static "Create"
1005 /// method on the class to actually do the construction. Usage:
1006 ///
1007 /// extern "C" void LLVMInitializeFooTarget() {
1008 /// extern Target TheFooTarget;
1009 /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
1010 /// }
1011 template <class MCInstrAnalysisImpl> struct RegisterMCInstrAnalysis {
1014  }
1015 
1016 private:
1017  static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
1018  return new MCInstrAnalysisImpl(Info);
1019  }
1020 };
1021 
1022 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
1023 /// instruction analyzer implementation. This invokes the specified function
1024 /// to do the construction. Usage:
1025 ///
1026 /// extern "C" void LLVMInitializeFooTarget() {
1027 /// extern Target TheFooTarget;
1028 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
1029 /// }
1033  }
1034 };
1035 
1036 /// RegisterMCRegInfo - Helper template for registering a target register info
1037 /// implementation. This invokes the static "Create" method on the class to
1038 /// actually do the construction. Usage:
1039 ///
1040 /// extern "C" void LLVMInitializeFooTarget() {
1041 /// extern Target TheFooTarget;
1042 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
1043 /// }
1044 template <class MCRegisterInfoImpl> struct RegisterMCRegInfo {
1047  }
1048 
1049 private:
1050  static MCRegisterInfo *Allocator(const Triple & /*TT*/) {
1051  return new MCRegisterInfoImpl();
1052  }
1053 };
1054 
1055 /// RegisterMCRegInfoFn - Helper template for registering a target register
1056 /// info implementation. This invokes the specified function to do the
1057 /// construction. Usage:
1058 ///
1059 /// extern "C" void LLVMInitializeFooTarget() {
1060 /// extern Target TheFooTarget;
1061 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
1062 /// }
1066  }
1067 };
1068 
1069 /// RegisterMCSubtargetInfo - Helper template for registering a target
1070 /// subtarget info implementation. This invokes the static "Create" method
1071 /// on the class to actually do the construction. Usage:
1072 ///
1073 /// extern "C" void LLVMInitializeFooTarget() {
1074 /// extern Target TheFooTarget;
1075 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
1076 /// }
1077 template <class MCSubtargetInfoImpl> struct RegisterMCSubtargetInfo {
1080  }
1081 
1082 private:
1083  static MCSubtargetInfo *Allocator(const Triple & /*TT*/, StringRef /*CPU*/,
1084  StringRef /*FS*/) {
1085  return new MCSubtargetInfoImpl();
1086  }
1087 };
1088 
1089 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
1090 /// subtarget info implementation. This invokes the specified function to
1091 /// do the construction. Usage:
1092 ///
1093 /// extern "C" void LLVMInitializeFooTarget() {
1094 /// extern Target TheFooTarget;
1095 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1096 /// }
1100  }
1101 };
1102 
1103 /// RegisterTargetMachine - Helper template for registering a target machine
1104 /// implementation, for use in the target machine initialization
1105 /// function. Usage:
1106 ///
1107 /// extern "C" void LLVMInitializeFooTarget() {
1108 /// extern Target TheFooTarget;
1109 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1110 /// }
1111 template <class TargetMachineImpl> struct RegisterTargetMachine {
1114  }
1115 
1116 private:
1117  static TargetMachine *
1118  Allocator(const Target &T, const Triple &TT, StringRef CPU, StringRef FS,
1119  const TargetOptions &Options, Optional<Reloc::Model> RM,
1120  Optional<CodeModel::Model> CM, CodeGenOpt::Level OL, bool JIT) {
1121  return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL, JIT);
1122  }
1123 };
1124 
1125 /// RegisterMCAsmBackend - Helper template for registering a target specific
1126 /// assembler backend. Usage:
1127 ///
1128 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1129 /// extern Target TheFooTarget;
1130 /// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1131 /// }
1132 template <class MCAsmBackendImpl> struct RegisterMCAsmBackend {
1135  }
1136 
1137 private:
1138  static MCAsmBackend *Allocator(const Target &T, const MCSubtargetInfo &STI,
1139  const MCRegisterInfo &MRI,
1140  const MCTargetOptions &Options) {
1141  return new MCAsmBackendImpl(T, STI, MRI);
1142  }
1143 };
1144 
1145 /// RegisterMCAsmParser - Helper template for registering a target specific
1146 /// assembly parser, for use in the target machine initialization
1147 /// function. Usage:
1148 ///
1149 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1150 /// extern Target TheFooTarget;
1151 /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1152 /// }
1153 template <class MCAsmParserImpl> struct RegisterMCAsmParser {
1156  }
1157 
1158 private:
1159  static MCTargetAsmParser *Allocator(const MCSubtargetInfo &STI,
1160  MCAsmParser &P, const MCInstrInfo &MII,
1161  const MCTargetOptions &Options) {
1162  return new MCAsmParserImpl(STI, P, MII, Options);
1163  }
1164 };
1165 
1166 /// RegisterAsmPrinter - Helper template for registering a target specific
1167 /// assembly printer, for use in the target machine initialization
1168 /// function. Usage:
1169 ///
1170 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1171 /// extern Target TheFooTarget;
1172 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1173 /// }
1174 template <class AsmPrinterImpl> struct RegisterAsmPrinter {
1177  }
1178 
1179 private:
1180  static AsmPrinter *Allocator(TargetMachine &TM,
1181  std::unique_ptr<MCStreamer> &&Streamer) {
1182  return new AsmPrinterImpl(TM, std::move(Streamer));
1183  }
1184 };
1185 
1186 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1187 /// machine code emitter, for use in the target initialization
1188 /// function. Usage:
1189 ///
1190 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1191 /// extern Target TheFooTarget;
1192 /// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1193 /// }
1194 template <class MCCodeEmitterImpl> struct RegisterMCCodeEmitter {
1197  }
1198 
1199 private:
1200  static MCCodeEmitter *Allocator(const MCInstrInfo & /*II*/,
1201  const MCRegisterInfo & /*MRI*/,
1202  MCContext & /*Ctx*/) {
1203  return new MCCodeEmitterImpl();
1204  }
1205 };
1206 
1207 } // end namespace llvm
1208 
1209 #endif // LLVM_SUPPORT_TARGETREGISTRY_H
const Target * operator->() const
RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn)
MCTargetStreamer *(*)(MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *InstPrint, bool IsVerboseAsm) AsmTargetStreamerCtorTy
MCAsmInfo * createMCAsmInfo(const MCRegisterInfo &MRI, StringRef TheTriple, const MCTargetOptions &Options) const
createMCAsmInfo - Create a MCAsmInfo implementation for the specified target triple.
MCStreamer * createMCObjectStreamer(const Triple &T, MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&Emitter, const MCSubtargetInfo &STI, bool RelaxAll, bool IncrementalLinkerCompatible, bool DWARFMustBeAtTheEnd) const
Create a target specific MCStreamer.
Target()=default
RegisterMCInstrInfoFn - Helper template for registering a target instruction info implementation...
This class represents lattice values for constants.
Definition: AllocatorList.h:23
RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn)
Generic assembler parser interface, for use by target specific assembly parsers.
Definition: MCAsmParser.h:109
TargetMachine * createTargetMachine(StringRef TT, StringRef CPU, StringRef Features, const TargetOptions &Options, Optional< Reloc::Model > RM, Optional< CodeModel::Model > CM=None, CodeGenOpt::Level OL=CodeGenOpt::Default, bool JIT=false) const
createTargetMachine - Create a target specific machine implementation for the specified Triple...
bool hasTargetMachine() const
hasTargetMachine - Check if this target supports code generation.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
RegisterMCSubtargetInfo - Helper template for registering a target subtarget info implementation...
formatted_raw_ostream - A raw_ostream that wraps another one and keeps track of line and column posit...
static void RegisterMCInstrAnalysis(Target &T, Target::MCInstrAnalysisCtorFnTy Fn)
RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for the given target...
MCTargetAsmParser - Generic interface to target specific assembly parsers.
Superclass for all disassemblers.
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
MCCodeEmitter *(*)(const MCInstrInfo &II, const MCRegisterInfo &MRI, MCContext &Ctx) MCCodeEmitterCtorTy
MCSymbolizer *(*)(const Triple &TT, LLVMOpInfoCallback GetOpInfo, LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo, MCContext *Ctx, std::unique_ptr< MCRelocationInfo > &&RelInfo) MCSymbolizerCtorTy
Target specific streamer interface.
Definition: MCStreamer.h:91
MCAsmBackend * createMCAsmBackend(const MCSubtargetInfo &STI, const MCRegisterInfo &MRI, const MCTargetOptions &Options) const
createMCAsmBackend - Create a target specific assembly parser.
RegisterMCCodeEmitter(Target &T)
MCInstrInfo * createMCInstrInfo() const
createMCInstrInfo - Create a MCInstrInfo implementation.
MCSubtargetInfo *(*)(const Triple &TT, StringRef CPU, StringRef Features) MCSubtargetInfoCtorFnTy
MCStreamer * createNullStreamer(MCContext &Ctx)
Create a dummy machine code streamer, which does nothing.
RegisterMCInstrAnalysis(Target &T)
MCTargetStreamer *(*)(MCStreamer &S) NullTargetStreamerCtorTy
MCDisassembler * createMCDisassembler(const MCSubtargetInfo &STI, MCContext &Ctx) const
static void RegisterMCDisassembler(Target &T, Target::MCDisassemblerCtorTy Fn)
RegisterMCDisassembler - Register a MCDisassembler implementation for the given target.
TargetRegistry - Generic interface to target specific features.
static void RegisterMCInstPrinter(Target &T, Target::MCInstPrinterCtorTy Fn)
RegisterMCInstPrinter - Register a MCInstPrinter implementation for the given target.
MCSymbolizer * createMCSymbolizer(const Triple &TT, LLVMOpInfoCallback GetOpInfo, LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo, MCContext *Ctx, std::unique_ptr< MCRelocationInfo > &&RelInfo)
static void RegisterAsmTargetStreamer(Target &T, Target::AsmTargetStreamerCtorTy Fn)
RegisterMCInstrAnalysisFn - Helper template for registering a target instruction analyzer implementat...
static void RegisterWasmStreamer(Target &T, Target::WasmStreamerCtorTy Fn)
const char * getShortDescription() const
getShortDescription - Get a short description of the target.
const char * getName() const
getName - Get the target name.
RegisterMCAsmBackend(Target &T)
RegisterTargetMachine(Target &T)
MCInstPrinter * createMCInstPrinter(const Triple &T, unsigned SyntaxVariant, const MCAsmInfo &MAI, const MCInstrInfo &MII, const MCRegisterInfo &MRI) const
MCStreamer * createXCOFFStreamer(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&CE, bool RelaxAll)
bool hasMCAsmParser() const
hasMCAsmParser - Check if this target supports assembly parsing.
RegisterMCRegInfoFn - Helper template for registering a target register info implementation.
static void RegisterCOFFStreamer(Target &T, Target::COFFStreamerCtorTy Fn)
int(* LLVMOpInfoCallback)(void *DisInfo, uint64_t PC, uint64_t Offset, uint64_t Size, int TagType, void *TagBuf)
The type for the operand information call back function.
MCAsmBackend *(*)(const Target &T, const MCSubtargetInfo &STI, const MCRegisterInfo &MRI, const MCTargetOptions &Options) MCAsmBackendCtorTy
APInt operator*(APInt a, uint64_t RHS)
Definition: APInt.h:2148
MCInstrAnalysis *(*)(const MCInstrInfo *Info) MCInstrAnalysisCtorFnTy
Context object for machine code objects.
Definition: MCContext.h:65
MCStreamer * createNullStreamer(MCContext &Ctx) const
MCRegisterInfo *(*)(const Triple &TT) MCRegInfoCtorFnTy
RegisterTargetMachine - Helper template for registering a target machine implementation, for use in the target machine initialization function.
RegisterMCAsmParser - Helper template for registering a target specific assembly parser, for use in the target machine initialization function.
static void RegisterTargetMachine(Target &T, Target::TargetMachineCtorTy Fn)
RegisterTargetMachine - Register a TargetMachine implementation for the given target.
MCStreamer * createAsmStreamer(MCContext &Ctx, std::unique_ptr< formatted_raw_ostream > OS, bool isVerboseAsm, bool useDwarfDirectory, MCInstPrinter *InstPrint, MCCodeEmitter *CE, MCAsmBackend *TAB, bool ShowInst)
Create a machine code streamer which will print out assembly for the native target, suitable for compiling with a native assembler.
RegisterAsmPrinter - Helper template for registering a target specific assembly printer, for use in the target machine initialization function.
RegisterMCInstrAnalysis - Helper template for registering a target instruction analyzer implementatio...
const Target & operator*() const
MCCodeEmitter * createMCCodeEmitter(const MCInstrInfo &II, const MCRegisterInfo &MRI, MCContext &Ctx) const
createMCCodeEmitter - Create a target specific code emitter.
AsmPrinter *(*)(TargetMachine &TM, std::unique_ptr< MCStreamer > &&Streamer) AsmPrinterCtorTy
Analysis containing CSE Info
Definition: CSEInfo.cpp:25
MCRelocationInfo * createMCRelocationInfo(const Triple &TT, MCContext &Ctx)
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
bool isOSWindows() const
Tests whether the OS is Windows.
Definition: Triple.h:539
const Target * getNext() const
static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn)
RegisterMCAsmBackend - Register a MCAsmBackend implementation for the given target.
#define P(N)
RegisterMCSubtargetInfoFn - Helper template for registering a target subtarget info implementation...
Streaming machine code generation interface.
Definition: MCStreamer.h:197
MCTargetAsmParser *(*)(const MCSubtargetInfo &STI, MCAsmParser &P, const MCInstrInfo &MII, const MCTargetOptions &Options) MCAsmParserCtorTy
unsigned const MachineRegisterInfo * MRI
RegisterAsmPrinter(Target &T)
AsmPrinter * createAsmPrinter(TargetMachine &TM, std::unique_ptr< MCStreamer > &&Streamer) const
createAsmPrinter - Create a target specific assembly printer pass.
static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn)
RegisterMCAsmParser - Register a MCTargetAsmParser implementation for the given target.
Symbolize and annotate disassembled instructions.
Definition: MCSymbolizer.h:38
MCDisassembler *(*)(const Target &T, const MCSubtargetInfo &STI, MCContext &Ctx) MCDisassemblerCtorTy
static void RegisterMachOStreamer(Target &T, Target::MachOStreamerCtorTy Fn)
MCAsmInfo *(*)(const MCRegisterInfo &MRI, const Triple &TT, const MCTargetOptions &Options) MCAsmInfoCtorFnTy
MCStreamer * createELFStreamer(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&CE, bool RelaxAll)
MCCodeEmitter - Generic instruction encoding interface.
Definition: MCCodeEmitter.h:21
Interface to description of machine instruction set.
Definition: MCInstrInfo.h:23
RegisterMCRegInfo(Target &T)
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:80
bool(*)(Triple::ArchType Arch) ArchMatchFnTy
static void RegisterTarget(Target &T, const char *Name, const char *ShortDesc, const char *BackendName, Target::ArchMatchFnTy ArchMatchFn, bool HasJIT=false)
RegisterTarget - Register the given target.
Create MCExprs from relocations found in an object file.
MCRegisterInfo * createMCRegInfo(StringRef TT) const
createMCRegInfo - Create a MCRegisterInfo implementation.
static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn)
RegisterMCAsmInfo - Register a MCAsmInfo implementation for the given target.
MCTargetAsmParser * createMCAsmParser(const MCSubtargetInfo &STI, MCAsmParser &Parser, const MCInstrInfo &MII, const MCTargetOptions &Options) const
createMCAsmParser - Create a target specific assembly parser.
static void RegisterMCSubtargetInfo(Target &T, Target::MCSubtargetInfoCtorFnTy Fn)
RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for the given target...
static void RegisterObjectTargetStreamer(Target &T, Target::ObjectTargetStreamerCtorTy Fn)
friend struct TargetRegistry
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:43
MCTargetStreamer * createAsmTargetStreamer(MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *InstPrint, bool IsVerboseAsm) const
RegisterMCAsmBackend - Helper template for registering a target specific assembler backend...
Basic Register Allocator
MCInstrAnalysis * createMCInstrAnalysis(const MCInstrInfo *Info) const
createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
RegisterTarget(Target &T, const char *Name, const char *Desc, const char *BackendName)
static void RegisterMCCodeEmitter(Target &T, Target::MCCodeEmitterCtorTy Fn)
RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the given target.
bool hasMCAsmBackend() const
hasMCAsmBackend - Check if this target supports .o generation.
MCTargetStreamer *(*)(MCStreamer &S, const MCSubtargetInfo &STI) ObjectTargetStreamerCtorTy
RegisterMCSubtargetInfo(Target &T)
RegisterMCAsmInfo(Target &T)
A range adaptor for a pair of iterators.
static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn)
RegisterMCRegInfo - Register a MCRegisterInfo implementation for the given target.
Target - Wrapper for Target specific information.
RegisterMCInstrInfo(Target &T)
RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn)
MCSubtargetInfo * createMCSubtargetInfo(StringRef TheTriple, StringRef CPU, StringRef Features) const
createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
RegisterMCAsmParser(Target &T)
This is an instance of a target assembly language printer that converts an MCInst to valid target ass...
Definition: MCInstPrinter.h:42
ObjectFormatType getObjectFormat() const
getFormat - Get the object format for this triple.
Definition: Triple.h:327
MCRelocationInfo *(*)(const Triple &TT, MCContext &Ctx) MCRelocationInfoCtorTy
static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn)
RegisterMCInstrInfo - Register a MCInstrInfo implementation for the given target. ...
Generic base class for all target subtargets.
TargetMachine *(*)(const Target &T, const Triple &TT, StringRef CPU, StringRef Features, const TargetOptions &Options, Optional< Reloc::Model > RM, Optional< CodeModel::Model > CM, CodeGenOpt::Level OL, bool JIT) TargetMachineCtorTy
MCSymbolizer * createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo, LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo, MCContext *Ctx, std::unique_ptr< MCRelocationInfo > &&RelInfo) const
createMCSymbolizer - Create a target specific MCSymbolizer.
static bool getArchMatch(Triple::ArchType Arch)
const char * getBackendName() const
getBackendName - Get the backend name.
static void RegisterELFStreamer(Target &T, Target::ELFStreamerCtorTy Fn)
MCStreamer * createAsmStreamer(MCContext &Ctx, std::unique_ptr< formatted_raw_ostream > OS, bool IsVerboseAsm, bool UseDwarfDirectory, MCInstPrinter *InstPrint, std::unique_ptr< MCCodeEmitter > &&CE, std::unique_ptr< MCAsmBackend > &&TAB, bool ShowInst) const
bool operator!=(const iterator &x) const
MCStreamer *(*)(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&Emitter, bool RelaxAll, bool DWARFMustBeAtTheEnd) MachOStreamerCtorTy
static void RegisterMCSymbolizer(Target &T, Target::MCSymbolizerCtorTy Fn)
RegisterMCSymbolizer - Register an MCSymbolizer implementation for the given target.
RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
RegisterMCRegInfo - Helper template for registering a target register info implementation.
MCRelocationInfo * createMCRelocationInfo(StringRef TT, MCContext &Ctx) const
createMCRelocationInfo - Create a target specific MCRelocationInfo.
RegisterMCAsmInfoFn - Helper template for registering a target assembly info implementation.
static void RegisterNullTargetStreamer(Target &T, Target::NullTargetStreamerCtorTy Fn)
Generic interface to target specific assembler backends.
Definition: MCAsmBackend.h:38
RegisterMCAsmInfo - Helper template for registering a target assembly info implementation.
bool hasJIT() const
hasJIT - Check if this targets supports the just-in-time compilation.
MCStreamer *(*)(const Triple &T, MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&Emitter, bool RelaxAll) ELFStreamerCtorTy
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
MCTargetStreamer * createNullTargetStreamer(MCStreamer &S) const
static void RegisterMCRelocationInfo(Target &T, Target::MCRelocationInfoCtorTy Fn)
RegisterMCRelocationInfo - Register an MCRelocationInfo implementation for the given target...
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
MCInstPrinter *(*)(const Triple &T, unsigned SyntaxVariant, const MCAsmInfo &MAI, const MCInstrInfo &MII, const MCRegisterInfo &MRI) MCInstPrinterCtorTy
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:65
static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn)
RegisterAsmPrinter - Register an AsmPrinter implementation for the given target.
MCStreamer * createWasmStreamer(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&CE, bool RelaxAll)
MCInstrInfo *(*)() MCInstrInfoCtorFnTy
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:54
MCStreamer *(*)(const Triple &T, MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&Emitter, bool RelaxAll) WasmStreamerCtorTy
bool operator==(uint64_t V1, const APInt &V2)
Definition: APInt.h:2024
MCStreamer * createMachOStreamer(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&CE, bool RelaxAll, bool DWARFMustBeAtTheEnd, bool LabelSections=false)
const char *(* LLVMSymbolLookupCallback)(void *DisInfo, uint64_t ReferenceValue, uint64_t *ReferenceType, uint64_t ReferencePC, const char **ReferenceName)
The type for the symbol lookup function.
bool operator==(const iterator &x) const
RegisterMCCodeEmitter - Helper template for registering a target specific machine code emitter...
RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn)
MCStreamer *(*)(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&Emitter, bool RelaxAll, bool IncrementalLinkerCompatible) COFFStreamerCtorTy
RegisterMCInstrInfo - Helper template for registering a target instruction info implementation.