LLVM 20.0.0git
AMDGPUTargetStreamer.h
Go to the documentation of this file.
1//===-- AMDGPUTargetStreamer.h - AMDGPU Target Streamer --------*- 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#ifndef LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUTARGETSTREAMER_H
10#define LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUTARGETSTREAMER_H
11
14#include "llvm/MC/MCStreamer.h"
15
16namespace llvm {
17
18class MCELFStreamer;
19class MCSymbol;
20class formatted_raw_ostream;
21
22namespace AMDGPU {
23
24struct AMDGPUMCKernelCodeT;
25struct MCKernelDescriptor;
26namespace HSAMD {
27struct Metadata;
28}
29} // namespace AMDGPU
30
32 AMDGPUPALMetadata PALMetadata;
33
34protected:
35 // TODO: Move HSAMetadataStream to AMDGPUTargetStreamer.
36 std::optional<AMDGPU::IsaInfo::AMDGPUTargetID> TargetID;
38
39 MCContext &getContext() const { return Streamer.getContext(); }
40
41public:
44 // Assume the default COV for now, EmitDirectiveAMDHSACodeObjectVersion
45 // will update this if it is encountered.
46 CodeObjectVersion(AMDGPU::getDefaultAMDHSACodeObjectVersion()) {}
47
48 AMDGPUPALMetadata *getPALMetadata() { return &PALMetadata; }
49
50 virtual void EmitDirectiveAMDGCNTarget(){};
51
52 virtual void EmitDirectiveAMDHSACodeObjectVersion(unsigned COV) {
54 }
55
57
58 virtual void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type){};
59
60 virtual void emitAMDGPULDS(MCSymbol *Symbol, unsigned Size, Align Alignment) {
61 }
62
63 virtual void EmitMCResourceInfo(
64 const MCSymbol *NumVGPR, const MCSymbol *NumAGPR,
65 const MCSymbol *NumExplicitSGPR, const MCSymbol *PrivateSegmentSize,
66 const MCSymbol *UsesVCC, const MCSymbol *UsesFlatScratch,
67 const MCSymbol *HasDynamicallySizedStack, const MCSymbol *HasRecursion,
68 const MCSymbol *HasIndirectCall) {};
69
70 virtual void EmitMCResourceMaximums(const MCSymbol *MaxVGPR,
71 const MCSymbol *MaxAGPR,
72 const MCSymbol *MaxSGPR) {};
73
74 /// \returns True on success, false on failure.
75 virtual bool EmitISAVersion() { return true; }
76
77 /// \returns True on success, false on failure.
78 virtual bool EmitHSAMetadataV3(StringRef HSAMetadataString);
79
80 /// Emit HSA Metadata
81 ///
82 /// When \p Strict is true, known metadata elements must already be
83 /// well-typed. When \p Strict is false, known types are inferred and
84 /// the \p HSAMetadata structure is updated with the correct types.
85 ///
86 /// \returns True on success, false on failure.
87 virtual bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict) {
88 return true;
89 }
90
91 /// \returns True on success, false on failure.
92 virtual bool EmitHSAMetadata(const AMDGPU::HSAMD::Metadata &HSAMetadata) {
93 return true;
94 }
95
96 /// \returns True on success, false on failure.
97 virtual bool EmitCodeEnd(const MCSubtargetInfo &STI) { return true; }
98
99 /// \returns True on success, false on failure.
101 bool TrapEnabled) {
102 return true;
103 }
104
105 virtual void
107 const AMDGPU::MCKernelDescriptor &KernelDescriptor,
108 const MCExpr *NextVGPR, const MCExpr *NextSGPR,
109 const MCExpr *ReserveVCC,
110 const MCExpr *ReserveFlatScr) {}
111
112 static StringRef getArchNameFromElfMach(unsigned ElfMach);
113 static unsigned getElfMach(StringRef GPU);
114
115 const std::optional<AMDGPU::IsaInfo::AMDGPUTargetID> &getTargetID() const {
116 return TargetID;
117 }
118 std::optional<AMDGPU::IsaInfo::AMDGPUTargetID> &getTargetID() {
119 return TargetID;
120 }
122 assert(TargetID == std::nullopt && "TargetID can only be initialized once");
123 TargetID.emplace(STI);
124 }
125 void initializeTargetID(const MCSubtargetInfo &STI, StringRef FeatureString) {
127
128 assert(getTargetID() != std::nullopt && "TargetID is None");
129 getTargetID()->setTargetIDFromFeaturesString(FeatureString);
130 }
131};
132
135public:
137
138 void finish() override;
139
140 void EmitDirectiveAMDGCNTarget() override;
141
142 void EmitDirectiveAMDHSACodeObjectVersion(unsigned COV) override;
143
144 void EmitAMDKernelCodeT(AMDGPU::AMDGPUMCKernelCodeT &Header) override;
145
146 void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) override;
147
148 void emitAMDGPULDS(MCSymbol *Sym, unsigned Size, Align Alignment) override;
149
150 void EmitMCResourceInfo(const MCSymbol *NumVGPR, const MCSymbol *NumAGPR,
151 const MCSymbol *NumExplicitSGPR,
152 const MCSymbol *PrivateSegmentSize,
153 const MCSymbol *UsesVCC,
154 const MCSymbol *UsesFlatScratch,
155 const MCSymbol *HasDynamicallySizedStack,
156 const MCSymbol *HasRecursion,
157 const MCSymbol *HasIndirectCall) override;
158
159 void EmitMCResourceMaximums(const MCSymbol *MaxVGPR, const MCSymbol *MaxAGPR,
160 const MCSymbol *MaxSGPR) override;
161
162 /// \returns True on success, false on failure.
163 bool EmitISAVersion() override;
164
165 /// \returns True on success, false on failure.
166 bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict) override;
167
168 /// \returns True on success, false on failure.
169 bool EmitCodeEnd(const MCSubtargetInfo &STI) override;
170
171 /// \returns True on success, false on failure.
173 bool TrapEnabled) override;
174
175 void
177 const AMDGPU::MCKernelDescriptor &KernelDescriptor,
178 const MCExpr *NextVGPR, const MCExpr *NextSGPR,
179 const MCExpr *ReserveVCC,
180 const MCExpr *ReserveFlatScr) override;
181};
182
184 const MCSubtargetInfo &STI;
185 MCStreamer &Streamer;
186
187 void EmitNote(StringRef Name, const MCExpr *DescSize, unsigned NoteType,
188 function_ref<void(MCELFStreamer &)> EmitDesc);
189
190 unsigned getEFlags();
191
192 unsigned getEFlagsR600();
193 unsigned getEFlagsAMDGCN();
194
195 unsigned getEFlagsUnknownOS();
196 unsigned getEFlagsAMDHSA();
197 unsigned getEFlagsAMDPAL();
198 unsigned getEFlagsMesa3D();
199
200 unsigned getEFlagsV3();
201 unsigned getEFlagsV4();
202 unsigned getEFlagsV6();
203
204public:
206
208
209 void finish() override;
210
211 void EmitDirectiveAMDGCNTarget() override;
212
213 void EmitAMDKernelCodeT(AMDGPU::AMDGPUMCKernelCodeT &Header) override;
214
215 void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) override;
216
217 void emitAMDGPULDS(MCSymbol *Sym, unsigned Size, Align Alignment) override;
218
219 /// \returns True on success, false on failure.
220 bool EmitISAVersion() override;
221
222 /// \returns True on success, false on failure.
223 bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict) override;
224
225 /// \returns True on success, false on failure.
226 bool EmitCodeEnd(const MCSubtargetInfo &STI) override;
227
228 /// \returns True on success, false on failure.
230 bool TrapEnabled) override;
231
232 void
234 const AMDGPU::MCKernelDescriptor &KernelDescriptor,
235 const MCExpr *NextVGPR, const MCExpr *NextSGPR,
236 const MCExpr *ReserveVCC,
237 const MCExpr *ReserveFlatScr) override;
238};
239}
240#endif
PAL metadata handling.
dxil translate DXIL Translate Metadata
std::string Name
uint64_t Size
Symbol * Sym
Definition: ELF_riscv.cpp:479
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
void EmitMCResourceInfo(const MCSymbol *NumVGPR, const MCSymbol *NumAGPR, const MCSymbol *NumExplicitSGPR, const MCSymbol *PrivateSegmentSize, const MCSymbol *UsesVCC, const MCSymbol *UsesFlatScratch, const MCSymbol *HasDynamicallySizedStack, const MCSymbol *HasRecursion, const MCSymbol *HasIndirectCall) override
bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict) override
void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) override
void EmitMCResourceMaximums(const MCSymbol *MaxVGPR, const MCSymbol *MaxAGPR, const MCSymbol *MaxSGPR) override
void EmitDirectiveAMDHSACodeObjectVersion(unsigned COV) override
void EmitAMDKernelCodeT(AMDGPU::AMDGPUMCKernelCodeT &Header) override
void EmitAmdhsaKernelDescriptor(const MCSubtargetInfo &STI, StringRef KernelName, const AMDGPU::MCKernelDescriptor &KernelDescriptor, const MCExpr *NextVGPR, const MCExpr *NextSGPR, const MCExpr *ReserveVCC, const MCExpr *ReserveFlatScr) override
bool EmitKernargPreloadHeader(const MCSubtargetInfo &STI, bool TrapEnabled) override
bool EmitCodeEnd(const MCSubtargetInfo &STI) override
void emitAMDGPULDS(MCSymbol *Sym, unsigned Size, Align Alignment) override
bool EmitCodeEnd(const MCSubtargetInfo &STI) override
void EmitAMDKernelCodeT(AMDGPU::AMDGPUMCKernelCodeT &Header) override
bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict) override
void emitAMDGPULDS(MCSymbol *Sym, unsigned Size, Align Alignment) override
void EmitAmdhsaKernelDescriptor(const MCSubtargetInfo &STI, StringRef KernelName, const AMDGPU::MCKernelDescriptor &KernelDescriptor, const MCExpr *NextVGPR, const MCExpr *NextSGPR, const MCExpr *ReserveVCC, const MCExpr *ReserveFlatScr) override
void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) override
bool EmitKernargPreloadHeader(const MCSubtargetInfo &STI, bool TrapEnabled) override
virtual void EmitAmdhsaKernelDescriptor(const MCSubtargetInfo &STI, StringRef KernelName, const AMDGPU::MCKernelDescriptor &KernelDescriptor, const MCExpr *NextVGPR, const MCExpr *NextSGPR, const MCExpr *ReserveVCC, const MCExpr *ReserveFlatScr)
virtual bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict)
Emit HSA Metadata.
AMDGPUPALMetadata * getPALMetadata()
virtual void EmitMCResourceInfo(const MCSymbol *NumVGPR, const MCSymbol *NumAGPR, const MCSymbol *NumExplicitSGPR, const MCSymbol *PrivateSegmentSize, const MCSymbol *UsesVCC, const MCSymbol *UsesFlatScratch, const MCSymbol *HasDynamicallySizedStack, const MCSymbol *HasRecursion, const MCSymbol *HasIndirectCall)
virtual void EmitDirectiveAMDHSACodeObjectVersion(unsigned COV)
void initializeTargetID(const MCSubtargetInfo &STI)
virtual void emitAMDGPULDS(MCSymbol *Symbol, unsigned Size, Align Alignment)
virtual bool EmitHSAMetadataV3(StringRef HSAMetadataString)
std::optional< AMDGPU::IsaInfo::AMDGPUTargetID > & getTargetID()
virtual bool EmitCodeEnd(const MCSubtargetInfo &STI)
static unsigned getElfMach(StringRef GPU)
virtual void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type)
virtual void EmitMCResourceMaximums(const MCSymbol *MaxVGPR, const MCSymbol *MaxAGPR, const MCSymbol *MaxSGPR)
void initializeTargetID(const MCSubtargetInfo &STI, StringRef FeatureString)
virtual void EmitDirectiveAMDGCNTarget()
virtual void EmitAMDKernelCodeT(AMDGPU::AMDGPUMCKernelCodeT &Header)
virtual bool EmitHSAMetadata(const AMDGPU::HSAMD::Metadata &HSAMetadata)
MCContext & getContext() const
static StringRef getArchNameFromElfMach(unsigned ElfMach)
const std::optional< AMDGPU::IsaInfo::AMDGPUTargetID > & getTargetID() const
std::optional< AMDGPU::IsaInfo::AMDGPUTargetID > TargetID
virtual bool EmitKernargPreloadHeader(const MCSubtargetInfo &STI, bool TrapEnabled)
Context object for machine code objects.
Definition: MCContext.h:83
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:34
Streaming machine code generation interface.
Definition: MCStreamer.h:213
MCContext & getContext() const
Definition: MCStreamer.h:300
Generic base class for all target subtargets.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
Target specific streamer interface.
Definition: MCStreamer.h:94
MCStreamer & Streamer
Definition: MCStreamer.h:96
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
formatted_raw_ostream - A raw_ostream that wraps another one and keeps track of line and column posit...
An efficient, type-erasing, non-owning reference to a callable.
Simple in-memory representation of a document of msgpack objects with ability to find and create arra...
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
In-memory representation of HSA metadata.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39