From d639120983c696563c35c13d938590ca19a74af2 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sun, 28 Feb 2021 10:59:20 -0800 Subject: [PATCH] [llvm] Use set_is_subset (NFC) --- llvm/include/llvm/ADT/SetOperations.h | 2 +- llvm/include/llvm/Analysis/LoopInfoImpl.h | 6 ++---- llvm/lib/Analysis/ScopedNoAliasAA.cpp | 10 ++-------- llvm/lib/CodeGen/MachinePipeliner.cpp | 15 ++++----------- llvm/lib/CodeGen/ReachingDefAnalysis.cpp | 11 ++++------- llvm/lib/Transforms/Scalar/LoopSink.cpp | 9 ++++----- llvm/lib/Transforms/Scalar/NewGVN.cpp | 4 ++-- 7 files changed, 19 insertions(+), 38 deletions(-) diff --git a/llvm/include/llvm/ADT/SetOperations.h b/llvm/include/llvm/ADT/SetOperations.h index 6087f47..d3c2230 100644 --- a/llvm/include/llvm/ADT/SetOperations.h +++ b/llvm/include/llvm/ADT/SetOperations.h @@ -71,7 +71,7 @@ template bool set_is_subset(const S1Ty &S1, const S2Ty &S2) { if (S1.size() > S2.size()) return false; - for (auto &It : S1) + for (const auto &It : S1) if (!S2.count(It)) return false; return true; diff --git a/llvm/include/llvm/Analysis/LoopInfoImpl.h b/llvm/include/llvm/Analysis/LoopInfoImpl.h index 426b349..ca44d03 100644 --- a/llvm/include/llvm/Analysis/LoopInfoImpl.h +++ b/llvm/include/llvm/Analysis/LoopInfoImpl.h @@ -17,6 +17,7 @@ #include "llvm/ADT/DepthFirstIterator.h" #include "llvm/ADT/PostOrderIterator.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/SetOperations.h" #include "llvm/Analysis/LoopInfo.h" #include "llvm/IR/Dominators.h" @@ -676,10 +677,7 @@ static void compareLoops(const LoopT *L, const LoopT *OtherL, const SmallPtrSetImpl &OtherBlocksSet = OtherL->getBlocksSet(); assert(BlocksSet.size() == OtherBlocksSet.size() && - llvm::all_of(BlocksSet, - [&OtherBlocksSet](const BlockT *BB) { - return OtherBlocksSet.count(BB); - }) && + llvm::set_is_subset(BlocksSet, OtherBlocksSet) && "Mismatched basic blocks in BlocksSets!"); } #endif diff --git a/llvm/lib/Analysis/ScopedNoAliasAA.cpp b/llvm/lib/Analysis/ScopedNoAliasAA.cpp index 6b38d67..d3ba607 100644 --- a/llvm/lib/Analysis/ScopedNoAliasAA.cpp +++ b/llvm/lib/Analysis/ScopedNoAliasAA.cpp @@ -32,6 +32,7 @@ //===----------------------------------------------------------------------===// #include "llvm/Analysis/ScopedNoAliasAA.h" +#include "llvm/ADT/SetOperations.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/Analysis/MemoryLocation.h" #include "llvm/IR/InstrTypes.h" @@ -138,14 +139,7 @@ bool ScopedNoAliasAAResult::mayAliasInScopes(const MDNode *Scopes, collectMDInDomain(NoAlias, Domain, NANodes); // To not alias, all of the nodes in ScopeNodes must be in NANodes. - bool FoundAll = true; - for (const MDNode *SMD : ScopeNodes) - if (!NANodes.count(SMD)) { - FoundAll = false; - break; - } - - if (FoundAll) + if (llvm::set_is_subset(ScopeNodes, NANodes)) return false; } diff --git a/llvm/lib/CodeGen/MachinePipeliner.cpp b/llvm/lib/CodeGen/MachinePipeliner.cpp index 7e5fa22..454d74e 100644 --- a/llvm/lib/CodeGen/MachinePipeliner.cpp +++ b/llvm/lib/CodeGen/MachinePipeliner.cpp @@ -34,6 +34,7 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/MapVector.h" #include "llvm/ADT/PriorityQueue.h" +#include "llvm/ADT/SetOperations.h" #include "llvm/ADT/SetVector.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallSet.h" @@ -1600,14 +1601,6 @@ static bool computePath(SUnit *Cur, SetVector &Path, return FoundPath; } -/// Return true if Set1 is a subset of Set2. -template static bool isSubset(S1Ty &Set1, S2Ty &Set2) { - for (typename S1Ty::iterator I = Set1.begin(), E = Set1.end(); I != E; ++I) - if (Set2.count(*I) == 0) - return false; - return true; -} - /// Compute the live-out registers for the instructions in a node-set. /// The live-out registers are those that are defined in the node-set, /// but not used. Except for use operands of Phis. @@ -1711,7 +1704,7 @@ void SwingSchedulerDAG::colocateNodeSets(NodeSetType &NodeSets) { SmallSetVector S2; if (N2.empty() || !succ_L(N2, S2)) continue; - if (isSubset(S1, S2) && S1.size() == S2.size()) { + if (llvm::set_is_subset(S1, S2) && S1.size() == S2.size()) { N1.setColocate(++Colocate); N2.setColocate(Colocate); break; @@ -1883,11 +1876,11 @@ void SwingSchedulerDAG::computeNodeOrder(NodeSetType &NodeSets) { LLVM_DEBUG(dbgs() << "NodeSet size " << Nodes.size() << "\n"); OrderKind Order; SmallSetVector N; - if (pred_L(NodeOrder, N) && isSubset(N, Nodes)) { + if (pred_L(NodeOrder, N) && llvm::set_is_subset(N, Nodes)) { R.insert(N.begin(), N.end()); Order = BottomUp; LLVM_DEBUG(dbgs() << " Bottom up (preds) "); - } else if (succ_L(NodeOrder, N) && isSubset(N, Nodes)) { + } else if (succ_L(NodeOrder, N) && llvm::set_is_subset(N, Nodes)) { R.insert(N.begin(), N.end()); Order = TopDown; LLVM_DEBUG(dbgs() << " Top down (succs) "); diff --git a/llvm/lib/CodeGen/ReachingDefAnalysis.cpp b/llvm/lib/CodeGen/ReachingDefAnalysis.cpp index d16e90a..63c668b 100644 --- a/llvm/lib/CodeGen/ReachingDefAnalysis.cpp +++ b/llvm/lib/CodeGen/ReachingDefAnalysis.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "llvm/ADT/SmallSet.h" +#include "llvm/ADT/SetOperations.h" #include "llvm/CodeGen/LivePhysRegs.h" #include "llvm/CodeGen/ReachingDefAnalysis.h" #include "llvm/CodeGen/TargetRegisterInfo.h" @@ -660,10 +661,7 @@ void ReachingDefAnalysis::collectKilledOperands(MachineInstr *MI, SmallPtrSet Uses; getGlobalUses(Def, PhysReg, Uses); - for (auto *Use : Uses) - if (!Dead.count(Use)) - return false; - return true; + return llvm::set_is_subset(Uses, Dead); }; for (auto &MO : MI->operands()) { @@ -688,9 +686,8 @@ bool ReachingDefAnalysis::isSafeToDefRegAt(MachineInstr *MI, MCRegister PhysReg, if (auto *Def = getReachingLocalMIDef(MI, PhysReg)) { SmallPtrSet Uses; getGlobalUses(Def, PhysReg, Uses); - for (auto *Use : Uses) - if (!Ignore.count(Use)) - return false; + if (!llvm::set_is_subset(Uses, Ignore)) + return false; } else return false; } diff --git a/llvm/lib/Transforms/Scalar/LoopSink.cpp b/llvm/lib/Transforms/Scalar/LoopSink.cpp index 58815a1..a01287f 100644 --- a/llvm/lib/Transforms/Scalar/LoopSink.cpp +++ b/llvm/lib/Transforms/Scalar/LoopSink.cpp @@ -31,6 +31,7 @@ //===----------------------------------------------------------------------===// #include "llvm/Transforms/Scalar/LoopSink.h" +#include "llvm/ADT/SetOperations.h" #include "llvm/ADT/Statistic.h" #include "llvm/Analysis/AliasAnalysis.h" #include "llvm/Analysis/AliasSetTracker.h" @@ -212,11 +213,9 @@ static bool sinkInstruction( return false; // Return if any of the candidate blocks to sink into is non-cold. - if (BBsToSinkInto.size() > 1) { - for (auto *BB : BBsToSinkInto) - if (!LoopBlockNumber.count(BB)) - return false; - } + if (BBsToSinkInto.size() > 1 && + !llvm::set_is_subset(BBsToSinkInto, LoopBlockNumber)) + return false; // Copy the final BBs into a vector and sort them using the total ordering // of the loop block numbers as iterating the set doesn't give a useful diff --git a/llvm/lib/Transforms/Scalar/NewGVN.cpp b/llvm/lib/Transforms/Scalar/NewGVN.cpp index 281d47c..31dbac1 100644 --- a/llvm/lib/Transforms/Scalar/NewGVN.cpp +++ b/llvm/lib/Transforms/Scalar/NewGVN.cpp @@ -62,6 +62,7 @@ #include "llvm/ADT/Hashing.h" #include "llvm/ADT/PointerIntPair.h" #include "llvm/ADT/PostOrderIterator.h" +#include "llvm/ADT/SetOperations.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/SparseBitVector.h" @@ -389,8 +390,7 @@ public: if (Members.size() != Other->Members.size()) return false; - return all_of(Members, - [&](const Value *V) { return Other->Members.count(V); }); + return llvm::set_is_subset(Members, Other->Members); } private: -- 2.7.4