summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Scalar/ADCE.cpp
diff options
context:
space:
mode:
authorDavid Callahan <dcallahan@fb.com>2016-09-19 23:17:58 +0000
committerDavid Callahan <dcallahan@fb.com>2016-09-19 23:17:58 +0000
commitc165a4e2154125dd209ea94055d9e41cb240439a (patch)
treea151a8110ed008b92316678da79158bd0d46c48c /llvm/lib/Transforms/Scalar/ADCE.cpp
parent1c3c3953c646bc57c4c6e2c247de912c87fa0665 (diff)
downloadbcm5719-llvm-c165a4e2154125dd209ea94055d9e41cb240439a.tar.gz
bcm5719-llvm-c165a4e2154125dd209ea94055d9e41cb240439a.zip
Merge branch 'ADCE5'
llvm-svn: 281947
Diffstat (limited to 'llvm/lib/Transforms/Scalar/ADCE.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/ADCE.cpp41
1 files changed, 39 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Scalar/ADCE.cpp b/llvm/lib/Transforms/Scalar/ADCE.cpp
index e74a89f9d5b..976b2fdcd9b 100644
--- a/llvm/lib/Transforms/Scalar/ADCE.cpp
+++ b/llvm/lib/Transforms/Scalar/ADCE.cpp
@@ -58,6 +58,10 @@ struct BlockInfoType {
bool Live = false;
/// True when this block ends in an unconditional branch.
bool UnconditionalBranch = false;
+ /// True when this block is known to have live PHI nodes.
+ bool HasLivePhiNodes = false;
+ /// Control dependence sources need to be live for this block.
+ bool CFLive = false;
/// Quick access to the LiveInfo for the terminator,
/// holds the value &InstInfo[Terminator]
@@ -109,6 +113,9 @@ class AggressiveDeadCodeElimination {
void markLiveInstructions();
/// Mark an instruction as live.
void markLive(Instruction *I);
+
+ /// Mark terminators of control predecessors of a PHI node live.
+ void markPhiLive(PHINode *PN);
/// Record the Debug Scopes which surround live debug information.
void collectLiveScopes(const DILocalScope &LS);
@@ -269,15 +276,18 @@ void AggressiveDeadCodeElimination::markLiveInstructions() {
// where we need to mark the inputs as live.
while (!Worklist.empty()) {
Instruction *LiveInst = Worklist.pop_back_val();
+ DEBUG(dbgs() << "work live: "; LiveInst->dump(););
// Collect the live debug info scopes attached to this instruction.
if (const DILocation *DL = LiveInst->getDebugLoc())
collectLiveScopes(*DL);
- DEBUG(dbgs() << "work live: "; LiveInst->dump(););
for (Use &OI : LiveInst->operands())
if (Instruction *Inst = dyn_cast<Instruction>(OI))
markLive(Inst);
+
+ if (auto *PN = dyn_cast<PHINode>(LiveInst))
+ markPhiLive(PN);
}
markLiveBranchesFromControlDependences();
@@ -315,7 +325,10 @@ void AggressiveDeadCodeElimination::markLive(Instruction *I) {
DEBUG(dbgs() << "mark block live: " << BBInfo.BB->getName() << '\n');
BBInfo.Live = true;
- NewLiveBlocks.insert(BBInfo.BB);
+ if (!BBInfo.CFLive) {
+ BBInfo.CFLive = true;
+ NewLiveBlocks.insert(BBInfo.BB);
+ }
// Mark unconditional branches at the end of live
// blocks as live since there is no work to do for them later
@@ -348,6 +361,25 @@ void AggressiveDeadCodeElimination::collectLiveScopes(const DILocation &DL) {
collectLiveScopes(*IA);
}
+void AggressiveDeadCodeElimination::markPhiLive(PHINode *PN) {
+ auto &Info = BlockInfo[PN->getParent()];
+ // Only need to check this once per block.
+ if (Info.HasLivePhiNodes)
+ return;
+ Info.HasLivePhiNodes = true;
+
+ // If a predecessor block is not live, mark it as control-flow live
+ // which will trigger marking live branches upon which
+ // that block is control dependent.
+ for (auto *PredBB : predecessors(Info.BB)) {
+ auto &Info = BlockInfo[PredBB];
+ if (!Info.CFLive) {
+ Info.CFLive = true;
+ NewLiveBlocks.insert(PredBB);
+ }
+ }
+}
+
void AggressiveDeadCodeElimination::markLiveBranchesFromControlDependences() {
if (BlocksWithDeadTerminators.empty())
@@ -382,6 +414,11 @@ void AggressiveDeadCodeElimination::markLiveBranchesFromControlDependences() {
}
}
+//===----------------------------------------------------------------------===//
+//
+// Routines to update the CFG and SSA information before removing dead code.
+//
+//===----------------------------------------------------------------------===//
bool AggressiveDeadCodeElimination::removeDeadInstructions() {
// The inverse of the live set is the dead set. These are those instructions
OpenPOWER on IntegriCloud