[llvm] r331221 - [SimplifyCFG] Use BB::instructionsWithoutDebug to skip DbgInfo (NFC).
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 30 13:10:53 PDT 2018
Author: fhahn
Date: Mon Apr 30 13:10:53 2018
New Revision: 331221
URL: http://llvm.org/viewvc/llvm-project?rev=331221&view=rev
Log:
[SimplifyCFG] Use BB::instructionsWithoutDebug to skip DbgInfo (NFC).
This patch updates some code responsible the skip debug info to use
BasicBlock::instructionsWithoutDebug. I think this makes things slightly
simpler and more direct.
Reviewers: aprantl, vsk, hans, danielcdh
Reviewed By: hans
Differential Revision: https://reviews.llvm.org/D46252
Modified:
llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
Modified: llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp?rev=331221&r1=331220&r2=331221&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp Mon Apr 30 13:10:53 2018
@@ -1864,12 +1864,9 @@ static Value *isSafeToSpeculateStore(Ins
// Look for a store to the same pointer in BrBB.
unsigned MaxNumInstToLookAt = 9;
- for (Instruction &CurI : reverse(*BrBB)) {
+ for (Instruction &CurI : reverse(BrBB->instructionsWithoutDebug())) {
if (!MaxNumInstToLookAt)
break;
- // Skip debug info.
- if (isa<DbgInfoIntrinsic>(CurI))
- continue;
--MaxNumInstToLookAt;
// Could be calling an instruction that affects memory like free().
@@ -2119,19 +2116,16 @@ static bool SpeculativelyExecuteBB(Branc
/// Return true if we can thread a branch across this block.
static bool BlockIsSimpleEnoughToThreadThrough(BasicBlock *BB) {
- BranchInst *BI = cast<BranchInst>(BB->getTerminator());
unsigned Size = 0;
- for (BasicBlock::iterator BBI = BB->begin(); &*BBI != BI; ++BBI) {
- if (isa<DbgInfoIntrinsic>(BBI))
- continue;
+ for (Instruction &I : BB->instructionsWithoutDebug()) {
if (Size > 10)
return false; // Don't clone large BB's.
++Size;
// We can only support instructions that do not define values that are
// live outside of the current basic block.
- for (User *U : BBI->users()) {
+ for (User *U : I.users()) {
Instruction *UI = cast<Instruction>(U);
if (UI->getParent() != BB || isa<PHINode>(UI))
return false;
@@ -2920,14 +2914,13 @@ static bool mergeConditionalStoreToAddre
// instructions inside are all cheap (arithmetic/GEPs), it's worthwhile to
// thread this store.
unsigned N = 0;
- for (auto &I : *BB) {
+ for (auto &I : BB->instructionsWithoutDebug()) {
// Cheap instructions viable for folding.
if (isa<BinaryOperator>(I) || isa<GetElementPtrInst>(I) ||
isa<StoreInst>(I))
++N;
// Free instructions.
- else if (isa<TerminatorInst>(I) || isa<DbgInfoIntrinsic>(I) ||
- IsaBitcastOfPointerType(I))
+ else if (isa<TerminatorInst>(I) || IsaBitcastOfPointerType(I))
continue;
else
return false;
@@ -3232,11 +3225,9 @@ static bool SimplifyCondBranchToCondBran
// If this is a conditional branch in an empty block, and if any
// predecessors are a conditional branch to one of our destinations,
// fold the conditions into logical ops and one cond br.
- BasicBlock::iterator BBI = BB->begin();
+
// Ignore dbg intrinsics.
- while (isa<DbgInfoIntrinsic>(BBI))
- ++BBI;
- if (&*BBI != BI)
+ if (&*BB->instructionsWithoutDebug().begin() != BI)
return false;
int PBIOp, BIOp;
@@ -4639,24 +4630,20 @@ GetCaseResults(SwitchInst *SI, ConstantI
// which we can constant-propagate the CaseVal, continue to its successor.
SmallDenseMap<Value *, Constant *> ConstantPool;
ConstantPool.insert(std::make_pair(SI->getCondition(), CaseVal));
- for (BasicBlock::iterator I = CaseDest->begin(), E = CaseDest->end(); I != E;
- ++I) {
- if (TerminatorInst *T = dyn_cast<TerminatorInst>(I)) {
+ for (Instruction &I :CaseDest->instructionsWithoutDebug()) {
+ if (TerminatorInst *T = dyn_cast<TerminatorInst>(&I)) {
// If the terminator is a simple branch, continue to the next block.
if (T->getNumSuccessors() != 1 || T->isExceptional())
return false;
Pred = CaseDest;
CaseDest = T->getSuccessor(0);
- } else if (isa<DbgInfoIntrinsic>(I)) {
- // Skip debug intrinsic.
- continue;
- } else if (Constant *C = ConstantFold(&*I, DL, ConstantPool)) {
+ } else if (Constant *C = ConstantFold(&I, DL, ConstantPool)) {
// Instruction is side-effect free and constant.
// If the instruction has uses outside this block or a phi node slot for
// the block, it is not safe to bypass the instruction since it would then
// no longer dominate all its uses.
- for (auto &Use : I->uses()) {
+ for (auto &Use : I.uses()) {
User *User = Use.getUser();
if (Instruction *I = dyn_cast<Instruction>(User))
if (I->getParent() == CaseDest)
@@ -4667,7 +4654,7 @@ GetCaseResults(SwitchInst *SI, ConstantI
return false;
}
- ConstantPool.insert(std::make_pair(&*I, C));
+ ConstantPool.insert(std::make_pair(&I, C));
} else {
break;
}
@@ -5602,11 +5589,7 @@ bool SimplifyCFGOpt::SimplifySwitch(Swit
// If the block only contains the switch, see if we can fold the block
// away into any preds.
- BasicBlock::iterator BBI = BB->begin();
- // Ignore dbg intrinsics.
- while (isa<DbgInfoIntrinsic>(BBI))
- ++BBI;
- if (SI == &*BBI)
+ if (SI == &*BB->instructionsWithoutDebug().begin())
if (FoldValueComparisonIntoPredecessors(SI, Builder))
return simplifyCFG(BB, TTI, Options) | true;
}
@@ -5833,18 +5816,12 @@ bool SimplifyCFGOpt::SimplifyCondBranch(
// This block must be empty, except for the setcond inst, if it exists.
// Ignore dbg intrinsics.
- BasicBlock::iterator I = BB->begin();
- // Ignore dbg intrinsics.
- while (isa<DbgInfoIntrinsic>(I))
- ++I;
+ auto I = BB->instructionsWithoutDebug().begin();
if (&*I == BI) {
if (FoldValueComparisonIntoPredecessors(BI, Builder))
return simplifyCFG(BB, TTI, Options) | true;
} else if (&*I == cast<Instruction>(BI->getCondition())) {
++I;
- // Ignore dbg intrinsics.
- while (isa<DbgInfoIntrinsic>(I))
- ++I;
if (&*I == BI && FoldValueComparisonIntoPredecessors(BI, Builder))
return simplifyCFG(BB, TTI, Options) | true;
}
More information about the llvm-commits
mailing list