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
13 changes: 2 additions & 11 deletions flang/lib/Lower/ConvertExprToHLFIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include "flang/Optimizer/Builder/Complex.h"
#include "flang/Optimizer/Builder/IntrinsicCall.h"
#include "flang/Optimizer/Builder/MutableBox.h"
#include "flang/Optimizer/Builder/Runtime/Character.h"
#include "flang/Optimizer/Builder/Runtime/Derived.h"
#include "flang/Optimizer/Builder/Runtime/Pointer.h"
#include "flang/Optimizer/Builder/Todo.h"
Expand Down Expand Up @@ -1286,16 +1285,8 @@ struct BinaryOp<Fortran::evaluate::Relational<
fir::FirOpBuilder &builder,
const Op &op, hlfir::Entity lhs,
hlfir::Entity rhs) {
auto [lhsExv, lhsCleanUp] =
hlfir::translateToExtendedValue(loc, builder, lhs);
auto [rhsExv, rhsCleanUp] =
hlfir::translateToExtendedValue(loc, builder, rhs);
auto cmp = fir::runtime::genCharCompare(
builder, loc, translateSignedRelational(op.opr), lhsExv, rhsExv);
if (lhsCleanUp)
(*lhsCleanUp)();
if (rhsCleanUp)
(*rhsCleanUp)();
auto cmp = hlfir::CmpCharOp::create(
builder, loc, translateSignedRelational(op.opr), lhs, rhs);
return hlfir::EntityWithAttributes{cmp};
}
};
Expand Down
49 changes: 42 additions & 7 deletions flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIRIntrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,20 +551,55 @@ class ReshapeOpConversion : public HlfirIntrinsicConversion<hlfir::ReshapeOp> {
}
};

class CmpCharOpConversion : public HlfirIntrinsicConversion<hlfir::CmpCharOp> {
using HlfirIntrinsicConversion<hlfir::CmpCharOp>::HlfirIntrinsicConversion;

llvm::LogicalResult
matchAndRewrite(hlfir::CmpCharOp cmp,
mlir::PatternRewriter &rewriter) const override {
fir::FirOpBuilder builder{rewriter, cmp.getOperation()};
const mlir::Location &loc = cmp->getLoc();
hlfir::Entity lhs{cmp.getLchr()};
hlfir::Entity rhs{cmp.getRchr()};

auto [lhsExv, lhsCleanUp] =
hlfir::translateToExtendedValue(loc, builder, lhs);
auto [rhsExv, rhsCleanUp] =
hlfir::translateToExtendedValue(loc, builder, rhs);

auto resultVal = fir::runtime::genCharCompare(
builder, loc, cmp.getPredicate(), lhsExv, rhsExv);
if (lhsCleanUp || rhsCleanUp) {
mlir::OpBuilder::InsertionGuard guard(builder);
builder.setInsertionPointAfter(cmp);
if (lhsCleanUp)
(*lhsCleanUp)();
if (rhsCleanUp)
(*rhsCleanUp)();
}
auto resultEntity = hlfir::EntityWithAttributes{resultVal};

processReturnValue(cmp, resultEntity, /*mustBeFreed=*/false, builder,
rewriter);
return mlir::success();
}
};

class LowerHLFIRIntrinsics
: public hlfir::impl::LowerHLFIRIntrinsicsBase<LowerHLFIRIntrinsics> {
public:
void runOnOperation() override {
mlir::ModuleOp module = this->getOperation();
mlir::MLIRContext *context = &getContext();
mlir::RewritePatternSet patterns(context);
patterns.insert<
MatmulOpConversion, MatmulTransposeOpConversion, AllOpConversion,
AnyOpConversion, SumOpConversion, ProductOpConversion,
TransposeOpConversion, CountOpConversion, DotProductOpConversion,
MaxvalOpConversion, MinvalOpConversion, MinlocOpConversion,
MaxlocOpConversion, ArrayShiftOpConversion<hlfir::CShiftOp>,
ArrayShiftOpConversion<hlfir::EOShiftOp>, ReshapeOpConversion>(context);
patterns.insert<MatmulOpConversion, MatmulTransposeOpConversion,
AllOpConversion, AnyOpConversion, SumOpConversion,
ProductOpConversion, TransposeOpConversion,
CountOpConversion, DotProductOpConversion,
MaxvalOpConversion, MinvalOpConversion, MinlocOpConversion,
MaxlocOpConversion, ArrayShiftOpConversion<hlfir::CShiftOp>,
ArrayShiftOpConversion<hlfir::EOShiftOp>,
ReshapeOpConversion, CmpCharOpConversion>(context);

// While conceptually this pass is performing dialect conversion, we use
// pattern rewrites here instead of dialect conversion because this pass
Expand Down
Loading