Skip to content

Commit 554be97

Browse files
authored
[flang][OpenMP] Implement getIterationVariableSymbol helper function,… (#90087)
… NFC
1 parent fbe8d2a commit 554be97

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

flang/lib/Lower/OpenMP/Utils.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "Utils.h"
14-
#include "Clauses.h"
1514

15+
#include "Clauses.h"
1616
#include <flang/Lower/AbstractConverter.h>
1717
#include <flang/Lower/ConvertType.h>
18+
#include <flang/Lower/PFTBuilder.h>
1819
#include <flang/Optimizer/Builder/FIRBuilder.h>
1920
#include <flang/Parser/parse-tree.h>
2021
#include <flang/Parser/tools.h>
@@ -47,6 +48,12 @@ int64_t getCollapseValue(const List<Clause> &clauses) {
4748
return 1;
4849
}
4950

51+
uint32_t getOpenMPVersion(mlir::ModuleOp mod) {
52+
if (mlir::Attribute verAttr = mod->getAttr("omp.version"))
53+
return llvm::cast<mlir::omp::VersionAttr>(verAttr).getVersion();
54+
llvm_unreachable("Expecting OpenMP version attribute in module");
55+
}
56+
5057
void genObjectList(const ObjectList &objects,
5158
Fortran::lower::AbstractConverter &converter,
5259
llvm::SmallVectorImpl<mlir::Value> &operands) {
@@ -81,6 +88,27 @@ mlir::Type getLoopVarType(Fortran::lower::AbstractConverter &converter,
8188
return converter.getFirOpBuilder().getIntegerType(loopVarTypeSize);
8289
}
8390

91+
Fortran::semantics::Symbol *
92+
getIterationVariableSymbol(const Fortran::lower::pft::Evaluation &eval) {
93+
return eval.visit(Fortran::common::visitors{
94+
[&](const Fortran::parser::DoConstruct &doLoop) {
95+
if (const auto &maybeCtrl = doLoop.GetLoopControl()) {
96+
using LoopControl = Fortran::parser::LoopControl;
97+
if (auto *bounds = std::get_if<LoopControl::Bounds>(&maybeCtrl->u)) {
98+
static_assert(
99+
std::is_same_v<decltype(bounds->name),
100+
Fortran::parser::Scalar<Fortran::parser::Name>>);
101+
return bounds->name.thing.symbol;
102+
}
103+
}
104+
return static_cast<Fortran::semantics::Symbol *>(nullptr);
105+
},
106+
[](auto &&) {
107+
return static_cast<Fortran::semantics::Symbol *>(nullptr);
108+
},
109+
});
110+
}
111+
84112
void gatherFuncAndVarSyms(
85113
const ObjectList &objects, mlir::omp::DeclareTargetCaptureClause clause,
86114
llvm::SmallVectorImpl<DeclareTargetCapturePair> &symbolAndClause) {

flang/lib/Lower/OpenMP/Utils.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ struct OmpObjectList;
3434
} // namespace parser
3535

3636
namespace lower {
37+
namespace pft {
38+
struct Evaluation;
39+
}
3740

3841
class AbstractConverter;
3942

@@ -54,11 +57,15 @@ createMapInfoOp(fir::FirOpBuilder &builder, mlir::Location loc,
5457
mlir::Type getLoopVarType(Fortran::lower::AbstractConverter &converter,
5558
std::size_t loopVarTypeSize);
5659

60+
Fortran::semantics::Symbol *
61+
getIterationVariableSymbol(const Fortran::lower::pft::Evaluation &eval);
62+
5763
void gatherFuncAndVarSyms(
5864
const ObjectList &objects, mlir::omp::DeclareTargetCaptureClause clause,
5965
llvm::SmallVectorImpl<DeclareTargetCapturePair> &symbolAndClause);
6066

6167
int64_t getCollapseValue(const List<Clause> &clauses);
68+
uint32_t getOpenMPVersion(mlir::ModuleOp mod);
6269

6370
Fortran::semantics::Symbol *
6471
getOmpObjectSymbol(const Fortran::parser::OmpObject &ompObject);

0 commit comments

Comments
 (0)