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

[WIP]: Introducing ptr dialect and its riscv conversion #3350

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
18 changes: 18 additions & 0 deletions tests/filecheck/transforms/convert_memref_to_ptr.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,22 @@ memref.store %v, %arr2[%idx1, %idx2] {"nontemporal" = false} : memref<10x10xi32>
// CHECK-NEXT: %lv2_6 = ptr.ptradd %lv2_5, %lv2_4 : (!ptr.ptr, index) -> !ptr.ptr
// CHECK-NEXT: %lv2_7 = ptr.load %lv2_6 : !ptr.ptr -> i32

%fv, %farr = "test.op"() : () -> (f64, memref<10xf64>)
memref.store %fv, %farr[%idx] {"nontemporal" = false} : memref<10xf64>

// CHECK-NEXT: %fv, %farr = "test.op"() : () -> (f64, memref<10xf64>)
// CHECK-NEXT: %11 = "ptr.type_offset"() <{"elem_type" = f64}> : () -> index
// CHECK-NEXT: %12 = arith.muli %idx, %11 : index
// CHECK-NEXT: %13 = memref.to_ptr %farr : memref<10xf64> -> !ptr.ptr
// CHECK-NEXT: %14 = ptr.ptradd %13, %12 : (!ptr.ptr, index) -> !ptr.ptr
// CHECK-NEXT: ptr.store %fv, %14 : f64, !ptr.ptr

%flv = memref.load %farr[%idx] {"nontemporal" = false} : memref<10xf64>

// CHECK-NEXT: %flv = "ptr.type_offset"() <{"elem_type" = f64}> : () -> index
// CHECK-NEXT: %flv_1 = arith.muli %idx, %flv : index
// CHECK-NEXT: %flv_2 = memref.to_ptr %farr : memref<10xf64> -> !ptr.ptr
// CHECK-NEXT: %flv_3 = ptr.ptradd %flv_2, %flv_1 : (!ptr.ptr, index) -> !ptr.ptr
// CHECK-NEXT: %flv_4 = ptr.load %flv_3 : !ptr.ptr -> f64

// CHECK-NEXT: }
3 changes: 2 additions & 1 deletion xdsl/dialects/ptr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from xdsl.ir import Dialect, ParametrizedAttribute, TypeAttribute
from xdsl.irdl import (
AnyOf,
Attribute,
IRDLOperation,
base,
irdl_attr_definition,
Expand Down Expand Up @@ -34,7 +35,7 @@ class PtrAddOp(IRDLOperation):
class TypeOffsetOp(IRDLOperation):
name = "ptr.type_offset"

elem_type = prop_def(base(IntegerType))
elem_type = prop_def(base(Attribute))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
elem_type = prop_def(base(Attribute))
elem_type = prop_def()

offset = result_def(AnyOf([IntegerType, IndexType]))


Expand Down
2 changes: 1 addition & 1 deletion xdsl/transforms/convert_memref_to_ptr.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def offset_calculations(
bytes_per_element_op := ptr.TypeOffsetOp(
operands=[],
result_types=[builtin.IndexType()],
properties={"elem_type": i32},
properties={"elem_type": memref_type.element_type},
),
final_offset := arith.Muli(head, bytes_per_element_op),
]
Expand Down
Loading