LLVM 24.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 bool AMDGCNTargetEmitted = false;
58
59protected:
60 // TODO: Move HSAMetadataStream to AMDGPUTargetStreamer.
61 std::optional<AMDGPU::TargetID> TargetID;
63
64 MCContext &getContext() const { return Streamer.getContext(); }
65
66public:
69 // Assume the default COV for now, EmitDirectiveAMDHSACodeObjectVersion
70 // will update this if it is encountered.
71 CodeObjectVersion(AMDGPU::getDefaultAMDHSACodeObjectVersion()) {}
72
73 AMDGPUPALMetadata *getPALMetadata() { return &PALMetadata; }
74
75 virtual void EmitDirectiveAMDGCNTarget(){};
76
77 /// Emit the .amdgcn_target directive unless it has already been emitted to
78 /// this streamer. The code generator and the parsers for any inline assembly
79 /// in the module share one streamer, and the directive must appear only once
80 /// per output file.
82 if (AMDGCNTargetEmitted)
83 return;
84 AMDGCNTargetEmitted = true;
86 }
87
88 virtual void EmitDirectiveAMDHSACodeObjectVersion(unsigned COV) {
90 }
91
93
94 virtual void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type){};
95
96 virtual void emitAMDGPULDS(MCSymbol *Symbol, unsigned Size, Align Alignment) {
97 }
98
99 virtual void EmitMCResourceInfo(
100 const MCSymbol *NumVGPR, const MCSymbol *NumAGPR,
101 const MCSymbol *NumExplicitSGPR, const MCSymbol *NumNamedBarrier,
102 const MCSymbol *PrivateSegmentSize, const MCSymbol *UsesVCC,
103 const MCSymbol *UsesFlatScratch, const MCSymbol *HasDynamicallySizedStack,
104 const MCSymbol *HasRecursion, const MCSymbol *HasIndirectCall) {};
105
106 virtual void EmitMCResourceMaximums(const MCSymbol *MaxVGPR,
107 const MCSymbol *MaxAGPR,
108 const MCSymbol *MaxSGPR,
109 const MCSymbol *MaxNamedBarrier) {};
110
111 /// \returns True on success, false on failure.
112 virtual bool EmitISAVersion() { return true; }
113
114 /// \returns True on success, false on failure.
115 virtual bool EmitHSAMetadataV3(StringRef HSAMetadataString);
116
117 /// Emit HSA Metadata
118 ///
119 /// When \p Strict is true, known metadata elements must already be
120 /// well-typed. When \p Strict is false, known types are inferred and
121 /// the \p HSAMetadata structure is updated with the correct types.
122 ///
123 /// \returns True on success, false on failure.
124 virtual bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict) {
125 return true;
126 }
127
128 /// \returns True on success, false on failure.
129 virtual bool EmitHSAMetadata(const AMDGPU::HSAMD::Metadata &HSAMetadata) {
130 return true;
131 }
132
133 /// \returns True on success, false on failure.
134 virtual bool EmitCodeEnd(const MCSubtargetInfo &STI) { return true; }
135
136 virtual void
138 const AMDGPU::MCKernelDescriptor &KernelDescriptor,
139 const MCExpr *NextVGPR, const MCExpr *NextSGPR,
140 const MCExpr *ReserveVCC,
141 const MCExpr *ReserveFlatScr) {}
142
144
145 static unsigned getElfMach(StringRef GPU);
146
147 const std::optional<AMDGPU::TargetID> &getTargetID() const {
148 return TargetID;
149 }
150 std::optional<AMDGPU::TargetID> &getTargetID() { return TargetID; }
151 void initializeTargetID(const MCSubtargetInfo &STI,
152 bool ApplyFeatureString = false);
153};
154
157public:
159
160 void finish() override;
161
162 void EmitDirectiveAMDGCNTarget() override;
163
164 void EmitDirectiveAMDHSACodeObjectVersion(unsigned COV) override;
165
166 void EmitAMDKernelCodeT(AMDGPU::AMDGPUMCKernelCodeT &Header) override;
167
168 void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) override;
169
170 void emitAMDGPULDS(MCSymbol *Sym, unsigned Size, Align Alignment) override;
171
173 const MCSymbol *NumVGPR, const MCSymbol *NumAGPR,
174 const MCSymbol *NumExplicitSGPR, const MCSymbol *NumNamedBarrier,
175 const MCSymbol *PrivateSegmentSize, const MCSymbol *UsesVCC,
176 const MCSymbol *UsesFlatScratch, const MCSymbol *HasDynamicallySizedStack,
177 const MCSymbol *HasRecursion, const MCSymbol *HasIndirectCall) override;
178
179 void EmitMCResourceMaximums(const MCSymbol *MaxVGPR, const MCSymbol *MaxAGPR,
180 const MCSymbol *MaxSGPR,
181 const MCSymbol *MaxNamedBarrier) override;
182
183 /// \returns True on success, false on failure.
184 bool EmitISAVersion() override;
185
186 /// \returns True on success, false on failure.
187 bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict) override;
188
189 /// \returns True on success, false on failure.
190 bool EmitCodeEnd(const MCSubtargetInfo &STI) override;
191
192 void
194 const AMDGPU::MCKernelDescriptor &KernelDescriptor,
195 const MCExpr *NextVGPR, const MCExpr *NextSGPR,
196 const MCExpr *ReserveVCC,
197 const MCExpr *ReserveFlatScr) override;
198
199 void emitAMDGPUInfo(const AMDGPU::InfoSectionData &Data) override;
200};
201
203 const MCSubtargetInfo &STI;
204 MCStreamer &Streamer;
205
206 void EmitNote(StringRef Name, const MCExpr *DescSize, unsigned NoteType,
207 function_ref<void(MCELFStreamer &)> EmitDesc);
208
209 unsigned getEFlags();
210
211 unsigned getEFlagsR600();
212 unsigned getEFlagsAMDGCN();
213
214 unsigned getEFlagsUnknownOS();
215 unsigned getEFlagsAMDHSA();
216 unsigned getEFlagsAMDPAL();
217 unsigned getEFlagsMesa3D();
218
219 unsigned getEFlagsV3();
220 unsigned getEFlagsV4();
221 unsigned getEFlagsV6();
222
223public:
225
227
228 void finish() override;
229
230 void EmitDirectiveAMDGCNTarget() override;
231
232 void EmitAMDKernelCodeT(AMDGPU::AMDGPUMCKernelCodeT &Header) override;
233
234 void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) override;
235
236 void emitAMDGPULDS(MCSymbol *Sym, unsigned Size, Align Alignment) override;
237
238 /// \returns True on success, false on failure.
239 bool EmitISAVersion() override;
240
241 /// \returns True on success, false on failure.
242 bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict) override;
243
244 /// \returns True on success, false on failure.
245 bool EmitCodeEnd(const MCSubtargetInfo &STI) override;
246
247 void
249 const AMDGPU::MCKernelDescriptor &KernelDescriptor,
250 const MCExpr *NextVGPR, const MCExpr *NextSGPR,
251 const MCExpr *ReserveVCC,
252 const MCExpr *ReserveFlatScr) override;
253
254 void emitAMDGPUInfo(const AMDGPU::InfoSectionData &Data) override;
255};
256}
257#endif
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()
void initializeTargetID(const MCSubtargetInfo &STI, bool ApplyFeatureString=false)
virtual void EmitDirectiveAMDHSACodeObjectVersion(unsigned COV)
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)
virtual bool EmitCodeEnd(const MCSubtargetInfo &STI)
static unsigned getElfMach(StringRef GPU)
virtual void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type)
std::optional< AMDGPU::TargetID > & getTargetID()
const std::optional< AMDGPU::TargetID > & getTargetID() const
void emitDirectiveAMDGCNTargetOnce()
Emit the .amdgcn_target directive unless it has already been emitted to this streamer.
std::optional< AMDGPU::TargetID > TargetID
virtual void EmitAMDKernelCodeT(AMDGPU::AMDGPUMCKernelCodeT &Header)
virtual bool EmitHSAMetadata(const AMDGPU::HSAMD::Metadata &HSAMetadata)
virtual void EmitMCResourceMaximums(const MCSymbol *MaxVGPR, const MCSymbol *MaxAGPR, const MCSymbol *MaxSGPR, const MCSymbol *MaxNamedBarrier)
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.
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