Skip to content

[flang][OpenMP] Implement getIterationVariableSymbol helper function,… #90087

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion flang/lib/Lower/OpenMP/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -47,6 +48,12 @@ int64_t getCollapseValue(const List<Clause> &clauses) {
return 1;
}

uint32_t getOpenMPVersion(mlir::ModuleOp mod) {
if (mlir::Attribute verAttr = mod->getAttr("omp.version"))
return llvm::cast<mlir::omp::VersionAttr>(verAttr).getVersion();
llvm_unreachable("Expecting OpenMP version attribute in module");
}

void genObjectList(const ObjectList &objects,
Fortran::lower::AbstractConverter &converter,
llvm::SmallVectorImpl<mlir::Value> &operands) {
Expand Down Expand Up @@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Since it's not really OpenMP-specific, maybe flang/include/flang/Lower/Support/Utils.h would be a better place to put it, though that would probably require adding the corresponding .cpp file (that header currently only has inline definitions). I'll leave it up to you to do that, find a more suitable spot or just leave it where it is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can consider this for another PR.

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) {
Expand Down
7 changes: 7 additions & 0 deletions flang/lib/Lower/OpenMP/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ struct OmpObjectList;
} // namespace parser

namespace lower {
namespace pft {
struct Evaluation;
}

class AbstractConverter;

Expand All @@ -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<DeclareTargetCapturePair> &symbolAndClause);

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

Fortran::semantics::Symbol *
getOmpObjectSymbol(const Fortran::parser::OmpObject &ompObject);
Expand Down