@@ -15,21 +15,36 @@ struct InlineCandidate {
1515 pFunc callee;
1616};
1717
18- bool isProfitableToInline (const Function& caller, const InlineCandidate &candidate) {
19- auto & callee = *candidate.callee ;
20- auto & call_points = candidate.call_points ;
18+ bool isProfitableToInline (const Function & caller, const InlineCandidate &candidate) {
19+ auto & callee = *candidate.callee ;
20+ auto & call_points = candidate.call_points ;
2121
2222 // Do not inline function that can be memoized
2323 if (isProfitableToMemoize (callee))
2424 return false ;
2525
2626 // Expand recursive call once can have better performance
27- if (callee.isRecursive () && &caller != &callee)
28- return false ;
27+ if (callee.isRecursive ()) {
28+ if (&caller != &callee)
29+ return false ;
30+
31+ if (callee.getInstCount () * call_points.size () > Config::IR ::FUNCTION_INLINE_RECURSIVE_EXPAND_THRESHOLD ) {
32+ Logger::logDebug (" [Inline]: Canceled expanding recursive function '" , callee.getName (),
33+ " ', due to too many instructions.(" , call_points.size (), " calls, with each " ,
34+ callee.getInstCount (), " instructions)" );
35+ return false ;
36+ }
37+
38+ return true ;
39+ }
40+
41+ if (call_points.size () == 1 )
42+ return true ;
2943
3044 if (callee.getInstCount () * call_points.size () > Config::IR ::FUNCTION_INLINE_INST_THRESHOLD ) {
3145 Logger::logDebug (" [Inline]: Canceled inlining '" , callee.getName (), " ' into '" , caller.getName (),
32- " ', due to too many instructions" );
46+ " ', due to too many instructions. (" , call_points.size (), " calls, with each " ,
47+ callee.getInstCount (), " instructions)" );
3348 return false ;
3449 }
3550 return true ;
@@ -43,6 +58,8 @@ void doInline(Function &caller, const pCall &call) {
4358
4459 if (candidate->isRecursive ())
4560 Logger::logDebug (" [Inline]: Expanding recursive function '" , candidate->getName (), " '." );
61+ else
62+ Logger::logDebug (" [Inline]: Inlining function '" , candidate->getName (), " ' into '" , caller.getName (), " '." );
4663
4764 auto cloned = makeClone (candidate);
4865
@@ -150,7 +167,7 @@ PM::PreservedAnalyses InlinePass::run(Function &function, FAM &fam) {
150167 if (auto call = inst->as <CALLInst>()) {
151168 auto callee_def = call->getFunc ()->as <Function>();
152169 if (callee_def != nullptr ) {
153- auto & candidate = candidates[callee_def];
170+ auto & candidate = candidates[callee_def];
154171 candidate.call_points .emplace_back (call);
155172 candidate.callee = callee_def;
156173 }
0 commit comments