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 if (!isValidFeatureListFormat(Features))
470 return nullptr;
471 return MCSubtargetInfoCtorFn(TheTriple, CPU, Features);
472 }
473
474 /// createTargetMachine - Create a target specific machine implementation
475 /// for the specified \p Triple.
476 ///
477 /// \param TT This argument is used to determine the target machine
478 /// feature set; it should always be provided. Generally this should be
479 /// either the target triple from the module, or the target triple of the
480 /// host if that does not exist.
482 const Triple &TT, StringRef CPU, StringRef Features,
483 const TargetOptions &Options, std::optional<Reloc::Model> RM,
484 std::optional<CodeModel::Model> CM = std::nullopt,
485 CodeGenOptLevel OL = CodeGenOptLevel::Default, bool JIT = false) const {
486 if (!TargetMachineCtorFn)
487 return nullptr;
488 return TargetMachineCtorFn(*this, TT, CPU, Features, Options, RM, CM, OL,
489 JIT);
490 }
491
492 /// createMCAsmBackend - Create a target specific assembly parser.
494 const MCRegisterInfo &MRI,
495 const MCTargetOptions &Options) const {
496 if (!MCAsmBackendCtorFn)
497 return nullptr;
498 return MCAsmBackendCtorFn(*this, STI, MRI, Options);
499 }
500
501 /// createMCAsmParser - Create a target specific assembly parser.
502 ///
503 /// \param Parser The target independent parser implementation to use for
504 /// parsing and lexing.
506 MCAsmParser &Parser,
507 const MCInstrInfo &MII,
508 const MCTargetOptions &Options) const {
509 if (!MCAsmParserCtorFn)
510 return nullptr;
511 return MCAsmParserCtorFn(STI, Parser, MII, Options);
512 }
513
514 /// createAsmPrinter - Create a target specific assembly printer pass. This
515 /// takes ownership of the MCStreamer object.
517 std::unique_ptr<MCStreamer> &&Streamer) const {
518 if (!AsmPrinterCtorFn)
519 return nullptr;
520 return AsmPrinterCtorFn(TM, std::move(Streamer));
521 }
522
524 MCContext &Ctx) const {
525 if (!MCDisassemblerCtorFn)
526 return nullptr;
527 return MCDisassemblerCtorFn(*this, STI, Ctx);
528 }
529
530 MCInstPrinter *createMCInstPrinter(const Triple &T, unsigned SyntaxVariant,
531 const MCAsmInfo &MAI,
532 const MCInstrInfo &MII,
533 const MCRegisterInfo &MRI) const {
534 if (!MCInstPrinterCtorFn)
535 return nullptr;
536 return MCInstPrinterCtorFn(T, SyntaxVariant, MAI, MII, MRI);
537 }
538
539 /// createMCCodeEmitter - Create a target specific code emitter.
541 MCContext &Ctx) const {
542 if (!MCCodeEmitterCtorFn)
543 return nullptr;
544 return MCCodeEmitterCtorFn(II, Ctx);
545 }
546
547 /// Create a target specific MCStreamer.
548 ///
549 /// \param T The target triple.
550 /// \param Ctx The target context.
551 /// \param TAB The target assembler backend object. Takes ownership.
552 /// \param OW The stream object.
553 /// \param Emitter The target independent assembler object.Takes ownership.
555 const Triple &T, MCContext &Ctx, std::unique_ptr<MCAsmBackend> TAB,
556 std::unique_ptr<MCObjectWriter> OW,
557 std::unique_ptr<MCCodeEmitter> Emitter, const MCSubtargetInfo &STI) const;
558
560 createAsmStreamer(MCContext &Ctx, std::unique_ptr<formatted_raw_ostream> OS,
561 std::unique_ptr<MCInstPrinter> IP,
562 std::unique_ptr<MCCodeEmitter> CE,
563 std::unique_ptr<MCAsmBackend> TAB) const;
564
567 MCInstPrinter *InstPrint) const {
568 if (AsmTargetStreamerCtorFn)
569 return AsmTargetStreamerCtorFn(S, OS, InstPrint);
570 return nullptr;
571 }
572
576 return S;
577 }
578
580 if (NullTargetStreamerCtorFn)
581 return NullTargetStreamerCtorFn(S);
582 return nullptr;
583 }
584
586 createMCLFIRewriter(MCContext &Ctx, std::unique_ptr<MCRegisterInfo> &&RegInfo,
587 std::unique_ptr<MCInstrInfo> &&InstInfo) const {
588 if (MCLFIRewriterCtorFn)
589 return MCLFIRewriterCtorFn(Ctx, std::move(RegInfo), std::move(InstInfo));
590 return nullptr;
591 }
592
593 /// createMCRelocationInfo - Create a target specific MCRelocationInfo.
594 ///
595 /// \param TT The target triple.
596 /// \param Ctx The target context.
598 MCContext &Ctx) const {
599 MCRelocationInfoCtorTy Fn = MCRelocationInfoCtorFn
600 ? MCRelocationInfoCtorFn
602 return Fn(TT, Ctx);
603 }
604
605 /// createMCSymbolizer - Create a target specific MCSymbolizer.
606 ///
607 /// \param TT The target triple.
608 /// \param GetOpInfo The function to get the symbolic information for
609 /// operands.
610 /// \param SymbolLookUp The function to lookup a symbol name.
611 /// \param DisInfo The pointer to the block of symbolic information for above
612 /// call
613 /// back.
614 /// \param Ctx The target context.
615 /// \param RelInfo The relocation information for this target. Takes
616 /// ownership.
619 LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo,
620 MCContext *Ctx,
621 std::unique_ptr<MCRelocationInfo> &&RelInfo) const {
623 MCSymbolizerCtorFn ? MCSymbolizerCtorFn : llvm::createMCSymbolizer;
624 return Fn(TT, GetOpInfo, SymbolLookUp, DisInfo, Ctx, std::move(RelInfo));
625 }
626
627 /// createCustomBehaviour - Create a target specific CustomBehaviour.
628 /// This class is used by llvm-mca and requires backend functionality.
630 const mca::SourceMgr &SrcMgr,
631 const MCInstrInfo &MCII) const {
632 if (CustomBehaviourCtorFn)
633 return CustomBehaviourCtorFn(STI, SrcMgr, MCII);
634 return nullptr;
635 }
636
637 /// createInstrPostProcess - Create a target specific InstrPostProcess.
638 /// This class is used by llvm-mca and requires backend functionality.
640 const MCInstrInfo &MCII) const {
641 if (InstrPostProcessCtorFn)
642 return InstrPostProcessCtorFn(STI, MCII);
643 return nullptr;
644 }
645
646 /// createInstrumentManager - Create a target specific
647 /// InstrumentManager. This class is used by llvm-mca and requires
648 /// backend functionality.
651 const MCInstrInfo &MCII) const {
652 if (InstrumentManagerCtorFn)
653 return InstrumentManagerCtorFn(STI, MCII);
654 return nullptr;
655 }
656
657 /// isValidFeatureListFormat - check that FeatureString
658 /// has the format:
659 /// "+attr1,+attr2,-attr3,...,+attrN"
660 /// A comma separates each feature from the next (all lowercase).
661 /// Each of the remaining features is prefixed with '+' or '-' indicating
662 /// whether that feature should be enabled or disabled contrary to the cpu
663 /// specification.
664 /// The string must match exactly that format otherwise
665 /// MCSubtargetInfo::ApplyFeatureFlag will fail.
666 /// For example feature string "+a,+m,c" is accepted, and results in feature
667 /// list {"+a", "+m", "c"}. Later in ApplyFeatureFlag, it asserts
668 /// that all features must start with '+' or '-' and assert is failed.
669 static bool isValidFeatureListFormat(StringRef FeaturesString);
670
671 /// @}
672};
673
674/// TargetRegistry - Generic interface to target specific features.
676 // FIXME: Make this a namespace, probably just move all the Register*
677 // functions into Target (currently they all just set members on the Target
678 // anyway, and Target friends this class so those functions can...
679 // function).
680 TargetRegistry() = delete;
681
682 class iterator {
683 friend struct TargetRegistry;
684
685 const Target *Current = nullptr;
686
687 explicit iterator(Target *T) : Current(T) {}
688
689 public:
690 using iterator_category = std::forward_iterator_tag;
692 using difference_type = std::ptrdiff_t;
695
696 iterator() = default;
697
698 bool operator==(const iterator &x) const { return Current == x.Current; }
699 bool operator!=(const iterator &x) const { return !operator==(x); }
700
701 // Iterator traversal: forward iteration only
702 iterator &operator++() { // Preincrement
703 assert(Current && "Cannot increment end iterator!");
704 Current = Current->getNext();
705 return *this;
706 }
707 iterator operator++(int) { // Postincrement
708 iterator tmp = *this;
709 ++*this;
710 return tmp;
711 }
712
713 const Target &operator*() const {
714 assert(Current && "Cannot dereference end iterator!");
715 return *Current;
716 }
717
718 const Target *operator->() const { return &operator*(); }
719 };
720
721 /// printRegisteredTargetsForVersion - Print the registered targets
722 /// appropriately for inclusion in a tool's version output.
724
725 /// @name Registry Access
726 /// @{
727
729
730 /// lookupTarget - Lookup a target based on a target triple.
731 ///
732 /// \param TripleStr - The triple to use for finding a target.
733 /// \param Error - On failure, an error string describing why no target was
734 /// found.
735 // TODO(boomanaiden154): Remove this function after LLVM 22 branches.
736 [[deprecated("Use overload accepting Triple instead")]]
737 static const Target *lookupTarget(StringRef TripleStr, std::string &Error) {
738 return lookupTarget(Triple(TripleStr), Error);
739 }
740
741 /// lookupTarget - Lookup a target based on a target triple.
742 ///
743 /// \param Triple - The triple to use for finding a target.
744 /// \param Error - On failure, an error string describing why no target was
745 /// found.
746 LLVM_ABI static const Target *lookupTarget(const Triple &TheTriple,
747 std::string &Error);
748
749 /// lookupTarget - Lookup a target based on an architecture name
750 /// and a target triple. If the architecture name is non-empty,
751 /// then the lookup is done by architecture. Otherwise, the target
752 /// triple is used.
753 ///
754 /// \param ArchName - The architecture to use for finding a target.
755 /// \param TheTriple - The triple to use for finding a target. The
756 /// triple is updated with canonical architecture name if a lookup
757 /// by architecture is done.
758 /// \param Error - On failure, an error string describing why no target was
759 /// found.
760 LLVM_ABI static const Target *
761 lookupTarget(StringRef ArchName, Triple &TheTriple, std::string &Error);
762
763 /// @}
764 /// @name Target Registration
765 /// @{
766
767 /// RegisterTarget - Register the given target. Attempts to register a
768 /// target which has already been registered will be ignored.
769 ///
770 /// Clients are responsible for ensuring that registration doesn't occur
771 /// while another thread is attempting to access the registry. Typically
772 /// this is done by initializing all targets at program startup.
773 ///
774 /// @param T - The target being registered.
775 /// @param Name - The target name. This should be a static string.
776 /// @param ShortDesc - A short target description. This should be a static
777 /// string.
778 /// @param BackendName - The name of the backend. This should be a static
779 /// string that is the same for all targets that share a backend
780 /// implementation and must match the name used in the 'def X : Target ...' in
781 /// TableGen.
782 /// @param ArchMatchFn - The arch match checking function for this target.
783 /// @param HasJIT - Whether the target supports JIT code
784 /// generation.
785 LLVM_ABI static void RegisterTarget(Target &T, const char *Name,
786 const char *ShortDesc,
787 const char *BackendName,
788 Target::ArchMatchFnTy ArchMatchFn,
789 bool HasJIT = false);
790
791 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
792 /// given target.
793 ///
794 /// Clients are responsible for ensuring that registration doesn't occur
795 /// while another thread is attempting to access the registry. Typically
796 /// this is done by initializing all targets at program startup.
797 ///
798 /// @param T - The target being registered.
799 /// @param Fn - A function to construct a MCAsmInfo for the target.
801 T.MCAsmInfoCtorFn = Fn;
802 }
803
804 /// Register a MCObjectFileInfo implementation for the given target.
805 ///
806 /// Clients are responsible for ensuring that registration doesn't occur
807 /// while another thread is attempting to access the registry. Typically
808 /// this is done by initializing all targets at program startup.
809 ///
810 /// @param T - The target being registered.
811 /// @param Fn - A function to construct a MCObjectFileInfo for the target.
814 T.MCObjectFileInfoCtorFn = Fn;
815 }
816
817 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
818 /// given target.
819 ///
820 /// Clients are responsible for ensuring that registration doesn't occur
821 /// while another thread is attempting to access the registry. Typically
822 /// this is done by initializing all targets at program startup.
823 ///
824 /// @param T - The target being registered.
825 /// @param Fn - A function to construct a MCInstrInfo for the target.
827 T.MCInstrInfoCtorFn = Fn;
828 }
829
830 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
831 /// the given target.
834 T.MCInstrAnalysisCtorFn = Fn;
835 }
836
837 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
838 /// given target.
839 ///
840 /// Clients are responsible for ensuring that registration doesn't occur
841 /// while another thread is attempting to access the registry. Typically
842 /// this is done by initializing all targets at program startup.
843 ///
844 /// @param T - The target being registered.
845 /// @param Fn - A function to construct a MCRegisterInfo for the target.
847 T.MCRegInfoCtorFn = Fn;
848 }
849
850 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
851 /// the given target.
852 ///
853 /// Clients are responsible for ensuring that registration doesn't occur
854 /// while another thread is attempting to access the registry. Typically
855 /// this is done by initializing all targets at program startup.
856 ///
857 /// @param T - The target being registered.
858 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
861 T.MCSubtargetInfoCtorFn = Fn;
862 }
863
864 /// RegisterTargetMachine - Register a TargetMachine implementation for the
865 /// given target.
866 ///
867 /// Clients are responsible for ensuring that registration doesn't occur
868 /// while another thread is attempting to access the registry. Typically
869 /// this is done by initializing all targets at program startup.
870 ///
871 /// @param T - The target being registered.
872 /// @param Fn - A function to construct a TargetMachine for the target.
874 T.TargetMachineCtorFn = Fn;
875 }
876
877 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
878 /// given target.
879 ///
880 /// Clients are responsible for ensuring that registration doesn't occur
881 /// while another thread is attempting to access the registry. Typically
882 /// this is done by initializing all targets at program startup.
883 ///
884 /// @param T - The target being registered.
885 /// @param Fn - A function to construct an AsmBackend for the target.
887 T.MCAsmBackendCtorFn = Fn;
888 }
889
890 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
891 /// the given target.
892 ///
893 /// Clients are responsible for ensuring that registration doesn't occur
894 /// while another thread is attempting to access the registry. Typically
895 /// this is done by initializing all targets at program startup.
896 ///
897 /// @param T - The target being registered.
898 /// @param Fn - A function to construct an MCTargetAsmParser for the target.
900 T.MCAsmParserCtorFn = Fn;
901 }
902
903 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
904 /// target.
905 ///
906 /// Clients are responsible for ensuring that registration doesn't occur
907 /// while another thread is attempting to access the registry. Typically
908 /// this is done by initializing all targets at program startup.
909 ///
910 /// @param T - The target being registered.
911 /// @param Fn - A function to construct an AsmPrinter for the target.
913 T.AsmPrinterCtorFn = Fn;
914 }
915
916 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
917 /// the given target.
918 ///
919 /// Clients are responsible for ensuring that registration doesn't occur
920 /// while another thread is attempting to access the registry. Typically
921 /// this is done by initializing all targets at program startup.
922 ///
923 /// @param T - The target being registered.
924 /// @param Fn - A function to construct an MCDisassembler for the target.
927 T.MCDisassemblerCtorFn = Fn;
928 }
929
930 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
931 /// given target.
932 ///
933 /// Clients are responsible for ensuring that registration doesn't occur
934 /// while another thread is attempting to access the registry. Typically
935 /// this is done by initializing all targets at program startup.
936 ///
937 /// @param T - The target being registered.
938 /// @param Fn - A function to construct an MCInstPrinter for the target.
940 T.MCInstPrinterCtorFn = Fn;
941 }
942
943 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
944 /// given target.
945 ///
946 /// Clients are responsible for ensuring that registration doesn't occur
947 /// while another thread is attempting to access the registry. Typically
948 /// this is done by initializing all targets at program startup.
949 ///
950 /// @param T - The target being registered.
951 /// @param Fn - A function to construct an MCCodeEmitter for the target.
953 T.MCCodeEmitterCtorFn = Fn;
954 }
955
957 T.COFFStreamerCtorFn = Fn;
958 }
959
961 T.MachOStreamerCtorFn = Fn;
962 }
963
965 T.ELFStreamerCtorFn = Fn;
966 }
967
969 T.XCOFFStreamerCtorFn = Fn;
970 }
971
974 T.NullTargetStreamerCtorFn = Fn;
975 }
976
978 T.AsmStreamerCtorFn = Fn;
979 }
980
983 T.AsmTargetStreamerCtorFn = Fn;
984 }
985
986 static void
989 T.ObjectTargetStreamerCtorFn = Fn;
990 }
991
992 /// RegisterMCRelocationInfo - Register an MCRelocationInfo
993 /// implementation for the given target.
994 ///
995 /// Clients are responsible for ensuring that registration doesn't occur
996 /// while another thread is attempting to access the registry. Typically
997 /// this is done by initializing all targets at program startup.
998 ///
999 /// @param T - The target being registered.
1000 /// @param Fn - A function to construct an MCRelocationInfo for the target.
1003 T.MCRelocationInfoCtorFn = Fn;
1004 }
1005
1006 /// RegisterMCSymbolizer - Register an MCSymbolizer
1007 /// implementation for the given target.
1008 ///
1009 /// Clients are responsible for ensuring that registration doesn't occur
1010 /// while another thread is attempting to access the registry. Typically
1011 /// this is done by initializing all targets at program startup.
1012 ///
1013 /// @param T - The target being registered.
1014 /// @param Fn - A function to construct an MCSymbolizer for the target.
1016 T.MCSymbolizerCtorFn = Fn;
1017 }
1018
1019 /// RegisterCustomBehaviour - Register a CustomBehaviour
1020 /// implementation for the given target.
1021 ///
1022 /// Clients are responsible for ensuring that registration doesn't occur
1023 /// while another thread is attempting to access the registry. Typically
1024 /// this is done by initializing all targets at program startup.
1025 ///
1026 /// @param T - The target being registered.
1027 /// @param Fn - A function to construct a CustomBehaviour for the target.
1030 T.CustomBehaviourCtorFn = Fn;
1031 }
1032
1033 /// RegisterInstrPostProcess - Register an InstrPostProcess
1034 /// implementation for the given target.
1035 ///
1036 /// Clients are responsible for ensuring that registration doesn't occur
1037 /// while another thread is attempting to access the registry. Typically
1038 /// this is done by initializing all targets at program startup.
1039 ///
1040 /// @param T - The target being registered.
1041 /// @param Fn - A function to construct an InstrPostProcess for the target.
1044 T.InstrPostProcessCtorFn = Fn;
1045 }
1046
1047 /// RegisterInstrumentManager - Register an InstrumentManager
1048 /// implementation for the given target.
1049 ///
1050 /// Clients are responsible for ensuring that registration doesn't occur
1051 /// while another thread is attempting to access the registry. Typically
1052 /// this is done by initializing all targets at program startup.
1053 ///
1054 /// @param T - The target being registered.
1055 /// @param Fn - A function to construct an InstrumentManager for the
1056 /// target.
1059 T.InstrumentManagerCtorFn = Fn;
1060 }
1061
1063 T.MCLFIRewriterCtorFn = 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
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
static bool isValidFeatureListFormat(StringRef FeaturesString)
isValidFeatureListFormat - check that FeatureString has the format: "+attr1,+attr2,...
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