File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change 2121#include " mlir/Support/DebugStringHelper.h"
2222#include " mlir/Transforms/InliningUtils.h"
2323#include " llvm/ADT/SCCIterator.h"
24+ #include " llvm/ADT/STLExtras.h"
2425#include " llvm/ADT/SmallPtrSet.h"
2526#include " llvm/Support/Debug.h"
2627
@@ -711,6 +712,13 @@ bool Inliner::Impl::shouldInline(ResolvedCall &resolvedCall) {
711712 if (resolvedCall.call ->hasTrait <OpTrait::IsTerminator>())
712713 return false ;
713714
715+ // Don't allow inlining if the target is a self-recursive function.
716+ if (llvm::count_if (*resolvedCall.targetNode ,
717+ [&](CallGraphNode::Edge const &edge) -> bool {
718+ return edge.getTarget () == resolvedCall.targetNode ;
719+ }) > 0 )
720+ return false ;
721+
714722 // Don't allow inlining if the target is an ancestor of the call. This
715723 // prevents inlining recursively.
716724 Region *callableRegion = resolvedCall.targetNode ->getCallableRegion ();
Original file line number Diff line number Diff line change 1+ // RUN: mlir-opt %s -inline='default-pipeline=''' | FileCheck %s
2+ // RUN: mlir-opt %s --mlir-disable-threading -inline='default-pipeline=''' | FileCheck %s
3+
4+ // CHECK-LABEL: func.func @b0
5+ func.func @b0 () {
6+ // CHECK: call @b0
7+ // CHECK-NEXT: call @b1
8+ // CHECK-NEXT: call @b0
9+ // CHECK-NEXT: call @b1
10+ // CHECK-NEXT: call @b0
11+ func.call @b0 () : () -> ()
12+ func.call @b1 () : () -> ()
13+ func.call @b0 () : () -> ()
14+ func.call @b1 () : () -> ()
15+ func.call @b0 () : () -> ()
16+ return
17+ }
18+ func.func @b1 () {
19+ func.call @b1 () : () -> ()
20+ func.call @b1 () : () -> ()
21+ return
22+ }
You can’t perform that action at this time.
0 commit comments