1 //===-- AMDGPUPALMetadata.h - PAL metadata handling -------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
10 /// PAL metadata handling
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUPALMETADATA_H
15 #define LLVM_LIB_TARGET_AMDGPU_AMDGPUPALMETADATA_H
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/BinaryFormat/MsgPackDocument.h"
23 class AMDGPUTargetStreamer
;
24 class formatted_raw_ostream
;
28 class AMDGPUPALMetadata
{
29 unsigned BlobType
= 0;
30 msgpack::Document MsgPackDoc
;
31 msgpack::DocNode Registers
;
32 msgpack::DocNode HwStages
;
35 // Read the amdgpu.pal.metadata supplied by the frontend, ready for
36 // per-function modification.
37 void readFromIR(Module
&M
);
39 // Set PAL metadata from a binary blob from the applicable .note record.
40 // Returns false if bad format. Blob must remain valid for the lifetime of
42 bool setFromBlob(unsigned Type
, StringRef Blob
);
44 // Set the rsrc1 register in the metadata for a particular shader stage.
45 // In fact this ORs the value into any previous setting of the register.
46 void setRsrc1(unsigned CC
, unsigned Val
);
48 // Set the rsrc2 register in the metadata for a particular shader stage.
49 // In fact this ORs the value into any previous setting of the register.
50 void setRsrc2(unsigned CC
, unsigned Val
);
52 // Set the SPI_PS_INPUT_ENA register in the metadata.
53 // In fact this ORs the value into any previous setting of the register.
54 void setSpiPsInputEna(unsigned Val
);
56 // Set the SPI_PS_INPUT_ADDR register in the metadata.
57 // In fact this ORs the value into any previous setting of the register.
58 void setSpiPsInputAddr(unsigned Val
);
60 // Get a register from the metadata, or 0 if not currently set.
61 unsigned getRegister(unsigned Reg
);
63 // Set a register in the metadata.
64 // In fact this ORs the value into any previous setting of the register.
65 void setRegister(unsigned Reg
, unsigned Val
);
67 // Set the entry point name for one shader.
68 void setEntryPoint(unsigned CC
, StringRef Name
);
70 // Set the number of used vgprs in the metadata. This is an optional advisory
71 // record for logging etc; wave dispatch actually uses the rsrc1 register for
72 // the shader stage to determine the number of vgprs to allocate.
73 void setNumUsedVgprs(unsigned CC
, unsigned Val
);
75 // Set the number of used sgprs in the metadata. This is an optional advisory
76 // record for logging etc; wave dispatch actually uses the rsrc1 register for
77 // the shader stage to determine the number of sgprs to allocate.
78 void setNumUsedSgprs(unsigned CC
, unsigned Val
);
80 // Set the scratch size in the metadata.
81 void setScratchSize(unsigned CC
, unsigned Val
);
83 // Set the hardware register bit in PAL metadata to enable wave32 on the
84 // shader of the given calling convention.
85 void setWave32(unsigned CC
);
87 // Emit the accumulated PAL metadata as asm directives.
88 // This is called from AMDGPUTargetAsmStreamer::Finish().
89 void toString(std::string
&S
);
91 // Set PAL metadata from YAML text.
92 bool setFromString(StringRef S
);
94 // Get .note record vendor name of metadata blob to be emitted.
95 const char *getVendor() const;
97 // Get .note record type of metadata blob to be emitted:
98 // ELF::NT_AMD_AMDGPU_PAL_METADATA (legacy key=val format), or
99 // ELF::NT_AMDGPU_METADATA (MsgPack format), or
100 // 0 (no PAL metadata).
101 unsigned getType() const;
103 // Emit the accumulated PAL metadata as a binary blob.
104 // This is called from AMDGPUTargetELFStreamer::Finish().
105 void toBlob(unsigned Type
, std::string
&S
);
107 // Get the msgpack::Document for the PAL metadata.
108 msgpack::Document
*getMsgPackDoc() { return &MsgPackDoc
; }
110 // Set legacy PAL metadata format.
114 // Return whether the blob type is legacy PAL metadata.
115 bool isLegacy() const;
117 // Reference (create if necessary) the node for the registers map.
118 msgpack::DocNode
&refRegisters();
120 // Get (create if necessary) the registers map.
121 msgpack::MapDocNode
getRegisters();
123 // Get (create if necessary) the .hardware_stages entry for the given calling
125 msgpack::MapDocNode
getHwStage(unsigned CC
);
127 bool setFromLegacyBlob(StringRef Blob
);
128 bool setFromMsgPackBlob(StringRef Blob
);
129 void toLegacyBlob(std::string
&Blob
);
130 void toMsgPackBlob(std::string
&Blob
);
133 } // end namespace llvm
135 #endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUPALMETADATA_H