LLVM 19.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 {
25
26struct MCKernelDescriptor;
27namespace HSAMD {
28struct Metadata;
29}
30} // namespace AMDGPU
31
33 AMDGPUPALMetadata PALMetadata;
34
35protected:
36 // TODO: Move HSAMetadataStream to AMDGPUTargetStreamer.
37 std::optional<AMDGPU::IsaInfo::AMDGPUTargetID> TargetID;
39
40 MCContext &getContext() const { return Streamer.getContext(); }
41
42public:
45 // Assume the default COV for now, EmitDirectiveAMDHSACodeObjectVersion
46 // will update this if it is encountered.
47 CodeObjectVersion(AMDGPU::getDefaultAMDHSACodeObjectVersion()) {}
48
49 AMDGPUPALMetadata *getPALMetadata() { return &PALMetadata; }
50
51 virtual void EmitDirectiveAMDGCNTarget(){};
52
53 virtual void EmitDirectiveAMDHSACodeObjectVersion(unsigned COV) {
55 }
56
57 virtual void EmitAMDKernelCodeT(const amd_kernel_code_t &Header){};
58
59 virtual void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type){};
60
61 virtual void emitAMDGPULDS(MCSymbol *Symbol, unsigned Size, Align Alignment) {
62 }
63
64 /// \returns True on success, false on failure.
65 virtual bool EmitISAVersion() { return true; }
66
67 /// \returns True on success, false on failure.
68 virtual bool EmitHSAMetadataV3(StringRef HSAMetadataString);
69
70 /// Emit HSA Metadata
71 ///
72 /// When \p Strict is true, known metadata elements must already be
73 /// well-typed. When \p Strict is false, known types are inferred and
74 /// the \p HSAMetadata structure is updated with the correct types.
75 ///
76 /// \returns True on success, false on failure.
77 virtual bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict) {
78 return true;
79 }
80
81 /// \returns True on success, false on failure.
82 virtual bool EmitHSAMetadata(const AMDGPU::HSAMD::Metadata &HSAMetadata) {
83 return true;
84 }
85
86 /// \returns True on success, false on failure.
87 virtual bool EmitCodeEnd(const MCSubtargetInfo &STI) { return true; }
88
89 /// \returns True on success, false on failure.
91 bool TrapEnabled) {
92 return true;
93 }
94
95 virtual void
97 const AMDGPU::MCKernelDescriptor &KernelDescriptor,
98 uint64_t NextVGPR, uint64_t NextSGPR,
99 bool ReserveVCC, bool ReserveFlatScr) {}
100
101 static StringRef getArchNameFromElfMach(unsigned ElfMach);
102 static unsigned getElfMach(StringRef GPU);
103
104 const std::optional<AMDGPU::IsaInfo::AMDGPUTargetID> &getTargetID() const {
105 return TargetID;
106 }
107 std::optional<AMDGPU::IsaInfo::AMDGPUTargetID> &getTargetID() {
108 return TargetID;
109 }
111 assert(TargetID == std::nullopt && "TargetID can only be initialized once");
112 TargetID.emplace(STI);
113 }
114 void initializeTargetID(const MCSubtargetInfo &STI, StringRef FeatureString) {
116
117 assert(getTargetID() != std::nullopt && "TargetID is None");
118 getTargetID()->setTargetIDFromFeaturesString(FeatureString);
119 }
120};
121
124public:
126
127 void finish() override;
128
129 void EmitDirectiveAMDGCNTarget() override;
130
131 void EmitDirectiveAMDHSACodeObjectVersion(unsigned COV) override;
132
133 void EmitAMDKernelCodeT(const amd_kernel_code_t &Header) override;
134
135 void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) override;
136
137 void emitAMDGPULDS(MCSymbol *Sym, unsigned Size, Align Alignment) override;
138
139 /// \returns True on success, false on failure.
140 bool EmitISAVersion() override;
141
142 /// \returns True on success, false on failure.
143 bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict) override;
144
145 /// \returns True on success, false on failure.
146 bool EmitCodeEnd(const MCSubtargetInfo &STI) override;
147
148 /// \returns True on success, false on failure.
150 bool TrapEnabled) override;
151
152 void
154 const AMDGPU::MCKernelDescriptor &KernelDescriptor,
155 uint64_t NextVGPR, uint64_t NextSGPR,
156 bool ReserveVCC, bool ReserveFlatScr) override;
157};
158
160 const MCSubtargetInfo &STI;
161 MCStreamer &Streamer;
162
163 void EmitNote(StringRef Name, const MCExpr *DescSize, unsigned NoteType,
164 function_ref<void(MCELFStreamer &)> EmitDesc);
165
166 unsigned getEFlags();
167
168 unsigned getEFlagsR600();
169 unsigned getEFlagsAMDGCN();
170
171 unsigned getEFlagsUnknownOS();
172 unsigned getEFlagsAMDHSA();
173 unsigned getEFlagsAMDPAL();
174 unsigned getEFlagsMesa3D();
175
176 unsigned getEFlagsV3();
177 unsigned getEFlagsV4();
178 unsigned getEFlagsV6();
179
180public:
182
184
185 void finish() override;
186
187 void EmitDirectiveAMDGCNTarget() override;
188
189 void EmitAMDKernelCodeT(const amd_kernel_code_t &Header) override;
190
191 void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) override;
192
193 void emitAMDGPULDS(MCSymbol *Sym, unsigned Size, Align Alignment) override;
194
195 /// \returns True on success, false on failure.
196 bool EmitISAVersion() override;
197
198 /// \returns True on success, false on failure.
199 bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict) override;
200
201 /// \returns True on success, false on failure.
202 bool EmitCodeEnd(const MCSubtargetInfo &STI) override;
203
204 /// \returns True on success, false on failure.
206 bool TrapEnabled) override;
207
208 void
210 const AMDGPU::MCKernelDescriptor &KernelDescriptor,
211 uint64_t NextVGPR, uint64_t NextSGPR,
212 bool ReserveVCC, bool ReserveFlatScr) override;
213};
214}
215#endif
PAL metadata handling.
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 EmitAMDKernelCodeT(const amd_kernel_code_t &Header) override
bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict) override
void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) override
void EmitDirectiveAMDHSACodeObjectVersion(unsigned COV) override
void EmitAmdhsaKernelDescriptor(const MCSubtargetInfo &STI, StringRef KernelName, const AMDGPU::MCKernelDescriptor &KernelDescriptor, uint64_t NextVGPR, uint64_t NextSGPR, bool ReserveVCC, bool 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(const amd_kernel_code_t &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, uint64_t NextVGPR, uint64_t NextSGPR, bool ReserveVCC, bool ReserveFlatScr) override
void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) override
bool EmitKernargPreloadHeader(const MCSubtargetInfo &STI, bool TrapEnabled) override
virtual bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict)
Emit HSA Metadata.
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)
std::optional< AMDGPU::IsaInfo::AMDGPUTargetID > & getTargetID()
virtual void EmitAMDKernelCodeT(const amd_kernel_code_t &Header)
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 EmitDirectiveAMDGCNTarget()
virtual void EmitAmdhsaKernelDescriptor(const MCSubtargetInfo &STI, StringRef KernelName, const AMDGPU::MCKernelDescriptor &KernelDescriptor, uint64_t NextVGPR, uint64_t NextSGPR, bool ReserveVCC, bool ReserveFlatScr)
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:81
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:40
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