-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[mlir][emitc] Support array result for emitc.member
and emitc.member_of_ptr
#155224
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
…member_of_ptr` This PR adds ArrayType as a valid result type for `emitc.member` and `emitc.member_of_ptr`, enabling direct access and assignment to struct array members in EmitC.
@llvm/pr-subscribers-mlir @llvm/pr-subscribers-mlir-emitc Author: Longsheng Mou (CoTinker) ChangesThis PR adds array type as a valid result type for Full diff: https://github.com/llvm/llvm-project/pull/155224.diff 2 Files Affected:
diff --git a/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td b/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td
index 59beac7d64154..9798015400a81 100644
--- a/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td
+++ b/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td
@@ -1051,6 +1051,8 @@ def EmitC_MemberOp : EmitC_Op<"member"> {
```mlir
%0 = "emitc.member" (%arg0) {member = "a"}
: (!emitc.lvalue<!emitc.opaque<"mystruct">>) -> !emitc.lvalue<i32>
+ %1 = "emitc.member" (%arg0) {member = "b"}
+ : (!emitc.lvalue<!emitc.opaque<"mystruct">>) -> !emitc.array<2xi32>
```
}];
@@ -1058,7 +1060,7 @@ def EmitC_MemberOp : EmitC_Op<"member"> {
Arg<StrAttr, "the member to access">:$member,
EmitC_LValueOf<[EmitC_OpaqueType]>:$operand
);
- let results = (outs EmitC_LValueOf<[EmitCType]>);
+ let results = (outs AnyTypeOf<[EmitC_ArrayType, EmitC_LValueType]>);
}
def EmitC_MemberOfPtrOp : EmitC_Op<"member_of_ptr"> {
@@ -1073,6 +1075,9 @@ def EmitC_MemberOfPtrOp : EmitC_Op<"member_of_ptr"> {
%0 = "emitc.member_of_ptr" (%arg0) {member = "a"}
: (!emitc.lvalue<!emitc.ptr<!emitc.opaque<"mystruct">>>)
-> !emitc.lvalue<i32>
+ %1 = "emitc.member_of_ptr" (%arg0) {member = "b"}
+ : (!emitc.lvalue<!emitc.ptr<!emitc.opaque<"mystruct">>>)
+ -> !emitc.array<2xi32>
```
}];
@@ -1080,7 +1085,7 @@ def EmitC_MemberOfPtrOp : EmitC_Op<"member_of_ptr"> {
Arg<StrAttr, "the member to access">:$member,
EmitC_LValueOf<[EmitC_OpaqueType,EmitC_PointerType]>:$operand
);
- let results = (outs EmitC_LValueOf<[EmitCType]>);
+ let results = (outs AnyTypeOf<[EmitC_ArrayType, EmitC_LValueType]>);
}
def EmitC_ConditionalOp : EmitC_Op<"conditional",
diff --git a/mlir/test/Dialect/EmitC/ops.mlir b/mlir/test/Dialect/EmitC/ops.mlir
index acee0a8d53fe4..fec8431262f37 100644
--- a/mlir/test/Dialect/EmitC/ops.mlir
+++ b/mlir/test/Dialect/EmitC/ops.mlir
@@ -286,8 +286,11 @@ func.func @assign_global(%arg0 : i32) {
func.func @member_access(%arg0: !emitc.lvalue<!emitc.opaque<"mystruct">>, %arg1: !emitc.lvalue<!emitc.opaque<"mystruct_ptr">>, %arg2: !emitc.lvalue<!emitc.ptr<!emitc.opaque<"mystruct">>>) {
%0 = "emitc.member" (%arg0) {member = "a"} : (!emitc.lvalue<!emitc.opaque<"mystruct">>) -> !emitc.lvalue<i32>
- %1 = "emitc.member_of_ptr" (%arg1) {member = "a"} : (!emitc.lvalue<!emitc.opaque<"mystruct_ptr">>) -> !emitc.lvalue<i32>
- %2 = "emitc.member_of_ptr" (%arg2) {member = "a"} : (!emitc.lvalue<!emitc.ptr<!emitc.opaque<"mystruct">>>) -> !emitc.lvalue<i32>
+ %1 = "emitc.member" (%arg0) {member = "b"} : (!emitc.lvalue<!emitc.opaque<"mystruct">>) -> !emitc.array<2xi32>
+ %2 = "emitc.member_of_ptr" (%arg1) {member = "a"} : (!emitc.lvalue<!emitc.opaque<"mystruct_ptr">>) -> !emitc.lvalue<i32>
+ %3 = "emitc.member_of_ptr" (%arg1) {member = "b"} : (!emitc.lvalue<!emitc.opaque<"mystruct_ptr">>) -> !emitc.array<2xi32>
+ %4 = "emitc.member_of_ptr" (%arg2) {member = "a"} : (!emitc.lvalue<!emitc.ptr<!emitc.opaque<"mystruct">>>) -> !emitc.lvalue<i32>
+ %5 = "emitc.member_of_ptr" (%arg2) {member = "b"} : (!emitc.lvalue<!emitc.ptr<!emitc.opaque<"mystruct">>>) -> !emitc.array<2xi32>
return
}
|
Can you add Translation Tests please. Maybe reading an element with load and writing an element with subscript/assign. |
Sure, it’s already added. |
Ping~ |
Thanks for your review. |
This PR adds array type as a valid result type for
emitc.member
andemitc.member_of_ptr
, enabling direct access and assignment to struct array members in EmitC.