-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[MLIR] Make resolveCallable
customizable in CallOpInterface
#100361
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
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write If you have received no comments on your PR for a week, you can request a review If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-mlir @llvm/pr-subscribers-mlir-bufferization Author: Henrich Lauko (xlauko) ChangesAllow customization of the
Full diff: https://github.com/llvm/llvm-project/pull/100361.diff 8 Files Affected:
diff --git a/mlir/include/mlir/Interfaces/CallInterfaces.h b/mlir/include/mlir/Interfaces/CallInterfaces.h
index 7dbcddb01b241..15a3d260f4166 100644
--- a/mlir/include/mlir/Interfaces/CallInterfaces.h
+++ b/mlir/include/mlir/Interfaces/CallInterfaces.h
@@ -25,9 +25,6 @@ struct CallInterfaceCallable : public PointerUnion<SymbolRefAttr, Value> {
};
} // namespace mlir
-/// Include the generated interface declarations.
-#include "mlir/Interfaces/CallInterfaces.h.inc"
-
namespace llvm {
// Allow llvm::cast style functions.
@@ -41,4 +38,7 @@ struct CastInfo<To, const mlir::CallInterfaceCallable>
} // namespace llvm
+/// Include the generated interface declarations.
+#include "mlir/Interfaces/CallInterfaces.h.inc"
+
#endif // MLIR_INTERFACES_CALLINTERFACES_H
diff --git a/mlir/include/mlir/Interfaces/CallInterfaces.td b/mlir/include/mlir/Interfaces/CallInterfaces.td
index 752de74e6e4d7..1da2a6d4e7eac 100644
--- a/mlir/include/mlir/Interfaces/CallInterfaces.td
+++ b/mlir/include/mlir/Interfaces/CallInterfaces.td
@@ -59,17 +59,41 @@ def CallOpInterface : OpInterface<"CallOpInterface"> {
Returns the operands within this call that are used as arguments to the
callee as a mutable range.
}],
- "::mlir::MutableOperandRange", "getArgOperandsMutable">,
- ];
+ "::mlir::MutableOperandRange", "getArgOperandsMutable"
+ >,
+ InterfaceMethod<[{
+ Resolve the callable operation for given callee to a
+ CallableOpInterface, or nullptr if a valid callable was not resolved.
+ `symbolTable` parameter allow for using a cached symbol table for symbol
+ lookups instead of performing an O(N) scan.
+ }],
+ "::mlir::Operation *", "resolveCallableInTable", (ins "::mlir::SymbolTableCollection &":$symbolTable),
+ /*methodBody=*/[{}], /*defaultImplementation=*/[{
+ ::mlir::CallInterfaceCallable callable = $_op.getCallableForCallee();
+ if (auto symbolVal = dyn_cast<::mlir::Value>(callable))
+ return symbolVal.getDefiningOp();
- let extraClassDeclaration = [{
- /// Resolve the callable operation for given callee to a
- /// CallableOpInterface, or nullptr if a valid callable was not resolved.
- /// `symbolTable` is an optional parameter that will allow for using a
- /// cached symbol table for symbol lookups instead of performing an O(N)
- /// scan.
- ::mlir::Operation *resolveCallable(::mlir::SymbolTableCollection *symbolTable = nullptr);
- }];
+ // If the callable isn't a value, lookup the symbol reference.
+ auto symbolRef = callable.get<::mlir::SymbolRefAttr>();
+ return symbolTable.lookupNearestSymbolFrom($_op, symbolRef);
+ }]
+ >,
+ InterfaceMethod<[{
+ Resolve the callable operation for given callee to a
+ CallableOpInterface, or nullptr if a valid callable was not resolved.
+ }],
+ "::mlir::Operation *", "resolveCallable", (ins),
+ /*methodBody=*/[{}], /*defaultImplementation=*/[{
+ ::mlir::CallInterfaceCallable callable = $_op.getCallableForCallee();
+ if (auto symbolVal = dyn_cast<::mlir::Value>(callable))
+ return symbolVal.getDefiningOp();
+
+ // If the callable isn't a value, lookup the symbol reference.
+ auto symbolRef = callable.get<::mlir::SymbolRefAttr>();
+ return SymbolTable::lookupNearestSymbolFrom($_op, symbolRef);
+ }]
+ >
+ ];
}
/// Interface for callable operations.
diff --git a/mlir/lib/Analysis/CallGraph.cpp b/mlir/lib/Analysis/CallGraph.cpp
index ccd4676632136..6a85fb1a0da27 100644
--- a/mlir/lib/Analysis/CallGraph.cpp
+++ b/mlir/lib/Analysis/CallGraph.cpp
@@ -146,7 +146,7 @@ CallGraphNode *CallGraph::lookupNode(Region *region) const {
CallGraphNode *
CallGraph::resolveCallable(CallOpInterface call,
SymbolTableCollection &symbolTable) const {
- Operation *callable = call.resolveCallable(&symbolTable);
+ Operation *callable = call.resolveCallableInTable(symbolTable);
if (auto callableOp = dyn_cast_or_null<CallableOpInterface>(callable))
if (auto *node = lookupNode(callableOp.getCallableRegion()))
return node;
diff --git a/mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp b/mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp
index fab2bd83888da..cb80d229ae678 100644
--- a/mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp
+++ b/mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp
@@ -295,7 +295,7 @@ LogicalResult DeadCodeAnalysis::visit(ProgramPoint point) {
}
void DeadCodeAnalysis::visitCallOperation(CallOpInterface call) {
- Operation *callableOp = call.resolveCallable(&symbolTable);
+ Operation *callableOp = call.resolveCallableInTable(symbolTable);
// A call to a externally-defined callable has unknown predecessors.
const auto isExternalCallable = [this](Operation *op) {
diff --git a/mlir/lib/Analysis/DataFlow/DenseAnalysis.cpp b/mlir/lib/Analysis/DataFlow/DenseAnalysis.cpp
index 9894810f0e04b..21f99c1b2b6cd 100644
--- a/mlir/lib/Analysis/DataFlow/DenseAnalysis.cpp
+++ b/mlir/lib/Analysis/DataFlow/DenseAnalysis.cpp
@@ -281,7 +281,7 @@ void AbstractDenseBackwardDataFlowAnalysis::visitCallOperation(
CallOpInterface call, const AbstractDenseLattice &after,
AbstractDenseLattice *before) {
// Find the callee.
- Operation *callee = call.resolveCallable(&symbolTable);
+ Operation *callee = call.resolveCallableInTable(symbolTable);
auto callable = dyn_cast_or_null<CallableOpInterface>(callee);
// No region means the callee is only declared in this module.
diff --git a/mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp b/mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp
index ad956b73e4b1d..a64c3b50ed6e7 100644
--- a/mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp
+++ b/mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp
@@ -438,7 +438,7 @@ void AbstractSparseBackwardDataFlowAnalysis::visitOperation(Operation *op) {
// For function calls, connect the arguments of the entry blocks to the
// operands of the call op that are forwarded to these arguments.
if (auto call = dyn_cast<CallOpInterface>(op)) {
- Operation *callableOp = call.resolveCallable(&symbolTable);
+ Operation *callableOp = call.resolveCallableInTable(symbolTable);
if (auto callable = dyn_cast_or_null<CallableOpInterface>(callableOp)) {
// Not all operands of a call op forward to arguments. Such operands are
// stored in `unaccounted`.
diff --git a/mlir/lib/Dialect/Bufferization/Transforms/OwnershipBasedBufferDeallocation.cpp b/mlir/lib/Dialect/Bufferization/Transforms/OwnershipBasedBufferDeallocation.cpp
index ca5d0688b5b59..949b08682443f 100644
--- a/mlir/lib/Dialect/Bufferization/Transforms/OwnershipBasedBufferDeallocation.cpp
+++ b/mlir/lib/Dialect/Bufferization/Transforms/OwnershipBasedBufferDeallocation.cpp
@@ -824,7 +824,8 @@ FailureOr<Operation *> BufferDeallocation::handleInterface(CallOpInterface op) {
// the function is referenced by SSA value instead of a Symbol, it's assumed
// to be public. (And we cannot easily change the type of the SSA value
// anyway.)
- Operation *funcOp = op.resolveCallable(state.getSymbolTable());
+ SymbolTableCollection *symbolTable = state.getSymbolTable();
+ Operation *funcOp = op.resolveCallableInTable(*symbolTable);
bool isPrivate = false;
if (auto symbol = dyn_cast_or_null<SymbolOpInterface>(funcOp))
isPrivate = symbol.isPrivate() && !symbol.isDeclaration();
diff --git a/mlir/lib/Interfaces/CallInterfaces.cpp b/mlir/lib/Interfaces/CallInterfaces.cpp
index 455684d8e2ea7..527c19713addf 100644
--- a/mlir/lib/Interfaces/CallInterfaces.cpp
+++ b/mlir/lib/Interfaces/CallInterfaces.cpp
@@ -14,23 +14,6 @@ using namespace mlir;
// CallOpInterface
//===----------------------------------------------------------------------===//
-/// Resolve the callable operation for given callee to a CallableOpInterface, or
-/// nullptr if a valid callable was not resolved. `symbolTable` is an optional
-/// parameter that will allow for using a cached symbol table for symbol lookups
-/// instead of performing an O(N) scan.
-Operation *
-CallOpInterface::resolveCallable(SymbolTableCollection *symbolTable) {
- CallInterfaceCallable callable = getCallableForCallee();
- if (auto symbolVal = dyn_cast<Value>(callable))
- return symbolVal.getDefiningOp();
-
- // If the callable isn't a value, lookup the symbol reference.
- auto symbolRef = callable.get<SymbolRefAttr>();
- if (symbolTable)
- return symbolTable->lookupNearestSymbolFrom(getOperation(), symbolRef);
- return SymbolTable::lookupNearestSymbolFrom(getOperation(), symbolRef);
-}
-
//===----------------------------------------------------------------------===//
// CallInterfaces
//===----------------------------------------------------------------------===//
|
ping @matthias-springer |
e86afb4
to
39c5553
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense to me, but I'm not a usual reviewer of core MLIR stuff, so perhaps some extra stamp might be needed?
Allow customization of the `resolveCallable` method in the `CallOpInterface`. This change allows for operations implementing this interface to provide their own logic for resolving callables. - Introduce the `resolveCallable` method, which does not include the optional symbol table parameter. This method replaces the previously existing extra class declaration `resolveCallable`. - Introduce the `resolveCallableInTable` method, which incorporates the symbol table parameter. This method replaces the previous extra class declaration `resolveCallable` that used the optional symbol table parameter.
@xlauko Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/89/builds/5973 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/80/builds/3318 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/130/builds/3275 Here is the relevant piece of the build log for the reference
|
Looks like a few dependencies ( |
Hopefully fixed in #107989 |
llvm#100361) Allow customization of the `resolveCallable` method in the `CallOpInterface`. This change allows for operations implementing this interface to provide their own logic for resolving callables. - Introduce the `resolveCallable` method, which does not include the optional symbol table parameter. This method replaces the previously existing extra class declaration `resolveCallable`. - Introduce the `resolveCallableInTable` method, which incorporates the symbol table parameter. This method replaces the previous extra class declaration `resolveCallable` that used the optional symbol table parameter.
llvm#100361) Allow customization of the `resolveCallable` method in the `CallOpInterface`. This change allows for operations implementing this interface to provide their own logic for resolving callables. - Introduce the `resolveCallable` method, which does not include the optional symbol table parameter. This method replaces the previously existing extra class declaration `resolveCallable`. - Introduce the `resolveCallableInTable` method, which incorporates the symbol table parameter. This method replaces the previous extra class declaration `resolveCallable` that used the optional symbol table parameter.
Bumps llvm to commit: iree-org/llvm-project@e268afb in branch https://github.com/iree-org/llvm-project/tree/shared/integrates_20240910 Following changes are made: 1. Fix formatv call to pass validation added by llvm/llvm-project#105745 2. API changes in DICompositeTypeAttr::get introduced by llvm/llvm-project#106571 3. Fix API call from llvm/llvm-project#100361 4. Fix chipset comparison in ROCMTarget.cpp There are two cherry-picks from upstream main as they contain fixes we need and one cheery-pick that is yet to land 1. iree-org/llvm-project@0d5d355 2. iree-org/llvm-project@650d852 3. iree-org/llvm-project@e268afb (the upstream PR for this one is llvm/llvm-project#108302 And a revert due to an outstanding torch-mlir issue iree-org/llvm-project@cf22797
Bumps llvm to commit: iree-org/llvm-project@e268afb in branch https://github.com/iree-org/llvm-project/tree/shared/integrates_20240910 Following changes are made: 1. Fix formatv call to pass validation added by llvm/llvm-project#105745 2. API changes in DICompositeTypeAttr::get introduced by llvm/llvm-project#106571 3. Fix API call from llvm/llvm-project#100361 4. Fix chipset comparison in ROCMTarget.cpp There are two cherry-picks from upstream main as they contain fixes we need and one cheery-pick that is yet to land 1. iree-org/llvm-project@0d5d355 2. iree-org/llvm-project@650d852 3. iree-org/llvm-project@e268afb (the upstream PR for this one is llvm/llvm-project#108302 And a revert due to an outstanding torch-mlir issue iree-org/llvm-project@cf22797
Allow customization of the
resolveCallable
method in theCallOpInterface
. This change allows for operations implementing this interface to provide their own logic for resolving callables.Introduce the
resolveCallable
method, which does not include the optional symbol table parameter. This method replaces the previously existing extra class declarationresolveCallable
.Introduce the
resolveCallableInTable
method, which incorporates the symbol table parameter. This method replaces the previous extra class declarationresolveCallable
that used the optional symbol table parameter.