@@ -36,7 +36,7 @@ class Ptr_ShapedValueType<list<Type> allowedTypes, list<Pred> preds = []> :
36
36
/*cppType=*/"::mlir::ShapedType">;
37
37
38
38
// A ptr-like type, either scalar or shaped type with value semantics.
39
- def Ptr_PtrLikeType :
39
+ def Ptr_PtrLikeType :
40
40
AnyTypeOf<[Ptr_ShapedValueType<[Ptr_PtrType], [HasRankPred]>, Ptr_PtrType]>;
41
41
42
42
// An int-like type, either scalar or shaped type with value semantics.
@@ -57,6 +57,31 @@ def Ptr_Mask1DType :
57
57
def Ptr_Ptr1DType :
58
58
Ptr_ShapedValueType<[Ptr_PtrType], [HasAnyRankOfPred<[1]>]>;
59
59
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
+
60
85
//===----------------------------------------------------------------------===//
61
86
// FromPtrOp
62
87
//===----------------------------------------------------------------------===//
@@ -81,7 +106,7 @@ def Ptr_FromPtrOp : Pointer_Op<"from_ptr", [
81
106
```mlir
82
107
%typed_ptr = ptr.from_ptr %ptr : !ptr.ptr<#ptr.generic_space> -> !my.ptr<f32, #ptr.generic_space>
83
108
%memref = ptr.from_ptr %ptr metadata %md : !ptr.ptr<#ptr.generic_space> -> memref<f32, #ptr.generic_space>
84
-
109
+
85
110
// Cast the `%ptr` to a memref without utilizing metadata.
86
111
%memref = ptr.from_ptr %ptr : !ptr.ptr<#ptr.generic_space> -> memref<f32, #ptr.generic_space>
87
112
```
@@ -361,13 +386,13 @@ def Ptr_PtrAddOp : Pointer_Op<"ptr_add", [
361
386
// Scalar base and offset
362
387
%x_off = ptr.ptr_add %x, %off : !ptr.ptr<#ptr.generic_space>, i32
363
388
%x_off0 = ptr.ptr_add nusw %x, %off : !ptr.ptr<#ptr.generic_space>, i32
364
-
389
+
365
390
// Shaped base with scalar offset
366
391
%ptrs_off = ptr.ptr_add %ptrs, %off : vector<4x!ptr.ptr<#ptr.generic_space>>, i32
367
-
392
+
368
393
// Scalar base with shaped offset
369
394
%x_offs = ptr.ptr_add %x, %offs : !ptr.ptr<#ptr.generic_space>, vector<4xi32>
370
-
395
+
371
396
// Both base and offset are shaped
372
397
%ptrs_offs = ptr.ptr_add %ptrs, %offs : vector<4x!ptr.ptr<#ptr.generic_space>>, vector<4xi32>
373
398
```
@@ -382,7 +407,7 @@ def Ptr_PtrAddOp : Pointer_Op<"ptr_add", [
382
407
}];
383
408
let hasFolder = 1;
384
409
let extraClassDeclaration = [{
385
- /// `ViewLikeOp::getViewSource` method.
410
+ /// `ViewLikeOp::getViewSource` method.
386
411
Value getViewSource() { return getBase(); }
387
412
388
413
/// Returns the ptr type of the operation.
@@ -418,7 +443,7 @@ def Ptr_ScatterOp : Pointer_Op<"scatter", [
418
443
// Scatter values to multiple memory locations
419
444
ptr.scatter %value, %ptrs, %mask :
420
445
vector<4xf32>, vector<4x!ptr.ptr<#ptr.generic_space>>
421
-
446
+
422
447
// Scatter with alignment
423
448
ptr.scatter %value, %ptrs, %mask alignment = 8 :
424
449
vector<4xf32>, vector<4x!ptr.ptr<#ptr.generic_space>>
0 commit comments