@@ -521,7 +521,8 @@ struct ForcedReduceComplex10 {
521
521
auto refTy = fir::ReferenceType::get (ty);
522
522
auto i1Ty = mlir::IntegerType::get (ctx, 1 );
523
523
return mlir::FunctionType::get (
524
- ctx, {ty, boxTy, opTy, strTy, intTy, intTy, boxTy, refTy, i1Ty}, {});
524
+ ctx, {refTy, boxTy, opTy, strTy, intTy, intTy, boxTy, refTy, i1Ty},
525
+ {});
525
526
};
526
527
}
527
528
};
@@ -541,7 +542,8 @@ struct ForcedReduceComplex16 {
541
542
auto refTy = fir::ReferenceType::get (ty);
542
543
auto i1Ty = mlir::IntegerType::get (ctx, 1 );
543
544
return mlir::FunctionType::get (
544
- ctx, {ty, boxTy, opTy, strTy, intTy, intTy, boxTy, refTy, i1Ty}, {});
545
+ ctx, {refTy, boxTy, opTy, strTy, intTy, intTy, boxTy, refTy, i1Ty},
546
+ {});
545
547
};
546
548
}
547
549
};
@@ -1319,12 +1321,71 @@ void fir::runtime::genIParityDim(fir::FirOpBuilder &builder, mlir::Location loc,
1319
1321
GEN_IALL_IANY_IPARITY (IParity)
1320
1322
1321
1323
// / Generate call to `Reduce` intrinsic runtime routine. This is the version
1322
- // / that does have a scalar result.
1324
+ // / that does not take a DIM argument and store result in the passed result
1325
+ // / value.
1326
+ void fir::runtime::genReduce(fir::FirOpBuilder &builder, mlir::Location loc,
1327
+ mlir::Value arrayBox, mlir::Value operation,
1328
+ mlir::Value maskBox, mlir::Value identity,
1329
+ mlir::Value ordered, mlir::Value resultBox) {
1330
+ mlir::func::FuncOp func;
1331
+ auto ty = arrayBox.getType ();
1332
+ auto arrTy = fir::dyn_cast_ptrOrBoxEleTy (ty);
1333
+ auto eleTy = mlir::cast<fir::SequenceType>(arrTy).getEleTy ();
1334
+ auto dim = builder.createIntegerConstant (loc, builder.getI32Type (), 1 );
1335
+
1336
+ assert (resultBox && " expect non null value for the result" );
1337
+ assert ((fir::isa_char (eleTy) || fir::isa_complex (eleTy) ||
1338
+ fir::isa_derived (eleTy)) &&
1339
+ " expect character, complex or derived-type" );
1340
+
1341
+ mlir::MLIRContext *ctx = builder.getContext ();
1342
+ fir::factory::CharacterExprHelper charHelper{builder, loc};
1343
+
1344
+ if (eleTy == fir::ComplexType::get (ctx, 2 ))
1345
+ func =
1346
+ fir::runtime::getRuntimeFunc<mkRTKey (CppReduceComplex2)>(loc, builder);
1347
+ else if (eleTy == fir::ComplexType::get (ctx, 3 ))
1348
+ func =
1349
+ fir::runtime::getRuntimeFunc<mkRTKey (CppReduceComplex3)>(loc, builder);
1350
+ else if (eleTy == fir::ComplexType::get (ctx, 4 ))
1351
+ func =
1352
+ fir::runtime::getRuntimeFunc<mkRTKey (CppReduceComplex4)>(loc, builder);
1353
+ else if (eleTy == fir::ComplexType::get (ctx, 8 ))
1354
+ func =
1355
+ fir::runtime::getRuntimeFunc<mkRTKey (CppReduceComplex8)>(loc, builder);
1356
+ else if (eleTy == fir::ComplexType::get (ctx, 10 ))
1357
+ func = fir::runtime::getRuntimeFunc<ForcedReduceComplex10>(loc, builder);
1358
+ else if (eleTy == fir::ComplexType::get (ctx, 16 ))
1359
+ func = fir::runtime::getRuntimeFunc<ForcedReduceComplex16>(loc, builder);
1360
+ else if (fir::isa_char (eleTy) && charHelper.getCharacterKind (eleTy) == 1 )
1361
+ func = fir::runtime::getRuntimeFunc<mkRTKey (ReduceChar1)>(loc, builder);
1362
+ else if (fir::isa_char (eleTy) && charHelper.getCharacterKind (eleTy) == 2 )
1363
+ func = fir::runtime::getRuntimeFunc<mkRTKey (ReduceChar2)>(loc, builder);
1364
+ else if (fir::isa_char (eleTy) && charHelper.getCharacterKind (eleTy) == 4 )
1365
+ func = fir::runtime::getRuntimeFunc<mkRTKey (ReduceChar4)>(loc, builder);
1366
+ else if (fir::isa_derived (eleTy))
1367
+ func =
1368
+ fir::runtime::getRuntimeFunc<mkRTKey (ReduceDerivedType)>(loc, builder);
1369
+ else
1370
+ fir::intrinsicTypeTODO (builder, eleTy, loc, " REDUCE" );
1371
+
1372
+ auto fTy = func.getFunctionType ();
1373
+ auto sourceFile = fir::factory::locationToFilename (builder, loc);
1374
+ auto sourceLine =
1375
+ fir::factory::locationToLineNo (builder, loc, fTy .getInput (4 ));
1376
+ auto opAddr = builder.create <fir::BoxAddrOp>(loc, fTy .getInput (2 ), operation);
1377
+ auto args = fir::runtime::createArguments (
1378
+ builder, loc, fTy , resultBox, arrayBox, opAddr, sourceFile, sourceLine,
1379
+ dim, maskBox, identity, ordered);
1380
+ builder.create <fir::CallOp>(loc, func, args);
1381
+ }
1382
+
1383
+ // / Generate call to `Reduce` intrinsic runtime routine. This is the version
1384
+ // / that does not take DIM argument and return a scalar result.
1323
1385
mlir::Value fir::runtime::genReduce (fir::FirOpBuilder &builder,
1324
1386
mlir::Location loc, mlir::Value arrayBox,
1325
1387
mlir::Value operation, mlir::Value maskBox,
1326
- mlir::Value identity, mlir::Value ordered,
1327
- mlir::Value resultBox) {
1388
+ mlir::Value identity, mlir::Value ordered) {
1328
1389
mlir::func::FuncOp func;
1329
1390
auto ty = arrayBox.getType ();
1330
1391
auto arrTy = fir::dyn_cast_ptrOrBoxEleTy (ty);
@@ -1334,6 +1395,10 @@ mlir::Value fir::runtime::genReduce(fir::FirOpBuilder &builder,
1334
1395
mlir::MLIRContext *ctx = builder.getContext ();
1335
1396
fir::factory::CharacterExprHelper charHelper{builder, loc};
1336
1397
1398
+ assert ((fir::isa_real (eleTy) || fir::isa_integer (eleTy) ||
1399
+ mlir::isa<fir::LogicalType>(eleTy)) &&
1400
+ " expect real, interger or logical" );
1401
+
1337
1402
if (eleTy.isF16 ())
1338
1403
func = fir::runtime::getRuntimeFunc<mkRTKey (ReduceReal2)>(loc, builder);
1339
1404
else if (eleTy.isBF16 ())
@@ -1356,22 +1421,6 @@ mlir::Value fir::runtime::genReduce(fir::FirOpBuilder &builder,
1356
1421
func = fir::runtime::getRuntimeFunc<mkRTKey (ReduceInteger8)>(loc, builder);
1357
1422
else if (eleTy.isInteger (builder.getKindMap ().getIntegerBitsize (16 )))
1358
1423
func = fir::runtime::getRuntimeFunc<ForcedReduceInteger16>(loc, builder);
1359
- else if (eleTy == fir::ComplexType::get (ctx, 2 ))
1360
- func =
1361
- fir::runtime::getRuntimeFunc<mkRTKey (CppReduceComplex2)>(loc, builder);
1362
- else if (eleTy == fir::ComplexType::get (ctx, 3 ))
1363
- func =
1364
- fir::runtime::getRuntimeFunc<mkRTKey (CppReduceComplex3)>(loc, builder);
1365
- else if (eleTy == fir::ComplexType::get (ctx, 4 ))
1366
- func =
1367
- fir::runtime::getRuntimeFunc<mkRTKey (CppReduceComplex4)>(loc, builder);
1368
- else if (eleTy == fir::ComplexType::get (ctx, 8 ))
1369
- func =
1370
- fir::runtime::getRuntimeFunc<mkRTKey (CppReduceComplex8)>(loc, builder);
1371
- else if (eleTy == fir::ComplexType::get (ctx, 10 ))
1372
- func = fir::runtime::getRuntimeFunc<ForcedReduceComplex10>(loc, builder);
1373
- else if (eleTy == fir::ComplexType::get (ctx, 16 ))
1374
- func = fir::runtime::getRuntimeFunc<ForcedSumComplex16>(loc, builder);
1375
1424
else if (eleTy == fir::LogicalType::get (ctx, 1 ))
1376
1425
func = fir::runtime::getRuntimeFunc<mkRTKey (ReduceLogical1)>(loc, builder);
1377
1426
else if (eleTy == fir::LogicalType::get (ctx, 2 ))
@@ -1380,33 +1429,11 @@ mlir::Value fir::runtime::genReduce(fir::FirOpBuilder &builder,
1380
1429
func = fir::runtime::getRuntimeFunc<mkRTKey (ReduceLogical4)>(loc, builder);
1381
1430
else if (eleTy == fir::LogicalType::get (ctx, 8 ))
1382
1431
func = fir::runtime::getRuntimeFunc<mkRTKey (ReduceLogical8)>(loc, builder);
1383
- else if (fir::isa_char (eleTy) && charHelper.getCharacterKind (eleTy) == 1 )
1384
- func = fir::runtime::getRuntimeFunc<mkRTKey (ReduceChar1)>(loc, builder);
1385
- else if (fir::isa_char (eleTy) && charHelper.getCharacterKind (eleTy) == 2 )
1386
- func = fir::runtime::getRuntimeFunc<mkRTKey (ReduceChar2)>(loc, builder);
1387
- else if (fir::isa_char (eleTy) && charHelper.getCharacterKind (eleTy) == 4 )
1388
- func = fir::runtime::getRuntimeFunc<mkRTKey (ReduceChar4)>(loc, builder);
1389
- else if (fir::isa_derived (eleTy))
1390
- func =
1391
- fir::runtime::getRuntimeFunc<mkRTKey (ReduceDerivedType)>(loc, builder);
1392
1432
else
1393
1433
fir::intrinsicTypeTODO (builder, eleTy, loc, " REDUCE" );
1394
1434
1395
1435
auto fTy = func.getFunctionType ();
1396
1436
auto sourceFile = fir::factory::locationToFilename (builder, loc);
1397
- if (fir::isa_complex (eleTy) || fir::isa_char (eleTy) ||
1398
- fir::isa_derived (eleTy)) {
1399
- auto sourceLine =
1400
- fir::factory::locationToLineNo (builder, loc, fTy .getInput (4 ));
1401
- auto opAddr =
1402
- builder.create <fir::BoxAddrOp>(loc, fTy .getInput (2 ), operation);
1403
- auto args = fir::runtime::createArguments (
1404
- builder, loc, fTy , resultBox, arrayBox, opAddr, sourceFile, sourceLine,
1405
- dim, maskBox, identity, ordered);
1406
- builder.create <fir::CallOp>(loc, func, args);
1407
- return resultBox;
1408
- }
1409
-
1410
1437
auto sourceLine =
1411
1438
fir::factory::locationToLineNo (builder, loc, fTy .getInput (3 ));
1412
1439
auto opAddr = builder.create <fir::BoxAddrOp>(loc, fTy .getInput (1 ), operation);
0 commit comments