Skip to content

Commit 68e7d13

Browse files
author
git apple-llvm automerger
committed
Merge commit '4d6604adf12a' from llvm.org/release/21.x into stable/21.x
2 parents 39735bb + 4d6604a commit 68e7d13

File tree

5 files changed

+53
-21
lines changed

5 files changed

+53
-21
lines changed

flang/include/flang/Lower/Support/ReductionProcessor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class ReductionProcessor {
124124
/// Creates a reduction declaration and associates it with an OpenMP block
125125
/// directive.
126126
template <typename OpType, typename RedOperatorListTy>
127-
static void processReductionArguments(
127+
static bool processReductionArguments(
128128
mlir::Location currentLocation, lower::AbstractConverter &converter,
129129
const RedOperatorListTy &redOperatorList,
130130
llvm::SmallVectorImpl<mlir::Value> &reductionVars,

flang/lib/Lower/Bridge.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2123,9 +2123,10 @@ class FirConverter : public Fortran::lower::AbstractConverter {
21232123

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

21302131
doConcurrentLoopOp.getReduceVarsMutable().assign(reduceVars);
21312132
doConcurrentLoopOp.setReduceSymsAttr(

flang/lib/Lower/OpenMP/ClauseProcessor.cpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,11 +1116,12 @@ bool ClauseProcessor::processInReduction(
11161116
collectReductionSyms(clause, inReductionSyms);
11171117

11181118
ReductionProcessor rp;
1119-
rp.processReductionArguments<mlir::omp::DeclareReductionOp>(
1120-
currentLocation, converter,
1121-
std::get<typename omp::clause::ReductionOperatorList>(clause.t),
1122-
inReductionVars, inReduceVarByRef, inReductionDeclSymbols,
1123-
inReductionSyms);
1119+
if (!rp.processReductionArguments<mlir::omp::DeclareReductionOp>(
1120+
currentLocation, converter,
1121+
std::get<typename omp::clause::ReductionOperatorList>(clause.t),
1122+
inReductionVars, inReduceVarByRef, inReductionDeclSymbols,
1123+
inReductionSyms))
1124+
inReductionSyms.clear();
11241125

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

14631464
ReductionProcessor rp;
1464-
rp.processReductionArguments<mlir::omp::DeclareReductionOp>(
1465-
currentLocation, converter,
1466-
std::get<typename omp::clause::ReductionOperatorList>(clause.t),
1467-
reductionVars, reduceVarByRef, reductionDeclSymbols, reductionSyms);
1465+
if (!rp.processReductionArguments<mlir::omp::DeclareReductionOp>(
1466+
currentLocation, converter,
1467+
std::get<typename omp::clause::ReductionOperatorList>(clause.t),
1468+
reductionVars, reduceVarByRef, reductionDeclSymbols,
1469+
reductionSyms))
1470+
reductionSyms.clear();
14681471
// Copy local lists into the output.
14691472
llvm::copy(reductionVars, std::back_inserter(result.reductionVars));
14701473
llvm::copy(reduceVarByRef, std::back_inserter(result.reductionByref));
@@ -1486,11 +1489,12 @@ bool ClauseProcessor::processTaskReduction(
14861489
collectReductionSyms(clause, taskReductionSyms);
14871490

14881491
ReductionProcessor rp;
1489-
rp.processReductionArguments<mlir::omp::DeclareReductionOp>(
1490-
currentLocation, converter,
1491-
std::get<typename omp::clause::ReductionOperatorList>(clause.t),
1492-
taskReductionVars, taskReduceVarByRef, taskReductionDeclSymbols,
1493-
taskReductionSyms);
1492+
if (!rp.processReductionArguments<mlir::omp::DeclareReductionOp>(
1493+
currentLocation, converter,
1494+
std::get<typename omp::clause::ReductionOperatorList>(clause.t),
1495+
taskReductionVars, taskReduceVarByRef, taskReductionDeclSymbols,
1496+
taskReductionSyms))
1497+
taskReductionSyms.clear();
14941498
// Copy local lists into the output.
14951499
llvm::copy(taskReductionVars,
14961500
std::back_inserter(result.taskReductionVars));

flang/lib/Lower/Support/ReductionProcessor.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace lower {
3939
namespace omp {
4040

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

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

608608
template <typename OpType, typename RedOperatorListTy>
609-
void ReductionProcessor::processReductionArguments(
609+
bool ReductionProcessor::processReductionArguments(
610610
mlir::Location currentLocation, lower::AbstractConverter &converter,
611611
const RedOperatorListTy &redOperatorList,
612612
llvm::SmallVectorImpl<mlir::Value> &reductionVars,
@@ -626,10 +626,10 @@ void ReductionProcessor::processReductionArguments(
626626
std::get_if<omp::clause::ProcedureDesignator>(&redOperator.u)) {
627627
if (!ReductionProcessor::supportedIntrinsicProcReduction(
628628
*reductionIntrinsic)) {
629-
return;
629+
return false;
630630
}
631631
} else {
632-
return;
632+
return false;
633633
}
634634
}
635635
}
@@ -764,6 +764,8 @@ void ReductionProcessor::processReductionArguments(
764764

765765
if (isDoConcurrent)
766766
builder.restoreInsertionPoint(dcIP);
767+
768+
return true;
767769
}
768770

769771
const semantics::SourceName
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
! Tests reduction processor behavior when a reduction symbol is not supported.
2+
3+
! RUN: %flang_fc1 -emit-hlfir -fopenmp -o - %s 2>&1 | FileCheck %s
4+
5+
subroutine foo
6+
implicit none
7+
integer :: k, i
8+
9+
interface max
10+
function max(m1,m2)
11+
integer :: m1, m2
12+
end function
13+
end interface
14+
15+
!$omp do reduction (max: k)
16+
do i=1,10
17+
end do
18+
!$omp end do
19+
end
20+
21+
! Verify that unsupported reduction is ignored.
22+
! CHECK: omp.wsloop
23+
! CHECK-SAME: private(@{{[^[:space:]]+}} %{{[^[:space:]]+}}
24+
! CHECK-SAME: -> %{{[^[:space:]]+}} : !{{[^[:space:]]+}}) {
25+
! CHECK: }

0 commit comments

Comments
 (0)