Skip to content
Closed
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
2 changes: 1 addition & 1 deletion flang/include/flang/Lower/Support/ReductionProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class ReductionProcessor {
/// Creates a reduction declaration and associates it with an OpenMP block
/// directive.
template <typename OpType, typename RedOperatorListTy>
static void processReductionArguments(
static bool processReductionArguments(
mlir::Location currentLocation, lower::AbstractConverter &converter,
const RedOperatorListTy &redOperatorList,
llvm::SmallVectorImpl<mlir::Value> &reductionVars,
Expand Down
3 changes: 2 additions & 1 deletion flang/lib/Lower/Bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2123,9 +2123,10 @@ class FirConverter : public Fortran::lower::AbstractConverter {

llvm::SmallVector<mlir::Value> reduceVars;
Fortran::lower::omp::ReductionProcessor rp;
rp.processReductionArguments<fir::DeclareReductionOp>(
bool result = rp.processReductionArguments<fir::DeclareReductionOp>(
toLocation(), *this, info.reduceOperatorList, reduceVars,
reduceVarByRef, reductionDeclSymbols, info.reduceSymList);
assert(result && "Failed to process `do concurrent` reductions");

doConcurrentLoopOp.getReduceVarsMutable().assign(reduceVars);
doConcurrentLoopOp.setReduceSymsAttr(
Expand Down
32 changes: 18 additions & 14 deletions flang/lib/Lower/OpenMP/ClauseProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1116,11 +1116,12 @@ bool ClauseProcessor::processInReduction(
collectReductionSyms(clause, inReductionSyms);

ReductionProcessor rp;
rp.processReductionArguments<mlir::omp::DeclareReductionOp>(
currentLocation, converter,
std::get<typename omp::clause::ReductionOperatorList>(clause.t),
inReductionVars, inReduceVarByRef, inReductionDeclSymbols,
inReductionSyms);
if (!rp.processReductionArguments<mlir::omp::DeclareReductionOp>(
currentLocation, converter,
std::get<typename omp::clause::ReductionOperatorList>(clause.t),
inReductionVars, inReduceVarByRef, inReductionDeclSymbols,
inReductionSyms))
inReductionSyms.clear();

// Copy local lists into the output.
llvm::copy(inReductionVars, std::back_inserter(result.inReductionVars));
Expand Down Expand Up @@ -1461,10 +1462,12 @@ bool ClauseProcessor::processReduction(
}

ReductionProcessor rp;
rp.processReductionArguments<mlir::omp::DeclareReductionOp>(
currentLocation, converter,
std::get<typename omp::clause::ReductionOperatorList>(clause.t),
reductionVars, reduceVarByRef, reductionDeclSymbols, reductionSyms);
if (!rp.processReductionArguments<mlir::omp::DeclareReductionOp>(
currentLocation, converter,
std::get<typename omp::clause::ReductionOperatorList>(clause.t),
reductionVars, reduceVarByRef, reductionDeclSymbols,
reductionSyms))
reductionSyms.clear();
// Copy local lists into the output.
llvm::copy(reductionVars, std::back_inserter(result.reductionVars));
llvm::copy(reduceVarByRef, std::back_inserter(result.reductionByref));
Expand All @@ -1486,11 +1489,12 @@ bool ClauseProcessor::processTaskReduction(
collectReductionSyms(clause, taskReductionSyms);

ReductionProcessor rp;
rp.processReductionArguments<mlir::omp::DeclareReductionOp>(
currentLocation, converter,
std::get<typename omp::clause::ReductionOperatorList>(clause.t),
taskReductionVars, taskReduceVarByRef, taskReductionDeclSymbols,
taskReductionSyms);
if (!rp.processReductionArguments<mlir::omp::DeclareReductionOp>(
currentLocation, converter,
std::get<typename omp::clause::ReductionOperatorList>(clause.t),
taskReductionVars, taskReduceVarByRef, taskReductionDeclSymbols,
taskReductionSyms))
taskReductionSyms.clear();
// Copy local lists into the output.
llvm::copy(taskReductionVars,
std::back_inserter(result.taskReductionVars));
Expand Down
12 changes: 7 additions & 5 deletions flang/lib/Lower/Support/ReductionProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace lower {
namespace omp {

// explicit template declarations
template void ReductionProcessor::processReductionArguments<
template bool ReductionProcessor::processReductionArguments<
mlir::omp::DeclareReductionOp, omp::clause::ReductionOperatorList>(
mlir::Location currentLocation, lower::AbstractConverter &converter,
const omp::clause::ReductionOperatorList &redOperatorList,
Expand All @@ -48,7 +48,7 @@ template void ReductionProcessor::processReductionArguments<
llvm::SmallVectorImpl<mlir::Attribute> &reductionDeclSymbols,
const llvm::SmallVectorImpl<const semantics::Symbol *> &reductionSymbols);

template void ReductionProcessor::processReductionArguments<
template bool ReductionProcessor::processReductionArguments<
fir::DeclareReductionOp, llvm::SmallVector<fir::ReduceOperationEnum>>(
mlir::Location currentLocation, lower::AbstractConverter &converter,
const llvm::SmallVector<fir::ReduceOperationEnum> &redOperatorList,
Expand Down Expand Up @@ -606,7 +606,7 @@ static bool doReductionByRef(mlir::Value reductionVar) {
}

template <typename OpType, typename RedOperatorListTy>
void ReductionProcessor::processReductionArguments(
bool ReductionProcessor::processReductionArguments(
mlir::Location currentLocation, lower::AbstractConverter &converter,
const RedOperatorListTy &redOperatorList,
llvm::SmallVectorImpl<mlir::Value> &reductionVars,
Expand All @@ -626,10 +626,10 @@ void ReductionProcessor::processReductionArguments(
std::get_if<omp::clause::ProcedureDesignator>(&redOperator.u)) {
if (!ReductionProcessor::supportedIntrinsicProcReduction(
*reductionIntrinsic)) {
return;
return false;
}
} else {
return;
return false;
}
}
}
Expand Down Expand Up @@ -764,6 +764,8 @@ void ReductionProcessor::processReductionArguments(

if (isDoConcurrent)
builder.restoreInsertionPoint(dcIP);

return true;
}

const semantics::SourceName
Expand Down
25 changes: 25 additions & 0 deletions flang/test/Lower/OpenMP/wsloop-reduction-non-intrinsic.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
! Tests reduction processor behavior when a reduction symbol is not supported.

! RUN: %flang_fc1 -emit-hlfir -fopenmp -o - %s 2>&1 | FileCheck %s

subroutine foo
implicit none
integer :: k, i

interface max
function max(m1,m2)
integer :: m1, m2
end function
end interface

!$omp do reduction (max: k)
do i=1,10
end do
!$omp end do
end

! Verify that unsupported reduction is ignored.
! CHECK: omp.wsloop
! CHECK-SAME: private(@{{[^[:space:]]+}} %{{[^[:space:]]+}}
! CHECK-SAME: -> %{{[^[:space:]]+}} : !{{[^[:space:]]+}}) {
! CHECK: }
Loading