diff options
author | Greg Roth <grroth@microsoft.com> | 2024-11-12 09:52:14 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-12 09:52:14 -0700 |
commit | 47ef3a0951e1f285caef4aff289b12ed0a57137d (patch) | |
tree | 94bc8bdb27a15d3567803d9e7647ba08aa2b7d6f /llvm/lib | |
parent | 63fb980d50c2ab513dd046f93983bab93dee787f (diff) | |
download | llvm-47ef3a0951e1f285caef4aff289b12ed0a57137d.zip llvm-47ef3a0951e1f285caef4aff289b12ed0a57137d.tar.gz llvm-47ef3a0951e1f285caef4aff289b12ed0a57137d.tar.bz2 |
[DirectX] Eliminate resource global variables from module (#114105)
By giving these intrinsics their appropriate attributes, loads of
globals that are stored on the other side of these calls can be
eliminated by the EarlyCSE pass. Stores to the same globals and the
globals themselves require more direct intervention as part of the
create/annotated handle lowering.
Adds a test that verifies that the unneeded globals and their uses can
be eliminated and also that the attributes are set properly.
Fixes #104271
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Target/DirectX/DXILOpLowering.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/llvm/lib/Target/DirectX/DXILOpLowering.cpp b/llvm/lib/Target/DirectX/DXILOpLowering.cpp index 0dd3a8d..02b4411 100644 --- a/llvm/lib/Target/DirectX/DXILOpLowering.cpp +++ b/llvm/lib/Target/DirectX/DXILOpLowering.cpp @@ -204,6 +204,25 @@ public: CleanupCasts.clear(); } + // Remove the resource global associated with the handleFromBinding call + // instruction and their uses as they aren't needed anymore. + // TODO: We should verify that all the globals get removed. + // It's expected we'll need a custom pass in the future that will eliminate + // the need for this here. + 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()) { + GV->removeDeadConstantUsers(); + GV->eraseFromParent(); + } + } + } + } + [[nodiscard]] bool lowerToCreateHandle(Function &F) { IRBuilder<> &IRB = OpBuilder.getIRB(); Type *Int8Ty = IRB.getInt8Ty(); @@ -228,6 +247,8 @@ public: Value *Cast = createTmpHandleCast(*OpCall, CI->getType()); + removeResourceGlobals(CI); + CI->replaceAllUsesWith(Cast); CI->eraseFromParent(); return Error::success(); @@ -272,6 +293,8 @@ public: Value *Cast = createTmpHandleCast(*OpAnnotate, CI->getType()); + removeResourceGlobals(CI); + CI->replaceAllUsesWith(Cast); CI->eraseFromParent(); |