[llvm] [DirectX] Convert private global variables to internal linkage during Finalize Linkage pass (PR #146406)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 30 12:02:59 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-directx
Author: Kaitlin Peng (kmpeng)
<details>
<summary>Changes</summary>
Fixes #<!-- -->140420. The switch.table.* validation errors were caused by DXIL not supporting private global variables. Converting them to internal linkage fixes the bug.
May need more discussion on the preserved analyses/a follow-up PR that fixes what this pass says it preserves.
---
Full diff: https://github.com/llvm/llvm-project/pull/146406.diff
1 Files Affected:
- (modified) llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp (+17-3)
``````````diff
diff --git a/llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp b/llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp
index 94b2dbe78c4f7..5f331dbd2d826 100644
--- a/llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp
+++ b/llvm/lib/Target/DirectX/DXILFinalizeLinkage.cpp
@@ -18,6 +18,16 @@
using namespace llvm;
static bool finalizeLinkage(Module &M) {
+ bool MadeChange = false;
+
+ // Convert private global variables to internal linkage.
+ for (GlobalVariable &GV : M.globals()) {
+ if (GV.hasPrivateLinkage()) {
+ GV.setLinkage(GlobalValue::InternalLinkage);
+ MadeChange = true;
+ }
+ }
+
SmallVector<Function *> Funcs;
// Collect non-entry and non-exported functions to set to internal linkage.
@@ -32,13 +42,17 @@ static bool finalizeLinkage(Module &M) {
}
for (Function *F : Funcs) {
- if (F->getLinkage() == GlobalValue::ExternalLinkage)
+ if (F->getLinkage() == GlobalValue::ExternalLinkage) {
F->setLinkage(GlobalValue::InternalLinkage);
- if (F->isDefTriviallyDead())
+ MadeChange = true;
+ }
+ if (F->isDefTriviallyDead()) {
M.getFunctionList().erase(F);
+ MadeChange = true;
+ }
}
- return false;
+ return MadeChange;
}
PreservedAnalyses DXILFinalizeLinkage::run(Module &M,
``````````
</details>
https://github.com/llvm/llvm-project/pull/146406
More information about the llvm-commits
mailing list