LLVM 23.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
15#include "llvm/MC/MCStreamer.h"
16#include <string>
17#include <utility>
18
19namespace llvm {
20
21class MCELFStreamer;
22class MCSymbol;
24
25namespace AMDGPU {
26
29namespace HSAMD {
30struct Metadata;
31}
32
33struct FuncInfo {
38 bool UsesVCC = false;
39 bool UsesFlatScratch = false;
40 bool HasDynStack = false;
41
42 MCSymbol *Sym = nullptr;
43};
44
52
53} // namespace AMDGPU
54
56 AMDGPUPALMetadata PALMetadata;
57
58protected:
59 // TODO: Move HSAMetadataStream to AMDGPUTargetStreamer.
60 std::optional<AMDGPU::IsaInfo::AMDGPUTargetID> TargetID;
62
63 MCContext &getContext() const { return Streamer.getContext(); }
64
65public:
68 // Assume the default COV for now, EmitDirectiveAMDHSACodeObjectVersion
69 // will update this if it is encountered.
70 CodeObjectVersion(AMDGPU::getDefaultAMDHSACodeObjectVersion()) {}
71
72 AMDGPUPALMetadata *getPALMetadata() { return &PALMetadata; }
73
74 virtual void EmitDirectiveAMDGCNTarget(){};
75
76 virtual void EmitDirectiveAMDHSACodeObjectVersion(unsigned COV) {
78 }
79
81
82 virtual void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type){};
83
84 virtual void emitAMDGPULDS(MCSymbol *Symbol, unsigned Size, Align Alignment) {
85 }
86
87 virtual void EmitMCResourceInfo(
88 const MCSymbol *NumVGPR, const MCSymbol *NumAGPR,
89 const MCSymbol *NumExplicitSGPR, const MCSymbol *NumNamedBarrier,
90 const MCSymbol *PrivateSegmentSize, const MCSymbol *UsesVCC,
91 const MCSymbol *UsesFlatScratch, const MCSymbol *HasDynamicallySizedStack,
92 const MCSymbol *HasRecursion, const MCSymbol *HasIndirectCall) {};
93
94 virtual void EmitMCResourceMaximums(const MCSymbol *MaxVGPR,
95 const MCSymbol *MaxAGPR,
96 const MCSymbol *MaxSGPR,
97 const MCSymbol *MaxNamedBarrier) {};
98
99 /// \returns True on success, false on failure.
100 virtual bool EmitISAVersion() { return true; }
101
102 /// \returns True on success, false on failure.
103 virtual bool EmitHSAMetadataV3(StringRef HSAMetadataString);
104
105 /// Emit HSA Metadata
106 ///
107 /// When \p Strict is true, known metadata elements must already be
108 /// well-typed. When \p Strict is false, known types are inferred and
109 /// the \p HSAMetadata structure is updated with the correct types.
110 ///
111 /// \returns True on success, false on failure.
112 virtual bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict) {
113 return true;
114 }
115
116 /// \returns True on success, false on failure.
117 virtual bool EmitHSAMetadata(const AMDGPU::HSAMD::Metadata &HSAMetadata) {
118 return true;
119 }
120
121 /// \returns True on success, false on failure.
122 virtual bool EmitCodeEnd(const MCSubtargetInfo &STI) { return true; }
123
124 virtual void
126 const AMDGPU::MCKernelDescriptor &KernelDescriptor,
127 const MCExpr *NextVGPR, const MCExpr *NextSGPR,
128 const MCExpr *ReserveVCC,
129 const MCExpr *ReserveFlatScr) {}
130
132
133 static StringRef getArchNameFromElfMach(unsigned ElfMach);
134 static unsigned getElfMach(StringRef GPU);
135
136 const std::optional<AMDGPU::IsaInfo::AMDGPUTargetID> &getTargetID() const {
137 return TargetID;
138 }
139 std::optional<AMDGPU::IsaInfo::AMDGPUTargetID> &getTargetID() {
140 return TargetID;
141 }
143 assert(TargetID == std::nullopt && "TargetID can only be initialized once");
144 TargetID.emplace(STI);
145 }
146 void initializeTargetID(const MCSubtargetInfo &STI, StringRef FeatureString) {
148
149 assert(getTargetID() != std::nullopt && "TargetID is None");
150 getTargetID()->setTargetIDFromFeaturesString(FeatureString);
151 }
152};
153
156public:
158
159 void finish() override;
160
161 void EmitDirectiveAMDGCNTarget() override;
162
163 void EmitDirectiveAMDHSACodeObjectVersion(unsigned COV) override;
164
165 void EmitAMDKernelCodeT(AMDGPU::AMDGPUMCKernelCodeT &Header) override;
166
167 void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) override;
168
169 void emitAMDGPULDS(MCSymbol *Sym, unsigned Size, Align Alignment) override;
170
172 const MCSymbol *NumVGPR, const MCSymbol *NumAGPR,
173 const MCSymbol *NumExplicitSGPR, const MCSymbol *NumNamedBarrier,
174 const MCSymbol *PrivateSegmentSize, const MCSymbol *UsesVCC,
175 const MCSymbol *UsesFlatScratch, const MCSymbol *HasDynamicallySizedStack,
176 const MCSymbol *HasRecursion, const MCSymbol *HasIndirectCall) override;
177
178 void EmitMCResourceMaximums(const MCSymbol *MaxVGPR, const MCSymbol *MaxAGPR,
179 const MCSymbol *MaxSGPR,
180 const MCSymbol *MaxNamedBarrier) override;
181
182 /// \returns True on success, false on failure.
183 bool EmitISAVersion() override;
184
185 /// \returns True on success, false on failure.
186 bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict) override;
187
188 /// \returns True on success, false on failure.
189 bool EmitCodeEnd(const MCSubtargetInfo &STI) override;
190
191 void
193 const AMDGPU::MCKernelDescriptor &KernelDescriptor,
194 const MCExpr *NextVGPR, const MCExpr *NextSGPR,
195 const MCExpr *ReserveVCC,
196 const MCExpr *ReserveFlatScr) override;
197
198 void emitAMDGPUInfo(const AMDGPU::InfoSectionData &Data) override;
199};
200
202 const MCSubtargetInfo &STI;
203 MCStreamer &Streamer;
204
205 void EmitNote(StringRef Name, const MCExpr *DescSize, unsigned NoteType,
206 function_ref<void(MCELFStreamer &)> EmitDesc);
207
208 unsigned getEFlags();
209
210 unsigned getEFlagsR600();
211 unsigned getEFlagsAMDGCN();
212
213 unsigned getEFlagsUnknownOS();
214 unsigned getEFlagsAMDHSA();
215 unsigned getEFlagsAMDPAL();
216 unsigned getEFlagsMesa3D();
217
218 unsigned getEFlagsV3();
219 unsigned getEFlagsV4();
220 unsigned getEFlagsV6();
221
222public:
224
226
227 void finish() override;
228
229 void EmitDirectiveAMDGCNTarget() override;
230
231 void EmitAMDKernelCodeT(AMDGPU::AMDGPUMCKernelCodeT &Header) override;
232
233 void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) override;
234
235 void emitAMDGPULDS(MCSymbol *Sym, unsigned Size, Align Alignment) override;
236
237 /// \returns True on success, false on failure.
238 bool EmitISAVersion() override;
239
240 /// \returns True on success, false on failure.
241 bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict) override;
242
243 /// \returns True on success, false on failure.
244 bool EmitCodeEnd(const MCSubtargetInfo &STI) override;
245
246 void
248 const AMDGPU::MCKernelDescriptor &KernelDescriptor,
249 const MCExpr *NextVGPR, const MCExpr *NextSGPR,
250 const MCExpr *ReserveVCC,
251 const MCExpr *ReserveFlatScr) override;
252
253 void emitAMDGPUInfo(const AMDGPU::InfoSectionData &Data) override;
254};
255}
256#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
PAL metadata handling.
This file defines the SmallVector class.
void emitAMDGPUInfo(const AMDGPU::InfoSectionData &Data) override
AMDGPUTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS)
bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict) override
void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) override
void EmitDirectiveAMDHSACodeObjectVersion(unsigned COV) override
void EmitMCResourceMaximums(const MCSymbol *MaxVGPR, const MCSymbol *MaxAGPR, const MCSymbol *MaxSGPR, const MCSymbol *MaxNamedBarrier) 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
void EmitMCResourceInfo(const MCSymbol *NumVGPR, const MCSymbol *NumAGPR, const MCSymbol *NumExplicitSGPR, const MCSymbol *NumNamedBarrier, const MCSymbol *PrivateSegmentSize, const MCSymbol *UsesVCC, const MCSymbol *UsesFlatScratch, const MCSymbol *HasDynamicallySizedStack, const MCSymbol *HasRecursion, const MCSymbol *HasIndirectCall) 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
AMDGPUTargetELFStreamer(MCStreamer &S, const MCSubtargetInfo &STI)
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
void emitAMDGPUInfo(const AMDGPU::InfoSectionData &Data) 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.
virtual void emitAMDGPUInfo(const AMDGPU::InfoSectionData &Data)
AMDGPUPALMetadata * getPALMetadata()
virtual void EmitDirectiveAMDHSACodeObjectVersion(unsigned COV)
void initializeTargetID(const MCSubtargetInfo &STI)
virtual void emitAMDGPULDS(MCSymbol *Symbol, unsigned Size, Align Alignment)
virtual bool EmitHSAMetadataV3(StringRef HSAMetadataString)
virtual void EmitMCResourceInfo(const MCSymbol *NumVGPR, const MCSymbol *NumAGPR, const MCSymbol *NumExplicitSGPR, const MCSymbol *NumNamedBarrier, const MCSymbol *PrivateSegmentSize, const MCSymbol *UsesVCC, const MCSymbol *UsesFlatScratch, const MCSymbol *HasDynamicallySizedStack, const MCSymbol *HasRecursion, const MCSymbol *HasIndirectCall)
std::optional< AMDGPU::IsaInfo::AMDGPUTargetID > & getTargetID()
virtual bool EmitCodeEnd(const MCSubtargetInfo &STI)
static unsigned getElfMach(StringRef GPU)
virtual void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type)
void initializeTargetID(const MCSubtargetInfo &STI, StringRef FeatureString)
virtual void EmitAMDKernelCodeT(AMDGPU::AMDGPUMCKernelCodeT &Header)
virtual bool EmitHSAMetadata(const AMDGPU::HSAMD::Metadata &HSAMetadata)
static StringRef getArchNameFromElfMach(unsigned ElfMach)
const std::optional< AMDGPU::IsaInfo::AMDGPUTargetID > & getTargetID() const
virtual void EmitMCResourceMaximums(const MCSymbol *MaxVGPR, const MCSymbol *MaxAGPR, const MCSymbol *MaxSGPR, const MCSymbol *MaxNamedBarrier)
std::optional< AMDGPU::IsaInfo::AMDGPUTargetID > TargetID
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:222
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:42
MCStreamer & Streamer
Definition MCStreamer.h:97
MCTargetStreamer(MCStreamer &S)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
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.
FunctionAddr VTableAddr uintptr_t uintptr_t Data
Definition InstrProf.h:221
In-memory representation of HSA metadata.
SmallVector< std::pair< MCSymbol *, std::string >, 4 > IndirectCalls
SmallVector< std::pair< MCSymbol *, MCSymbol * >, 8 > Calls
SmallVector< FuncInfo, 8 > Funcs
SmallVector< std::pair< MCSymbol *, std::string >, 4 > TypeIds
SmallVector< std::pair< MCSymbol *, MCSymbol * >, 4 > Uses
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39