LLVM  15.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
17 
18 namespace llvm {
19 
20 class MachineFunction;
21 class Module;
22 class StringRef;
23 
25  unsigned BlobType = 0;
26  msgpack::Document MsgPackDoc;
27  msgpack::DocNode Registers;
28  msgpack::DocNode HwStages;
29  msgpack::DocNode ShaderFunctions;
30 
31 public:
32  // Read the amdgpu.pal.metadata supplied by the frontend, ready for
33  // per-function modification.
34  void readFromIR(Module &M);
35 
36  // Set PAL metadata from a binary blob from the applicable .note record.
37  // Returns false if bad format. Blob must remain valid for the lifetime of
38  // the Metadata.
39  bool setFromBlob(unsigned Type, StringRef Blob);
40 
41  // Set the rsrc1 register in the metadata for a particular shader stage.
42  // In fact this ORs the value into any previous setting of the register.
43  void setRsrc1(unsigned CC, unsigned Val);
44 
45  // Set the rsrc2 register in the metadata for a particular shader stage.
46  // In fact this ORs the value into any previous setting of the register.
47  void setRsrc2(unsigned CC, unsigned Val);
48 
49  // Set the SPI_PS_INPUT_ENA register in the metadata.
50  // In fact this ORs the value into any previous setting of the register.
51  void setSpiPsInputEna(unsigned Val);
52 
53  // Set the SPI_PS_INPUT_ADDR register in the metadata.
54  // In fact this ORs the value into any previous setting of the register.
55  void setSpiPsInputAddr(unsigned Val);
56 
57  // Get a register from the metadata, or 0 if not currently set.
58  unsigned getRegister(unsigned Reg);
59 
60  // Set a register in the metadata.
61  // In fact this ORs the value into any previous setting of the register.
62  void setRegister(unsigned Reg, unsigned Val);
63 
64  // Set the entry point name for one shader.
65  void setEntryPoint(unsigned CC, StringRef Name);
66 
67  // Set the number of used vgprs in the metadata. This is an optional advisory
68  // record for logging etc; wave dispatch actually uses the rsrc1 register for
69  // the shader stage to determine the number of vgprs to allocate.
70  void setNumUsedVgprs(unsigned CC, unsigned Val);
71 
72  // Set the number of used agprs in the metadata. This is an optional advisory
73  // record for logging etc;
74  void setNumUsedAgprs(unsigned CC, unsigned Val);
75 
76  // Set the number of used sgprs in the metadata. This is an optional advisory
77  // record for logging etc; wave dispatch actually uses the rsrc1 register for
78  // the shader stage to determine the number of sgprs to allocate.
79  void setNumUsedSgprs(unsigned CC, unsigned Val);
80 
81  // Set the scratch size in the metadata.
82  void setScratchSize(unsigned CC, unsigned Val);
83 
84  // Set the stack frame size of a function in the metadata.
85  void setFunctionScratchSize(const MachineFunction &MF, unsigned Val);
86 
87  // Set the amount of LDS used in bytes in the metadata. This is an optional
88  // advisory record for logging etc; wave dispatch actually uses the rsrc1
89  // register for the shader stage to determine the amount of LDS to allocate.
90  void setFunctionLdsSize(const MachineFunction &MF, unsigned Val);
91 
92  // Set the number of used vgprs in the metadata. This is an optional advisory
93  // record for logging etc; wave dispatch actually uses the rsrc1 register for
94  // the shader stage to determine the number of vgprs to allocate.
95  void setFunctionNumUsedVgprs(const MachineFunction &MF, unsigned Val);
96 
97  // Set the number of used sgprs in the metadata. This is an optional advisory
98  // record for logging etc; wave dispatch actually uses the rsrc1 register for
99  // the shader stage to determine the number of sgprs to allocate.
100  void setFunctionNumUsedSgprs(const MachineFunction &MF, unsigned Val);
101 
102  // Set the hardware register bit in PAL metadata to enable wave32 on the
103  // shader of the given calling convention.
104  void setWave32(unsigned CC);
105 
106  // Emit the accumulated PAL metadata as asm directives.
107  // This is called from AMDGPUTargetAsmStreamer::Finish().
108  void toString(std::string &S);
109 
110  // Set PAL metadata from YAML text.
111  bool setFromString(StringRef S);
112 
113  // Get .note record vendor name of metadata blob to be emitted.
114  const char *getVendor() const;
115 
116  // Get .note record type of metadata blob to be emitted:
117  // ELF::NT_AMD_PAL_METADATA (legacy key=val format), or
118  // ELF::NT_AMDGPU_METADATA (MsgPack format), or
119  // 0 (no PAL metadata).
120  unsigned getType() const;
121 
122  // Emit the accumulated PAL metadata as a binary blob.
123  // This is called from AMDGPUTargetELFStreamer::Finish().
124  void toBlob(unsigned Type, std::string &S);
125 
126  // Get the msgpack::Document for the PAL metadata.
127  msgpack::Document *getMsgPackDoc() { return &MsgPackDoc; }
128 
129  // Set legacy PAL metadata format.
130  void setLegacy();
131 
132  // Erase all PAL metadata.
133  void reset();
134 
135 private:
136  // Return whether the blob type is legacy PAL metadata.
137  bool isLegacy() const;
138 
139  // Reference (create if necessary) the node for the registers map.
140  msgpack::DocNode &refRegisters();
141 
142  // Get (create if necessary) the registers map.
143  msgpack::MapDocNode getRegisters();
144 
145  // Reference (create if necessary) the node for the shader functions map.
146  msgpack::DocNode &refShaderFunctions();
147 
148  // Get (create if necessary) the shader functions map.
149  msgpack::MapDocNode getShaderFunctions();
150 
151  // Get (create if necessary) a function in the shader functions map.
152  msgpack::MapDocNode getShaderFunction(StringRef Name);
153 
154  // Get (create if necessary) the .hardware_stages entry for the given calling
155  // convention.
156  msgpack::MapDocNode getHwStage(unsigned CC);
157 
158  bool setFromLegacyBlob(StringRef Blob);
159  bool setFromMsgPackBlob(StringRef Blob);
160  void toLegacyBlob(std::string &Blob);
161  void toMsgPackBlob(std::string &Blob);
162 };
163 
164 } // end namespace llvm
165 
166 #endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUPALMETADATA_H
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::AMDGPUPALMetadata::readFromIR
void readFromIR(Module &M)
Definition: AMDGPUPALMetadata.cpp:31
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::AMDGPUPALMetadata::getRegister
unsigned getRegister(unsigned Reg)
Definition: AMDGPUPALMetadata.cpp:161
llvm::X86Disassembler::Reg
Reg
All possible values of the reg field in the ModR/M byte.
Definition: X86DisassemblerDecoder.h:462
llvm::AMDGPUPALMetadata::toString
void toString(std::string &S)
Definition: AMDGPUPALMetadata.cpp:664
llvm::AMDGPUPALMetadata::setWave32
void setWave32(unsigned CC)
Definition: AMDGPUPALMetadata.cpp:274
llvm::AMDGPUPALMetadata::setEntryPoint
void setEntryPoint(unsigned CC, StringRef Name)
Definition: AMDGPUPALMetadata.cpp:188
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::AMDGPUPALMetadata
Definition: AMDGPUPALMetadata.h:24
llvm::AMDGPUPALMetadata::setNumUsedVgprs
void setNumUsedVgprs(unsigned CC, unsigned Val)
Definition: AMDGPUPALMetadata.cpp:199
llvm::AMDGPUPALMetadata::setSpiPsInputEna
void setSpiPsInputEna(unsigned Val)
Definition: AMDGPUPALMetadata.cpp:150
llvm::AMDGPUPALMetadata::setNumUsedAgprs
void setNumUsedAgprs(unsigned CC, unsigned Val)
Definition: AMDGPUPALMetadata.cpp:213
llvm::msgpack::DocNode
A node in a MsgPack Document.
Definition: MsgPackDocument.h:38
llvm::AMDGPUPALMetadata::setFunctionLdsSize
void setFunctionLdsSize(const MachineFunction &MF, unsigned Val)
Definition: AMDGPUPALMetadata.cpp:252
llvm::msgpack::Document
Simple in-memory representation of a document of msgpack objects with ability to find and create arra...
Definition: MsgPackDocument.h:272
llvm::AMDGPUPALMetadata::setFromBlob
bool setFromBlob(unsigned Type, StringRef Blob)
Definition: AMDGPUPALMetadata.cpp:70
llvm::msgpack::MapDocNode
A DocNode that is a map.
Definition: MsgPackDocument.h:219
llvm::AMDGPUPALMetadata::setSpiPsInputAddr
void setSpiPsInputAddr(unsigned Val)
Definition: AMDGPUPALMetadata.cpp:156
llvm::AMDGPUPALMetadata::setScratchSize
void setScratchSize(unsigned CC, unsigned Val)
Definition: AMDGPUPALMetadata.cpp:234
llvm::AMDGPUPALMetadata::toBlob
void toBlob(unsigned Type, std::string &S)
Definition: AMDGPUPALMetadata.cpp:716
MsgPackDocument.h
llvm::AMDGPUPALMetadata::getMsgPackDoc
msgpack::Document * getMsgPackDoc()
Definition: AMDGPUPALMetadata.h:127
llvm::AMDGPUPALMetadata::setLegacy
void setLegacy()
Definition: AMDGPUPALMetadata.cpp:867
llvm::AMDGPUPALMetadata::setFunctionNumUsedVgprs
void setFunctionNumUsedVgprs(const MachineFunction &MF, unsigned Val)
Definition: AMDGPUPALMetadata.cpp:259
llvm::AMDGPUPALMetadata::getVendor
const char * getVendor() const
Definition: AMDGPUPALMetadata.cpp:849
llvm::AMDGPUPALMetadata::setFromString
bool setFromString(StringRef S)
Definition: AMDGPUPALMetadata.cpp:742
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
llvm::MachineFunction
Definition: MachineFunction.h:241
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
Module
Machine Check Debug Module
Definition: MachineCheckDebugify.cpp:122
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:50
llvm::AMDGPUPALMetadata::setRegister
void setRegister(unsigned Reg, unsigned Val)
Definition: AMDGPUPALMetadata.cpp:174
llvm::AMDGPUPALMetadata::setRsrc1
void setRsrc1(unsigned CC, unsigned Val)
Definition: AMDGPUPALMetadata.cpp:138
llvm::AMDGPUPALMetadata::setFunctionScratchSize
void setFunctionScratchSize(const MachineFunction &MF, unsigned Val)
Definition: AMDGPUPALMetadata.cpp:245
llvm::AMDGPUPALMetadata::setFunctionNumUsedSgprs
void setFunctionNumUsedSgprs(const MachineFunction &MF, unsigned Val)
Definition: AMDGPUPALMetadata.cpp:266
llvm::AMDGPUPALMetadata::reset
void reset()
Definition: AMDGPUPALMetadata.cpp:872
llvm::AMDGPUPALMetadata::setNumUsedSgprs
void setNumUsedSgprs(unsigned CC, unsigned Val)
Definition: AMDGPUPALMetadata.cpp:220
llvm::AMDGPUPALMetadata::getType
unsigned getType() const
Definition: AMDGPUPALMetadata.cpp:857
llvm::AMDGPUPALMetadata::setRsrc2
void setRsrc2(unsigned CC, unsigned Val)
Definition: AMDGPUPALMetadata.cpp:144