Skip to content

Commit bfce025

Browse files
authored
[flang][OpenMP] Store list of expressions in InitializerT (#170923)
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.
1 parent 8445909 commit bfce025

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

flang/lib/Lower/OpenMP/ClauseProcessor.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ bool ClauseProcessor::processInitializer(
412412
}
413413
// Lower the expression/function call
414414
lower::StatementContext stmtCtx;
415+
const semantics::SomeExpr &initExpr = clause->v.front();
415416
mlir::Value result = common::visit(
416417
common::visitors{
417418
[&](const evaluate::ProcedureRef &procRef) -> mlir::Value {
@@ -422,7 +423,7 @@ bool ClauseProcessor::processInitializer(
422423
},
423424
[&](const auto &expr) -> mlir::Value {
424425
mlir::Value exprResult = fir::getBase(convertExprToValue(
425-
loc, converter, clause->v, symMap, stmtCtx));
426+
loc, converter, initExpr, symMap, stmtCtx));
426427
// Conversion can either give a value or a refrence to a value,
427428
// we need to return the reduction type, so an optional load may
428429
// be generated.
@@ -432,7 +433,7 @@ bool ClauseProcessor::processInitializer(
432433
exprResult = fir::LoadOp::create(builder, loc, exprResult);
433434
return exprResult;
434435
}},
435-
clause->v.u);
436+
initExpr.u);
436437
stmtCtx.finalizeAndPop();
437438
return result;
438439
};

flang/lib/Lower/OpenMP/Clauses.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -982,21 +982,23 @@ Init make(const parser::OmpClause::Init &inp,
982982
Initializer make(const parser::OmpClause::Initializer &inp,
983983
semantics::SemanticsContext &semaCtx) {
984984
const parser::OmpInitializerExpression &iexpr = inp.v.v;
985-
const parser::OmpStylizedInstance &styleInstance = iexpr.v.front();
986-
const parser::OmpStylizedInstance::Instance &instance =
987-
std::get<parser::OmpStylizedInstance::Instance>(styleInstance.t);
988-
if (const auto *as = std::get_if<parser::AssignmentStmt>(&instance.u)) {
989-
auto &expr = std::get<parser::Expr>(as->t);
990-
return Initializer{makeExpr(expr, semaCtx)};
991-
} else if (const auto *call = std::get_if<parser::CallStmt>(&instance.u)) {
992-
if (call->typedCall) {
985+
Initializer initializer;
986+
for (const parser::OmpStylizedInstance &styleInstance : iexpr.v) {
987+
auto &instance =
988+
std::get<parser::OmpStylizedInstance::Instance>(styleInstance.t);
989+
if (const auto *as = std::get_if<parser::AssignmentStmt>(&instance.u)) {
990+
auto &expr = std::get<parser::Expr>(as->t);
991+
initializer.v.push_back(makeExpr(expr, semaCtx));
992+
} else if (const auto *call = std::get_if<parser::CallStmt>(&instance.u)) {
993+
assert(call->typedCall && "Expecting typedCall");
993994
const auto &procRef = *call->typedCall;
994-
semantics::SomeExpr evalProcRef{procRef};
995-
return Initializer{evalProcRef};
995+
initializer.v.push_back(semantics::SomeExpr(procRef));
996+
} else {
997+
llvm_unreachable("Unexpected initializer");
996998
}
997999
}
9981000

999-
llvm_unreachable("Unexpected initializer");
1001+
return initializer;
10001002
}
10011003

10021004
InReduction make(const parser::OmpClause::InReduction &inp,

llvm/include/llvm/Frontend/OpenMP/ClauseT.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,8 +763,9 @@ struct InitT {
763763
template <typename T, typename I, typename E> //
764764
struct InitializerT {
765765
using InitializerExpr = E;
766+
using List = ListT<InitializerExpr>;
766767
using WrapperTrait = std::true_type;
767-
InitializerExpr v;
768+
List v;
768769
};
769770

770771
// V5.2: [5.5.10] `in_reduction` clause

0 commit comments

Comments
 (0)