LLVM 23.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"
24#include "llvm/MC/MCAsmInfo.h"
31#include <cassert>
32#include <cstddef>
33#include <iterator>
34#include <memory>
35#include <optional>
36#include <string>
37
38namespace llvm {
39
40class AsmPrinter;
41class MCAsmBackend;
42class MCAsmInfo;
43class MCAsmParser;
44class MCCodeEmitter;
45class MCContext;
46class MCDisassembler;
47class MCInstPrinter;
48class MCInstrAnalysis;
49class MCInstrInfo;
50class MCLFIRewriter;
51class MCObjectWriter;
52class MCRegisterInfo;
54class MCStreamer;
55class MCSubtargetInfo;
56class MCSymbolizer;
58class MCTargetOptions;
60class raw_ostream;
61class TargetMachine;
62class TargetOptions;
63namespace mca {
64class CustomBehaviour;
67struct SourceMgr;
68} // namespace mca
69
71// Takes ownership of \p TAB and \p CE.
72
73/// Create a machine code streamer which will print out assembly for the native
74/// target, suitable for compiling with a native assembler.
75///
76/// \param InstPrint - If given, the instruction printer to use. If not given
77/// the MCInst representation will be printed. This method takes ownership of
78/// InstPrint.
79///
80/// \param CE - If given, a code emitter to use to show the instruction
81/// encoding inline with the assembly. This method takes ownership of \p CE.
82///
83/// \param TAB - If given, a target asm backend to use to show the fixup
84/// information in conjunction with encoding information. This method takes
85/// ownership of \p TAB.
86///
87/// \param ShowInst - Whether to show the MCInst representation inline with
88/// the assembly.
90createAsmStreamer(MCContext &Ctx, std::unique_ptr<formatted_raw_ostream> OS,
91 std::unique_ptr<MCInstPrinter> InstPrint,
92 std::unique_ptr<MCCodeEmitter> CE,
93 std::unique_ptr<MCAsmBackend> TAB);
94
96 std::unique_ptr<MCAsmBackend> &&TAB,
97 std::unique_ptr<MCObjectWriter> &&OW,
98 std::unique_ptr<MCCodeEmitter> &&CE);
100 std::unique_ptr<MCAsmBackend> &&TAB,
101 std::unique_ptr<MCObjectWriter> &&OW,
102 std::unique_ptr<MCCodeEmitter> &&CE);
104 std::unique_ptr<MCAsmBackend> &&TAB,
105 std::unique_ptr<MCObjectWriter> &&OW,
106 std::unique_ptr<MCCodeEmitter> &&CE,
107 bool DWARFMustBeAtTheEnd,
108 bool LabelSections = false);
110 std::unique_ptr<MCAsmBackend> &&TAB,
111 std::unique_ptr<MCObjectWriter> &&OW,
112 std::unique_ptr<MCCodeEmitter> &&CE);
114 std::unique_ptr<MCAsmBackend> &&TAB,
115 std::unique_ptr<MCObjectWriter> &&OW,
116 std::unique_ptr<MCCodeEmitter> &&CE);
118createDXContainerStreamer(MCContext &Ctx, std::unique_ptr<MCAsmBackend> &&TAB,
119 std::unique_ptr<MCObjectWriter> &&OW,
120 std::unique_ptr<MCCodeEmitter> &&CE);
121
123 MCContext &Ctx);
124
126createMCSymbolizer(const Triple &TT, LLVMOpInfoCallback GetOpInfo,
127 LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo,
128 MCContext *Ctx, std::unique_ptr<MCRelocationInfo> &&RelInfo);
129
132 const MCInstrInfo &MCII);
133
136
139
140/// Target - Wrapper for Target specific information.
141///
142/// For registration purposes, this is a POD type so that targets can be
143/// registered without the use of static constructors.
144///
145/// Targets should implement a single global instance of this class (which
146/// will be zero initialized), and pass that instance to the TargetRegistry as
147/// part of their initialization.
148class Target {
149public:
150 friend struct TargetRegistry;
151
153
155 const Triple &TT,
156 const MCTargetOptions &Options);
158 bool PIC,
159 bool LargeCodeModel);
162 using MCRegInfoCtorFnTy = MCRegisterInfo *(*)(const Triple &TT);
164 StringRef CPU,
165 StringRef Features);
167 *(*)(const Target &T, const Triple &TT, StringRef CPU, StringRef Features,
168 const TargetOptions &Options, std::optional<Reloc::Model> RM,
169 std::optional<CodeModel::Model> CM, CodeGenOptLevel OL, bool JIT);
170 // If it weren't for layering issues (this header is in llvm/Support, but
171 // depends on MC?) this should take the Streamer by value rather than rvalue
172 // reference.
174 TargetMachine &TM, std::unique_ptr<MCStreamer> &&Streamer);
176 const MCSubtargetInfo &STI,
177 const MCRegisterInfo &MRI,
178 const MCTargetOptions &Options);
180 const MCSubtargetInfo &STI, MCAsmParser &P, const MCInstrInfo &MII,
181 const MCTargetOptions &Options);
183 const MCSubtargetInfo &STI,
184 MCContext &Ctx);
186 unsigned SyntaxVariant,
187 const MCAsmInfo &MAI,
188 const MCInstrInfo &MII,
189 const MCRegisterInfo &MRI);
191 MCContext &Ctx);
193 MCStreamer *(*)(const Triple &T, MCContext &Ctx,
194 std::unique_ptr<MCAsmBackend> &&TAB,
195 std::unique_ptr<MCObjectWriter> &&OW,
196 std::unique_ptr<MCCodeEmitter> &&Emitter);
198 MCStreamer *(*)(MCContext &Ctx, std::unique_ptr<MCAsmBackend> &&TAB,
199 std::unique_ptr<MCObjectWriter> &&OW,
200 std::unique_ptr<MCCodeEmitter> &&Emitter);
202 MCStreamer *(*)(MCContext &Ctx, std::unique_ptr<MCAsmBackend> &&TAB,
203 std::unique_ptr<MCObjectWriter> &&OW,
204 std::unique_ptr<MCCodeEmitter> &&Emitter);
206 MCStreamer *(*)(const Triple &T, MCContext &Ctx,
207 std::unique_ptr<MCAsmBackend> &&TAB,
208 std::unique_ptr<MCObjectWriter> &&OW,
209 std::unique_ptr<MCCodeEmitter> &&Emitter);
210
214 MCInstPrinter *InstPrint);
216 *(*)(MCContext & Ctx, std::unique_ptr<formatted_raw_ostream> OS,
217 std::unique_ptr<MCInstPrinter> IP, std::unique_ptr<MCCodeEmitter> CE,
218 std::unique_ptr<MCAsmBackend> TAB);
220 MCTargetStreamer *(*)(MCStreamer &S, const MCSubtargetInfo &STI);
222 MCContext &Ctx);
224 MCSymbolizer *(*)(const Triple &TT, LLVMOpInfoCallback GetOpInfo,
225 LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo,
226 MCContext *Ctx,
227 std::unique_ptr<MCRelocationInfo> &&RelInfo);
228
231 const mca::SourceMgr &SrcMgr,
232 const MCInstrInfo &MCII);
233
236 const MCInstrInfo &MCII);
237
240 const MCInstrInfo &MCII);
241
243 MCLFIRewriter *(*)(MCContext & Ctx,
244 std::unique_ptr<MCRegisterInfo> &&RegInfo,
245 std::unique_ptr<MCInstrInfo> &&InstInfo);
246
247private:
248 /// Next - The next registered target in the linked list, maintained by the
249 /// TargetRegistry.
250 Target *Next;
251
252 /// The target function for checking if an architecture is supported.
253 ArchMatchFnTy ArchMatchFn;
254
255 /// Name - The target name.
256 const char *Name;
257
258 /// ShortDesc - A short description of the target.
259 const char *ShortDesc;
260
261 /// BackendName - The name of the backend implementation. This must match the
262 /// name of the 'def X : Target ...' in TableGen.
263 const char *BackendName;
264
265 /// HasJIT - Whether this target supports the JIT.
266 bool HasJIT;
267
268 /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
269 /// registered.
270 MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
271
272 /// Constructor function for this target's MCObjectFileInfo, if registered.
273 MCObjectFileInfoCtorFnTy MCObjectFileInfoCtorFn;
274
275 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
276 /// if registered.
277 MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
278
279 /// MCInstrAnalysisCtorFn - Constructor function for this target's
280 /// MCInstrAnalysis, if registered.
281 MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
282
283 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
284 /// if registered.
285 MCRegInfoCtorFnTy MCRegInfoCtorFn;
286
287 /// MCSubtargetInfoCtorFn - Constructor function for this target's
288 /// MCSubtargetInfo, if registered.
289 MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
290
291 /// TargetMachineCtorFn - Construction function for this target's
292 /// TargetMachine, if registered.
293 TargetMachineCtorTy TargetMachineCtorFn;
294
295 /// MCAsmBackendCtorFn - Construction function for this target's
296 /// MCAsmBackend, if registered.
297 MCAsmBackendCtorTy MCAsmBackendCtorFn;
298
299 /// MCAsmParserCtorFn - Construction function for this target's
300 /// MCTargetAsmParser, if registered.
301 MCAsmParserCtorTy MCAsmParserCtorFn;
302
303 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
304 /// if registered.
305 AsmPrinterCtorTy AsmPrinterCtorFn;
306
307 /// MCDisassemblerCtorFn - Construction function for this target's
308 /// MCDisassembler, if registered.
309 MCDisassemblerCtorTy MCDisassemblerCtorFn;
310
311 /// MCInstPrinterCtorFn - Construction function for this target's
312 /// MCInstPrinter, if registered.
313 MCInstPrinterCtorTy MCInstPrinterCtorFn;
314
315 /// MCCodeEmitterCtorFn - Construction function for this target's
316 /// CodeEmitter, if registered.
317 MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
318
319 // Construction functions for the various object formats, if registered.
320 COFFStreamerCtorTy COFFStreamerCtorFn = nullptr;
321 MachOStreamerCtorTy MachOStreamerCtorFn = nullptr;
322 ELFStreamerCtorTy ELFStreamerCtorFn = nullptr;
323 XCOFFStreamerCtorTy XCOFFStreamerCtorFn = nullptr;
324
325 /// Construction function for this target's null TargetStreamer, if
326 /// registered (default = nullptr).
327 NullTargetStreamerCtorTy NullTargetStreamerCtorFn = nullptr;
328
329 /// Construction function for this target's asm TargetStreamer, if
330 /// registered (default = nullptr).
331 AsmTargetStreamerCtorTy AsmTargetStreamerCtorFn = nullptr;
332
333 /// Construction function for this target's AsmStreamer, if
334 /// registered (default = nullptr).
335 AsmStreamerCtorTy AsmStreamerCtorFn = nullptr;
336
337 /// Construction function for this target's obj TargetStreamer, if
338 /// registered (default = nullptr).
339 ObjectTargetStreamerCtorTy ObjectTargetStreamerCtorFn = nullptr;
340
341 /// MCRelocationInfoCtorFn - Construction function for this target's
342 /// MCRelocationInfo, if registered (default = llvm::createMCRelocationInfo)
343 MCRelocationInfoCtorTy MCRelocationInfoCtorFn = nullptr;
344
345 /// MCSymbolizerCtorFn - Construction function for this target's
346 /// MCSymbolizer, if registered (default = llvm::createMCSymbolizer)
347 MCSymbolizerCtorTy MCSymbolizerCtorFn = nullptr;
348
349 /// CustomBehaviourCtorFn - Construction function for this target's
350 /// CustomBehaviour, if registered (default = nullptr).
351 CustomBehaviourCtorTy CustomBehaviourCtorFn = nullptr;
352
353 /// InstrPostProcessCtorFn - Construction function for this target's
354 /// InstrPostProcess, if registered (default = nullptr).
355 InstrPostProcessCtorTy InstrPostProcessCtorFn = nullptr;
356
357 /// InstrumentManagerCtorFn - Construction function for this target's
358 /// InstrumentManager, if registered (default = nullptr).
359 InstrumentManagerCtorTy InstrumentManagerCtorFn = nullptr;
360
361 // MCLFIRewriterCtorFn - Construction function for this target's
362 // MCLFIRewriter, if registered (default = nullptr).
363 MCLFIRewriterCtorTy MCLFIRewriterCtorFn = nullptr;
364
365public:
366 Target() = default;
367
368 /// @name Target Information
369 /// @{
370
371 // getNext - Return the next registered target.
372 const Target *getNext() const { return Next; }
373
374 /// getName - Get the target name.
375 const char *getName() const { return Name; }
376
377 /// getShortDescription - Get a short description of the target.
378 const char *getShortDescription() const { return ShortDesc; }
379
380 /// getBackendName - Get the backend name.
381 const char *getBackendName() const { return BackendName; }
382
383 /// @}
384 /// @name Feature Predicates
385 /// @{
386
387 /// hasJIT - Check if this targets supports the just-in-time compilation.
388 bool hasJIT() const { return HasJIT; }
389
390 /// hasTargetMachine - Check if this target supports code generation.
391 bool hasTargetMachine() const { return TargetMachineCtorFn != nullptr; }
392
393 /// hasMCAsmBackend - Check if this target supports .o generation.
394 bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != nullptr; }
395
396 /// hasMCAsmParser - Check if this target supports assembly parsing.
397 bool hasMCAsmParser() const { return MCAsmParserCtorFn != nullptr; }
398
399 /// @}
400 /// @name Feature Constructors
401 /// @{
402
403 /// Create a MCAsmInfo implementation for the specified
404 /// target triple.
405 ///
406 /// \param TheTriple This argument is used to determine the target machine
407 /// feature set; it should always be provided. Generally this should be
408 /// either the target triple from the module, or the target triple of the
409 /// host if that does not exist.
410 MCAsmInfo *createMCAsmInfo(const MCRegisterInfo &MRI, const Triple &TheTriple,
411 const MCTargetOptions &Options) const {
412 if (!MCAsmInfoCtorFn)
413 return nullptr;
414 auto *MAI = MCAsmInfoCtorFn(MRI, TheTriple, Options);
415 if (MAI)
416 MAI->setTargetOptions(Options);
417 return MAI;
418 }
419
420 /// Create a MCObjectFileInfo implementation for the specified target
421 /// triple.
422 ///
424 bool LargeCodeModel = false) const {
425 if (!MCObjectFileInfoCtorFn) {
427 MOFI->initMCObjectFileInfo(Ctx, PIC, LargeCodeModel);
428 return MOFI;
429 }
430 return MCObjectFileInfoCtorFn(Ctx, PIC, LargeCodeModel);
431 }
432
433 /// createMCInstrInfo - Create a MCInstrInfo implementation.
434 ///
436 if (!MCInstrInfoCtorFn)
437 return nullptr;
438 return MCInstrInfoCtorFn();
439 }
440
441 /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
442 ///
444 if (!MCInstrAnalysisCtorFn)
445 return nullptr;
446 return MCInstrAnalysisCtorFn(Info);
447 }
448
449 /// Create a MCRegisterInfo implementation.
451 if (!MCRegInfoCtorFn)
452 return nullptr;
453 return MCRegInfoCtorFn(TT);
454 }
455
456 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
457 ///
458 /// \param TheTriple This argument is used to determine the target machine
459 /// feature set; it should always be provided. Generally this should be
460 /// either the target triple from the module, or the target triple of the
461 /// host if that does not exist.
462 /// \param CPU This specifies the name of the target CPU.
463 /// \param Features This specifies the string representation of the
464 /// additional target features.
466 StringRef Features) const {
467 if (!MCSubtargetInfoCtorFn)
468 return nullptr;
469 return MCSubtargetInfoCtorFn(TheTriple, CPU, Features);
470 }
471
472 /// createTargetMachine - Create a target specific machine implementation
473 /// for the specified \p Triple.
474 ///
475 /// \param TT This argument is used to determine the target machine
476 /// feature set; it should always be provided. Generally this should be
477 /// either the target triple from the module, or the target triple of the
478 /// host if that does not exist.
480 const Triple &TT, StringRef CPU, StringRef Features,
481 const TargetOptions &Options, std::optional<Reloc::Model> RM,
482 std::optional<CodeModel::Model> CM = std::nullopt,
483 CodeGenOptLevel OL = CodeGenOptLevel::Default, bool JIT = false) const {
484 if (!TargetMachineCtorFn)
485 return nullptr;
486 return TargetMachineCtorFn(*this, TT, CPU, Features, Options, RM, CM, OL,
487 JIT);
488 }
489
490 /// createMCAsmBackend - Create a target specific assembly parser.
492 const MCRegisterInfo &MRI,
493 const MCTargetOptions &Options) const {
494 if (!MCAsmBackendCtorFn)
495 return nullptr;
496 return MCAsmBackendCtorFn(*this, STI, MRI, Options);
497 }
498
499 /// createMCAsmParser - Create a target specific assembly parser.
500 ///
501 /// \param Parser The target independent parser implementation to use for
502 /// parsing and lexing.
504 MCAsmParser &Parser,
505 const MCInstrInfo &MII,
506 const MCTargetOptions &Options) const {
507 if (!MCAsmParserCtorFn)
508 return nullptr;
509 return MCAsmParserCtorFn(STI, Parser, MII, Options);
510 }
511
512 /// createAsmPrinter - Create a target specific assembly printer pass. This
513 /// takes ownership of the MCStreamer object.
515 std::unique_ptr<MCStreamer> &&Streamer) const {
516 if (!AsmPrinterCtorFn)
517 return nullptr;
518 return AsmPrinterCtorFn(TM, std::move(Streamer));
519 }
520
522 MCContext &Ctx) const {
523 if (!MCDisassemblerCtorFn)
524 return nullptr;
525 return MCDisassemblerCtorFn(*this, STI, Ctx);
526 }
527
528 MCInstPrinter *createMCInstPrinter(const Triple &T, unsigned SyntaxVariant,
529 const MCAsmInfo &MAI,
530 const MCInstrInfo &MII,
531 const MCRegisterInfo &MRI) const {
532 if (!MCInstPrinterCtorFn)
533 return nullptr;
534 return MCInstPrinterCtorFn(T, SyntaxVariant, MAI, MII, MRI);
535 }
536
537 /// createMCCodeEmitter - Create a target specific code emitter.
539 MCContext &Ctx) const {
540 if (!MCCodeEmitterCtorFn)
541 return nullptr;
542 return MCCodeEmitterCtorFn(II, Ctx);
543 }
544
545 /// Create a target specific MCStreamer.
546 ///
547 /// \param T The target triple.
548 /// \param Ctx The target context.
549 /// \param TAB The target assembler backend object. Takes ownership.
550 /// \param OW The stream object.
551 /// \param Emitter The target independent assembler object.Takes ownership.
553 const Triple &T, MCContext &Ctx, std::unique_ptr<MCAsmBackend> TAB,
554 std::unique_ptr<MCObjectWriter> OW,
555 std::unique_ptr<MCCodeEmitter> Emitter, const MCSubtargetInfo &STI) const;
556
558 createAsmStreamer(MCContext &Ctx, std::unique_ptr<formatted_raw_ostream> OS,
559 std::unique_ptr<MCInstPrinter> IP,
560 std::unique_ptr<MCCodeEmitter> CE,
561 std::unique_ptr<MCAsmBackend> TAB) const;
562
565 MCInstPrinter *InstPrint) const {
566 if (AsmTargetStreamerCtorFn)
567 return AsmTargetStreamerCtorFn(S, OS, InstPrint);
568 return nullptr;
569 }
570
574 return S;
575 }
576
578 if (NullTargetStreamerCtorFn)
579 return NullTargetStreamerCtorFn(S);
580 return nullptr;
581 }
582
584 createMCLFIRewriter(MCContext &Ctx, std::unique_ptr<MCRegisterInfo> &&RegInfo,
585 std::unique_ptr<MCInstrInfo> &&InstInfo) const {
586 if (MCLFIRewriterCtorFn)
587 return MCLFIRewriterCtorFn(Ctx, std::move(RegInfo), std::move(InstInfo));
588 return nullptr;
589 }
590
591 /// createMCRelocationInfo - Create a target specific MCRelocationInfo.
592 ///
593 /// \param TT The target triple.
594 /// \param Ctx The target context.
596 MCContext &Ctx) const {
597 MCRelocationInfoCtorTy Fn = MCRelocationInfoCtorFn
598 ? MCRelocationInfoCtorFn
600 return Fn(TT, Ctx);
601 }
602
603 /// createMCSymbolizer - Create a target specific MCSymbolizer.
604 ///
605 /// \param TT The target triple.
606 /// \param GetOpInfo The function to get the symbolic information for
607 /// operands.
608 /// \param SymbolLookUp The function to lookup a symbol name.
609 /// \param DisInfo The pointer to the block of symbolic information for above
610 /// call
611 /// back.
612 /// \param Ctx The target context.
613 /// \param RelInfo The relocation information for this target. Takes
614 /// ownership.
617 LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo,
618 MCContext *Ctx,
619 std::unique_ptr<MCRelocationInfo> &&RelInfo) const {
621 MCSymbolizerCtorFn ? MCSymbolizerCtorFn : llvm::createMCSymbolizer;
622 return Fn(TT, GetOpInfo, SymbolLookUp, DisInfo, Ctx, std::move(RelInfo));
623 }
624
625 /// createCustomBehaviour - Create a target specific CustomBehaviour.
626 /// This class is used by llvm-mca and requires backend functionality.
628 const mca::SourceMgr &SrcMgr,
629 const MCInstrInfo &MCII) const {
630 if (CustomBehaviourCtorFn)
631 return CustomBehaviourCtorFn(STI, SrcMgr, MCII);
632 return nullptr;
633 }
634
635 /// createInstrPostProcess - Create a target specific InstrPostProcess.
636 /// This class is used by llvm-mca and requires backend functionality.
638 const MCInstrInfo &MCII) const {
639 if (InstrPostProcessCtorFn)
640 return InstrPostProcessCtorFn(STI, MCII);
641 return nullptr;
642 }
643
644 /// createInstrumentManager - Create a target specific
645 /// InstrumentManager. This class is used by llvm-mca and requires
646 /// backend functionality.
649 const MCInstrInfo &MCII) const {
650 if (InstrumentManagerCtorFn)
651 return InstrumentManagerCtorFn(STI, MCII);
652 return nullptr;
653 }
654
655 /// @}
656};
657
658/// TargetRegistry - Generic interface to target specific features.
660 // FIXME: Make this a namespace, probably just move all the Register*
661 // functions into Target (currently they all just set members on the Target
662 // anyway, and Target friends this class so those functions can...
663 // function).
664 TargetRegistry() = delete;
665
666 class iterator {
667 friend struct TargetRegistry;
668
669 const Target *Current = nullptr;
670
671 explicit iterator(Target *T) : Current(T) {}
672
673 public:
674 using iterator_category = std::forward_iterator_tag;
676 using difference_type = std::ptrdiff_t;
679
680 iterator() = default;
681
682 bool operator==(const iterator &x) const { return Current == x.Current; }
683 bool operator!=(const iterator &x) const { return !operator==(x); }
684
685 // Iterator traversal: forward iteration only
686 iterator &operator++() { // Preincrement
687 assert(Current && "Cannot increment end iterator!");
688 Current = Current->getNext();
689 return *this;
690 }
691 iterator operator++(int) { // Postincrement
692 iterator tmp = *this;
693 ++*this;
694 return tmp;
695 }
696
697 const Target &operator*() const {
698 assert(Current && "Cannot dereference end iterator!");
699 return *Current;
700 }
701
702 const Target *operator->() const { return &operator*(); }
703 };
704
705 /// printRegisteredTargetsForVersion - Print the registered targets
706 /// appropriately for inclusion in a tool's version output.
708
709 /// @name Registry Access
710 /// @{
711
713
714 /// lookupTarget - Lookup a target based on a target triple.
715 ///
716 /// \param TripleStr - The triple to use for finding a target.
717 /// \param Error - On failure, an error string describing why no target was
718 /// found.
719 // TODO(boomanaiden154): Remove this function after LLVM 22 branches.
720 [[deprecated("Use overload accepting Triple instead")]]
721 static const Target *lookupTarget(StringRef TripleStr, std::string &Error) {
722 return lookupTarget(Triple(TripleStr), Error);
723 }
724
725 /// lookupTarget - Lookup a target based on a target triple.
726 ///
727 /// \param Triple - The triple to use for finding a target.
728 /// \param Error - On failure, an error string describing why no target was
729 /// found.
730 LLVM_ABI static const Target *lookupTarget(const Triple &TheTriple,
731 std::string &Error);
732
733 /// lookupTarget - Lookup a target based on an architecture name
734 /// and a target triple. If the architecture name is non-empty,
735 /// then the lookup is done by architecture. Otherwise, the target
736 /// triple is used.
737 ///
738 /// \param ArchName - The architecture to use for finding a target.
739 /// \param TheTriple - The triple to use for finding a target. The
740 /// triple is updated with canonical architecture name if a lookup
741 /// by architecture is done.
742 /// \param Error - On failure, an error string describing why no target was
743 /// found.
744 LLVM_ABI static const Target *
745 lookupTarget(StringRef ArchName, Triple &TheTriple, std::string &Error);
746
747 /// @}
748 /// @name Target Registration
749 /// @{
750
751 /// RegisterTarget - Register the given target. Attempts to register a
752 /// target which has already been registered will be ignored.
753 ///
754 /// Clients are responsible for ensuring that registration doesn't occur
755 /// while another thread is attempting to access the registry. Typically
756 /// this is done by initializing all targets at program startup.
757 ///
758 /// @param T - The target being registered.
759 /// @param Name - The target name. This should be a static string.
760 /// @param ShortDesc - A short target description. This should be a static
761 /// string.
762 /// @param BackendName - The name of the backend. This should be a static
763 /// string that is the same for all targets that share a backend
764 /// implementation and must match the name used in the 'def X : Target ...' in
765 /// TableGen.
766 /// @param ArchMatchFn - The arch match checking function for this target.
767 /// @param HasJIT - Whether the target supports JIT code
768 /// generation.
769 LLVM_ABI static void RegisterTarget(Target &T, const char *Name,
770 const char *ShortDesc,
771 const char *BackendName,
772 Target::ArchMatchFnTy ArchMatchFn,
773 bool HasJIT = false);
774
775 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
776 /// given target.
777 ///
778 /// Clients are responsible for ensuring that registration doesn't occur
779 /// while another thread is attempting to access the registry. Typically
780 /// this is done by initializing all targets at program startup.
781 ///
782 /// @param T - The target being registered.
783 /// @param Fn - A function to construct a MCAsmInfo for the target.
785 T.MCAsmInfoCtorFn = Fn;
786 }
787
788 /// Register a MCObjectFileInfo implementation for the given target.
789 ///
790 /// Clients are responsible for ensuring that registration doesn't occur
791 /// while another thread is attempting to access the registry. Typically
792 /// this is done by initializing all targets at program startup.
793 ///
794 /// @param T - The target being registered.
795 /// @param Fn - A function to construct a MCObjectFileInfo for the target.
798 T.MCObjectFileInfoCtorFn = Fn;
799 }
800
801 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
802 /// given target.
803 ///
804 /// Clients are responsible for ensuring that registration doesn't occur
805 /// while another thread is attempting to access the registry. Typically
806 /// this is done by initializing all targets at program startup.
807 ///
808 /// @param T - The target being registered.
809 /// @param Fn - A function to construct a MCInstrInfo for the target.
811 T.MCInstrInfoCtorFn = Fn;
812 }
813
814 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
815 /// the given target.
818 T.MCInstrAnalysisCtorFn = Fn;
819 }
820
821 /// RegisterMCRegInfo - Register a MCRegisterInfo 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 MCRegisterInfo for the target.
831 T.MCRegInfoCtorFn = Fn;
832 }
833
834 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
835 /// the given target.
836 ///
837 /// Clients are responsible for ensuring that registration doesn't occur
838 /// while another thread is attempting to access the registry. Typically
839 /// this is done by initializing all targets at program startup.
840 ///
841 /// @param T - The target being registered.
842 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
845 T.MCSubtargetInfoCtorFn = Fn;
846 }
847
848 /// RegisterTargetMachine - Register a TargetMachine implementation for the
849 /// given target.
850 ///
851 /// Clients are responsible for ensuring that registration doesn't occur
852 /// while another thread is attempting to access the registry. Typically
853 /// this is done by initializing all targets at program startup.
854 ///
855 /// @param T - The target being registered.
856 /// @param Fn - A function to construct a TargetMachine for the target.
858 T.TargetMachineCtorFn = Fn;
859 }
860
861 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
862 /// given target.
863 ///
864 /// Clients are responsible for ensuring that registration doesn't occur
865 /// while another thread is attempting to access the registry. Typically
866 /// this is done by initializing all targets at program startup.
867 ///
868 /// @param T - The target being registered.
869 /// @param Fn - A function to construct an AsmBackend for the target.
871 T.MCAsmBackendCtorFn = Fn;
872 }
873
874 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
875 /// the given target.
876 ///
877 /// Clients are responsible for ensuring that registration doesn't occur
878 /// while another thread is attempting to access the registry. Typically
879 /// this is done by initializing all targets at program startup.
880 ///
881 /// @param T - The target being registered.
882 /// @param Fn - A function to construct an MCTargetAsmParser for the target.
884 T.MCAsmParserCtorFn = Fn;
885 }
886
887 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
888 /// target.
889 ///
890 /// Clients are responsible for ensuring that registration doesn't occur
891 /// while another thread is attempting to access the registry. Typically
892 /// this is done by initializing all targets at program startup.
893 ///
894 /// @param T - The target being registered.
895 /// @param Fn - A function to construct an AsmPrinter for the target.
897 T.AsmPrinterCtorFn = Fn;
898 }
899
900 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
901 /// the given target.
902 ///
903 /// Clients are responsible for ensuring that registration doesn't occur
904 /// while another thread is attempting to access the registry. Typically
905 /// this is done by initializing all targets at program startup.
906 ///
907 /// @param T - The target being registered.
908 /// @param Fn - A function to construct an MCDisassembler for the target.
911 T.MCDisassemblerCtorFn = Fn;
912 }
913
914 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
915 /// given target.
916 ///
917 /// Clients are responsible for ensuring that registration doesn't occur
918 /// while another thread is attempting to access the registry. Typically
919 /// this is done by initializing all targets at program startup.
920 ///
921 /// @param T - The target being registered.
922 /// @param Fn - A function to construct an MCInstPrinter for the target.
924 T.MCInstPrinterCtorFn = Fn;
925 }
926
927 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
928 /// given target.
929 ///
930 /// Clients are responsible for ensuring that registration doesn't occur
931 /// while another thread is attempting to access the registry. Typically
932 /// this is done by initializing all targets at program startup.
933 ///
934 /// @param T - The target being registered.
935 /// @param Fn - A function to construct an MCCodeEmitter for the target.
937 T.MCCodeEmitterCtorFn = Fn;
938 }
939
941 T.COFFStreamerCtorFn = Fn;
942 }
943
945 T.MachOStreamerCtorFn = Fn;
946 }
947
949 T.ELFStreamerCtorFn = Fn;
950 }
951
953 T.XCOFFStreamerCtorFn = Fn;
954 }
955
958 T.NullTargetStreamerCtorFn = Fn;
959 }
960
962 T.AsmStreamerCtorFn = Fn;
963 }
964
967 T.AsmTargetStreamerCtorFn = Fn;
968 }
969
970 static void
973 T.ObjectTargetStreamerCtorFn = Fn;
974 }
975
976 /// RegisterMCRelocationInfo - Register an MCRelocationInfo
977 /// implementation for the given target.
978 ///
979 /// Clients are responsible for ensuring that registration doesn't occur
980 /// while another thread is attempting to access the registry. Typically
981 /// this is done by initializing all targets at program startup.
982 ///
983 /// @param T - The target being registered.
984 /// @param Fn - A function to construct an MCRelocationInfo for the target.
987 T.MCRelocationInfoCtorFn = Fn;
988 }
989
990 /// RegisterMCSymbolizer - Register an MCSymbolizer
991 /// implementation for the given target.
992 ///
993 /// Clients are responsible for ensuring that registration doesn't occur
994 /// while another thread is attempting to access the registry. Typically
995 /// this is done by initializing all targets at program startup.
996 ///
997 /// @param T - The target being registered.
998 /// @param Fn - A function to construct an MCSymbolizer for the target.
1000 T.MCSymbolizerCtorFn = Fn;
1001 }
1002
1003 /// RegisterCustomBehaviour - Register a CustomBehaviour
1004 /// implementation for the given target.
1005 ///
1006 /// Clients are responsible for ensuring that registration doesn't occur
1007 /// while another thread is attempting to access the registry. Typically
1008 /// this is done by initializing all targets at program startup.
1009 ///
1010 /// @param T - The target being registered.
1011 /// @param Fn - A function to construct a CustomBehaviour for the target.
1014 T.CustomBehaviourCtorFn = Fn;
1015 }
1016
1017 /// RegisterInstrPostProcess - Register an InstrPostProcess
1018 /// implementation for the given target.
1019 ///
1020 /// Clients are responsible for ensuring that registration doesn't occur
1021 /// while another thread is attempting to access the registry. Typically
1022 /// this is done by initializing all targets at program startup.
1023 ///
1024 /// @param T - The target being registered.
1025 /// @param Fn - A function to construct an InstrPostProcess for the target.
1028 T.InstrPostProcessCtorFn = Fn;
1029 }
1030
1031 /// RegisterInstrumentManager - Register an InstrumentManager
1032 /// implementation for the given target.
1033 ///
1034 /// Clients are responsible for ensuring that registration doesn't occur
1035 /// while another thread is attempting to access the registry. Typically
1036 /// this is done by initializing all targets at program startup.
1037 ///
1038 /// @param T - The target being registered.
1039 /// @param Fn - A function to construct an InstrumentManager for the
1040 /// target.
1043 T.InstrumentManagerCtorFn = Fn;
1044 }
1045
1047 T.MCLFIRewriterCtorFn = Fn;
1048 }
1049
1050 /// @}
1051};
1052
1053//===--------------------------------------------------------------------===//
1054
1055/// RegisterTarget - Helper template for registering a target, for use in the
1056/// target's initialization function. Usage:
1057///
1058///
1059/// Target &getTheFooTarget() { // The global target instance.
1060/// static Target TheFooTarget;
1061/// return TheFooTarget;
1062/// }
1063/// extern "C" void LLVMInitializeFooTargetInfo() {
1064/// RegisterTarget<Triple::foo> X(getTheFooTarget(), "foo", "Foo
1065/// description", "Foo" /* Backend Name */);
1066/// }
1067template <Triple::ArchType TargetArchType = Triple::UnknownArch,
1068 bool HasJIT = false>
1070 RegisterTarget(Target &T, const char *Name, const char *Desc,
1071 const char *BackendName) {
1072 TargetRegistry::RegisterTarget(T, Name, Desc, BackendName, &getArchMatch,
1073 HasJIT);
1074 }
1075
1076 static bool getArchMatch(Triple::ArchType Arch) {
1077 return Arch == TargetArchType;
1078 }
1079};
1080
1081/// RegisterMCAsmInfo - Helper template for registering a target assembly info
1082/// implementation. This invokes the static "Create" method on the class to
1083/// actually do the construction. Usage:
1084///
1085/// extern "C" void LLVMInitializeFooTarget() {
1086/// extern Target TheFooTarget;
1087/// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
1088/// }
1089template <class MCAsmInfoImpl> struct RegisterMCAsmInfo {
1093
1094private:
1095 static MCAsmInfo *Allocator(const MCRegisterInfo & /*MRI*/, const Triple &TT,
1096 const MCTargetOptions &Options) {
1097 return new MCAsmInfoImpl(TT, Options);
1098 }
1099};
1100
1101/// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
1102/// implementation. This invokes the specified function to do the
1103/// construction. Usage:
1104///
1105/// extern "C" void LLVMInitializeFooTarget() {
1106/// extern Target TheFooTarget;
1107/// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
1108/// }
1114
1115/// Helper template for registering a target object file info implementation.
1116/// This invokes the static "Create" method on the class to actually do the
1117/// construction. Usage:
1118///
1119/// extern "C" void LLVMInitializeFooTarget() {
1120/// extern Target TheFooTarget;
1121/// RegisterMCObjectFileInfo<FooMCObjectFileInfo> X(TheFooTarget);
1122/// }
1123template <class MCObjectFileInfoImpl> struct RegisterMCObjectFileInfo {
1127
1128private:
1129 static MCObjectFileInfo *Allocator(MCContext &Ctx, bool PIC,
1130 bool LargeCodeModel = false) {
1131 return new MCObjectFileInfoImpl(Ctx, PIC, LargeCodeModel);
1132 }
1133};
1134
1135/// Helper template for registering a target object file info implementation.
1136/// This invokes the specified function to do the construction. Usage:
1137///
1138/// extern "C" void LLVMInitializeFooTarget() {
1139/// extern Target TheFooTarget;
1140/// RegisterMCObjectFileInfoFn X(TheFooTarget, TheFunction);
1141/// }
1147
1148/// RegisterMCInstrInfo - Helper template for registering a target instruction
1149/// info implementation. This invokes the static "Create" method on the class
1150/// to actually do the construction. Usage:
1151///
1152/// extern "C" void LLVMInitializeFooTarget() {
1153/// extern Target TheFooTarget;
1154/// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
1155/// }
1156template <class MCInstrInfoImpl> struct RegisterMCInstrInfo {
1160
1161private:
1162 static MCInstrInfo *Allocator() { return new MCInstrInfoImpl(); }
1163};
1164
1165/// RegisterMCInstrInfoFn - Helper template for registering a target
1166/// instruction info implementation. This invokes the specified function to
1167/// do the construction. Usage:
1168///
1169/// extern "C" void LLVMInitializeFooTarget() {
1170/// extern Target TheFooTarget;
1171/// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
1172/// }
1178
1179/// RegisterMCInstrAnalysis - Helper template for registering a target
1180/// instruction analyzer implementation. This invokes the static "Create"
1181/// method on the class to actually do the construction. Usage:
1182///
1183/// extern "C" void LLVMInitializeFooTarget() {
1184/// extern Target TheFooTarget;
1185/// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
1186/// }
1187template <class MCInstrAnalysisImpl> struct RegisterMCInstrAnalysis {
1191
1192private:
1193 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
1194 return new MCInstrAnalysisImpl(Info);
1195 }
1196};
1197
1198/// RegisterMCInstrAnalysisFn - Helper template for registering a target
1199/// instruction analyzer implementation. This invokes the specified function
1200/// to do the construction. Usage:
1201///
1202/// extern "C" void LLVMInitializeFooTarget() {
1203/// extern Target TheFooTarget;
1204/// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
1205/// }
1211
1212/// RegisterMCRegInfo - Helper template for registering a target register info
1213/// implementation. This invokes the static "Create" method on the class to
1214/// actually do the construction. Usage:
1215///
1216/// extern "C" void LLVMInitializeFooTarget() {
1217/// extern Target TheFooTarget;
1218/// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
1219/// }
1220template <class MCRegisterInfoImpl> struct RegisterMCRegInfo {
1224
1225private:
1226 static MCRegisterInfo *Allocator(const Triple & /*TT*/) {
1227 return new MCRegisterInfoImpl();
1228 }
1229};
1230
1231/// RegisterMCRegInfoFn - Helper template for registering a target register
1232/// info implementation. This invokes the specified function to do the
1233/// construction. Usage:
1234///
1235/// extern "C" void LLVMInitializeFooTarget() {
1236/// extern Target TheFooTarget;
1237/// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
1238/// }
1244
1245/// RegisterMCSubtargetInfo - Helper template for registering a target
1246/// subtarget info implementation. This invokes the static "Create" method
1247/// on the class to actually do the construction. Usage:
1248///
1249/// extern "C" void LLVMInitializeFooTarget() {
1250/// extern Target TheFooTarget;
1251/// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
1252/// }
1253template <class MCSubtargetInfoImpl> struct RegisterMCSubtargetInfo {
1257
1258private:
1259 static MCSubtargetInfo *Allocator(const Triple & /*TT*/, StringRef /*CPU*/,
1260 StringRef /*FS*/) {
1261 return new MCSubtargetInfoImpl();
1262 }
1263};
1264
1265/// RegisterMCSubtargetInfoFn - Helper template for registering a target
1266/// subtarget info implementation. This invokes the specified function to
1267/// do the construction. Usage:
1268///
1269/// extern "C" void LLVMInitializeFooTarget() {
1270/// extern Target TheFooTarget;
1271/// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1272/// }
1278
1279/// RegisterTargetMachine - Helper template for registering a target machine
1280/// implementation, for use in the target machine initialization
1281/// function. Usage:
1282///
1283/// extern "C" void LLVMInitializeFooTarget() {
1284/// extern Target TheFooTarget;
1285/// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1286/// }
1287template <class TargetMachineImpl> struct RegisterTargetMachine {
1291
1292private:
1293 static TargetMachine *
1294 Allocator(const Target &T, const Triple &TT, StringRef CPU, StringRef FS,
1295 const TargetOptions &Options, std::optional<Reloc::Model> RM,
1296 std::optional<CodeModel::Model> CM, CodeGenOptLevel OL, bool JIT) {
1297 return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL, JIT);
1298 }
1299};
1300
1301/// RegisterMCAsmBackend - Helper template for registering a target specific
1302/// assembler backend. Usage:
1303///
1304/// extern "C" void LLVMInitializeFooMCAsmBackend() {
1305/// extern Target TheFooTarget;
1306/// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1307/// }
1308template <class MCAsmBackendImpl> struct RegisterMCAsmBackend {
1312
1313private:
1314 static MCAsmBackend *Allocator(const Target &T, const MCSubtargetInfo &STI,
1315 const MCRegisterInfo &MRI,
1316 const MCTargetOptions &Options) {
1317 return new MCAsmBackendImpl(T, STI, MRI);
1318 }
1319};
1320
1321/// RegisterMCAsmParser - Helper template for registering a target specific
1322/// assembly parser, for use in the target machine initialization
1323/// function. Usage:
1324///
1325/// extern "C" void LLVMInitializeFooMCAsmParser() {
1326/// extern Target TheFooTarget;
1327/// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1328/// }
1329template <class MCAsmParserImpl> struct RegisterMCAsmParser {
1333
1334private:
1335 static MCTargetAsmParser *Allocator(const MCSubtargetInfo &STI,
1336 MCAsmParser &P, const MCInstrInfo &MII,
1337 const MCTargetOptions &Options) {
1338 return new MCAsmParserImpl(STI, P, MII, Options);
1339 }
1340};
1341
1342/// RegisterAsmPrinter - Helper template for registering a target specific
1343/// assembly printer, for use in the target machine initialization
1344/// function. Usage:
1345///
1346/// extern "C" void LLVMInitializeFooAsmPrinter() {
1347/// extern Target TheFooTarget;
1348/// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1349/// }
1350template <class AsmPrinterImpl> struct RegisterAsmPrinter {
1354
1355private:
1357 std::unique_ptr<MCStreamer> &&Streamer) {
1358 return new AsmPrinterImpl(TM, std::move(Streamer));
1359 }
1360};
1361
1362/// RegisterMCCodeEmitter - Helper template for registering a target specific
1363/// machine code emitter, for use in the target initialization
1364/// function. Usage:
1365///
1366/// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1367/// extern Target TheFooTarget;
1368/// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1369/// }
1370template <class MCCodeEmitterImpl> struct RegisterMCCodeEmitter {
1374
1375private:
1376 static MCCodeEmitter *Allocator(const MCInstrInfo & /*II*/,
1377 MCContext & /*Ctx*/) {
1378 return new MCCodeEmitterImpl();
1379 }
1380};
1381
1382} // end namespace llvm
1383
1384#endif // LLVM_MC_TARGETREGISTRY_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#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:222
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:95
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
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
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
MCStreamer *(*)(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&Emitter) MachOStreamerCtorTy
MCLFIRewriter *(*)(MCContext &Ctx, std::unique_ptr< MCRegisterInfo > &&RegInfo, std::unique_ptr< MCInstrInfo > &&InstInfo) MCLFIRewriterCtorTy
MCTargetStreamer * createAsmTargetStreamer(MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *InstPrint) const
MCInstrAnalysis *(*)(const MCInstrInfo *Info) MCInstrAnalysisCtorFnTy
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.
MCLFIRewriter * createMCLFIRewriter(MCContext &Ctx, std::unique_ptr< MCRegisterInfo > &&RegInfo, std::unique_ptr< MCInstrInfo > &&InstInfo) const
MCDisassembler * createMCDisassembler(const MCSubtargetInfo &STI, MCContext &Ctx) const
bool hasMCAsmBackend() const
hasMCAsmBackend - Check if this target supports .o generation.
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, -Oz
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 RegisterMCLFIRewriter(Target &T, Target::MCLFIRewriterCtorTy Fn)
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