[Mlir-commits] [mlir] [mlir][inliner] optimize self-recursive function detection (PR #88452)
Mehdi Amini
llvmlistbot at llvm.org
Sat May 11 20:12:21 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.
----------------
joker-eph wrote:
This seems overly conservative I would think, wouldn't it prevent to inline a case like:
```
void foo(int value) {
if (value > 20) foo(value-1);
}
void bar() {
foo(10);
}
```
Here foo is self-recursive, but inlining it into bar is still desirable.
https://github.com/llvm/llvm-project/pull/88452
More information about the Mlir-commits
mailing list