https://github.com/kparzysz created https://github.com/llvm/llvm-project/pull/90087
… NFC >From 45d5017db069a8804fbdb75da223b68cbaab11f2 Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek <krzysztof.parzys...@amd.com> Date: Tue, 26 Mar 2024 10:14:13 -0500 Subject: [PATCH] [flang][OpenMP] Implement getIterationVariableSymbol helper function, NFC --- flang/lib/Lower/OpenMP/Utils.cpp | 24 +++++++++++++++++++++++- flang/lib/Lower/OpenMP/Utils.h | 6 ++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/flang/lib/Lower/OpenMP/Utils.cpp b/flang/lib/Lower/OpenMP/Utils.cpp index 1400f1f4cc8dd2..c38e0c18cac88c 100644 --- a/flang/lib/Lower/OpenMP/Utils.cpp +++ b/flang/lib/Lower/OpenMP/Utils.cpp @@ -11,10 +11,11 @@ //===----------------------------------------------------------------------===// #include "Utils.h" -#include "Clauses.h" +#include "Clauses.h" #include <flang/Lower/AbstractConverter.h> #include <flang/Lower/ConvertType.h> +#include <flang/Lower/PFTBuilder.h> #include <flang/Optimizer/Builder/FIRBuilder.h> #include <flang/Parser/parse-tree.h> #include <flang/Parser/tools.h> @@ -87,6 +88,27 @@ mlir::Type getLoopVarType(Fortran::lower::AbstractConverter &converter, return converter.getFirOpBuilder().getIntegerType(loopVarTypeSize); } +Fortran::semantics::Symbol * +getIterationVariableSymbol(const Fortran::lower::pft::Evaluation &eval) { + return eval.visit(Fortran::common::visitors{ + [&](const Fortran::parser::DoConstruct &doLoop) { + if (const auto &maybeCtrl = doLoop.GetLoopControl()) { + using LoopControl = Fortran::parser::LoopControl; + if (auto *bounds = std::get_if<LoopControl::Bounds>(&maybeCtrl->u)) { + static_assert( + std::is_same_v<decltype(bounds->name), + Fortran::parser::Scalar<Fortran::parser::Name>>); + return bounds->name.thing.symbol; + } + } + return static_cast<Fortran::semantics::Symbol *>(nullptr); + }, + [](auto &&) { + return static_cast<Fortran::semantics::Symbol *>(nullptr); + }, + }); +} + void gatherFuncAndVarSyms( const ObjectList &objects, mlir::omp::DeclareTargetCaptureClause clause, llvm::SmallVectorImpl<DeclareTargetCapturePair> &symbolAndClause) { diff --git a/flang/lib/Lower/OpenMP/Utils.h b/flang/lib/Lower/OpenMP/Utils.h index 693a91f7cc6954..5e0ebba23bf358 100644 --- a/flang/lib/Lower/OpenMP/Utils.h +++ b/flang/lib/Lower/OpenMP/Utils.h @@ -34,6 +34,9 @@ struct OmpObjectList; } // namespace parser namespace lower { +namespace pft { +struct Evaluation; +} class AbstractConverter; @@ -54,6 +57,9 @@ createMapInfoOp(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type getLoopVarType(Fortran::lower::AbstractConverter &converter, std::size_t loopVarTypeSize); +Fortran::semantics::Symbol * +getIterationVariableSymbol(const Fortran::lower::pft::Evaluation &eval); + void gatherFuncAndVarSyms( const ObjectList &objects, mlir::omp::DeclareTargetCaptureClause clause, llvm::SmallVectorImpl<DeclareTargetCapturePair> &symbolAndClause); _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits