| Tim Renouf | d737b55 | 2019-03-20 17:42:00 +0000 | [diff] [blame] | 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 | |
| 17 | #include "llvm/ADT/StringRef.h" |
| 18 | #include <map> |
| 19 | |
| 20 | namespace llvm { |
| 21 | |
| 22 | class AMDGPUTargetStreamer; |
| 23 | class formatted_raw_ostream; |
| 24 | class MCStreamer; |
| 25 | class Module; |
| 26 | |
| 27 | class AMDGPUPALMetadata { |
| 28 | std::map<uint32_t, uint32_t> Registers; |
| 29 | |
| 30 | public: |
| 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 |