LLVM 24.0.0git
AMDGPUPALMetadata.h
Go to the documentation of this file.
1//===-- AMDGPUPALMetadata.h - PAL metadata handling -------------*- 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/// \file
10/// PAL metadata handling
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUPALMETADATA_H
15#define LLVM_LIB_TARGET_AMDGPU_AMDGPUPALMETADATA_H
16#include "AMDGPUDelayedMCExpr.h"
17#include "llvm/ADT/DenseMap.h"
19#include "llvm/MC/MCContext.h"
20
21namespace llvm {
22
23class Module;
24
26public:
28
29private:
30 unsigned BlobType = 0;
31 msgpack::Document MsgPackDoc;
32 msgpack::DocNode Registers;
33 msgpack::DocNode HwStages;
34 msgpack::DocNode ShaderFunctions;
35 bool VersionChecked = false;
36 msgpack::DocNode Version;
37 // From PAL version >= 3.0
38 msgpack::DocNode ComputeRegisters;
39 msgpack::DocNode GraphicsRegisters;
40
41 DelayedMCExprs DelayedExprs;
43 bool ResolvedAll = true;
44
45public:
46 // Read the amdgpu.pal.metadata supplied by the frontend, ready for
47 // per-function modification.
48 void readFromIR(Module &M);
49
50 // Set the rsrc1 register in the metadata for a particular shader stage.
51 // In fact this ORs the value into any previous setting of the register.
52 void setRsrc1(unsigned CC, unsigned Val);
53 void setRsrc1(unsigned CC, const MCExpr *Val, MCContext &Ctx);
54
55 // Set the rsrc2 register in the metadata for a particular shader stage.
56 // In fact this ORs the value into any previous setting of the register.
57 void setRsrc2(unsigned CC, unsigned Val);
58 void setRsrc2(unsigned CC, const MCExpr *Val, MCContext &Ctx);
59
60 // Set the SPI_PS_INPUT_ENA register in the metadata.
61 // In fact this ORs the value into any previous setting of the register.
62 void setSpiPsInputEna(unsigned Val);
63
64 // Set the SPI_PS_INPUT_ADDR register in the metadata.
65 // In fact this ORs the value into any previous setting of the register.
66 void setSpiPsInputAddr(unsigned Val);
67
68 // Get a register from the metadata, or 0 if not currently set.
69 unsigned getRegister(unsigned Reg);
70
71 // Set a register in the metadata.
72 // In fact this ORs the value into any previous setting of the register.
73 void setRegister(unsigned Reg, unsigned Val);
74 void setRegister(unsigned Reg, const MCExpr *Val, MCContext &Ctx);
75
76 // Set the entry point name for one shader.
77 void setEntryPoint(unsigned CC, StringRef Name);
78
79 // Set the number of used vgprs in the metadata. This is an optional advisory
80 // record for logging etc; wave dispatch actually uses the rsrc1 register for
81 // the shader stage to determine the number of vgprs to allocate.
82 void setNumUsedVgprs(unsigned CC, unsigned Val);
83 void setNumUsedVgprs(unsigned CC, const MCExpr *Val, MCContext &Ctx);
84
85 // Set the number of used agprs in the metadata. This is an optional advisory
86 // record for logging etc;
87 void setNumUsedAgprs(unsigned CC, unsigned Val);
88 void setNumUsedAgprs(unsigned CC, const MCExpr *Val);
89
90 // Set the number of used sgprs in the metadata. This is an optional advisory
91 // record for logging etc; wave dispatch actually uses the rsrc1 register for
92 // the shader stage to determine the number of sgprs to allocate.
93 void setNumUsedSgprs(unsigned CC, unsigned Val);
94 void setNumUsedSgprs(unsigned CC, const MCExpr *Val, MCContext &Ctx);
95
96 // Set the scratch size in the metadata.
97 void setScratchSize(unsigned CC, unsigned Val);
98 void setScratchSize(unsigned CC, const MCExpr *Val, MCContext &Ctx);
99
100 // Set the stack frame size of a function in the metadata.
101 void setFunctionScratchSize(StringRef FnName, unsigned Val);
102
103 // Set the amount of LDS used in bytes in the metadata. This is an optional
104 // advisory record for logging etc; wave dispatch actually uses the rsrc1
105 // register for the shader stage to determine the amount of LDS to allocate.
106 void setFunctionLdsSize(StringRef FnName, unsigned Val);
107
108 // Set the number of used vgprs in the metadata. This is an optional advisory
109 // record for logging etc; wave dispatch actually uses the rsrc1 register for
110 // the shader stage to determine the number of vgprs to allocate.
111 void setFunctionNumUsedVgprs(StringRef FnName, unsigned Val);
112 void setFunctionNumUsedVgprs(StringRef FnName, const MCExpr *Val);
113
114 // Set the number of used sgprs in the metadata. This is an optional advisory
115 // record for logging etc; wave dispatch actually uses the rsrc1 register for
116 // the shader stage to determine the number of sgprs to allocate.
117 void setFunctionNumUsedSgprs(StringRef FnName, unsigned Val);
118 void setFunctionNumUsedSgprs(StringRef FnName, const MCExpr *Val);
119
120 // Set the hardware register bit in PAL metadata to enable wave32 on the
121 // shader of the given calling convention.
122 void setWave32(unsigned CC);
123
124 // Emit the accumulated PAL metadata as asm directives.
125 // This is called from AMDGPUTargetAsmStreamer::Finish().
126 void toString(std::string &S);
127
128 // Set PAL metadata from YAML text.
129 bool setFromString(StringRef S);
130
131 // Get .note record vendor name of metadata blob to be emitted.
132 const char *getVendor() const;
133
134 // Get .note record type of metadata blob to be emitted:
135 // ELF::NT_AMD_PAL_METADATA (legacy key=val format), or
136 // ELF::NT_AMDGPU_METADATA (MsgPack format), or
137 // 0 (no PAL metadata).
138 unsigned getType() const;
139
140 // Emit the accumulated PAL metadata as a binary blob.
141 // This is called from AMDGPUTargetELFStreamer::Finish().
142 void toBlob(unsigned Type, std::string &S);
143
144 // Set legacy PAL metadata format.
145 void setLegacy();
146
147 unsigned getPALMajorVersion();
149
150 void updateHwStageMaximum(unsigned CC, StringRef field, unsigned Val);
151 void setHwStage(unsigned CC, StringRef field, unsigned Val);
152 void setHwStage(unsigned CC, StringRef field, bool Val);
153 void setHwStage(unsigned CC, StringRef field, msgpack::Type Type,
154 const MCExpr *Val);
155
156 void setComputeRegisters(StringRef field, unsigned Val);
157 void setComputeRegisters(StringRef field, bool Val);
158
159 // If the field does not exist will return nullptr rather than creating a new
160 // entry (which is the behaviour of the other functions).
162 bool checkComputeRegisters(StringRef field, unsigned Val);
163 bool checkComputeRegisters(StringRef field, bool Val);
164
165 void setGraphicsRegisters(StringRef field, unsigned Val);
166 void setGraphicsRegisters(StringRef field, bool Val);
167 void setGraphicsRegisters(StringRef field1, StringRef field2, unsigned Val);
168 void setGraphicsRegisters(StringRef field1, StringRef field2, bool Val);
169
170 // Erase all PAL metadata.
171 void reset();
172
173 bool resolvedAllMCExpr();
174
175private:
176 // Return whether the blob type is legacy PAL metadata.
177 bool isLegacy() const;
178
179 // Reference (create if necessary) the node for the registers map.
180 msgpack::DocNode &refRegisters();
181
182 // Get (create if necessary) the registers map.
183 msgpack::MapDocNode getRegisters();
184
185 // Reference (create if necessary) the node for the shader functions map.
186 msgpack::DocNode &refShaderFunctions();
187
188 // Get (create if necessary) the shader functions map.
189 msgpack::MapDocNode getShaderFunctions();
190
191 // Get (create if necessary) a function in the shader functions map.
192 msgpack::MapDocNode getShaderFunction(StringRef Name);
193
194 // Reference (create if necessary) the node for the compute_registers map.
195 msgpack::DocNode &refComputeRegisters();
196
197 // Get (create if necessary) the .compute_registers entry.
198 msgpack::MapDocNode getComputeRegisters();
199
200 // Reference (create if necessary) the node for the graphics registers map.
201 msgpack::DocNode &refGraphicsRegisters();
202
203 // Get (create if necessary) the .graphics_registers entry.
204 msgpack::MapDocNode getGraphicsRegisters();
205
206 // Reference (create if necessary) the node for the hardware_stages map.
207 msgpack::DocNode &refHwStage();
208
209 // Get (create if necessary) the .hardware_stages entry for the given calling
210 // convention.
211 msgpack::MapDocNode getHwStage(unsigned CC);
212
213 // Get the PAL version major (idx 0) or minor (idx 1). This is an internal
214 // helper for the public wrapper functions that request Major or Minor
215 unsigned getPALVersion(unsigned idx);
216
217 bool setFromLegacyBlob(StringRef Blob);
218 bool setFromMsgPackBlob(StringRef Blob);
219 void toLegacyBlob(std::string &Blob);
220 void toMsgPackBlob(std::string &Blob);
221};
222
223} // end namespace llvm
224
225#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUPALMETADATA_H
This file defines the DenseMap class.
Register Reg
This file declares a class that exposes a simple in-memory representation of a document of MsgPack ob...
void setSpiPsInputAddr(unsigned Val)
void setEntryPoint(unsigned CC, StringRef Name)
const char * getVendor() const
void setFunctionScratchSize(StringRef FnName, unsigned Val)
bool setFromString(StringRef S)
void setNumUsedVgprs(unsigned CC, unsigned Val)
unsigned getRegister(unsigned Reg)
msgpack::DocNode * refComputeRegister(StringRef field)
void setFunctionNumUsedVgprs(StringRef FnName, unsigned Val)
void setFunctionNumUsedSgprs(StringRef FnName, unsigned Val)
void setScratchSize(unsigned CC, unsigned Val)
DenseMap< unsigned, const MCExpr * > RegisterExprMap
void setRegister(unsigned Reg, unsigned Val)
void setHwStage(unsigned CC, StringRef field, unsigned Val)
void setRsrc1(unsigned CC, unsigned Val)
void setSpiPsInputEna(unsigned Val)
void setNumUsedAgprs(unsigned CC, unsigned Val)
void setGraphicsRegisters(StringRef field, unsigned Val)
bool checkComputeRegisters(StringRef field, unsigned Val)
void toBlob(unsigned Type, std::string &S)
void toString(std::string &S)
void setFunctionLdsSize(StringRef FnName, unsigned Val)
void updateHwStageMaximum(unsigned CC, StringRef field, unsigned Val)
void setRsrc2(unsigned CC, unsigned Val)
void setNumUsedSgprs(unsigned CC, unsigned Val)
void setComputeRegisters(StringRef field, unsigned Val)
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
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
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
Represents a version number in the form major[.minor[.subminor[.build]]].
A node in a MsgPack Document.
Simple in-memory representation of a document of msgpack objects with ability to find and create arra...
A DocNode that is a map.
Type
MessagePack types as defined in the standard, with the exception of Integer being divided into a sign...
This is an optimization pass for GlobalISel generic memory operations.