Skip to content

Commit 133e3ef

Browse files
committed
address reviewer comments
1 parent a2cfd2d commit 133e3ef

File tree

7 files changed

+36
-7
lines changed

7 files changed

+36
-7
lines changed

mlir/include/mlir/Dialect/Ptr/IR/PtrEnums.td

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,15 @@ def AtomicOrdering : I64EnumAttr<
6666
let cppNamespace = "::mlir::ptr";
6767
}
6868

69+
//===----------------------------------------------------------------------===//
70+
// Ptr add flags enum attr.
71+
//===----------------------------------------------------------------------===//
72+
73+
def Ptr_PtrAddFlags : I32EnumAttr<"PtrAddFlags", "Pointer add flags", [
74+
I32EnumAttrCase<"none", 0>, I32EnumAttrCase<"nusw", 1>,
75+
I32EnumAttrCase<"nuw", 2>, I32EnumAttrCase<"inbounds", 3>
76+
]> {
77+
let cppNamespace = "::mlir::ptr";
78+
}
79+
6980
#endif // PTR_ENUMS

mlir/include/mlir/Dialect/Ptr/IR/PtrOps.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "mlir/Dialect/Ptr/IR/PtrTypes.h"
2020
#include "mlir/IR/OpDefinition.h"
2121
#include "mlir/Interfaces/SideEffectInterfaces.h"
22+
#include "mlir/Interfaces/ViewLikeInterface.h"
2223

2324
#define GET_OP_CLASSES
2425
#include "mlir/Dialect/Ptr/IR/PtrOps.h.inc"

mlir/include/mlir/Dialect/Ptr/IR/PtrOps.td

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,19 @@
1111

1212
include "mlir/Dialect/Ptr/IR/PtrDialect.td"
1313
include "mlir/Dialect/Ptr/IR/PtrAttrDefs.td"
14+
include "mlir/Dialect/Ptr/IR/PtrEnums.td"
1415
include "mlir/Dialect/Ptr/IR/MemorySpaceInterfaces.td"
1516
include "mlir/Interfaces/SideEffectInterfaces.td"
17+
include "mlir/Interfaces/ViewLikeInterface.td"
1618
include "mlir/IR/OpAsmInterface.td"
1719

1820
//===----------------------------------------------------------------------===//
1921
// PtrAddOp
2022
//===----------------------------------------------------------------------===//
2123

2224
def Ptr_PtrAddOp : Pointer_Op<"ptradd", [
23-
Pure, AllTypesMatch<["base", "result"]>
25+
Pure, AllTypesMatch<["base", "result"]>,
26+
DeclareOpInterfaceMethods<ViewLikeOpInterface>
2427
]> {
2528
let summary = "Pointer add operation";
2629
let description = [{
@@ -30,14 +33,19 @@ def Ptr_PtrAddOp : Pointer_Op<"ptradd", [
3033
Example:
3134

3235
```mlir
33-
%x_off = ptr.ptradd %x, %off : !ptr.ptr<0>, i32
36+
%x_off = ptr.ptradd %x, %off : !ptr.ptr<0>, i32
37+
%x_off0 = ptr.ptradd nusw %x, %off : !ptr.ptr<0>, i32
3438
```
3539
}];
3640

37-
let arguments = (ins Ptr_PtrType:$base, AnySignlessIntegerOrIndex:$offset);
41+
let arguments = (ins
42+
Ptr_PtrType:$base,
43+
AnySignlessIntegerOrIndex:$offset,
44+
DefaultValuedAttr<Ptr_PtrAddFlags,
45+
"::mlir::ptr::PtrAddFlags::none">:$flags);
3846
let results = (outs Ptr_PtrType:$result);
3947
let assemblyFormat = [{
40-
$base `,` $offset attr-dict `:` type($base) `,` type($offset)
48+
($flags^)? $base `,` $offset attr-dict `:` type($base) `,` type($offset)
4149
}];
4250
let hasFolder = 1;
4351
}

mlir/lib/Dialect/Ptr/IR/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ add_mlir_dialect_library(
1414
MLIRIR
1515
MLIRDataLayoutInterfaces
1616
MLIRMemorySlotInterfaces
17+
MLIRViewLikeInterface
1718
)

mlir/lib/Dialect/Ptr/IR/PtrDialect.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ OpFoldResult PtrAddOp::fold(FoldAdaptor adaptor) {
5555
return nullptr;
5656
}
5757

58+
Value PtrAddOp::getViewSource() { return getBase(); }
59+
5860
//===----------------------------------------------------------------------===//
5961
// TypeOffsetOp
6062
//===----------------------------------------------------------------------===//

mlir/test/Dialect/Ptr/canonicalize.mlir

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ func.func @ops0(%ptr: !ptr.ptr<#ptr.int_space<3>>, %c: i1) -> !ptr.ptr<#ptr.int_
2020
%res0 = ptr.ptradd %ptr, %off0 : !ptr.ptr<#ptr.int_space<3>>, index
2121
%off1 = ptr.type_offset f32 : index
2222
%res1 = ptr.ptradd %res0, %off1 : !ptr.ptr<#ptr.int_space<3>>, index
23-
%res = scf.if %c -> !ptr.ptr<#ptr.int_space<3>> {
23+
%res3 = scf.if %c -> !ptr.ptr<#ptr.int_space<3>> {
2424
%off2 = ptr.type_offset f32 : index
2525
%res2 = ptr.ptradd %res1, %off2 : !ptr.ptr<#ptr.int_space<3>>, index
2626
scf.yield %res2 : !ptr.ptr<#ptr.int_space<3>>
2727
} else {
2828
scf.yield %ptr : !ptr.ptr<#ptr.int_space<3>>
2929
}
30-
return %res : !ptr.ptr<#ptr.int_space<3>>
30+
%off3 = index.constant 0
31+
%res4 = ptr.ptradd %res3, %off3 : !ptr.ptr<#ptr.int_space<3>>, index
32+
return %res4 : !ptr.ptr<#ptr.int_space<3>>
3133
}

mlir/test/Dialect/Ptr/ops.mlir

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: mlir-opt %s | FileCheck %s
1+
// RUN: mlir-opt %s --verify-roundtrip | FileCheck %s
22

33
/// Check op assembly.
44
func.func @ops0(%ptr: !ptr.ptr<#ptr.int_space>) -> !ptr.ptr<#ptr.int_space> {
@@ -7,5 +7,9 @@ func.func @ops0(%ptr: !ptr.ptr<#ptr.int_space>) -> !ptr.ptr<#ptr.int_space> {
77
// CHECK-NEXT: ptr.ptradd %{{.*}}, %{{.*}} : <#ptr.int_space>, index
88
%off = ptr.type_offset f32 : index
99
%res = ptr.ptradd %ptr, %off : !ptr.ptr<#ptr.int_space>, index
10+
%res0 = ptr.ptradd none %ptr, %off : !ptr.ptr<#ptr.int_space>, index
11+
%res1 = ptr.ptradd nusw %ptr, %off : !ptr.ptr<#ptr.int_space>, index
12+
%res2 = ptr.ptradd nuw %ptr, %off : !ptr.ptr<#ptr.int_space>, index
13+
%res3 = ptr.ptradd inbounds %ptr, %off : !ptr.ptr<#ptr.int_space>, index
1014
return %res : !ptr.ptr<#ptr.int_space>
1115
}

0 commit comments

Comments
 (0)