33
44include "mlir/IR/OpBase.td"
55include "mlir/Interfaces/SideEffectInterfaces.td"
6- // include "mlir/Dialect/Ptr/IR/MemorySpaceInterfaces.td"
7- // include "mlir/Dialect/Ptr/IR/PtrDialect.td"
6+ include "mlir/Dialect/Ptr/IR/MemorySpaceInterfaces.td"
7+ include "mlir/Dialect/Ptr/IR/PtrDialect.td"
88include "mlir/IR/AttrTypeBase.td"
99include "mlir/IR/BuiltinAttributeInterfaces.td"
1010include "mlir/IR/BuiltinTypeInterfaces.td"
11- include "triton/Dialect/Triton/IR/TritonDialect.td"
12- include "triton/Dialect/Triton/IR/TritonTypes.td"
13-
1411
1512def TPtr_Dialect : Dialect {
1613 let name = "tptr";
@@ -27,8 +24,8 @@ def TPtr_Dialect : Dialect {
2724 void registerTypes();
2825 }];
2926
30- let dependentDialects = [
31- "mlir::triton::TritonDialect "
27+ let dependentDialects = [
28+ "mlir::ptr::PtrDialect "
3229 ];
3330
3431 let useDefaultAttributePrinterParser = 1;
@@ -50,10 +47,10 @@ class TPtr_Attr<string name, string _mnemonic,
5047// Memory space attr is required for building Ptr ops
5148// This acts as default memory space since there is
5249// no such default implemented upstream
53- // def DefaultMemorySpaceAttr
54- // : TPtr_Attr<"DefaultMemorySpace", "default_memory_space",
55- // [DeclareAttrInterfaceMethods<MemorySpaceAttrInterface>]> {
56- // }
50+ def DefaultMemorySpaceAttr
51+ : TPtr_Attr<"DefaultMemorySpace", "default_memory_space",
52+ [DeclareAttrInterfaceMethods<MemorySpaceAttrInterface>]> {
53+ }
5754
5855//
5956// Op Base
@@ -75,7 +72,7 @@ def TPTR_IntToPtrOp : TPTR_Op<"inttoptr", [
7572 ```
7673 }];
7774 let arguments = (ins AnySignlessIntegerOrIndex:$arg);
78- let results = (outs TT_PtrLike :$res);
75+ let results = (outs Ptr_PtrType :$res);
7976 let assemblyFormat = "$arg attr-dict `:` type($arg) `to` type($res)";
8077}
8178
@@ -91,61 +88,45 @@ def TPTR_PtrToIntOp : TPTR_Op<"ptrtoint", [
9188 %int = ptr.ptrtoint %ptr : !ptr.ptr<1 : i32> to i32
9289 ```
9390 }];
94- let arguments = (ins TT_PtrLike :$arg);
91+ let arguments = (ins Ptr_PtrType :$arg);
9592 let results = (outs AnySignlessIntegerOrIndex:$res);
9693 let assemblyFormat = "$arg attr-dict `:` type($arg) `to` type($res)";
9794}
9895
99- // def TPTR_TypeOffsetOp : TPTR_Op<"type_offset", [ConstantLike, Pure]> {
100- // let summary = "Creates a type offset constant.";
101- // let description = [{
102- // The `addr.type_offset` operation produces an int or index-typed SSA value
103- // equal to a target-specific constant representing the offset of a single
104- // element of the given type. The default return type is `index`.
105- // Example:
106-
107- // ```mlir
108- // %0 = addr.type_offset f32
109- // %1 = addr.type_offset memref<12 x f64> : i32
110- // ```
111- // }];
112-
113- // let arguments = (ins TypeAttr:$baseType);
114- // let results = (outs AnySignlessIntegerOrIndex:$result);
115- // let builders = [
116- // OpBuilder<(ins "TypeAttr":$baseType, CArg<"Type", "nullptr">:$resultTy), [{
117- // Type resultType = resultTy ? resultTy : $_builder.getIndexType();
118- // $_state.addAttribute("baseType", baseType);
119- // $_state.addTypes(resultType);
120- // }]>,
121- // OpBuilder<(ins "Type":$baseType), [{
122- // TypeAttr baseTypeAttr = TypeAttr::get(baseType);
123- // Type resultType = $_builder.getIndexType();
124- // $_state.addAttribute("baseType", baseTypeAttr);
125- // $_state.addTypes(resultType);
126- // }]>
127- // ];
128- // let assemblyFormat = [{
129- // attr-dict $baseType custom<IntType>(type($result))
130- // }];
131- // let extraClassDeclaration = [{
132- // /// Returns the type offset according to `layout`. If `layout` is `nullopt`
133- // /// the nearest layout the op will be used for the computation.
134- // /// ! I copied this from ptr dialect
135- // llvm::TypeSize getTypeSize(std::optional<DataLayout> layout = std::nullopt);
136- // }];
137- // let hasFolder = 1;
138- // }
96+ def TPTR_TypeOffsetOp : TPTR_Op<"type_offset", [ConstantLike, Pure]> {
97+ let summary = "Creates a type offset constant.";
98+ let description = [{
99+ The `addr.type_offset` operation produces an int or index-typed SSA value
100+ equal to a target-specific constant representing the offset of a single
101+ element of the given type. The default return type is `index`.
102+ Example:
103+
104+ ```mlir
105+ %0 = addr.type_offset f32
106+ %1 = addr.type_offset memref<12 x f64> : i32
107+ ```
108+ }];
109+
110+ let arguments = (ins TypeAttr:$baseType);
111+ let results = (outs AnySignlessIntegerOrIndex:$result);
112+ let builders = [
113+ OpBuilder<(ins "TypeAttr":$baseType, CArg<"Type", "nullptr">:$resultTy)>
114+ ];
115+ let assemblyFormat = [{
116+ attr-dict $baseType custom<IntType>(type($result))
117+ }];
118+ let hasFolder = 1;
119+ }
139120
140121def TPTR_FromMemrefOp : TPTR_Op<"from_memref", [Pure]> {
141122 let arguments = (ins AnyMemRef:$input);
142- let results = (outs TT_PtrLike :$result);
123+ let results = (outs Ptr_PtrType :$result);
143124 let assemblyFormat = "$input attr-dict `:` type($input) `to` type($result)";
144125}
145126
146127def TPTR_ToMemrefOp : TPTR_Op<"to_memref", [
147128 Pure ]> {
148- let arguments = (ins TT_PtrLike :$arg);
129+ let arguments = (ins Ptr_PtrType :$arg);
149130 let results = (outs AnyStaticShapeMemRef:$res);
150131 let assemblyFormat = "$arg attr-dict `:` type($arg) `to` type($res)";
151132}
@@ -162,8 +143,8 @@ def TPTR_PtrAddOp : TPTR_Op<"ptradd", [Pure, AllTypesMatch<["base", "result"]>]>
162143 ```
163144 }];
164145
165- let arguments = (ins TT_PtrLike :$base, AnySignlessIntegerOrIndex:$offset);
166- let results = (outs TT_PtrLike :$result);
146+ let arguments = (ins Ptr_PtrType :$base, AnySignlessIntegerOrIndex:$offset);
147+ let results = (outs Ptr_PtrType :$result);
167148 let assemblyFormat = "$base $offset attr-dict `:` type($base) `,` type($offset) `to` type($result)";
168149}
169150
0 commit comments