[llvm] [HLSL] Analyze update counter usage (PR #130356)
Justin Bogner via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 19 17:56:30 PDT 2025
================
@@ -823,8 +827,153 @@ DXILBindingMap::findByUse(const Value *Key) const {
//===----------------------------------------------------------------------===//
+static bool isUpdateCounterIntrinsic(Function &F) {
+ return F.getIntrinsicID() == Intrinsic::dx_resource_updatecounter;
+}
+
+void DXILResourceCounterDirectionMap::populate(Module &M, DXILBindingMap &DBM) {
+ std::vector<std::tuple<dxil::ResourceBindingInfo, ResourceCounterDirection,
+ const Function *, const CallInst *>>
+ DiagCounterDirs;
+
+ for (Function &F : M.functions()) {
+ if (!isUpdateCounterIntrinsic(F))
+ continue;
+
+ 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 = dyn_cast<ConstantInt>(CountArg);
+ int64_t CountLiteral = CountValue->getSExtValue();
----------------
bogner wrote:
Should this be `cast<ConstantInt>(CountArg)`, which assumes the cast will always succeed? As is this is missing a null check. If non-constant values are possible here we'll need to add handling for that.
https://github.com/llvm/llvm-project/pull/130356
More information about the llvm-commits
mailing list