blob: 36a3ec457e38a83d57e312473a3821f5559769ef [file] [log] [blame]
Tim Renoufd737b552019-03-20 17:42:00 +00001//===-- 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
17#include "llvm/ADT/StringRef.h"
18#include <map>
19
20namespace llvm {
21
22class AMDGPUTargetStreamer;
23class formatted_raw_ostream;
24class MCStreamer;
25class Module;
26
27class AMDGPUPALMetadata {
28 std::map<uint32_t, uint32_t> Registers;
29
30public:
31 // Read the amdgpu.pal.metadata supplied by the frontend, ready for
32 // per-function modification.
33 void readFromIR(Module &M);
34
35 // Set PAL metadata from a binary blob from the applicable .note record.
36 // Returns false if bad format. Blob must remain valid for the lifetime of
37 // the Metadata.
38 bool setFromBlob(unsigned Type, StringRef Blob);
39
40 // Set the rsrc1 register in the metadata for a particular shader stage.
41 // In fact this ORs the value into any previous setting of the register.
42 void setRsrc1(unsigned CC, unsigned Val);
43
44 // Set the rsrc2 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 setRsrc2(unsigned CC, unsigned Val);
47
48 // Set the SPI_PS_INPUT_ENA register in the metadata.
49 // In fact this ORs the value into any previous setting of the register.
50 void setSpiPsInputEna(unsigned Val);
51
52 // Set the SPI_PS_INPUT_ADDR register in the metadata.
53 // In fact this ORs the value into any previous setting of the register.
54 void setSpiPsInputAddr(unsigned Val);
55
56 // Get a register from the metadata, or 0 if not currently set.
57 unsigned getRegister(unsigned Reg);
58
59 // Set a register in the metadata.
60 // In fact this ORs the value into any previous setting of the register.
61 void setRegister(unsigned Reg, unsigned Val);
62
63 // Set the number of used vgprs in the metadata. This is an optional advisory
64 // record for logging etc; wave dispatch actually uses the rsrc1 register for
65 // the shader stage to determine the number of vgprs to allocate.
66 void setNumUsedVgprs(unsigned CC, unsigned Val);
67
68 // Set the number of used sgprs in the metadata. This is an optional advisory
69 // record for logging etc; wave dispatch actually uses the rsrc1 register for
70 // the shader stage to determine the number of sgprs to allocate.
71 void setNumUsedSgprs(unsigned CC, unsigned Val);
72
73 // Set the scratch size in the metadata.
74 void setScratchSize(unsigned CC, unsigned Val);
75
76 // Emit the accumulated PAL metadata as an asm directive.
77 // This is called from AMDGPUTargetAsmStreamer::Finish().
78 void toString(std::string &S);
79
80 // Emit the accumulated PAL metadata as a binary blob.
81 // This is called from AMDGPUTargetELFStreamer::Finish().
82 void toBlob(unsigned Type, std::string &S);
83};
84
85} // end namespace llvm
86
87#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUPALMETADATA_H