[flang-commits] [flang] [Flang] Switch to common::visit more call sites (PR #90018)
via flang-commits
flang-commits at lists.llvm.org
Wed Apr 24 23:09:57 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics
Author: Alexander Shaposhnikov (alexander-shaposhnikov)
<details>
<summary>Changes</summary>
Switch to common::visit more call sites + git clang-format --style=llvm.
Test plan: ninja check-all
---
Patch is 88.36 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/90018.diff
29 Files Affected:
- (modified) flang/include/flang/Evaluate/tools.h (+2-2)
- (modified) flang/include/flang/Lower/DumpEvaluateExpr.h (+1-1)
- (modified) flang/include/flang/Lower/PFTBuilder.h (+4-3)
- (modified) flang/include/flang/Lower/Support/Utils.h (+24-16)
- (modified) flang/include/flang/Optimizer/Support/Matcher.h (+3-2)
- (modified) flang/lib/Evaluate/intrinsics.cpp (+1-1)
- (modified) flang/lib/Lower/Allocatable.cpp (+12-11)
- (modified) flang/lib/Lower/Bridge.cpp (+67-62)
- (modified) flang/lib/Lower/CallInterface.cpp (+3-3)
- (modified) flang/lib/Lower/ComponentPath.cpp (+1-1)
- (modified) flang/lib/Lower/ConvertArrayConstructor.cpp (+19-18)
- (modified) flang/lib/Lower/ConvertCall.cpp (+2-1)
- (modified) flang/lib/Lower/ConvertConstant.cpp (+4-4)
- (modified) flang/lib/Lower/ConvertExpr.cpp (+85-70)
- (modified) flang/lib/Lower/ConvertExprToHLFIR.cpp (+12-11)
- (modified) flang/lib/Lower/ConvertType.cpp (+1-1)
- (modified) flang/lib/Lower/DirectivesCommon.h (+4-4)
- (modified) flang/lib/Lower/IO.cpp (+8-8)
- (modified) flang/lib/Lower/IterationSpace.cpp (+20-19)
- (modified) flang/lib/Lower/Mangler.cpp (+1-1)
- (modified) flang/lib/Lower/OpenACC.cpp (+21-20)
- (modified) flang/lib/Lower/OpenMP/Clauses.cpp (+12-12)
- (modified) flang/lib/Lower/OpenMP/OpenMP.cpp (+6-6)
- (modified) flang/lib/Lower/OpenMP/Utils.cpp (+1-1)
- (modified) flang/lib/Lower/PFTBuilder.cpp (+26-25)
- (modified) flang/lib/Lower/VectorSubscripts.cpp (+48-47)
- (modified) flang/lib/Optimizer/Builder/IntrinsicCall.cpp (+3-3)
- (modified) flang/lib/Semantics/check-acc-structure.cpp (+2-2)
- (modified) flang/lib/Semantics/check-coarray.cpp (+1-1)
``````````diff
diff --git a/flang/include/flang/Evaluate/tools.h b/flang/include/flang/Evaluate/tools.h
index ca14c144af2d60..ea355e886bd40a 100644
--- a/flang/include/flang/Evaluate/tools.h
+++ b/flang/include/flang/Evaluate/tools.h
@@ -448,12 +448,12 @@ struct ExtractSubstringHelper {
template <typename T>
static std::optional<Substring> visit(const Designator<T> &e) {
- return std::visit([](auto &&s) { return visit(s); }, e.u);
+ return Fortran::common::visit([](auto &&s) { return visit(s); }, e.u);
}
template <typename T>
static std::optional<Substring> visit(const Expr<T> &e) {
- return std::visit([](auto &&s) { return visit(s); }, e.u);
+ return Fortran::common::visit([](auto &&s) { return visit(s); }, e.u);
}
};
diff --git a/flang/include/flang/Lower/DumpEvaluateExpr.h b/flang/include/flang/Lower/DumpEvaluateExpr.h
index c67df245359e36..88f53e96a81c29 100644
--- a/flang/include/flang/Lower/DumpEvaluateExpr.h
+++ b/flang/include/flang/Lower/DumpEvaluateExpr.h
@@ -68,7 +68,7 @@ class DumpEvaluateExpr {
}
template <typename... A>
void show(const std::variant<A...> &u) {
- std::visit([&](const auto &v) { show(v); }, u);
+ Fortran::common::visit([&](const auto &v) { show(v); }, u);
}
template <typename A>
void show(const std::vector<A> &x) {
diff --git a/flang/include/flang/Lower/PFTBuilder.h b/flang/include/flang/Lower/PFTBuilder.h
index 9913f584133faa..ad8df259c8ff7e 100644
--- a/flang/include/flang/Lower/PFTBuilder.h
+++ b/flang/include/flang/Lower/PFTBuilder.h
@@ -73,7 +73,7 @@ class ReferenceVariantBase {
}
template <typename VISITOR>
constexpr auto visit(VISITOR &&visitor) const {
- return std::visit(
+ return Fortran::common::visit(
common::visitors{[&visitor](auto ref) { return visitor(ref.get()); }},
u);
}
@@ -489,7 +489,8 @@ struct Variable {
/// Is this variable a global?
bool isGlobal() const {
- return std::visit([](const auto &x) { return x.isGlobal(); }, var);
+ return Fortran::common::visit([](const auto &x) { return x.isGlobal(); },
+ var);
}
/// Is this a module or submodule variable?
@@ -499,7 +500,7 @@ struct Variable {
}
const Fortran::semantics::Scope *getOwningScope() const {
- return std::visit(
+ return Fortran::common::visit(
common::visitors{
[](const Nominal &x) { return &x.symbol->GetUltimate().owner(); },
[](const AggregateStore &agg) { return &agg.getOwningScope(); }},
diff --git a/flang/include/flang/Lower/Support/Utils.h b/flang/include/flang/Lower/Support/Utils.h
index 64641ab4b6ca13..6722c52575dcaf 100644
--- a/flang/include/flang/Lower/Support/Utils.h
+++ b/flang/include/flang/Lower/Support/Utils.h
@@ -69,7 +69,8 @@ static Fortran::lower::SomeExpr ignoreEvConvert(const A &x) {
inline Fortran::lower::SomeExpr
ignoreEvConvert(const Fortran::evaluate::Expr<Fortran::evaluate::Type<
Fortran::common::TypeCategory::Integer, 8>> &x) {
- return std::visit([](const auto &v) { return ignoreEvConvert(v); }, x.u);
+ return Fortran::common::visit(
+ [](const auto &v) { return ignoreEvConvert(v); }, x.u);
}
/// Zip two containers of the same size together and flatten the pairs. `flatZip
@@ -119,7 +120,8 @@ class HashEvaluateExpr {
return 0u;
}
static unsigned getHashValue(const Fortran::evaluate::Subscript &x) {
- return std::visit([&](const auto &v) { return getHashValue(v); }, x.u);
+ return Fortran::common::visit(
+ [&](const auto &v) { return getHashValue(v); }, x.u);
}
static unsigned getHashValue(const Fortran::evaluate::Triplet &x) {
return getHashValue(x.lower()) - getHashValue(x.upper()) * 5u -
@@ -154,7 +156,8 @@ class HashEvaluateExpr {
return getHashValue(x.GetComponent()) * 13u;
}
static unsigned getHashValue(const Fortran::evaluate::DataRef &x) {
- return std::visit([&](const auto &v) { return getHashValue(v); }, x.u);
+ return Fortran::common::visit(
+ [&](const auto &v) { return getHashValue(v); }, x.u);
}
static unsigned getHashValue(const Fortran::evaluate::ComplexPart &x) {
return getHashValue(x.complex()) - static_cast<unsigned>(x.part());
@@ -247,8 +250,9 @@ class HashEvaluateExpr {
return getHashValue(sym.get());
}
static unsigned getHashValue(const Fortran::evaluate::Substring &x) {
- return 61u * std::visit([&](const auto &p) { return getHashValue(p); },
- x.parent()) -
+ return 61u *
+ Fortran::common::visit(
+ [&](const auto &p) { return getHashValue(p); }, x.parent()) -
getHashValue(x.lower()) - (getHashValue(x.lower()) + 1u);
}
static unsigned
@@ -270,7 +274,8 @@ class HashEvaluateExpr {
}
static unsigned
getHashValue(const Fortran::evaluate::ProcedureDesignator &x) {
- return std::visit([&](const auto &v) { return getHashValue(v); }, x.u);
+ return Fortran::common::visit(
+ [&](const auto &v) { return getHashValue(v); }, x.u);
}
static unsigned getHashValue(const Fortran::evaluate::ProcedureRef &x) {
unsigned args = 13u;
@@ -321,15 +326,18 @@ class HashEvaluateExpr {
}
template <typename A>
static unsigned getHashValue(const Fortran::evaluate::Expr<A> &x) {
- return std::visit([&](const auto &v) { return getHashValue(v); }, x.u);
+ return Fortran::common::visit(
+ [&](const auto &v) { return getHashValue(v); }, x.u);
}
static unsigned getHashValue(
const Fortran::evaluate::Relational<Fortran::evaluate::SomeType> &x) {
- return std::visit([&](const auto &v) { return getHashValue(v); }, x.u);
+ return Fortran::common::visit(
+ [&](const auto &v) { return getHashValue(v); }, x.u);
}
template <typename A>
static unsigned getHashValue(const Fortran::evaluate::Designator<A> &x) {
- return std::visit([&](const auto &v) { return getHashValue(v); }, x.u);
+ return Fortran::common::visit(
+ [&](const auto &v) { return getHashValue(v); }, x.u);
}
template <int BITS>
static unsigned
@@ -378,7 +386,7 @@ class IsEqualEvaluateExpr {
}
static bool isEqual(const Fortran::evaluate::Subscript &x,
const Fortran::evaluate::Subscript &y) {
- return std::visit(
+ return Fortran::common::visit(
[&](const auto &v, const auto &w) { return isEqual(v, w); }, x.u, y.u);
}
static bool isEqual(const Fortran::evaluate::Triplet &x,
@@ -411,7 +419,7 @@ class IsEqualEvaluateExpr {
}
static bool isEqual(const Fortran::evaluate::DataRef &x,
const Fortran::evaluate::DataRef &y) {
- return std::visit(
+ return Fortran::common::visit(
[&](const auto &v, const auto &w) { return isEqual(v, w); }, x.u, y.u);
}
static bool isEqual(const Fortran::evaluate::ComplexPart &x,
@@ -499,7 +507,7 @@ class IsEqualEvaluateExpr {
}
static bool isEqual(const Fortran::evaluate::Substring &x,
const Fortran::evaluate::Substring &y) {
- return std::visit(
+ return Fortran::common::visit(
[&](const auto &p, const auto &q) { return isEqual(p, q); },
x.parent(), y.parent()) &&
isEqual(x.lower(), y.lower()) && isEqual(x.lower(), y.lower());
@@ -529,7 +537,7 @@ class IsEqualEvaluateExpr {
}
static bool isEqual(const Fortran::evaluate::ProcedureDesignator &x,
const Fortran::evaluate::ProcedureDesignator &y) {
- return std::visit(
+ return Fortran::common::visit(
[&](const auto &v, const auto &w) { return isEqual(v, w); }, x.u, y.u);
}
static bool isEqual(const Fortran::evaluate::ProcedureRef &x,
@@ -591,19 +599,19 @@ class IsEqualEvaluateExpr {
template <typename A>
static bool isEqual(const Fortran::evaluate::Expr<A> &x,
const Fortran::evaluate::Expr<A> &y) {
- return std::visit(
+ return Fortran::common::visit(
[&](const auto &v, const auto &w) { return isEqual(v, w); }, x.u, y.u);
}
static bool
isEqual(const Fortran::evaluate::Relational<Fortran::evaluate::SomeType> &x,
const Fortran::evaluate::Relational<Fortran::evaluate::SomeType> &y) {
- return std::visit(
+ return Fortran::common::visit(
[&](const auto &v, const auto &w) { return isEqual(v, w); }, x.u, y.u);
}
template <typename A>
static bool isEqual(const Fortran::evaluate::Designator<A> &x,
const Fortran::evaluate::Designator<A> &y) {
- return std::visit(
+ return Fortran::common::visit(
[&](const auto &v, const auto &w) { return isEqual(v, w); }, x.u, y.u);
}
template <int BITS>
diff --git a/flang/include/flang/Optimizer/Support/Matcher.h b/flang/include/flang/Optimizer/Support/Matcher.h
index da1d7c21f42c4a..44672d3c0a0725 100644
--- a/flang/include/flang/Optimizer/Support/Matcher.h
+++ b/flang/include/flang/Optimizer/Support/Matcher.h
@@ -13,6 +13,7 @@
#ifndef FORTRAN_OPTIMIZER_SUPPORT_MATCHER_H
#define FORTRAN_OPTIMIZER_SUPPORT_MATCHER_H
+#include "flang/Common/idioms.h"
#include <variant>
// Boilerplate CRTP class for a simplified type-casing syntactic sugar. This
@@ -23,10 +24,10 @@ template<class... Ts> struct matches : Ts... { using Ts::operator()...; };
template<class... Ts> matches(Ts...) -> matches<Ts...>;
template<typename N> struct matcher {
template<typename... Ts> auto match(Ts... ts) {
- return std::visit(matches{ts...}, static_cast<N*>(this)->matchee());
+ return Fortran::common::visit(matches{ts...}, static_cast<N*>(this)->matchee());
}
template<typename... Ts> auto match(Ts... ts) const {
- return std::visit(matches{ts...}, static_cast<N const*>(this)->matchee());
+ return Fortran::common::visit(matches{ts...}, static_cast<N const*>(this)->matchee());
}
};
// clang-format on
diff --git a/flang/lib/Evaluate/intrinsics.cpp b/flang/lib/Evaluate/intrinsics.cpp
index 1b73cadb682d98..a80ee0ca6f010b 100644
--- a/flang/lib/Evaluate/intrinsics.cpp
+++ b/flang/lib/Evaluate/intrinsics.cpp
@@ -2879,7 +2879,7 @@ static bool CheckForNonPositiveValues(FoldingContext &context,
if (arg.Rank() > 0) {
if (const Expr<SomeType> *expr{arg.UnwrapExpr()}) {
if (const auto *intExpr{std::get_if<Expr<SomeInteger>>(&expr->u)}) {
- std::visit(
+ Fortran::common::visit(
[&](const auto &kindExpr) {
using IntType = typename std::decay_t<decltype(kindExpr)>::Result;
if (const auto *constArray{
diff --git a/flang/lib/Lower/Allocatable.cpp b/flang/lib/Lower/Allocatable.cpp
index 8e84ea2fc5d522..3ca70f7066db20 100644
--- a/flang/lib/Lower/Allocatable.cpp
+++ b/flang/lib/Lower/Allocatable.cpp
@@ -349,10 +349,10 @@ class AllocateStmtHelper {
void visitAllocateOptions() {
for (const auto &allocOption :
std::get<std::list<Fortran::parser::AllocOpt>>(stmt.t))
- std::visit(
+ Fortran::common::visit(
Fortran::common::visitors{
[&](const Fortran::parser::StatOrErrmsg &statOrErr) {
- std::visit(
+ Fortran::common::visit(
Fortran::common::visitors{
[&](const Fortran::parser::StatVariable &statVar) {
statExpr = Fortran::semantics::GetExpr(statVar);
@@ -897,15 +897,16 @@ void Fortran::lower::genDeallocateStmt(
const Fortran::lower::SomeExpr *errMsgExpr = nullptr;
for (const Fortran::parser::StatOrErrmsg &statOrErr :
std::get<std::list<Fortran::parser::StatOrErrmsg>>(stmt.t))
- std::visit(Fortran::common::visitors{
- [&](const Fortran::parser::StatVariable &statVar) {
- statExpr = Fortran::semantics::GetExpr(statVar);
- },
- [&](const Fortran::parser::MsgVariable &errMsgVar) {
- errMsgExpr = Fortran::semantics::GetExpr(errMsgVar);
- },
- },
- statOrErr.u);
+ Fortran::common::visit(
+ Fortran::common::visitors{
+ [&](const Fortran::parser::StatVariable &statVar) {
+ statExpr = Fortran::semantics::GetExpr(statVar);
+ },
+ [&](const Fortran::parser::MsgVariable &errMsgVar) {
+ errMsgExpr = Fortran::semantics::GetExpr(errMsgVar);
+ },
+ },
+ statOrErr.u);
ErrorManager errorManager;
errorManager.init(converter, loc, statExpr, errMsgExpr);
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp
index 8b62fe8c022f80..8426bfdc198dbf 100644
--- a/flang/lib/Lower/Bridge.cpp
+++ b/flang/lib/Lower/Bridge.cpp
@@ -293,28 +293,29 @@ class FirConverter : public Fortran::lower::AbstractConverter {
bool hasMainProgram = false;
const Fortran::semantics::Symbol *globalOmpRequiresSymbol = nullptr;
for (Fortran::lower::pft::Program::Units &u : pft.getUnits()) {
- std::visit(Fortran::common::visitors{
- [&](Fortran::lower::pft::FunctionLikeUnit &f) {
- if (f.isMainProgram())
- hasMainProgram = true;
- declareFunction(f);
- if (!globalOmpRequiresSymbol)
- globalOmpRequiresSymbol = f.getScope().symbol();
- },
- [&](Fortran::lower::pft::ModuleLikeUnit &m) {
- lowerModuleDeclScope(m);
- for (Fortran::lower::pft::FunctionLikeUnit &f :
- m.nestedFunctions)
- declareFunction(f);
- },
- [&](Fortran::lower::pft::BlockDataUnit &b) {
- if (!globalOmpRequiresSymbol)
- globalOmpRequiresSymbol = b.symTab.symbol();
- },
- [&](Fortran::lower::pft::CompilerDirectiveUnit &d) {},
- [&](Fortran::lower::pft::OpenACCDirectiveUnit &d) {},
- },
- u);
+ Fortran::common::visit(
+ Fortran::common::visitors{
+ [&](Fortran::lower::pft::FunctionLikeUnit &f) {
+ if (f.isMainProgram())
+ hasMainProgram = true;
+ declareFunction(f);
+ if (!globalOmpRequiresSymbol)
+ globalOmpRequiresSymbol = f.getScope().symbol();
+ },
+ [&](Fortran::lower::pft::ModuleLikeUnit &m) {
+ lowerModuleDeclScope(m);
+ for (Fortran::lower::pft::FunctionLikeUnit &f :
+ m.nestedFunctions)
+ declareFunction(f);
+ },
+ [&](Fortran::lower::pft::BlockDataUnit &b) {
+ if (!globalOmpRequiresSymbol)
+ globalOmpRequiresSymbol = b.symTab.symbol();
+ },
+ [&](Fortran::lower::pft::CompilerDirectiveUnit &d) {},
+ [&](Fortran::lower::pft::OpenACCDirectiveUnit &d) {},
+ },
+ u);
}
// Create definitions of intrinsic module constants.
@@ -323,7 +324,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
// Primary translation pass.
for (Fortran::lower::pft::Program::Units &u : pft.getUnits()) {
- std::visit(
+ Fortran::common::visit(
Fortran::common::visitors{
[&](Fortran::lower::pft::FunctionLikeUnit &f) { lowerFunc(f); },
[&](Fortran::lower::pft::ModuleLikeUnit &m) { lowerMod(m); },
@@ -2266,7 +2267,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
}
void genFIR(const Fortran::parser::ForallAssignmentStmt &stmt) {
- std::visit([&](const auto &x) { genFIR(x); }, stmt.u);
+ Fortran::common::visit([&](const auto &x) { genFIR(x); }, stmt.u);
}
void genFIR(const Fortran::parser::EndForallStmt &) {
@@ -2327,7 +2328,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
forall.t));
for (const Fortran::parser::ForallBodyConstruct &s :
std::get<std::list<Fortran::parser::ForallBodyConstruct>>(forall.t)) {
- std::visit(
+ Fortran::common::visit(
Fortran::common::visitors{
[&](const Fortran::parser::WhereConstruct &b) { genFIR(b); },
[&](const Fortran::common::Indirection<
@@ -3252,7 +3253,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
Fortran::parser::Label errLabel{};
bool hasIostat{};
for (const auto &spec : specList) {
- std::visit(
+ Fortran::common::visit(
Fortran::common::visitors{
[&](const Fortran::parser::EndLabel &label) {
endLabel = label.v;
@@ -3949,7 +3950,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
void genAssignment(const Fortran::evaluate::Assignment &assign) {
mlir::Location loc = toLocation();
if (lowerToHighLevelFIR()) {
- std::visit(
+ Fortran::common::visit(
Fortran::common::visitors{
[&](const Fortran::evaluate::Assignment::Intrinsic &) {
genDataAssignment(assign, /*userDefinedAssignment=*/nullptr);
@@ -3977,7 +3978,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
explicitIterSpace.genLoopNest();
}
Fortran::lower::StatementContext stmtCtx;
- std::visit(
+ Fortran::common::visit(
Fortran::common::visitors{
// [1] Plain old assignment.
[&](const Fortran::evaluate::Assignment::Intrinsic &) {
@@ -4246,7 +4247,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
}
}
void genFIR(const Fortran::parser::WhereBodyConstruct &body) {
- std::visit(
+ Fortran::common::visit(
Fortran::common::visitors{
[&](const Fortran::parser::Statement<
Fortran::parser::AssignmentStmt> &stmt) {
@@ -4965,18 +4966,19 @@ class FirConverter : public Fortran::lower::AbstractConverter {
// The intrinsic module scope, if present, is the first scope.
const Fortran::semantics::Scope *intrinsicModuleScope = nullptr;
for (Fortran::lower::pft::Program::Units &u : pft.getUnits()) {
- std::visit(Fortran::common::visitors{
- [&](Fortran::lower::pft::FunctionLikeUnit &f) {
- intrinsicModuleScope = &f.getScope().parent();
- },
- [&](Fortran::lower::pft::ModuleLikeUnit &m) {
- intrinsicModuleScope = &m.getScope().parent();
- },
- [&](Fortran::lower::pft::BlockDataUnit &b) {},
- [&](Fortran::lower::pft::CompilerDirectiveUnit &d) {},
- [&](Fortran::lower::pft::OpenACCDirectiveUnit &d) {},
- },
- u);
+ Fortran::common::visit(
+ Fortran::common::visitors{
+ [&](Fortran::lower::pft::FunctionLikeUnit &f) {
+ intrinsicModuleScope = &f.getScope().parent();
+ },
+ [&](Fortran::lower::pft::ModuleLikeUnit &m) {
+ intrinsicModuleScope = &m.getScope().parent();
+ },
+ [&](Fortran::lower::pft::BlockDataUnit &b) {},
+ [&](Fortran::lower::pft::CompilerDirectiveUnit &d) {},
+ [&](Fortran::lower::pft::OpenACCDirectiveUnit &d) {},
+ },
+ u);
if (intrinsicModuleScope) {
while (!intrinsicModuleScope->IsGlobal())
intrinsicModuleScope = &intrinsicModuleScope->parent();
@@ -5108,7 +5110,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
analyzeExplicitSpace</*LHS=*/true>(lhs);
analyzeExplicitSpace(rhs);
};
- std::visit(
+ Fortran::common::visit(
Fortran::common::visitors{
[&](const Fortran::evaluate::ProcedureRef &procRef) {
// Ensure the procRef expressions are the one being visited.
@@ -5126,7 +5128,8 @@ class FirConverter : public Fortran::lower::AbstractConverter {
explicitIterSpace.endAssign();
}
void analyzeExplicitSpace(const Fortran::parser::ForallAssignmentStmt &stmt) {
- std::visit([&](const auto &s) { analyzeExplicitSpace(s); }, stmt.u);
+ Fortran::common::visit([&](const...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/90018
More information about the flang-commits
mailing list