[flang-commits] [flang] [Flang] Switch to common::visit more call sites (PR #90018)
Alexander Shaposhnikov via flang-commits
flang-commits at lists.llvm.org
Mon Jun 17 12:52:48 PDT 2024
https://github.com/alexander-shaposhnikov updated https://github.com/llvm/llvm-project/pull/90018
>From 9eae545facce8a29c5819231e74198b5f9d89d02 Mon Sep 17 00:00:00 2001
From: Alexander Shaposhnikov <ashaposhnikov at google.com>
Date: Thu, 25 Apr 2024 06:07:20 +0000
Subject: [PATCH] [Flang] Switch to common::visit more call sites
---
flang/include/flang/Evaluate/tools.h | 4 +-
flang/include/flang/Lower/DumpEvaluateExpr.h | 2 +-
flang/include/flang/Lower/PFTBuilder.h | 7 +-
flang/include/flang/Lower/Support/Utils.h | 40 +++--
.../include/flang/Optimizer/Support/Matcher.h | 5 +-
flang/lib/Evaluate/intrinsics.cpp | 2 +-
flang/lib/Lower/Allocatable.cpp | 23 +--
flang/lib/Lower/Bridge.cpp | 98 +++++------
flang/lib/Lower/CallInterface.cpp | 6 +-
flang/lib/Lower/ComponentPath.cpp | 2 +-
flang/lib/Lower/ConvertArrayConstructor.cpp | 37 +++--
flang/lib/Lower/ConvertCall.cpp | 3 +-
flang/lib/Lower/ConvertConstant.cpp | 8 +-
flang/lib/Lower/ConvertExpr.cpp | 155 ++++++++++--------
flang/lib/Lower/ConvertExprToHLFIR.cpp | 23 +--
flang/lib/Lower/ConvertType.cpp | 2 +-
flang/lib/Lower/DirectivesCommon.h | 8 +-
flang/lib/Lower/IO.cpp | 16 +-
flang/lib/Lower/IterationSpace.cpp | 39 ++---
flang/lib/Lower/Mangler.cpp | 2 +-
flang/lib/Lower/OpenACC.cpp | 41 ++---
flang/lib/Lower/OpenMP/Clauses.cpp | 24 +--
flang/lib/Lower/OpenMP/OpenMP.cpp | 27 +--
flang/lib/Lower/OpenMP/Utils.cpp | 2 +-
flang/lib/Lower/PFTBuilder.cpp | 51 +++---
flang/lib/Lower/VectorSubscripts.cpp | 95 +++++------
flang/lib/Optimizer/Builder/IntrinsicCall.cpp | 6 +-
flang/lib/Semantics/check-acc-structure.cpp | 14 +-
flang/lib/Semantics/check-coarray.cpp | 2 +-
29 files changed, 391 insertions(+), 353 deletions(-)
diff --git a/flang/include/flang/Evaluate/tools.h b/flang/include/flang/Evaluate/tools.h
index 378a5fca03264..ea56a20633f0c 100644
--- a/flang/include/flang/Evaluate/tools.h
+++ b/flang/include/flang/Evaluate/tools.h
@@ -450,12 +450,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 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 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 c67df245359e3..88f53e96a81c2 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 c2b600c6b5d9b..7f1b93c564b4c 100644
--- a/flang/include/flang/Lower/PFTBuilder.h
+++ b/flang/include/flang/Lower/PFTBuilder.h
@@ -76,7 +76,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);
}
@@ -494,7 +494,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?
@@ -504,7 +505,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 e791f3dbb221a..1cc74521e22d8 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.upper(), y.upper());
@@ -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 da1d7c21f42c4..44672d3c0a072 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 ace316174a892..1bba541e8e14a 100644
--- a/flang/lib/Evaluate/intrinsics.cpp
+++ b/flang/lib/Evaluate/intrinsics.cpp
@@ -2936,7 +2936,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 068f5d25967c9..77e02898ac9fb 100644
--- a/flang/lib/Lower/Allocatable.cpp
+++ b/flang/lib/Lower/Allocatable.cpp
@@ -350,10 +350,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);
@@ -898,15 +898,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 c73d43210a260..01023bae617f2 100644
--- a/flang/lib/Lower/Bridge.cpp
+++ b/flang/lib/Lower/Bridge.cpp
@@ -302,7 +302,7 @@ 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::visit(
Fortran::common::visitors{
[&](Fortran::lower::pft::FunctionLikeUnit &f) {
if (f.isMainProgram())
@@ -336,7 +336,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); },
@@ -2060,7 +2060,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
handleLocalitySpecs(info);
for (const auto *dir : dirs) {
- std::visit(
+ Fortran::common::visit(
Fortran::common::visitors{
[&](const Fortran::parser::CompilerDirective::VectorAlways
&d) { addLoopAnnotationAttr(info); },
@@ -2431,7 +2431,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 &) {
@@ -2492,7 +2492,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<
@@ -2615,7 +2615,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
void genFIR(const Fortran::parser::CompilerDirective &dir) {
Fortran::lower::pft::Evaluation &eval = getEval();
- std::visit(
+ Fortran::common::visit(
Fortran::common::visitors{
[&](const Fortran::parser::CompilerDirective::VectorAlways &) {
attachDirectiveToLoop(dir, &eval);
@@ -3196,7 +3196,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
const auto &rank = std::get<Fortran::parser::SelectRankCaseStmt::Rank>(
rankCaseStmt->t);
assert(e->block && "missing SelectRankCaseStmt block");
- std::visit(
+ Fortran::common::visit(
Fortran::common::visitors{
[&](const Fortran::parser::ScalarIntConstantExpr &rankExpr) {
blockList.emplace_back(e->block);
@@ -3227,9 +3227,9 @@ class FirConverter : public Fortran::lower::AbstractConverter {
"selector should not yet be set");
Fortran::lower::StatementContext &stmtCtx =
activeConstructStack.back().stmtCtx;
- const Fortran::lower::SomeExpr *selectorExpr =
- std::visit([](const auto &x) { return Fortran::semantics::GetExpr(x); },
- std::get<Fortran::parser::Selector>(selectRankStmt.t).u);
+ const Fortran::lower::SomeExpr *selectorExpr = Fortran::common::visit(
+ [](const auto &x) { return Fortran::semantics::GetExpr(x); },
+ std::get<Fortran::parser::Selector>(selectRankStmt.t).u);
assert(selectorExpr && "failed to retrieve selector expr");
hlfir::Entity selector = Fortran::lower::convertExprToHLFIR(
loc, *this, *selectorExpr, localSymbols, stmtCtx);
@@ -3661,7 +3661,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;
@@ -4371,7 +4371,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);
@@ -4399,7 +4399,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 &) {
@@ -4668,7 +4668,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) {
@@ -5384,18 +5384,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();
@@ -5529,7 +5530,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.
@@ -5547,7 +5548,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 auto &s) { analyzeExplicitSpace(s); },
+ stmt.u);
}
void analyzeExplicitSpace(const Fortran::parser::AssignmentStmt &s) {
analyzeExplicitSpace(s.typedAssignment->v.operator->());
@@ -5592,13 +5594,14 @@ class FirConverter : public Fortran::lower::AbstractConverter {
analyzeExplicitSpace(e);
}
void analyzeExplicitSpace(const Fortran::parser::WhereBodyConstruct &body) {
- std::visit(Fortran::common::visitors{
- [&](const Fortran::common::Indirection<
- Fortran::parser::WhereConstruct> &wc) {
- analyzeExplicitSpace(wc.value());
- },
- [&](const auto &s) { analyzeExplicitSpace(s.statement); }},
- body.u);
+ Fortran::common::visit(
+ Fortran::common::visitors{
+ [&](const Fortran::common::Indirection<
+ Fortran::parser::WhereConstruct> &wc) {
+ analyzeExplicitSpace(wc.value());
+ },
+ [&](const auto &s) { analyzeExplicitSpace(s.statement); }},
+ body.u);
}
void analyzeExplicitSpace(const Fortran::parser::MaskedElsewhereStmt &stmt) {
const Fortran::lower::SomeExpr *exp = Fortran::semantics::GetExpr(
@@ -5649,16 +5652,17 @@ class FirConverter : public Fortran::lower::AbstractConverter {
.statement);
for (const Fortran::parser::ForallBodyConstruct &s :
std::get<std::list<Fortran::parser::ForallBodyConstruct>>(forall.t)) {
- std::visit(Fortran::common::visitors{
- [&](const Fortran::common::Indirection<
- Fortran::parser::ForallConstruct> &b) {
- analyzeExplicitSpace(b.value());
- },
- [&](const Fortran::parser::WhereConstruct &w) {
- analyzeExplicitSpace(w);
- },
- [&](const auto &b) { analyzeExplicitSpace(b.statement); }},
- s.u);
+ Fortran::common::visit(
+ Fortran::common::visitors{
+ [&](const Fortran::common::Indirection<
+ Fortran::parser::ForallConstruct> &b) {
+ analyzeExplicitSpace(b.value());
+ },
+ [&](const Fortran::parser::WhereConstruct &w) {
+ analyzeExplicitSpace(w);
+ },
+ [&](const auto &b) { analyzeExplicitSpace(b.statement); }},
+ s.u);
}
analyzeExplicitSpacePop();
}
@@ -5713,7 +5717,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
std::string getConstantExprManglePrefix(mlir::Location loc,
const Fortran::lower::SomeExpr &expr,
mlir::Type eleTy) {
- return std::visit(
+ return Fortran::common::visit(
[&](const auto &x) -> std::string {
using T = std::decay_t<decltype(x)>;
if constexpr (Fortran::common::HasMember<
@@ -5728,7 +5732,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
fir::emitFatalError(loc,
"non a constant derived type expression");
} else {
- return std::visit(
+ return Fortran::common::visit(
[&](const auto &someKind) -> std::string {
using T = std::decay_t<decltype(someKind)>;
using TK = Fortran::evaluate::Type<T::Result::category,
diff --git a/flang/lib/Lower/CallInterface.cpp b/flang/lib/Lower/CallInterface.cpp
index 5f1d69c1de7ac..75a86273250d1 100644
--- a/flang/lib/Lower/CallInterface.cpp
+++ b/flang/lib/Lower/CallInterface.cpp
@@ -187,7 +187,7 @@ asImplicitArg(Fortran::evaluate::characteristics::DummyDataObject &&dummy) {
static Fortran::evaluate::characteristics::DummyArgument
asImplicitArg(Fortran::evaluate::characteristics::DummyArgument &&dummy) {
- return std::visit(
+ return Fortran::common::visit(
Fortran::common::visitors{
[&](Fortran::evaluate::characteristics::DummyDataObject &obj) {
return Fortran::evaluate::characteristics::DummyArgument(
@@ -843,7 +843,7 @@ class Fortran::lower::CallInterfaceImpl {
for (auto pair : llvm::zip(procedure.dummyArguments, argumentEntities)) {
const Fortran::evaluate::characteristics::DummyArgument
&argCharacteristics = std::get<0>(pair);
- std::visit(
+ Fortran::common::visit(
Fortran::common::visitors{
[&](const auto &dummy) {
const auto &entity = getDataObjectEntity(std::get<1>(pair));
@@ -877,7 +877,7 @@ class Fortran::lower::CallInterfaceImpl {
for (auto pair : llvm::zip(procedure.dummyArguments, argumentEntities)) {
const Fortran::evaluate::characteristics::DummyArgument
&argCharacteristics = std::get<0>(pair);
- std::visit(
+ Fortran::common::visit(
Fortran::common::visitors{
[&](const Fortran::evaluate::characteristics::DummyDataObject
&dummy) {
diff --git a/flang/lib/Lower/ComponentPath.cpp b/flang/lib/Lower/ComponentPath.cpp
index d20ea23153102..5bdbca6062e6d 100644
--- a/flang/lib/Lower/ComponentPath.cpp
+++ b/flang/lib/Lower/ComponentPath.cpp
@@ -36,7 +36,7 @@ void Fortran::lower::ComponentPath::clear() {
bool Fortran::lower::isRankedArrayAccess(const Fortran::evaluate::ArrayRef &x) {
for (const Fortran::evaluate::Subscript &sub : x.subscript()) {
- if (std::visit(
+ if (Fortran::common::visit(
Fortran::common::visitors{
[&](const Fortran::evaluate::Triplet &) { return true; },
[&](const Fortran::evaluate::IndirectSubscriptIntegerExpr &e) {
diff --git a/flang/lib/Lower/ConvertArrayConstructor.cpp b/flang/lib/Lower/ConvertArrayConstructor.cpp
index 341fad9a5e43c..3c43cd20eb080 100644
--- a/flang/lib/Lower/ConvertArrayConstructor.cpp
+++ b/flang/lib/Lower/ConvertArrayConstructor.cpp
@@ -438,7 +438,7 @@ class ArrayCtorLoweringStrategy {
void pushValue(mlir::Location loc, fir::FirOpBuilder &builder,
hlfir::Entity value) {
- return std::visit(
+ return Fortran::common::visit(
[&](auto &impl) { return impl.pushValue(loc, builder, value); },
implVariant);
}
@@ -446,7 +446,7 @@ class ArrayCtorLoweringStrategy {
mlir::Value startImpliedDo(mlir::Location loc, fir::FirOpBuilder &builder,
mlir::Value lower, mlir::Value upper,
mlir::Value stride) {
- return std::visit(
+ return Fortran::common::visit(
[&](auto &impl) {
return impl.startImpliedDo(loc, builder, lower, upper, stride);
},
@@ -455,13 +455,13 @@ class ArrayCtorLoweringStrategy {
hlfir::Entity finishArrayCtorLowering(mlir::Location loc,
fir::FirOpBuilder &builder) {
- return std::visit(
+ return Fortran::common::visit(
[&](auto &impl) { return impl.finishArrayCtorLowering(loc, builder); },
implVariant);
}
void startImpliedDoScope(llvm::StringRef doName, mlir::Value indexValue) {
- std::visit(
+ Fortran::common::visit(
[&](auto &impl) {
return impl.startImpliedDoScope(doName, indexValue);
},
@@ -469,8 +469,8 @@ class ArrayCtorLoweringStrategy {
}
void endImpliedDoScope() {
- std::visit([&](auto &impl) { return impl.endImpliedDoScope(); },
- implVariant);
+ Fortran::common::visit([&](auto &impl) { return impl.endImpliedDoScope(); },
+ implVariant);
}
private:
@@ -612,16 +612,17 @@ ArrayCtorAnalysis::ArrayCtorAnalysis(
arrayValueListStack.pop_back_val();
for (const Fortran::evaluate::ArrayConstructorValue<T> &acValue :
*currentArrayValueList)
- std::visit(Fortran::common::visitors{
- [&](const Fortran::evaluate::ImpliedDo<T> &impledDo) {
- arrayValueListStack.push_back(&impledDo.values());
- localNumberOfImpliedDo++;
- },
- [&](const Fortran::evaluate::Expr<T> &expr) {
- localNumberOfExpr++;
- anyArrayExpr = anyArrayExpr || expr.Rank() > 0;
- }},
- acValue.u);
+ Fortran::common::visit(
+ Fortran::common::visitors{
+ [&](const Fortran::evaluate::ImpliedDo<T> &impledDo) {
+ arrayValueListStack.push_back(&impledDo.values());
+ localNumberOfImpliedDo++;
+ },
+ [&](const Fortran::evaluate::Expr<T> &expr) {
+ localNumberOfExpr++;
+ anyArrayExpr = anyArrayExpr || expr.Rank() > 0;
+ }},
+ acValue.u);
anyImpliedDo = anyImpliedDo || localNumberOfImpliedDo > 0;
if (localNumberOfImpliedDo == 0) {
@@ -765,7 +766,7 @@ static void genAcValue(mlir::Location loc,
impliedDoIndexValue);
for (const auto &acValue : impledDo.values())
- std::visit(
+ Fortran::common::visit(
[&](const auto &x) {
genAcValue(loc, converter, x, symMap, stmtCtx, arrayBuilder);
},
@@ -787,7 +788,7 @@ hlfir::EntityWithAttributes Fortran::lower::ArrayConstructorBuilder<T>::gen(
loc, converter, arrayCtorExpr, symMap, stmtCtx);
// Run the array lowering strategy through the ac-values.
for (const auto &acValue : arrayCtorExpr)
- std::visit(
+ Fortran::common::visit(
[&](const auto &x) {
genAcValue(loc, converter, x, symMap, stmtCtx, arrayBuilder);
},
diff --git a/flang/lib/Lower/ConvertCall.cpp b/flang/lib/Lower/ConvertCall.cpp
index b1dc41f3ca838..65a2ffbea5dd1 100644
--- a/flang/lib/Lower/ConvertCall.cpp
+++ b/flang/lib/Lower/ConvertCall.cpp
@@ -935,7 +935,8 @@ struct CallCleanUp {
mlir::Value mustFree;
};
void genCleanUp(mlir::Location loc, fir::FirOpBuilder &builder) {
- std::visit([&](auto &c) { c.genCleanUp(loc, builder); }, cleanUp);
+ Fortran::common::visit([&](auto &c) { c.genCleanUp(loc, builder); },
+ cleanUp);
}
std::variant<CopyIn, ExprAssociate> cleanUp;
};
diff --git a/flang/lib/Lower/ConvertConstant.cpp b/flang/lib/Lower/ConvertConstant.cpp
index a4ace40a3a1c4..3361817ee27ee 100644
--- a/flang/lib/Lower/ConvertConstant.cpp
+++ b/flang/lib/Lower/ConvertConstant.cpp
@@ -105,7 +105,7 @@ class DenseGlobalBuilder {
const Fortran::lower::SomeExpr &initExpr,
cuf::DataAttributeAttr dataAttr) {
DenseGlobalBuilder globalBuilder;
- std::visit(
+ Fortran::common::visit(
Fortran::common::visitors{
[&](const Fortran::evaluate::Expr<Fortran::evaluate::SomeLogical> &
x) { globalBuilder.tryConvertingToAttributes(builder, x); },
@@ -164,7 +164,7 @@ class DenseGlobalBuilder {
template <typename SomeCat>
void tryConvertingToAttributes(fir::FirOpBuilder &builder,
const Fortran::evaluate::Expr<SomeCat> &expr) {
- std::visit(
+ Fortran::common::visit(
[&](const auto &x) {
using TR = Fortran::evaluate::ResultType<decltype(x)>;
if (const auto *constant =
@@ -796,7 +796,7 @@ static fir::ExtendedValue
genConstantValue(Fortran::lower::AbstractConverter &converter,
mlir::Location loc,
const Fortran::lower::SomeExpr &constantExpr) {
- return std::visit(
+ return Fortran::common::visit(
[&](const auto &x) -> fir::ExtendedValue {
using T = std::decay_t<decltype(x)>;
if constexpr (Fortran::common::HasMember<
@@ -805,7 +805,7 @@ genConstantValue(Fortran::lower::AbstractConverter &converter,
Fortran::common::TypeCategory::Derived) {
return genConstantValue(converter, loc, x);
} else {
- return std::visit(
+ return Fortran::common::visit(
[&](const auto &preciseKind) {
return genConstantValue(converter, loc, preciseKind);
},
diff --git a/flang/lib/Lower/ConvertExpr.cpp b/flang/lib/Lower/ConvertExpr.cpp
index 9567685aa3d2e..9937e9d159886 100644
--- a/flang/lib/Lower/ConvertExpr.cpp
+++ b/flang/lib/Lower/ConvertExpr.cpp
@@ -398,8 +398,8 @@ static bool isParenthesizedVariable(const Fortran::evaluate::Expr<T> &expr) {
return Fortran::evaluate::IsVariable(parentheses->left());
return false;
} else {
- return std::visit([&](const auto &x) { return isParenthesizedVariable(x); },
- expr.u);
+ return Fortran::common::visit(
+ [&](const auto &x) { return isParenthesizedVariable(x); }, expr.u);
}
}
@@ -646,7 +646,7 @@ isOptimizableTranspose(Fortran::evaluate::Expr<T> expr,
if (!isTransposeOptEnabled(converter))
return false;
- return std::visit(
+ return Fortran::common::visit(
[&](const auto &e) { return isOptimizableTranspose(e, converter); },
expr.u);
}
@@ -696,7 +696,7 @@ class ScalarExprLowering {
// - result of NULL() or NULL(MOLD) intrinsic.
// NULL() requires some context to be lowered, so it is not handled
// here and must be lowered according to the context where it appears.
- ExtValue exv = std::visit(
+ ExtValue exv = Fortran::common::visit(
[&](const auto &x) { return genMutableBoxValueImpl(x); }, expr.u);
const fir::MutableBoxValue *mutableBox =
exv.getBoxOf<fir::MutableBoxValue>();
@@ -737,7 +737,7 @@ class ScalarExprLowering {
template <typename T>
ExtValue
genMutableBoxValueImpl(const Fortran::evaluate::Designator<T> &designator) {
- return std::visit(
+ return Fortran::common::visit(
Fortran::common::visitors{
[&](const Fortran::evaluate::SymbolRef &sym) -> ExtValue {
return converter.getSymbolExtendedValue(*sym, &symMap);
@@ -754,8 +754,8 @@ class ScalarExprLowering {
template <typename T>
ExtValue genMutableBoxValueImpl(const Fortran::evaluate::Expr<T> &expr) {
- return std::visit([&](const auto &x) { return genMutableBoxValueImpl(x); },
- expr.u);
+ return Fortran::common::visit(
+ [&](const auto &x) { return genMutableBoxValueImpl(x); }, expr.u);
}
mlir::Location getLoc() { return location; }
@@ -1222,7 +1222,8 @@ class ScalarExprLowering {
ExtValue
genval(const Fortran::evaluate::Relational<Fortran::evaluate::SomeType> &op) {
- return std::visit([&](const auto &x) { return genval(x); }, op.u);
+ return Fortran::common::visit([&](const auto &x) { return genval(x); },
+ op.u);
}
template <Fortran::common::TypeCategory TC1, int KIND,
@@ -1341,7 +1342,7 @@ class ScalarExprLowering {
/// Reference to a substring.
ExtValue gen(const Fortran::evaluate::Substring &s) {
// Get base string
- auto baseString = std::visit(
+ auto baseString = Fortran::common::visit(
Fortran::common::visitors{
[&](const Fortran::evaluate::DataRef &x) { return gen(x); },
[&](const Fortran::evaluate::StaticDataObject::Pointer &p)
@@ -1400,10 +1401,12 @@ class ScalarExprLowering {
}
ExtValue gen(const Fortran::evaluate::DataRef &dref) {
- return std::visit([&](const auto &x) { return gen(x); }, dref.u);
+ return Fortran::common::visit([&](const auto &x) { return gen(x); },
+ dref.u);
}
ExtValue genval(const Fortran::evaluate::DataRef &dref) {
- return std::visit([&](const auto &x) { return genval(x); }, dref.u);
+ return Fortran::common::visit([&](const auto &x) { return genval(x); },
+ dref.u);
}
// Helper function to turn the Component structure into a list of nested
@@ -1418,7 +1421,7 @@ class ScalarExprLowering {
std::list<const Fortran::evaluate::Component *> &list) {
if (!getLastSym(cmpt).test(Fortran::semantics::Symbol::Flag::ParentComp))
list.push_front(&cmpt);
- return std::visit(
+ return Fortran::common::visit(
Fortran::common::visitors{
[&](const Fortran::evaluate::Component &x) {
if (Fortran::semantics::IsAllocatableOrPointer(getLastSym(x)))
@@ -1713,11 +1716,12 @@ class ScalarExprLowering {
template <typename A>
ExtValue gen(const Fortran::evaluate::Designator<A> &des) {
- return std::visit([&](const auto &x) { return gen(x); }, des.u);
+ return Fortran::common::visit([&](const auto &x) { return gen(x); }, des.u);
}
template <typename A>
ExtValue genval(const Fortran::evaluate::Designator<A> &des) {
- return std::visit([&](const auto &x) { return genval(x); }, des.u);
+ return Fortran::common::visit([&](const auto &x) { return genval(x); },
+ des.u);
}
mlir::Type genType(const Fortran::evaluate::DynamicType &dt) {
@@ -2900,8 +2904,8 @@ class ScalarExprLowering {
}
template <typename T>
bool isTransformationalRef(Fortran::evaluate::Expr<T> expr) {
- return std::visit([&](const auto &e) { return isTransformationalRef(e); },
- expr.u);
+ return Fortran::common::visit(
+ [&](const auto &e) { return isTransformationalRef(e); }, expr.u);
}
template <typename A>
@@ -2914,11 +2918,13 @@ class ScalarExprLowering {
/// value, so it may be possible to avoid making a temporary.
template <typename A>
ExtValue asArrayArg(const Fortran::evaluate::Expr<A> &x) {
- return std::visit([&](const auto &e) { return asArrayArg(e, x); }, x.u);
+ return Fortran::common::visit(
+ [&](const auto &e) { return asArrayArg(e, x); }, x.u);
}
template <typename A, typename B>
ExtValue asArrayArg(const Fortran::evaluate::Expr<A> &x, const B &y) {
- return std::visit([&](const auto &e) { return asArrayArg(e, y); }, x.u);
+ return Fortran::common::visit(
+ [&](const auto &e) { return asArrayArg(e, y); }, x.u);
}
template <typename A, typename B>
ExtValue asArrayArg(const Fortran::evaluate::Designator<A> &, const B &x) {
@@ -2956,7 +2962,8 @@ class ScalarExprLowering {
if (isScalar(x) ||
Fortran::evaluate::UnwrapWholeSymbolOrComponentDataRef(x) ||
(isTransformationalRef(x) && !isOptimizableTranspose(x, converter)))
- return std::visit([&](const auto &e) { return genref(e); }, x.u);
+ return Fortran::common::visit([&](const auto &e) { return genref(e); },
+ x.u);
if (useBoxArg)
return asArrayArg(x);
return asArray(x);
@@ -2967,7 +2974,8 @@ class ScalarExprLowering {
return val;
if (isScalar(x) || Fortran::evaluate::UnwrapWholeSymbolDataRef(x) ||
inInitializer)
- return std::visit([&](const auto &e) { return genval(e); }, x.u);
+ return Fortran::common::visit([&](const auto &e) { return genval(e); },
+ x.u);
return asArray(x);
}
@@ -2976,7 +2984,8 @@ class ScalarExprLowering {
Fortran::common::TypeCategory::Logical, KIND>> &exp) {
if (mlir::Value val = getIfOverridenExpr(exp))
return val;
- return std::visit([&](const auto &e) { return genval(e); }, exp.u);
+ return Fortran::common::visit([&](const auto &e) { return genval(e); },
+ exp.u);
}
using RefSet =
@@ -3462,7 +3471,7 @@ class ArrayExprLowering {
ExtValue lowerBoxedArrayExpr(const Fortran::lower::SomeExpr &exp) {
PushSemantics(ConstituentSemantics::BoxValue);
- return std::visit(
+ return Fortran::common::visit(
[&](const auto &e) {
auto f = genarr(e);
ExtValue exv = f(IterationSpace{});
@@ -3824,28 +3833,29 @@ class ArrayExprLowering {
fir::factory::getExtents(loc, builder, exv);
mlir::Value one = builder.createIntegerConstant(loc, idxTy, 1);
for (auto ss : llvm::enumerate(x.subscript())) {
- std::visit(Fortran::common::visitors{
- [&](const Fortran::evaluate::Triplet &trip) {
- // For a subscript of triple notation, we compute the
- // range of this dimension of the iteration space.
- auto lo = [&]() {
- if (auto optLo = trip.lower())
- return fir::getBase(asScalar(*optLo));
- return getLBound(exv, ss.index(), one);
- }();
- auto hi = [&]() {
- if (auto optHi = trip.upper())
- return fir::getBase(asScalar(*optHi));
- return getUBound(exv, ss.index(), one);
- }();
- auto step = builder.createConvert(
- loc, idxTy, fir::getBase(asScalar(trip.stride())));
- auto extent = builder.genExtentFromTriplet(loc, lo, hi,
- step, idxTy);
- destShape.push_back(extent);
- },
- [&](auto) {}},
- ss.value().u);
+ Fortran::common::visit(
+ Fortran::common::visitors{
+ [&](const Fortran::evaluate::Triplet &trip) {
+ // For a subscript of triple notation, we compute the
+ // range of this dimension of the iteration space.
+ auto lo = [&]() {
+ if (auto optLo = trip.lower())
+ return fir::getBase(asScalar(*optLo));
+ return getLBound(exv, ss.index(), one);
+ }();
+ auto hi = [&]() {
+ if (auto optHi = trip.upper())
+ return fir::getBase(asScalar(*optHi));
+ return getUBound(exv, ss.index(), one);
+ }();
+ auto step = builder.createConvert(
+ loc, idxTy, fir::getBase(asScalar(trip.stride())));
+ auto extent =
+ builder.genExtentFromTriplet(loc, lo, hi, step, idxTy);
+ destShape.push_back(extent);
+ },
+ [&](auto) {}},
+ ss.value().u);
}
return true;
}
@@ -3855,8 +3865,8 @@ class ArrayExprLowering {
return genShapeFromDataRef(x.GetComponent());
}
bool genShapeFromDataRef(const Fortran::evaluate::DataRef &x) {
- return std::visit([&](const auto &v) { return genShapeFromDataRef(v); },
- x.u);
+ return Fortran::common::visit(
+ [&](const auto &v) { return genShapeFromDataRef(v); }, x.u);
}
/// When in an explicit space, the ranked component must be evaluated to
@@ -3890,7 +3900,7 @@ class ArrayExprLowering {
TODO(getLoc(),
"polymorphic array expression lowering with vector subscript");
- return std::visit(
+ return Fortran::common::visit(
[&](const auto &e) { return lowerArrayExpression(genarr(e), resTy); },
exp.u);
}
@@ -5012,10 +5022,12 @@ class ArrayExprLowering {
LLVM_DEBUG(Fortran::lower::DumpEvaluateExpr::dump(llvm::dbgs(), x));
if (isArray(x) || (explicitSpaceIsActive() && isLeftHandSide()) ||
isElementalProcWithArrayArgs(x))
- return std::visit([&](const auto &e) { return genarr(e); }, x.u);
+ return Fortran::common::visit([&](const auto &e) { return genarr(e); },
+ x.u);
if (explicitSpaceIsActive()) {
assert(!isArray(x) && !isLeftHandSide());
- auto cc = std::visit([&](const auto &e) { return genarr(e); }, x.u);
+ auto cc =
+ Fortran::common::visit([&](const auto &e) { return genarr(e); }, x.u);
auto result = cc(IterationSpace{});
return [=](IterSpace) { return result; };
}
@@ -5289,7 +5301,8 @@ class ArrayExprLowering {
static 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);
}
template <Fortran::common::TypeCategory FROM>
static Fortran::lower::SomeExpr ignoreEvConvert(
@@ -5310,8 +5323,8 @@ class ArrayExprLowering {
template <typename A>
static const Fortran::semantics::Symbol *
extractSubscriptSymbol(const Fortran::evaluate::Expr<A> &x) {
- return std::visit([&](const auto &v) { return extractSubscriptSymbol(v); },
- x.u);
+ return Fortran::common::visit(
+ [&](const auto &v) { return extractSubscriptSymbol(v); }, x.u);
}
template <typename A>
static const Fortran::semantics::Symbol *
@@ -5420,7 +5433,7 @@ class ArrayExprLowering {
std::size_t shapeIndex = 0;
for (auto sub : llvm::enumerate(x.subscript())) {
const std::size_t subsIndex = sub.index();
- std::visit(
+ Fortran::common::visit(
Fortran::common::visitors{
[&](const Fortran::evaluate::Triplet &t) {
mlir::Value lowerBound;
@@ -6034,8 +6047,8 @@ class ArrayExprLowering {
/// Substrings (see 9.4.1)
CC genarr(const Fortran::evaluate::Substring &x, ComponentPath &components) {
components.substring = &x;
- return std::visit([&](const auto &v) { return genarr(v, components); },
- x.parent());
+ return Fortran::common::visit(
+ [&](const auto &v) { return genarr(v, components); }, x.parent());
}
template <typename T>
@@ -6333,7 +6346,7 @@ class ArrayExprLowering {
stmtCtx.pushScope();
std::optional<mlir::Value> charLen;
for (const Fortran::evaluate::ArrayConstructorValue<A> &acv : x.values()) {
- auto [exv, copyNeeded] = std::visit(
+ auto [exv, copyNeeded] = Fortran::common::visit(
[&](const auto &v) {
return genArrayCtorInitializer(v, resTy, mem, buffPos, buffSize,
stmtCtx);
@@ -6417,7 +6430,7 @@ class ArrayExprLowering {
// Populate the buffer with the elements, growing as necessary.
std::optional<mlir::Value> charLen;
for (const auto &expr : x) {
- auto [exv, copyNeeded] = std::visit(
+ auto [exv, copyNeeded] = Fortran::common::visit(
[&](const auto &e) {
return genArrayCtorInitializer(e, resTy, mem, buffPos, buffSize,
stmtCtx);
@@ -6582,22 +6595,24 @@ class ArrayExprLowering {
}
CC genarr(
const Fortran::evaluate::Relational<Fortran::evaluate::SomeType> &r) {
- return std::visit([&](const auto &x) { return genarr(x); }, r.u);
+ return Fortran::common::visit([&](const auto &x) { return genarr(x); },
+ r.u);
}
template <typename A>
CC genarr(const Fortran::evaluate::Designator<A> &des) {
ComponentPath components(des.Rank() > 0);
- return std::visit([&](const auto &x) { return genarr(x, components); },
- des.u);
+ return Fortran::common::visit(
+ [&](const auto &x) { return genarr(x, components); }, des.u);
}
/// Is the path component rank > 0?
static bool ranked(const PathComponent &x) {
- return std::visit(Fortran::common::visitors{
- [](const ImplicitSubscripts &) { return false; },
- [](const auto *v) { return v->Rank() > 0; }},
- x);
+ return Fortran::common::visit(
+ Fortran::common::visitors{
+ [](const ImplicitSubscripts &) { return false; },
+ [](const auto *v) { return v->Rank() > 0; }},
+ x);
}
void extendComponent(Fortran::lower::ComponentPath &component,
@@ -6653,7 +6668,7 @@ class ArrayExprLowering {
: nextPathSemantics());
unsigned index = 0;
for (const auto &v : llvm::reverse(revPath)) {
- std::visit(
+ Fortran::common::visit(
Fortran::common::visitors{
[&](const ImplicitSubscripts &) {
prefix = false;
@@ -6678,7 +6693,7 @@ class ArrayExprLowering {
unsigned ssIndex = 0u;
llvm::SmallVector<mlir::Value> componentsToAdd;
for (const auto &ss : x->subscript()) {
- std::visit(
+ Fortran::common::visit(
Fortran::common::visitors{
[&](const Fortran::evaluate::
IndirectSubscriptIntegerExpr &ie) {
@@ -7099,8 +7114,8 @@ class ArrayExprLowering {
}
CC genarr(const Fortran::evaluate::DataRef &x, ComponentPath &components) {
- return std::visit([&](const auto &v) { return genarr(v, components); },
- x.u);
+ return Fortran::common::visit(
+ [&](const auto &v) { return genarr(v, components); }, x.u);
}
bool pathIsEmpty(const ComponentPath &components) {
@@ -7575,13 +7590,13 @@ void Fortran::lower::createArrayLoads(
};
if (esp.lhsBases[counter]) {
auto &base = *esp.lhsBases[counter];
- auto load = std::visit(genLoad, base);
+ auto load = Fortran::common::visit(genLoad, base);
esp.initialArgs.push_back(load);
esp.resetInnerArgs();
esp.bindLoad(base, load);
}
for (const auto &base : esp.rhsBases[counter])
- esp.bindLoad(base, std::visit(genLoad, base));
+ esp.bindLoad(base, Fortran::common::visit(genLoad, base));
}
void Fortran::lower::createArrayMergeStores(
diff --git a/flang/lib/Lower/ConvertExprToHLFIR.cpp b/flang/lib/Lower/ConvertExprToHLFIR.cpp
index 9035856eabfe7..1933f38f735b5 100644
--- a/flang/lib/Lower/ConvertExprToHLFIR.cpp
+++ b/flang/lib/Lower/ConvertExprToHLFIR.cpp
@@ -75,7 +75,7 @@ class HlfirDesignatorBuilder {
hlfir::EntityWithAttributes
gen(const CharacterDesignators &designatorVariant,
bool vectorSubscriptDesignatorToValue = true) {
- return std::visit(
+ return Fortran::common::visit(
[&](const auto &x) -> hlfir::EntityWithAttributes {
return genLeafPartRef(x, vectorSubscriptDesignatorToValue);
},
@@ -88,7 +88,7 @@ class HlfirDesignatorBuilder {
hlfir::EntityWithAttributes
gen(const RealDesignators &designatorVariant,
bool vectorSubscriptDesignatorToValue = true) {
- return std::visit(
+ return Fortran::common::visit(
[&](const auto &x) -> hlfir::EntityWithAttributes {
return genLeafPartRef(x, vectorSubscriptDesignatorToValue);
},
@@ -101,7 +101,7 @@ class HlfirDesignatorBuilder {
hlfir::EntityWithAttributes
gen(const OtherDesignators &designatorVariant,
bool vectorSubscriptDesignatorToValue = true) {
- return std::visit(
+ return Fortran::common::visit(
[&](const auto &x) -> hlfir::EntityWithAttributes {
return genLeafPartRef(x, vectorSubscriptDesignatorToValue);
},
@@ -169,7 +169,7 @@ class HlfirDesignatorBuilder {
fir::FortranVariableOpInterface
gen(const Fortran::evaluate::DataRef &dataRef) {
- return std::visit(
+ return Fortran::common::visit(
Fortran::common::visitors{[&](const auto &x) { return gen(x); }},
dataRef.u);
}
@@ -364,7 +364,7 @@ class HlfirDesignatorBuilder {
fir::FortranVariableOpInterface
gen(const Fortran::evaluate::Substring &substring) {
PartInfo partInfo;
- mlir::Type baseStringType = std::visit(
+ mlir::Type baseStringType = Fortran::common::visit(
[&](const auto &x) { return visit(x, partInfo); }, substring.parent());
assert(partInfo.typeParams.size() == 1 && "expect base string length");
// Compute the substring lower and upper bound.
@@ -436,8 +436,8 @@ class HlfirDesignatorBuilder {
mlir::Type visit(const Fortran::evaluate::DataRef &dataRef,
PartInfo &partInfo) {
- return std::visit([&](const auto &x) { return visit(x, partInfo); },
- dataRef.u);
+ return Fortran::common::visit(
+ [&](const auto &x) { return visit(x, partInfo); }, dataRef.u);
}
mlir::Type
@@ -892,7 +892,7 @@ hlfir::EntityWithAttributes HlfirDesignatorBuilder::genDesignatorExpr(
bool vectorSubscriptDesignatorToValue) {
// Expr<SomeType> plumbing to unwrap Designator<T> and call
// gen(Designator<T>.u).
- return std::visit(
+ return Fortran::common::visit(
[&](const auto &x) -> hlfir::EntityWithAttributes {
using T = std::decay_t<decltype(x)>;
if constexpr (Fortran::common::HasMember<
@@ -904,7 +904,7 @@ hlfir::EntityWithAttributes HlfirDesignatorBuilder::genDesignatorExpr(
.u,
vectorSubscriptDesignatorToValue);
} else {
- return std::visit(
+ return Fortran::common::visit(
[&](const auto &preciseKind) {
using TK =
typename std::decay_t<decltype(preciseKind)>::Result;
@@ -1426,7 +1426,8 @@ class HlfirBuilder {
return hlfir::EntityWithAttributes{match->second};
}
}
- return std::visit([&](const auto &x) { return gen(x); }, expr.u);
+ return Fortran::common::visit([&](const auto &x) { return gen(x); },
+ expr.u);
}
private:
@@ -1594,7 +1595,7 @@ class HlfirBuilder {
hlfir::EntityWithAttributes
gen(const Fortran::evaluate::Relational<Fortran::evaluate::SomeType> &op) {
- return std::visit([&](const auto &x) { return gen(x); }, op.u);
+ return Fortran::common::visit([&](const auto &x) { return gen(x); }, op.u);
}
hlfir::EntityWithAttributes gen(const Fortran::evaluate::TypeParamInquiry &) {
diff --git a/flang/lib/Lower/ConvertType.cpp b/flang/lib/Lower/ConvertType.cpp
index e6557d7f0b767..f64f6c93541a3 100644
--- a/flang/lib/Lower/ConvertType.cpp
+++ b/flang/lib/Lower/ConvertType.cpp
@@ -212,7 +212,7 @@ struct TypeBuilderImpl {
}
mlir::Type genTypelessExprType(const Fortran::lower::SomeExpr &expr) {
- return std::visit(
+ return Fortran::common::visit(
Fortran::common::visitors{
[&](const Fortran::evaluate::BOZLiteralConstant &) -> mlir::Type {
return mlir::NoneType::get(context);
diff --git a/flang/lib/Lower/DirectivesCommon.h b/flang/lib/Lower/DirectivesCommon.h
index 48b090f6d2dbe..f0af5f982c14f 100644
--- a/flang/lib/Lower/DirectivesCommon.h
+++ b/flang/lib/Lower/DirectivesCommon.h
@@ -836,7 +836,7 @@ struct PeelConvert {
static Fortran::semantics::MaybeExpr visit_with_category(
const Fortran::evaluate::Expr<Fortran::evaluate::Type<Category, Kind>>
&expr) {
- return std::visit(
+ return Fortran::common::visit(
[](auto &&s) { return visit_with_category<Category, Kind>(s); },
expr.u);
}
@@ -859,12 +859,12 @@ struct PeelConvert {
static Fortran::semantics::MaybeExpr
visit(const Fortran::evaluate::Expr<Fortran::evaluate::SomeKind<Category>>
&expr) {
- return std::visit([](auto &&s) { return visit_with_category<Category>(s); },
- expr.u);
+ return Fortran::common::visit(
+ [](auto &&s) { return visit_with_category<Category>(s); }, expr.u);
}
static Fortran::semantics::MaybeExpr
visit(const Fortran::evaluate::Expr<Fortran::evaluate::SomeType> &expr) {
- return std::visit([](auto &&s) { return visit(s); }, expr.u);
+ return Fortran::common::visit([](auto &&s) { return visit(s); }, expr.u);
}
template <typename T> //
static Fortran::semantics::MaybeExpr visit(const T &) {
diff --git a/flang/lib/Lower/IO.cpp b/flang/lib/Lower/IO.cpp
index 97ef991cb3990..9e98b230b676f 100644
--- a/flang/lib/Lower/IO.cpp
+++ b/flang/lib/Lower/IO.cpp
@@ -1388,7 +1388,7 @@ static void threadSpecs(Fortran::lower::AbstractConverter &converter,
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
for (const auto &spec : specList) {
makeNextConditionalOn(builder, loc, checkResult, ok);
- ok = std::visit(
+ ok = Fortran::common::visit(
Fortran::common::visitors{
[&](const Fortran::parser::IoControlSpec::Size &x) -> mlir::Value {
// Size must be queried after the related READ runtime calls, not
@@ -1425,7 +1425,7 @@ ConditionSpecInfo lowerErrorSpec(Fortran::lower::AbstractConverter &converter,
ConditionSpecInfo csi;
const Fortran::lower::SomeExpr *ioMsgExpr = nullptr;
for (const auto &spec : specList) {
- std::visit(
+ Fortran::common::visit(
Fortran::common::visitors{
[&](const Fortran::parser::StatVariable &var) {
csi.ioStatExpr = Fortran::semantics::GetExpr(var);
@@ -2397,7 +2397,7 @@ lowerIdExpr(Fortran::lower::AbstractConverter &converter, mlir::Location loc,
const std::list<Fortran::parser::InquireSpec> &ispecs,
Fortran::lower::StatementContext &stmtCtx) {
for (const Fortran::parser::InquireSpec &spec : ispecs)
- if (mlir::Value v = std::visit(
+ if (mlir::Value v = Fortran::common::visit(
Fortran::common::visitors{
[&](const Fortran::parser::IdExpr &idExpr) {
return fir::getBase(converter.genExprValue(
@@ -2419,11 +2419,11 @@ static void threadInquire(Fortran::lower::AbstractConverter &converter,
mlir::Value idExpr = lowerIdExpr(converter, loc, ispecs, stmtCtx);
for (const Fortran::parser::InquireSpec &spec : ispecs) {
makeNextConditionalOn(builder, loc, checkResult, ok);
- ok = std::visit(Fortran::common::visitors{[&](const auto &x) {
- return genInquireSpec(converter, loc, cookie, idExpr, x,
- stmtCtx);
- }},
- spec.u);
+ ok = Fortran::common::visit(Fortran::common::visitors{[&](const auto &x) {
+ return genInquireSpec(converter, loc, cookie,
+ idExpr, x, stmtCtx);
+ }},
+ spec.u);
}
}
diff --git a/flang/lib/Lower/IterationSpace.cpp b/flang/lib/Lower/IterationSpace.cpp
index 6bf310b5cfb76..9303536403837 100644
--- a/flang/lib/Lower/IterationSpace.cpp
+++ b/flang/lib/Lower/IterationSpace.cpp
@@ -21,14 +21,14 @@
unsigned Fortran::lower::getHashValue(
const Fortran::lower::ExplicitIterSpace::ArrayBases &x) {
- return std::visit(
+ return Fortran::common::visit(
[&](const auto *p) { return HashEvaluateExpr::getHashValue(*p); }, x);
}
bool Fortran::lower::isEqual(
const Fortran::lower::ExplicitIterSpace::ArrayBases &x,
const Fortran::lower::ExplicitIterSpace::ArrayBases &y) {
- return std::visit(
+ return Fortran::common::visit(
Fortran::common::visitors{
// Fortran::semantics::Symbol * are the exception here. These pointers
// have identity; if two Symbol * values are the same (different) then
@@ -169,7 +169,7 @@ class ArrayBaseFinder {
}
template <typename... A>
RT find(const std::variant<A...> &u) {
- return std::visit([&](const auto &v) { return find(v); }, u);
+ return Fortran::common::visit([&](const auto &v) { return find(v); }, u);
}
template <typename A>
RT find(const std::vector<A> &x) {
@@ -361,22 +361,23 @@ llvm::raw_ostream &
Fortran::lower::operator<<(llvm::raw_ostream &s,
const Fortran::lower::ExplicitIterSpace &e) {
auto dump = [&](const auto &u) {
- std::visit(Fortran::common::visitors{
- [&](const Fortran::semantics::Symbol *y) {
- s << " " << *y << '\n';
- },
- [&](const Fortran::evaluate::ArrayRef *y) {
- s << " ";
- if (y->base().IsSymbol())
- s << y->base().GetFirstSymbol();
- else
- s << y->base().GetComponent().GetLastSymbol();
- s << '\n';
- },
- [&](const Fortran::evaluate::Component *y) {
- s << " " << y->GetLastSymbol() << '\n';
- }},
- u);
+ Fortran::common::visit(
+ Fortran::common::visitors{
+ [&](const Fortran::semantics::Symbol *y) {
+ s << " " << *y << '\n';
+ },
+ [&](const Fortran::evaluate::ArrayRef *y) {
+ s << " ";
+ if (y->base().IsSymbol())
+ s << y->base().GetFirstSymbol();
+ else
+ s << y->base().GetComponent().GetLastSymbol();
+ s << '\n';
+ },
+ [&](const Fortran::evaluate::Component *y) {
+ s << " " << y->GetLastSymbol() << '\n';
+ }},
+ u);
};
s << "LHS bases:\n";
for (const std::optional<Fortran::lower::ExplicitIterSpace::ArrayBases> &u :
diff --git a/flang/lib/Lower/Mangler.cpp b/flang/lib/Lower/Mangler.cpp
index 9a33be318a27d..878ba6dea49b6 100644
--- a/flang/lib/Lower/Mangler.cpp
+++ b/flang/lib/Lower/Mangler.cpp
@@ -110,7 +110,7 @@ std::string Fortran::lower::mangle::mangleName(
return fir::NameUniquer::doVariable(modules, procs, blockId, symbolName);
};
- return std::visit(
+ return Fortran::common::visit(
Fortran::common::visitors{
[&](const Fortran::semantics::MainProgramDetails &) {
return fir::NameUniquer::doProgramEntry().str();
diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp
index 4f5da8fb70eba..166fa686cd883 100644
--- a/flang/lib/Lower/OpenACC.cpp
+++ b/flang/lib/Lower/OpenACC.cpp
@@ -46,14 +46,15 @@ static mlir::Location
genOperandLocation(Fortran::lower::AbstractConverter &converter,
const Fortran::parser::AccObject &accObject) {
mlir::Location loc = converter.genUnknownLocation();
- std::visit(Fortran::common::visitors{
- [&](const Fortran::parser::Designator &designator) {
- loc = converter.genLocation(designator.source);
- },
- [&](const Fortran::parser::Name &name) {
- loc = converter.genLocation(name.source);
- }},
- accObject.u);
+ Fortran::common::visit(
+ Fortran::common::visitors{
+ [&](const Fortran::parser::Designator &designator) {
+ loc = converter.genLocation(designator.source);
+ },
+ [&](const Fortran::parser::Name &name) {
+ loc = converter.genLocation(name.source);
+ }},
+ accObject.u);
return loc;
}
@@ -297,8 +298,8 @@ genDataOperandOperations(const Fortran::parser::AccObjectList &objectList,
std::stringstream asFortran;
mlir::Location operandLocation = genOperandLocation(converter, accObject);
Fortran::semantics::Symbol &symbol = getSymbolFromAccObject(accObject);
- Fortran::semantics::MaybeExpr designator =
- std::visit([&](auto &&s) { return ea.Analyze(s); }, accObject.u);
+ Fortran::semantics::MaybeExpr designator = Fortran::common::visit(
+ [&](auto &&s) { return ea.Analyze(s); }, accObject.u);
Fortran::lower::AddrAndBoundsInfo info =
Fortran::lower::gatherDataOperandAddrAndBounds<
mlir::acc::DataBoundsOp, mlir::acc::DataBoundsType>(
@@ -335,8 +336,8 @@ static void genDeclareDataOperandOperations(
std::stringstream asFortran;
mlir::Location operandLocation = genOperandLocation(converter, accObject);
Fortran::semantics::Symbol &symbol = getSymbolFromAccObject(accObject);
- Fortran::semantics::MaybeExpr designator =
- std::visit([&](auto &&s) { return ea.Analyze(s); }, accObject.u);
+ Fortran::semantics::MaybeExpr designator = Fortran::common::visit(
+ [&](auto &&s) { return ea.Analyze(s); }, accObject.u);
Fortran::lower::AddrAndBoundsInfo info =
Fortran::lower::gatherDataOperandAddrAndBounds<
mlir::acc::DataBoundsOp, mlir::acc::DataBoundsType>(
@@ -790,8 +791,8 @@ genPrivatizations(const Fortran::parser::AccObjectList &objectList,
std::stringstream asFortran;
mlir::Location operandLocation = genOperandLocation(converter, accObject);
Fortran::semantics::Symbol &symbol = getSymbolFromAccObject(accObject);
- Fortran::semantics::MaybeExpr designator =
- std::visit([&](auto &&s) { return ea.Analyze(s); }, accObject.u);
+ Fortran::semantics::MaybeExpr designator = Fortran::common::visit(
+ [&](auto &&s) { return ea.Analyze(s); }, accObject.u);
Fortran::lower::AddrAndBoundsInfo info =
Fortran::lower::gatherDataOperandAddrAndBounds<
mlir::acc::DataBoundsOp, mlir::acc::DataBoundsType>(
@@ -1364,8 +1365,8 @@ genReductions(const Fortran::parser::AccObjectListWithReduction &objectList,
std::stringstream asFortran;
mlir::Location operandLocation = genOperandLocation(converter, accObject);
Fortran::semantics::Symbol &symbol = getSymbolFromAccObject(accObject);
- Fortran::semantics::MaybeExpr designator =
- std::visit([&](auto &&s) { return ea.Analyze(s); }, accObject.u);
+ Fortran::semantics::MaybeExpr designator = Fortran::common::visit(
+ [&](auto &&s) { return ea.Analyze(s); }, accObject.u);
Fortran::lower::AddrAndBoundsInfo info =
Fortran::lower::gatherDataOperandAddrAndBounds<
mlir::acc::DataBoundsOp, mlir::acc::DataBoundsType>(
@@ -3414,7 +3415,7 @@ static void genGlobalCtors(Fortran::lower::AbstractConverter &converter,
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
for (const auto &accObject : accObjectList.v) {
mlir::Location operandLocation = genOperandLocation(converter, accObject);
- std::visit(
+ Fortran::common::visit(
Fortran::common::visitors{
[&](const Fortran::parser::Designator &designator) {
if (const auto *name =
@@ -3993,7 +3994,7 @@ genACC(Fortran::lower::AbstractConverter &converter,
const Fortran::parser::OpenACCAtomicConstruct &atomicConstruct) {
mlir::Location loc = converter.genLocation(atomicConstruct.source);
- std::visit(
+ Fortran::common::visit(
Fortran::common::visitors{
[&](const Fortran::parser::AccAtomicRead &atomicRead) {
Fortran::lower::genOmpAccAtomicRead<Fortran::parser::AccAtomicRead,
@@ -4061,7 +4062,7 @@ mlir::Value Fortran::lower::genOpenACCConstruct(
const Fortran::parser::OpenACCConstruct &accConstruct) {
mlir::Value exitCond;
- std::visit(
+ Fortran::common::visit(
common::visitors{
[&](const Fortran::parser::OpenACCBlockConstruct &blockConstruct) {
genACC(converter, semanticsContext, eval, blockConstruct);
@@ -4101,7 +4102,7 @@ void Fortran::lower::genOpenACCDeclarativeConstruct(
const Fortran::parser::OpenACCDeclarativeConstruct &accDeclConstruct,
Fortran::lower::AccRoutineInfoMappingList &accRoutineInfos) {
- std::visit(
+ Fortran::common::visit(
common::visitors{
[&](const Fortran::parser::OpenACCStandaloneDeclarativeConstruct
&standaloneDeclarativeConstruct) {
diff --git a/flang/lib/Lower/OpenMP/Clauses.cpp b/flang/lib/Lower/OpenMP/Clauses.cpp
index 6bae62cd85860..c355b63deff8a 100644
--- a/flang/lib/Lower/OpenMP/Clauses.cpp
+++ b/flang/lib/Lower/OpenMP/Clauses.cpp
@@ -38,8 +38,8 @@ llvm::omp::Clause getClauseIdForClass(C &&) {
} // namespace detail
static llvm::omp::Clause getClauseId(const Fortran::parser::OmpClause &clause) {
- return std::visit([](auto &&s) { return detail::getClauseIdForClass(s); },
- clause.u);
+ return Fortran::common::visit(
+ [](auto &&s) { return detail::getClauseIdForClass(s); }, clause.u);
}
namespace Fortran::lower::omp {
@@ -83,7 +83,7 @@ struct SymbolAndDesignatorExtractor {
template <typename T>
static SymbolWithDesignator visit(const evaluate::Expr<T> &e) {
- return std::visit([](auto &&s) { return visit(s); }, e.u);
+ return Fortran::common::visit([](auto &&s) { return visit(s); }, e.u);
}
static void verify(const SymbolWithDesignator &sd) {
@@ -112,7 +112,7 @@ struct SymbolAndDesignatorExtractor {
SymbolWithDesignator getSymbolAndDesignator(const MaybeExpr &expr) {
if (!expr)
return SymbolWithDesignator{};
- return std::visit(
+ return Fortran::common::visit(
[](auto &&s) { return SymbolAndDesignatorExtractor::visit(s); }, expr->u);
}
@@ -278,7 +278,7 @@ DefinedOperator makeDefinedOperator(const parser::DefinedOperator &inp,
// clang-format on
);
- return std::visit(
+ return Fortran::common::visit(
common::visitors{
[&](const parser::DefinedOpName &s) {
return DefinedOperator{
@@ -294,7 +294,7 @@ DefinedOperator makeDefinedOperator(const parser::DefinedOperator &inp,
ProcedureDesignator
makeProcedureDesignator(const parser::ProcedureDesignator &inp,
semantics::SemanticsContext &semaCtx) {
- return ProcedureDesignator{std::visit(
+ return ProcedureDesignator{Fortran::common::visit(
common::visitors{
[&](const parser::Name &t) { return makeObject(t, semaCtx); },
[&](const parser::ProcComponentRef &t) {
@@ -306,7 +306,7 @@ makeProcedureDesignator(const parser::ProcedureDesignator &inp,
ReductionOperator makeReductionOperator(const parser::OmpReductionOperator &inp,
semantics::SemanticsContext &semaCtx) {
- return std::visit(
+ return Fortran::common::visit(
common::visitors{
[&](const parser::DefinedOperator &s) {
return ReductionOperator{makeDefinedOperator(s, semaCtx)};
@@ -366,7 +366,7 @@ Allocate make(const parser::OmpClause::Allocate &inp,
using Tuple = decltype(Allocate::t);
- return Allocate{std::visit(
+ return Allocate{Fortran::common::visit(
common::visitors{
// simple-modifier
[&](const wrapped::AllocateModifier::Allocator &v) -> Tuple {
@@ -531,7 +531,7 @@ Depend make(const parser::OmpClause::Depend &inp,
// clang-format on
);
- return Depend{std::visit( //
+ return Depend{Fortran::common::visit( //
common::visitors{
// Doacross
[&](const wrapped::Source &s) -> Variant {
@@ -793,7 +793,7 @@ Linear make(const parser::OmpClause::Linear &inp,
using Tuple = decltype(Linear::t);
- return Linear{std::visit(
+ return Linear{Fortran::common::visit(
common::visitors{
[&](const wrapped::WithModifier &s) -> Tuple {
return {
@@ -949,7 +949,7 @@ Order make(const parser::OmpClause::Order &inp,
auto &t1 = std::get<wrapped::Type>(inp.v.t);
auto convert3 = [&](const parser::OmpOrderModifier &s) {
- return std::visit(
+ return Fortran::common::visit(
[&](parser::OmpOrderModifier::Kind k) { return convert1(k); }, s.u);
};
return Order{
@@ -1212,7 +1212,7 @@ UsesAllocators make(const parser::OmpClause::UsesAllocators &inp,
Clause makeClause(const parser::OmpClause &cls,
semantics::SemanticsContext &semaCtx) {
- return std::visit(
+ return Fortran::common::visit(
[&](auto &&s) {
return makeClause(getClauseId(cls), clause::make(s, semaCtx),
cls.source);
diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp b/flang/lib/Lower/OpenMP/OpenMP.cpp
index aac22f0faad37..7d75e6f67dc1b 100644
--- a/flang/lib/Lower/OpenMP/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP/OpenMP.cpp
@@ -2199,7 +2199,7 @@ static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
semantics::SemanticsContext &semaCtx,
lower::pft::Evaluation &eval,
const parser::OpenMPDeclarativeConstruct &ompDeclConstruct) {
- std::visit(
+ Fortran::common::visit(
[&](auto &&s) { return genOMP(converter, symTable, semaCtx, eval, s); },
ompDeclConstruct.u);
}
@@ -2276,7 +2276,7 @@ static void
genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
semantics::SemanticsContext &semaCtx, lower::pft::Evaluation &eval,
const parser::OpenMPStandaloneConstruct &standaloneConstruct) {
- std::visit(
+ Fortran::common::visit(
[&](auto &&s) { return genOMP(converter, symTable, semaCtx, eval, s); },
standaloneConstruct.u);
}
@@ -2296,7 +2296,7 @@ static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
semantics::SemanticsContext &semaCtx,
lower::pft::Evaluation &eval,
const parser::OpenMPAtomicConstruct &atomicConstruct) {
- std::visit(
+ Fortran::common::visit(
common::visitors{
[&](const parser::OmpAtomicRead &atomicRead) {
mlir::Location loc = converter.genLocation(atomicRead.source);
@@ -2487,7 +2487,7 @@ static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
semantics::SemanticsContext &semaCtx,
lower::pft::Evaluation &eval,
const parser::OpenMPConstruct &ompConstruct) {
- std::visit(
+ Fortran::common::visit(
[&](auto &&s) { return genOMP(converter, symTable, semaCtx, eval, s); },
ompConstruct.u);
}
@@ -2649,21 +2649,22 @@ void Fortran::lower::gatherOpenMPDeferredDeclareTargets(
const parser::OpenMPDeclarativeConstruct &ompDecl,
llvm::SmallVectorImpl<OMPDeferredDeclareTargetInfo>
&deferredDeclareTarget) {
- std::visit(common::visitors{
- [&](const parser::OpenMPDeclareTargetConstruct &ompReq) {
- collectDeferredDeclareTargets(converter, semaCtx, eval,
- ompReq, deferredDeclareTarget);
- },
- [&](const auto &) {},
- },
- ompDecl.u);
+ Fortran::common::visit(
+ common::visitors{
+ [&](const parser::OpenMPDeclareTargetConstruct &ompReq) {
+ collectDeferredDeclareTargets(converter, semaCtx, eval, ompReq,
+ deferredDeclareTarget);
+ },
+ [&](const auto &) {},
+ },
+ ompDecl.u);
}
bool Fortran::lower::isOpenMPDeviceDeclareTarget(
lower::AbstractConverter &converter, semantics::SemanticsContext &semaCtx,
lower::pft::Evaluation &eval,
const parser::OpenMPDeclarativeConstruct &ompDecl) {
- return std::visit(
+ return Fortran::common::visit(
common::visitors{
[&](const parser::OpenMPDeclareTargetConstruct &ompReq) {
mlir::omp::DeclareTargetDeviceType targetType =
diff --git a/flang/lib/Lower/OpenMP/Utils.cpp b/flang/lib/Lower/OpenMP/Utils.cpp
index 36d96f37ff36a..8aeef175ad2d2 100644
--- a/flang/lib/Lower/OpenMP/Utils.cpp
+++ b/flang/lib/Lower/OpenMP/Utils.cpp
@@ -325,7 +325,7 @@ void insertChildMapInfoIntoParent(
semantics::Symbol *getOmpObjectSymbol(const parser::OmpObject &ompObject) {
semantics::Symbol *sym = nullptr;
- std::visit(
+ Fortran::common::visit(
common::visitors{
[&](const parser::Designator &designator) {
if (auto *arrayEle =
diff --git a/flang/lib/Lower/PFTBuilder.cpp b/flang/lib/Lower/PFTBuilder.cpp
index fc34895d1ec75..5b3d5471925bf 100644
--- a/flang/lib/Lower/PFTBuilder.cpp
+++ b/flang/lib/Lower/PFTBuilder.cpp
@@ -103,7 +103,7 @@ class PFTBuilder {
stmt.unwrapped, pftParentStack.back(), stmt.position, stmt.label});
return false;
} else if constexpr (std::is_same_v<T, parser::ActionStmt>) {
- return std::visit(
+ return Fortran::common::visit(
common::visitors{
[&](const common::Indirection<parser::CallStmt> &x) {
addEvaluation(lower::pft::Evaluation{
@@ -239,7 +239,7 @@ class PFTBuilder {
// Get rid of production wrapper
bool Pre(const parser::Statement<parser::ForallAssignmentStmt> &statement) {
- addEvaluation(std::visit(
+ addEvaluation(Fortran::common::visit(
[&](const auto &x) {
return lower::pft::Evaluation{x, pftParentStack.back(),
statement.source, statement.label};
@@ -248,7 +248,7 @@ class PFTBuilder {
return false;
}
bool Pre(const parser::WhereBodyConstruct &whereBody) {
- return std::visit(
+ return Fortran::common::visit(
common::visitors{
[&](const parser::Statement<parser::AssignmentStmt> &stmt) {
// Not caught as other AssignmentStmt because it is not
@@ -469,7 +469,7 @@ class PFTBuilder {
makeEvaluationAction(const parser::ActionStmt &statement,
parser::CharBlock position,
std::optional<parser::Label> label) {
- return std::visit(
+ return Fortran::common::visit(
common::visitors{
[&](const auto &x) {
return lower::pft::Evaluation{
@@ -664,7 +664,7 @@ class PFTBuilder {
};
auto analyzeSpecs{[&](const auto &specList) {
for (const auto &spec : specList) {
- std::visit(
+ Fortran::common::visit(
Fortran::common::visitors{
[&](const Fortran::parser::Format &format) {
analyzeFormatSpec(format);
@@ -1172,26 +1172,27 @@ class PFTDumper {
void dumpPFT(llvm::raw_ostream &outputStream,
const lower::pft::Program &pft) {
for (auto &unit : pft.getUnits()) {
- std::visit(common::visitors{
- [&](const lower::pft::BlockDataUnit &unit) {
- outputStream << getNodeIndex(unit) << " ";
- outputStream << "BlockData: ";
- outputStream << "\nEnd BlockData\n\n";
- },
- [&](const lower::pft::FunctionLikeUnit &func) {
- dumpFunctionLikeUnit(outputStream, func);
- },
- [&](const lower::pft::ModuleLikeUnit &unit) {
- dumpModuleLikeUnit(outputStream, unit);
- },
- [&](const lower::pft::CompilerDirectiveUnit &unit) {
- dumpCompilerDirectiveUnit(outputStream, unit);
- },
- [&](const lower::pft::OpenACCDirectiveUnit &unit) {
- dumpOpenACCDirectiveUnit(outputStream, unit);
- },
- },
- unit);
+ Fortran::common::visit(
+ common::visitors{
+ [&](const lower::pft::BlockDataUnit &unit) {
+ outputStream << getNodeIndex(unit) << " ";
+ outputStream << "BlockData: ";
+ outputStream << "\nEnd BlockData\n\n";
+ },
+ [&](const lower::pft::FunctionLikeUnit &func) {
+ dumpFunctionLikeUnit(outputStream, func);
+ },
+ [&](const lower::pft::ModuleLikeUnit &unit) {
+ dumpModuleLikeUnit(outputStream, unit);
+ },
+ [&](const lower::pft::CompilerDirectiveUnit &unit) {
+ dumpCompilerDirectiveUnit(outputStream, unit);
+ },
+ [&](const lower::pft::OpenACCDirectiveUnit &unit) {
+ dumpOpenACCDirectiveUnit(outputStream, unit);
+ },
+ },
+ unit);
}
}
diff --git a/flang/lib/Lower/VectorSubscripts.cpp b/flang/lib/Lower/VectorSubscripts.cpp
index d7a311d32d59d..389a89ddcf102 100644
--- a/flang/lib/Lower/VectorSubscripts.cpp
+++ b/flang/lib/Lower/VectorSubscripts.cpp
@@ -55,10 +55,11 @@ class VectorSubscriptBoxBuilder {
using Designator = Fortran::evaluate::Designator<T>;
if constexpr (Fortran::common::HasMember<Designator, ExprVariant>) {
const auto &designator = std::get<Designator>(expr.u);
- return std::visit([&](const auto &x) { return gen(x); }, designator.u);
+ return Fortran::common::visit([&](const auto &x) { return gen(x); },
+ designator.u);
} else {
- return std::visit([&](const auto &x) { return genDesignator(x); },
- expr.u);
+ return Fortran::common::visit(
+ [&](const auto &x) { return genDesignator(x); }, expr.u);
}
}
@@ -66,8 +67,8 @@ class VectorSubscriptBoxBuilder {
// type of X elements.
mlir::Type gen(const Fortran::evaluate::DataRef &dataRef) {
- return std::visit([&](const auto &ref) -> mlir::Type { return gen(ref); },
- dataRef.u);
+ return Fortran::common::visit(
+ [&](const auto &ref) -> mlir::Type { return gen(ref); }, dataRef.u);
}
mlir::Type gen(const Fortran::evaluate::SymbolRef &symRef) {
@@ -128,7 +129,7 @@ class VectorSubscriptBoxBuilder {
mlir::Type gen(const Fortran::evaluate::ArrayRef &arrayRef) {
auto isTripletOrVector =
[](const Fortran::evaluate::Subscript &subscript) -> bool {
- return std::visit(
+ return Fortran::common::visit(
Fortran::common::visitors{
[](const Fortran::evaluate::IndirectSubscriptIntegerExpr &expr) {
return expr.value().Rank() != 0;
@@ -165,7 +166,7 @@ class VectorSubscriptBoxBuilder {
mlir::Type idxTy = builder.getIndexType();
mlir::Value one = builder.createIntegerConstant(loc, idxTy, 1);
for (const auto &subscript : llvm::enumerate(arrayRef.subscript())) {
- std::visit(
+ Fortran::common::visit(
Fortran::common::visitors{
[&](const Fortran::evaluate::IndirectSubscriptIntegerExpr &expr) {
if (expr.value().Rank() == 0) {
@@ -327,24 +328,24 @@ Fortran::lower::VectorSubscriptBox::createSlice(fir::FirOpBuilder &builder,
mlir::Value one = builder.createIntegerConstant(loc, idxTy, 1);
auto undef = builder.create<fir::UndefOp>(loc, idxTy);
for (const LoweredSubscript &subscript : loweredSubscripts)
- std::visit(Fortran::common::visitors{
- [&](const LoweredTriplet &triplet) {
- triples.emplace_back(triplet.lb);
- triples.emplace_back(triplet.ub);
- triples.emplace_back(triplet.stride);
- },
- [&](const LoweredVectorSubscript &vector) {
- triples.emplace_back(one);
- triples.emplace_back(vector.size);
- triples.emplace_back(one);
- },
- [&](const mlir::Value &i) {
- triples.emplace_back(i);
- triples.emplace_back(undef);
- triples.emplace_back(undef);
- },
- },
- subscript);
+ Fortran::common::visit(Fortran::common::visitors{
+ [&](const LoweredTriplet &triplet) {
+ triples.emplace_back(triplet.lb);
+ triples.emplace_back(triplet.ub);
+ triples.emplace_back(triplet.stride);
+ },
+ [&](const LoweredVectorSubscript &vector) {
+ triples.emplace_back(one);
+ triples.emplace_back(vector.size);
+ triples.emplace_back(one);
+ },
+ [&](const mlir::Value &i) {
+ triples.emplace_back(i);
+ triples.emplace_back(undef);
+ triples.emplace_back(undef);
+ },
+ },
+ subscript);
return builder.create<fir::SliceOp>(loc, triples, componentPath);
}
@@ -390,28 +391,28 @@ fir::ExtendedValue Fortran::lower::VectorSubscriptBox::getElementAt(
llvm::SmallVector<mlir::Value> indexes;
size_t inductionIdx = inductionVariables.size() - 1;
for (const LoweredSubscript &subscript : loweredSubscripts)
- std::visit(Fortran::common::visitors{
- [&](const LoweredTriplet &triplet) {
- indexes.emplace_back(inductionVariables[inductionIdx--]);
- },
- [&](const LoweredVectorSubscript &vector) {
- mlir::Value vecIndex = inductionVariables[inductionIdx--];
- mlir::Value vecBase = fir::getBase(vector.vector);
- mlir::Type vecEleTy = fir::unwrapSequenceType(
- fir::unwrapPassByRefType(vecBase.getType()));
- mlir::Type refTy = builder.getRefType(vecEleTy);
- auto vecEltRef = builder.create<fir::CoordinateOp>(
- loc, refTy, vecBase, vecIndex);
- auto vecElt =
- builder.create<fir::LoadOp>(loc, vecEleTy, vecEltRef);
- indexes.emplace_back(
- builder.createConvert(loc, idxTy, vecElt));
- },
- [&](const mlir::Value &i) {
- indexes.emplace_back(builder.createConvert(loc, idxTy, i));
- },
- },
- subscript);
+ Fortran::common::visit(
+ Fortran::common::visitors{
+ [&](const LoweredTriplet &triplet) {
+ indexes.emplace_back(inductionVariables[inductionIdx--]);
+ },
+ [&](const LoweredVectorSubscript &vector) {
+ mlir::Value vecIndex = inductionVariables[inductionIdx--];
+ mlir::Value vecBase = fir::getBase(vector.vector);
+ mlir::Type vecEleTy = fir::unwrapSequenceType(
+ fir::unwrapPassByRefType(vecBase.getType()));
+ mlir::Type refTy = builder.getRefType(vecEleTy);
+ auto vecEltRef = builder.create<fir::CoordinateOp>(
+ loc, refTy, vecBase, vecIndex);
+ auto vecElt =
+ builder.create<fir::LoadOp>(loc, vecEleTy, vecEltRef);
+ indexes.emplace_back(builder.createConvert(loc, idxTy, vecElt));
+ },
+ [&](const mlir::Value &i) {
+ indexes.emplace_back(builder.createConvert(loc, idxTy, i));
+ },
+ },
+ subscript);
mlir::Type refTy = builder.getRefType(getElementType());
auto elementAddr = builder.create<fir::ArrayCoorOp>(
loc, refTy, fir::getBase(loweredBase), shape, slice, indexes,
diff --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
index ab106f62aecfb..c929d05038462 100644
--- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
+++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
@@ -1788,7 +1788,7 @@ IntrinsicLibrary::genIntrinsicCall(llvm::StringRef specificName,
llvm::StringRef name = genericName(specificName);
if (const IntrinsicHandler *handler = findIntrinsicHandler(name)) {
bool outline = handler->outline || outlineAllIntrinsics;
- return {std::visit(
+ return {Fortran::common::visit(
[&](auto &generator) -> fir::ExtendedValue {
return invokeHandler(generator, *handler, resultType, args,
outline, *this);
@@ -1802,7 +1802,7 @@ IntrinsicLibrary::genIntrinsicCall(llvm::StringRef specificName,
if (fir::getTargetTriple(mod).isPPC()) {
if (const IntrinsicHandler *ppcHandler = findPPCIntrinsicHandler(name)) {
bool outline = ppcHandler->outline || outlineAllIntrinsics;
- return {std::visit(
+ return {Fortran::common::visit(
[&](auto &generator) -> fir::ExtendedValue {
return invokeHandler(generator, *ppcHandler, resultType,
args, outline, *this);
@@ -2136,7 +2136,7 @@ mlir::SymbolRefAttr IntrinsicLibrary::getUnrestrictedIntrinsicSymbolRefAttr(
bool loadRefArguments = true;
mlir::func::FuncOp funcOp;
if (const IntrinsicHandler *handler = findIntrinsicHandler(name))
- funcOp = std::visit(
+ funcOp = Fortran::common::visit(
[&](auto generator) {
return getWrapper(generator, name, signature, loadRefArguments);
},
diff --git a/flang/lib/Semantics/check-acc-structure.cpp b/flang/lib/Semantics/check-acc-structure.cpp
index 69b9fe17e6a88..25140a0473749 100644
--- a/flang/lib/Semantics/check-acc-structure.cpp
+++ b/flang/lib/Semantics/check-acc-structure.cpp
@@ -403,9 +403,9 @@ void AccStructureChecker::CheckMultipleOccurrenceInDeclare(
if (GetContext().directive != llvm::acc::Directive::ACCD_declare)
return;
for (const auto &object : list.v) {
- std::visit(
- Fortran::common::visitors{
- [&](const Fortran::parser::Designator &designator) {
+ common::visit(
+ common::visitors{
+ [&](const parser::Designator &designator) {
if (const auto *name = getDesignatorNameIfDataRef(designator)) {
if (declareSymbols.contains(&name->symbol->GetUltimate())) {
if (declareSymbols[&name->symbol->GetUltimate()] == clause) {
@@ -435,7 +435,7 @@ void AccStructureChecker::CheckMultipleOccurrenceInDeclare(
declareSymbols.insert({&name->symbol->GetUltimate(), clause});
}
},
- [&](const Fortran::parser::Name &name) {
+ [&](const parser::Name &name) {
// TODO: check common block
}},
object.u);
@@ -674,9 +674,9 @@ void AccStructureChecker::Enter(const parser::AccClause::Reduction &reduction) {
const auto &objects{std::get<parser::AccObjectList>(list.t)};
for (const auto &object : objects.v) {
- std::visit(
- Fortran::common::visitors{
- [&](const Fortran::parser::Designator &designator) {
+ common::visit(
+ common::visitors{
+ [&](const parser::Designator &designator) {
if (const auto *name = getDesignatorNameIfDataRef(designator)) {
const auto *type{name->symbol->GetType()};
if (type->IsNumeric(TypeCategory::Integer) &&
diff --git a/flang/lib/Semantics/check-coarray.cpp b/flang/lib/Semantics/check-coarray.cpp
index 106af7960fa94..6cf61a6b923db 100644
--- a/flang/lib/Semantics/check-coarray.cpp
+++ b/flang/lib/Semantics/check-coarray.cpp
@@ -93,7 +93,7 @@ static void CheckCoindexedStatOrErrmsg(SemanticsContext &context,
}
}
}};
- std::visit(CoindexedCheck, statOrErrmsg.u);
+ Fortran::common::visit(CoindexedCheck, statOrErrmsg.u);
}
static void CheckSyncStatList(
More information about the flang-commits
mailing list