1//===- DXILResource.h - Representations of DXIL resources -------*- 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//===----------------------------------------------------------------------===// 9#ifndef LLVM_ANALYSIS_DXILRESOURCE_H 10#define LLVM_ANALYSIS_DXILRESOURCE_H 28classDXILResourceTypeMap;
32/// The dx.RawBuffer target extension type 34/// `target("dx.RawBuffer", Type, IsWriteable, IsROV)` 42// TODO: We need to be more prescriptive here, but since there's some debate 43// over whether byte address buffer should have a void type or an i8 type, 44// accept either for now. 56returnT->getName() ==
"dx.RawBuffer";
59return isa<TargetExtType>(
T) &&
classof(cast<TargetExtType>(
T));
63/// The dx.TypedBuffer target extension type 65/// `target("dx.TypedBuffer", Type, IsWriteable, IsROV, IsSigned)` 78returnT->getName() ==
"dx.TypedBuffer";
81return isa<TargetExtType>(
T) &&
classof(cast<TargetExtType>(
T));
85/// The dx.Texture target extension type 87/// `target("dx.Texture", Type, IsWriteable, IsROV, IsSigned, Dimension)` 103returnT->getName() ==
"dx.Texture";
106return isa<TargetExtType>(
T) &&
classof(cast<TargetExtType>(
T));
110/// The dx.MSTexture target extension type 112/// `target("dx.MSTexture", Type, IsWriteable, Samples, IsSigned, Dimension)` 128returnT->getName() ==
"dx.MSTexture";
131return isa<TargetExtType>(
T) &&
classof(cast<TargetExtType>(
T));
135/// The dx.FeedbackTexture target extension type 137/// `target("dx.FeedbackTexture", FeedbackType, Dimension)` 152returnT->getName() ==
"dx.FeedbackTexture";
155return isa<TargetExtType>(
T) &&
classof(cast<TargetExtType>(
T));
159/// The dx.CBuffer target extension type 161/// `target("dx.CBuffer", <Type>, ...)` 172returnT->getName() ==
"dx.CBuffer";
175return isa<TargetExtType>(
T) &&
classof(cast<TargetExtType>(
T));
179/// The dx.Sampler target extension type 181/// `target("dx.Sampler", SamplerType)` 193returnT->getName() ==
"dx.Sampler";
196return isa<TargetExtType>(
T) &&
classof(cast<TargetExtType>(
T));
200//===----------------------------------------------------------------------===// 211 std::tie(
RHS.GloballyCoherent,
RHS.HasCounter,
RHS.IsROV);
216 std::tie(
RHS.GloballyCoherent,
RHS.HasCounter,
RHS.IsROV);
222// Note: we store an integer here rather than using `MaybeAlign` because in 223// GCC 7 MaybeAlign isn't trivial so having one in this union would delete 224// our move constructor. 225// See https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0602r4.html 243 std::tie(
RHS.ElementTy,
RHS.ElementCount);
248 std::tie(
RHS.ElementTy,
RHS.ElementCount);
255// GloballyCoherent and HasCounter aren't really part of the type and need to 256// be determined by analysis, so they're just provided directly by the 257// DXILResourceTypeMap when we construct these. 258bool GloballyCoherent;
267bool HasCounter =
false);
269bool HasCounter =
false)
271 GloballyCoherent, HasCounter) {}
276// Conditions to check before accessing specific views. 285// Views into the type. 307//===----------------------------------------------------------------------===// 319 std::tie(
RHS.RecordID,
RHS.Space,
RHS.LowerBound,
RHS.Size);
322return !(*
this ==
RHS);
326 std::tie(
RHS.RecordID,
RHS.Space,
RHS.LowerBound,
RHS.Size);
331 ResourceBinding Binding;
339 : Binding{RecordID, Space, LowerBound,
Size}, HandleTy(HandleTy),
352 std::pair<uint32_t, uint32_t>
356return std::tie(Binding, HandleTy, Symbol) ==
357 std::tie(
RHS.Binding,
RHS.HandleTy,
RHS.Symbol);
360return !(*
this ==
RHS);
363return Binding <
RHS.Binding;
372//===----------------------------------------------------------------------===// 382auto It = Infos.
find(Ty);
383if (It != Infos.
end())
400// Running the pass just generates an empty map, which will be filled when 401// users of the pass query the results. 421//===----------------------------------------------------------------------===// 426unsigned FirstUAV = 0;
427unsigned FirstCBuffer = 0;
428unsigned FirstSampler = 0;
430 /// Populate the map given the resource binding calls in the given module. 445auto Pos = CallMap.
find(Key);
446return Pos == CallMap.
end() ? Infos.
end() : (Infos.
begin() + Pos->second);
450auto Pos = CallMap.
find(Key);
451return Pos == CallMap.
end() ? Infos.
end() : (Infos.
begin() + Pos->second);
510 /// Gather resource info for the module \c M. 514/// Printer pass for the \c DXILResourceBindingAnalysis results. 528 std::unique_ptr<DXILBindingMap> Map;
532staticcharID;
// Class identification, replacement for typeinfo 552#endif// LLVM_ANALYSIS_DXILRESOURCE_H MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This header defines various interfaces for pass management in LLVM.
This file implements a map that provides insertion order iteration.
API to communicate dependencies between analyses during invalidation.
A container for analyses that lazily runs them and caches their results.
Represent the analysis usage information of a pass.
This class represents a function call, abstracting a target machine's calling convention.
iterator_range< const_iterator > srvs() const
iterator_range< iterator > cbuffers()
iterator find(const CallInst *Key)
const_iterator sampler_end() const
iterator_range< const_iterator > samplers() const
void print(raw_ostream &OS, DXILResourceTypeMap &DRTM, const DataLayout &DL) const
const_iterator sampler_begin() const
const_iterator begin() const
const_iterator cbuffer_end() const
const_iterator srv_begin() const
iterator_range< iterator > srvs()
const_iterator find(const CallInst *Key) const
iterator_range< iterator > samplers()
iterator_range< const_iterator > uavs() const
iterator_range< const_iterator > cbuffers() const
const_iterator end() const
const_iterator uav_end() const
const_iterator cbuffer_begin() const
const_iterator srv_end() const
const_iterator uav_begin() const
iterator_range< iterator > uavs()
DXILBindingMap run(Module &M, ModuleAnalysisManager &AM)
Gather resource info for the module M.
Printer pass for the DXILResourceBindingAnalysis results.
DXILResourceBindingPrinterPass(raw_ostream &OS)
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
bool runOnModule(Module &M) override
runOnModule - Virtual method overriden by subclasses to process the module being operated on.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
~DXILResourceBindingWrapperPass() override
DXILResourceBindingWrapperPass()
void print(raw_ostream &OS, const Module *M) const override
print - Print out the internal state of the pass.
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
const DXILBindingMap & getBindingMap() const
DXILBindingMap & getBindingMap()
DXILResourceTypeMap run(Module &M, ModuleAnalysisManager &AM)
DXILResourceTypeMap Result
dxil::ResourceTypeInfo & operator[](TargetExtType *Ty)
bool invalidate(Module &M, const PreservedAnalyses &PA, ModuleAnalysisManager::Invalidator &Inv)
DXILResourceTypeWrapperPass()
DXILResourceTypeMap & getResourceTypeMap()
const DXILResourceTypeMap & getResourceTypeMap() const
A parsed version of the target data layout string in and methods for querying it.
iterator find(const_arg_type_t< KeyT > Val)
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&...Args)
ImmutablePass class - This class is used to provide information that does not need to be run.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
A Module instance is used to store all the information related to an LLVM module.
A set of analyses that are preserved following a run of a transformation pass.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
Class to represent struct types.
Class to represent target extensions types, which are generally unintrospectable from target-independ...
Type * getTypeParameter(unsigned i) const
unsigned getIntParameter(unsigned i) const
The instances of the Type class are immutable: once they are created, they are never changed.
bool isIntegerTy() const
True if this is an instance of IntegerType.
bool isVoidTy() const
Return true if this is 'void'.
The dx.CBuffer target extension type.
static bool classof(const TargetExtType *T)
CBufferExtType & operator=(const CBufferExtType &)=delete
CBufferExtType(const CBufferExtType &)=delete
static bool classof(const Type *T)
uint32_t getCBufferSize() const
Type * getResourceType() const
The dx.FeedbackTexture target extension type.
dxil::SamplerFeedbackType getFeedbackType() const
FeedbackTextureExtType(const FeedbackTextureExtType &)=delete
dxil::ResourceKind getDimension() const
FeedbackTextureExtType & operator=(const FeedbackTextureExtType &)=delete
static bool classof(const TargetExtType *T)
FeedbackTextureExtType()=delete
static bool classof(const Type *T)
The dx.MSTexture target extension type.
dxil::ResourceKind getDimension() const
MSTextureExtType(const MSTextureExtType &)=delete
static bool classof(const TargetExtType *T)
MSTextureExtType()=delete
Type * getResourceType() const
uint32_t getSampleCount() const
static bool classof(const Type *T)
MSTextureExtType & operator=(const MSTextureExtType &)=delete
The dx.RawBuffer target extension type.
static bool classof(const TargetExtType *T)
bool isStructured() const
RawBufferExtType()=delete
RawBufferExtType(const RawBufferExtType &)=delete
static bool classof(const Type *T)
RawBufferExtType & operator=(const RawBufferExtType &)=delete
Type * getResourceType() const
const StringRef getName() const
bool operator==(const ResourceBindingInfo &RHS) const
void setBindingID(unsigned ID)
bool operator<(const ResourceBindingInfo &RHS) const
GlobalVariable * createSymbol(Module &M, StructType *Ty, StringRef Name="")
std::pair< uint32_t, uint32_t > getAnnotateProps(Module &M, dxil::ResourceTypeInfo &RTI) const
TargetExtType * getHandleTy() const
MDTuple * getAsMetadata(Module &M, dxil::ResourceTypeInfo &RTI) const
ResourceBindingInfo(uint32_t RecordID, uint32_t Space, uint32_t LowerBound, uint32_t Size, TargetExtType *HandleTy, GlobalVariable *Symbol=nullptr)
const ResourceBinding & getBinding() const
bool operator!=(const ResourceBindingInfo &RHS) const
void print(raw_ostream &OS, dxil::ResourceTypeInfo &RTI, const DataLayout &DL) const
dxil::ResourceClass getResourceClass() const
uint32_t getMultiSampleCount() const
uint32_t getCBufferSize(const DataLayout &DL) const
bool operator<(const ResourceTypeInfo &RHS) const
bool isMultiSample() const
dxil::SamplerType getSamplerType() const
void setHasCounter(bool V)
TypedInfo getTyped() const
bool operator!=(const ResourceTypeInfo &RHS) const
TargetExtType * getHandleTy() const
StructType * createElementStruct()
ResourceTypeInfo(TargetExtType *HandleTy, bool GloballyCoherent=false, bool HasCounter=false)
void setGloballyCoherent(bool V)
StructInfo getStruct(const DataLayout &DL) const
dxil::SamplerFeedbackType getFeedbackType() const
dxil::ResourceKind getResourceKind() const
void print(raw_ostream &OS, const DataLayout &DL) const
The dx.Sampler target extension type.
SamplerExtType(const SamplerExtType &)=delete
static bool classof(const Type *T)
dxil::SamplerType getSamplerType() const
SamplerExtType & operator=(const SamplerExtType &)=delete
static bool classof(const TargetExtType *T)
The dx.Texture target extension type.
static bool classof(const TargetExtType *T)
dxil::ResourceKind getDimension() const
Type * getResourceType() const
TextureExtType & operator=(const TextureExtType &)=delete
TextureExtType(const TextureExtType &)=delete
static bool classof(const Type *T)
The dx.TypedBuffer target extension type.
Type * getResourceType() const
TypedBufferExtType & operator=(const TypedBufferExtType &)=delete
TypedBufferExtType()=delete
static bool classof(const TargetExtType *T)
TypedBufferExtType(const TypedBufferExtType &)=delete
static bool classof(const Type *T)
A range adaptor for a pair of iterators.
This class implements an extremely fast bulk output stream that can only output to a stream.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
ResourceKind
The kind of resource for an SRV or UAV resource.
ElementType
The element type of an SRV or UAV resource.
This is an optimization pass for GlobalISel generic memory operations.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
ModulePass * createDXILResourceTypeWrapperPassPass()
ModulePass * createDXILResourceBindingWrapperPassPass()
A CRTP mix-in that provides informational APIs needed for analysis passes.
A special type used by analysis passes to provide an address that identifies that particular analysis...
A CRTP mix-in to automatically provide informational APIs needed for passes.
bool operator!=(const ResourceBinding &RHS) const
bool operator<(const ResourceBinding &RHS) const
bool operator==(const ResourceBinding &RHS) const
bool operator==(const StructInfo &RHS) const
bool operator!=(const StructInfo &RHS) const
bool operator<(const StructInfo &RHS) const
bool operator<(const TypedInfo &RHS) const
bool operator==(const TypedInfo &RHS) const
dxil::ElementType ElementTy
bool operator!=(const TypedInfo &RHS) const
bool operator!=(const UAVInfo &RHS) const
bool operator==(const UAVInfo &RHS) const
bool operator<(const UAVInfo &RHS) const