[llvm] [HLSL] Implement DXILResourceBindingAnalysis (PR #137258)
Ashley Coleman via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 30 11:12:18 PDT 2025
================
@@ -879,8 +883,121 @@ SmallVector<dxil::ResourceInfo *> DXILResourceMap::findByUse(const Value *Key) {
//===----------------------------------------------------------------------===//
+void DXILResourceBindingInfo::populate(Module &M, DXILResourceTypeMap &DRTM) {
+ struct Binding {
+ ResourceClass ResClass;
+ uint32_t Space;
+ uint32_t LowerBound;
+ uint32_t UpperBound;
+ Binding(ResourceClass RC, uint32_t Sp, uint32_t LB, uint32_t UB)
+ : ResClass(RC), Space(Sp), LowerBound(LB), UpperBound(UB) {}
+ };
+ SmallVector<Binding> Bindings;
+
+ // collect all of the llvm.dx.resource.handlefrombinding calls;
+ // make a note if there is llvm.dx.resource.handlefromimplicitbinding
+ for (Function &F : M.functions()) {
+ if (!F.isDeclaration())
+ continue;
+
+ switch (F.getIntrinsicID()) {
+ default:
+ continue;
+ case Intrinsic::dx_resource_handlefrombinding: {
+ auto *HandleTy = cast<TargetExtType>(F.getReturnType());
+ ResourceTypeInfo &RTI = DRTM[HandleTy];
+
+ for (User *U : F.users())
+ if (CallInst *CI = dyn_cast<CallInst>(U)) {
+ uint32_t Space =
+ cast<ConstantInt>(CI->getArgOperand(0))->getZExtValue();
+ uint32_t LowerBound =
+ cast<ConstantInt>(CI->getArgOperand(1))->getZExtValue();
+ int32_t Size =
+ cast<ConstantInt>(CI->getArgOperand(2))->getZExtValue();
+
+ // negative size means unbounded resource array;
+ // upper bound register overflow should be detected in Sema
+ assert((Size < 0 || (unsigned)LowerBound + Size - 1 <= UINT32_MAX) &&
+ "upper bound register overflow");
+ uint32_t UpperBound = Size < 0 ? UINT32_MAX : LowerBound + Size - 1;
+ Bindings.emplace_back(RTI.getResourceClass(), Space, LowerBound,
+ UpperBound);
+ }
+ break;
+ }
+ case Intrinsic::dx_resource_handlefromimplicitbinding: {
+ if (!F.user_empty())
+ ImplicitBinding = true;
----------------
V-FEXrt wrote:
nit:
```suggestion
ImplicitBinding = !F.user_empty();
```
https://github.com/llvm/llvm-project/pull/137258
More information about the llvm-commits
mailing list