Skip to content
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
8 changes: 8 additions & 0 deletions flang/lib/Lower/Bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
#include "mlir/Parser/Parser.h"
#include "mlir/Support/StateStack.h"
#include "mlir/Transforms/RegionUtils.h"
#include "llvm/ADT/ScopeExit.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/Support/CommandLine.h"
Expand Down Expand Up @@ -2198,6 +2199,11 @@ class FirConverter : public Fortran::lower::AbstractConverter {
// Loops with induction variables inside OpenACC compute constructs
// need special handling to ensure that the IVs are privatized.
if (Fortran::lower::isInsideOpenACCComputeConstruct(*builder)) {
// Open up a new scope for the loop variables.
localSymbols.pushScope();
auto scopeGuard =
llvm::make_scope_exit([&]() { localSymbols.popScope(); });

mlir::Operation *loopOp = Fortran::lower::genOpenACCLoopFromDoConstruct(
*this, bridge.getSemanticsContext(), localSymbols, doConstruct, eval);
bool success = loopOp != nullptr;
Expand All @@ -2214,6 +2220,8 @@ class FirConverter : public Fortran::lower::AbstractConverter {
for (auto end = --eval.getNestedEvaluations().end(); iter != end;
++iter)
genFIR(*iter, unstructuredContext);

builder->setInsertionPointAfter(loopOp);
return;
}
// Fall back to normal loop handling.
Expand Down
12 changes: 8 additions & 4 deletions flang/lib/Lower/OpenACC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ static llvm::cl::opt<bool> strideIncludeLowerExtent(
"Whether to include the lower dimensions extents in the stride."),
llvm::cl::init(true));

static llvm::cl::opt<bool> lowerDoLoopToAccLoop(
"openacc-do-loop-to-acc-loop",
llvm::cl::desc("Whether to lower do loops as `acc.loop` operations."),
llvm::cl::init(true));

// Special value for * passed in device_type or gang clauses.
static constexpr std::int64_t starCst = -1;

Expand Down Expand Up @@ -5005,6 +5010,9 @@ mlir::Operation *Fortran::lower::genOpenACCLoopFromDoConstruct(
Fortran::semantics::SemanticsContext &semanticsContext,
Fortran::lower::SymMap &localSymbols,
const Fortran::parser::DoConstruct &doConstruct, pft::Evaluation &eval) {
if (!lowerDoLoopToAccLoop)
return nullptr;

// Only convert loops which have induction variables that need privatized.
if (!doConstruct.IsDoNormal() && !doConstruct.IsDoConcurrent())
return nullptr;
Expand All @@ -5027,10 +5035,6 @@ mlir::Operation *Fortran::lower::genOpenACCLoopFromDoConstruct(
return nullptr;
}

// Open up a new scope for the loop variables.
localSymbols.pushScope();
auto scopeGuard = llvm::make_scope_exit([&]() { localSymbols.popScope(); });

// Prepare empty operand vectors since there are no associated `acc loop`
// clauses with the Fortran do loops being handled here.
llvm::SmallVector<mlir::Value> privateOperands, gangOperands,
Expand Down
Loading