LLVM  13.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 sgprs in the metadata. This is an optional advisory
73  // record for logging etc; wave dispatch actually uses the rsrc1 register for
74  // the shader stage to determine the number of sgprs to allocate.
75  void setNumUsedSgprs(unsigned CC, unsigned Val);
76 
77  // Set the scratch size in the metadata.
78  void setScratchSize(unsigned CC, unsigned Val);
79 
80  // Set the stack frame size of a function in the metadata.
81  void setFunctionScratchSize(const MachineFunction &MF, unsigned Val);
82 
83  // Set the amount of LDS used in bytes in the metadata. This is an optional
84  // advisory record for logging etc; wave dispatch actually uses the rsrc1
85  // register for the shader stage to determine the amount of LDS to allocate.
86  void setFunctionLdsSize(const MachineFunction &MF, unsigned Val);
87 
88  // Set the number of used vgprs in the metadata. This is an optional advisory
89  // record for logging etc; wave dispatch actually uses the rsrc1 register for
90  // the shader stage to determine the number of vgprs to allocate.
91  void setFunctionNumUsedVgprs(const MachineFunction &MF, unsigned Val);
92 
93  // Set the number of used sgprs in the metadata. This is an optional advisory
94  // record for logging etc; wave dispatch actually uses the rsrc1 register for
95  // the shader stage to determine the number of sgprs to allocate.
96  void setFunctionNumUsedSgprs(const MachineFunction &MF, unsigned Val);
97 
98  // Set the hardware register bit in PAL metadata to enable wave32 on the
99  // shader of the given calling convention.
100  void setWave32(unsigned CC);
101 
102  // Emit the accumulated PAL metadata as asm directives.
103  // This is called from AMDGPUTargetAsmStreamer::Finish().
104  void toString(std::string &S);
105 
106  // Set PAL metadata from YAML text.
107  bool setFromString(StringRef S);
108 
109  // Get .note record vendor name of metadata blob to be emitted.
110  const char *getVendor() const;
111 
112  // Get .note record type of metadata blob to be emitted:
113  // ELF::NT_AMD_PAL_METADATA (legacy key=val format), or
114  // ELF::NT_AMDGPU_METADATA (MsgPack format), or
115  // 0 (no PAL metadata).
116  unsigned getType() const;
117 
118  // Emit the accumulated PAL metadata as a binary blob.
119  // This is called from AMDGPUTargetELFStreamer::Finish().
120  void toBlob(unsigned Type, std::string &S);
121 
122  // Get the msgpack::Document for the PAL metadata.
123  msgpack::Document *getMsgPackDoc() { return &MsgPackDoc; }
124 
125  // Set legacy PAL metadata format.
126  void setLegacy();
127 
128  // Erase all PAL metadata.
129  void reset();
130 
131 private:
132  // Return whether the blob type is legacy PAL metadata.
133  bool isLegacy() const;
134 
135  // Reference (create if necessary) the node for the registers map.
136  msgpack::DocNode &refRegisters();
137 
138  // Get (create if necessary) the registers map.
139  msgpack::MapDocNode getRegisters();
140 
141  // Reference (create if necessary) the node for the shader functions map.
142  msgpack::DocNode &refShaderFunctions();
143 
144  // Get (create if necessary) the shader functions map.
145  msgpack::MapDocNode getShaderFunctions();
146 
147  // Get (create if necessary) a function in the shader functions map.
148  msgpack::MapDocNode getShaderFunction(StringRef Name);
149 
150  // Get (create if necessary) the .hardware_stages entry for the given calling
151  // convention.
152  msgpack::MapDocNode getHwStage(unsigned CC);
153 
154  bool setFromLegacyBlob(StringRef Blob);
155  bool setFromMsgPackBlob(StringRef Blob);
156  void toLegacyBlob(std::string &Blob);
157  void toMsgPackBlob(std::string &Blob);
158 };
159 
160 } // end namespace llvm
161 
162 #endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUPALMETADATA_H
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::AMDGPUPALMetadata::readFromIR
void readFromIR(Module &M)
Definition: AMDGPUPALMetadata.cpp:31
Reg
unsigned Reg
Definition: MachineSink.cpp:1566
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::AMDGPUPALMetadata::toString
void toString(std::string &S)
Definition: AMDGPUPALMetadata.cpp:659
llvm::AMDGPUPALMetadata::setWave32
void setWave32(unsigned CC)
Definition: AMDGPUPALMetadata.cpp:269
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::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:247
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:229
llvm::AMDGPUPALMetadata::toBlob
void toBlob(unsigned Type, std::string &S)
Definition: AMDGPUPALMetadata.cpp:711
MsgPackDocument.h
llvm::AMDGPUPALMetadata::getMsgPackDoc
msgpack::Document * getMsgPackDoc()
Definition: AMDGPUPALMetadata.h:123
llvm::AMDGPUPALMetadata::setLegacy
void setLegacy()
Definition: AMDGPUPALMetadata.cpp:862
llvm::AMDGPUPALMetadata::setFunctionNumUsedVgprs
void setFunctionNumUsedVgprs(const MachineFunction &MF, unsigned Val)
Definition: AMDGPUPALMetadata.cpp:254
llvm::AMDGPUPALMetadata::getVendor
const char * getVendor() const
Definition: AMDGPUPALMetadata.cpp:844
llvm::AMDGPUPALMetadata::setFromString
bool setFromString(StringRef S)
Definition: AMDGPUPALMetadata.cpp:737
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
llvm::MachineFunction
Definition: MachineFunction.h:230
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:52
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:240
llvm::AMDGPUPALMetadata::setFunctionNumUsedSgprs
void setFunctionNumUsedSgprs(const MachineFunction &MF, unsigned Val)
Definition: AMDGPUPALMetadata.cpp:261
llvm::AMDGPUPALMetadata::reset
void reset()
Definition: AMDGPUPALMetadata.cpp:867
llvm::AMDGPUPALMetadata::setNumUsedSgprs
void setNumUsedSgprs(unsigned CC, unsigned Val)
Definition: AMDGPUPALMetadata.cpp:215
llvm::AMDGPUPALMetadata::getType
unsigned getType() const
Definition: AMDGPUPALMetadata.cpp:852
llvm::AMDGPUPALMetadata::setRsrc2
void setRsrc2(unsigned CC, unsigned Val)
Definition: AMDGPUPALMetadata.cpp:144