[Mlir-commits] [mlir] [mlir][inliner] optimize self-recursive function detection (PR #88452)
Mehdi Amini
llvmlistbot at llvm.org
Sat May 11 20:12:41 PDT 2024
================
@@ -705,24 +715,30 @@ Inliner::Impl::inlineCallsInSCC(InlinerInterfaceImpl &inlinerIface,
return success(inlinedAnyCalls);
}
+static bool isSelfRecursiveFunction(CallGraphNode *node) {
+ return llvm::find_if(*node, [&](const CallGraphNode::Edge &edge) -> bool {
+ return edge.getTarget() == node;
+ }) != node->end();
+}
+
/// Returns true if the given call should be inlined.
-bool Inliner::Impl::shouldInline(ResolvedCall &resolvedCall) {
+bool Inliner::Impl::shouldInline(
+ ResolvedCall &resolvedCall,
+ const llvm::SmallPtrSetImpl<Region *> &recursiveCallRegions) {
// Don't allow inlining terminator calls. We currently don't support this
// case.
if (resolvedCall.call->hasTrait<OpTrait::IsTerminator>())
return false;
- // Don't allow inlining if the target is a self-recursive function.
- if (llvm::count_if(*resolvedCall.targetNode,
- [&](CallGraphNode::Edge const &edge) -> bool {
- return edge.getTarget() == resolvedCall.targetNode;
- }) > 0)
- return false;
-
- // Don't allow inlining if the target is an ancestor of the call. This
- // prevents inlining recursively.
Region *callableRegion = resolvedCall.targetNode->getCallableRegion();
- if (callableRegion->isAncestor(resolvedCall.call->getParentRegion()))
+
+ // Don't allow inlining this following cases to prevent inlining recursively.
+ // 1. target has at least an edge back to itself in original call graph.
+ // 2. target has call instructions call itself after pervious inlining.
----------------
joker-eph wrote:
```suggestion
// 2. target has call instructions call itself after previous inlining.
```
https://github.com/llvm/llvm-project/pull/88452
More information about the Mlir-commits
mailing list