diff --git a/flang/lib/Lower/OpenMP/Utils.cpp b/flang/lib/Lower/OpenMP/Utils.cpp index da3f2be73e509..c38e0c18cac88 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 #include +#include #include #include #include @@ -47,6 +48,12 @@ int64_t getCollapseValue(const List &clauses) { return 1; } +uint32_t getOpenMPVersion(mlir::ModuleOp mod) { + if (mlir::Attribute verAttr = mod->getAttr("omp.version")) + return llvm::cast(verAttr).getVersion(); + llvm_unreachable("Expecting OpenMP version attribute in module"); +} + void genObjectList(const ObjectList &objects, Fortran::lower::AbstractConverter &converter, llvm::SmallVectorImpl &operands) { @@ -81,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(&maybeCtrl->u)) { + static_assert( + std::is_same_vname), + Fortran::parser::Scalar>); + return bounds->name.thing.symbol; + } + } + return static_cast(nullptr); + }, + [](auto &&) { + return static_cast(nullptr); + }, + }); +} + void gatherFuncAndVarSyms( const ObjectList &objects, mlir::omp::DeclareTargetCaptureClause clause, llvm::SmallVectorImpl &symbolAndClause) { diff --git a/flang/lib/Lower/OpenMP/Utils.h b/flang/lib/Lower/OpenMP/Utils.h index b3a9f7f30c98b..5e0ebba23bf35 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,11 +57,15 @@ 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 &symbolAndClause); int64_t getCollapseValue(const List &clauses); +uint32_t getOpenMPVersion(mlir::ModuleOp mod); Fortran::semantics::Symbol * getOmpObjectSymbol(const Fortran::parser::OmpObject &ompObject);