-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[flang] Use llvm::any_of and llvm::none_of (NFC) #102797
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
[flang] Use llvm::any_of and llvm::none_of (NFC) #102797
Conversation
@llvm/pr-subscribers-flang-semantics Author: Kazu Hirata (kazutakahirata) ChangesFull diff: https://github.com/llvm/llvm-project/pull/102797.diff 4 Files Affected:
diff --git a/flang/lib/Optimizer/Transforms/ConstantArgumentGlobalisation.cpp b/flang/lib/Optimizer/Transforms/ConstantArgumentGlobalisation.cpp
index 7d0b8b3d7bc53d..1e44288c784c2a 100644
--- a/flang/lib/Optimizer/Transforms/ConstantArgumentGlobalisation.cpp
+++ b/flang/lib/Optimizer/Transforms/ConstantArgumentGlobalisation.cpp
@@ -98,9 +98,8 @@ class CallOpRewriter : public mlir::OpRewritePattern<fir::CallOp> {
assert(!builder.getNamedGlobal(globalName) &&
"We should have a unique name here");
- if (std::find_if(allocas.begin(), allocas.end(), [alloca](auto x) {
- return x.first == alloca;
- }) == allocas.end()) {
+ if (llvm::none_of(allocas,
+ [alloca](auto x) { return x.first == alloca; })) {
allocas.push_back(std::make_pair(alloca, store));
}
diff --git a/flang/lib/Semantics/data-to-inits.cpp b/flang/lib/Semantics/data-to-inits.cpp
index b6dbbbf63138ec..0f8b36de460865 100644
--- a/flang/lib/Semantics/data-to-inits.cpp
+++ b/flang/lib/Semantics/data-to-inits.cpp
@@ -522,11 +522,10 @@ static const DerivedTypeSpec *HasDefaultInitialization(const Symbol &symbol) {
} else if (!object->isDummy() && object->type()) {
if (const DerivedTypeSpec * derived{object->type()->AsDerived()}) {
DirectComponentIterator directs{*derived};
- if (std::find_if(
- directs.begin(), directs.end(), [](const Symbol &component) {
- return !IsAllocatable(component) &&
- HasDeclarationInitializer(component);
- }) != directs.end()) {
+ if (llvm::any_of(directs, [](const Symbol &component) {
+ return !IsAllocatable(component) &&
+ HasDeclarationInitializer(component);
+ })) {
return derived;
}
}
diff --git a/flang/lib/Semantics/rewrite-directives.cpp b/flang/lib/Semantics/rewrite-directives.cpp
index 2c3c87f2546a35..c94d0f3855bee3 100644
--- a/flang/lib/Semantics/rewrite-directives.cpp
+++ b/flang/lib/Semantics/rewrite-directives.cpp
@@ -88,11 +88,9 @@ bool OmpRewriteMutator::Pre(parser::OpenMPAtomicConstruct &x) {
auto findMemOrderClause =
[](const std::list<parser::OmpAtomicClause> &clauses) {
- return std::find_if(
- clauses.begin(), clauses.end(), [](const auto &clause) {
- return std::get_if<parser::OmpMemoryOrderClause>(
- &clause.u);
- }) != clauses.end();
+ return llvm::any_of(clauses, [](const auto &clause) {
+ return std::get_if<parser::OmpMemoryOrderClause>(&clause.u);
+ });
};
// Get the clause list to which the new memory order clause must be added,
diff --git a/flang/lib/Semantics/symbol.cpp b/flang/lib/Semantics/symbol.cpp
index 31e91ee7355e33..b593bf89b18bc9 100644
--- a/flang/lib/Semantics/symbol.cpp
+++ b/flang/lib/Semantics/symbol.cpp
@@ -230,11 +230,10 @@ void GenericDetails::CopyFrom(const GenericDetails &from) {
derivedType_ = from.derivedType_;
}
for (std::size_t i{0}; i < from.specificProcs_.size(); ++i) {
- if (std::find_if(specificProcs_.begin(), specificProcs_.end(),
- [&](const Symbol &mySymbol) {
- return &mySymbol.GetUltimate() ==
- &from.specificProcs_[i]->GetUltimate();
- }) == specificProcs_.end()) {
+ if (llvm::none_of(specificProcs_, [&](const Symbol &mySymbol) {
+ return &mySymbol.GetUltimate() ==
+ &from.specificProcs_[i]->GetUltimate();
+ })) {
specificProcs_.push_back(from.specificProcs_[i]);
bindingNames_.push_back(from.bindingNames_[i]);
}
|
@llvm/pr-subscribers-flang-fir-hlfir Author: Kazu Hirata (kazutakahirata) ChangesFull diff: https://github.com/llvm/llvm-project/pull/102797.diff 4 Files Affected:
diff --git a/flang/lib/Optimizer/Transforms/ConstantArgumentGlobalisation.cpp b/flang/lib/Optimizer/Transforms/ConstantArgumentGlobalisation.cpp
index 7d0b8b3d7bc53d..1e44288c784c2a 100644
--- a/flang/lib/Optimizer/Transforms/ConstantArgumentGlobalisation.cpp
+++ b/flang/lib/Optimizer/Transforms/ConstantArgumentGlobalisation.cpp
@@ -98,9 +98,8 @@ class CallOpRewriter : public mlir::OpRewritePattern<fir::CallOp> {
assert(!builder.getNamedGlobal(globalName) &&
"We should have a unique name here");
- if (std::find_if(allocas.begin(), allocas.end(), [alloca](auto x) {
- return x.first == alloca;
- }) == allocas.end()) {
+ if (llvm::none_of(allocas,
+ [alloca](auto x) { return x.first == alloca; })) {
allocas.push_back(std::make_pair(alloca, store));
}
diff --git a/flang/lib/Semantics/data-to-inits.cpp b/flang/lib/Semantics/data-to-inits.cpp
index b6dbbbf63138ec..0f8b36de460865 100644
--- a/flang/lib/Semantics/data-to-inits.cpp
+++ b/flang/lib/Semantics/data-to-inits.cpp
@@ -522,11 +522,10 @@ static const DerivedTypeSpec *HasDefaultInitialization(const Symbol &symbol) {
} else if (!object->isDummy() && object->type()) {
if (const DerivedTypeSpec * derived{object->type()->AsDerived()}) {
DirectComponentIterator directs{*derived};
- if (std::find_if(
- directs.begin(), directs.end(), [](const Symbol &component) {
- return !IsAllocatable(component) &&
- HasDeclarationInitializer(component);
- }) != directs.end()) {
+ if (llvm::any_of(directs, [](const Symbol &component) {
+ return !IsAllocatable(component) &&
+ HasDeclarationInitializer(component);
+ })) {
return derived;
}
}
diff --git a/flang/lib/Semantics/rewrite-directives.cpp b/flang/lib/Semantics/rewrite-directives.cpp
index 2c3c87f2546a35..c94d0f3855bee3 100644
--- a/flang/lib/Semantics/rewrite-directives.cpp
+++ b/flang/lib/Semantics/rewrite-directives.cpp
@@ -88,11 +88,9 @@ bool OmpRewriteMutator::Pre(parser::OpenMPAtomicConstruct &x) {
auto findMemOrderClause =
[](const std::list<parser::OmpAtomicClause> &clauses) {
- return std::find_if(
- clauses.begin(), clauses.end(), [](const auto &clause) {
- return std::get_if<parser::OmpMemoryOrderClause>(
- &clause.u);
- }) != clauses.end();
+ return llvm::any_of(clauses, [](const auto &clause) {
+ return std::get_if<parser::OmpMemoryOrderClause>(&clause.u);
+ });
};
// Get the clause list to which the new memory order clause must be added,
diff --git a/flang/lib/Semantics/symbol.cpp b/flang/lib/Semantics/symbol.cpp
index 31e91ee7355e33..b593bf89b18bc9 100644
--- a/flang/lib/Semantics/symbol.cpp
+++ b/flang/lib/Semantics/symbol.cpp
@@ -230,11 +230,10 @@ void GenericDetails::CopyFrom(const GenericDetails &from) {
derivedType_ = from.derivedType_;
}
for (std::size_t i{0}; i < from.specificProcs_.size(); ++i) {
- if (std::find_if(specificProcs_.begin(), specificProcs_.end(),
- [&](const Symbol &mySymbol) {
- return &mySymbol.GetUltimate() ==
- &from.specificProcs_[i]->GetUltimate();
- }) == specificProcs_.end()) {
+ if (llvm::none_of(specificProcs_, [&](const Symbol &mySymbol) {
+ return &mySymbol.GetUltimate() ==
+ &from.specificProcs_[i]->GetUltimate();
+ })) {
specificProcs_.push_back(from.specificProcs_[i]);
bindingNames_.push_back(from.bindingNames_[i]);
}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this a good change? Replacing standard C++ with local idioms doesn't improve readability.
The change avoids repeating the same container names multiple times. Your comment about the local idiom is well taken, but we can also look at it as using |
No description provided.