summaryrefslogtreecommitdiff
path: root/flang
diff options
context:
space:
mode:
authorWhitney Tsang <whitney.tsang@intel.com>2023-05-08 06:07:10 -0700
committerWhitney Tsang <whitney.tsang@intel.com>2023-05-08 06:07:10 -0700
commita2ab6a5e2b8d4e10ce29b24db7d6ae18c9acbec1 (patch)
tree7d6df7060808ad22aff07e369ff740a46875114e /flang
parent9fca0313f8c34ca9b4b5c434d4d013e86f47537a (diff)
downloadllvm-a2ab6a5e2b8d4e10ce29b24db7d6ae18c9acbec1.tar.gz
[mlir][CallOpInterface] Add `setCalleeFromCallable` method
Currently `CallOpInterface` has a method `getCallableForCallee` to have a consistent way to get the callee from an operation with `CallOpInterface`, but missing a consistent way to set a callee for an operation with `CallOpInterface`. A set callee method is useful for transformations that operate on `CallOpInterface`, and change the callee, e.g., a pass that specialize function, which clone the callee, and change the `CallOpInterface`'s callee to the cloned version. Without such method, transformation would need to understand the implementation for every operations with `CallOpInterface`, and have a type switch to handle them. This review adds a method to set callee for operation with `CallOpInterface`. Reviewed By: gysit, zero9178o Differential Revision: https://reviews.llvm.org/D149763
Diffstat (limited to 'flang')
-rw-r--r--flang/include/flang/Optimizer/Dialect/FIROps.td8
1 files changed, 8 insertions, 0 deletions
diff --git a/flang/include/flang/Optimizer/Dialect/FIROps.td b/flang/include/flang/Optimizer/Dialect/FIROps.td
index 2bc4ec0401d5..0e07e6fcaac9 100644
--- a/flang/include/flang/Optimizer/Dialect/FIROps.td
+++ b/flang/include/flang/Optimizer/Dialect/FIROps.td
@@ -2357,6 +2357,14 @@ def fir_CallOp : fir_Op<"call",
return calling;
return getOperand(0);
}
+
+ /// Set the callee for this operation.
+ void setCalleeFromCallable(mlir::CallInterfaceCallable callee) {
+ if (auto calling =
+ (*this)->getAttrOfType<mlir::SymbolRefAttr>(getCalleeAttrName()))
+ (*this)->setAttr(getCalleeAttrName(), callee.get<mlir::SymbolRefAttr>());
+ setOperand(0, callee.get<mlir::Value>());
+ }
}];
}