[llvm-branch-commits] [BOLT] Eliminate dead jump tables (PR #91666)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu May 9 14:56:10 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-bolt
Author: Amir Ayupov (aaupov)
<details>
<summary>Changes</summary>
Dead jump tables such as those arising from FIXED_PIC_BRANCH
optimization don't need to be updated or moved. Further, if any jump
table entry points to a block removed by unreachable code elimination,
we would be unable to update it and jump table emission would fail.
Identify non-referenced jump tables and delete them to prevent that.
Test Plan: NFC for existing tests.
---
Full diff: https://github.com/llvm/llvm-project/pull/91666.diff
1 Files Affected:
- (modified) bolt/lib/Core/BinaryFunction.cpp (+20)
``````````diff
diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp
index 11103f7bdce8..f74ecea8ac0a 100644
--- a/bolt/lib/Core/BinaryFunction.cpp
+++ b/bolt/lib/Core/BinaryFunction.cpp
@@ -1697,6 +1697,26 @@ void BinaryFunction::postProcessEntryPoints() {
}
void BinaryFunction::postProcessJumpTables() {
+ // Set of JTs accessed from this function.
+ std::unordered_set<uint64_t> LiveJTs;
+ for (auto &JTSite : JTSites)
+ LiveJTs.emplace(JTSite.second);
+
+ // Remove dead jump tables (reference removed as a result of
+ // POSSIBLE_PIC_FIXED_BRANCH optimization).
+ for (auto JTI = JumpTables.begin(), JTE = JumpTables.end(); JTI != JTE; ) {
+ const uint64_t Address = JTI->first;
+ JumpTable *JT = JTI->second;
+ bool HasOneParent = JT->Parents.size() == 1;
+ if (LiveJTs.count(Address) == 0 && HasOneParent) {
+ BC.deregisterJumpTable(Address);
+ delete JT;
+ JTI = JumpTables.erase(JTI);
+ continue;
+ }
+ ++JTI;
+ }
+
// Create labels for all entries.
for (auto &JTI : JumpTables) {
JumpTable &JT = *JTI.second;
``````````
</details>
https://github.com/llvm/llvm-project/pull/91666
More information about the llvm-branch-commits
mailing list