-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[mlir][emitc] Add an option to cast array type to ptr type #126385
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
Conversation
@llvm/pr-subscribers-mlir-emitc @llvm/pr-subscribers-mlir Author: Andrey Timonin (EtoAndruwa) ChangesFull diff: https://github.com/llvm/llvm-project/pull/126385.diff 4 Files Affected:
diff --git a/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td b/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td
index 4fbce995ce5b80..360f2e84343636 100644
--- a/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td
+++ b/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td
@@ -266,8 +266,7 @@ def EmitC_CallOpaqueOp : EmitC_Op<"call_opaque", [CExpression]> {
def EmitC_CastOp : EmitC_Op<"cast",
[CExpression,
- DeclareOpInterfaceMethods<CastOpInterface>,
- SameOperandsAndResultShape]> {
+ DeclareOpInterfaceMethods<CastOpInterface>]> {
let summary = "Cast operation";
let description = [{
The `emitc.cast` operation performs an explicit type conversion and is emitted
diff --git a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
index 728a2d33f46e7f..01effa5734caa6 100644
--- a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
+++ b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
@@ -247,11 +247,12 @@ LogicalResult emitc::AssignOp::verify() {
bool CastOp::areCastCompatible(TypeRange inputs, TypeRange outputs) {
Type input = inputs.front(), output = outputs.front();
- return (
- (emitc::isIntegerIndexOrOpaqueType(input) ||
- emitc::isSupportedFloatType(input) || isa<emitc::PointerType>(input)) &&
- (emitc::isIntegerIndexOrOpaqueType(output) ||
- emitc::isSupportedFloatType(output) || isa<emitc::PointerType>(output)));
+ return ((emitc::isIntegerIndexOrOpaqueType(input) ||
+ emitc::isSupportedFloatType(input) ||
+ isa<emitc::PointerType>(input) || isa<emitc::ArrayType>(input)) &&
+ (emitc::isIntegerIndexOrOpaqueType(output) ||
+ emitc::isSupportedFloatType(output) ||
+ isa<emitc::PointerType>(output)));
}
//===----------------------------------------------------------------------===//
diff --git a/mlir/test/Dialect/EmitC/invalid_ops.mlir b/mlir/test/Dialect/EmitC/invalid_ops.mlir
index a0d8d7f59de115..c40195dd3473aa 100644
--- a/mlir/test/Dialect/EmitC/invalid_ops.mlir
+++ b/mlir/test/Dialect/EmitC/invalid_ops.mlir
@@ -130,9 +130,17 @@ func.func @cast_tensor(%arg : tensor<f32>) {
// -----
-func.func @cast_array(%arg : !emitc.array<4xf32>) {
- // expected-error @+1 {{'emitc.cast' op operand type '!emitc.array<4xf32>' and result type '!emitc.array<4xf32>' are cast incompatible}}
- %1 = emitc.cast %arg: !emitc.array<4xf32> to !emitc.array<4xf32>
+func.func @cast_to_array(%arg : f32) {
+ // expected-error @+1 {{'emitc.cast' op operand type 'f32' and result type '!emitc.array<4xf32>' are cast incompatible}}
+ %1 = emitc.cast %arg: f32 to !emitc.array<4xf32>
+ return
+}
+
+// -----
+
+func.func @cast_pointer_to_array(%arg : !emitc.ptr<i32>) {
+ // expected-error @+1 {{'emitc.cast' op operand type '!emitc.ptr<i32>' and result type '!emitc.array<3xi32>' are cast incompatible}}
+ %1 = emitc.cast %arg: !emitc.ptr<i32> to !emitc.array<3xi32>
return
}
diff --git a/mlir/test/Dialect/EmitC/ops.mlir b/mlir/test/Dialect/EmitC/ops.mlir
index 7fd0a2d020397b..c6f90f56008555 100644
--- a/mlir/test/Dialect/EmitC/ops.mlir
+++ b/mlir/test/Dialect/EmitC/ops.mlir
@@ -39,6 +39,11 @@ func.func @cast(%arg0: i32) {
return
}
+func.func @cast_array_to_pointer(%arg0: !emitc.array<3xi32>) {
+ %1 = emitc.cast %arg0: !emitc.array<3xi32> to !emitc.ptr<i32>
+ return
+}
+
func.func @c() {
%1 = "emitc.constant"(){value = 42 : i32} : () -> i32
%2 = "emitc.constant"(){value = 42 : index} : () -> !emitc.size_t
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR, I think we can strengthen the check a bit, otherwise this looks good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Can you please swap the PR title to [mlir][emitc] ...
.
845126e
to
2199c2f
Compare
@marbre, gentle ping |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Could someone please merge this PR? |
No description provided.