mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-16 14:31:59 +00:00
Let simplify cfg simplify bb with only debug and lifetime intrinsics.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@134057 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
c4a84304a0
commit
0fb7dcd48f
@ -138,6 +138,12 @@ public:
|
|||||||
return const_cast<BasicBlock*>(this)->getFirstNonPHIOrDbg();
|
return const_cast<BasicBlock*>(this)->getFirstNonPHIOrDbg();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Same as above, but also skip lifetime intrinsics.
|
||||||
|
Instruction* getFirstNonPHIOrDbgOrLifetime();
|
||||||
|
const Instruction* getFirstNonPHIOrDbgOrLifetime() const {
|
||||||
|
return const_cast<BasicBlock*>(this)->getFirstNonPHIOrDbgOrLifetime();
|
||||||
|
}
|
||||||
|
|
||||||
/// removeFromParent - This method unlinks 'this' from the containing
|
/// removeFromParent - This method unlinks 'this' from the containing
|
||||||
/// function, but does not delete it.
|
/// function, but does not delete it.
|
||||||
///
|
///
|
||||||
|
@ -536,9 +536,9 @@ static bool CanPropagatePredecessorsForPHIs(BasicBlock *BB, BasicBlock *Succ) {
|
|||||||
|
|
||||||
/// TryToSimplifyUncondBranchFromEmptyBlock - BB is known to contain an
|
/// TryToSimplifyUncondBranchFromEmptyBlock - BB is known to contain an
|
||||||
/// unconditional branch, and contains no instructions other than PHI nodes,
|
/// unconditional branch, and contains no instructions other than PHI nodes,
|
||||||
/// potential debug intrinsics and the branch. If possible, eliminate BB by
|
/// potential side-effect free intrinsics and the branch. If possible,
|
||||||
/// rewriting all the predecessors to branch to the successor block and return
|
/// eliminate BB by rewriting all the predecessors to branch to the successor
|
||||||
/// true. If we can't transform, return false.
|
/// block and return true. If we can't transform, return false.
|
||||||
bool llvm::TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB) {
|
bool llvm::TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB) {
|
||||||
assert(BB != &BB->getParent()->getEntryBlock() &&
|
assert(BB != &BB->getParent()->getEntryBlock() &&
|
||||||
"TryToSimplifyUncondBranchFromEmptyBlock called on entry block!");
|
"TryToSimplifyUncondBranchFromEmptyBlock called on entry block!");
|
||||||
@ -613,13 +613,15 @@ bool llvm::TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while (PHINode *PN = dyn_cast<PHINode>(&BB->front())) {
|
if (Succ->getSinglePredecessor()) {
|
||||||
if (Succ->getSinglePredecessor()) {
|
// BB is the only predecessor of Succ, so Succ will end up with exactly
|
||||||
// BB is the only predecessor of Succ, so Succ will end up with exactly
|
// the same predecessors BB had.
|
||||||
// the same predecessors BB had.
|
|
||||||
Succ->getInstList().splice(Succ->begin(),
|
// Copy over any phi, debug or lifetime instruction.
|
||||||
BB->getInstList(), BB->begin());
|
BB->getTerminator()->eraseFromParent();
|
||||||
} else {
|
Succ->getInstList().splice(Succ->begin(), BB->getInstList());
|
||||||
|
} else {
|
||||||
|
while (PHINode *PN = dyn_cast<PHINode>(&BB->front())) {
|
||||||
// We explicitly check for such uses in CanPropagatePredecessorsForPHIs.
|
// We explicitly check for such uses in CanPropagatePredecessorsForPHIs.
|
||||||
assert(PN->use_empty() && "There shouldn't be any uses here!");
|
assert(PN->use_empty() && "There shouldn't be any uses here!");
|
||||||
PN->eraseFromParent();
|
PN->eraseFromParent();
|
||||||
|
@ -2604,7 +2604,7 @@ bool SimplifyCFGOpt::SimplifyUncondBranch(BranchInst *BI, IRBuilder<> &Builder){
|
|||||||
BasicBlock *BB = BI->getParent();
|
BasicBlock *BB = BI->getParent();
|
||||||
|
|
||||||
// If the Terminator is the only non-phi instruction, simplify the block.
|
// If the Terminator is the only non-phi instruction, simplify the block.
|
||||||
BasicBlock::iterator I = BB->getFirstNonPHIOrDbg();
|
BasicBlock::iterator I = BB->getFirstNonPHIOrDbgOrLifetime();
|
||||||
if (I->isTerminator() && BB != &BB->getParent()->getEntryBlock() &&
|
if (I->isTerminator() && BB != &BB->getParent()->getEntryBlock() &&
|
||||||
TryToSimplifyUncondBranchFromEmptyBlock(BB))
|
TryToSimplifyUncondBranchFromEmptyBlock(BB))
|
||||||
return true;
|
return true;
|
||||||
|
@ -147,6 +147,26 @@ Instruction* BasicBlock::getFirstNonPHIOrDbg() {
|
|||||||
return &*i;
|
return &*i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Instruction* BasicBlock::getFirstNonPHIOrDbgOrLifetime() {
|
||||||
|
// All valid basic blocks should have a terminator,
|
||||||
|
// which is not a PHINode. If we have an invalid basic
|
||||||
|
// block we'll get an assertion failure when dereferencing
|
||||||
|
// a past-the-end iterator.
|
||||||
|
BasicBlock::iterator i = begin();
|
||||||
|
for (;; ++i) {
|
||||||
|
if (isa<PHINode>(i) || isa<DbgInfoIntrinsic>(i))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
const IntrinsicInst *II = dyn_cast<IntrinsicInst>(i);
|
||||||
|
if (!II)
|
||||||
|
break;
|
||||||
|
if (II->getIntrinsicID() != Intrinsic::lifetime_start &&
|
||||||
|
II->getIntrinsicID() != Intrinsic::lifetime_end)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return &*i;
|
||||||
|
}
|
||||||
|
|
||||||
void BasicBlock::dropAllReferences() {
|
void BasicBlock::dropAllReferences() {
|
||||||
for(iterator I = begin(), E = end(); I != E; ++I)
|
for(iterator I = begin(), E = end(); I != E; ++I)
|
||||||
I->dropAllReferences();
|
I->dropAllReferences();
|
||||||
|
29
test/Transforms/SimplifyCFG/lifetime.ll
Normal file
29
test/Transforms/SimplifyCFG/lifetime.ll
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
; RUN: opt < %s -simplifycfg -S | FileCheck %s
|
||||||
|
|
||||||
|
; Test that a lifetime intrinsic doesn't prevent us from simplifying this.
|
||||||
|
|
||||||
|
; CHECK: foo
|
||||||
|
; CHECK: entry:
|
||||||
|
; CHECK-NOT: bb0:
|
||||||
|
; CHECK-NOT: bb1:
|
||||||
|
; CHECK: ret
|
||||||
|
define void @foo(i1 %x) {
|
||||||
|
entry:
|
||||||
|
%a = alloca i8
|
||||||
|
call void @llvm.lifetime.start(i64 -1, i8* %a) nounwind
|
||||||
|
br i1 %x, label %bb0, label %bb1
|
||||||
|
|
||||||
|
bb0:
|
||||||
|
call void @llvm.lifetime.end(i64 -1, i8* %a) nounwind
|
||||||
|
br label %bb1
|
||||||
|
|
||||||
|
bb1:
|
||||||
|
call void @f()
|
||||||
|
ret void
|
||||||
|
}
|
||||||
|
|
||||||
|
declare void @f()
|
||||||
|
|
||||||
|
declare void @llvm.lifetime.start(i64, i8* nocapture) nounwind
|
||||||
|
|
||||||
|
declare void @llvm.lifetime.end(i64, i8* nocapture) nounwind
|
Loading…
x
Reference in New Issue
Block a user