Skip to content
Merged
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
41 changes: 41 additions & 0 deletions flang/lib/Lower/HlfirIntrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,17 @@ class HlfirCShiftLowering : public HlfirTransformationalIntrinsic {
mlir::Type stmtResultType) override;
};

class HlfirEOShiftLowering : public HlfirTransformationalIntrinsic {
public:
using HlfirTransformationalIntrinsic::HlfirTransformationalIntrinsic;

protected:
mlir::Value
lowerImpl(const Fortran::lower::PreparedActualArguments &loweredActuals,
const fir::IntrinsicArgumentLoweringRules *argLowering,
mlir::Type stmtResultType) override;
};

class HlfirReshapeLowering : public HlfirTransformationalIntrinsic {
public:
using HlfirTransformationalIntrinsic::HlfirTransformationalIntrinsic;
Expand Down Expand Up @@ -430,6 +441,33 @@ mlir::Value HlfirCShiftLowering::lowerImpl(
return createOp<hlfir::CShiftOp>(resultType, operands);
}

mlir::Value HlfirEOShiftLowering::lowerImpl(
const Fortran::lower::PreparedActualArguments &loweredActuals,
const fir::IntrinsicArgumentLoweringRules *argLowering,
mlir::Type stmtResultType) {
auto operands = getOperandVector(loweredActuals, argLowering);
assert(operands.size() == 4);
mlir::Value array = operands[0];
mlir::Value shift = operands[1];
mlir::Value boundary = operands[2];
mlir::Value dim = operands[3];
// If DIM is present, then dereference it if it is a ref.
if (dim)
dim = hlfir::loadTrivialScalar(loc, builder, hlfir::Entity{dim});

mlir::Type resultType = computeResultType(array, stmtResultType);

// Scalar logical constant boundary might be represented using i1, i2, ...
// type. We need to cast it to fir.logical type of the ARRAY/result.
if (auto logicalTy = mlir::dyn_cast<fir::LogicalType>(
hlfir::getFortranElementType(resultType)))
if (boundary && fir::isa_trivial(boundary.getType()) &&
boundary.getType() != logicalTy)
boundary = builder.createConvert(loc, logicalTy, boundary);

return createOp<hlfir::EOShiftOp>(resultType, array, shift, boundary, dim);
}

mlir::Value HlfirReshapeLowering::lowerImpl(
const Fortran::lower::PreparedActualArguments &loweredActuals,
const fir::IntrinsicArgumentLoweringRules *argLowering,
Expand Down Expand Up @@ -489,6 +527,9 @@ std::optional<hlfir::EntityWithAttributes> Fortran::lower::lowerHlfirIntrinsic(
if (name == "cshift")
return HlfirCShiftLowering{builder, loc}.lower(loweredActuals, argLowering,
stmtResultType);
if (name == "eoshift")
return HlfirEOShiftLowering{builder, loc}.lower(loweredActuals, argLowering,
stmtResultType);
if (name == "reshape")
return HlfirReshapeLowering{builder, loc}.lower(loweredActuals, argLowering,
stmtResultType);
Expand Down
Loading
Loading