[llvm] [DirectX] Add Resource uses to Resource Handle map in DXILResourceMap (PR #112798)
Zhengxing li via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 21 11:44:34 PDT 2024
================
@@ -744,6 +750,47 @@ DXILResourceMap::DXILResourceMap(
}
}
+// Parameter origCallInst: original Resource Handle
+// Parameter newCallInst: new Resource Handle
+//
+// This function is needed when origCallInst's lowered to newCallInst.
+//
+// Because origCallInst and its uses will be replaced by newCallInst and new def
+// instructions after lowering. The [origCallInst, resource info] entry in
+// CallMap and [origCallInst's use, origCallInst] entries in ResUseToHandleMap
+// have to be updated per the changes in lowering.
+//
+// What this function does are:
+// 1. Add [newCallInst, resource info] entry in CallMap
+// 2. Add [origCallInst's use, newCallInst] entries in ResUseToHandleMap
+// 3. Remove [origCallInst, resource info] entry in CallMap
+// 4. Remove [origCallInst's use, origCallInst] entries in ResUseToHandleMap
+//
+// Remove those entries related to origCallInst in maps is necessary since
+// origCallInst's no longer existing after lowering. Moreover, keeping those
+// entries in maps will crash DXILResourceMap::print function
+//
+// FYI:
+// Make sure to invoke this function before origCallInst->replaceAllUsesWith()
+// and origCallInst->eraseFromParent() since this function needs to visit
+// origCallInst and its uses.
+//
+void DXILResourceMap::updateResourceMap(CallInst *origCallInst,
+ CallInst *newCallInst) {
+ assert((origCallInst != nullptr) && (newCallInst != nullptr) &&
+ (origCallInst != newCallInst));
+
+ CallMap.try_emplace(newCallInst, CallMap[origCallInst]);
+ CallMap.erase(origCallInst);
+
+ // Update ResUseToHandleMap since Resource Handle changed
+ for (auto it = origCallInst->users().begin();
+ it != origCallInst->users().end(); ++it) {
+ CallInst *CI_Use = dyn_cast<CallInst>(*it);
+ ResUseToHandleMap[CI_Use] = newCallInst;
----------------
lizhengxing wrote:
@hekota Done. Updated the comment.
https://github.com/llvm/llvm-project/pull/112798
More information about the llvm-commits
mailing list