This is a port of the 'ptr' dialect proposed in this thread https://discourse.llvm.org/t/rfc-ptr-dialect-modularizing-ptr-ops-in-the-llvm-dialect/75142/21
Main parts of the dialect has already been agreed upon but only the basic datatype is
implemented upstream.
When the upstream implementation is merged we should fix our implementation to be
consistent with the mlir version.
Current deviations:
1. Name of the dialect should be changed: ptr_xdsl -> ptr. We currently chose another
name to avoid conflicts when loading our dialect to mlir-opt.
2. There is no ptr.to_ptr operation currently proposed, but there is a memref.to_ptr.
We do this so that we can feed the results of convert-memref-to-ptr pass without any
conflict.
Ptr = Dialect('ptr_xdsl', [PtrAddOp, TypeOffsetOp, StoreOp, LoadOp, ToPtrOp, FromPtrOp], [PtrType])
module-attribute
PtrType
dataclass
Bases: ParametrizedAttribute, TypeAttribute
Source code in xdsl/dialects/ptr.py
| @irdl_attr_definition
class PtrType(ParametrizedAttribute, TypeAttribute):
name = "ptr_xdsl.ptr"
|
name = 'ptr_xdsl.ptr'
class-attribute
instance-attribute
PtrAddOpHasCanonicalizationPatterns
dataclass
Bases: HasCanonicalizationPatternsTrait
Source code in xdsl/dialects/ptr.py
| class PtrAddOpHasCanonicalizationPatterns(HasCanonicalizationPatternsTrait):
@classmethod
def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
from xdsl.transforms.canonicalization_patterns import ptr
return (ptr.PtrAddZero(),)
|
get_canonicalization_patterns() -> tuple[RewritePattern, ...]
classmethod
Source code in xdsl/dialects/ptr.py
| @classmethod
def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
from xdsl.transforms.canonicalization_patterns import ptr
return (ptr.PtrAddZero(),)
|
PtrAddOp
Bases: IRDLOperation
Source code in xdsl/dialects/ptr.py
51
52
53
54
55
56
57
58
59
60
61
62
63
64 | @irdl_op_definition
class PtrAddOp(IRDLOperation):
name = "ptr_xdsl.ptradd"
addr = operand_def(PtrType)
offset = operand_def(IntegerAttrTypeConstr)
result = result_def(PtrType)
assembly_format = "$addr `,` $offset attr-dict `:` `(` type($addr) `,` type($offset) `)` `->` type($result)"
traits = traits_def(PtrAddOpHasCanonicalizationPatterns())
def __init__(self, addr: SSAValue, offset: SSAValue):
super().__init__(operands=(addr, offset), result_types=(PtrType(),))
|
name = 'ptr_xdsl.ptradd'
class-attribute
instance-attribute
addr = operand_def(PtrType)
class-attribute
instance-attribute
offset = operand_def(IntegerAttrTypeConstr)
class-attribute
instance-attribute
result = result_def(PtrType)
class-attribute
instance-attribute
traits = traits_def(PtrAddOpHasCanonicalizationPatterns())
class-attribute
instance-attribute
__init__(addr: SSAValue, offset: SSAValue)
Source code in xdsl/dialects/ptr.py
| def __init__(self, addr: SSAValue, offset: SSAValue):
super().__init__(operands=(addr, offset), result_types=(PtrType(),))
|
TypeOffsetOp
Bases: IRDLOperation
Source code in xdsl/dialects/ptr.py
68
69
70
71
72
73
74
75
76
77
78 | @irdl_op_definition
class TypeOffsetOp(IRDLOperation):
name = "ptr_xdsl.type_offset"
elem_type = prop_def(AnyAttr())
offset = result_def(IntegerAttrTypeConstr)
assembly_format = "$elem_type attr-dict `:` type($offset)"
def __init__(self, elem_type: Attribute, offset: IndexType | IntegerType):
super().__init__(properties={"elem_type": elem_type}, result_types=(offset,))
|
name = 'ptr_xdsl.type_offset'
class-attribute
instance-attribute
elem_type = prop_def(AnyAttr())
class-attribute
instance-attribute
offset = result_def(IntegerAttrTypeConstr)
class-attribute
instance-attribute
__init__(elem_type: Attribute, offset: IndexType | IntegerType)
Source code in xdsl/dialects/ptr.py
| def __init__(self, elem_type: Attribute, offset: IndexType | IntegerType):
super().__init__(properties={"elem_type": elem_type}, result_types=(offset,))
|
StoreOp
Bases: IRDLOperation
Source code in xdsl/dialects/ptr.py
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110 | @irdl_op_definition
class StoreOp(IRDLOperation):
name = "ptr_xdsl.store"
addr = operand_def(PtrType)
value = operand_def()
volatile = opt_prop_def(UnitAttr)
syncscope = opt_prop_def(UnitAttr)
ordering = opt_prop_def(UnitAttr)
assembly_format = "(`volatile` $volatile^)? $value `,` $addr (`atomic` (`syncscope` `(` $syncscope^ `)`)? $ordering^)? attr-dict `:` type($value) `,` type($addr)" # noqa: E501
def __init__(
self,
addr: SSAValue,
value: SSAValue,
*,
volatile: bool = False,
syncscope: bool = False,
ordering: bool = False,
):
super().__init__(
operands=(addr, value),
properties={
"volatile": UnitAttr() if volatile else None,
"syncscope": UnitAttr() if syncscope else None,
"ordering": UnitAttr() if ordering else None,
},
)
|
name = 'ptr_xdsl.store'
class-attribute
instance-attribute
addr = operand_def(PtrType)
class-attribute
instance-attribute
value = operand_def()
class-attribute
instance-attribute
volatile = opt_prop_def(UnitAttr)
class-attribute
instance-attribute
syncscope = opt_prop_def(UnitAttr)
class-attribute
instance-attribute
ordering = opt_prop_def(UnitAttr)
class-attribute
instance-attribute
__init__(addr: SSAValue, value: SSAValue, *, volatile: bool = False, syncscope: bool = False, ordering: bool = False)
Source code in xdsl/dialects/ptr.py
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110 | def __init__(
self,
addr: SSAValue,
value: SSAValue,
*,
volatile: bool = False,
syncscope: bool = False,
ordering: bool = False,
):
super().__init__(
operands=(addr, value),
properties={
"volatile": UnitAttr() if volatile else None,
"syncscope": UnitAttr() if syncscope else None,
"ordering": UnitAttr() if ordering else None,
},
)
|
LoadOp
Bases: IRDLOperation
Source code in xdsl/dialects/ptr.py
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146 | @irdl_op_definition
class LoadOp(IRDLOperation):
name = "ptr_xdsl.load"
addr = operand_def(PtrType)
res = result_def()
volatile = opt_prop_def(UnitAttr)
syncscope = opt_prop_def(UnitAttr)
ordering = opt_prop_def(UnitAttr)
invariant = opt_prop_def(UnitAttr)
assembly_format = "(`volatile` $volatile^)? $addr (`atomic` (`syncscope` `(` $syncscope^ `)`)? $ordering^)? (`invariant` $invariant^)? attr-dict `:` type($addr) `->` type($res)" # noqa: E501
def __init__(
self,
addr: SSAValue,
result_type: Attribute,
*,
volatile: bool = False,
syncscope: bool = False,
ordering: bool = False,
invariant: bool = False,
):
super().__init__(
operands=(addr,),
result_types=(result_type,),
properties={
"volatile": UnitAttr() if volatile else None,
"syncscope": UnitAttr() if syncscope else None,
"ordering": UnitAttr() if ordering else None,
"invariant": UnitAttr() if invariant else None,
},
)
|
name = 'ptr_xdsl.load'
class-attribute
instance-attribute
addr = operand_def(PtrType)
class-attribute
instance-attribute
res = result_def()
class-attribute
instance-attribute
volatile = opt_prop_def(UnitAttr)
class-attribute
instance-attribute
syncscope = opt_prop_def(UnitAttr)
class-attribute
instance-attribute
ordering = opt_prop_def(UnitAttr)
class-attribute
instance-attribute
invariant = opt_prop_def(UnitAttr)
class-attribute
instance-attribute
__init__(addr: SSAValue, result_type: Attribute, *, volatile: bool = False, syncscope: bool = False, ordering: bool = False, invariant: bool = False)
Source code in xdsl/dialects/ptr.py
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146 | def __init__(
self,
addr: SSAValue,
result_type: Attribute,
*,
volatile: bool = False,
syncscope: bool = False,
ordering: bool = False,
invariant: bool = False,
):
super().__init__(
operands=(addr,),
result_types=(result_type,),
properties={
"volatile": UnitAttr() if volatile else None,
"syncscope": UnitAttr() if syncscope else None,
"ordering": UnitAttr() if ordering else None,
"invariant": UnitAttr() if invariant else None,
},
)
|
ToPtrOpHasCanonicalizationPatternsTrait
dataclass
Bases: HasCanonicalizationPatternsTrait
Source code in xdsl/dialects/ptr.py
| class ToPtrOpHasCanonicalizationPatternsTrait(HasCanonicalizationPatternsTrait):
@classmethod
def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
from xdsl.transforms.canonicalization_patterns.ptr import RedundantToPtr
return (RedundantToPtr(),)
|
get_canonicalization_patterns() -> tuple[RewritePattern, ...]
classmethod
Source code in xdsl/dialects/ptr.py
| @classmethod
def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
from xdsl.transforms.canonicalization_patterns.ptr import RedundantToPtr
return (RedundantToPtr(),)
|
ToPtrOp
Bases: IRDLOperation
Source code in xdsl/dialects/ptr.py
157
158
159
160
161
162
163
164
165
166
167
168
169 | @irdl_op_definition
class ToPtrOp(IRDLOperation):
name = "ptr_xdsl.to_ptr"
source = operand_def(MemRefType)
res = result_def(PtrType)
assembly_format = "$source attr-dict `:` type($source) `->` type($res)"
traits = traits_def(Pure(), ToPtrOpHasCanonicalizationPatternsTrait())
def __init__(self, source: SSAValue):
super().__init__(operands=(source,), result_types=(PtrType(),))
|
name = 'ptr_xdsl.to_ptr'
class-attribute
instance-attribute
source = operand_def(MemRefType)
class-attribute
instance-attribute
res = result_def(PtrType)
class-attribute
instance-attribute
traits = traits_def(Pure(), ToPtrOpHasCanonicalizationPatternsTrait())
class-attribute
instance-attribute
__init__(source: SSAValue)
Source code in xdsl/dialects/ptr.py
| def __init__(self, source: SSAValue):
super().__init__(operands=(source,), result_types=(PtrType(),))
|
FromPtrOpHasCanonicalizationPatternsTrait
dataclass
Bases: HasCanonicalizationPatternsTrait
Source code in xdsl/dialects/ptr.py
| class FromPtrOpHasCanonicalizationPatternsTrait(HasCanonicalizationPatternsTrait):
@classmethod
def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
from xdsl.transforms.canonicalization_patterns.ptr import RedundantFromPtr
return (RedundantFromPtr(),)
|
get_canonicalization_patterns() -> tuple[RewritePattern, ...]
classmethod
Source code in xdsl/dialects/ptr.py
| @classmethod
def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
from xdsl.transforms.canonicalization_patterns.ptr import RedundantFromPtr
return (RedundantFromPtr(),)
|
FromPtrOp
Bases: IRDLOperation
Source code in xdsl/dialects/ptr.py
180
181
182
183
184
185
186
187
188
189
190
191
192 | @irdl_op_definition
class FromPtrOp(IRDLOperation):
name = "ptr_xdsl.from_ptr"
source = operand_def(PtrType)
res = result_def(MemRefType)
assembly_format = "$source attr-dict `:` type($source) `->` type($res)"
traits = traits_def(Pure(), FromPtrOpHasCanonicalizationPatternsTrait())
def __init__(self, source: SSAValue, result_type: MemRefType):
super().__init__(operands=(source,), result_types=(result_type,))
|
name = 'ptr_xdsl.from_ptr'
class-attribute
instance-attribute
source = operand_def(PtrType)
class-attribute
instance-attribute
res = result_def(MemRefType)
class-attribute
instance-attribute
traits = traits_def(Pure(), FromPtrOpHasCanonicalizationPatternsTrait())
class-attribute
instance-attribute
__init__(source: SSAValue, result_type: MemRefType)
Source code in xdsl/dialects/ptr.py
| def __init__(self, source: SSAValue, result_type: MemRefType):
super().__init__(operands=(source,), result_types=(result_type,))
|