Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EmitC: Allow casts between opaque and float types #428

Merged
merged 3 commits into from
Dec 17, 2024
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
4 changes: 2 additions & 2 deletions mlir/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ class TruncFConversion : public OpConversionPattern<arith::TruncFOp> {
return rewriter.notifyMatchFailure(castOp,
"unsupported cast destination type");

if (!castOp.areCastCompatible(operandType, dstType))
if (!emitc::CastOp::areCastCompatible(operandType, dstType))
return rewriter.notifyMatchFailure(castOp, "cast-incompatible types");

rewriter.replaceOpWithNewOp<emitc::CastOp>(castOp, dstType,
Expand Down Expand Up @@ -787,7 +787,7 @@ class ExtFConversion : public OpConversionPattern<arith::ExtFOp> {
return rewriter.notifyMatchFailure(castOp,
"unsupported cast destination type");

if (!castOp.areCastCompatible(operandType, dstType))
if (!emitc::CastOp::areCastCompatible(operandType, dstType))
return rewriter.notifyMatchFailure(castOp, "cast-incompatible types");

rewriter.replaceOpWithNewOp<emitc::CastOp>(castOp, dstType,
Expand Down
4 changes: 4 additions & 0 deletions mlir/lib/Dialect/EmitC/IR/EmitC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,10 @@ LogicalResult emitc::AssignOp::verify() {
bool CastOp::areCastCompatible(TypeRange inputs, TypeRange outputs) {
Type input = inputs.front(), output = outputs.front();

// Opaque types are always allowed
if (isa<emitc::OpaqueType>(input) || isa<emitc::OpaqueType>(output))
return true;

// Cast to array is only possible from an array
if (isa<emitc::ArrayType>(input) != isa<emitc::ArrayType>(output))
return false;
Expand Down
4 changes: 4 additions & 0 deletions mlir/test/Dialect/EmitC/ops.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,15 @@ emitc.func private @extern(i32) attributes {specifiers = ["extern"]}

func.func @cast(%arg0: i32) {
%1 = emitc.cast %arg0: i32 to f32
%2 = emitc.cast %1: f32 to !emitc.opaque<"some type">
%3 = emitc.cast %2: !emitc.opaque<"some type"> to !emitc.size_t
return
}

func.func @cast_array(%arg : !emitc.array<4xf32>) {
%1 = emitc.cast %arg: !emitc.array<4xf32> to !emitc.array<4xf32> ref
%2 = emitc.cast %arg: !emitc.array<4xf32> to !emitc.opaque<"some type">
%3 = emitc.cast %2: !emitc.opaque<"some type"> to !emitc.array<4xf32> ref
return
}

Expand Down
Loading