[llvm] 773353b - [SCCP] Move common code to simplify basic block to helper (NFC).
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 17 02:04:07 PDT 2020
Author: Florian Hahn
Date: 2020-06-17T10:03:43+01:00
New Revision: 773353be4e5d76c4dda3b1776c745c8e794a3384
URL: https://github.com/llvm/llvm-project/commit/773353be4e5d76c4dda3b1776c745c8e794a3384
DIFF: https://github.com/llvm/llvm-project/commit/773353be4e5d76c4dda3b1776c745c8e794a3384.diff
LOG: [SCCP] Move common code to simplify basic block to helper (NFC).
Reviewers: efriedma, davide
Reviewed By: efriedma
Differential Revision: https://reviews.llvm.org/D81755
Added:
Modified:
llvm/lib/Transforms/Scalar/SCCP.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/SCCP.cpp b/llvm/lib/Transforms/Scalar/SCCP.cpp
index cfe5aea61093..ccfc0b844c30 100644
--- a/llvm/lib/Transforms/Scalar/SCCP.cpp
+++ b/llvm/lib/Transforms/Scalar/SCCP.cpp
@@ -1606,6 +1606,23 @@ static bool tryToReplaceWithConstant(SCCPSolver &Solver, Value *V) {
return true;
}
+static bool simplifyInstsInBlock(SCCPSolver &Solver, BasicBlock &BB,
+ Statistic &InstRemovedStat) {
+ bool MadeChanges = false;
+ for (Instruction &Inst : make_early_inc_range(BB)) {
+ if (Inst.getType()->isVoidTy())
+ continue;
+ if (tryToReplaceWithConstant(Solver, &Inst)) {
+ if (Inst.isSafeToRemove())
+ Inst.eraseFromParent();
+ // Hey, we just changed something!
+ MadeChanges = true;
+ ++InstRemovedStat;
+ }
+ }
+ return MadeChanges;
+}
+
// runSCCP() - Run the Sparse Conditional Constant Propagation algorithm,
// and return true if the function was modified.
static bool runSCCP(Function &F, const DataLayout &DL,
@@ -1647,21 +1664,7 @@ static bool runSCCP(Function &F, const DataLayout &DL,
continue;
}
- // Iterate over all of the instructions in a function, replacing them with
- // constants if we have found them to be of constant values.
- for (BasicBlock::iterator BI = BB.begin(), E = BB.end(); BI != E;) {
- Instruction *Inst = &*BI++;
- if (Inst->getType()->isVoidTy() || Inst->isTerminator())
- continue;
-
- if (tryToReplaceWithConstant(Solver, Inst)) {
- if (isInstructionTriviallyDead(Inst))
- Inst->eraseFromParent();
- // Hey, we just changed something!
- MadeChanges = true;
- ++NumInstRemoved;
- }
- }
+ MadeChanges |= simplifyInstsInBlock(Solver, BB, NumInstRemoved);
}
return MadeChanges;
@@ -1890,30 +1893,19 @@ bool llvm::runIPSCCP(
}
}
- for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) {
- if (!Solver.isBlockExecutable(&*BB)) {
- LLVM_DEBUG(dbgs() << " BasicBlock Dead:" << *BB);
+ for (BasicBlock &BB : F) {
+ if (!Solver.isBlockExecutable(&BB)) {
+ LLVM_DEBUG(dbgs() << " BasicBlock Dead:" << BB);
++NumDeadBlocks;
MadeChanges = true;
- if (&*BB != &F.front())
- BlocksToErase.push_back(&*BB);
+ if (&BB != &F.front())
+ BlocksToErase.push_back(&BB);
continue;
}
- for (BasicBlock::iterator BI = BB->begin(), E = BB->end(); BI != E; ) {
- Instruction *Inst = &*BI++;
- if (Inst->getType()->isVoidTy())
- continue;
- if (tryToReplaceWithConstant(Solver, Inst)) {
- if (Inst->isSafeToRemove())
- Inst->eraseFromParent();
- // Hey, we just changed something!
- MadeChanges = true;
- ++IPNumInstRemoved;
- }
- }
+ MadeChanges |= simplifyInstsInBlock(Solver, BB, IPNumInstRemoved);
}
DomTreeUpdater DTU = Solver.getDTU(F);
More information about the llvm-commits
mailing list