[llvm] [HLSL] Analyze updateCounter usage (PR #135669)
Ashley Coleman via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 22 10:15:02 PDT 2025
================
@@ -775,6 +778,42 @@ void DXILResourceMap::populate(Module &M, DXILResourceTypeMap &DRTM) {
// Adjust the resource binding to use the next ID.
RI.setBindingID(NextID++);
}
+
+ for (Function &F : M.functions()) {
+ if (!isUpdateCounterIntrinsic(F))
+ continue;
+
+ LLVM_DEBUG(dbgs() << "Update Counter Function: " << F.getName() << "\n");
+
+ for (const User *U : F.users()) {
+ const CallInst *CI = dyn_cast<CallInst>(U);
+ assert(CI && "Users of dx_resource_updateCounter must be call instrs");
+
+ // Determine if the use is an increment or decrement
+ Value *CountArg = CI->getArgOperand(1);
+ ConstantInt *CountValue = cast<ConstantInt>(CountArg);
+ int64_t CountLiteral = CountValue->getSExtValue();
+
+ // 0 is an unknown direction and shouldn't result in an insert
+ if (CountLiteral == 0)
+ continue;
+
+ ResourceCounterDirection Direction = ResourceCounterDirection::Decrement;
+ if (CountLiteral > 0)
+ Direction = ResourceCounterDirection::Increment;
+
+ // Collect all potential creation points for the handle arg
+ Value *HandleArg = CI->getArgOperand(0);
+ SmallVector<ResourceInfo *> RBInfos = findByUse(HandleArg);
+ for (ResourceInfo *RBInfo : RBInfos) {
+ if (RBInfo->CounterDirection == ResourceCounterDirection::Unknown ||
+ RBInfo->CounterDirection == Direction)
+ RBInfo->CounterDirection = Direction;
+ else
+ RBInfo->CounterDirection = ResourceCounterDirection::Invalid;
----------------
V-FEXrt wrote:
Conflicting information!
If CounterDirection is detected as both Increment and Decrement that is considered invalid (because only one direction is allowed)
https://github.com/llvm/llvm-project/pull/135669
More information about the llvm-commits
mailing list