18#include "llvm/IR/IntrinsicsDirectX.h"
23#define DEBUG_TYPE "dxil-post-optimization-validation"
31 case DescriptorRangeType::SRV:
32 return ResourceClass::SRV;
33 case DescriptorRangeType::UAV:
34 return ResourceClass::UAV;
35 case DescriptorRangeType::CBV:
36 return ResourceClass::CBuffer;
37 case DescriptorRangeType::Sampler:
38 return ResourceClass::Sampler;
46 case RootParameterType::Constants32Bit:
47 return ResourceClass::CBuffer;
48 case RootParameterType::SRV:
49 return ResourceClass::SRV;
50 case RootParameterType::UAV:
51 return ResourceClass::UAV;
52 case RootParameterType::CBV:
53 return ResourceClass::CBuffer;
54 case dxbc::RootParameterType::DescriptorTable:
61 for (
const auto &
UAV : DRM.
uavs()) {
62 if (
UAV.CounterDirection != ResourceCounterDirection::Invalid)
67 if (*DRM.
find(MaybeHandle) ==
UAV) {
68 ResourceHandle = MaybeHandle;
73 StringRef Message =
"RWStructuredBuffers may increment or decrement their "
74 "counters, but not both.";
75 for (
const auto &U : ResourceHandle->
users()) {
76 const CallInst *CI = dyn_cast<CallInst>(U);
77 if (!CI && CI->
getIntrinsicID() != Intrinsic::dx_resource_updatecounter)
90 OS <<
"resource " << R1.
getName() <<
" at register "
92 <<
" at register " <<
R2.getBinding().LowerBound <<
" in space "
93 <<
R2.getBinding().Space;
98 [[maybe_unused]]
bool ErrorFound =
false;
99 for (
const auto &ResList :
104 for (
auto *
I = ResList.begin() + 1;
I != ResList.end(); ++
I) {
107 while (RI != ResList.end() &&
116 assert(ErrorFound &&
"this function should be called only when if "
117 "DXILResourceBindingInfo::hasOverlapingBinding() is "
118 "true, yet no overlapping binding was found");
129 <<
" (space=" <<
R2.Space <<
", registers=[" <<
R2.LowerBound <<
", "
130 <<
R2.UpperBound <<
"])";
140 <<
" in space " << Unbound.
Space
141 <<
" does not have a binding in the Root Signature";
149 return dxbc::ShaderVisibility::Pixel;
151 return dxbc::ShaderVisibility::Vertex;
153 return dxbc::ShaderVisibility::Geometry;
155 return dxbc::ShaderVisibility::Hull;
157 return dxbc::ShaderVisibility::Domain;
159 return dxbc::ShaderVisibility::Mesh;
161 return dxbc::ShaderVisibility::All;
179 if (ParamVisibility != dxbc::ShaderVisibility::All &&
180 ParamVisibility != Visibility)
184 case dxbc::RootParameterType::Constants32Bit: {
187 Builder.
trackBinding(dxil::ResourceClass::CBuffer, Const.RegisterSpace,
188 Const.ShaderRegister, Const.ShaderRegister,
193 case dxbc::RootParameterType::SRV:
194 case dxbc::RootParameterType::UAV:
195 case dxbc::RootParameterType::CBV: {
199 Desc.ShaderRegister,
Desc.ShaderRegister,
204 case dxbc::RootParameterType::DescriptorTable: {
210 Range.NumDescriptors == ~0U
211 ?
Range.BaseShaderRegister
212 :
Range.BaseShaderRegister +
Range.NumDescriptors - 1;
216 Range.RegisterSpace,
Range.BaseShaderRegister, UpperBound,
238 ResourceClass RC = DRTM[RI.getHandleTy()].getResourceClass();
265 "DXILResourceImplicitBinding pass");
284class DXILPostOptimizationValidationLegacy :
public ModulePass {
286 bool runOnModule(
Module &M)
override {
288 getAnalysis<DXILResourceWrapperPass>().getResourceMap();
290 getAnalysis<DXILResourceBindingWrapperPass>().getBindingInfo();
292 getAnalysis<RootSignatureAnalysisWrapper>().getRSInfo();
294 getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata();
296 getAnalysis<DXILResourceTypeWrapperPass>().getResourceTypeMap();
302 return "DXIL Post Optimization Validation";
304 DXILPostOptimizationValidationLegacy() :
ModulePass(
ID) {}
320char DXILPostOptimizationValidationLegacy::ID = 0;
324 "DXIL Post Optimization Validation",
false,
false)
335 return new DXILPostOptimizationValidationLegacy();
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
DXIL Post Optimization Validation
static dxbc::ShaderVisibility tripleToVisibility(llvm::Triple::EnvironmentType ET)
static ResourceClass toResourceClass(dxbc::DescriptorRangeType RangeType)
static void reportRegNotBound(Module &M, ResourceClass Class, const llvm::dxil::ResourceInfo::ResourceBinding &Unbound)
static void reportOverlappingError(Module &M, ResourceInfo R1, ResourceInfo R2)
static void reportErrors(Module &M, DXILResourceMap &DRM, DXILResourceBindingInfo &DRBI, RootSignatureBindingInfo &RSBI, dxil::ModuleMetadataInfo &MMI, DXILResourceTypeMap &DRTM)
static void validateRootSignature(Module &M, const mcdxbc::RootSignatureDesc &RSD, dxil::ModuleMetadataInfo &MMI, DXILResourceMap &DRM, DXILResourceTypeMap &DRTM)
static mcdxbc::RootSignatureDesc * getRootSignature(RootSignatureBindingInfo &RSBI, dxil::ModuleMetadataInfo &MMI)
static void reportOverlappingBinding(Module &M, DXILResourceMap &DRM)
static void reportInvalidDirection(Module &M, DXILResourceMap &DRM)
static void reportOverlappingRegisters(Module &M, const llvm::hlsl::Binding &R1, const llvm::hlsl::Binding &R2)
DXIL Resource Implicit Binding
Module.h This file contains the declarations for the Module class.
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
PowerPC MI Peephole Optimization
ModuleAnalysisManager MAM
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
This file defines the SmallString class.
A container for analyses that lazily runs them and caches their results.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
LLVM_ABI Intrinsic::ID getIntrinsicID() const
Returns the intrinsic ID of the intrinsic called or Intrinsic::not_intrinsic if the called function i...
This class represents a function call, abstracting a target machine's calling convention.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM)
bool hasOverlappingBinding() const
bool hasImplicitBinding() const
iterator find(const CallInst *Key)
bool hasInvalidCounterDirection() const
iterator_range< iterator > samplers()
iterator_range< iterator > srvs()
iterator_range< iterator > cbuffers()
iterator_range< iterator > uavs()
iterator_range< call_iterator > calls()
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
LLVM_ABI const Function * getFunction() const
Return the function this instruction belongs to.
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.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
StringRef - Represent a constant reference to a string, i.e.
The instances of the Type class are immutable: once they are created, they are never changed.
iterator_range< user_iterator > users()
StringRef getName() const
const ResourceBinding & getBinding() const
Wrapper pass for the legacy pass manager.
mcdxbc::RootSignatureDesc * getDescForFunction(const Function *F)
Wrapper pass for the legacy pass manager.
Builder class for creating a /c BindingInfo.
LLVM_ABI const Binding & findOverlapping(const Binding &ReportedBinding) const
For use in the ReportOverlap callback of calculateBindingInfo - finds a binding that the ReportedBind...
void trackBinding(dxil::ResourceClass RC, uint32_t Space, uint32_t LowerBound, uint32_t UpperBound, const void *Cookie)
LLVM_ABI BindingInfo calculateBindingInfo(llvm::function_ref< void(const BindingInfoBuilder &Builder, const Binding &Overlapping)> ReportOverlap)
Calculate the binding info - ReportOverlap will be called once for each overlapping binding.
LLVM_ABI BoundRegs takeBoundRegs()
bool isBound(dxil::ResourceClass RC, uint32_t Space, uint32_t LowerBound, uint32_t UpperBound) const
A raw_ostream that writes to an SmallVector or SmallString.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
LLVM_ABI StringRef getResourceClassName(ResourceClass RC)
This is an optimization pass for GlobalISel generic memory operations.
ModulePass * createDXILPostOptimizationValidationLegacyPass()
Pass to lowering LLVM intrinsic call to DXIL op function call.
Description of the encoding of one expression Op.
bool overlapsWith(const ResourceBinding &RHS) const
SmallVector< dxbc::RTS0::v2::DescriptorRange > Ranges
dxbc::ShaderVisibility Visibility
dxbc::RootParameterType Type
const RootDescriptor & getRootDescriptor(size_t Index) const
const DescriptorTable & getDescriptorTable(size_t Index) const
const RootConstants & getConstant(size_t Index) const
SmallVector< dxbc::RTS0::v1::StaticSampler > StaticSamplers
mcdxbc::RootParametersContainer ParametersContainer