@@ -170,6 +170,17 @@ class HlfirCShiftLowering : public HlfirTransformationalIntrinsic {
170
170
mlir::Type stmtResultType) override ;
171
171
};
172
172
173
+ class HlfirEOShiftLowering : public HlfirTransformationalIntrinsic {
174
+ public:
175
+ using HlfirTransformationalIntrinsic::HlfirTransformationalIntrinsic;
176
+
177
+ protected:
178
+ mlir::Value
179
+ lowerImpl (const Fortran::lower::PreparedActualArguments &loweredActuals,
180
+ const fir::IntrinsicArgumentLoweringRules *argLowering,
181
+ mlir::Type stmtResultType) override ;
182
+ };
183
+
173
184
class HlfirReshapeLowering : public HlfirTransformationalIntrinsic {
174
185
public:
175
186
using HlfirTransformationalIntrinsic::HlfirTransformationalIntrinsic;
@@ -430,6 +441,33 @@ mlir::Value HlfirCShiftLowering::lowerImpl(
430
441
return createOp<hlfir::CShiftOp>(resultType, operands);
431
442
}
432
443
444
+ mlir::Value HlfirEOShiftLowering::lowerImpl (
445
+ const Fortran::lower::PreparedActualArguments &loweredActuals,
446
+ const fir::IntrinsicArgumentLoweringRules *argLowering,
447
+ mlir::Type stmtResultType) {
448
+ auto operands = getOperandVector (loweredActuals, argLowering);
449
+ assert (operands.size () == 4 );
450
+ mlir::Value array = operands[0 ];
451
+ mlir::Value shift = operands[1 ];
452
+ mlir::Value boundary = operands[2 ];
453
+ mlir::Value dim = operands[3 ];
454
+ // If DIM is present, then dereference it if it is a ref.
455
+ if (dim)
456
+ dim = hlfir::loadTrivialScalar (loc, builder, hlfir::Entity{dim});
457
+
458
+ mlir::Type resultType = computeResultType (array, stmtResultType);
459
+
460
+ // Scalar logical constant boundary might be represented using i1, i2, ...
461
+ // type. We need to cast it to fir.logical type of the ARRAY/result.
462
+ if (auto logicalTy = mlir::dyn_cast<fir::LogicalType>(
463
+ hlfir::getFortranElementType (resultType)))
464
+ if (boundary && fir::isa_trivial (boundary.getType ()) &&
465
+ boundary.getType () != logicalTy)
466
+ boundary = builder.createConvert (loc, logicalTy, boundary);
467
+
468
+ return createOp<hlfir::EOShiftOp>(resultType, array, shift, boundary, dim);
469
+ }
470
+
433
471
mlir::Value HlfirReshapeLowering::lowerImpl (
434
472
const Fortran::lower::PreparedActualArguments &loweredActuals,
435
473
const fir::IntrinsicArgumentLoweringRules *argLowering,
@@ -489,6 +527,9 @@ std::optional<hlfir::EntityWithAttributes> Fortran::lower::lowerHlfirIntrinsic(
489
527
if (name == " cshift" )
490
528
return HlfirCShiftLowering{builder, loc}.lower (loweredActuals, argLowering,
491
529
stmtResultType);
530
+ if (name == " eoshift" )
531
+ return HlfirEOShiftLowering{builder, loc}.lower (loweredActuals, argLowering,
532
+ stmtResultType);
492
533
if (name == " reshape" )
493
534
return HlfirReshapeLowering{builder, loc}.lower (loweredActuals, argLowering,
494
535
stmtResultType);
0 commit comments