Skip to content

Commit b621116

Browse files
[Transforms] Use llvm::erase_if (NFC)
1 parent 7087ae7 commit b621116

File tree

8 files changed

+65
-97
lines changed

8 files changed

+65
-97
lines changed

llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -950,10 +950,9 @@ void CHR::checkScopeHoistable(CHRScope *Scope) {
950950
<< "Dropped select due to unhoistable branch";
951951
});
952952
}
953-
Selects.erase(std::remove_if(Selects.begin(), Selects.end(),
954-
[EntryBB](SelectInst *SI) {
955-
return SI->getParent() == EntryBB;
956-
}), Selects.end());
953+
llvm::erase_if(Selects, [EntryBB](SelectInst *SI) {
954+
return SI->getParent() == EntryBB;
955+
});
957956
Unhoistables.clear();
958957
InsertPoint = Branch;
959958
}

llvm/lib/Transforms/Scalar/GuardWidening.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ bool GuardWideningImpl::combineRangeChecks(
666666
};
667667

668668
copy_if(Checks, std::back_inserter(CurrentChecks), IsCurrentCheck);
669-
Checks.erase(remove_if(Checks, IsCurrentCheck), Checks.end());
669+
erase_if(Checks, IsCurrentCheck);
670670

671671
assert(CurrentChecks.size() != 0 && "We know we have at least one!");
672672

llvm/lib/Transforms/Scalar/IndVarSimplify.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,7 +1399,7 @@ bool IndVarSimplify::optimizeLoopExits(Loop *L, SCEVExpander &Rewriter) {
13991399

14001400
// Remove all exits which aren't both rewriteable and execute on every
14011401
// iteration.
1402-
auto NewEnd = llvm::remove_if(ExitingBlocks, [&](BasicBlock *ExitingBB) {
1402+
llvm::erase_if(ExitingBlocks, [&](BasicBlock *ExitingBB) {
14031403
// If our exitting block exits multiple loops, we can only rewrite the
14041404
// innermost one. Otherwise, we're changing how many times the innermost
14051405
// loop runs before it exits.
@@ -1421,7 +1421,6 @@ bool IndVarSimplify::optimizeLoopExits(Loop *L, SCEVExpander &Rewriter) {
14211421

14221422
return false;
14231423
});
1424-
ExitingBlocks.erase(NewEnd, ExitingBlocks.end());
14251424

14261425
if (ExitingBlocks.empty())
14271426
return false;

llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2038,8 +2038,7 @@ static void relocationViaAlloca(
20382038
/// tests in ways which make them less useful in testing fused safepoints.
20392039
template <typename T> static void unique_unsorted(SmallVectorImpl<T> &Vec) {
20402040
SmallSet<T, 8> Seen;
2041-
Vec.erase(remove_if(Vec, [&](const T &V) { return !Seen.insert(V).second; }),
2042-
Vec.end());
2041+
erase_if(Vec, [&](const T &V) { return !Seen.insert(V).second; });
20432042
}
20442043

20452044
/// Insert holders so that each Value is obviously live through the entire

llvm/lib/Transforms/Scalar/SROA.cpp

Lines changed: 52 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -467,12 +467,8 @@ class AllocaSlices::partition_iterator
467467
// Remove the uses which have ended in the prior partition. This
468468
// cannot change the max split slice end because we just checked that
469469
// the prior partition ended prior to that max.
470-
P.SplitTails.erase(llvm::remove_if(P.SplitTails,
471-
[&](Slice *S) {
472-
return S->endOffset() <=
473-
P.EndOffset;
474-
}),
475-
P.SplitTails.end());
470+
llvm::erase_if(P.SplitTails,
471+
[&](Slice *S) { return S->endOffset() <= P.EndOffset; });
476472
assert(llvm::any_of(P.SplitTails,
477473
[&](Slice *S) {
478474
return S->endOffset() == MaxSplitSliceEndOffset;
@@ -1076,9 +1072,7 @@ AllocaSlices::AllocaSlices(const DataLayout &DL, AllocaInst &AI)
10761072
return;
10771073
}
10781074

1079-
Slices.erase(
1080-
llvm::remove_if(Slices, [](const Slice &S) { return S.isDead(); }),
1081-
Slices.end());
1075+
llvm::erase_if(Slices, [](const Slice &S) { return S.isDead(); });
10821076

10831077
// Sort the uses. This arranges for the offsets to be in ascending order,
10841078
// and the sizes to be in descending order.
@@ -1932,12 +1926,9 @@ static VectorType *isVectorPromotionViable(Partition &P, const DataLayout &DL) {
19321926
// do that until all the backends are known to produce good code for all
19331927
// integer vector types.
19341928
if (!HaveCommonEltTy) {
1935-
CandidateTys.erase(
1936-
llvm::remove_if(CandidateTys,
1937-
[](VectorType *VTy) {
1938-
return !VTy->getElementType()->isIntegerTy();
1939-
}),
1940-
CandidateTys.end());
1929+
llvm::erase_if(CandidateTys, [](VectorType *VTy) {
1930+
return !VTy->getElementType()->isIntegerTy();
1931+
});
19411932

19421933
// If there were no integer vector types, give up.
19431934
if (CandidateTys.empty())
@@ -3902,63 +3893,53 @@ bool SROA::presplitLoadsAndStores(AllocaInst &AI, AllocaSlices &AS) {
39023893
// such loads and stores, we can only pre-split them if their splits exactly
39033894
// match relative to their starting offset. We have to verify this prior to
39043895
// any rewriting.
3905-
Stores.erase(
3906-
llvm::remove_if(Stores,
3907-
[&UnsplittableLoads, &SplitOffsetsMap](StoreInst *SI) {
3908-
// Lookup the load we are storing in our map of split
3909-
// offsets.
3910-
auto *LI = cast<LoadInst>(SI->getValueOperand());
3911-
// If it was completely unsplittable, then we're done,
3912-
// and this store can't be pre-split.
3913-
if (UnsplittableLoads.count(LI))
3914-
return true;
3915-
3916-
auto LoadOffsetsI = SplitOffsetsMap.find(LI);
3917-
if (LoadOffsetsI == SplitOffsetsMap.end())
3918-
return false; // Unrelated loads are definitely safe.
3919-
auto &LoadOffsets = LoadOffsetsI->second;
3920-
3921-
// Now lookup the store's offsets.
3922-
auto &StoreOffsets = SplitOffsetsMap[SI];
3923-
3924-
// If the relative offsets of each split in the load and
3925-
// store match exactly, then we can split them and we
3926-
// don't need to remove them here.
3927-
if (LoadOffsets.Splits == StoreOffsets.Splits)
3928-
return false;
3929-
3930-
LLVM_DEBUG(
3931-
dbgs()
3932-
<< " Mismatched splits for load and store:\n"
3933-
<< " " << *LI << "\n"
3934-
<< " " << *SI << "\n");
3935-
3936-
// We've found a store and load that we need to split
3937-
// with mismatched relative splits. Just give up on them
3938-
// and remove both instructions from our list of
3939-
// candidates.
3940-
UnsplittableLoads.insert(LI);
3941-
return true;
3942-
}),
3943-
Stores.end());
3896+
llvm::erase_if(Stores, [&UnsplittableLoads, &SplitOffsetsMap](StoreInst *SI) {
3897+
// Lookup the load we are storing in our map of split
3898+
// offsets.
3899+
auto *LI = cast<LoadInst>(SI->getValueOperand());
3900+
// If it was completely unsplittable, then we're done,
3901+
// and this store can't be pre-split.
3902+
if (UnsplittableLoads.count(LI))
3903+
return true;
3904+
3905+
auto LoadOffsetsI = SplitOffsetsMap.find(LI);
3906+
if (LoadOffsetsI == SplitOffsetsMap.end())
3907+
return false; // Unrelated loads are definitely safe.
3908+
auto &LoadOffsets = LoadOffsetsI->second;
3909+
3910+
// Now lookup the store's offsets.
3911+
auto &StoreOffsets = SplitOffsetsMap[SI];
3912+
3913+
// If the relative offsets of each split in the load and
3914+
// store match exactly, then we can split them and we
3915+
// don't need to remove them here.
3916+
if (LoadOffsets.Splits == StoreOffsets.Splits)
3917+
return false;
3918+
3919+
LLVM_DEBUG(dbgs() << " Mismatched splits for load and store:\n"
3920+
<< " " << *LI << "\n"
3921+
<< " " << *SI << "\n");
3922+
3923+
// We've found a store and load that we need to split
3924+
// with mismatched relative splits. Just give up on them
3925+
// and remove both instructions from our list of
3926+
// candidates.
3927+
UnsplittableLoads.insert(LI);
3928+
return true;
3929+
});
39443930
// Now we have to go *back* through all the stores, because a later store may
39453931
// have caused an earlier store's load to become unsplittable and if it is
39463932
// unsplittable for the later store, then we can't rely on it being split in
39473933
// the earlier store either.
3948-
Stores.erase(llvm::remove_if(Stores,
3949-
[&UnsplittableLoads](StoreInst *SI) {
3950-
auto *LI =
3951-
cast<LoadInst>(SI->getValueOperand());
3952-
return UnsplittableLoads.count(LI);
3953-
}),
3954-
Stores.end());
3934+
llvm::erase_if(Stores, [&UnsplittableLoads](StoreInst *SI) {
3935+
auto *LI = cast<LoadInst>(SI->getValueOperand());
3936+
return UnsplittableLoads.count(LI);
3937+
});
39553938
// Once we've established all the loads that can't be split for some reason,
39563939
// filter any that made it into our list out.
3957-
Loads.erase(llvm::remove_if(Loads,
3958-
[&UnsplittableLoads](LoadInst *LI) {
3959-
return UnsplittableLoads.count(LI);
3960-
}),
3961-
Loads.end());
3940+
llvm::erase_if(Loads, [&UnsplittableLoads](LoadInst *LI) {
3941+
return UnsplittableLoads.count(LI);
3942+
});
39623943

39633944
// If no loads or stores are left, there is no pre-splitting to be done for
39643945
// this alloca.
@@ -4232,8 +4213,7 @@ bool SROA::presplitLoadsAndStores(AllocaInst &AI, AllocaSlices &AS) {
42324213
}
42334214

42344215
// Remove the killed slices that have ben pre-split.
4235-
AS.erase(llvm::remove_if(AS, [](const Slice &S) { return S.isDead(); }),
4236-
AS.end());
4216+
llvm::erase_if(AS, [](const Slice &S) { return S.isDead(); });
42374217

42384218
// Insert our new slices. This will sort and merge them into the sorted
42394219
// sequence.
@@ -4247,11 +4227,9 @@ bool SROA::presplitLoadsAndStores(AllocaInst &AI, AllocaSlices &AS) {
42474227

42484228
// Finally, don't try to promote any allocas that new require re-splitting.
42494229
// They have already been added to the worklist above.
4250-
PromotableAllocas.erase(
4251-
llvm::remove_if(
4252-
PromotableAllocas,
4253-
[&](AllocaInst *AI) { return ResplitPromotableAllocas.count(AI); }),
4254-
PromotableAllocas.end());
4230+
llvm::erase_if(PromotableAllocas, [&](AllocaInst *AI) {
4231+
return ResplitPromotableAllocas.count(AI);
4232+
});
42554233

42564234
return true;
42574235
}
@@ -4768,8 +4746,7 @@ PreservedAnalyses SROA::runImpl(Function &F, DominatorTree &RunDT,
47684746
auto IsInSet = [&](AllocaInst *AI) { return DeletedAllocas.count(AI); };
47694747
Worklist.remove_if(IsInSet);
47704748
PostPromotionWorklist.remove_if(IsInSet);
4771-
PromotableAllocas.erase(llvm::remove_if(PromotableAllocas, IsInSet),
4772-
PromotableAllocas.end());
4749+
llvm::erase_if(PromotableAllocas, IsInSet);
47734750
DeletedAllocas.clear();
47744751
}
47754752
}

llvm/lib/Transforms/Scalar/SpeculateAroundPHIs.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -756,13 +756,10 @@ static bool tryToSpeculatePHIs(SmallVectorImpl<PHINode *> &PNs,
756756
// For each PHI node in this block, check whether there are immediate folding
757757
// opportunities from speculation, and whether that speculation will be
758758
// valid. This determise the set of safe PHIs to speculate.
759-
PNs.erase(llvm::remove_if(PNs,
760-
[&](PHINode *PN) {
761-
return !isSafeAndProfitableToSpeculateAroundPHI(
762-
*PN, CostSavingsMap, PotentialSpecSet,
763-
UnsafeSet, DT, TTI);
764-
}),
765-
PNs.end());
759+
llvm::erase_if(PNs, [&](PHINode *PN) {
760+
return !isSafeAndProfitableToSpeculateAroundPHI(
761+
*PN, CostSavingsMap, PotentialSpecSet, UnsafeSet, DT, TTI);
762+
});
766763
// If no PHIs were profitable, skip.
767764
if (PNs.empty()) {
768765
LLVM_DEBUG(dbgs() << " No safe and profitable PHIs found!\n");

llvm/lib/Transforms/Utils/InlineFunction.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2194,10 +2194,9 @@ llvm::InlineResult llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI,
21942194
// match the callee's return type, we also need to change the return type of
21952195
// the intrinsic.
21962196
if (Caller->getReturnType() == CB.getType()) {
2197-
auto NewEnd = llvm::remove_if(Returns, [](ReturnInst *RI) {
2197+
llvm::erase_if(Returns, [](ReturnInst *RI) {
21982198
return RI->getParent()->getTerminatingDeoptimizeCall() != nullptr;
21992199
});
2200-
Returns.erase(NewEnd, Returns.end());
22012200
} else {
22022201
SmallVector<ReturnInst *, 8> NormalReturns;
22032202
Function *NewDeoptIntrinsic = Intrinsic::getDeclaration(

llvm/lib/Transforms/Utils/LowerSwitch.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -474,10 +474,8 @@ void ProcessSwitchInst(SwitchInst *SI,
474474
// cases.
475475
assert(MaxPop > 0 && PopSucc);
476476
Default = PopSucc;
477-
Cases.erase(
478-
llvm::remove_if(
479-
Cases, [PopSucc](const CaseRange &R) { return R.BB == PopSucc; }),
480-
Cases.end());
477+
llvm::erase_if(Cases,
478+
[PopSucc](const CaseRange &R) { return R.BB == PopSucc; });
481479

482480
// If there are no cases left, just branch.
483481
if (Cases.empty()) {

0 commit comments

Comments
 (0)