Skip to content

Commit

Permalink
[Utils] Use make_early_inc_range (NFC)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazutakahirata committed Sep 13, 2021
1 parent ec92f78 commit abca4c0
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 29 deletions.
9 changes: 3 additions & 6 deletions llvm/lib/Transforms/Utils/InlineFunction.cpp
Expand Up @@ -539,12 +539,10 @@ static Value *getUnwindDestToken(Instruction *EHPad,
static BasicBlock *HandleCallsInBlockInlinedThroughInvoke(
BasicBlock *BB, BasicBlock *UnwindEdge,
UnwindDestMemoTy *FuncletUnwindMap = nullptr) {
for (BasicBlock::iterator BBI = BB->begin(), E = BB->end(); BBI != E; ) {
Instruction *I = &*BBI++;

for (Instruction &I : llvm::make_early_inc_range(*BB)) {
// We only need to check for function calls: inlined invoke
// instructions require no special handling.
CallInst *CI = dyn_cast<CallInst>(I);
CallInst *CI = dyn_cast<CallInst>(&I);

if (!CI || CI->doesNotThrow())
continue;
Expand Down Expand Up @@ -2129,8 +2127,7 @@ llvm::InlineResult llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI,

for (Function::iterator BB = FirstNewBlock, E = Caller->end(); BB != E;
++BB) {
for (auto II = BB->begin(); II != BB->end();) {
Instruction &I = *II++;
for (Instruction &I : llvm::make_early_inc_range(*BB)) {
CallInst *CI = dyn_cast<CallInst>(&I);
if (!CI)
continue;
Expand Down
8 changes: 2 additions & 6 deletions llvm/lib/Transforms/Utils/Local.cpp
Expand Up @@ -2677,9 +2677,7 @@ static unsigned replaceDominatedUsesWith(Value *From, Value *To,
assert(From->getType() == To->getType());

unsigned Count = 0;
for (Value::use_iterator UI = From->use_begin(), UE = From->use_end();
UI != UE;) {
Use &U = *UI++;
for (Use &U : llvm::make_early_inc_range(From->uses())) {
if (!Dominates(Root, U))
continue;
U.set(To);
Expand All @@ -2695,9 +2693,7 @@ unsigned llvm::replaceNonLocalUsesWith(Instruction *From, Value *To) {
auto *BB = From->getParent();
unsigned Count = 0;

for (Value::use_iterator UI = From->use_begin(), UE = From->use_end();
UI != UE;) {
Use &U = *UI++;
for (Use &U : llvm::make_early_inc_range(From->uses())) {
auto *I = cast<Instruction>(U.getUser());
if (I->getParent() == BB)
continue;
Expand Down
13 changes: 6 additions & 7 deletions llvm/lib/Transforms/Utils/LoopUnroll.cpp
Expand Up @@ -224,13 +224,12 @@ void llvm::simplifyLoopAfterUnroll(Loop *L, bool SimplifyIVs, LoopInfo *LI,
const DataLayout &DL = L->getHeader()->getModule()->getDataLayout();
SmallVector<WeakTrackingVH, 16> DeadInsts;
for (BasicBlock *BB : L->getBlocks()) {
for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E;) {
Instruction *Inst = &*I++;
if (Value *V = SimplifyInstruction(Inst, {DL, nullptr, DT, AC}))
if (LI->replacementPreservesLCSSAForm(Inst, V))
Inst->replaceAllUsesWith(V);
if (isInstructionTriviallyDead(Inst))
DeadInsts.emplace_back(Inst);
for (Instruction &Inst : llvm::make_early_inc_range(*BB)) {
if (Value *V = SimplifyInstruction(&Inst, {DL, nullptr, DT, AC}))
if (LI->replacementPreservesLCSSAForm(&Inst, V))
Inst.replaceAllUsesWith(V);
if (isInstructionTriviallyDead(&Inst))
DeadInsts.emplace_back(&Inst);
}
// We can't do recursive deletion until we're done iterating, as we might
// have a phi which (potentially indirectly) uses instructions later in
Expand Down
13 changes: 6 additions & 7 deletions llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp
Expand Up @@ -974,13 +974,12 @@ bool llvm::UnrollRuntimeLoopRemainder(
const DataLayout &DL = L->getHeader()->getModule()->getDataLayout();
SmallVector<WeakTrackingVH, 16> DeadInsts;
for (BasicBlock *BB : RemainderBlocks) {
for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E;) {
Instruction *Inst = &*I++;
if (Value *V = SimplifyInstruction(Inst, {DL, nullptr, DT, AC}))
if (LI->replacementPreservesLCSSAForm(Inst, V))
Inst->replaceAllUsesWith(V);
if (isInstructionTriviallyDead(Inst))
DeadInsts.emplace_back(Inst);
for (Instruction &Inst : llvm::make_early_inc_range(*BB)) {
if (Value *V = SimplifyInstruction(&Inst, {DL, nullptr, DT, AC}))
if (LI->replacementPreservesLCSSAForm(&Inst, V))
Inst.replaceAllUsesWith(V);
if (isInstructionTriviallyDead(&Inst))
DeadInsts.emplace_back(&Inst);
}
// We can't do recursive deletion until we're done iterating, as we might
// have a phi which (potentially indirectly) uses instructions later in
Expand Down
4 changes: 1 addition & 3 deletions llvm/lib/Transforms/Utils/RelLookupTableConverter.cpp
Expand Up @@ -177,9 +177,7 @@ static bool convertToRelativeLookupTables(

bool Changed = false;

for (auto GVI = M.global_begin(), E = M.global_end(); GVI != E;) {
GlobalVariable &GV = *GVI++;

for (GlobalVariable &GV : llvm::make_early_inc_range(M.globals())) {
if (!shouldConvertToRelLookupTable(M, GV))
continue;

Expand Down

0 comments on commit abca4c0

Please sign in to comment.