LLVM 22.0.0git
TargetRegistry.h
Go to the documentation of this file.
1//===- MC/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_MC_TARGETREGISTRY_H
19#define LLVM_MC_TARGETREGISTRY_H
20
22#include "llvm/ADT/StringRef.h"
30#include <cassert>
31#include <cstddef>
32#include <iterator>
33#include <memory>
34#include <optional>
35#include <string>
36
37namespace llvm {
38
39class AsmPrinter;
40class MCAsmBackend;
41class MCAsmInfo;
42class MCAsmParser;
43class MCCodeEmitter;
44class MCContext;
45class MCDisassembler;
46class MCInstPrinter;
47class MCInstrAnalysis;
48class MCInstrInfo;
49class MCObjectWriter;
50class MCRegisterInfo;
52class MCStreamer;
53class MCSubtargetInfo;
54class MCSymbolizer;
56class MCTargetOptions;
58class raw_ostream;
59class TargetMachine;
60class TargetOptions;
61namespace mca {
62class CustomBehaviour;
65struct SourceMgr;
66} // namespace mca
67
69// Takes ownership of \p TAB and \p CE.
70
71/// Create a machine code streamer which will print out assembly for the native
72/// target, suitable for compiling with a native assembler.
73///
74/// \param InstPrint - If given, the instruction printer to use. If not given
75/// the MCInst representation will be printed. This method takes ownership of
76/// InstPrint.
77///
78/// \param CE - If given, a code emitter to use to show the instruction
79/// encoding inline with the assembly. This method takes ownership of \p CE.
80///
81/// \param TAB - If given, a target asm backend to use to show the fixup
82/// information in conjunction with encoding information. This method takes
83/// ownership of \p TAB.
84///
85/// \param ShowInst - Whether to show the MCInst representation inline with
86/// the assembly.
88createAsmStreamer(MCContext &Ctx, std::unique_ptr<formatted_raw_ostream> OS,
89 std::unique_ptr<MCInstPrinter> InstPrint,
90 std::unique_ptr<MCCodeEmitter> CE,
91 std::unique_ptr<MCAsmBackend> TAB);
92
94 std::unique_ptr<MCAsmBackend> &&TAB,
95 std::unique_ptr<MCObjectWriter> &&OW,
96 std::unique_ptr<MCCodeEmitter> &&CE);
98 std::unique_ptr<MCAsmBackend> &&TAB,
99 std::unique_ptr<MCObjectWriter> &&OW,
100 std::unique_ptr<MCCodeEmitter> &&CE);
102 std::unique_ptr<MCAsmBackend> &&TAB,
103 std::unique_ptr<MCObjectWriter> &&OW,
104 std::unique_ptr<MCCodeEmitter> &&CE,
105 bool DWARFMustBeAtTheEnd,
106 bool LabelSections = false);
108 std::unique_ptr<MCAsmBackend> &&TAB,
109 std::unique_ptr<MCObjectWriter> &&OW,
110 std::unique_ptr<MCCodeEmitter> &&CE);
112 std::unique_ptr<MCAsmBackend> &&TAB,
113 std::unique_ptr<MCObjectWriter> &&OW,
114 std::unique_ptr<MCCodeEmitter> &&CE);
116createDXContainerStreamer(MCContext &Ctx, std::unique_ptr<MCAsmBackend> &&TAB,
117 std::unique_ptr<MCObjectWriter> &&OW,
118 std::unique_ptr<MCCodeEmitter> &&CE);
119
121 MCContext &Ctx);
122
124createMCSymbolizer(const Triple &TT, LLVMOpInfoCallback GetOpInfo,
125 LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo,
126 MCContext *Ctx, std::unique_ptr<MCRelocationInfo> &&RelInfo);
127
130 const MCInstrInfo &MCII);
131
134
137
138/// Target - Wrapper for Target specific information.
139///
140/// For registration purposes, this is a POD type so that targets can be
141/// registered without the use of static constructors.
142///
143/// Targets should implement a single global instance of this class (which
144/// will be zero initialized), and pass that instance to the TargetRegistry as
145/// part of their initialization.
146class Target {
147public:
148 friend struct TargetRegistry;
149
151
153 const Triple &TT,
154 const MCTargetOptions &Options);
156 bool PIC,
157 bool LargeCodeModel);
160 using MCRegInfoCtorFnTy = MCRegisterInfo *(*)(const Triple &TT);
162 StringRef CPU,
163 StringRef Features);
165 *(*)(const Target &T, const Triple &TT, StringRef CPU, StringRef Features,
166 const TargetOptions &Options, std::optional<Reloc::Model> RM,
167 std::optional<CodeModel::Model> CM, CodeGenOptLevel OL, bool JIT);
168 // If it weren't for layering issues (this header is in llvm/Support, but
169 // depends on MC?) this should take the Streamer by value rather than rvalue
170 // reference.
172 TargetMachine &TM, std::unique_ptr<MCStreamer> &&Streamer);
174 const MCSubtargetInfo &STI,
175 const MCRegisterInfo &MRI,
176 const MCTargetOptions &Options);
178 const MCSubtargetInfo &STI, MCAsmParser &P, const MCInstrInfo &MII,
179 const MCTargetOptions &Options);
181 const MCSubtargetInfo &STI,
182 MCContext &Ctx);
184 unsigned SyntaxVariant,
185 const MCAsmInfo &MAI,
186 const MCInstrInfo &MII,
187 const MCRegisterInfo &MRI);
189 MCContext &Ctx);
191 MCStreamer *(*)(const Triple &T, MCContext &Ctx,
192 std::unique_ptr<MCAsmBackend> &&TAB,
193 std::unique_ptr<MCObjectWriter> &&OW,
194 std::unique_ptr<MCCodeEmitter> &&Emitter);
196 MCStreamer *(*)(MCContext &Ctx, std::unique_ptr<MCAsmBackend> &&TAB,
197 std::unique_ptr<MCObjectWriter> &&OW,
198 std::unique_ptr<MCCodeEmitter> &&Emitter);
200 MCStreamer *(*)(MCContext &Ctx, std::unique_ptr<MCAsmBackend> &&TAB,
201 std::unique_ptr<MCObjectWriter> &&OW,
202 std::unique_ptr<MCCodeEmitter> &&Emitter);
204 MCStreamer *(*)(const Triple &T, MCContext &Ctx,
205 std::unique_ptr<MCAsmBackend> &&TAB,
206 std::unique_ptr<MCObjectWriter> &&OW,
207 std::unique_ptr<MCCodeEmitter> &&Emitter);
208
212 MCInstPrinter *InstPrint);
214 *(*)(MCContext & Ctx, std::unique_ptr<formatted_raw_ostream> OS,
215 std::unique_ptr<MCInstPrinter> IP, std::unique_ptr<MCCodeEmitter> CE,
216 std::unique_ptr<MCAsmBackend> TAB);
218 MCTargetStreamer *(*)(MCStreamer &S, const MCSubtargetInfo &STI);
220 MCContext &Ctx);
222 MCSymbolizer *(*)(const Triple &TT, LLVMOpInfoCallback GetOpInfo,
223 LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo,
224 MCContext *Ctx,
225 std::unique_ptr<MCRelocationInfo> &&RelInfo);
226
229 const mca::SourceMgr &SrcMgr,
230 const MCInstrInfo &MCII);
231
234 const MCInstrInfo &MCII);
235
238 const MCInstrInfo &MCII);
239
240private:
241 /// Next - The next registered target in the linked list, maintained by the
242 /// TargetRegistry.
243 Target *Next;
244
245 /// The target function for checking if an architecture is supported.
246 ArchMatchFnTy ArchMatchFn;
247
248 /// Name - The target name.
249 const char *Name;
250
251 /// ShortDesc - A short description of the target.
252 const char *ShortDesc;
253
254 /// BackendName - The name of the backend implementation. This must match the
255 /// name of the 'def X : Target ...' in TableGen.
256 const char *BackendName;
257
258 /// HasJIT - Whether this target supports the JIT.
259 bool HasJIT;
260
261 /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
262 /// registered.
263 MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
264
265 /// Constructor function for this target's MCObjectFileInfo, if registered.
266 MCObjectFileInfoCtorFnTy MCObjectFileInfoCtorFn;
267
268 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
269 /// if registered.
270 MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
271
272 /// MCInstrAnalysisCtorFn - Constructor function for this target's
273 /// MCInstrAnalysis, if registered.
274 MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
275
276 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
277 /// if registered.
278 MCRegInfoCtorFnTy MCRegInfoCtorFn;
279
280 /// MCSubtargetInfoCtorFn - Constructor function for this target's
281 /// MCSubtargetInfo, if registered.
282 MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
283
284 /// TargetMachineCtorFn - Construction function for this target's
285 /// TargetMachine, if registered.
286 TargetMachineCtorTy TargetMachineCtorFn;
287
288 /// MCAsmBackendCtorFn - Construction function for this target's
289 /// MCAsmBackend, if registered.
290 MCAsmBackendCtorTy MCAsmBackendCtorFn;
291
292 /// MCAsmParserCtorFn - Construction function for this target's
293 /// MCTargetAsmParser, if registered.
294 MCAsmParserCtorTy MCAsmParserCtorFn;
295
296 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
297 /// if registered.
298 AsmPrinterCtorTy AsmPrinterCtorFn;
299
300 /// MCDisassemblerCtorFn - Construction function for this target's
301 /// MCDisassembler, if registered.
302 MCDisassemblerCtorTy MCDisassemblerCtorFn;
303
304 /// MCInstPrinterCtorFn - Construction function for this target's
305 /// MCInstPrinter, if registered.
306 MCInstPrinterCtorTy MCInstPrinterCtorFn;
307
308 /// MCCodeEmitterCtorFn - Construction function for this target's
309 /// CodeEmitter, if registered.
310 MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
311
312 // Construction functions for the various object formats, if registered.
313 COFFStreamerCtorTy COFFStreamerCtorFn = nullptr;
314 MachOStreamerCtorTy MachOStreamerCtorFn = nullptr;
315 ELFStreamerCtorTy ELFStreamerCtorFn = nullptr;
316 XCOFFStreamerCtorTy XCOFFStreamerCtorFn = nullptr;
317
318 /// Construction function for this target's null TargetStreamer, if
319 /// registered (default = nullptr).
320 NullTargetStreamerCtorTy NullTargetStreamerCtorFn = nullptr;
321
322 /// Construction function for this target's asm TargetStreamer, if
323 /// registered (default = nullptr).
324 AsmTargetStreamerCtorTy AsmTargetStreamerCtorFn = nullptr;
325
326 /// Construction function for this target's AsmStreamer, if
327 /// registered (default = nullptr).
328 AsmStreamerCtorTy AsmStreamerCtorFn = nullptr;
329
330 /// Construction function for this target's obj TargetStreamer, if
331 /// registered (default = nullptr).
332 ObjectTargetStreamerCtorTy ObjectTargetStreamerCtorFn = nullptr;
333
334 /// MCRelocationInfoCtorFn - Construction function for this target's
335 /// MCRelocationInfo, if registered (default = llvm::createMCRelocationInfo)
336 MCRelocationInfoCtorTy MCRelocationInfoCtorFn = nullptr;
337
338 /// MCSymbolizerCtorFn - Construction function for this target's
339 /// MCSymbolizer, if registered (default = llvm::createMCSymbolizer)
340 MCSymbolizerCtorTy MCSymbolizerCtorFn = nullptr;
341
342 /// CustomBehaviourCtorFn - Construction function for this target's
343 /// CustomBehaviour, if registered (default = nullptr).
344 CustomBehaviourCtorTy CustomBehaviourCtorFn = nullptr;
345
346 /// InstrPostProcessCtorFn - Construction function for this target's
347 /// InstrPostProcess, if registered (default = nullptr).
348 InstrPostProcessCtorTy InstrPostProcessCtorFn = nullptr;
349
350 /// InstrumentManagerCtorFn - Construction function for this target's
351 /// InstrumentManager, if registered (default = nullptr).
352 InstrumentManagerCtorTy InstrumentManagerCtorFn = nullptr;
353
354public:
355 Target() = default;
356
357 /// @name Target Information
358 /// @{
359
360 // getNext - Return the next registered target.
361 const Target *getNext() const { return Next; }
362
363 /// getName - Get the target name.
364 const char *getName() const { return Name; }
365
366 /// getShortDescription - Get a short description of the target.
367 const char *getShortDescription() const { return ShortDesc; }
368
369 /// getBackendName - Get the backend name.
370 const char *getBackendName() const { return BackendName; }
371
372 /// @}
373 /// @name Feature Predicates
374 /// @{
375
376 /// hasJIT - Check if this targets supports the just-in-time compilation.
377 bool hasJIT() const { return HasJIT; }
378
379 /// hasTargetMachine - Check if this target supports code generation.
380 bool hasTargetMachine() const { return TargetMachineCtorFn != nullptr; }
381
382 /// hasMCAsmBackend - Check if this target supports .o generation.
383 bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != nullptr; }
384
385 /// hasMCAsmParser - Check if this target supports assembly parsing.
386 bool hasMCAsmParser() const { return MCAsmParserCtorFn != nullptr; }
387
388 /// @}
389 /// @name Feature Constructors
390 /// @{
391
392 // TODO(boomanaiden154): Remove this function after LLVM 22 branches.
393 [[deprecated("Use overload accepting Triple instead")]]
395 const MCTargetOptions &Options) const {
396 if (!MCAsmInfoCtorFn)
397 return nullptr;
398 return MCAsmInfoCtorFn(MRI, Triple(TheTriple), Options);
399 }
400
401 /// Create a MCAsmInfo implementation for the specified
402 /// target triple.
403 ///
404 /// \param TheTriple This argument is used to determine the target machine
405 /// feature set; it should always be provided. Generally this should be
406 /// either the target triple from the module, or the target triple of the
407 /// host if that does not exist.
409 const MCTargetOptions &Options) const {
410 if (!MCAsmInfoCtorFn)
411 return nullptr;
412 return MCAsmInfoCtorFn(MRI, TheTriple, Options);
413 }
414
415 /// Create a MCObjectFileInfo implementation for the specified target
416 /// triple.
417 ///
419 bool LargeCodeModel = false) const {
420 if (!MCObjectFileInfoCtorFn) {
422 MOFI->initMCObjectFileInfo(Ctx, PIC, LargeCodeModel);
423 return MOFI;
424 }
425 return MCObjectFileInfoCtorFn(Ctx, PIC, LargeCodeModel);
426 }
427
428 /// createMCInstrInfo - Create a MCInstrInfo implementation.
429 ///
431 if (!MCInstrInfoCtorFn)
432 return nullptr;
433 return MCInstrInfoCtorFn();
434 }
435
436 /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
437 ///
439 if (!MCInstrAnalysisCtorFn)
440 return nullptr;
441 return MCInstrAnalysisCtorFn(Info);
442 }
443
444 // TODO(boomanaiden154): Remove this function after LLVM 22 branches.
445 [[deprecated("Use overload accepting Triple instead")]]
447 if (!MCRegInfoCtorFn)
448 return nullptr;
449 return MCRegInfoCtorFn(Triple(TT));
450 }
451
452 /// Create a MCRegisterInfo implementation.
454 if (!MCRegInfoCtorFn)
455 return nullptr;
456 return MCRegInfoCtorFn(TT);
457 }
458
459 // TODO(boomanaiden154): Remove this function after LLVM 22 branches.
460 [[deprecated("Use overload accepting Triple instead")]]
462 StringRef Features) const {
463 if (!MCSubtargetInfoCtorFn)
464 return nullptr;
465 return MCSubtargetInfoCtorFn(Triple(TheTriple), CPU, Features);
466 }
467
468 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
469 ///
470 /// \param TheTriple This argument is used to determine the target machine
471 /// feature set; it should always be provided. Generally this should be
472 /// either the target triple from the module, or the target triple of the
473 /// host if that does not exist.
474 /// \param CPU This specifies the name of the target CPU.
475 /// \param Features This specifies the string representation of the
476 /// additional target features.
478 StringRef Features) const {
479 if (!MCSubtargetInfoCtorFn)
480 return nullptr;
481 return MCSubtargetInfoCtorFn(TheTriple, CPU, Features);
482 }
483
484 /// createTargetMachine - Create a target specific machine implementation
485 /// for the specified \p Triple.
486 ///
487 /// \param TT This argument is used to determine the target machine
488 /// feature set; it should always be provided. Generally this should be
489 /// either the target triple from the module, or the target triple of the
490 /// host if that does not exist.
492 const Triple &TT, StringRef CPU, StringRef Features,
493 const TargetOptions &Options, std::optional<Reloc::Model> RM,
494 std::optional<CodeModel::Model> CM = std::nullopt,
495 CodeGenOptLevel OL = CodeGenOptLevel::Default, bool JIT = false) const {
496 if (!TargetMachineCtorFn)
497 return nullptr;
498 return TargetMachineCtorFn(*this, TT, CPU, Features, Options, RM, CM, OL,
499 JIT);
500 }
501
502 /// createMCAsmBackend - Create a target specific assembly parser.
504 const MCRegisterInfo &MRI,
505 const MCTargetOptions &Options) const {
506 if (!MCAsmBackendCtorFn)
507 return nullptr;
508 return MCAsmBackendCtorFn(*this, STI, MRI, Options);
509 }
510
511 /// createMCAsmParser - Create a target specific assembly parser.
512 ///
513 /// \param Parser The target independent parser implementation to use for
514 /// parsing and lexing.
516 MCAsmParser &Parser,
517 const MCInstrInfo &MII,
518 const MCTargetOptions &Options) const {
519 if (!MCAsmParserCtorFn)
520 return nullptr;
521 return MCAsmParserCtorFn(STI, Parser, MII, Options);
522 }
523
524 /// createAsmPrinter - Create a target specific assembly printer pass. This
525 /// takes ownership of the MCStreamer object.
527 std::unique_ptr<MCStreamer> &&Streamer) const {
528 if (!AsmPrinterCtorFn)
529 return nullptr;
530 return AsmPrinterCtorFn(TM, std::move(Streamer));
531 }
532
534 MCContext &Ctx) const {
535 if (!MCDisassemblerCtorFn)
536 return nullptr;
537 return MCDisassemblerCtorFn(*this, STI, Ctx);
538 }
539
540 MCInstPrinter *createMCInstPrinter(const Triple &T, unsigned SyntaxVariant,
541 const MCAsmInfo &MAI,
542 const MCInstrInfo &MII,
543 const MCRegisterInfo &MRI) const {
544 if (!MCInstPrinterCtorFn)
545 return nullptr;
546 return MCInstPrinterCtorFn(T, SyntaxVariant, MAI, MII, MRI);
547 }
548
549 /// createMCCodeEmitter - Create a target specific code emitter.
551 MCContext &Ctx) const {
552 if (!MCCodeEmitterCtorFn)
553 return nullptr;
554 return MCCodeEmitterCtorFn(II, Ctx);
555 }
556
557 /// Create a target specific MCStreamer.
558 ///
559 /// \param T The target triple.
560 /// \param Ctx The target context.
561 /// \param TAB The target assembler backend object. Takes ownership.
562 /// \param OW The stream object.
563 /// \param Emitter The target independent assembler object.Takes ownership.
565 const Triple &T, MCContext &Ctx, std::unique_ptr<MCAsmBackend> TAB,
566 std::unique_ptr<MCObjectWriter> OW,
567 std::unique_ptr<MCCodeEmitter> Emitter, const MCSubtargetInfo &STI) const;
568
570 createAsmStreamer(MCContext &Ctx, std::unique_ptr<formatted_raw_ostream> OS,
571 std::unique_ptr<MCInstPrinter> IP,
572 std::unique_ptr<MCCodeEmitter> CE,
573 std::unique_ptr<MCAsmBackend> TAB) const;
574
577 MCInstPrinter *InstPrint) const {
578 if (AsmTargetStreamerCtorFn)
579 return AsmTargetStreamerCtorFn(S, OS, InstPrint);
580 return nullptr;
581 }
582
586 return S;
587 }
588
590 if (NullTargetStreamerCtorFn)
591 return NullTargetStreamerCtorFn(S);
592 return nullptr;
593 }
594
595 // TODO(boomanaiden154): Remove this function after LLVM 22 branches.
596 [[deprecated("Use overload accepting Triple instead")]]
600
601 /// createMCRelocationInfo - Create a target specific MCRelocationInfo.
602 ///
603 /// \param TT The target triple.
604 /// \param Ctx The target context.
606 MCContext &Ctx) const {
607 MCRelocationInfoCtorTy Fn = MCRelocationInfoCtorFn
608 ? MCRelocationInfoCtorFn
610 return Fn(TT, Ctx);
611 }
612
613 // TODO(boomanaiden154): Remove this function after LLVM 22 branches.
614 [[deprecated("Use overload accepting Triple instead")]]
617 LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo,
618 MCContext *Ctx,
619 std::unique_ptr<MCRelocationInfo> &&RelInfo) const {
620 return createMCSymbolizer(Triple(TT), GetOpInfo, SymbolLookUp, DisInfo, Ctx,
621 std::move(RelInfo));
622 }
623
624 /// createMCSymbolizer - Create a target specific MCSymbolizer.
625 ///
626 /// \param TT The target triple.
627 /// \param GetOpInfo The function to get the symbolic information for
628 /// operands.
629 /// \param SymbolLookUp The function to lookup a symbol name.
630 /// \param DisInfo The pointer to the block of symbolic information for above
631 /// call
632 /// back.
633 /// \param Ctx The target context.
634 /// \param RelInfo The relocation information for this target. Takes
635 /// ownership.
638 LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo,
639 MCContext *Ctx,
640 std::unique_ptr<MCRelocationInfo> &&RelInfo) const {
642 MCSymbolizerCtorFn ? MCSymbolizerCtorFn : llvm::createMCSymbolizer;
643 return Fn(TT, GetOpInfo, SymbolLookUp, DisInfo, Ctx, std::move(RelInfo));
644 }
645
646 /// createCustomBehaviour - Create a target specific CustomBehaviour.
647 /// This class is used by llvm-mca and requires backend functionality.
649 const mca::SourceMgr &SrcMgr,
650 const MCInstrInfo &MCII) const {
651 if (CustomBehaviourCtorFn)
652 return CustomBehaviourCtorFn(STI, SrcMgr, MCII);
653 return nullptr;
654 }
655
656 /// createInstrPostProcess - Create a target specific InstrPostProcess.
657 /// This class is used by llvm-mca and requires backend functionality.
659 const MCInstrInfo &MCII) const {
660 if (InstrPostProcessCtorFn)
661 return InstrPostProcessCtorFn(STI, MCII);
662 return nullptr;
663 }
664
665 /// createInstrumentManager - Create a target specific
666 /// InstrumentManager. This class is used by llvm-mca and requires
667 /// backend functionality.
670 const MCInstrInfo &MCII) const {
671 if (InstrumentManagerCtorFn)
672 return InstrumentManagerCtorFn(STI, MCII);
673 return nullptr;
674 }
675
676 /// @}
677};
678
679/// TargetRegistry - Generic interface to target specific features.
681 // FIXME: Make this a namespace, probably just move all the Register*
682 // functions into Target (currently they all just set members on the Target
683 // anyway, and Target friends this class so those functions can...
684 // function).
685 TargetRegistry() = delete;
686
687 class iterator {
688 friend struct TargetRegistry;
689
690 const Target *Current = nullptr;
691
692 explicit iterator(Target *T) : Current(T) {}
693
694 public:
695 using iterator_category = std::forward_iterator_tag;
697 using difference_type = std::ptrdiff_t;
700
701 iterator() = default;
702
703 bool operator==(const iterator &x) const { return Current == x.Current; }
704 bool operator!=(const iterator &x) const { return !operator==(x); }
705
706 // Iterator traversal: forward iteration only
707 iterator &operator++() { // Preincrement
708 assert(Current && "Cannot increment end iterator!");
709 Current = Current->getNext();
710 return *this;
711 }
712 iterator operator++(int) { // Postincrement
713 iterator tmp = *this;
714 ++*this;
715 return tmp;
716 }
717
718 const Target &operator*() const {
719 assert(Current && "Cannot dereference end iterator!");
720 return *Current;
721 }
722
723 const Target *operator->() const { return &operator*(); }
724 };
725
726 /// printRegisteredTargetsForVersion - Print the registered targets
727 /// appropriately for inclusion in a tool's version output.
729
730 /// @name Registry Access
731 /// @{
732
734
735 /// lookupTarget - Lookup a target based on a target triple.
736 ///
737 /// \param TripleStr - The triple to use for finding a target.
738 /// \param Error - On failure, an error string describing why no target was
739 /// found.
740 // TODO: Drop this in favor of the method accepting Triple.
741 static const Target *lookupTarget(StringRef TripleStr, std::string &Error) {
742 return lookupTarget(Triple(TripleStr), Error);
743 }
744
745 /// lookupTarget - Lookup a target based on a target triple.
746 ///
747 /// \param Triple - The triple to use for finding a target.
748 /// \param Error - On failure, an error string describing why no target was
749 /// found.
750 LLVM_ABI static const Target *lookupTarget(const Triple &TheTriple,
751 std::string &Error);
752
753 /// lookupTarget - Lookup a target based on an architecture name
754 /// and a target triple. If the architecture name is non-empty,
755 /// then the lookup is done by architecture. Otherwise, the target
756 /// triple is used.
757 ///
758 /// \param ArchName - The architecture to use for finding a target.
759 /// \param TheTriple - The triple to use for finding a target. The
760 /// triple is updated with canonical architecture name if a lookup
761 /// by architecture is done.
762 /// \param Error - On failure, an error string describing why no target was
763 /// found.
764 LLVM_ABI static const Target *
765 lookupTarget(StringRef ArchName, Triple &TheTriple, std::string &Error);
766
767 /// @}
768 /// @name Target Registration
769 /// @{
770
771 /// RegisterTarget - Register the given target. Attempts to register a
772 /// target which has already been registered will be ignored.
773 ///
774 /// Clients are responsible for ensuring that registration doesn't occur
775 /// while another thread is attempting to access the registry. Typically
776 /// this is done by initializing all targets at program startup.
777 ///
778 /// @param T - The target being registered.
779 /// @param Name - The target name. This should be a static string.
780 /// @param ShortDesc - A short target description. This should be a static
781 /// string.
782 /// @param BackendName - The name of the backend. This should be a static
783 /// string that is the same for all targets that share a backend
784 /// implementation and must match the name used in the 'def X : Target ...' in
785 /// TableGen.
786 /// @param ArchMatchFn - The arch match checking function for this target.
787 /// @param HasJIT - Whether the target supports JIT code
788 /// generation.
789 LLVM_ABI static void RegisterTarget(Target &T, const char *Name,
790 const char *ShortDesc,
791 const char *BackendName,
792 Target::ArchMatchFnTy ArchMatchFn,
793 bool HasJIT = false);
794
795 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
796 /// given 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 a MCAsmInfo for the target.
805 T.MCAsmInfoCtorFn = Fn;
806 }
807
808 /// Register a MCObjectFileInfo implementation for the given target.
809 ///
810 /// Clients are responsible for ensuring that registration doesn't occur
811 /// while another thread is attempting to access the registry. Typically
812 /// this is done by initializing all targets at program startup.
813 ///
814 /// @param T - The target being registered.
815 /// @param Fn - A function to construct a MCObjectFileInfo for the target.
818 T.MCObjectFileInfoCtorFn = Fn;
819 }
820
821 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
822 /// given target.
823 ///
824 /// Clients are responsible for ensuring that registration doesn't occur
825 /// while another thread is attempting to access the registry. Typically
826 /// this is done by initializing all targets at program startup.
827 ///
828 /// @param T - The target being registered.
829 /// @param Fn - A function to construct a MCInstrInfo for the target.
831 T.MCInstrInfoCtorFn = Fn;
832 }
833
834 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
835 /// the given target.
838 T.MCInstrAnalysisCtorFn = Fn;
839 }
840
841 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
842 /// given target.
843 ///
844 /// Clients are responsible for ensuring that registration doesn't occur
845 /// while another thread is attempting to access the registry. Typically
846 /// this is done by initializing all targets at program startup.
847 ///
848 /// @param T - The target being registered.
849 /// @param Fn - A function to construct a MCRegisterInfo for the target.
851 T.MCRegInfoCtorFn = Fn;
852 }
853
854 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
855 /// the given target.
856 ///
857 /// Clients are responsible for ensuring that registration doesn't occur
858 /// while another thread is attempting to access the registry. Typically
859 /// this is done by initializing all targets at program startup.
860 ///
861 /// @param T - The target being registered.
862 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
865 T.MCSubtargetInfoCtorFn = Fn;
866 }
867
868 /// RegisterTargetMachine - Register a TargetMachine implementation for the
869 /// given target.
870 ///
871 /// Clients are responsible for ensuring that registration doesn't occur
872 /// while another thread is attempting to access the registry. Typically
873 /// this is done by initializing all targets at program startup.
874 ///
875 /// @param T - The target being registered.
876 /// @param Fn - A function to construct a TargetMachine for the target.
878 T.TargetMachineCtorFn = Fn;
879 }
880
881 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
882 /// given target.
883 ///
884 /// Clients are responsible for ensuring that registration doesn't occur
885 /// while another thread is attempting to access the registry. Typically
886 /// this is done by initializing all targets at program startup.
887 ///
888 /// @param T - The target being registered.
889 /// @param Fn - A function to construct an AsmBackend for the target.
891 T.MCAsmBackendCtorFn = Fn;
892 }
893
894 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
895 /// 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 MCTargetAsmParser for the target.
904 T.MCAsmParserCtorFn = Fn;
905 }
906
907 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
908 /// target.
909 ///
910 /// Clients are responsible for ensuring that registration doesn't occur
911 /// while another thread is attempting to access the registry. Typically
912 /// this is done by initializing all targets at program startup.
913 ///
914 /// @param T - The target being registered.
915 /// @param Fn - A function to construct an AsmPrinter for the target.
917 T.AsmPrinterCtorFn = Fn;
918 }
919
920 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
921 /// the given target.
922 ///
923 /// Clients are responsible for ensuring that registration doesn't occur
924 /// while another thread is attempting to access the registry. Typically
925 /// this is done by initializing all targets at program startup.
926 ///
927 /// @param T - The target being registered.
928 /// @param Fn - A function to construct an MCDisassembler for the target.
931 T.MCDisassemblerCtorFn = Fn;
932 }
933
934 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
935 /// given target.
936 ///
937 /// Clients are responsible for ensuring that registration doesn't occur
938 /// while another thread is attempting to access the registry. Typically
939 /// this is done by initializing all targets at program startup.
940 ///
941 /// @param T - The target being registered.
942 /// @param Fn - A function to construct an MCInstPrinter for the target.
944 T.MCInstPrinterCtorFn = Fn;
945 }
946
947 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
948 /// given target.
949 ///
950 /// Clients are responsible for ensuring that registration doesn't occur
951 /// while another thread is attempting to access the registry. Typically
952 /// this is done by initializing all targets at program startup.
953 ///
954 /// @param T - The target being registered.
955 /// @param Fn - A function to construct an MCCodeEmitter for the target.
957 T.MCCodeEmitterCtorFn = Fn;
958 }
959
961 T.COFFStreamerCtorFn = Fn;
962 }
963
965 T.MachOStreamerCtorFn = Fn;
966 }
967
969 T.ELFStreamerCtorFn = Fn;
970 }
971
973 T.XCOFFStreamerCtorFn = Fn;
974 }
975
978 T.NullTargetStreamerCtorFn = Fn;
979 }
980
982 T.AsmStreamerCtorFn = Fn;
983 }
984
987 T.AsmTargetStreamerCtorFn = Fn;
988 }
989
990 static void
993 T.ObjectTargetStreamerCtorFn = Fn;
994 }
995
996 /// RegisterMCRelocationInfo - Register an MCRelocationInfo
997 /// implementation for the given target.
998 ///
999 /// Clients are responsible for ensuring that registration doesn't occur
1000 /// while another thread is attempting to access the registry. Typically
1001 /// this is done by initializing all targets at program startup.
1002 ///
1003 /// @param T - The target being registered.
1004 /// @param Fn - A function to construct an MCRelocationInfo for the target.
1007 T.MCRelocationInfoCtorFn = Fn;
1008 }
1009
1010 /// RegisterMCSymbolizer - Register an MCSymbolizer
1011 /// implementation for the given target.
1012 ///
1013 /// Clients are responsible for ensuring that registration doesn't occur
1014 /// while another thread is attempting to access the registry. Typically
1015 /// this is done by initializing all targets at program startup.
1016 ///
1017 /// @param T - The target being registered.
1018 /// @param Fn - A function to construct an MCSymbolizer for the target.
1020 T.MCSymbolizerCtorFn = Fn;
1021 }
1022
1023 /// RegisterCustomBehaviour - Register a CustomBehaviour
1024 /// implementation for the given target.
1025 ///
1026 /// Clients are responsible for ensuring that registration doesn't occur
1027 /// while another thread is attempting to access the registry. Typically
1028 /// this is done by initializing all targets at program startup.
1029 ///
1030 /// @param T - The target being registered.
1031 /// @param Fn - A function to construct a CustomBehaviour for the target.
1034 T.CustomBehaviourCtorFn = Fn;
1035 }
1036
1037 /// RegisterInstrPostProcess - Register an InstrPostProcess
1038 /// implementation for the given target.
1039 ///
1040 /// Clients are responsible for ensuring that registration doesn't occur
1041 /// while another thread is attempting to access the registry. Typically
1042 /// this is done by initializing all targets at program startup.
1043 ///
1044 /// @param T - The target being registered.
1045 /// @param Fn - A function to construct an InstrPostProcess for the target.
1048 T.InstrPostProcessCtorFn = Fn;
1049 }
1050
1051 /// RegisterInstrumentManager - Register an InstrumentManager
1052 /// implementation for the given target.
1053 ///
1054 /// Clients are responsible for ensuring that registration doesn't occur
1055 /// while another thread is attempting to access the registry. Typically
1056 /// this is done by initializing all targets at program startup.
1057 ///
1058 /// @param T - The target being registered.
1059 /// @param Fn - A function to construct an InstrumentManager for the
1060 /// target.
1063 T.InstrumentManagerCtorFn = Fn;
1064 }
1065
1066 /// @}
1067};
1068
1069//===--------------------------------------------------------------------===//
1070
1071/// RegisterTarget - Helper template for registering a target, for use in the
1072/// target's initialization function. Usage:
1073///
1074///
1075/// Target &getTheFooTarget() { // The global target instance.
1076/// static Target TheFooTarget;
1077/// return TheFooTarget;
1078/// }
1079/// extern "C" void LLVMInitializeFooTargetInfo() {
1080/// RegisterTarget<Triple::foo> X(getTheFooTarget(), "foo", "Foo
1081/// description", "Foo" /* Backend Name */);
1082/// }
1083template <Triple::ArchType TargetArchType = Triple::UnknownArch,
1084 bool HasJIT = false>
1086 RegisterTarget(Target &T, const char *Name, const char *Desc,
1087 const char *BackendName) {
1088 TargetRegistry::RegisterTarget(T, Name, Desc, BackendName, &getArchMatch,
1089 HasJIT);
1090 }
1091
1092 static bool getArchMatch(Triple::ArchType Arch) {
1093 return Arch == TargetArchType;
1094 }
1095};
1096
1097/// RegisterMCAsmInfo - Helper template for registering a target assembly info
1098/// implementation. This invokes the static "Create" method on the class to
1099/// actually do the construction. Usage:
1100///
1101/// extern "C" void LLVMInitializeFooTarget() {
1102/// extern Target TheFooTarget;
1103/// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
1104/// }
1105template <class MCAsmInfoImpl> struct RegisterMCAsmInfo {
1109
1110private:
1111 static MCAsmInfo *Allocator(const MCRegisterInfo & /*MRI*/, const Triple &TT,
1112 const MCTargetOptions &Options) {
1113 return new MCAsmInfoImpl(TT, Options);
1114 }
1115};
1116
1117/// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
1118/// implementation. This invokes the specified function to do the
1119/// construction. Usage:
1120///
1121/// extern "C" void LLVMInitializeFooTarget() {
1122/// extern Target TheFooTarget;
1123/// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
1124/// }
1130
1131/// Helper template for registering a target object file info implementation.
1132/// This invokes the static "Create" method on the class to actually do the
1133/// construction. Usage:
1134///
1135/// extern "C" void LLVMInitializeFooTarget() {
1136/// extern Target TheFooTarget;
1137/// RegisterMCObjectFileInfo<FooMCObjectFileInfo> X(TheFooTarget);
1138/// }
1139template <class MCObjectFileInfoImpl> struct RegisterMCObjectFileInfo {
1143
1144private:
1145 static MCObjectFileInfo *Allocator(MCContext &Ctx, bool PIC,
1146 bool LargeCodeModel = false) {
1147 return new MCObjectFileInfoImpl(Ctx, PIC, LargeCodeModel);
1148 }
1149};
1150
1151/// Helper template for registering a target object file info implementation.
1152/// This invokes the specified function to do the construction. Usage:
1153///
1154/// extern "C" void LLVMInitializeFooTarget() {
1155/// extern Target TheFooTarget;
1156/// RegisterMCObjectFileInfoFn X(TheFooTarget, TheFunction);
1157/// }
1163
1164/// RegisterMCInstrInfo - Helper template for registering a target instruction
1165/// info implementation. This invokes the static "Create" method on the class
1166/// to actually do the construction. Usage:
1167///
1168/// extern "C" void LLVMInitializeFooTarget() {
1169/// extern Target TheFooTarget;
1170/// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
1171/// }
1172template <class MCInstrInfoImpl> struct RegisterMCInstrInfo {
1176
1177private:
1178 static MCInstrInfo *Allocator() { return new MCInstrInfoImpl(); }
1179};
1180
1181/// RegisterMCInstrInfoFn - Helper template for registering a target
1182/// instruction info implementation. This invokes the specified function to
1183/// do the construction. Usage:
1184///
1185/// extern "C" void LLVMInitializeFooTarget() {
1186/// extern Target TheFooTarget;
1187/// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
1188/// }
1194
1195/// RegisterMCInstrAnalysis - Helper template for registering a target
1196/// instruction analyzer implementation. This invokes the static "Create"
1197/// method on the class to actually do the construction. Usage:
1198///
1199/// extern "C" void LLVMInitializeFooTarget() {
1200/// extern Target TheFooTarget;
1201/// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
1202/// }
1203template <class MCInstrAnalysisImpl> struct RegisterMCInstrAnalysis {
1207
1208private:
1209 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
1210 return new MCInstrAnalysisImpl(Info);
1211 }
1212};
1213
1214/// RegisterMCInstrAnalysisFn - Helper template for registering a target
1215/// instruction analyzer implementation. This invokes the specified function
1216/// to do the construction. Usage:
1217///
1218/// extern "C" void LLVMInitializeFooTarget() {
1219/// extern Target TheFooTarget;
1220/// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
1221/// }
1227
1228/// RegisterMCRegInfo - Helper template for registering a target register info
1229/// implementation. This invokes the static "Create" method on the class to
1230/// actually do the construction. Usage:
1231///
1232/// extern "C" void LLVMInitializeFooTarget() {
1233/// extern Target TheFooTarget;
1234/// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
1235/// }
1236template <class MCRegisterInfoImpl> struct RegisterMCRegInfo {
1240
1241private:
1242 static MCRegisterInfo *Allocator(const Triple & /*TT*/) {
1243 return new MCRegisterInfoImpl();
1244 }
1245};
1246
1247/// RegisterMCRegInfoFn - Helper template for registering a target register
1248/// info implementation. This invokes the specified function to do the
1249/// construction. Usage:
1250///
1251/// extern "C" void LLVMInitializeFooTarget() {
1252/// extern Target TheFooTarget;
1253/// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
1254/// }
1260
1261/// RegisterMCSubtargetInfo - Helper template for registering a target
1262/// subtarget info implementation. This invokes the static "Create" method
1263/// on the class to actually do the construction. Usage:
1264///
1265/// extern "C" void LLVMInitializeFooTarget() {
1266/// extern Target TheFooTarget;
1267/// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
1268/// }
1269template <class MCSubtargetInfoImpl> struct RegisterMCSubtargetInfo {
1273
1274private:
1275 static MCSubtargetInfo *Allocator(const Triple & /*TT*/, StringRef /*CPU*/,
1276 StringRef /*FS*/) {
1277 return new MCSubtargetInfoImpl();
1278 }
1279};
1280
1281/// RegisterMCSubtargetInfoFn - Helper template for registering a target
1282/// subtarget info implementation. This invokes the specified function to
1283/// do the construction. Usage:
1284///
1285/// extern "C" void LLVMInitializeFooTarget() {
1286/// extern Target TheFooTarget;
1287/// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1288/// }
1294
1295/// RegisterTargetMachine - Helper template for registering a target machine
1296/// implementation, for use in the target machine initialization
1297/// function. Usage:
1298///
1299/// extern "C" void LLVMInitializeFooTarget() {
1300/// extern Target TheFooTarget;
1301/// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1302/// }
1303template <class TargetMachineImpl> struct RegisterTargetMachine {
1307
1308private:
1309 static TargetMachine *
1310 Allocator(const Target &T, const Triple &TT, StringRef CPU, StringRef FS,
1311 const TargetOptions &Options, std::optional<Reloc::Model> RM,
1312 std::optional<CodeModel::Model> CM, CodeGenOptLevel OL, bool JIT) {
1313 return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL, JIT);
1314 }
1315};
1316
1317/// RegisterMCAsmBackend - Helper template for registering a target specific
1318/// assembler backend. Usage:
1319///
1320/// extern "C" void LLVMInitializeFooMCAsmBackend() {
1321/// extern Target TheFooTarget;
1322/// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1323/// }
1324template <class MCAsmBackendImpl> struct RegisterMCAsmBackend {
1328
1329private:
1330 static MCAsmBackend *Allocator(const Target &T, const MCSubtargetInfo &STI,
1331 const MCRegisterInfo &MRI,
1332 const MCTargetOptions &Options) {
1333 return new MCAsmBackendImpl(T, STI, MRI);
1334 }
1335};
1336
1337/// RegisterMCAsmParser - Helper template for registering a target specific
1338/// assembly parser, for use in the target machine initialization
1339/// function. Usage:
1340///
1341/// extern "C" void LLVMInitializeFooMCAsmParser() {
1342/// extern Target TheFooTarget;
1343/// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1344/// }
1345template <class MCAsmParserImpl> struct RegisterMCAsmParser {
1349
1350private:
1351 static MCTargetAsmParser *Allocator(const MCSubtargetInfo &STI,
1352 MCAsmParser &P, const MCInstrInfo &MII,
1353 const MCTargetOptions &Options) {
1354 return new MCAsmParserImpl(STI, P, MII, Options);
1355 }
1356};
1357
1358/// RegisterAsmPrinter - Helper template for registering a target specific
1359/// assembly printer, for use in the target machine initialization
1360/// function. Usage:
1361///
1362/// extern "C" void LLVMInitializeFooAsmPrinter() {
1363/// extern Target TheFooTarget;
1364/// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1365/// }
1366template <class AsmPrinterImpl> struct RegisterAsmPrinter {
1370
1371private:
1373 std::unique_ptr<MCStreamer> &&Streamer) {
1374 return new AsmPrinterImpl(TM, std::move(Streamer));
1375 }
1376};
1377
1378/// RegisterMCCodeEmitter - Helper template for registering a target specific
1379/// machine code emitter, for use in the target initialization
1380/// function. Usage:
1381///
1382/// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1383/// extern Target TheFooTarget;
1384/// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1385/// }
1386template <class MCCodeEmitterImpl> struct RegisterMCCodeEmitter {
1390
1391private:
1392 static MCCodeEmitter *Allocator(const MCInstrInfo & /*II*/,
1393 MCContext & /*Ctx*/) {
1394 return new MCCodeEmitterImpl();
1395 }
1396};
1397
1398} // end namespace llvm
1399
1400#endif // LLVM_MC_TARGETREGISTRY_H
unsigned const MachineRegisterInfo * MRI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Analysis containing CSE Info
Definition CSEInfo.cpp:27
#define LLVM_ABI
Definition Compiler.h:213
dxil DXContainer Global Emitter
static LVOptions Options
Definition LVOptions.cpp:25
#define T
uint64_t IntrinsicInst * II
#define P(N)
PassInstrumentationCallbacks PIC
Basic Register Allocator
This class is intended to be used as a driving class for all asm writers.
Definition AsmPrinter.h:91
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
Generic interface to target specific assembler backends.
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition MCAsmInfo.h:64
Generic assembler parser interface, for use by target specific assembly parsers.
MCCodeEmitter - Generic instruction encoding interface.
Context object for machine code objects.
Definition MCContext.h:83
Superclass for all disassemblers.
This is an instance of a target assembly language printer that converts an MCInst to valid target ass...
Interface to description of machine instruction set.
Definition MCInstrInfo.h:27
void initMCObjectFileInfo(MCContext &MCCtx, bool PIC, bool LargeCodeModel=false)
Defines the object file and target independent interfaces used by the assembler backend to write nati...
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Create MCExprs from relocations found in an object file.
Streaming machine code generation interface.
Definition MCStreamer.h:220
Generic base class for all target subtargets.
Symbolize and annotate disassembled instructions.
MCTargetAsmParser - Generic interface to target specific assembly parsers.
Target specific streamer interface.
Definition MCStreamer.h:93
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
Primary interface to the complete machine description for the target machine.
bool operator!=(const iterator &x) const
const Target * operator->() const
bool operator==(const iterator &x) const
const Target & operator*() const
std::forward_iterator_tag iterator_category
Target - Wrapper for Target specific information.
TargetMachine * createTargetMachine(const Triple &TT, StringRef CPU, StringRef Features, const TargetOptions &Options, std::optional< Reloc::Model > RM, std::optional< CodeModel::Model > CM=std::nullopt, CodeGenOptLevel OL=CodeGenOptLevel::Default, bool JIT=false) const
createTargetMachine - Create a target specific machine implementation for the specified Triple.
MCRelocationInfo *(*)(const Triple &TT, MCContext &Ctx) MCRelocationInfoCtorTy
MCStreamer *(*)(const Triple &T, MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&Emitter) XCOFFStreamerCtorTy
MCRegisterInfo * createMCRegInfo(const Triple &TT) const
Create a MCRegisterInfo implementation.
MCTargetStreamer *(*)(MCStreamer &S) NullTargetStreamerCtorTy
MCAsmInfo *(*)(const MCRegisterInfo &MRI, const Triple &TT, const MCTargetOptions &Options) MCAsmInfoCtorFnTy
mca::InstrPostProcess *(*)(const MCSubtargetInfo &STI, const MCInstrInfo &MCII) InstrPostProcessCtorTy
mca::InstrumentManager *(*)(const MCSubtargetInfo &STI, const MCInstrInfo &MCII) InstrumentManagerCtorTy
MCSubtargetInfo *(*)(const Triple &TT, StringRef CPU, StringRef Features) MCSubtargetInfoCtorFnTy
Target()=default
MCCodeEmitter *(*)(const MCInstrInfo &II, MCContext &Ctx) MCCodeEmitterCtorTy
MCTargetStreamer *(*)(MCStreamer &S, const MCSubtargetInfo &STI) ObjectTargetStreamerCtorTy
bool hasTargetMachine() const
hasTargetMachine - Check if this target supports code generation.
MCCodeEmitter * createMCCodeEmitter(const MCInstrInfo &II, MCContext &Ctx) const
createMCCodeEmitter - Create a target specific code emitter.
const char * getName() const
getName - Get the target name.
MCObjectFileInfo * createMCObjectFileInfo(MCContext &Ctx, bool PIC, bool LargeCodeModel=false) const
Create a MCObjectFileInfo implementation for the specified target triple.
const Target * getNext() const
MCObjectFileInfo *(*)(MCContext &Ctx, bool PIC, bool LargeCodeModel) MCObjectFileInfoCtorFnTy
MCSubtargetInfo * createMCSubtargetInfo(StringRef TheTriple, StringRef CPU, StringRef Features) const
MCAsmInfo * createMCAsmInfo(const MCRegisterInfo &MRI, const Triple &TheTriple, const MCTargetOptions &Options) const
Create a MCAsmInfo implementation for the specified target triple.
MCDisassembler *(*)(const Target &T, const MCSubtargetInfo &STI, MCContext &Ctx) MCDisassemblerCtorTy
MCSymbolizer * createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo, LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo, MCContext *Ctx, std::unique_ptr< MCRelocationInfo > &&RelInfo) const
MCAsmBackend *(*)(const Target &T, const MCSubtargetInfo &STI, const MCRegisterInfo &MRI, const MCTargetOptions &Options) MCAsmBackendCtorTy
MCAsmBackend * createMCAsmBackend(const MCSubtargetInfo &STI, const MCRegisterInfo &MRI, const MCTargetOptions &Options) const
createMCAsmBackend - Create a target specific assembly parser.
MCStreamer *(*)(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&Emitter) COFFStreamerCtorTy
MCTargetStreamer *(*)(MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *InstPrint) AsmTargetStreamerCtorTy
bool hasMCAsmParser() const
hasMCAsmParser - Check if this target supports assembly parsing.
MCStreamer * createNullStreamer(MCContext &Ctx) const
LLVM_ABI MCStreamer * createAsmStreamer(MCContext &Ctx, std::unique_ptr< formatted_raw_ostream > OS, std::unique_ptr< MCInstPrinter > IP, std::unique_ptr< MCCodeEmitter > CE, std::unique_ptr< MCAsmBackend > TAB) const
MCRelocationInfo * createMCRelocationInfo(StringRef TT, MCContext &Ctx) const
MCStreamer *(*)(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&Emitter) MachOStreamerCtorTy
MCTargetStreamer * createAsmTargetStreamer(MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *InstPrint) const
MCInstrAnalysis *(*)(const MCInstrInfo *Info) MCInstrAnalysisCtorFnTy
MCRegisterInfo * createMCRegInfo(StringRef TT) const
MCRegisterInfo *(*)(const Triple &TT) MCRegInfoCtorFnTy
MCInstrInfo *(*)() MCInstrInfoCtorFnTy
LLVM_ABI 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) const
Create a target specific MCStreamer.
mca::CustomBehaviour * createCustomBehaviour(const MCSubtargetInfo &STI, const mca::SourceMgr &SrcMgr, const MCInstrInfo &MCII) const
createCustomBehaviour - Create a target specific CustomBehaviour.
friend struct TargetRegistry
mca::CustomBehaviour *(*)(const MCSubtargetInfo &STI, const mca::SourceMgr &SrcMgr, const MCInstrInfo &MCII) CustomBehaviourCtorTy
bool(*)(Triple::ArchType Arch) ArchMatchFnTy
MCSymbolizer * createMCSymbolizer(const Triple &TT, LLVMOpInfoCallback GetOpInfo, LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo, MCContext *Ctx, std::unique_ptr< MCRelocationInfo > &&RelInfo) const
createMCSymbolizer - Create a target specific MCSymbolizer.
MCDisassembler * createMCDisassembler(const MCSubtargetInfo &STI, MCContext &Ctx) const
bool hasMCAsmBackend() const
hasMCAsmBackend - Check if this target supports .o generation.
MCAsmInfo * createMCAsmInfo(const MCRegisterInfo &MRI, StringRef TheTriple, const MCTargetOptions &Options) const
MCInstPrinter * createMCInstPrinter(const Triple &T, unsigned SyntaxVariant, const MCAsmInfo &MAI, const MCInstrInfo &MII, const MCRegisterInfo &MRI) const
mca::InstrPostProcess * createInstrPostProcess(const MCSubtargetInfo &STI, const MCInstrInfo &MCII) const
createInstrPostProcess - Create a target specific InstrPostProcess.
const char * getBackendName() const
getBackendName - Get the backend name.
MCRelocationInfo * createMCRelocationInfo(const Triple &TT, MCContext &Ctx) const
createMCRelocationInfo - Create a target specific MCRelocationInfo.
MCTargetAsmParser * createMCAsmParser(const MCSubtargetInfo &STI, MCAsmParser &Parser, const MCInstrInfo &MII, const MCTargetOptions &Options) const
createMCAsmParser - Create a target specific assembly parser.
MCInstrAnalysis * createMCInstrAnalysis(const MCInstrInfo *Info) const
createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
MCSubtargetInfo * createMCSubtargetInfo(const Triple &TheTriple, StringRef CPU, StringRef Features) const
createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
const char * getShortDescription() const
getShortDescription - Get a short description of the target.
MCStreamer *(*)(MCContext &Ctx, std::unique_ptr< formatted_raw_ostream > OS, std::unique_ptr< MCInstPrinter > IP, std::unique_ptr< MCCodeEmitter > CE, std::unique_ptr< MCAsmBackend > TAB) AsmStreamerCtorTy
MCSymbolizer *(*)(const Triple &TT, LLVMOpInfoCallback GetOpInfo, LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo, MCContext *Ctx, std::unique_ptr< MCRelocationInfo > &&RelInfo) MCSymbolizerCtorTy
bool hasJIT() const
hasJIT - Check if this targets supports the just-in-time compilation.
AsmPrinter *(*)( TargetMachine &TM, std::unique_ptr< MCStreamer > &&Streamer) AsmPrinterCtorTy
TargetMachine *(*)(const Target &T, const Triple &TT, StringRef CPU, StringRef Features, const TargetOptions &Options, std::optional< Reloc::Model > RM, std::optional< CodeModel::Model > CM, CodeGenOptLevel OL, bool JIT) TargetMachineCtorTy
MCTargetStreamer * createNullTargetStreamer(MCStreamer &S) const
MCInstPrinter *(*)(const Triple &T, unsigned SyntaxVariant, const MCAsmInfo &MAI, const MCInstrInfo &MII, const MCRegisterInfo &MRI) MCInstPrinterCtorTy
AsmPrinter * createAsmPrinter(TargetMachine &TM, std::unique_ptr< MCStreamer > &&Streamer) const
createAsmPrinter - Create a target specific assembly printer pass.
MCTargetAsmParser *(*)( const MCSubtargetInfo &STI, MCAsmParser &P, const MCInstrInfo &MII, const MCTargetOptions &Options) MCAsmParserCtorTy
MCStreamer *(*)(const Triple &T, MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&Emitter) ELFStreamerCtorTy
MCInstrInfo * createMCInstrInfo() const
createMCInstrInfo - Create a MCInstrInfo implementation.
mca::InstrumentManager * createInstrumentManager(const MCSubtargetInfo &STI, const MCInstrInfo &MCII) const
createInstrumentManager - Create a target specific InstrumentManager.
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:47
@ UnknownArch
Definition Triple.h:50
formatted_raw_ostream - A raw_ostream that wraps another one and keeps track of line and column posit...
A range adaptor for a pair of iterators.
Class which can be overriden by targets to enforce instruction dependencies and behaviours that aren'...
Class which can be overriden by targets to modify the mca::Instruction objects before the pipeline st...
This class allows targets to optionally customize the logic that resolves scheduling class IDs.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
const char *(* LLVMSymbolLookupCallback)(void *DisInfo, uint64_t ReferenceValue, uint64_t *ReferenceType, uint64_t ReferencePC, const char **ReferenceName)
The type for the symbol lookup function.
int(* LLVMOpInfoCallback)(void *DisInfo, uint64_t PC, uint64_t Offset, uint64_t OpSize, uint64_t InstSize, int TagType, void *TagBuf)
The type for the operand information call back function.
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI mca::InstrumentManager * createInstrumentManager(const MCSubtargetInfo &STI, const MCInstrInfo &MCII)
LLVM_ABI MCStreamer * createELFStreamer(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&CE)
LLVM_ABI MCStreamer * createAsmStreamer(MCContext &Ctx, std::unique_ptr< formatted_raw_ostream > OS, std::unique_ptr< MCInstPrinter > InstPrint, std::unique_ptr< MCCodeEmitter > CE, std::unique_ptr< MCAsmBackend > TAB)
Create a machine code streamer which will print out assembly for the native target,...
Op::Description Desc
LLVM_ABI MCStreamer * createNullStreamer(MCContext &Ctx)
Create a dummy machine code streamer, which does nothing.
LLVM_ABI MCSymbolizer * createMCSymbolizer(const Triple &TT, LLVMOpInfoCallback GetOpInfo, LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo, MCContext *Ctx, std::unique_ptr< MCRelocationInfo > &&RelInfo)
LLVM_ABI MCStreamer * createMachOStreamer(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&CE, bool DWARFMustBeAtTheEnd, bool LabelSections=false)
SourceMgr SrcMgr
Definition Error.cpp:24
LLVM_ABI MCRelocationInfo * createMCRelocationInfo(const Triple &TT, MCContext &Ctx)
LLVM_ABI mca::CustomBehaviour * createCustomBehaviour(const MCSubtargetInfo &STI, const mca::SourceMgr &SrcMgr, const MCInstrInfo &MCII)
CodeGenOptLevel
Code generation optimization level.
Definition CodeGen.h:82
@ Default
-O2, -Os
Definition CodeGen.h:85
LLVM_ABI MCStreamer * createDXContainerStreamer(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&CE)
LLVM_ABI MCStreamer * createWasmStreamer(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&CE)
LLVM_ABI MCStreamer * createGOFFStreamer(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&CE)
LLVM_ABI MCStreamer * createSPIRVStreamer(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&CE)
LLVM_ABI mca::InstrPostProcess * createInstrPostProcess(const MCSubtargetInfo &STI, const MCInstrInfo &MCII)
RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn)
RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn)
RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn)
RegisterMCObjectFileInfoFn(Target &T, Target::MCObjectFileInfoCtorFnTy Fn)
RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn)
RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn)
static bool getArchMatch(Triple::ArchType Arch)
RegisterTarget(Target &T, const char *Name, const char *Desc, const char *BackendName)
static const Target * lookupTarget(StringRef TripleStr, std::string &Error)
lookupTarget - Lookup a target based on a target triple.
static void RegisterMCSymbolizer(Target &T, Target::MCSymbolizerCtorTy Fn)
RegisterMCSymbolizer - Register an MCSymbolizer implementation for the given target.
static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn)
RegisterMCRegInfo - Register a MCRegisterInfo implementation for the given target.
static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn)
RegisterAsmPrinter - Register an AsmPrinter implementation for the given target.
static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn)
RegisterMCAsmBackend - Register a MCAsmBackend implementation for the given target.
static void RegisterXCOFFStreamer(Target &T, Target::XCOFFStreamerCtorTy Fn)
static void RegisterMCCodeEmitter(Target &T, Target::MCCodeEmitterCtorTy Fn)
RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the given target.
static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn)
RegisterMCAsmInfo - Register a MCAsmInfo implementation for the given target.
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)
static void RegisterMCInstrAnalysis(Target &T, Target::MCInstrAnalysisCtorFnTy Fn)
RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for the given target.
static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn)
static void RegisterELFStreamer(Target &T, Target::ELFStreamerCtorTy Fn)
static void RegisterNullTargetStreamer(Target &T, Target::NullTargetStreamerCtorTy Fn)
static void RegisterInstrPostProcess(Target &T, Target::InstrPostProcessCtorTy Fn)
RegisterInstrPostProcess - Register an InstrPostProcess implementation for the given target.
static void RegisterMCDisassembler(Target &T, Target::MCDisassemblerCtorTy Fn)
RegisterMCDisassembler - Register a MCDisassembler implementation for the given target.
static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn)
RegisterMCAsmParser - Register a MCTargetAsmParser implementation for the given target.
static LLVM_ABI void printRegisteredTargetsForVersion(raw_ostream &OS)
printRegisteredTargetsForVersion - Print the registered targets appropriately for inclusion in a tool...
static void RegisterTargetMachine(Target &T, Target::TargetMachineCtorTy Fn)
RegisterTargetMachine - Register a TargetMachine implementation for the given target.
static void RegisterMCInstPrinter(Target &T, Target::MCInstPrinterCtorTy Fn)
RegisterMCInstPrinter - Register a MCInstPrinter implementation for the given target.
static void RegisterCOFFStreamer(Target &T, Target::COFFStreamerCtorTy Fn)
static LLVM_ABI void RegisterTarget(Target &T, const char *Name, const char *ShortDesc, const char *BackendName, Target::ArchMatchFnTy ArchMatchFn, bool HasJIT=false)
RegisterTarget - Register the given target.
static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn)
RegisterMCInstrInfo - Register a MCInstrInfo implementation for the given target.
static LLVM_ABI iterator_range< iterator > targets()
static void RegisterInstrumentManager(Target &T, Target::InstrumentManagerCtorTy Fn)
RegisterInstrumentManager - Register an InstrumentManager implementation for the given target.
static void RegisterCustomBehaviour(Target &T, Target::CustomBehaviourCtorTy Fn)
RegisterCustomBehaviour - Register a CustomBehaviour implementation for the given target.
static void RegisterMachOStreamer(Target &T, Target::MachOStreamerCtorTy Fn)
static void RegisterMCObjectFileInfo(Target &T, Target::MCObjectFileInfoCtorFnTy Fn)
Register a MCObjectFileInfo implementation for the given target.
static void RegisterAsmTargetStreamer(Target &T, Target::AsmTargetStreamerCtorTy Fn)
static void RegisterMCRelocationInfo(Target &T, Target::MCRelocationInfoCtorTy Fn)
RegisterMCRelocationInfo - Register an MCRelocationInfo implementation for the given target.
Abstracting the input code sequence (a sequence of MCInst) and assigning unique identifiers to every ...
Definition SourceMgr.h:29