LLVM 18.0.0git
DXILResource.h
Go to the documentation of this file.
1//===- DXILResource.h - DXIL Resource helper objects ----------------------===//
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 This file contains helper objects for working with DXIL Resources.
10///
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_TARGET_DIRECTX_DXILRESOURCE_H
14#define LLVM_TARGET_DIRECTX_DXILRESOURCE_H
15
17#include "llvm/ADT/StringRef.h"
19#include "llvm/IR/Metadata.h"
21#include <cstdint>
22
23namespace llvm {
24class Module;
25class GlobalVariable;
26
27namespace dxil {
28class CBufferDataLayout;
29
31protected:
39
40 void write(LLVMContext &Ctx, MutableArrayRef<Metadata *> Entries) const;
41
42 void print(raw_ostream &O, StringRef IDPrefix, StringRef BindingPrefix) const;
44 static StringRef getKindName(Kinds Kind);
45 static void printKind(Kinds Kind, unsigned Alignment, raw_ostream &OS,
46 bool SRV = false, bool HasCounter = false,
47 uint32_t SampleCount = 0);
48
49 // The value ordering of this enumeration is part of the DXIL ABI. Elements
50 // can only be added to the end, and not removed.
51 enum class ComponentType : uint32_t {
52 Invalid = 0,
53 I1,
54 I16,
55 U16,
56 I32,
57 U32,
58 I64,
59 U64,
60 F16,
61 F32,
62 F64,
72 };
73
75 static void printComponentType(Kinds Kind, ComponentType CompType,
76 unsigned Alignment, raw_ostream &OS);
77
78public:
80 std::optional<ComponentType> ElementType;
81
82 // The value ordering of this enumeration is part of the DXIL ABI. Elements
83 // can only be added to the end, and not removed.
84 enum Tags : uint32_t {
89 };
90
91 MDNode *write(LLVMContext &Ctx) const;
92 };
93};
94
95class UAVResource : public ResourceBase {
97 bool GloballyCoherent;
98 bool HasCounter;
99 bool IsROV;
101
102 void parseSourceType(StringRef S);
103
104public:
106
107 MDNode *write() const;
108 void print(raw_ostream &O) const;
109};
110
112 uint32_t CBufferSizeInBytes = 0; // Cbuffer used size in bytes.
113public:
116 MDNode *write() const;
117 void print(raw_ostream &O) const;
118};
119
120template <typename T> class ResourceTable {
121 StringRef MDName;
122
124
125public:
127 void collect(Module &M);
128 MDNode *write(Module &M) const;
129 void print(raw_ostream &O) const;
130};
131
132// FIXME: Fully computing the resource structures requires analyzing the IR
133// because some flags are set based on what operations are performed on the
134// resource. This partial patch handles some of the leg work, but not all of it.
135// See issue https://github.com/llvm/llvm-project/issues/57936.
137 ResourceTable<UAVResource> UAVs = {"hlsl.uavs"};
138 ResourceTable<ConstantBuffer> CBuffers = {"hlsl.cbufs"};
139
140public:
141 void collect(Module &M);
142 void write(Module &M) const;
143 void print(raw_ostream &O) const;
144 LLVM_DUMP_METHOD void dump() const;
145};
146
147} // namespace dxil
148} // namespace llvm
149
150#endif // LLVM_TARGET_DIRECTX_DXILRESOURCE_H
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:510
std::string Name
#define I(x, y, z)
Definition: MD5.cpp:58
Machine Check Debug Module
This file contains the declarations for metadata subclasses.
raw_pwrite_stream & OS
This file defines the SmallVector class.
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
Metadata node.
Definition: Metadata.h:1037
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:307
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1200
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
void setSize(CBufferDataLayout &DL)
void print(raw_ostream &O) const
void print(raw_ostream &O, StringRef IDPrefix, StringRef BindingPrefix) const
GlobalVariable * GV
Definition: DXILResource.h:33
static void printKind(Kinds Kind, unsigned Alignment, raw_ostream &OS, bool SRV=false, bool HasCounter=false, uint32_t SampleCount=0)
static StringRef getKindName(Kinds Kind)
static void printComponentType(Kinds Kind, ComponentType CompType, unsigned Alignment, raw_ostream &OS)
static StringRef getComponentTypeName(ComponentType CompType)
void write(LLVMContext &Ctx, MutableArrayRef< Metadata * > Entries) const
hlsl::ResourceKind Kinds
Definition: DXILResource.h:43
void print(raw_ostream &O) const
MDNode * write(Module &M) const
ResourceTable(StringRef Name)
Definition: DXILResource.h:126
LLVM_DUMP_METHOD void dump() const
void print(raw_ostream &O) const
void write(Module &M) const
void collect(Module &M)
MDNode * write() const
void print(raw_ostream &O) const
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
std::optional< ComponentType > ElementType
Definition: DXILResource.h:80
MDNode * write(LLVMContext &Ctx) const