[PATCH] D90498: Fix the compilation assertion due to unreachable BB pruning not deleting the associated BB from the jump tables
Victor Huang via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 30 14:13:05 PDT 2020
NeHuang created this revision.
NeHuang added reviewers: cperfetto, nemanjai, madscientist159, lei, power-llvm-team, hfinkel.
NeHuang added a project: LLVM.
Herald added subscribers: llvm-commits, hiraditya.
NeHuang requested review of this revision.
We encountered the same failure as https://reviews.llvm.org/D22435. Original bug tracked in https://bugs.llvm.org/show_bug.cgi?id=28102
@cperfetto provided a potential solution to remove the unreachable MBBs reference in the jump table. (Comment 27 and Comment 28)
We have confirmed the assertion issue fixed with this patch.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D90498
Files:
llvm/include/llvm/CodeGen/MachineJumpTableInfo.h
llvm/lib/CodeGen/MachineFunction.cpp
Index: llvm/lib/CodeGen/MachineFunction.cpp
===================================================================
--- llvm/lib/CodeGen/MachineFunction.cpp
+++ llvm/lib/CodeGen/MachineFunction.cpp
@@ -420,6 +420,9 @@
void
MachineFunction::DeleteMachineBasicBlock(MachineBasicBlock *MBB) {
assert(MBB->getParent() == this && "MBB parent mismatch!");
+ // Clean up any references to MBB in jump tables before deleting it
+ if (JumpTableInfo)
+ JumpTableInfo->RemoveMBBFromJumpTables(MBB);
MBB->~MachineBasicBlock();
BasicBlockRecycler.Deallocate(Allocator, MBB);
}
@@ -1047,6 +1050,17 @@
return MadeChange;
}
+/// If MBB is present in any jump tables, remove it
+bool MachineJumpTableInfo::RemoveMBBFromJumpTables(MachineBasicBlock *MBB) {
+ bool MadeChange = false;
+ for (MachineJumpTableEntry &JTE : JumpTables) {
+ auto removeBeginItr = std::remove(JTE.MBBs.begin(), JTE.MBBs.end(), MBB);
+ MadeChange |= (removeBeginItr != JTE.MBBs.end());
+ JTE.MBBs.erase(removeBeginItr, JTE.MBBs.end());
+ }
+ return MadeChange;
+}
+
/// If Old is a target of the jump tables, update the jump table to branch to
/// New instead.
bool MachineJumpTableInfo::ReplaceMBBInJumpTable(unsigned Idx,
Index: llvm/include/llvm/CodeGen/MachineJumpTableInfo.h
===================================================================
--- llvm/include/llvm/CodeGen/MachineJumpTableInfo.h
+++ llvm/include/llvm/CodeGen/MachineJumpTableInfo.h
@@ -106,6 +106,9 @@
JumpTables[Idx].MBBs.clear();
}
+ /// RemoveMBBFromJumpTables - If MBB is present in any jump tables, remove it
+ bool RemoveMBBFromJumpTables(MachineBasicBlock *MBB);
+
/// ReplaceMBBInJumpTables - If Old is the target of any jump tables, update
/// the jump tables to branch to New instead.
bool ReplaceMBBInJumpTables(MachineBasicBlock *Old, MachineBasicBlock *New);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90498.301873.patch
Type: text/x-patch
Size: 1858 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201030/a19c3df4/attachment.bin>
More information about the llvm-commits
mailing list