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
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 /// \returns True on success, false on failure.
64 virtual bool EmitISAVersion() { return true; }
65
66 /// \returns True on success, false on failure.
67 virtual bool EmitHSAMetadataV3(StringRef HSAMetadataString);
68
69 /// Emit HSA Metadata
70 ///
71 /// When \p Strict is true, known metadata elements must already be
72 /// well-typed. When \p Strict is false, known types are inferred and
73 /// the \p HSAMetadata structure is updated with the correct types.
74 ///
75 /// \returns True on success, false on failure.
76 virtual bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict) {
77 return true;
78 }
79
80 /// \returns True on success, false on failure.
81 virtual bool EmitHSAMetadata(const AMDGPU::HSAMD::Metadata &HSAMetadata) {
82 return true;
83 }
84
85 /// \returns True on success, false on failure.
86 virtual bool EmitCodeEnd(const MCSubtargetInfo &STI) { return true; }
87
88 /// \returns True on success, false on failure.
90 bool TrapEnabled) {
91 return true;
92 }
93
94 virtual void
96 const AMDGPU::MCKernelDescriptor &KernelDescriptor,
97 uint64_t NextVGPR, uint64_t NextSGPR,
98 bool ReserveVCC, bool ReserveFlatScr) {}
99
100 static StringRef getArchNameFromElfMach(unsigned ElfMach);
101 static unsigned getElfMach(StringRef GPU);
102
103 const std::optional<AMDGPU::IsaInfo::AMDGPUTargetID> &getTargetID() const {
104 return TargetID;
105 }
106 std::optional<AMDGPU::IsaInfo::AMDGPUTargetID> &getTargetID() {
107 return TargetID;
108 }
110 assert(TargetID == std::nullopt && "TargetID can only be initialized once");
111 TargetID.emplace(STI);
112 }
113 void initializeTargetID(const MCSubtargetInfo &STI, StringRef FeatureString) {
115
116 assert(getTargetID() != std::nullopt && "TargetID is None");
117 getTargetID()->setTargetIDFromFeaturesString(FeatureString);
118 }
119};
120
123public:
125
126 void finish() override;
127
128 void EmitDirectiveAMDGCNTarget() override;
129
130 void EmitDirectiveAMDHSACodeObjectVersion(unsigned COV) override;
131
132 void EmitAMDKernelCodeT(AMDGPU::AMDGPUMCKernelCodeT &Header) override;
133
134 void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) override;
135
136 void emitAMDGPULDS(MCSymbol *Sym, unsigned Size, Align Alignment) override;
137
138 /// \returns True on success, false on failure.
139 bool EmitISAVersion() override;
140
141 /// \returns True on success, false on failure.
142 bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict) override;
143
144 /// \returns True on success, false on failure.
145 bool EmitCodeEnd(const MCSubtargetInfo &STI) override;
146
147 /// \returns True on success, false on failure.
149 bool TrapEnabled) override;
150
151 void
153 const AMDGPU::MCKernelDescriptor &KernelDescriptor,
154 uint64_t NextVGPR, uint64_t NextSGPR,
155 bool ReserveVCC, bool ReserveFlatScr) override;
156};
157
159 const MCSubtargetInfo &STI;
160 MCStreamer &Streamer;
161
162 void EmitNote(StringRef Name, const MCExpr *DescSize, unsigned NoteType,
163 function_ref<void(MCELFStreamer &)> EmitDesc);
164
165 unsigned getEFlags();
166
167 unsigned getEFlagsR600();
168 unsigned getEFlagsAMDGCN();
169
170 unsigned getEFlagsUnknownOS();
171 unsigned getEFlagsAMDHSA();
172 unsigned getEFlagsAMDPAL();
173 unsigned getEFlagsMesa3D();
174
175 unsigned getEFlagsV3();
176 unsigned getEFlagsV4();
177 unsigned getEFlagsV6();
178
179public:
181
183
184 void finish() override;
185
186 void EmitDirectiveAMDGCNTarget() override;
187
188 void EmitAMDKernelCodeT(AMDGPU::AMDGPUMCKernelCodeT &Header) override;
189
190 void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) override;
191
192 void emitAMDGPULDS(MCSymbol *Sym, unsigned Size, Align Alignment) override;
193
194 /// \returns True on success, false on failure.
195 bool EmitISAVersion() override;
196
197 /// \returns True on success, false on failure.
198 bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict) override;
199
200 /// \returns True on success, false on failure.
201 bool EmitCodeEnd(const MCSubtargetInfo &STI) override;
202
203 /// \returns True on success, false on failure.
205 bool TrapEnabled) override;
206
207 void
209 const AMDGPU::MCKernelDescriptor &KernelDescriptor,
210 uint64_t NextVGPR, uint64_t NextSGPR,
211 bool ReserveVCC, bool ReserveFlatScr) override;
212};
213}
214#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
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
void EmitAMDKernelCodeT(AMDGPU::AMDGPUMCKernelCodeT &Header) 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, 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 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 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: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
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