From 0abf9f34bf085e79f2bddfe6d99e5167d3021b32 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sun, 20 Dec 2020 09:19:35 -0800 Subject: [PATCH] [Analysis, IR, CodeGen] Use llvm::erase_if (NFC) --- include/llvm/IR/PassManager.h | 6 +++--- lib/Analysis/CGSCCPassManager.cpp | 27 ++++++++++++--------------- lib/Analysis/ScalarEvolution.cpp | 4 +--- lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 4 +--- lib/CodeGen/RDFLiveness.cpp | 2 +- lib/CodeGen/StackMaps.cpp | 5 +---- lib/IR/LLVMContextImpl.h | 3 +-- lib/IR/Metadata.cpp | 9 ++++----- 8 files changed, 24 insertions(+), 36 deletions(-) diff --git a/include/llvm/IR/PassManager.h b/include/llvm/IR/PassManager.h index 9aea968c895..c669565aa33 100644 --- a/include/llvm/IR/PassManager.h +++ b/include/llvm/IR/PassManager.h @@ -1129,9 +1129,9 @@ public: for (auto &KeyValuePair : OuterAnalysisInvalidationMap) { AnalysisKey *OuterID = KeyValuePair.first; auto &InnerIDs = KeyValuePair.second; - InnerIDs.erase(llvm::remove_if(InnerIDs, [&](AnalysisKey *InnerID) { - return Inv.invalidate(InnerID, IRUnit, PA); }), - InnerIDs.end()); + llvm::erase_if(InnerIDs, [&](AnalysisKey *InnerID) { + return Inv.invalidate(InnerID, IRUnit, PA); + }); if (InnerIDs.empty()) DeadKeys.push_back(OuterID); } diff --git a/lib/Analysis/CGSCCPassManager.cpp b/lib/Analysis/CGSCCPassManager.cpp index 59df6059dcf..7eb2168bcc0 100644 --- a/lib/Analysis/CGSCCPassManager.cpp +++ b/lib/Analysis/CGSCCPassManager.cpp @@ -1039,23 +1039,20 @@ static LazyCallGraph::SCC &updateCGAndAnalysisManagerForPass( DeadTargets.push_back(&E.getNode()); } // Remove the easy cases quickly and actually pull them out of our list. - DeadTargets.erase( - llvm::remove_if(DeadTargets, - [&](Node *TargetN) { - SCC &TargetC = *G.lookupSCC(*TargetN); - RefSCC &TargetRC = TargetC.getOuterRefSCC(); + llvm::erase_if(DeadTargets, [&](Node *TargetN) { + SCC &TargetC = *G.lookupSCC(*TargetN); + RefSCC &TargetRC = TargetC.getOuterRefSCC(); - // We can't trivially remove internal targets, so skip - // those. - if (&TargetRC == RC) - return false; + // We can't trivially remove internal targets, so skip + // those. + if (&TargetRC == RC) + return false; - RC->removeOutgoingEdge(N, *TargetN); - LLVM_DEBUG(dbgs() << "Deleting outgoing edge from '" - << N << "' to '" << TargetN << "'\n"); - return true; - }), - DeadTargets.end()); + RC->removeOutgoingEdge(N, *TargetN); + LLVM_DEBUG(dbgs() << "Deleting outgoing edge from '" << N << "' to '" + << TargetN << "'\n"); + return true; + }); // Now do a batch removal of the internal ref edges left. auto NewRefSCCs = RC->removeInternalRefEdge(N, DeadTargets); diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp index 071b569d3f1..361a1437f69 100644 --- a/lib/Analysis/ScalarEvolution.cpp +++ b/lib/Analysis/ScalarEvolution.cpp @@ -11620,9 +11620,7 @@ static bool findArrayDimensionsRec(ScalarEvolution &SE, } // Remove all SCEVConstants. - Terms.erase( - remove_if(Terms, [](const SCEV *E) { return isa(E); }), - Terms.end()); + erase_if(Terms, [](const SCEV *E) { return isa(E); }); if (Terms.size() > 0) if (!findArrayDimensionsRec(SE, Terms, Sizes)) diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index 2be446531fa..75b4a2831b0 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -1636,9 +1636,7 @@ bool DwarfDebug::buildLocationList(SmallVectorImpl &DebugLoc, // Remove all values that are no longer live. size_t Index = std::distance(EB, EI); - auto Last = - remove_if(OpenRanges, [&](OpenRange &R) { return R.first <= Index; }); - OpenRanges.erase(Last, OpenRanges.end()); + erase_if(OpenRanges, [&](OpenRange &R) { return R.first <= Index; }); // If we are dealing with a clobbering entry, this iteration will result in // a location list entry starting after the clobbering instruction. diff --git a/lib/CodeGen/RDFLiveness.cpp b/lib/CodeGen/RDFLiveness.cpp index 50bd910739b..37273bb0c4b 100644 --- a/lib/CodeGen/RDFLiveness.cpp +++ b/lib/CodeGen/RDFLiveness.cpp @@ -300,7 +300,7 @@ NodeList Liveness::getAllReachingDefs(RegisterRef RefRR, auto DeadP = [](const NodeAddr DA) -> bool { return DA.Addr->getFlags() & NodeAttrs::Dead; }; - RDefs.resize(std::distance(RDefs.begin(), llvm::remove_if(RDefs, DeadP))); + llvm::erase_if(RDefs, DeadP); return RDefs; } diff --git a/lib/CodeGen/StackMaps.cpp b/lib/CodeGen/StackMaps.cpp index ee1a4a47b4c..5645e3062d4 100644 --- a/lib/CodeGen/StackMaps.cpp +++ b/lib/CodeGen/StackMaps.cpp @@ -361,10 +361,7 @@ StackMaps::parseRegisterLiveOutMask(const uint32_t *Mask) const { } } - LiveOuts.erase( - llvm::remove_if(LiveOuts, - [](const LiveOutReg &LO) { return LO.Reg == 0; }), - LiveOuts.end()); + llvm::erase_if(LiveOuts, [](const LiveOutReg &LO) { return LO.Reg == 0; }); return LiveOuts; } diff --git a/lib/IR/LLVMContextImpl.h b/lib/IR/LLVMContextImpl.h index ddbf1e518eb..46feca94fcd 100644 --- a/lib/IR/LLVMContextImpl.h +++ b/lib/IR/LLVMContextImpl.h @@ -1304,8 +1304,7 @@ public: /// /// Erases all attachments matching the \c shouldRemove predicate. template void remove_if(PredTy shouldRemove) { - Attachments.erase(llvm::remove_if(Attachments, shouldRemove), - Attachments.end()); + llvm::erase_if(Attachments, shouldRemove); } }; diff --git a/lib/IR/Metadata.cpp b/lib/IR/Metadata.cpp index 4dd0052c60a..7ca538995db 100644 --- a/lib/IR/Metadata.cpp +++ b/lib/IR/Metadata.cpp @@ -1169,11 +1169,10 @@ bool MDAttachments::erase(unsigned ID) { return true; } - auto I = std::remove_if(Attachments.begin(), Attachments.end(), - [ID](const Attachment &A) { return A.MDKind == ID; }); - bool Changed = I != Attachments.end(); - Attachments.erase(I, Attachments.end()); - return Changed; + auto OldSize = Attachments.size(); + llvm::erase_if(Attachments, + [ID](const Attachment &A) { return A.MDKind == ID; }); + return OldSize != Attachments.size(); } MDNode *Value::getMetadata(unsigned KindID) const {