Skip to content

Commit e731342

Browse files
authored
[mlir][ptr] Switch LogicalResult to bool in MemorySpaceAttrInterrface (#137513)
This patch switches the return type in `MemorySpaceAttrInterface` methods from `LogicalResult` to `bool`. As `is*` methods are predicates. Users of the `MemorySpaceAttrInterface` API must note that, if `emitError` is non-null and the result of a `is*` method is `false`, then an error was likely emitted. To avoid the emission of an error the user can pass a default constructed `emitError`.
1 parent ee4b34c commit e731342

File tree

3 files changed

+54
-35
lines changed

3 files changed

+54
-35
lines changed

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

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ def MemorySpaceAttrInterface : AttrInterface<"MemorySpaceAttrInterface"> {
3535
This method checks if it's valid to load a value from the memory space
3636
with a specific type, alignment, and atomic ordering.
3737
If `emitError` is non-null then the method is allowed to emit errors.
38+
Furthermore, if `emitError` is non-null and the result is `false` an
39+
error must have been emitted.
3840
}],
39-
/*returnType=*/ "::mlir::LogicalResult",
41+
/*returnType=*/ "bool",
4042
/*methodName=*/ "isValidLoad",
4143
/*args=*/ (ins "::mlir::Type":$type,
4244
"::mlir::ptr::AtomicOrdering":$ordering,
@@ -48,8 +50,10 @@ def MemorySpaceAttrInterface : AttrInterface<"MemorySpaceAttrInterface"> {
4850
This method checks if it's valid to store a value in the memory space
4951
with a specific type, alignment, and atomic ordering.
5052
If `emitError` is non-null then the method is allowed to emit errors.
53+
Furthermore, if `emitError` is non-null and the result is `false` an
54+
error must have been emitted.
5155
}],
52-
/*returnType=*/ "::mlir::LogicalResult",
56+
/*returnType=*/ "bool",
5357
/*methodName=*/ "isValidStore",
5458
/*args=*/ (ins "::mlir::Type":$type,
5559
"::mlir::ptr::AtomicOrdering":$ordering,
@@ -61,8 +65,10 @@ def MemorySpaceAttrInterface : AttrInterface<"MemorySpaceAttrInterface"> {
6165
This method checks if it's valid to perform an atomic operation in the
6266
memory space with a specific type, alignment, and atomic ordering.
6367
If `emitError` is non-null then the method is allowed to emit errors.
68+
Furthermore, if `emitError` is non-null and the result is `false` an
69+
error must have been emitted.
6470
}],
65-
/*returnType=*/ "::mlir::LogicalResult",
71+
/*returnType=*/ "bool",
6672
/*methodName=*/ "isValidAtomicOp",
6773
/*args=*/ (ins "::mlir::ptr::AtomicBinOp":$op,
6874
"::mlir::Type":$type,
@@ -76,8 +82,10 @@ def MemorySpaceAttrInterface : AttrInterface<"MemorySpaceAttrInterface"> {
7682
in the memory space with a specific type, alignment, and atomic
7783
orderings.
7884
If `emitError` is non-null then the method is allowed to emit errors.
85+
Furthermore, if `emitError` is non-null and the result is `false` an
86+
error must have been emitted.
7987
}],
80-
/*returnType=*/ "::mlir::LogicalResult",
88+
/*returnType=*/ "bool",
8189
/*methodName=*/ "isValidAtomicXchg",
8290
/*args=*/ (ins "::mlir::Type":$type,
8391
"::mlir::ptr::AtomicOrdering":$successOrdering,
@@ -90,8 +98,10 @@ def MemorySpaceAttrInterface : AttrInterface<"MemorySpaceAttrInterface"> {
9098
This method checks if it's valid to perform an `addrspacecast` op
9199
in the memory space.
92100
If `emitError` is non-null then the method is allowed to emit errors.
101+
Furthermore, if `emitError` is non-null and the result is `false` an
102+
error must have been emitted.
93103
}],
94-
/*returnType=*/ "::mlir::LogicalResult",
104+
/*returnType=*/ "bool",
95105
/*methodName=*/ "isValidAddrSpaceCast",
96106
/*args=*/ (ins "::mlir::Type":$tgt,
97107
"::mlir::Type":$src,
@@ -101,11 +111,13 @@ def MemorySpaceAttrInterface : AttrInterface<"MemorySpaceAttrInterface"> {
101111
/*desc=*/ [{
102112
This method checks if it's valid to perform a `ptrtoint` or `inttoptr`
103113
op in the memory space.
104-
The first type is expected to be integer-like, while the second must be a
105-
ptr-like type.
114+
The first type is expected to be integer-like, while the second must be
115+
a ptr-like type.
106116
If `emitError` is non-null then the method is allowed to emit errors.
117+
Furthermore, if `emitError` is non-null and the result is `false` an
118+
error must have been emitted.
107119
}],
108-
/*returnType=*/ "::mlir::LogicalResult",
120+
/*returnType=*/ "bool",
109121
/*methodName=*/ "isValidPtrIntCast",
110122
/*args=*/ (ins "::mlir::Type":$intLikeTy,
111123
"::mlir::Type":$ptrLikeTy,

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,45 +23,45 @@ constexpr const static unsigned kBitsInByte = 8;
2323
// GenericSpaceAttr
2424
//===----------------------------------------------------------------------===//
2525

26-
LogicalResult GenericSpaceAttr::isValidLoad(
26+
bool GenericSpaceAttr::isValidLoad(
2727
Type type, ptr::AtomicOrdering ordering, IntegerAttr alignment,
2828
function_ref<InFlightDiagnostic()> emitError) const {
29-
return success();
29+
return true;
3030
}
3131

32-
LogicalResult GenericSpaceAttr::isValidStore(
32+
bool GenericSpaceAttr::isValidStore(
3333
Type type, ptr::AtomicOrdering ordering, IntegerAttr alignment,
3434
function_ref<InFlightDiagnostic()> emitError) const {
35-
return success();
35+
return true;
3636
}
3737

38-
LogicalResult GenericSpaceAttr::isValidAtomicOp(
38+
bool GenericSpaceAttr::isValidAtomicOp(
3939
ptr::AtomicBinOp op, Type type, ptr::AtomicOrdering ordering,
4040
IntegerAttr alignment, function_ref<InFlightDiagnostic()> emitError) const {
41-
return success();
41+
return true;
4242
}
4343

44-
LogicalResult GenericSpaceAttr::isValidAtomicXchg(
44+
bool GenericSpaceAttr::isValidAtomicXchg(
4545
Type type, ptr::AtomicOrdering successOrdering,
4646
ptr::AtomicOrdering failureOrdering, IntegerAttr alignment,
4747
function_ref<InFlightDiagnostic()> emitError) const {
48-
return success();
48+
return true;
4949
}
5050

51-
LogicalResult GenericSpaceAttr::isValidAddrSpaceCast(
51+
bool GenericSpaceAttr::isValidAddrSpaceCast(
5252
Type tgt, Type src, function_ref<InFlightDiagnostic()> emitError) const {
5353
// TODO: update this method once the `addrspace_cast` op is added to the
5454
// dialect.
5555
assert(false && "unimplemented, see TODO in the source.");
56-
return failure();
56+
return false;
5757
}
5858

59-
LogicalResult GenericSpaceAttr::isValidPtrIntCast(
59+
bool GenericSpaceAttr::isValidPtrIntCast(
6060
Type intLikeTy, Type ptrLikeTy,
6161
function_ref<InFlightDiagnostic()> emitError) const {
6262
// TODO: update this method once the int-cast ops are added to the dialect.
6363
assert(false && "unimplemented, see TODO in the source.");
64-
return failure();
64+
return false;
6565
}
6666

6767
//===----------------------------------------------------------------------===//

mlir/test/lib/Dialect/Test/TestAttributes.cpp

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -331,43 +331,50 @@ TestOpAsmAttrInterfaceAttr::getAlias(::llvm::raw_ostream &os) const {
331331
// TestConstMemorySpaceAttr
332332
//===----------------------------------------------------------------------===//
333333

334-
LogicalResult TestConstMemorySpaceAttr::isValidLoad(
334+
bool TestConstMemorySpaceAttr::isValidLoad(
335335
Type type, mlir::ptr::AtomicOrdering ordering, IntegerAttr alignment,
336336
function_ref<InFlightDiagnostic()> emitError) const {
337-
return success();
337+
return true;
338338
}
339339

340-
LogicalResult TestConstMemorySpaceAttr::isValidStore(
340+
bool TestConstMemorySpaceAttr::isValidStore(
341341
Type type, mlir::ptr::AtomicOrdering ordering, IntegerAttr alignment,
342342
function_ref<InFlightDiagnostic()> emitError) const {
343-
return emitError ? (emitError() << "memory space is read-only") : failure();
343+
if (emitError)
344+
emitError() << "memory space is read-only";
345+
return false;
344346
}
345347

346-
LogicalResult TestConstMemorySpaceAttr::isValidAtomicOp(
348+
bool TestConstMemorySpaceAttr::isValidAtomicOp(
347349
mlir::ptr::AtomicBinOp binOp, Type type, mlir::ptr::AtomicOrdering ordering,
348350
IntegerAttr alignment, function_ref<InFlightDiagnostic()> emitError) const {
349-
return emitError ? (emitError() << "memory space is read-only") : failure();
351+
if (emitError)
352+
emitError() << "memory space is read-only";
353+
return false;
350354
}
351355

352-
LogicalResult TestConstMemorySpaceAttr::isValidAtomicXchg(
356+
bool TestConstMemorySpaceAttr::isValidAtomicXchg(
353357
Type type, mlir::ptr::AtomicOrdering successOrdering,
354358
mlir::ptr::AtomicOrdering failureOrdering, IntegerAttr alignment,
355359
function_ref<InFlightDiagnostic()> emitError) const {
356-
return emitError ? (emitError() << "memory space is read-only") : failure();
360+
if (emitError)
361+
emitError() << "memory space is read-only";
362+
return false;
357363
}
358364

359-
LogicalResult TestConstMemorySpaceAttr::isValidAddrSpaceCast(
365+
bool TestConstMemorySpaceAttr::isValidAddrSpaceCast(
360366
Type tgt, Type src, function_ref<InFlightDiagnostic()> emitError) const {
361-
return emitError
362-
? (emitError() << "memory space doesn't allow addrspace casts")
363-
: failure();
367+
if (emitError)
368+
emitError() << "memory space doesn't allow addrspace casts";
369+
return false;
364370
}
365371

366-
LogicalResult TestConstMemorySpaceAttr::isValidPtrIntCast(
372+
bool TestConstMemorySpaceAttr::isValidPtrIntCast(
367373
Type intLikeTy, Type ptrLikeTy,
368374
function_ref<InFlightDiagnostic()> emitError) const {
369-
return emitError ? (emitError() << "memory space doesn't allow int-ptr casts")
370-
: failure();
375+
if (emitError)
376+
emitError() << "memory space doesn't allow int-ptr casts";
377+
return false;
371378
}
372379

373380
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)