@@ -36,7 +36,7 @@ class Ptr_ShapedValueType<list<Type> allowedTypes, list<Pred> preds = []> :
3636 /*cppType=*/"::mlir::ShapedType">;
3737
3838// A ptr-like type, either scalar or shaped type with value semantics.
39- def Ptr_PtrLikeType :
39+ def Ptr_PtrLikeType :
4040 AnyTypeOf<[Ptr_ShapedValueType<[Ptr_PtrType], [HasRankPred]>, Ptr_PtrType]>;
4141
4242// An int-like type, either scalar or shaped type with value semantics.
@@ -57,6 +57,31 @@ def Ptr_Mask1DType :
5757def Ptr_Ptr1DType :
5858 Ptr_ShapedValueType<[Ptr_PtrType], [HasAnyRankOfPred<[1]>]>;
5959
60+ //===----------------------------------------------------------------------===//
61+ // ConstantOp
62+ //===----------------------------------------------------------------------===//
63+
64+ def Ptr_ConstantOp : Pointer_Op<"constant", [
65+ ConstantLike, Pure, AllTypesMatch<["value", "result"]>
66+ ]> {
67+ let summary = "Pointer constant operation";
68+ let description = [{
69+ The `constant` operation produces a pointer constant. The attribute must be
70+ a typed attribute of pointer type.
71+
72+ Example:
73+
74+ ```mlir
75+ // Create a null pointer
76+ %null = ptr.constant #ptr.null : !ptr.ptr<#ptr.generic_space>
77+ ```
78+ }];
79+ let arguments = (ins TypedAttrInterface:$value);
80+ let results = (outs Ptr_PtrType:$result);
81+ let assemblyFormat = "attr-dict $value";
82+ let hasFolder = 1;
83+ }
84+
6085//===----------------------------------------------------------------------===//
6186// FromPtrOp
6287//===----------------------------------------------------------------------===//
@@ -81,7 +106,7 @@ def Ptr_FromPtrOp : Pointer_Op<"from_ptr", [
81106 ```mlir
82107 %typed_ptr = ptr.from_ptr %ptr : !ptr.ptr<#ptr.generic_space> -> !my.ptr<f32, #ptr.generic_space>
83108 %memref = ptr.from_ptr %ptr metadata %md : !ptr.ptr<#ptr.generic_space> -> memref<f32, #ptr.generic_space>
84-
109+
85110 // Cast the `%ptr` to a memref without utilizing metadata.
86111 %memref = ptr.from_ptr %ptr : !ptr.ptr<#ptr.generic_space> -> memref<f32, #ptr.generic_space>
87112 ```
@@ -361,13 +386,13 @@ def Ptr_PtrAddOp : Pointer_Op<"ptr_add", [
361386 // Scalar base and offset
362387 %x_off = ptr.ptr_add %x, %off : !ptr.ptr<#ptr.generic_space>, i32
363388 %x_off0 = ptr.ptr_add nusw %x, %off : !ptr.ptr<#ptr.generic_space>, i32
364-
389+
365390 // Shaped base with scalar offset
366391 %ptrs_off = ptr.ptr_add %ptrs, %off : vector<4x!ptr.ptr<#ptr.generic_space>>, i32
367-
392+
368393 // Scalar base with shaped offset
369394 %x_offs = ptr.ptr_add %x, %offs : !ptr.ptr<#ptr.generic_space>, vector<4xi32>
370-
395+
371396 // Both base and offset are shaped
372397 %ptrs_offs = ptr.ptr_add %ptrs, %offs : vector<4x!ptr.ptr<#ptr.generic_space>>, vector<4xi32>
373398 ```
@@ -382,7 +407,7 @@ def Ptr_PtrAddOp : Pointer_Op<"ptr_add", [
382407 }];
383408 let hasFolder = 1;
384409 let extraClassDeclaration = [{
385- /// `ViewLikeOp::getViewSource` method.
410+ /// `ViewLikeOp::getViewSource` method.
386411 Value getViewSource() { return getBase(); }
387412
388413 /// Returns the ptr type of the operation.
@@ -418,7 +443,7 @@ def Ptr_ScatterOp : Pointer_Op<"scatter", [
418443 // Scatter values to multiple memory locations
419444 ptr.scatter %value, %ptrs, %mask :
420445 vector<4xf32>, vector<4x!ptr.ptr<#ptr.generic_space>>
421-
446+
422447 // Scatter with alignment
423448 ptr.scatter %value, %ptrs, %mask alignment = 8 :
424449 vector<4xf32>, vector<4x!ptr.ptr<#ptr.generic_space>>
0 commit comments