forked from OSchip/llvm-project
[Transforms] Use make_early_inc_range (NFC)
This commit is contained in:
parent
d0eb472f33
commit
1b108ab975
|
@ -520,8 +520,8 @@ void CoroCloner::replaceRetconOrAsyncSuspendUses() {
|
|||
}
|
||||
|
||||
// Try to peephole extracts of an aggregate return.
|
||||
for (auto UI = NewS->use_begin(), UE = NewS->use_end(); UI != UE; ) {
|
||||
auto EVI = dyn_cast<ExtractValueInst>((UI++)->getUser());
|
||||
for (Use &U : llvm::make_early_inc_range(NewS->uses())) {
|
||||
auto *EVI = dyn_cast<ExtractValueInst>(U.getUser());
|
||||
if (!EVI || EVI->getNumIndices() != 1)
|
||||
continue;
|
||||
|
||||
|
@ -1974,9 +1974,9 @@ static void replacePrepare(CallInst *Prepare, LazyCallGraph &CG,
|
|||
// %2 = bitcast %1 to [[TYPE]]
|
||||
// ==>
|
||||
// %2 = @some_function
|
||||
for (auto UI = Prepare->use_begin(), UE = Prepare->use_end(); UI != UE;) {
|
||||
for (Use &U : llvm::make_early_inc_range(Prepare->uses())) {
|
||||
// Look for bitcasts back to the original function type.
|
||||
auto *Cast = dyn_cast<BitCastInst>((UI++)->getUser());
|
||||
auto *Cast = dyn_cast<BitCastInst>(U.getUser());
|
||||
if (!Cast || Cast->getType() != Fn->getType())
|
||||
continue;
|
||||
|
||||
|
@ -2056,9 +2056,9 @@ static void replacePrepare(CallInst *Prepare, CallGraph &CG) {
|
|||
static bool replaceAllPrepares(Function *PrepareFn, LazyCallGraph &CG,
|
||||
LazyCallGraph::SCC &C) {
|
||||
bool Changed = false;
|
||||
for (auto PI = PrepareFn->use_begin(), PE = PrepareFn->use_end(); PI != PE;) {
|
||||
for (Use &P : llvm::make_early_inc_range(PrepareFn->uses())) {
|
||||
// Intrinsics can only be used in calls.
|
||||
auto *Prepare = cast<CallInst>((PI++)->getUser());
|
||||
auto *Prepare = cast<CallInst>(P.getUser());
|
||||
replacePrepare(Prepare, CG, C);
|
||||
Changed = true;
|
||||
}
|
||||
|
@ -2074,10 +2074,9 @@ static bool replaceAllPrepares(Function *PrepareFn, LazyCallGraph &CG,
|
|||
/// switch coroutines, which are lowered in multiple stages).
|
||||
static bool replaceAllPrepares(Function *PrepareFn, CallGraph &CG) {
|
||||
bool Changed = false;
|
||||
for (auto PI = PrepareFn->use_begin(), PE = PrepareFn->use_end();
|
||||
PI != PE; ) {
|
||||
for (Use &P : llvm::make_early_inc_range(PrepareFn->uses())) {
|
||||
// Intrinsics can only be used in calls.
|
||||
auto *Prepare = cast<CallInst>((PI++)->getUser());
|
||||
auto *Prepare = cast<CallInst>(P.getUser());
|
||||
replacePrepare(Prepare, CG);
|
||||
Changed = true;
|
||||
}
|
||||
|
|
|
@ -175,8 +175,8 @@ bool DeadArgumentEliminationPass::DeleteDeadVarargs(Function &Fn) {
|
|||
// to pass in a smaller number of arguments into the new function.
|
||||
//
|
||||
std::vector<Value *> Args;
|
||||
for (Value::user_iterator I = Fn.user_begin(), E = Fn.user_end(); I != E; ) {
|
||||
CallBase *CB = dyn_cast<CallBase>(*I++);
|
||||
for (User *U : llvm::make_early_inc_range(Fn.users())) {
|
||||
CallBase *CB = dyn_cast<CallBase>(U);
|
||||
if (!CB)
|
||||
continue;
|
||||
|
||||
|
|
|
@ -154,11 +154,8 @@ static bool splitGlobals(Module &M) {
|
|||
return false;
|
||||
|
||||
bool Changed = false;
|
||||
for (auto I = M.global_begin(); I != M.global_end();) {
|
||||
GlobalVariable &GV = *I;
|
||||
++I;
|
||||
for (GlobalVariable &GV : llvm::make_early_inc_range(M.globals()))
|
||||
Changed |= splitGlobal(GV);
|
||||
}
|
||||
return Changed;
|
||||
}
|
||||
|
||||
|
|
|
@ -135,12 +135,8 @@ struct OutlinableGroup {
|
|||
/// \param SourceBB - the BasicBlock to pull Instructions from.
|
||||
/// \param TargetBB - the BasicBlock to put Instruction into.
|
||||
static void moveBBContents(BasicBlock &SourceBB, BasicBlock &TargetBB) {
|
||||
BasicBlock::iterator BBCurr, BBEnd, BBNext;
|
||||
for (BBCurr = SourceBB.begin(), BBEnd = SourceBB.end(); BBCurr != BBEnd;
|
||||
BBCurr = BBNext) {
|
||||
BBNext = std::next(BBCurr);
|
||||
BBCurr->moveBefore(TargetBB, TargetBB.end());
|
||||
}
|
||||
for (Instruction &I : llvm::make_early_inc_range(SourceBB))
|
||||
I.moveBefore(TargetBB, TargetBB.end());
|
||||
}
|
||||
|
||||
/// A function to sort the keys of \p Map, which must be a mapping of constant
|
||||
|
|
|
@ -1773,11 +1773,7 @@ static bool isDirectCall(Use& U) {
|
|||
void LowerTypeTestsModule::replaceCfiUses(Function *Old, Value *New,
|
||||
bool IsJumpTableCanonical) {
|
||||
SmallSetVector<Constant *, 4> Constants;
|
||||
auto UI = Old->use_begin(), E = Old->use_end();
|
||||
for (; UI != E;) {
|
||||
Use &U = *UI;
|
||||
++UI;
|
||||
|
||||
for (Use &U : llvm::make_early_inc_range(Old->uses())) {
|
||||
// Skip block addresses
|
||||
if (isa<BlockAddress>(U.getUser()))
|
||||
continue;
|
||||
|
@ -1814,12 +1810,11 @@ bool LowerTypeTestsModule::lower() {
|
|||
M.getFunction(Intrinsic::getName(Intrinsic::type_test));
|
||||
|
||||
if (DropTypeTests && TypeTestFunc) {
|
||||
for (auto UI = TypeTestFunc->use_begin(), UE = TypeTestFunc->use_end();
|
||||
UI != UE;) {
|
||||
auto *CI = cast<CallInst>((*UI++).getUser());
|
||||
for (Use &U : llvm::make_early_inc_range(TypeTestFunc->uses())) {
|
||||
auto *CI = cast<CallInst>(U.getUser());
|
||||
// Find and erase llvm.assume intrinsics for this llvm.type.test call.
|
||||
for (auto CIU = CI->use_begin(), CIUE = CI->use_end(); CIU != CIUE;)
|
||||
if (auto *Assume = dyn_cast<AssumeInst>((*CIU++).getUser()))
|
||||
for (Use &CIU : llvm::make_early_inc_range(CI->uses()))
|
||||
if (auto *Assume = dyn_cast<AssumeInst>(CIU.getUser()))
|
||||
Assume->eraseFromParent();
|
||||
// If the assume was merged with another assume, we might have a use on a
|
||||
// phi (which will feed the assume). Simply replace the use on the phi
|
||||
|
@ -1857,13 +1852,9 @@ bool LowerTypeTestsModule::lower() {
|
|||
return false;
|
||||
|
||||
if (ImportSummary) {
|
||||
if (TypeTestFunc) {
|
||||
for (auto UI = TypeTestFunc->use_begin(), UE = TypeTestFunc->use_end();
|
||||
UI != UE;) {
|
||||
auto *CI = cast<CallInst>((*UI++).getUser());
|
||||
importTypeTest(CI);
|
||||
}
|
||||
}
|
||||
if (TypeTestFunc)
|
||||
for (Use &U : llvm::make_early_inc_range(TypeTestFunc->uses()))
|
||||
importTypeTest(cast<CallInst>(U.getUser()));
|
||||
|
||||
if (ICallBranchFunnelFunc && !ICallBranchFunnelFunc->use_empty())
|
||||
report_fatal_error(
|
||||
|
|
|
@ -463,17 +463,15 @@ bool MergeFunctions::runOnModule(Module &M) {
|
|||
// Replace direct callers of Old with New.
|
||||
void MergeFunctions::replaceDirectCallers(Function *Old, Function *New) {
|
||||
Constant *BitcastNew = ConstantExpr::getBitCast(New, Old->getType());
|
||||
for (auto UI = Old->use_begin(), UE = Old->use_end(); UI != UE;) {
|
||||
Use *U = &*UI;
|
||||
++UI;
|
||||
CallBase *CB = dyn_cast<CallBase>(U->getUser());
|
||||
if (CB && CB->isCallee(U)) {
|
||||
for (Use &U : llvm::make_early_inc_range(Old->uses())) {
|
||||
CallBase *CB = dyn_cast<CallBase>(U.getUser());
|
||||
if (CB && CB->isCallee(&U)) {
|
||||
// Do not copy attributes from the called function to the call-site.
|
||||
// Function comparison ensures that the attributes are the same up to
|
||||
// type congruences in byval(), in which case we need to keep the byval
|
||||
// type of the call-site, not the callee function.
|
||||
remove(CB->getFunction());
|
||||
U->set(BitcastNew);
|
||||
U.set(BitcastNew);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -323,15 +323,14 @@ static bool sinkLoopInvariantInstructions(Loop &L, AAResults &AA, LoopInfo &LI,
|
|||
// Traverse preheader's instructions in reverse order becaue if A depends
|
||||
// on B (A appears after B), A needs to be sinked first before B can be
|
||||
// sinked.
|
||||
for (auto II = Preheader->rbegin(), E = Preheader->rend(); II != E;) {
|
||||
Instruction *I = &*II++;
|
||||
for (Instruction &I : llvm::make_early_inc_range(llvm::reverse(*Preheader))) {
|
||||
// No need to check for instruction's operands are loop invariant.
|
||||
assert(L.hasLoopInvariantOperands(I) &&
|
||||
assert(L.hasLoopInvariantOperands(&I) &&
|
||||
"Insts in a loop's preheader should have loop invariant operands!");
|
||||
if (!canSinkOrHoistInst(*I, &AA, &DT, &L, CurAST, MSSAU.get(), false,
|
||||
if (!canSinkOrHoistInst(I, &AA, &DT, &L, CurAST, MSSAU.get(), false,
|
||||
LICMFlags.get()))
|
||||
continue;
|
||||
if (sinkInstruction(L, *I, ColdLoopBBs, LoopBlockNumber, LI, DT, BFI,
|
||||
if (sinkInstruction(L, I, ColdLoopBBs, LoopBlockNumber, LI, DT, BFI,
|
||||
MSSAU.get()))
|
||||
Changed = true;
|
||||
}
|
||||
|
|
|
@ -357,11 +357,10 @@ static bool lowerExpectIntrinsic(Function &F) {
|
|||
// Remove llvm.expect intrinsics. Iterate backwards in order
|
||||
// to process select instructions before the intrinsic gets
|
||||
// removed.
|
||||
for (auto BI = BB.rbegin(), BE = BB.rend(); BI != BE;) {
|
||||
Instruction *Inst = &*BI++;
|
||||
CallInst *CI = dyn_cast<CallInst>(Inst);
|
||||
for (Instruction &Inst : llvm::make_early_inc_range(llvm::reverse(BB))) {
|
||||
CallInst *CI = dyn_cast<CallInst>(&Inst);
|
||||
if (!CI) {
|
||||
if (SelectInst *SI = dyn_cast<SelectInst>(Inst)) {
|
||||
if (SelectInst *SI = dyn_cast<SelectInst>(&Inst)) {
|
||||
if (handleBrSelExpect(*SI))
|
||||
ExpectIntrinsicsHandled++;
|
||||
}
|
||||
|
|
|
@ -1167,8 +1167,8 @@ bool SeparateConstOffsetFromGEP::run(Function &F) {
|
|||
if (!DT->isReachableFromEntry(&B))
|
||||
continue;
|
||||
|
||||
for (BasicBlock::iterator I = B.begin(), IE = B.end(); I != IE;)
|
||||
if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(I++))
|
||||
for (Instruction &I : llvm::make_early_inc_range(B))
|
||||
if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(&I))
|
||||
Changed |= splitGEP(GEP);
|
||||
// No need to split GEP ConstantExprs because all its indices are constant
|
||||
// already.
|
||||
|
|
|
@ -410,11 +410,9 @@ void llvm::moveInstructionsToTheBeginning(BasicBlock &FromBB, BasicBlock &ToBB,
|
|||
DominatorTree &DT,
|
||||
const PostDominatorTree &PDT,
|
||||
DependenceInfo &DI) {
|
||||
for (auto It = ++FromBB.rbegin(); It != FromBB.rend();) {
|
||||
for (Instruction &I :
|
||||
llvm::make_early_inc_range(llvm::drop_begin(llvm::reverse(FromBB)))) {
|
||||
Instruction *MovePos = ToBB.getFirstNonPHIOrDbg();
|
||||
Instruction &I = *It;
|
||||
// Increment the iterator before modifying FromBB.
|
||||
++It;
|
||||
|
||||
if (isSafeToMoveBefore(I, *MovePos, DT, &PDT, &DI))
|
||||
I.moveBefore(MovePos);
|
||||
|
|
|
@ -2298,8 +2298,8 @@ llvm::InlineResult llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI,
|
|||
BB != E; ++BB) {
|
||||
// Add bundle operands to any top-level call sites.
|
||||
SmallVector<OperandBundleDef, 1> OpBundles;
|
||||
for (BasicBlock::iterator BBI = BB->begin(), E = BB->end(); BBI != E;) {
|
||||
CallBase *I = dyn_cast<CallBase>(&*BBI++);
|
||||
for (Instruction &II : llvm::make_early_inc_range(*BB)) {
|
||||
CallBase *I = dyn_cast<CallBase>(&II);
|
||||
if (!I)
|
||||
continue;
|
||||
|
||||
|
|
|
@ -6683,28 +6683,28 @@ void BoUpSLP::optimizeGatherSequence() {
|
|||
"Worklist not sorted properly!");
|
||||
BasicBlock *BB = (*I)->getBlock();
|
||||
// For all instructions in blocks containing gather sequences:
|
||||
for (BasicBlock::iterator it = BB->begin(), e = BB->end(); it != e;) {
|
||||
Instruction *In = &*it++;
|
||||
if (isDeleted(In))
|
||||
for (Instruction &In : llvm::make_early_inc_range(*BB)) {
|
||||
if (isDeleted(&In))
|
||||
continue;
|
||||
if (!isa<InsertElementInst>(In) && !isa<ExtractElementInst>(In) &&
|
||||
!isa<ShuffleVectorInst>(In))
|
||||
if (!isa<InsertElementInst>(&In) && !isa<ExtractElementInst>(&In) &&
|
||||
!isa<ShuffleVectorInst>(&In))
|
||||
continue;
|
||||
|
||||
// Check if we can replace this instruction with any of the
|
||||
// visited instructions.
|
||||
bool Replaced = false;
|
||||
for (Instruction *v : Visited) {
|
||||
if (In->isIdenticalTo(v) &&
|
||||
DT->dominates(v->getParent(), In->getParent())) {
|
||||
In->replaceAllUsesWith(v);
|
||||
eraseInstruction(In);
|
||||
In = nullptr;
|
||||
if (In.isIdenticalTo(v) &&
|
||||
DT->dominates(v->getParent(), In.getParent())) {
|
||||
In.replaceAllUsesWith(v);
|
||||
eraseInstruction(&In);
|
||||
Replaced = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (In) {
|
||||
assert(!is_contained(Visited, In));
|
||||
Visited.push_back(In);
|
||||
if (!Replaced) {
|
||||
assert(!is_contained(Visited, &In));
|
||||
Visited.push_back(&In);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue