Skip to content

Commit

Permalink
[Transforms] Use {DenseSet,SetVector,SmallPtrSet}::contains (NFC)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazutakahirata committed Oct 31, 2021
1 parent 1c2d333 commit c714da2
Show file tree
Hide file tree
Showing 14 changed files with 26 additions and 30 deletions.
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Coroutines/CoroSplit.cpp
Expand Up @@ -1355,7 +1355,7 @@ static bool hasCallsInBlocksBetween(BasicBlock *SaveBB, BasicBlock *ResDesBB) {
auto *BB = Worklist.pop_back_val();
Set.insert(BB);
for (auto *Pred : predecessors(BB))
if (Set.count(Pred) == 0)
if (!Set.contains(Pred))
Worklist.push_back(Pred);
}

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/IPO/FunctionAttrs.cpp
Expand Up @@ -1439,7 +1439,7 @@ static bool InstrBreaksNonConvergent(Instruction &I,
// Breaks non-convergent assumption if CS is a convergent call to a function
// not in the SCC.
return CB && CB->isConvergent() &&
SCCNodes.count(CB->getCalledFunction()) == 0;
!SCCNodes.contains(CB->getCalledFunction());
}

/// Helper for NoUnwind inference predicate InstrBreaksAttribute.
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/IPO/StripSymbols.cpp
Expand Up @@ -214,13 +214,13 @@ static bool StripSymbolNames(Module &M, bool PreserveDbgInfo) {
findUsedValues(M.getGlobalVariable("llvm.compiler.used"), llvmUsedValues);

for (GlobalVariable &GV : M.globals()) {
if (GV.hasLocalLinkage() && llvmUsedValues.count(&GV) == 0)
if (GV.hasLocalLinkage() && !llvmUsedValues.contains(&GV))
if (!PreserveDbgInfo || !GV.getName().startswith("llvm.dbg"))
GV.setName(""); // Internal symbols can't participate in linkage
}

for (Function &I : M) {
if (I.hasLocalLinkage() && llvmUsedValues.count(&I) == 0)
if (I.hasLocalLinkage() && !llvmUsedValues.contains(&I))
if (!PreserveDbgInfo || !I.getName().startswith("llvm.dbg"))
I.setName(""); // Internal symbols can't participate in linkage
if (auto *Symtab = I.getValueSymbolTable())
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
Expand Up @@ -2555,7 +2555,7 @@ Instruction *InstCombinerImpl::optimizeBitCastFromPhi(CastInst &CI,
// As long as the user is another old PHI node, then even if we don't
// rewrite it, the PHI web we're considering won't have any users
// outside itself, so it'll be dead.
if (OldPhiNodes.count(PHI) == 0)
if (!OldPhiNodes.contains(PHI))
return nullptr;
} else {
return nullptr;
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
Expand Up @@ -541,7 +541,7 @@ static bool canRewriteGEPAsOffset(Value *Start, Value *Base,
if (!CI->isNoopCast(DL))
return false;

if (Explored.count(CI->getOperand(0)) == 0)
if (!Explored.contains(CI->getOperand(0)))
WorkList.push_back(CI->getOperand(0));
}

Expand All @@ -553,7 +553,7 @@ static bool canRewriteGEPAsOffset(Value *Start, Value *Base,
GEP->getType() != Start->getType())
return false;

if (Explored.count(GEP->getOperand(0)) == 0)
if (!Explored.contains(GEP->getOperand(0)))
WorkList.push_back(GEP->getOperand(0));
}

Expand All @@ -575,7 +575,7 @@ static bool canRewriteGEPAsOffset(Value *Start, Value *Base,
// Explore the PHI nodes further.
for (auto *PN : PHIs)
for (Value *Op : PN->incoming_values())
if (Explored.count(Op) == 0)
if (!Explored.contains(Op))
WorkList.push_back(Op);
}

Expand All @@ -589,7 +589,7 @@ static bool canRewriteGEPAsOffset(Value *Start, Value *Base,
auto *Inst = dyn_cast<Instruction>(Val);

if (Inst == Base || Inst == PHI || !Inst || !PHI ||
Explored.count(PHI) == 0)
!Explored.contains(PHI))
continue;

if (PHI->getParent() == Inst->getParent())
Expand Down
Expand Up @@ -1553,11 +1553,11 @@ static bool negateICmpIfUsedByBranchOrSelectOnly(ICmpInst *ICmp,
SI->swapValues();
SI->swapProfMetadata();
if (Scope->TrueBiasedSelects.count(SI)) {
assert(Scope->FalseBiasedSelects.count(SI) == 0 &&
assert(!Scope->FalseBiasedSelects.contains(SI) &&
"Must not be already in");
Scope->FalseBiasedSelects.insert(SI);
} else if (Scope->FalseBiasedSelects.count(SI)) {
assert(Scope->TrueBiasedSelects.count(SI) == 0 &&
assert(!Scope->TrueBiasedSelects.contains(SI) &&
"Must not be already in");
Scope->TrueBiasedSelects.insert(SI);
}
Expand Down Expand Up @@ -1592,7 +1592,7 @@ static void insertTrivialPHIs(CHRScope *Scope,
SmallVector<Instruction *, 8> Users;
for (User *U : I.users()) {
if (auto *UI = dyn_cast<Instruction>(U)) {
if (BlocksInScope.count(UI->getParent()) == 0 &&
if (!BlocksInScope.contains(UI->getParent()) &&
// Unless there's already a phi for I at the exit block.
!(isa<PHINode>(UI) && UI->getParent() == ExitBlock)) {
CHR_DEBUG(dbgs() << "V " << I << "\n");
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Scalar/Float2Int.cpp
Expand Up @@ -372,7 +372,7 @@ bool Float2IntPass::validateAndTransform() {
// If it does, transformation would be illegal.
//
// Don't count the roots, as they terminate the graphs.
if (Roots.count(I) == 0) {
if (!Roots.contains(I)) {
// Set the type of the conversion while we're here.
if (!ConvertedToTy)
ConvertedToTy = I->getType();
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
Expand Up @@ -1019,7 +1019,7 @@ mayLoopAccessLocation(Value *Ptr, ModRefInfo Access, Loop *L,

for (BasicBlock *B : L->blocks())
for (Instruction &I : *B)
if (IgnoredInsts.count(&I) == 0 &&
if (!IgnoredInsts.contains(&I) &&
isModOrRefSet(
intersectModRef(AA.getModRefInfo(&I, StoreLoc), Access)))
return true;
Expand Down
16 changes: 6 additions & 10 deletions llvm/lib/Transforms/Scalar/LoopInterchange.cpp
Expand Up @@ -1710,16 +1710,12 @@ bool LoopInterchangeTransform::adjustLoopBranches() {
auto &OuterInnerReductions = LIL.getOuterInnerReductions();
// Now update the reduction PHIs in the inner and outer loop headers.
SmallVector<PHINode *, 4> InnerLoopPHIs, OuterLoopPHIs;
for (PHINode &PHI : InnerLoopHeader->phis()) {
if (OuterInnerReductions.find(&PHI) == OuterInnerReductions.end())
continue;
InnerLoopPHIs.push_back(cast<PHINode>(&PHI));
}
for (PHINode &PHI : OuterLoopHeader->phis()) {
if (OuterInnerReductions.find(&PHI) == OuterInnerReductions.end())
continue;
OuterLoopPHIs.push_back(cast<PHINode>(&PHI));
}
for (PHINode &PHI : InnerLoopHeader->phis())
if (OuterInnerReductions.contains(&PHI))
InnerLoopPHIs.push_back(cast<PHINode>(&PHI));
for (PHINode &PHI : OuterLoopHeader->phis())
if (OuterInnerReductions.contains(&PHI))
OuterLoopPHIs.push_back(cast<PHINode>(&PHI));

// Now move the remaining reduction PHIs from outer to inner loop header and
// vice versa. The PHI nodes must be part of a reduction across the inner and
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Scalar/NewGVN.cpp
Expand Up @@ -3607,7 +3607,7 @@ void NewGVN::convertClassToDFSOrdered(

// Skip uses in unreachable blocks, as we're going
// to delete them.
if (ReachableBlocks.count(IBlock) == 0)
if (!ReachableBlocks.contains(IBlock))
continue;

DomTreeNode *DomNode = DT->getNode(IBlock);
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Scalar/SpeculativeExecution.cpp
Expand Up @@ -268,7 +268,7 @@ bool SpeculativeExecutionPass::considerHoistingFromTo(
if (const auto *DVI = dyn_cast<DbgVariableIntrinsic>(U)) {
return all_of(DVI->location_ops(), [&NotHoisted](Value *V) {
if (const auto *I = dyn_cast_or_null<Instruction>(V)) {
if (NotHoisted.count(I) == 0)
if (!NotHoisted.contains(I))
return true;
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Utils/FixIrreducible.cpp
Expand Up @@ -124,7 +124,7 @@ static void reconnectChildLoops(LoopInfo &LI, Loop *ParentLoop, Loop *NewLoop,
// children to a new vector.
auto FirstChild = std::partition(
CandidateLoops.begin(), CandidateLoops.end(), [&](Loop *L) {
return L == NewLoop || Blocks.count(L->getHeader()) == 0;
return L == NewLoop || !Blocks.contains(L->getHeader());
});
SmallVector<Loop *, 8> ChildLoops(FirstChild, CandidateLoops.end());
CandidateLoops.erase(FirstChild, CandidateLoops.end());
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/Utils/FlattenCFG.cpp
Expand Up @@ -162,7 +162,7 @@ bool FlattenCFGOpt::FlattenParallelAndOr(BasicBlock *BB, IRBuilder<> &Builder) {
// of \param BB (BB4) and should not have address-taken.
// There should exist only one such unconditional
// branch among the predecessors.
if (UnCondBlock || !PP || (Preds.count(PP) == 0) ||
if (UnCondBlock || !PP || !Preds.contains(PP) ||
Pred->hasAddressTaken())
return false;

Expand Down Expand Up @@ -215,7 +215,7 @@ bool FlattenCFGOpt::FlattenParallelAndOr(BasicBlock *BB, IRBuilder<> &Builder) {

// PS is the successor which is not BB. Check successors to identify
// the last conditional branch.
if (Preds.count(PS) == 0) {
if (!Preds.contains(PS)) {
// Case 2.
LastCondBlock = Pred;
} else {
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Utils/SimplifyCFG.cpp
Expand Up @@ -2058,7 +2058,7 @@ static bool SinkCommonCodeFromPredecessors(BasicBlock *BB,
unsigned NumPHIdValues = 0;
for (auto *I : *LRI)
for (auto *V : PHIOperands[I]) {
if (InstructionsToSink.count(V) == 0)
if (!InstructionsToSink.contains(V))
++NumPHIdValues;
// FIXME: this check is overly optimistic. We may end up not sinking
// said instruction, due to the very same profitability check.
Expand Down

0 comments on commit c714da2

Please sign in to comment.