[llvm] [HLSL] Analyze update counter usage (PR #130356)
Ashley Coleman via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 21 12:44:01 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();
+
+ ResourceCounterDirection Direction = ResourceCounterDirection::Unknown;
+ if (CountLiteral > 0)
+ Direction = ResourceCounterDirection::Increment;
+ if (CountLiteral < 0)
+ Direction = ResourceCounterDirection::Decrement;
+
+ // Collect all potential creation points for the handle arg
+ Value *HandleArg = CI->getArgOperand(0);
+ SmallVector<dxil::ResourceBindingInfo> RBInfos = DBM.findByUse(HandleArg);
+ for (const dxil::ResourceBindingInfo RBInfo : RBInfos)
+ DiagCounterDirs.emplace_back(RBInfo, Direction, &F, CI);
+ }
+ }
+
+ // An entry that is not in the map is considered unknown so its wasted
+ // overhead and increased complexity to keep an entry explicitly marked
+ // unknown
+ const auto RemoveEnd = std::remove_if(
+ DiagCounterDirs.begin(), DiagCounterDirs.end(), [](const auto &Item) {
+ return std::get<ResourceCounterDirection>(Item) ==
+ ResourceCounterDirection::Unknown;
+ });
+
+ // Sort by the Binding and Direction for fast lookup
+ std::sort(DiagCounterDirs.begin(), RemoveEnd,
----------------
V-FEXrt wrote:
It shouldn't matter right? The goal is that we mention every CallInst in the diag. One per update counter call. For this to work we need to be able to emit multiple Diags per invocation but IIRC we do that for release builds and its only test/local/debug builds that assert after the first diag?
https://github.com/llvm/llvm-project/pull/130356
More information about the llvm-commits
mailing list