SmallPtrSet::find -> SmallPtrSet::count

The latter is more readable and more efficient. While there clean up
some double lookups. NFCI.
This commit is contained in:
Benjamin Kramer 2020-06-07 22:36:10 +02:00
parent 73d41f52ec
commit ce9aba2e75
11 changed files with 31 additions and 44 deletions

View File

@ -435,9 +435,8 @@ template <class G> void AbstractDependenceGraphBuilder<G>::simplify() {
NodeType &Src = *Worklist.pop_back_val();
// As nodes get merged, we need to skip any node that has been removed from
// the candidate set (see below).
if (CandidateSourceNodes.find(&Src) == CandidateSourceNodes.end())
if (!CandidateSourceNodes.erase(&Src))
continue;
CandidateSourceNodes.erase(&Src);
assert(Src.getEdges().size() == 1 &&
"Expected a single edge from the candidate src node.");
@ -470,10 +469,9 @@ template <class G> void AbstractDependenceGraphBuilder<G>::simplify() {
// We also need to remove the old target (b), from the worklist. We first
// remove it from the candidate set here, and skip any item from the
// worklist that is not in the set.
if (CandidateSourceNodes.find(&Tgt) != CandidateSourceNodes.end()) {
if (CandidateSourceNodes.erase(&Tgt)) {
Worklist.push_back(&Src);
CandidateSourceNodes.insert(&Src);
CandidateSourceNodes.erase(&Tgt);
LLVM_DEBUG(dbgs() << "Putting " << &Src << " back in the worklist.\n");
}
}

View File

@ -684,7 +684,7 @@ StackSafetyGlobalInfo::~StackSafetyGlobalInfo() = default;
bool StackSafetyGlobalInfo::isSafe(const AllocaInst &AI) const {
const auto &Info = getInfo();
return Info.SafeAllocas.find(&AI) != Info.SafeAllocas.end();
return Info.SafeAllocas.count(&AI);
}
void StackSafetyGlobalInfo::print(raw_ostream &O) const {

View File

@ -2613,8 +2613,7 @@ void Verifier::visitCallBrInst(CallBrInst &CBI) {
if (auto *BA = dyn_cast<BlockAddress>(V))
ArgBBs.insert(BA->getBasicBlock());
for (BasicBlock *BB : CBI.getIndirectDests())
Assert(ArgBBs.find(BB) != ArgBBs.end(),
"Indirect label missing from arglist.", &CBI);
Assert(ArgBBs.count(BB), "Indirect label missing from arglist.", &CBI);
}
visitTerminator(CBI);

View File

@ -214,9 +214,8 @@ void GCNMinRegScheduler::bumpPredsPriority(const SUnit *SchedSU, int Priority) {
LLVM_DEBUG(dbgs() << "Make the predecessors of SU(" << SchedSU->NodeNum
<< ")'s non-ready successors of " << Priority
<< " priority in ready queue: ");
const auto SetEnd = Set.end();
for (auto &C : RQ) {
if (Set.find(C.SU) != SetEnd) {
if (Set.count(C.SU)) {
C.Priority = Priority;
LLVM_DEBUG(dbgs() << " SU(" << C.SU->NodeNum << ')');
}

View File

@ -1792,7 +1792,7 @@ struct DSEState {
return false;
if (SI->getParent() == NI->getParent())
return ThrowingBlocks.find(SI->getParent()) != ThrowingBlocks.end();
return ThrowingBlocks.count(SI->getParent());
return !ThrowingBlocks.empty();
}

View File

@ -694,7 +694,7 @@ bool LoopInterchangeLegality::findInductionAndReductions(
// PHIs in inner loops need to be part of a reduction in the outer loop,
// discovered when checking the PHIs of the outer loop earlier.
if (!InnerLoop) {
if (OuterInnerReductions.find(&PHI) == OuterInnerReductions.end()) {
if (!OuterInnerReductions.count(&PHI)) {
LLVM_DEBUG(dbgs() << "Inner loop PHI is not part of reductions "
"across the outer loop.\n");
return false;
@ -908,8 +908,8 @@ areInnerLoopExitPHIsSupported(Loop *InnerL, Loop *OuterL,
return false;
if (any_of(PHI.users(), [&Reductions, OuterL](User *U) {
PHINode *PN = dyn_cast<PHINode>(U);
return !PN || (Reductions.find(PN) == Reductions.end() &&
OuterL->contains(PN->getParent()));
return !PN ||
(!Reductions.count(PN) && OuterL->contains(PN->getParent()));
})) {
return false;
}
@ -1582,13 +1582,11 @@ bool LoopInterchangeTransform::adjustLoopBranches() {
// outer loop and all the remains to do is and updating the incoming blocks.
for (PHINode *PHI : OuterLoopPHIs) {
PHI->moveBefore(InnerLoopHeader->getFirstNonPHI());
assert(OuterInnerReductions.find(PHI) != OuterInnerReductions.end() &&
"Expected a reduction PHI node");
assert(OuterInnerReductions.count(PHI) && "Expected a reduction PHI node");
}
for (PHINode *PHI : InnerLoopPHIs) {
PHI->moveBefore(OuterLoopHeader->getFirstNonPHI());
assert(OuterInnerReductions.find(PHI) != OuterInnerReductions.end() &&
"Expected a reduction PHI node");
assert(OuterInnerReductions.count(PHI) && "Expected a reduction PHI node");
}
// Update the incoming blocks for moved PHI nodes.

View File

@ -705,7 +705,7 @@ public:
// Third, lower remaining instructions with shape information.
for (Instruction *Inst : MatrixInsts) {
if (FusedInsts.find(Inst) != FusedInsts.end())
if (FusedInsts.count(Inst))
continue;
IRBuilder<> Builder(Inst);
@ -1593,7 +1593,7 @@ public:
// Deal with shared subtrees. Mark them as shared, if required.
if (!ParentShared) {
auto SI = Shared.find(Expr);
assert(SI != Shared.end() && SI->second.find(Leaf) != SI->second.end());
assert(SI != Shared.end() && SI->second.count(Leaf));
for (Value *S : SI->second) {
if (S == Leaf)

View File

@ -213,9 +213,8 @@ bool FastDivInsertionTask::isHashLikeValue(Value *V, VisitedSetTy &Visited) {
return false;
// Do not visit nodes that have been visited already. We return true because
// it means that we couldn't find any value that doesn't look hash-like.
if (Visited.find(I) != Visited.end())
if (!Visited.insert(I).second)
return true;
Visited.insert(I);
return llvm::all_of(cast<PHINode>(I)->incoming_values(), [&](Value *V) {
// Ignore undef values as they probably don't affect the division
// operands.

View File

@ -2260,7 +2260,7 @@ bool llvm::removeUnreachableBlocks(Function &F, DomTreeUpdater *DTU,
SmallSetVector<BasicBlock *, 8> DeadBlockSet;
for (BasicBlock &BB : F) {
// Skip reachable basic blocks
if (Reachable.find(&BB) != Reachable.end())
if (Reachable.count(&BB))
continue;
DeadBlockSet.insert(&BB);
}

View File

@ -1070,7 +1070,7 @@ public:
auto UniformsPerVF = Uniforms.find(VF);
assert(UniformsPerVF != Uniforms.end() &&
"VF not yet analyzed for uniformity");
return UniformsPerVF->second.find(I) != UniformsPerVF->second.end();
return UniformsPerVF->second.count(I);
}
/// Returns true if \p I is known to be scalar after vectorization.
@ -1086,7 +1086,7 @@ public:
auto ScalarsPerVF = Scalars.find(VF);
assert(ScalarsPerVF != Scalars.end() &&
"Scalar values are not calculated for VF");
return ScalarsPerVF->second.find(I) != ScalarsPerVF->second.end();
return ScalarsPerVF->second.count(I);
}
/// \returns True if instruction \p I can be truncated to a smaller bitwidth
@ -3354,8 +3354,7 @@ void InnerLoopVectorizer::truncateToMinimalBitwidths() {
continue;
for (unsigned Part = 0; Part < UF; ++Part) {
Value *I = getOrCreateVectorValue(KV.first, Part);
if (Erased.find(I) != Erased.end() || I->use_empty() ||
!isa<Instruction>(I))
if (Erased.count(I) || I->use_empty() || !isa<Instruction>(I))
continue;
Type *OriginalTy = I->getType();
Type *ScalarTruncatedTy =
@ -4532,7 +4531,7 @@ void LoopVectorizationCostModel::collectLoopScalars(unsigned VF) {
}
}
for (auto *I : ScalarPtrs)
if (PossibleNonScalarPtrs.find(I) == PossibleNonScalarPtrs.end()) {
if (!PossibleNonScalarPtrs.count(I)) {
LLVM_DEBUG(dbgs() << "LV: Found scalar instruction: " << *I << "\n");
Worklist.insert(I);
}
@ -4838,7 +4837,7 @@ void LoopVectorizationCostModel::collectLoopUniforms(unsigned VF) {
// Add to the Worklist all consecutive and consecutive-like pointers that
// aren't also identified as possibly non-uniform.
for (auto *V : ConsecutiveLikePtrs)
if (PossibleNonUniformPtrs.find(V) == PossibleNonUniformPtrs.end())
if (!PossibleNonUniformPtrs.count(V))
addToWorklistIfAllowed(V);
// Expand Worklist in topological order: whenever a new instruction
@ -5185,7 +5184,7 @@ LoopVectorizationCostModel::getSmallestAndWidestTypes() {
Type *T = I.getType();
// Skip ignored values.
if (ValuesToIgnore.find(&I) != ValuesToIgnore.end())
if (ValuesToIgnore.count(&I))
continue;
// Only examine Loads, Stores and PHINodes.
@ -5504,11 +5503,11 @@ LoopVectorizationCostModel::calculateRegisterUsage(ArrayRef<unsigned> VFs) {
OpenIntervals.erase(ToRemove);
// Ignore instructions that are never used within the loop.
if (Ends.find(I) == Ends.end())
if (!Ends.count(I))
continue;
// Skip ignored values.
if (ValuesToIgnore.find(I) != ValuesToIgnore.end())
if (ValuesToIgnore.count(I))
continue;
// For each VF find the maximum usage of registers.
@ -5528,7 +5527,7 @@ LoopVectorizationCostModel::calculateRegisterUsage(ArrayRef<unsigned> VFs) {
collectUniformsAndScalars(VFs[j]);
for (auto Inst : OpenIntervals) {
// Skip ignored values for VF > 1.
if (VecValuesToIgnore.find(Inst) != VecValuesToIgnore.end())
if (VecValuesToIgnore.count(Inst))
continue;
if (isScalarAfterVectorization(Inst, VFs[j])) {
unsigned ClassID = TTI.getRegisterClassForType(false, Inst->getType());
@ -5766,8 +5765,7 @@ LoopVectorizationCostModel::expectedCost(unsigned VF) {
// For each instruction in the old loop.
for (Instruction &I : BB->instructionsWithoutDebug()) {
// Skip ignored values.
if (ValuesToIgnore.find(&I) != ValuesToIgnore.end() ||
(VF > 1 && VecValuesToIgnore.find(&I) != VecValuesToIgnore.end()))
if (ValuesToIgnore.count(&I) || (VF > 1 && VecValuesToIgnore.count(&I)))
continue;
VectorizationCostTy C = getInstructionCost(&I, VF);
@ -6011,7 +6009,7 @@ LoopVectorizationCostModel::getInstructionCost(Instruction *I, unsigned VF) {
auto ForcedScalar = ForcedScalars.find(VF);
if (VF > 1 && ForcedScalar != ForcedScalars.end()) {
auto InstSet = ForcedScalar->second;
if (InstSet.find(I) != InstSet.end())
if (InstSet.count(I))
return VectorizationCostTy((getInstructionCost(I, 1).first * VF), false);
}
@ -6231,10 +6229,8 @@ unsigned LoopVectorizationCostModel::getInstructionCost(Instruction *I,
bool ScalarPredicatedBB = false;
BranchInst *BI = cast<BranchInst>(I);
if (VF > 1 && BI->isConditional() &&
(PredicatedBBsAfterVectorization.find(BI->getSuccessor(0)) !=
PredicatedBBsAfterVectorization.end() ||
PredicatedBBsAfterVectorization.find(BI->getSuccessor(1)) !=
PredicatedBBsAfterVectorization.end()))
(PredicatedBBsAfterVectorization.count(BI->getSuccessor(0)) ||
PredicatedBBsAfterVectorization.count(BI->getSuccessor(1))))
ScalarPredicatedBB = true;
if (ScalarPredicatedBB) {
@ -6673,8 +6669,7 @@ void LoopVectorizationPlanner::collectTriviallyDeadInstructions(
PHINode *Ind = Induction.first;
auto *IndUpdate = cast<Instruction>(Ind->getIncomingValueForBlock(Latch));
if (llvm::all_of(IndUpdate->users(), [&](User *U) -> bool {
return U == Ind || DeadInstructions.find(cast<Instruction>(U)) !=
DeadInstructions.end();
return U == Ind || DeadInstructions.count(cast<Instruction>(U));
}))
DeadInstructions.insert(IndUpdate);
@ -7291,8 +7286,7 @@ VPlanPtr LoopVectorizationPlanner::buildVPlanWithVPRecipes(
// First filter out irrelevant instructions, to ensure no recipes are
// built for them.
if (isa<BranchInst>(Instr) ||
DeadInstructions.find(Instr) != DeadInstructions.end())
if (isa<BranchInst>(Instr) || DeadInstructions.count(Instr))
continue;
if (auto Recipe =

View File

@ -864,7 +864,7 @@ bool ReduceCrashingMetadata::TestInsts(std::vector<Instruction *> &Insts) {
// selected in Instructions.
for (Function &F : *M)
for (Instruction &Inst : instructions(F)) {
if (Instructions.find(&Inst) == Instructions.end()) {
if (!Instructions.count(&Inst)) {
Inst.dropUnknownNonDebugMetadata();
Inst.setDebugLoc({});
}