mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-12 13:38:21 +00:00
Do trivial CSE of dead BBs during codegen preparation.
Some BBs can become dead after codegen preparation. If we delete them here, it could help enable tail-call optimizations later on. <rdar://problem/10256573> git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@152002 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -65,6 +65,11 @@ static cl::opt<bool> DisableBranchOpts(
|
||||
"disable-cgp-branch-opts", cl::Hidden, cl::init(false),
|
||||
cl::desc("Disable branch optimizations in CodeGenPrepare"));
|
||||
|
||||
// FIXME: Remove this abomination once all of the tests pass without it!
|
||||
static cl::opt<bool> DisableDeleteDeadBlocks(
|
||||
"disable-cgp-delete-dead-blocks", cl::Hidden, cl::init(false),
|
||||
cl::desc("Disable deleting dead blocks in CodeGenPrepare"));
|
||||
|
||||
namespace {
|
||||
class CodeGenPrepare : public FunctionPass {
|
||||
/// TLI - Keep a pointer of a TargetLowering to consult for determining
|
||||
@ -160,8 +165,22 @@ bool CodeGenPrepare::runOnFunction(Function &F) {
|
||||
|
||||
if (!DisableBranchOpts) {
|
||||
MadeChange = false;
|
||||
for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
|
||||
SmallPtrSet<BasicBlock*, 8> WorkList;
|
||||
for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) {
|
||||
SmallVector<BasicBlock*, 2> Successors(succ_begin(BB), succ_end(BB));
|
||||
MadeChange |= ConstantFoldTerminator(BB, true);
|
||||
if (!MadeChange) continue;
|
||||
|
||||
for (SmallVectorImpl<BasicBlock*>::iterator
|
||||
II = Successors.begin(), IE = Successors.end(); II != IE; ++II)
|
||||
if (pred_begin(*II) == pred_end(*II))
|
||||
WorkList.insert(*II);
|
||||
}
|
||||
|
||||
if (!DisableDeleteDeadBlocks)
|
||||
for (SmallPtrSet<BasicBlock*, 8>::iterator
|
||||
I = WorkList.begin(), E = WorkList.end(); I != E; ++I)
|
||||
DeleteDeadBlock(*I);
|
||||
|
||||
if (MadeChange)
|
||||
ModifiedDT = true;
|
||||
|
Reference in New Issue
Block a user