[llvm] c8f9555 - [Transforms] Use *{Set,Map}::contains (NFC)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 14 00:24:37 PDT 2023
Author: Kazu Hirata
Date: 2023-03-14T00:24:30-07:00
New Revision: c8f9555c4d2d5686207a0111bf420cce5b219c46
URL: https://github.com/llvm/llvm-project/commit/c8f9555c4d2d5686207a0111bf420cce5b219c46
DIFF: https://github.com/llvm/llvm-project/commit/c8f9555c4d2d5686207a0111bf420cce5b219c46.diff
LOG: [Transforms] Use *{Set,Map}::contains (NFC)
Added:
Modified:
llvm/lib/Transforms/Coroutines/CoroFrame.cpp
llvm/lib/Transforms/IPO/IROutliner.cpp
llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
llvm/lib/Transforms/Scalar/Float2Int.cpp
llvm/lib/Transforms/Scalar/LoopInterchange.cpp
llvm/lib/Transforms/Scalar/Reassociate.cpp
llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp
llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
llvm/lib/Transforms/Vectorize/VPlan.h
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Coroutines/CoroFrame.cpp b/llvm/lib/Transforms/Coroutines/CoroFrame.cpp
index d15f73326631c..542a5a3bd6c95 100644
--- a/llvm/lib/Transforms/Coroutines/CoroFrame.cpp
+++ b/llvm/lib/Transforms/Coroutines/CoroFrame.cpp
@@ -943,7 +943,7 @@ void FrameTypeBuilder::finish(StructType *Ty) {
static void cacheDIVar(FrameDataInfo &FrameData,
DenseMap<Value *, DILocalVariable *> &DIVarCache) {
for (auto *V : FrameData.getAllDefs()) {
- if (DIVarCache.find(V) != DIVarCache.end())
+ if (DIVarCache.contains(V))
continue;
auto DDIs = FindDbgDeclareUses(V);
@@ -1166,7 +1166,7 @@ static void buildFrameDebugInfo(Function &F, coro::Shape &Shape,
dwarf::DW_ATE_unsigned_char)});
for (auto *V : FrameData.getAllDefs()) {
- if (DIVarCache.find(V) == DIVarCache.end())
+ if (!DIVarCache.contains(V))
continue;
auto Index = FrameData.getFieldIndex(V);
@@ -1198,7 +1198,7 @@ static void buildFrameDebugInfo(Function &F, coro::Shape &Shape,
// fields confilicts with each other.
unsigned UnknownTypeNum = 0;
for (unsigned Index = 0; Index < FrameTy->getNumElements(); Index++) {
- if (OffsetCache.find(Index) == OffsetCache.end())
+ if (!OffsetCache.contains(Index))
continue;
std::string Name;
@@ -1213,7 +1213,7 @@ static void buildFrameDebugInfo(Function &F, coro::Shape &Shape,
AlignInBits = OffsetCache[Index].first * 8;
OffsetInBits = OffsetCache[Index].second * 8;
- if (NameCache.find(Index) != NameCache.end()) {
+ if (NameCache.contains(Index)) {
Name = NameCache[Index].str();
DITy = TyCache[Index];
} else {
diff --git a/llvm/lib/Transforms/IPO/IROutliner.cpp b/llvm/lib/Transforms/IPO/IROutliner.cpp
index 82f890a50f059..b55aae1761406 100644
--- a/llvm/lib/Transforms/IPO/IROutliner.cpp
+++ b/llvm/lib/Transforms/IPO/IROutliner.cpp
@@ -588,7 +588,7 @@ collectRegionsConstants(OutlinableRegion &Region,
// While this value is a register, it might not have been previously,
// make sure we don't already have a constant mapped to this global value
// number.
- if (GVNToConstant.find(GVN) != GVNToConstant.end())
+ if (GVNToConstant.contains(GVN))
ConstantsTheSame = false;
NotSame.insert(GVN);
@@ -816,7 +816,7 @@ static void mapInputsToGVNs(IRSimilarityCandidate &C,
// replacement.
for (Value *Input : CurrentInputs) {
assert(Input && "Have a nullptr as an input");
- if (OutputMappings.find(Input) != OutputMappings.end())
+ if (OutputMappings.contains(Input))
Input = OutputMappings.find(Input)->second;
assert(C.getGVN(Input) && "Could not find a numbering for the given input");
EndInputNumbers.push_back(*C.getGVN(Input));
@@ -838,7 +838,7 @@ remapExtractedInputs(const ArrayRef<Value *> ArgInputs,
// Get the global value number for each input that will be extracted as an
// argument by the code extractor, remapping if needed for reloaded values.
for (Value *Input : ArgInputs) {
- if (OutputMappings.find(Input) != OutputMappings.end())
+ if (OutputMappings.contains(Input))
Input = OutputMappings.find(Input)->second;
RemappedArgInputs.insert(Input);
}
@@ -1481,8 +1481,7 @@ CallInst *replaceCalledFunction(Module &M, OutlinableRegion &Region) {
}
// If it is a constant, we simply add it to the argument list as a value.
- if (Region.AggArgToConstant.find(AggArgIdx) !=
- Region.AggArgToConstant.end()) {
+ if (Region.AggArgToConstant.contains(AggArgIdx)) {
Constant *CST = Region.AggArgToConstant.find(AggArgIdx)->second;
LLVM_DEBUG(dbgs() << "Setting argument " << AggArgIdx << " to value "
<< *CST << "\n");
@@ -2698,7 +2697,7 @@ void IROutliner::updateOutputMapping(OutlinableRegion &Region,
if (!OutputIdx)
return;
- if (OutputMappings.find(Outputs[*OutputIdx]) == OutputMappings.end()) {
+ if (!OutputMappings.contains(Outputs[*OutputIdx])) {
LLVM_DEBUG(dbgs() << "Mapping extracted output " << *LI << " to "
<< *Outputs[*OutputIdx] << "\n");
OutputMappings.insert(std::make_pair(LI, Outputs[*OutputIdx]));
diff --git a/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp b/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
index d0ef84b724aed..406692cad0b08 100644
--- a/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
+++ b/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
@@ -895,8 +895,7 @@ static Error checkCombinedSummaryForTesting(ModuleSummaryIndex *Summary) {
// DevirtIndex::run, not to DevirtModule::run used by opt/runForTesting.
const auto &ModPaths = Summary->modulePaths();
if (ClSummaryAction != PassSummaryAction::Import &&
- ModPaths.find(ModuleSummaryIndex::getRegularLTOModuleName()) ==
- ModPaths.end())
+ !ModPaths.contains(ModuleSummaryIndex::getRegularLTOModuleName()))
return createStringError(
errc::invalid_argument,
"combined summary should contain Regular LTO module");
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 2eb96abd24fc8..8d2759f597203 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -563,7 +563,7 @@ static Value *rewriteGEPAsOffset(Type *ElemTy, Value *Start, Value *Base,
// Create all the other instructions.
for (Value *Val : Explored) {
- if (NewInsts.find(Val) != NewInsts.end())
+ if (NewInsts.contains(Val))
continue;
if (auto *CI = dyn_cast<CastInst>(Val)) {
@@ -611,7 +611,7 @@ static Value *rewriteGEPAsOffset(Type *ElemTy, Value *Start, Value *Base,
for (unsigned I = 0, E = PHI->getNumIncomingValues(); I < E; ++I) {
Value *NewIncoming = PHI->getIncomingValue(I);
- if (NewInsts.find(NewIncoming) != NewInsts.end())
+ if (NewInsts.contains(NewIncoming))
NewIncoming = NewInsts[NewIncoming];
NewPhi->addIncoming(NewIncoming, PHI->getIncomingBlock(I));
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
index ea9aba449c749..5851e76454334 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
@@ -2936,7 +2936,7 @@ Instruction *InstCombinerImpl::visitShuffleVectorInst(ShuffleVectorInst &SVI) {
unsigned SrcElemsPerTgtElem = TgtElemBitWidth / SrcElemBitWidth;
assert(SrcElemsPerTgtElem);
BegIdx /= SrcElemsPerTgtElem;
- bool BCAlreadyExists = NewBCs.find(CastSrcTy) != NewBCs.end();
+ bool BCAlreadyExists = NewBCs.contains(CastSrcTy);
auto *NewBC =
BCAlreadyExists
? NewBCs[CastSrcTy]
diff --git a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
index 71cf77c97ed09..3d4724e5094dd 100644
--- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
@@ -515,8 +515,8 @@ ConstraintInfo::getConstraint(CmpInst::Predicate Pred, Value *Op0, Value *Op1,
// Add extra constraints for variables that are known positive.
for (auto &KV : KnownNonNegativeVariables) {
- if (!KV.second || (Value2Index.find(KV.first) == Value2Index.end() &&
- NewIndexMap.find(KV.first) == NewIndexMap.end()))
+ if (!KV.second ||
+ (!Value2Index.contains(KV.first) && !NewIndexMap.contains(KV.first)))
continue;
SmallVector<int64_t, 8> C(Value2Index.size() + NewVariables.size() + 1, 0);
C[GetOrAddIndex(KV.first)] = -1;
@@ -807,7 +807,7 @@ static void generateReproducer(CmpInst *Cond, Module *M,
continue;
auto *I = dyn_cast<Instruction>(V);
- if (Value2Index.find(V) != Value2Index.end() || !I ||
+ if (Value2Index.contains(V) || !I ||
!isa<CmpInst, BinaryOperator, GetElementPtrInst, CastInst>(V)) {
Old2New[V] = V;
Args.push_back(V);
@@ -857,7 +857,7 @@ static void generateReproducer(CmpInst *Cond, Module *M,
continue;
auto *I = dyn_cast<Instruction>(V);
- if (Value2Index.find(V) == Value2Index.end() && I) {
+ if (!Value2Index.contains(V) && I) {
Old2New[V] = nullptr;
ToClone.push_back(I);
append_range(WorkList, I->operands());
diff --git a/llvm/lib/Transforms/Scalar/Float2Int.cpp b/llvm/lib/Transforms/Scalar/Float2Int.cpp
index 7d27b783f1372..149d0dee2428d 100644
--- a/llvm/lib/Transforms/Scalar/Float2Int.cpp
+++ b/llvm/lib/Transforms/Scalar/Float2Int.cpp
@@ -187,7 +187,7 @@ void Float2IntPass::walkBackwards() {
Instruction *I = Worklist.back();
Worklist.pop_back();
- if (SeenInsts.find(I) != SeenInsts.end())
+ if (SeenInsts.contains(I))
// Seen already.
continue;
@@ -371,7 +371,7 @@ bool Float2IntPass::validateAndTransform() {
ConvertedToTy = I->getType();
for (User *U : I->users()) {
Instruction *UI = dyn_cast<Instruction>(U);
- if (!UI || SeenInsts.find(UI) == SeenInsts.end()) {
+ if (!UI || !SeenInsts.contains(UI)) {
LLVM_DEBUG(dbgs() << "F2I: Failing because of " << *U << "\n");
Fail = true;
break;
@@ -428,7 +428,7 @@ bool Float2IntPass::validateAndTransform() {
}
Value *Float2IntPass::convert(Instruction *I, Type *ToTy) {
- if (ConvertedInsts.find(I) != ConvertedInsts.end())
+ if (ConvertedInsts.contains(I))
// Already converted this instruction.
return ConvertedInsts[I];
diff --git a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
index 66c498aae808a..c256099557a58 100644
--- a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
@@ -1104,8 +1104,7 @@ LoopInterchangeProfitability::isProfitablePerLoopCacheAnalysis(
// This is the new cost model returned from loop cache analysis.
// A smaller index means the loop should be placed an outer loop, and vice
// versa.
- if (CostMap.find(InnerLoop) != CostMap.end() &&
- CostMap.find(OuterLoop) != CostMap.end()) {
+ if (CostMap.contains(InnerLoop) && CostMap.contains(OuterLoop)) {
unsigned InnerIndex = 0, OuterIndex = 0;
InnerIndex = CostMap.find(InnerLoop)->second;
OuterIndex = CostMap.find(OuterLoop)->second;
diff --git a/llvm/lib/Transforms/Scalar/Reassociate.cpp b/llvm/lib/Transforms/Scalar/Reassociate.cpp
index 21628b61edd62..f12b635a4da84 100644
--- a/llvm/lib/Transforms/Scalar/Reassociate.cpp
+++ b/llvm/lib/Transforms/Scalar/Reassociate.cpp
@@ -2048,7 +2048,7 @@ void ReassociatePass::EraseInst(Instruction *I) {
// blocks because it's a waste of time and also because it can
// lead to infinite loop due to LLVM's non-standard definition
// of dominance.
- if (ValueRankMap.find(Op) != ValueRankMap.end())
+ if (ValueRankMap.contains(Op))
RedoInsts.insert(Op);
}
diff --git a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
index 77afefcf37a40..37c32e12635ae 100644
--- a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
+++ b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
@@ -695,7 +695,7 @@ static Value *findBaseDefiningValue(Value *I, DefiningValueMapTy &Cache,
/// Returns the base defining value for this value.
static Value *findBaseDefiningValueCached(Value *I, DefiningValueMapTy &Cache,
IsKnownBaseMapTy &KnownBases) {
- if (Cache.find(I) == Cache.end()) {
+ if (!Cache.contains(I)) {
auto *BDV = findBaseDefiningValue(I, Cache, KnownBases);
Cache[I] = BDV;
LLVM_DEBUG(dbgs() << "fBDV-cached: " << I->getName() << " -> "
diff --git a/llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp b/llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp
index b125e952ec941..ed8e34f84e5aa 100644
--- a/llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp
+++ b/llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp
@@ -757,11 +757,11 @@ checkDependencies(Loop &Root, const BasicBlockSet &SubLoopBlocks,
DependenceInfo &DI, LoopInfo &LI) {
SmallVector<BasicBlockSet, 8> AllBlocks;
for (Loop *L : Root.getLoopsInPreorder())
- if (ForeBlocksMap.find(L) != ForeBlocksMap.end())
+ if (ForeBlocksMap.contains(L))
AllBlocks.push_back(ForeBlocksMap.lookup(L));
AllBlocks.push_back(SubLoopBlocks);
for (Loop *L : Root.getLoopsInPreorder())
- if (AftBlocksMap.find(L) != AftBlocksMap.end())
+ if (AftBlocksMap.contains(L))
AllBlocks.push_back(AftBlocksMap.lookup(L));
unsigned LoopDepth = Root.getLoopDepth();
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
index a7cd0c9821869..91539dd6f0786 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
@@ -902,7 +902,7 @@ bool LoopVectorizationLegality::canVectorizeInstrs() {
if (any_of(FixedOrderRecurrences, [LoopLatch, this](const PHINode *Phi) {
Instruction *V =
cast<Instruction>(Phi->getIncomingValueForBlock(LoopLatch));
- return SinkAfter.find(V) != SinkAfter.end();
+ return SinkAfter.contains(V);
}))
return false;
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 56211b1731f24..05922d3fa2146 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -1300,7 +1300,7 @@ class LoopVectorizationCostModel {
auto Scalars = InstsToScalarize.find(VF);
assert(Scalars != InstsToScalarize.end() &&
"VF not yet analyzed for scalarization profitability");
- return Scalars->second.find(I) != Scalars->second.end();
+ return Scalars->second.contains(I);
}
/// Returns true if \p I is known to be uniform after vectorization.
@@ -1344,7 +1344,7 @@ class LoopVectorizationCostModel {
/// \returns True if instruction \p I can be truncated to a smaller bitwidth
/// for vectorization factor \p VF.
bool canTruncateToMinimalBitwidth(Instruction *I, ElementCount VF) const {
- return VF.isVector() && MinBWs.find(I) != MinBWs.end() &&
+ return VF.isVector() && MinBWs.contains(I) &&
!isProfitableToScalarize(I, VF) &&
!isScalarAfterVectorization(I, VF);
}
@@ -1447,7 +1447,7 @@ class LoopVectorizationCostModel {
/// that may be vectorized as interleave, gather-scatter or scalarized.
void collectUniformsAndScalars(ElementCount VF) {
// Do the analysis once.
- if (VF.isScalar() || Uniforms.find(VF) != Uniforms.end())
+ if (VF.isScalar() || Uniforms.contains(VF))
return;
setCostBasedWideningDecision(VF);
collectLoopUniforms(VF);
@@ -1831,8 +1831,7 @@ class LoopVectorizationCostModel {
// the scalars are collected. That should be a safe assumption in most
// cases, because we check if the operands have vectorizable types
// beforehand in LoopVectorizationLegality.
- return Scalars.find(VF) == Scalars.end() ||
- !isScalarAfterVectorization(I, VF);
+ return !Scalars.contains(VF) || !isScalarAfterVectorization(I, VF);
};
/// Returns a range containing only operands needing to be extracted.
@@ -6189,8 +6188,7 @@ void LoopVectorizationCostModel::collectInstsToScalarize(ElementCount VF) {
// instructions to scalarize, there's nothing to do. Collection may already
// have occurred if we have a user-selected VF and are now computing the
// expected cost for interleaving.
- if (VF.isScalar() || VF.isZero() ||
- InstsToScalarize.find(VF) != InstsToScalarize.end())
+ if (VF.isScalar() || VF.isZero() || InstsToScalarize.contains(VF))
return;
// Initialize a mapping for VF in InstsToScalalarize. If we find that it's
@@ -6279,7 +6277,7 @@ InstructionCost LoopVectorizationCostModel::computePredInstDiscount(
Instruction *I = Worklist.pop_back_val();
// If we've already analyzed the instruction, there's nothing to do.
- if (ScalarCosts.find(I) != ScalarCosts.end())
+ if (ScalarCosts.contains(I))
continue;
// Compute the cost of the vector instruction. Note that this cost already
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index a20d4416457ff..21cfd084cb700 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -248,7 +248,7 @@ struct VPTransformState {
}
bool hasAnyVectorValue(VPValue *Def) const {
- return Data.PerPartOutput.find(Def) != Data.PerPartOutput.end();
+ return Data.PerPartOutput.contains(Def);
}
bool hasScalarValue(VPValue *Def, VPIteration Instance) {
More information about the llvm-commits
mailing list