LLVM  17.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 
16 #include "llvm/ADT/SmallVector.h"
17 #include "llvm/ADT/StringRef.h"
19 #include "llvm/IR/Metadata.h"
20 #include "llvm/Support/Compiler.h"
21 #include <cstdint>
22 
23 namespace llvm {
24 class Module;
25 class GlobalVariable;
26 
27 namespace dxil {
28 class CBufferDataLayout;
29 
30 class ResourceBase {
31 protected:
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,
63  SNormF16,
64  UNormF16,
65  SNormF32,
66  UNormF32,
67  SNormF64,
68  UNormF64,
71  LastEntry
72  };
73 
75  static void printComponentType(Kinds Kind, ComponentType CompType,
76  unsigned Alignment, raw_ostream &OS);
77 
78 public:
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 
95 class UAVResource : public ResourceBase {
96  ResourceBase::Kinds Shape;
97  bool GloballyCoherent;
98  bool HasCounter;
99  bool IsROV;
101 
102  void parseSourceType(StringRef S);
103 
104 public:
106 
107  MDNode *write() const;
108  void print(raw_ostream &O) const;
109 };
110 
111 class ConstantBuffer : public ResourceBase {
112  uint32_t CBufferSizeInBytes = 0; // Cbuffer used size in bytes.
113 public:
116  MDNode *write() const;
117  void print(raw_ostream &O) const;
118 };
119 
120 template <typename T> class ResourceTable {
121  StringRef MDName;
122 
124 
125 public:
126  ResourceTable(StringRef Name) : MDName(Name) {}
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.
136 class Resources {
137  ResourceTable<UAVResource> UAVs = {"hlsl.uavs"};
138  ResourceTable<ConstantBuffer> CBuffers = {"hlsl.cbufs"};
139 
140 public:
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
llvm::dxil::ResourceBase::ComponentType::I32
@ I32
llvm::dxil::ResourceBase::ComponentType::F64
@ F64
llvm::dxil::ResourceTable::ResourceTable
ResourceTable(StringRef Name)
Definition: DXILResource.h:126
HLSLResource.h
LLVM_DUMP_METHOD
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:492
llvm::dxil::ResourceBase
Definition: DXILResource.h:30
llvm::dxil::ConstantBuffer::setSize
void setSize(CBufferDataLayout &DL)
Definition: DXILResource.cpp:303
llvm::dxil::ResourceTable::print
void print(raw_ostream &O) const
Definition: DXILResource.cpp:319
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
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::dxil::CBufferDataLayout
Definition: CBufferDataLayout.h:29
llvm::dxil::ResourceBase::ExtendedProperties::Tags
Tags
Definition: DXILResource.h:84
llvm::dxil::ResourceBase::GV
GlobalVariable * GV
Definition: DXILResource.h:33
llvm::hlsl::FrontendResource
Definition: HLSLResource.h:57
Metadata.h
llvm::dxil::ResourceBase::printComponentType
static void printComponentType(Kinds Kind, ComponentType CompType, unsigned Alignment, raw_ostream &OS)
Definition: DXILResource.cpp:110
llvm::dxil::ResourceBase::printKind
static void printKind(Kinds Kind, unsigned Alignment, raw_ostream &OS, bool SRV=false, bool HasCounter=false, uint32_t SampleCount=0)
Definition: DXILResource.cpp:177
llvm::dxil::ResourceBase::ComponentType::U64
@ U64
llvm::dxil::ResourceBase::ExtendedProperties::SamplerFeedbackKind
@ SamplerFeedbackKind
Definition: DXILResource.h:87
StringRef.h
llvm::dxil::ResourceBase::ComponentType::U16
@ U16
llvm::SmallVector< T >
llvm::dxil::ResourceBase::ExtendedProperties::TypedBufferElementType
@ TypedBufferElementType
Definition: DXILResource.h:85
llvm::GlobalVariable
Definition: GlobalVariable.h:39
llvm::dxil::ResourceBase::ComponentType::PackedS8x32
@ PackedS8x32
llvm::dxil::ResourceBase::Kinds
hlsl::ResourceKind Kinds
Definition: DXILResource.h:43
llvm::dxil::ResourceBase::ResourceBase
ResourceBase(uint32_t I, hlsl::FrontendResource R)
Definition: DXILResource.cpp:59
llvm::dxil::ResourceBase::ComponentType::Invalid
@ Invalid
llvm::dxil::ConstantBuffer::write
MDNode * write() const
Definition: DXILResource.cpp:363
llvm::dxil::Resources::write
void write(Module &M) const
Definition: DXILResource.cpp:387
llvm::dxil::ResourceBase::RangeSize
uint32_t RangeSize
Definition: DXILResource.h:37
llvm::dxil::ResourceBase::ComponentType::UNormF16
@ UNormF16
llvm::dxil::ResourceBase::ComponentType::UNormF64
@ UNormF64
llvm::dxil::ResourceBase::ExtendedProperties::ElementType
std::optional< ComponentType > ElementType
Definition: DXILResource.h:80
llvm::dxil::ResourceBase::ComponentType::UNormF32
@ UNormF32
llvm::hlsl::ResourceKind
ResourceKind
Definition: HLSLResource.h:34
llvm::dxil::ConstantBuffer::ConstantBuffer
ConstantBuffer(uint32_t I, hlsl::FrontendResource R)
Definition: DXILResource.cpp:300
llvm::MutableArrayRef
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:27
llvm::dxil::ResourceBase::getKindName
static StringRef getKindName(Kinds Kind)
Definition: DXILResource.cpp:133
llvm::dxil::UAVResource::UAVResource
UAVResource(uint32_t I, hlsl::FrontendResource R)
Definition: DXILResource.cpp:233
llvm::dxil::ResourceBase::ExtendedProperties::Atomic64Use
@ Atomic64Use
Definition: DXILResource.h:88
llvm::dxil::ResourceTable::collect
void collect(Module &M)
Definition: DXILResource.cpp:26
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
llvm::dxil::ResourceBase::ExtendedProperties
Definition: DXILResource.h:79
llvm::dxil::ResourceBase::ComponentType::SNormF64
@ SNormF64
llvm::dxil::ResourceBase::LowerBound
uint32_t LowerBound
Definition: DXILResource.h:36
llvm::dxil::UAVResource::print
void print(raw_ostream &O) const
Definition: DXILResource.cpp:240
llvm::dxil::ResourceBase::ComponentType::I64
@ I64
llvm::dxil::ResourceBase::Space
uint32_t Space
Definition: DXILResource.h:35
llvm::RISCVFenceField::O
@ O
Definition: RISCVBaseInfo.h:274
llvm::dxil::ResourceBase::Name
StringRef Name
Definition: DXILResource.h:34
llvm::LLVMContext
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
I
#define I(x, y, z)
Definition: MD5.cpp:58
llvm::dxil::ResourceBase::ExtendedProperties::write
MDNode * write(LLVMContext &Ctx) const
Definition: DXILResource.cpp:324
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
llvm::MDNode
Metadata node.
Definition: Metadata.h:943
llvm::dxil::ResourceBase::ComponentType::U32
@ U32
llvm::dxil::ResourceBase::ComponentType::F16
@ F16
llvm::dxil::ResourceBase::ComponentType::SNormF32
@ SNormF32
llvm::dxil::ResourceBase::ID
uint32_t ID
Definition: DXILResource.h:32
llvm::dxil::ResourceTable::write
MDNode * write(Module &M) const
Definition: DXILResource.cpp:373
llvm::dxil::Resources
Definition: DXILResource.h:136
llvm::dxil::ResourceBase::print
void print(raw_ostream &O, StringRef IDPrefix, StringRef BindingPrefix) const
Definition: DXILResource.cpp:215
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
llvm::dxil::Resources::print
void print(raw_ostream &O) const
Definition: DXILResource.cpp:407
uint32_t
Compiler.h
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
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::dxil::ResourceBase::ComponentType::I1
@ I1
llvm::dxil::UAVResource::write
MDNode * write() const
Definition: DXILResource.cpp:349
llvm::dxil::ResourceBase::ExtendedProperties::StructuredBufferElementStride
@ StructuredBufferElementStride
Definition: DXILResource.h:86
llvm::dxil::ResourceBase::write
void write(LLVMContext &Ctx, MutableArrayRef< Metadata * > Entries) const
Definition: DXILResource.cpp:338
llvm::dxil::ResourceBase::ComponentType::PackedU8x32
@ PackedU8x32
llvm::dxil::ResourceBase::ComponentType
ComponentType
Definition: DXILResource.h:51
SmallVector.h
llvm::dxil::ResourceBase::getComponentTypeName
static StringRef getComponentTypeName(ComponentType CompType)
Definition: DXILResource.cpp:66
llvm::dxil::Resources::dump
LLVM_DUMP_METHOD void dump() const
Definition: DXILResource.cpp:420
llvm::dxil::ConstantBuffer
Definition: DXILResource.h:111
llvm::dxil::ResourceTable
Definition: DXILResource.h:120
llvm::dxil::ConstantBuffer::print
void print(raw_ostream &O) const
Definition: DXILResource.cpp:307
llvm::dxil::ResourceBase::ComponentType::LastEntry
@ LastEntry
llvm::dxil::ResourceBase::ComponentType::I16
@ I16
llvm::dxil::ResourceBase::ComponentType::F32
@ F32
llvm::dxil::ResourceBase::ComponentType::SNormF16
@ SNormF16
llvm::dxil::UAVResource
Definition: DXILResource.h:95
llvm::dxil::Resources::collect
void collect(Module &M)
Definition: DXILResource.cpp:54