Skip to content

Commit 1c8d305

Browse files
committed
Update for asbent dim
1 parent 437b0c8 commit 1c8d305

File tree

5 files changed

+41
-43
lines changed

5 files changed

+41
-43
lines changed

flang/include/flang/Optimizer/Builder/IntrinsicCall.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,8 @@ struct IntrinsicLibrary {
328328
void genRandomNumber(llvm::ArrayRef<fir::ExtendedValue>);
329329
void genRandomSeed(llvm::ArrayRef<fir::ExtendedValue>);
330330
fir::ExtendedValue genReduce(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
331+
fir::ExtendedValue genReduceDim(mlir::Type,
332+
llvm::ArrayRef<fir::ExtendedValue>);
331333
fir::ExtendedValue genRepeat(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
332334
fir::ExtendedValue genReshape(mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
333335
mlir::Value genRRSpacing(mlir::Type resultType,

flang/include/flang/Optimizer/Builder/Runtime/Reduction.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,8 @@ void genIParityDim(fir::FirOpBuilder &builder, mlir::Location loc,
228228
/// that does not take a dim argument.
229229
mlir::Value genReduce(fir::FirOpBuilder &builder, mlir::Location loc,
230230
mlir::Value arrayBox, mlir::Value operation,
231-
mlir::Value dim, mlir::Value maskBox,
232-
mlir::Value identity, mlir::Value ordered,
233-
mlir::Value resultBox);
231+
mlir::Value maskBox, mlir::Value identity,
232+
mlir::Value ordered, mlir::Value resultBox);
234233

235234
} // namespace fir::runtime
236235

flang/lib/Optimizer/Builder/IntrinsicCall.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5749,9 +5749,7 @@ IntrinsicLibrary::genReduce(mlir::Type resultType,
57495749
mlir::Type eleTy = mlir::cast<fir::SequenceType>(arrTy).getEleTy();
57505750

57515751
// Handle optional mask argument
5752-
auto dim = isStaticallyAbsent(args[3])
5753-
? builder.createIntegerConstant(loc, builder.getI32Type(), 1)
5754-
: fir::getBase(args[2]);
5752+
bool absentDim = isStaticallyAbsent(args[1]);
57555753

57565754
auto mask = isStaticallyAbsent(args[3])
57575755
? builder.create<fir::AbsentOp>(
@@ -5769,11 +5767,11 @@ IntrinsicLibrary::genReduce(mlir::Type resultType,
57695767

57705768
// We call the type specific versions because the result is scalar
57715769
// in the case below.
5772-
if (rank == 1) {
5770+
if (absentDim || rank == 1) {
57735771
if (fir::isa_complex(eleTy) || fir::isa_derived(eleTy)) {
57745772
mlir::Value result = builder.createTemporary(loc, eleTy);
5775-
fir::runtime::genReduce(builder, loc, array, operation, dim, mask,
5776-
identity, ordered, result);
5773+
fir::runtime::genReduce(builder, loc, array, operation, mask, identity,
5774+
ordered, result);
57775775
if (fir::isa_derived(eleTy))
57785776
return result;
57795777
return builder.create<fir::LoadOp>(loc, result);
@@ -5784,18 +5782,17 @@ IntrinsicLibrary::genReduce(mlir::Type resultType,
57845782
fir::factory::createTempMutableBox(builder, loc, eleTy);
57855783
mlir::Value resultIrBox =
57865784
fir::factory::getMutableIRBox(builder, loc, resultMutableBox);
5787-
fir::runtime::genReduce(builder, loc, array, operation, dim, mask,
5788-
identity, ordered, resultIrBox);
5785+
fir::runtime::genReduce(builder, loc, array, operation, mask, identity,
5786+
ordered, resultIrBox);
57895787
// Handle cleanup of allocatable result descriptor and return
57905788
return readAndAddCleanUp(resultMutableBox, resultType, "REDUCE");
57915789
}
57925790
auto resultBox = builder.create<fir::AbsentOp>(
57935791
loc, fir::BoxType::get(builder.getI1Type()));
5794-
return fir::runtime::genReduce(builder, loc, array, operation, dim, mask,
5792+
return fir::runtime::genReduce(builder, loc, array, operation, mask,
57955793
identity, ordered, resultBox);
57965794
}
5797-
5798-
TODO(loc, "intrinsic: reduce with non scalar result");
5795+
TODO(loc, "reduce with array result");
57995796
}
58005797

58015798
// REPEAT

flang/lib/Optimizer/Builder/Runtime/Reduction.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,14 +1322,14 @@ GEN_IALL_IANY_IPARITY(IParity)
13221322
/// that does have a scalar result.
13231323
mlir::Value fir::runtime::genReduce(fir::FirOpBuilder &builder,
13241324
mlir::Location loc, mlir::Value arrayBox,
1325-
mlir::Value operation, mlir::Value dim,
1326-
mlir::Value maskBox, mlir::Value identity,
1327-
mlir::Value ordered,
1325+
mlir::Value operation, mlir::Value maskBox,
1326+
mlir::Value identity, mlir::Value ordered,
13281327
mlir::Value resultBox) {
13291328
mlir::func::FuncOp func;
13301329
auto ty = arrayBox.getType();
13311330
auto arrTy = fir::dyn_cast_ptrOrBoxEleTy(ty);
13321331
auto eleTy = mlir::cast<fir::SequenceType>(arrTy).getEleTy();
1332+
auto dim = builder.createIntegerConstant(loc, builder.getI32Type(), 1);
13331333

13341334
mlir::MLIRContext *ctx = builder.getContext();
13351335
fir::factory::CharacterExprHelper charHelper{builder, loc};

flang/test/Lower/Intrinsics/reduce.f90

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ subroutine integer1(a, id)
2020

2121
res = reduce(a, red_int1)
2222

23-
res = reduce(a, red_int1, 1, identity=id)
23+
res = reduce(a, red_int1, identity=id)
2424

25-
res = reduce(a, red_int1, 1, identity=id, ordered = .false.)
25+
res = reduce(a, red_int1, identity=id, ordered = .false.)
2626

27-
res = reduce(a, red_int1, 1, [.true., .true., .false.])
27+
res = reduce(a, red_int1, [.true., .true., .false.])
2828
end subroutine
2929

3030
! CHECK-LABEL: func.func @_QMreduce_modPinteger1(
@@ -65,7 +65,7 @@ pure function red_int2(a,b)
6565
subroutine integer2(a)
6666
integer(2), intent(in) :: a(:)
6767
integer(2) :: res
68-
res = reduce(a, red_int2, 1)
68+
res = reduce(a, red_int2)
6969
end subroutine
7070

7171
! CHECK: fir.call @_FortranAReduceInteger2
@@ -79,7 +79,7 @@ pure function red_int4(a,b)
7979
subroutine integer4(a)
8080
integer(4), intent(in) :: a(:)
8181
integer(4) :: res
82-
res = reduce(a, red_int4, 1)
82+
res = reduce(a, red_int4)
8383
end subroutine
8484

8585
! CHECK: fir.call @_FortranAReduceInteger4
@@ -93,7 +93,7 @@ pure function red_int8(a,b)
9393
subroutine integer8(a)
9494
integer(8), intent(in) :: a(:)
9595
integer(8) :: res
96-
res = reduce(a, red_int8, 1)
96+
res = reduce(a, red_int8)
9797
end subroutine
9898

9999
! CHECK: fir.call @_FortranAReduceInteger8
@@ -107,7 +107,7 @@ pure function red_int16(a,b)
107107
subroutine integer16(a)
108108
integer(16), intent(in) :: a(:)
109109
integer(16) :: res
110-
res = reduce(a, red_int16, 1)
110+
res = reduce(a, red_int16)
111111
end subroutine
112112

113113
! CHECK: fir.call @_FortranAReduceInteger16
@@ -121,7 +121,7 @@ pure function red_real2(a,b)
121121
subroutine real2(a)
122122
real(2), intent(in) :: a(:)
123123
real(2) :: res
124-
res = reduce(a, red_real2, 1)
124+
res = reduce(a, red_real2)
125125
end subroutine
126126

127127
! CHECK: fir.call @_FortranAReduceReal2
@@ -135,7 +135,7 @@ pure function red_real3(a,b)
135135
subroutine real3(a)
136136
real(3), intent(in) :: a(:)
137137
real(3) :: res
138-
res = reduce(a, red_real3, 1)
138+
res = reduce(a, red_real3)
139139
end subroutine
140140

141141
! CHECK: fir.call @_FortranAReduceReal3
@@ -149,7 +149,7 @@ pure function red_real4(a,b)
149149
subroutine real4(a)
150150
real(4), intent(in) :: a(:)
151151
real(4) :: res
152-
res = reduce(a, red_real4, 1)
152+
res = reduce(a, red_real4)
153153
end subroutine
154154

155155
! CHECK: fir.call @_FortranAReduceReal4
@@ -163,7 +163,7 @@ pure function red_real8(a,b)
163163
subroutine real8(a)
164164
real(8), intent(in) :: a(:)
165165
real(8) :: res
166-
res = reduce(a, red_real8, 1)
166+
res = reduce(a, red_real8)
167167
end subroutine
168168

169169
! CHECK: fir.call @_FortranAReduceReal8
@@ -177,7 +177,7 @@ pure function red_real10(a,b)
177177
subroutine real10(a)
178178
real(10), intent(in) :: a(:)
179179
real(10) :: res
180-
res = reduce(a, red_real10, 1)
180+
res = reduce(a, red_real10)
181181
end subroutine
182182

183183
! CHECK: fir.call @_FortranAReduceReal10
@@ -191,7 +191,7 @@ pure function red_real16(a,b)
191191
subroutine real16(a)
192192
real(16), intent(in) :: a(:)
193193
real(16) :: res
194-
res = reduce(a, red_real16, 1)
194+
res = reduce(a, red_real16)
195195
end subroutine
196196

197197
! CHECK: fir.call @_FortranAReduceReal16
@@ -205,7 +205,7 @@ pure function red_complex2(a,b)
205205
subroutine complex2(a)
206206
complex(2), intent(in) :: a(:)
207207
complex(2) :: res
208-
res = reduce(a, red_complex2, 1)
208+
res = reduce(a, red_complex2)
209209
end subroutine
210210

211211
! CHECK: fir.call @_FortranACppReduceComplex2
@@ -219,7 +219,7 @@ pure function red_complex3(a,b)
219219
subroutine complex3(a)
220220
complex(3), intent(in) :: a(:)
221221
complex(3) :: res
222-
res = reduce(a, red_complex3, 1)
222+
res = reduce(a, red_complex3)
223223
end subroutine
224224

225225
! CHECK: fir.call @_FortranACppReduceComplex3
@@ -233,7 +233,7 @@ pure function red_complex4(a,b)
233233
subroutine complex4(a)
234234
complex(4), intent(in) :: a(:)
235235
complex(4) :: res
236-
res = reduce(a, red_complex4, 1)
236+
res = reduce(a, red_complex4)
237237
end subroutine
238238

239239
! CHECK: fir.call @_FortranACppReduceComplex4
@@ -247,7 +247,7 @@ pure function red_complex8(a,b)
247247
subroutine complex8(a)
248248
complex(8), intent(in) :: a(:)
249249
complex(8) :: res
250-
res = reduce(a, red_complex8, 1)
250+
res = reduce(a, red_complex8)
251251
end subroutine
252252

253253
! CHECK: fir.call @_FortranACppReduceComplex8
@@ -261,7 +261,7 @@ pure function red_complex10(a,b)
261261
subroutine complex10(a)
262262
complex(10), intent(in) :: a(:)
263263
complex(10) :: res
264-
! res = reduce(a, red_complex10, 1)
264+
! res = reduce(a, red_complex10)
265265
end subroutine
266266

267267
pure function red_log1(a,b)
@@ -273,7 +273,7 @@ pure function red_log1(a,b)
273273
subroutine log1(a)
274274
logical(1), intent(in) :: a(:)
275275
logical(1) :: res
276-
res = reduce(a, red_log1, 1)
276+
res = reduce(a, red_log1)
277277
end subroutine
278278

279279
! CHECK: fir.call @_FortranAReduceLogical1
@@ -287,7 +287,7 @@ pure function red_log2(a,b)
287287
subroutine log2(a)
288288
logical(2), intent(in) :: a(:)
289289
logical(2) :: res
290-
res = reduce(a, red_log2, 1)
290+
res = reduce(a, red_log2)
291291
end subroutine
292292

293293
! CHECK: fir.call @_FortranAReduceLogical2
@@ -301,7 +301,7 @@ pure function red_log4(a,b)
301301
subroutine log4(a)
302302
logical(4), intent(in) :: a(:)
303303
logical(4) :: res
304-
res = reduce(a, red_log4, 1)
304+
res = reduce(a, red_log4)
305305
end subroutine
306306

307307
! CHECK: fir.call @_FortranAReduceLogical4
@@ -315,7 +315,7 @@ pure function red_log8(a,b)
315315
subroutine log8(a)
316316
logical(8), intent(in) :: a(:)
317317
logical(8) :: res
318-
res = reduce(a, red_log8, 1)
318+
res = reduce(a, red_log8)
319319
end subroutine
320320

321321
! CHECK: fir.call @_FortranAReduceLogical8
@@ -329,7 +329,7 @@ pure function red_char1(a,b)
329329
subroutine char1(a)
330330
character(1), intent(in) :: a(:)
331331
character(1) :: res
332-
res = reduce(a, red_char1, 1)
332+
res = reduce(a, red_char1)
333333
end subroutine
334334

335335
! CHECK: fir.call @_FortranAReduceChar1
@@ -343,7 +343,7 @@ pure function red_char2(a,b)
343343
subroutine char2(a)
344344
character(kind=2), intent(in) :: a(:)
345345
character(kind=2) :: res
346-
res = reduce(a, red_char2, 1)
346+
res = reduce(a, red_char2)
347347
end subroutine
348348

349349
! CHECK: fir.call @_FortranAReduceChar2
@@ -357,7 +357,7 @@ pure function red_char4(a,b)
357357
subroutine char4(a)
358358
character(kind=4), intent(in) :: a(:)
359359
character(kind=4) :: res
360-
res = reduce(a, red_char4, 1)
360+
res = reduce(a, red_char4)
361361
end subroutine
362362

363363
! CHECK: fir.call @_FortranAReduceChar4
@@ -371,7 +371,7 @@ pure function red_type(a,b)
371371
subroutine testtype(a)
372372
type(t1), intent(in) :: a(:)
373373
type(t1) :: res
374-
res = reduce(a, red_type, 1)
374+
res = reduce(a, red_type)
375375
end subroutine
376376

377377
! CHECK: fir.call @_FortranAReduceDerivedType

0 commit comments

Comments
 (0)