Skip to content

Commit e70b0f2

Browse files
committed
improve docs
1 parent d753be0 commit e70b0f2

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1288,7 +1288,7 @@ def LoadOp : MemRef_Op<"load",
12881288
def MemRef_MemorySpaceCastOp : MemRef_Op<"memory_space_cast", [
12891289
DeclareOpInterfaceMethods<CastOpInterface>,
12901290
DeclareOpInterfaceMethods<OpAsmOpInterface, ["getAsmResultNames"]>,
1291-
DeclareOpInterfaceMethods<MemorySpaceCastOpInterface>,
1291+
MemorySpaceCastOpInterface,
12921292
MemRefsNormalizable,
12931293
Pure,
12941294
SameOperandsAndResultElementType,
@@ -1326,6 +1326,27 @@ def MemRef_MemorySpaceCastOp : MemRef_Op<"memory_space_cast", [
13261326

13271327
let extraClassDeclaration = [{
13281328
Value getViewSource() { return getSource(); }
1329+
1330+
//===------------------------------------------------------------------===//
1331+
// MemorySpaceCastConsumerOpInterface
1332+
//===------------------------------------------------------------------===//
1333+
/// Returns the `source` memref.
1334+
TypedValue<PtrLikeTypeInterface> getSourcePtr();
1335+
/// Returns the `dest` memref.
1336+
TypedValue<PtrLikeTypeInterface> getTargetPtr();
1337+
/// Returns whether the memory-space cast is valid. Only casts between
1338+
/// memrefs are considered valid. Further, the `tgt` and `src` should only
1339+
/// differ on the memory-space parameter of the memref type.
1340+
bool isValidMemorySpaceCast(PtrLikeTypeInterface tgt,
1341+
PtrLikeTypeInterface src);
1342+
/// Clones the operation using a new target type and source value.
1343+
MemorySpaceCastOpInterface cloneMemorySpaceCastOp(
1344+
OpBuilder &b, PtrLikeTypeInterface tgt,
1345+
TypedValue<PtrLikeTypeInterface> src);
1346+
/// Returns whether the `source` value can be promoted by the
1347+
/// `MemorySpaceCastConsumerOpInterface::bubbleDownCasts` method. The only
1348+
/// casts the op recognizes as promotable are to the generic memory-space.
1349+
bool isSourcePromotable();
13291350
}];
13301351

13311352
let hasFolder = 1;

mlir/include/mlir/Interfaces/MemOpInterfaces.td

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@
1414
#define MLIR_INTERFACES_MEMOPINTERFACES_TD
1515

1616
include "mlir/IR/OpBase.td"
17-
include "mlir/Interfaces/SideEffectInterfaces.td"
1817

1918
def MemorySpaceCastConsumerOpInterface :
2019
OpInterface<"MemorySpaceCastConsumerOpInterface"> {
2120
let description = [{
2221
An interface for operations that can consume memory-space cast-like
2322
operations.
23+
24+
This interface can be used to bubble-down memory-space cast operations,
25+
see the `bubble-down-memory-space-casts` pass for an example.
2426
}];
2527
let cppNamespace = "::mlir";
2628
let methods = [
@@ -59,6 +61,10 @@ def MemorySpaceCastOpInterface : OpInterface<"MemorySpaceCastOpInterface"> {
5961

6062
These operations expect to have a well-defined ptr-like operand, and
6163
a well-defined target ptr-like result.
64+
65+
This interface also allows to determine whether a cast can be bubbled-down
66+
by the `MemorySpaceCastConsumerOpInterface`, allowing control over which
67+
casts can be bubbled-down or not.
6268
}];
6369
let cppNamespace = "::mlir";
6470
let methods = [
@@ -91,14 +97,16 @@ def MemorySpaceCastOpInterface : OpInterface<"MemorySpaceCastOpInterface"> {
9197
Returns whether the source pointer of the memory-space cast can be used
9298
by the `MemorySpaceCastConsumerOpInterface::bubbleDownCasts` method to
9399
promote the source pointer and bubble down the cast.
100+
101+
For example, a cast operation might decide that all casts to the generic
102+
memory-space can be promoted.
94103
}],
95104
"bool", "isSourcePromotable"
96105
>
97106
];
98107
let verify = [{
99108
return ::mlir::detail::verifyMemorySpaceCastOpInterface($_op);
100109
}];
101-
let dependentTraits = [Pure];
102110
let extraClassDeclaration = [{
103111
/// Returns the underlying `MemorySpaceCastOpInterface` op if `value`
104112
/// is produced by a `MemorySpaceCastOpInterface` op, and

mlir/include/mlir/Transforms/Passes.td

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -590,8 +590,12 @@ def BubbleDownMemorySpaceCasts :
590590
let summary = "Bubbles down memory-space cast operations.";
591591
let description = [{
592592
This pass tries to iteratively bubble down all possible memory-space cast
593-
operations. It does this by looking for `MemorySpaceCastConsumerOpInterface`
594-
operations, and invoking the interface methods to perform the bubbling down.
593+
operations. It is important to note that the determination of which casts
594+
are bubbled down is based on the interfaces
595+
`MemorySpaceCastConsumerOpInterface`, and `MemorySpaceCastOpInterface`, and
596+
not the pass. The pass only looks for operations implementing the
597+
`MemorySpaceCastConsumerOpInterface` interface, and invoking the interface
598+
methods to perform the bubbling down.
595599

596600
Example:
597601

0 commit comments

Comments
 (0)