From c38b636e6ee76cc55c0e99a12cc959a2b3cda789 Mon Sep 17 00:00:00 2001 From: Bob Wilson Date: Sun, 7 Oct 2012 01:11:19 +0000 Subject: Make sure always-inline functions get inlined. Without this change, when the estimated cost for inlining a function with an "alwaysinline" attribute was lower than the inlining threshold, the getInlineCost function was returning that estimated cost rather than the special InlineCost::AlwaysInlineCost value. That is fine in the normal inlining case, but it can fail when the inliner considers the opportunity cost of inlining into an internal or linkonce-odr function. It may decide not to inline the always-inline function in that case. The fix here is just to make getInlineCost always return the special value for always-inline functions. I ran into this building clang with libc++. Tablegen failed to link because of an always-inline function that was not inlined. I have been unable to reduce the testcase down to a reasonable size. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@165367 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/InlineCost.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/Analysis/InlineCost.cpp b/lib/Analysis/InlineCost.cpp index 7ecc06bbb2..aca91071ba 100644 --- a/lib/Analysis/InlineCost.cpp +++ b/lib/Analysis/InlineCost.cpp @@ -142,6 +142,7 @@ public: int getThreshold() { return Threshold; } int getCost() { return Cost; } + bool isAlwaysInline() { return AlwaysInline; } // Keep a bunch of stats about the cost savings found so we can print them // out when debugging. @@ -1057,7 +1058,8 @@ InlineCost InlineCostAnalyzer::getInlineCost(CallSite CS, Function *Callee, // Check if there was a reason to force inlining or no inlining. if (!ShouldInline && CA.getCost() < CA.getThreshold()) return InlineCost::getNever(); - if (ShouldInline && CA.getCost() >= CA.getThreshold()) + if (ShouldInline && (CA.isAlwaysInline() || + CA.getCost() >= CA.getThreshold())) return InlineCost::getAlways(); return llvm::InlineCost::get(CA.getCost(), CA.getThreshold()); -- cgit v1.2.3