[llvm] d639120 - [llvm] Use set_is_subset (NFC)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Sun Feb 28 10:59:51 PST 2021
Author: Kazu Hirata
Date: 2021-02-28T10:59:20-08:00
New Revision: d639120983c696563c35c13d938590ca19a74af2
URL: https://github.com/llvm/llvm-project/commit/d639120983c696563c35c13d938590ca19a74af2
DIFF: https://github.com/llvm/llvm-project/commit/d639120983c696563c35c13d938590ca19a74af2.diff
LOG: [llvm] Use set_is_subset (NFC)
Added:
Modified:
llvm/include/llvm/ADT/SetOperations.h
llvm/include/llvm/Analysis/LoopInfoImpl.h
llvm/lib/Analysis/ScopedNoAliasAA.cpp
llvm/lib/CodeGen/MachinePipeliner.cpp
llvm/lib/CodeGen/ReachingDefAnalysis.cpp
llvm/lib/Transforms/Scalar/LoopSink.cpp
llvm/lib/Transforms/Scalar/NewGVN.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/ADT/SetOperations.h b/llvm/include/llvm/ADT/SetOperations.h
index 6087f479fe37..d3c22306cb57 100644
--- a/llvm/include/llvm/ADT/SetOperations.h
+++ b/llvm/include/llvm/ADT/SetOperations.h
@@ -71,7 +71,7 @@ template <class S1Ty, class S2Ty>
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 426b349c6b8a..ca44d03f57cb 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<const BlockT *> &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 6b38d6716b92..d3ba607b2399 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 7e5fa221b775..454d74e7af4c 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<SUnit *> &Path,
return FoundPath;
}
-/// Return true if Set1 is a subset of Set2.
-template <class S1Ty, class S2Ty> 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<SUnit *, 8> 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<SUnit *, 8> 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 d16e90a7e0b4..63c668bc192f 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<MachineInstr*, 4> 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<MachineInstr*, 2> 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 58815a1c4fa6..a01287f587d7 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 281d47c8625f..31dbac139020 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 @@ class CongruenceClass {
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:
More information about the llvm-commits
mailing list