Skip to content

Lower elemental subroutine calls (outside of user assignment case) #1069

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 1 commit into from
Sep 20, 2021
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
10 changes: 10 additions & 0 deletions flang/include/flang/Lower/ConvertExpr.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,16 @@ createSomeArrayBox(AbstractConverter &converter,
const evaluate::Expr<evaluate::SomeType> &expr,
SymMap &symMap, StatementContext &stmtCtx);

/// Lower a subroutine call. This handles both elemental and non elemental
/// subroutines. \p isUserDefAssignment must be set if this is called in the
/// context of a user defined assignment. For subroutines with alternate
/// returns, the returned value indicates which label the code should jump to.
/// The returned value is null otherwise.
mlir::Value createSubroutineCall(AbstractConverter &converter,
const evaluate::Expr<evaluate::SomeType> &call,
SymMap &symMap, StatementContext &stmtCtx,
bool isUserDefAssignment);

// Attribute for an alloca that is a trivial adaptor for converting a value to
// pass-by-ref semantics for a VALUE parameter. The optimizer may be able to
// eliminate these.
Expand Down
13 changes: 8 additions & 5 deletions flang/lib/Lower/Bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,8 @@ class FirConverter : public Fortran::lower::AbstractConverter {
assert(stmt.typedCall && "Call was not analyzed");
// Call statement lowering shares code with function call lowering.
Fortran::semantics::SomeExpr expr{*stmt.typedCall};
auto res = createFIRExpr(toLocation(), &expr, stmtCtx);
auto res = Fortran::lower::createSubroutineCall(
*this, expr, localSymbols, stmtCtx, /*isUserDefAssignment=*/false);
if (!res)
return; // "Normal" subroutine call.
// Call with alternate return specifiers.
Expand Down Expand Up @@ -1939,11 +1940,13 @@ class FirConverter : public Fortran::lower::AbstractConverter {
[&](const Fortran::evaluate::ProcedureRef &procRef) {
if (implicitIterationSpace())
TODO(loc, "user defined assignment within WHERE");

Fortran::semantics::SomeExpr expr{procRef};
createFIRExpr(toLocation(), &expr,
explicitIterationSpace()
? explicitIterSpace.stmtContext()
: stmtCtx);
auto &ctx = explicitIterationSpace()
? explicitIterSpace.stmtContext()
: stmtCtx;
Fortran::lower::createSubroutineCall(
*this, expr, localSymbols, ctx, /*isUserDefAssignment=*/true);
},

// [3] Pointer assignment with possibly empty bounds-spec. R1035: a
Expand Down
Loading