LLVM 17.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
17
18namespace llvm {
19
20class MCELFStreamer;
21class MCSymbol;
22class formatted_raw_ostream;
23
24namespace AMDGPU {
25namespace HSAMD {
26struct Metadata;
27}
28} // namespace AMDGPU
29
30namespace amdhsa {
31struct kernel_descriptor_t;
32}
33
35 AMDGPUPALMetadata PALMetadata;
36
37protected:
38 // TODO: Move HSAMetadataStream to AMDGPUTargetStreamer.
39 std::optional<AMDGPU::IsaInfo::AMDGPUTargetID> TargetID;
40
41 MCContext &getContext() const { return Streamer.getContext(); }
42
43public:
45
46 AMDGPUPALMetadata *getPALMetadata() { return &PALMetadata; }
47
48 virtual void EmitDirectiveAMDGCNTarget(){};
49
51 uint32_t Minor){};
52
54 uint32_t Stepping,
55 StringRef VendorName,
56 StringRef ArchName){};
57
58 virtual void EmitAMDKernelCodeT(const amd_kernel_code_t &Header){};
59
60 virtual void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type){};
61
62 virtual void emitAMDGPULDS(MCSymbol *Symbol, unsigned Size, Align Alignment) {
63 }
64
65 /// \returns True on success, false on failure.
66 virtual bool EmitISAVersion() { return true; }
67
68 /// \returns True on success, false on failure.
69 virtual bool EmitHSAMetadataV2(StringRef HSAMetadataString);
70
71 /// \returns True on success, false on failure.
72 virtual bool EmitHSAMetadataV3(StringRef HSAMetadataString);
73
74 /// Emit HSA Metadata
75 ///
76 /// When \p Strict is true, known metadata elements must already be
77 /// well-typed. When \p Strict is false, known types are inferred and
78 /// the \p HSAMetadata structure is updated with the correct types.
79 ///
80 /// \returns True on success, false on failure.
81 virtual bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict) {
82 return true;
83 }
84
85 /// \returns True on success, false on failure.
86 virtual bool EmitHSAMetadata(const AMDGPU::HSAMD::Metadata &HSAMetadata) {
87 return true;
88 }
89
90 /// \returns True on success, false on failure.
91 virtual bool EmitCodeEnd(const MCSubtargetInfo &STI) { return true; }
92
94 const MCSubtargetInfo &STI, StringRef KernelName,
95 const amdhsa::kernel_descriptor_t &KernelDescriptor, uint64_t NextVGPR,
96 uint64_t NextSGPR, bool ReserveVCC, bool ReserveFlatScr,
97 unsigned CodeObjectVersion){};
98
99 static StringRef getArchNameFromElfMach(unsigned ElfMach);
100 static unsigned getElfMach(StringRef GPU);
101
102 const std::optional<AMDGPU::IsaInfo::AMDGPUTargetID> &getTargetID() const {
103 return TargetID;
104 }
105 std::optional<AMDGPU::IsaInfo::AMDGPUTargetID> &getTargetID() {
106 return TargetID;
107 }
109 assert(TargetID == std::nullopt && "TargetID can only be initialized once");
110 TargetID.emplace(STI);
111 }
112 void initializeTargetID(const MCSubtargetInfo &STI, StringRef FeatureString) {
114
115 assert(getTargetID() != std::nullopt && "TargetID is None");
116 getTargetID()->setTargetIDFromFeaturesString(FeatureString);
117 }
118};
119
122public:
124
125 void finish() override;
126
127 void EmitDirectiveAMDGCNTarget() override;
128
130 uint32_t Minor) override;
131
133 uint32_t Stepping, StringRef VendorName,
134 StringRef ArchName) override;
135
136 void EmitAMDKernelCodeT(const amd_kernel_code_t &Header) override;
137
138 void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) override;
139
140 void emitAMDGPULDS(MCSymbol *Sym, unsigned Size, Align Alignment) override;
141
142 /// \returns True on success, false on failure.
143 bool EmitISAVersion() override;
144
145 /// \returns True on success, false on failure.
146 bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict) override;
147
148 /// \returns True on success, false on failure.
149 bool EmitHSAMetadata(const AMDGPU::HSAMD::Metadata &HSAMetadata) override;
150
151 /// \returns True on success, false on failure.
152 bool EmitCodeEnd(const MCSubtargetInfo &STI) override;
153
155 const MCSubtargetInfo &STI, StringRef KernelName,
156 const amdhsa::kernel_descriptor_t &KernelDescriptor, uint64_t NextVGPR,
157 uint64_t NextSGPR, bool ReserveVCC, bool ReserveFlatScr,
158 unsigned CodeObjectVersion) override;
159};
160
162 const MCSubtargetInfo &STI;
163 MCStreamer &Streamer;
164
165 void EmitNote(StringRef Name, const MCExpr *DescSize, unsigned NoteType,
166 function_ref<void(MCELFStreamer &)> EmitDesc);
167
168 unsigned getEFlags();
169
170 unsigned getEFlagsR600();
171 unsigned getEFlagsAMDGCN();
172
173 unsigned getEFlagsUnknownOS();
174 unsigned getEFlagsAMDHSA();
175 unsigned getEFlagsAMDPAL();
176 unsigned getEFlagsMesa3D();
177
178 unsigned getEFlagsV3();
179 unsigned getEFlagsV4();
180
181public:
183
185
186 void finish() override;
187
188 void EmitDirectiveAMDGCNTarget() override;
189
191 uint32_t Minor) override;
192
194 uint32_t Stepping, StringRef VendorName,
195 StringRef ArchName) override;
196
197 void EmitAMDKernelCodeT(const amd_kernel_code_t &Header) override;
198
199 void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) override;
200
201 void emitAMDGPULDS(MCSymbol *Sym, unsigned Size, Align Alignment) override;
202
203 /// \returns True on success, false on failure.
204 bool EmitISAVersion() override;
205
206 /// \returns True on success, false on failure.
207 bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict) override;
208
209 /// \returns True on success, false on failure.
210 bool EmitHSAMetadata(const AMDGPU::HSAMD::Metadata &HSAMetadata) override;
211
212 /// \returns True on success, false on failure.
213 bool EmitCodeEnd(const MCSubtargetInfo &STI) override;
214
216 const MCSubtargetInfo &STI, StringRef KernelName,
217 const amdhsa::kernel_descriptor_t &KernelDescriptor, uint64_t NextVGPR,
218 uint64_t NextSGPR, bool ReserveVCC, bool ReserveFlatScr,
219 unsigned CodeObjectVersion) override;
220};
221
222}
223#endif
PAL metadata handling.
std::string Name
uint64_t Size
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void EmitAMDKernelCodeT(const amd_kernel_code_t &Header) override
void EmitAmdhsaKernelDescriptor(const MCSubtargetInfo &STI, StringRef KernelName, const amdhsa::kernel_descriptor_t &KernelDescriptor, uint64_t NextVGPR, uint64_t NextSGPR, bool ReserveVCC, bool ReserveFlatScr, unsigned CodeObjectVersion) override
bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict) override
void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) override
void EmitDirectiveHSACodeObjectISAV2(uint32_t Major, uint32_t Minor, uint32_t Stepping, StringRef VendorName, StringRef ArchName) override
void EmitDirectiveHSACodeObjectVersion(uint32_t Major, uint32_t Minor) override
bool EmitCodeEnd(const MCSubtargetInfo &STI) override
void emitAMDGPULDS(MCSymbol *Sym, unsigned Size, Align Alignment) override
bool EmitCodeEnd(const MCSubtargetInfo &STI) override
void EmitAMDKernelCodeT(const amd_kernel_code_t &Header) override
bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict) override
void EmitDirectiveHSACodeObjectVersion(uint32_t Major, uint32_t Minor) override
void EmitDirectiveHSACodeObjectISAV2(uint32_t Major, uint32_t Minor, uint32_t Stepping, StringRef VendorName, StringRef ArchName) override
void emitAMDGPULDS(MCSymbol *Sym, unsigned Size, Align Alignment) override
void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) override
void EmitAmdhsaKernelDescriptor(const MCSubtargetInfo &STI, StringRef KernelName, const amdhsa::kernel_descriptor_t &KernelDescriptor, uint64_t NextVGPR, uint64_t NextSGPR, bool ReserveVCC, bool ReserveFlatScr, unsigned CodeObjectVersion) override
virtual bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict)
Emit HSA Metadata.
AMDGPUPALMetadata * getPALMetadata()
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 void EmitAMDKernelCodeT(const amd_kernel_code_t &Header)
virtual bool EmitCodeEnd(const MCSubtargetInfo &STI)
virtual void EmitDirectiveHSACodeObjectVersion(uint32_t Major, uint32_t Minor)
static unsigned getElfMach(StringRef GPU)
virtual void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type)
virtual void EmitAmdhsaKernelDescriptor(const MCSubtargetInfo &STI, StringRef KernelName, const amdhsa::kernel_descriptor_t &KernelDescriptor, uint64_t NextVGPR, uint64_t NextSGPR, bool ReserveVCC, bool ReserveFlatScr, unsigned CodeObjectVersion)
void initializeTargetID(const MCSubtargetInfo &STI, StringRef FeatureString)
virtual void EmitDirectiveAMDGCNTarget()
virtual bool EmitHSAMetadata(const AMDGPU::HSAMD::Metadata &HSAMetadata)
MCContext & getContext() const
static StringRef getArchNameFromElfMach(unsigned ElfMach)
virtual void EmitDirectiveHSACodeObjectISAV2(uint32_t Major, uint32_t Minor, uint32_t Stepping, StringRef VendorName, StringRef ArchName)
const std::optional< AMDGPU::IsaInfo::AMDGPUTargetID > & getTargetID() const
std::optional< AMDGPU::IsaInfo::AMDGPUTargetID > TargetID
virtual bool EmitHSAMetadataV2(StringRef HSAMetadataString)
Context object for machine code objects.
Definition: MCContext.h:76
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
Streaming machine code generation interface.
Definition: MCStreamer.h:212
MCContext & getContext() const
Definition: MCStreamer.h:297
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:93
MCStreamer & Streamer
Definition: MCStreamer.h:95
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
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
AMD Kernel Code Object (amd_kernel_code_t).
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