Anticipate cpu_loop_exit removal

Fix of another bug showing up only with LLVM in debug mode: splitting a
malformed basic block is not allowed, and we had a function call after a
`ret` instruction.
This commit is contained in:
Alessandro Di Federico
2017-03-02 11:16:32 +01:00
parent 04a4591f5c
commit 1e9163c73d
+10 -6
View File
@@ -427,8 +427,13 @@ bool CpuLoopExitPass::runOnModule(llvm::Module& M) {
assert(CpuLoop != nullptr);
for (User *TheUser : CpuLoopExit->users()) {
auto *Call = cast<CallInst>(TheUser);
std::queue<User *> CpuLoopExitUsers;
for (User *TheUser : CpuLoopExit->users())
CpuLoopExitUsers.push(TheUser);
while (!CpuLoopExitUsers.empty()) {
auto *Call = cast<CallInst>(CpuLoopExitUsers.front());
CpuLoopExitUsers.pop();
assert(Call->getCalledFunction() == CpuLoopExit);
// Call cpu_loop
@@ -444,9 +449,11 @@ bool CpuLoopExitPass::runOnModule(llvm::Module& M) {
auto *Unreach = cast<UnreachableInst>(&*++Call->getIterator());
Unreach->eraseFromParent();
// Remove the call to cpu_loop_exit
Function *Caller = Call->getParent()->getParent();
// Remove the call to cpu_loop_exit
Call->eraseFromParent();
if (FixedCallers.find(Caller) == FixedCallers.end()) {
FixedCallers.insert(Caller);
@@ -518,9 +525,6 @@ bool CpuLoopExitPass::runOnModule(llvm::Module& M) {
}
}
for (User *TheUser : CpuLoopExit->users())
cast<Instruction>(TheUser)->eraseFromParent();
return true;
}