-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[mlir] Implement a memory-space cast bubbling-down transform #159454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a15b8ca
[mlir] Implement memory-space cast operand fusion into consumers
fabianmcg 3709f67
address comments 1/2
fabianmcg 4789d11
address comements 2/2
fabianmcg 7a881b6
Update mlir/include/mlir/Interfaces/MemOpInterfaces.td
fabianmcg 7f4a7f9
fix benefit
fabianmcg 150b791
Update mlir/include/mlir/Interfaces/MemOpInterfaces.td
fabianmcg 231ae13
fix build
fabianmcg 1321454
rename isLosslesscast method
fabianmcg d753be0
use std::optional in bubbleDownCasts
fabianmcg e70b0f2
improve docs
fabianmcg 2e5ff23
address reviewer comments
fabianmcg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//===- MemOpInterfaces.h - Memory operation interfaces ----------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file contains declarations of interfaces for operations that interact | ||
// with memory. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef MLIR_INTERFACES_MEMOPINTERFACES_H | ||
#define MLIR_INTERFACES_MEMOPINTERFACES_H | ||
|
||
#include "mlir/IR/OpDefinition.h" | ||
|
||
namespace mlir { | ||
namespace detail { | ||
/// Attempt to verify the given memory space cast operation. | ||
LogicalResult verifyMemorySpaceCastOpInterface(Operation *op); | ||
|
||
/// Tries to bubble-down inplace a `MemorySpaceCastOpInterface` operation | ||
/// referenced by `operand`. On success, it returns `std::nullopt`. It | ||
/// returns failure if `operand` doesn't reference a | ||
/// `MemorySpaceCastOpInterface` op. | ||
FailureOr<std::optional<SmallVector<Value>>> | ||
bubbleDownInPlaceMemorySpaceCastImpl(OpOperand &operand, ValueRange results); | ||
} // namespace detail | ||
} // namespace mlir | ||
|
||
/// Include the generated interface declarations. | ||
#include "mlir/Interfaces/MemOpInterfaces.h.inc" | ||
|
||
#endif // MLIR_INTERFACES_MEMOPINTERFACES_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
//===- MemOpInterfaces.td - Memory operation interfaces -----*- tablegen -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file contains interfaces for operations that interact with memory. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef MLIR_INTERFACES_MEMOPINTERFACES_TD | ||
#define MLIR_INTERFACES_MEMOPINTERFACES_TD | ||
|
||
include "mlir/IR/OpBase.td" | ||
include "mlir/Interfaces/SideEffectInterfaces.td" | ||
|
||
def MemorySpaceCastConsumerOpInterface : | ||
OpInterface<"MemorySpaceCastConsumerOpInterface"> { | ||
let description = [{ | ||
An interface for operations that can consume memory-space cast-like | ||
operations. | ||
}]; | ||
let cppNamespace = "::mlir"; | ||
let methods = [ | ||
InterfaceMethod<[{ | ||
Attempt to bubble-down the incoming cast-like operands. On success | ||
returns a `std::optional<SmallVector<Value>>`, otherwise it returns | ||
failure. If the optional is `std::nullopt` then the cast was performed | ||
in place, otherwise the method returns a list of replacement values. | ||
If new results are produced, these must be compatible with the original | ||
operation results. | ||
|
||
If the operation was not modified in place, then the interface | ||
guarantees it is valid to erase the original operation. | ||
If the operation was modified in place, then the interface must | ||
guarantee no operations were created by the method, and that no further | ||
IR modification is necessary. | ||
|
||
Any implementations of this method must not erase/replace the original | ||
operation, instead it is the caller responsibility to erase or replace | ||
the op with the results provided by the method. | ||
|
||
Finally, any implementations of this method have to guarantee that the | ||
IR remains valid at all times. | ||
}], | ||
"::llvm::FailureOr<std::optional<::llvm::SmallVector<::mlir::Value>>>", | ||
"bubbleDownCasts", | ||
(ins "::mlir::OpBuilder &":$builder) | ||
>, | ||
]; | ||
} | ||
|
||
def MemorySpaceCastOpInterface : OpInterface<"MemorySpaceCastOpInterface"> { | ||
let description = [{ | ||
An interface for operations that perform memory-space casts. This | ||
interface assumes that the cast operation is `pure`. | ||
|
||
These operations expect to have a well-defined ptr-like operand, and | ||
a well-defined target ptr-like result. | ||
}]; | ||
let cppNamespace = "::mlir"; | ||
let methods = [ | ||
InterfaceMethod<[{ | ||
Returns the source ptr-like value. | ||
}], | ||
"::mlir::TypedValue<::mlir::PtrLikeTypeInterface>", "getSourcePtr" | ||
>, | ||
InterfaceMethod<[{ | ||
Returns the target ptr-like value. | ||
}], | ||
"::mlir::TypedValue<::mlir::PtrLikeTypeInterface>", "getTargetPtr" | ||
>, | ||
InterfaceMethod<[{ | ||
Returns whether the memory space cast specified by `tgt` and `src` | ||
is supported. | ||
}], | ||
"bool", "isValidMemorySpaceCast", | ||
(ins "::mlir::PtrLikeTypeInterface":$tgt, | ||
"::mlir::PtrLikeTypeInterface":$src) | ||
>, | ||
InterfaceMethod<[{ | ||
Clones the memory space cast op with the given source and target type. | ||
}], | ||
"::mlir::MemorySpaceCastOpInterface", "cloneMemorySpaceCastOp", | ||
(ins "::mlir::OpBuilder &":$builder, "::mlir::PtrLikeTypeInterface":$tgt, | ||
"::mlir::TypedValue<::mlir::PtrLikeTypeInterface>":$src) | ||
>, | ||
InterfaceMethod<[{ | ||
Returns whether the source pointer of the memory-space cast can be used | ||
by the `MemorySpaceCastConsumerOpInterface::bubbleDownCasts` method to | ||
promote the source pointer and bubble down the cast. | ||
}], | ||
"bool", "isSourcePromotable" | ||
> | ||
]; | ||
let verify = [{ | ||
return ::mlir::detail::verifyMemorySpaceCastOpInterface($_op); | ||
}]; | ||
let dependentTraits = [Pure]; | ||
let extraClassDeclaration = [{ | ||
/// Returns the underlying `MemorySpaceCastOpInterface` op if `value` | ||
/// is produced by a `MemorySpaceCastOpInterface` op, and | ||
/// `isSourcePromotable` returns true, otherwise it returns null. | ||
static ::mlir::MemorySpaceCastOpInterface | ||
getIfPromotableCast(::mlir::Value value) { | ||
auto op = ::llvm::dyn_cast_or_null<::mlir::MemorySpaceCastOpInterface>( | ||
value.getDefiningOp()); | ||
if (!op || !op.isSourcePromotable()) | ||
return nullptr; | ||
return op; | ||
} | ||
}]; | ||
} | ||
|
||
#endif // MLIR_INTERFACES_MEMOPINTERFACES_TD |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.