Skip to content

Commit d639120

Browse files
[llvm] Use set_is_subset (NFC)
1 parent ca5247b commit d639120

File tree

7 files changed

+19
-38
lines changed

7 files changed

+19
-38
lines changed

llvm/include/llvm/ADT/SetOperations.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ template <class S1Ty, class S2Ty>
7171
bool set_is_subset(const S1Ty &S1, const S2Ty &S2) {
7272
if (S1.size() > S2.size())
7373
return false;
74-
for (auto &It : S1)
74+
for (const auto &It : S1)
7575
if (!S2.count(It))
7676
return false;
7777
return true;

llvm/include/llvm/Analysis/LoopInfoImpl.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "llvm/ADT/DepthFirstIterator.h"
1818
#include "llvm/ADT/PostOrderIterator.h"
1919
#include "llvm/ADT/STLExtras.h"
20+
#include "llvm/ADT/SetOperations.h"
2021
#include "llvm/Analysis/LoopInfo.h"
2122
#include "llvm/IR/Dominators.h"
2223

@@ -676,10 +677,7 @@ static void compareLoops(const LoopT *L, const LoopT *OtherL,
676677
const SmallPtrSetImpl<const BlockT *> &OtherBlocksSet =
677678
OtherL->getBlocksSet();
678679
assert(BlocksSet.size() == OtherBlocksSet.size() &&
679-
llvm::all_of(BlocksSet,
680-
[&OtherBlocksSet](const BlockT *BB) {
681-
return OtherBlocksSet.count(BB);
682-
}) &&
680+
llvm::set_is_subset(BlocksSet, OtherBlocksSet) &&
683681
"Mismatched basic blocks in BlocksSets!");
684682
}
685683
#endif

llvm/lib/Analysis/ScopedNoAliasAA.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
//===----------------------------------------------------------------------===//
3333

3434
#include "llvm/Analysis/ScopedNoAliasAA.h"
35+
#include "llvm/ADT/SetOperations.h"
3536
#include "llvm/ADT/SmallPtrSet.h"
3637
#include "llvm/Analysis/MemoryLocation.h"
3738
#include "llvm/IR/InstrTypes.h"
@@ -138,14 +139,7 @@ bool ScopedNoAliasAAResult::mayAliasInScopes(const MDNode *Scopes,
138139
collectMDInDomain(NoAlias, Domain, NANodes);
139140

140141
// To not alias, all of the nodes in ScopeNodes must be in NANodes.
141-
bool FoundAll = true;
142-
for (const MDNode *SMD : ScopeNodes)
143-
if (!NANodes.count(SMD)) {
144-
FoundAll = false;
145-
break;
146-
}
147-
148-
if (FoundAll)
142+
if (llvm::set_is_subset(ScopeNodes, NANodes))
149143
return false;
150144
}
151145

llvm/lib/CodeGen/MachinePipeliner.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "llvm/ADT/DenseMap.h"
3535
#include "llvm/ADT/MapVector.h"
3636
#include "llvm/ADT/PriorityQueue.h"
37+
#include "llvm/ADT/SetOperations.h"
3738
#include "llvm/ADT/SetVector.h"
3839
#include "llvm/ADT/SmallPtrSet.h"
3940
#include "llvm/ADT/SmallSet.h"
@@ -1600,14 +1601,6 @@ static bool computePath(SUnit *Cur, SetVector<SUnit *> &Path,
16001601
return FoundPath;
16011602
}
16021603

1603-
/// Return true if Set1 is a subset of Set2.
1604-
template <class S1Ty, class S2Ty> static bool isSubset(S1Ty &Set1, S2Ty &Set2) {
1605-
for (typename S1Ty::iterator I = Set1.begin(), E = Set1.end(); I != E; ++I)
1606-
if (Set2.count(*I) == 0)
1607-
return false;
1608-
return true;
1609-
}
1610-
16111604
/// Compute the live-out registers for the instructions in a node-set.
16121605
/// The live-out registers are those that are defined in the node-set,
16131606
/// but not used. Except for use operands of Phis.
@@ -1711,7 +1704,7 @@ void SwingSchedulerDAG::colocateNodeSets(NodeSetType &NodeSets) {
17111704
SmallSetVector<SUnit *, 8> S2;
17121705
if (N2.empty() || !succ_L(N2, S2))
17131706
continue;
1714-
if (isSubset(S1, S2) && S1.size() == S2.size()) {
1707+
if (llvm::set_is_subset(S1, S2) && S1.size() == S2.size()) {
17151708
N1.setColocate(++Colocate);
17161709
N2.setColocate(Colocate);
17171710
break;
@@ -1883,11 +1876,11 @@ void SwingSchedulerDAG::computeNodeOrder(NodeSetType &NodeSets) {
18831876
LLVM_DEBUG(dbgs() << "NodeSet size " << Nodes.size() << "\n");
18841877
OrderKind Order;
18851878
SmallSetVector<SUnit *, 8> N;
1886-
if (pred_L(NodeOrder, N) && isSubset(N, Nodes)) {
1879+
if (pred_L(NodeOrder, N) && llvm::set_is_subset(N, Nodes)) {
18871880
R.insert(N.begin(), N.end());
18881881
Order = BottomUp;
18891882
LLVM_DEBUG(dbgs() << " Bottom up (preds) ");
1890-
} else if (succ_L(NodeOrder, N) && isSubset(N, Nodes)) {
1883+
} else if (succ_L(NodeOrder, N) && llvm::set_is_subset(N, Nodes)) {
18911884
R.insert(N.begin(), N.end());
18921885
Order = TopDown;
18931886
LLVM_DEBUG(dbgs() << " Top down (succs) ");

llvm/lib/CodeGen/ReachingDefAnalysis.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "llvm/ADT/SmallSet.h"
10+
#include "llvm/ADT/SetOperations.h"
1011
#include "llvm/CodeGen/LivePhysRegs.h"
1112
#include "llvm/CodeGen/ReachingDefAnalysis.h"
1213
#include "llvm/CodeGen/TargetRegisterInfo.h"
@@ -660,10 +661,7 @@ void ReachingDefAnalysis::collectKilledOperands(MachineInstr *MI,
660661

661662
SmallPtrSet<MachineInstr*, 4> Uses;
662663
getGlobalUses(Def, PhysReg, Uses);
663-
for (auto *Use : Uses)
664-
if (!Dead.count(Use))
665-
return false;
666-
return true;
664+
return llvm::set_is_subset(Uses, Dead);
667665
};
668666

669667
for (auto &MO : MI->operands()) {
@@ -688,9 +686,8 @@ bool ReachingDefAnalysis::isSafeToDefRegAt(MachineInstr *MI, MCRegister PhysReg,
688686
if (auto *Def = getReachingLocalMIDef(MI, PhysReg)) {
689687
SmallPtrSet<MachineInstr*, 2> Uses;
690688
getGlobalUses(Def, PhysReg, Uses);
691-
for (auto *Use : Uses)
692-
if (!Ignore.count(Use))
693-
return false;
689+
if (!llvm::set_is_subset(Uses, Ignore))
690+
return false;
694691
} else
695692
return false;
696693
}

llvm/lib/Transforms/Scalar/LoopSink.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
//===----------------------------------------------------------------------===//
3232

3333
#include "llvm/Transforms/Scalar/LoopSink.h"
34+
#include "llvm/ADT/SetOperations.h"
3435
#include "llvm/ADT/Statistic.h"
3536
#include "llvm/Analysis/AliasAnalysis.h"
3637
#include "llvm/Analysis/AliasSetTracker.h"
@@ -212,11 +213,9 @@ static bool sinkInstruction(
212213
return false;
213214

214215
// Return if any of the candidate blocks to sink into is non-cold.
215-
if (BBsToSinkInto.size() > 1) {
216-
for (auto *BB : BBsToSinkInto)
217-
if (!LoopBlockNumber.count(BB))
218-
return false;
219-
}
216+
if (BBsToSinkInto.size() > 1 &&
217+
!llvm::set_is_subset(BBsToSinkInto, LoopBlockNumber))
218+
return false;
220219

221220
// Copy the final BBs into a vector and sort them using the total ordering
222221
// of the loop block numbers as iterating the set doesn't give a useful

llvm/lib/Transforms/Scalar/NewGVN.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
#include "llvm/ADT/Hashing.h"
6363
#include "llvm/ADT/PointerIntPair.h"
6464
#include "llvm/ADT/PostOrderIterator.h"
65+
#include "llvm/ADT/SetOperations.h"
6566
#include "llvm/ADT/SmallPtrSet.h"
6667
#include "llvm/ADT/SmallVector.h"
6768
#include "llvm/ADT/SparseBitVector.h"
@@ -389,8 +390,7 @@ class CongruenceClass {
389390
if (Members.size() != Other->Members.size())
390391
return false;
391392

392-
return all_of(Members,
393-
[&](const Value *V) { return Other->Members.count(V); });
393+
return llvm::set_is_subset(Members, Other->Members);
394394
}
395395

396396
private:

0 commit comments

Comments
 (0)