[llvm] [DirectX] Eliminate resource global variables from module (PR #114105)

Justin Bogner via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 1 11:20:54 PDT 2024


================
@@ -204,6 +204,22 @@ class OpLowerer {
     CleanupCasts.clear();
   }
 
+  // Remove the resource global associated with the handleFromBinding call
+  // instruction and their uses as they aren't needed anymore.
+  void removeResourceGlobals(CallInst *CI) {
+    for (User *User : make_early_inc_range(CI->users())) {
+      if (StoreInst *Store = dyn_cast<StoreInst>(User)) {
+        Value *V = Store->getOperand(1);
+        Store->eraseFromParent();
+        if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V))
+          if (GV->use_empty()) {
----------------
bogner wrote:

Might be worth leaving a TODO comment around here somewhere that says we should really validate that all of the globals do eventually get removed, since otherwise we'll generate a broken module. Actually implementing that validation can probably be left for later for now, since it would be quite difficult to do locally here.

https://github.com/llvm/llvm-project/pull/114105


More information about the llvm-commits mailing list