Skip to content

Commit

Permalink
Allow opaque types in casts (also for array types)
Browse files Browse the repository at this point in the history
  • Loading branch information
TinaAMD committed Dec 16, 2024
1 parent 96d2f92 commit 3a6675a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
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

0 comments on commit 3a6675a

Please sign in to comment.