-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[llvm] Use llvm::is_contained (NFC) #145844
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[llvm] Use llvm::is_contained (NFC) #145844
Conversation
llvm::is_contained is shorter than llvm::all_of plus a lambda.
@llvm/pr-subscribers-tablegen @llvm/pr-subscribers-mc Author: Kazu Hirata (kazutakahirata) Changesllvm::is_contained is shorter than llvm::all_of plus a lambda. Full diff: https://github.com/llvm/llvm-project/pull/145844.diff 5 Files Affected:
diff --git a/llvm/lib/MC/MCRegisterInfo.cpp b/llvm/lib/MC/MCRegisterInfo.cpp
index 4a9bacdbc8fc4..ba9ef00f9f0d8 100644
--- a/llvm/lib/MC/MCRegisterInfo.cpp
+++ b/llvm/lib/MC/MCRegisterInfo.cpp
@@ -93,7 +93,7 @@ ArrayRef<MCPhysReg> MCRegisterInfo::getCachedAliasesOf(MCRegister R) const {
sort(Aliases);
Aliases.erase(unique(Aliases), Aliases.end());
- assert(none_of(Aliases, [&](auto &Cur) { return R == Cur; }) &&
+ assert(!llvm::is_contained(Aliases, R) &&
"MCRegAliasIteratorImpl includes Self!");
// Always put "self" at the end, so the iterator can choose to ignore it.
diff --git a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
index 3387dee8aa4c8..79b2dc2b3845e 100644
--- a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
@@ -4855,7 +4855,7 @@ getAppleRuntimeUnrollPreferences(Loop *L, ScalarEvolution &SE,
auto *Latch = L->getLoopLatch();
SmallVector<BasicBlock *> Preds(predecessors(Latch));
if (!Term || !Term->isConditional() || Preds.size() == 1 ||
- none_of(Preds, [Header](BasicBlock *Pred) { return Header == Pred; }) ||
+ !llvm::is_contained(Preds, Header) ||
none_of(Preds, [L](BasicBlock *Pred) { return L->contains(Pred); }))
return;
diff --git a/llvm/lib/Transforms/IPO/StripSymbols.cpp b/llvm/lib/Transforms/IPO/StripSymbols.cpp
index ecd0ade131467..ec701b6d0037b 100644
--- a/llvm/lib/Transforms/IPO/StripSymbols.cpp
+++ b/llvm/lib/Transforms/IPO/StripSymbols.cpp
@@ -309,8 +309,7 @@ PreservedAnalyses StripDeadCGProfilePass::run(Module &M,
SmallVector<Metadata *, 16> ValidCGEdges;
for (Metadata *Edge : CGProf->operands()) {
if (auto *EdgeAsNode = dyn_cast_or_null<MDNode>(Edge))
- if (llvm::all_of(EdgeAsNode->operands(),
- [](const Metadata *V) { return V != nullptr; }))
+ if (!llvm::is_contained(EdgeAsNode->operands(), nullptr))
ValidCGEdges.push_back(Edge);
}
M.setModuleFlag(Module::Append, "CG Profile",
diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp
index 7df5e9958182c..673422b7c7fce 100644
--- a/llvm/lib/Transforms/Utils/InlineFunction.cpp
+++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp
@@ -2336,16 +2336,14 @@ remapIndices(Function &Caller, BasicBlock *StartBB,
Worklist.push_back(Succ);
}
- assert(
- llvm::all_of(CalleeCounterMap, [&](const auto &V) { return V != 0; }) &&
- "Counter index mapping should be either to -1 or to non-zero index, "
- "because the 0 "
- "index corresponds to the entry BB of the caller");
- assert(
- llvm::all_of(CalleeCallsiteMap, [&](const auto &V) { return V != 0; }) &&
- "Callsite index mapping should be either to -1 or to non-zero index, "
- "because there should have been at least a callsite - the inlined one "
- "- which would have had a 0 index.");
+ assert(!llvm::is_contained(CalleeCounterMap, 0) &&
+ "Counter index mapping should be either to -1 or to non-zero index, "
+ "because the 0 "
+ "index corresponds to the entry BB of the caller");
+ assert(!llvm::is_contained(CalleeCallsiteMap, 0) &&
+ "Callsite index mapping should be either to -1 or to non-zero index, "
+ "because there should have been at least a callsite - the inlined one "
+ "- which would have had a 0 index.");
return {std::move(CalleeCounterMap), std::move(CalleeCallsiteMap)};
}
diff --git a/llvm/utils/TableGen/Common/CodeGenRegisters.cpp b/llvm/utils/TableGen/Common/CodeGenRegisters.cpp
index 57a243158692b..6260eeee331e1 100644
--- a/llvm/utils/TableGen/Common/CodeGenRegisters.cpp
+++ b/llvm/utils/TableGen/Common/CodeGenRegisters.cpp
@@ -881,7 +881,7 @@ bool CodeGenRegisterClass::hasType(const ValueTypeByHwMode &VT) const {
if (VT.isSimple()) {
MVT T = VT.getSimple();
for (const ValueTypeByHwMode &OurVT : VTs) {
- if (llvm::count_if(OurVT, [T](auto &&P) { return P.second == T; }))
+ if (llvm::is_contained(llvm::make_second_range(OurVT), T))
return true;
}
}
|
@llvm/pr-subscribers-backend-aarch64 Author: Kazu Hirata (kazutakahirata) Changesllvm::is_contained is shorter than llvm::all_of plus a lambda. Full diff: https://github.com/llvm/llvm-project/pull/145844.diff 5 Files Affected:
diff --git a/llvm/lib/MC/MCRegisterInfo.cpp b/llvm/lib/MC/MCRegisterInfo.cpp
index 4a9bacdbc8fc4..ba9ef00f9f0d8 100644
--- a/llvm/lib/MC/MCRegisterInfo.cpp
+++ b/llvm/lib/MC/MCRegisterInfo.cpp
@@ -93,7 +93,7 @@ ArrayRef<MCPhysReg> MCRegisterInfo::getCachedAliasesOf(MCRegister R) const {
sort(Aliases);
Aliases.erase(unique(Aliases), Aliases.end());
- assert(none_of(Aliases, [&](auto &Cur) { return R == Cur; }) &&
+ assert(!llvm::is_contained(Aliases, R) &&
"MCRegAliasIteratorImpl includes Self!");
// Always put "self" at the end, so the iterator can choose to ignore it.
diff --git a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
index 3387dee8aa4c8..79b2dc2b3845e 100644
--- a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
@@ -4855,7 +4855,7 @@ getAppleRuntimeUnrollPreferences(Loop *L, ScalarEvolution &SE,
auto *Latch = L->getLoopLatch();
SmallVector<BasicBlock *> Preds(predecessors(Latch));
if (!Term || !Term->isConditional() || Preds.size() == 1 ||
- none_of(Preds, [Header](BasicBlock *Pred) { return Header == Pred; }) ||
+ !llvm::is_contained(Preds, Header) ||
none_of(Preds, [L](BasicBlock *Pred) { return L->contains(Pred); }))
return;
diff --git a/llvm/lib/Transforms/IPO/StripSymbols.cpp b/llvm/lib/Transforms/IPO/StripSymbols.cpp
index ecd0ade131467..ec701b6d0037b 100644
--- a/llvm/lib/Transforms/IPO/StripSymbols.cpp
+++ b/llvm/lib/Transforms/IPO/StripSymbols.cpp
@@ -309,8 +309,7 @@ PreservedAnalyses StripDeadCGProfilePass::run(Module &M,
SmallVector<Metadata *, 16> ValidCGEdges;
for (Metadata *Edge : CGProf->operands()) {
if (auto *EdgeAsNode = dyn_cast_or_null<MDNode>(Edge))
- if (llvm::all_of(EdgeAsNode->operands(),
- [](const Metadata *V) { return V != nullptr; }))
+ if (!llvm::is_contained(EdgeAsNode->operands(), nullptr))
ValidCGEdges.push_back(Edge);
}
M.setModuleFlag(Module::Append, "CG Profile",
diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp
index 7df5e9958182c..673422b7c7fce 100644
--- a/llvm/lib/Transforms/Utils/InlineFunction.cpp
+++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp
@@ -2336,16 +2336,14 @@ remapIndices(Function &Caller, BasicBlock *StartBB,
Worklist.push_back(Succ);
}
- assert(
- llvm::all_of(CalleeCounterMap, [&](const auto &V) { return V != 0; }) &&
- "Counter index mapping should be either to -1 or to non-zero index, "
- "because the 0 "
- "index corresponds to the entry BB of the caller");
- assert(
- llvm::all_of(CalleeCallsiteMap, [&](const auto &V) { return V != 0; }) &&
- "Callsite index mapping should be either to -1 or to non-zero index, "
- "because there should have been at least a callsite - the inlined one "
- "- which would have had a 0 index.");
+ assert(!llvm::is_contained(CalleeCounterMap, 0) &&
+ "Counter index mapping should be either to -1 or to non-zero index, "
+ "because the 0 "
+ "index corresponds to the entry BB of the caller");
+ assert(!llvm::is_contained(CalleeCallsiteMap, 0) &&
+ "Callsite index mapping should be either to -1 or to non-zero index, "
+ "because there should have been at least a callsite - the inlined one "
+ "- which would have had a 0 index.");
return {std::move(CalleeCounterMap), std::move(CalleeCallsiteMap)};
}
diff --git a/llvm/utils/TableGen/Common/CodeGenRegisters.cpp b/llvm/utils/TableGen/Common/CodeGenRegisters.cpp
index 57a243158692b..6260eeee331e1 100644
--- a/llvm/utils/TableGen/Common/CodeGenRegisters.cpp
+++ b/llvm/utils/TableGen/Common/CodeGenRegisters.cpp
@@ -881,7 +881,7 @@ bool CodeGenRegisterClass::hasType(const ValueTypeByHwMode &VT) const {
if (VT.isSimple()) {
MVT T = VT.getSimple();
for (const ValueTypeByHwMode &OurVT : VTs) {
- if (llvm::count_if(OurVT, [T](auto &&P) { return P.second == T; }))
+ if (llvm::is_contained(llvm::make_second_range(OurVT), T))
return true;
}
}
|
llvm::is_contained is shorter than llvm::all_of plus a lambda.
llvm::is_contained is shorter than llvm::all_of plus a lambda.
llvm::is_contained is shorter than llvm::all_of plus a lambda.