[flang] [llvm] [flang][OpenMP] Store list of expressions in InitializerT (PR #170923)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 5 13:14:01 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-openmp
Author: Krzysztof Parzyszek (kparzysz)
<details>
<summary>Changes</summary>
The INITIALIZER clause holds a stylized expression that can be intiantiated with different types. Currently, the InitializerT class only holds one expression, which happens to correspond to the first type in the DECLARE_REDUCTION type list.
Change InitializerT to hold a list of expressions instead, one for each type. Keep the lowering code unchanged by picking the first expression from the list.
---
Full diff: https://github.com/llvm/llvm-project/pull/170923.diff
3 Files Affected:
- (modified) flang/lib/Lower/OpenMP/ClauseProcessor.cpp (+3-2)
- (modified) flang/lib/Lower/OpenMP/Clauses.cpp (+13-11)
- (modified) llvm/include/llvm/Frontend/OpenMP/ClauseT.h (+2-1)
``````````diff
diff --git a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
index a81ba37856492..451b53e71b31b 100644
--- a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
+++ b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
@@ -412,6 +412,7 @@ bool ClauseProcessor::processInitializer(
}
// Lower the expression/function call
lower::StatementContext stmtCtx;
+ const semantics::SomeExpr &initExpr = clause->v.front();
mlir::Value result = common::visit(
common::visitors{
[&](const evaluate::ProcedureRef &procRef) -> mlir::Value {
@@ -422,7 +423,7 @@ bool ClauseProcessor::processInitializer(
},
[&](const auto &expr) -> mlir::Value {
mlir::Value exprResult = fir::getBase(convertExprToValue(
- loc, converter, clause->v, symMap, stmtCtx));
+ loc, converter, initExpr, symMap, stmtCtx));
// Conversion can either give a value or a refrence to a value,
// we need to return the reduction type, so an optional load may
// be generated.
@@ -432,7 +433,7 @@ bool ClauseProcessor::processInitializer(
exprResult = fir::LoadOp::create(builder, loc, exprResult);
return exprResult;
}},
- clause->v.u);
+ initExpr.u);
stmtCtx.finalizeAndPop();
return result;
};
diff --git a/flang/lib/Lower/OpenMP/Clauses.cpp b/flang/lib/Lower/OpenMP/Clauses.cpp
index 61430fceafe2a..5893b4fcdf3f7 100644
--- a/flang/lib/Lower/OpenMP/Clauses.cpp
+++ b/flang/lib/Lower/OpenMP/Clauses.cpp
@@ -982,21 +982,23 @@ Init make(const parser::OmpClause::Init &inp,
Initializer make(const parser::OmpClause::Initializer &inp,
semantics::SemanticsContext &semaCtx) {
const parser::OmpInitializerExpression &iexpr = inp.v.v;
- const parser::OmpStylizedInstance &styleInstance = iexpr.v.front();
- const parser::OmpStylizedInstance::Instance &instance =
- std::get<parser::OmpStylizedInstance::Instance>(styleInstance.t);
- if (const auto *as = std::get_if<parser::AssignmentStmt>(&instance.u)) {
- auto &expr = std::get<parser::Expr>(as->t);
- return Initializer{makeExpr(expr, semaCtx)};
- } else if (const auto *call = std::get_if<parser::CallStmt>(&instance.u)) {
- if (call->typedCall) {
+ Initializer initializer;
+ for (const parser::OmpStylizedInstance &styleInstance : iexpr.v) {
+ auto &instance =
+ std::get<parser::OmpStylizedInstance::Instance>(styleInstance.t);
+ if (const auto *as = std::get_if<parser::AssignmentStmt>(&instance.u)) {
+ auto &expr = std::get<parser::Expr>(as->t);
+ initializer.v.push_back(makeExpr(expr, semaCtx));
+ } else if (const auto *call = std::get_if<parser::CallStmt>(&instance.u)) {
+ assert(call->typedCall && "Expecting typedCall");
const auto &procRef = *call->typedCall;
- semantics::SomeExpr evalProcRef{procRef};
- return Initializer{evalProcRef};
+ initializer.v.push_back(semantics::SomeExpr(procRef));
+ } else {
+ llvm_unreachable("Unexpected initializer");
}
}
- llvm_unreachable("Unexpected initializer");
+ return initializer;
}
InReduction make(const parser::OmpClause::InReduction &inp,
diff --git a/llvm/include/llvm/Frontend/OpenMP/ClauseT.h b/llvm/include/llvm/Frontend/OpenMP/ClauseT.h
index eb0e4a828eb1e..cf401711173e7 100644
--- a/llvm/include/llvm/Frontend/OpenMP/ClauseT.h
+++ b/llvm/include/llvm/Frontend/OpenMP/ClauseT.h
@@ -763,8 +763,9 @@ struct InitT {
template <typename T, typename I, typename E> //
struct InitializerT {
using InitializerExpr = E;
+ using List = ListT<InitializerExpr>;
using WrapperTrait = std::true_type;
- InitializerExpr v;
+ List v;
};
// V5.2: [5.5.10] `in_reduction` clause
``````````
</details>
https://github.com/llvm/llvm-project/pull/170923
More information about the llvm-commits
mailing list