-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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
Conversation
@llvm/pr-subscribers-flang-fir-hlfir Author: Krzysztof Parzyszek (kparzysz) Changes… NFC Full diff: https://github.com/llvm/llvm-project/pull/90087.diff 2 Files Affected:
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);
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LG.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LG
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, LGTM. Just a small comment.
@@ -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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
… NFC