diff options
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/IPO/FunctionImport.cpp | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/IPO/FunctionImport.cpp b/llvm/lib/Transforms/IPO/FunctionImport.cpp index 233a36d2bc5..f3460c49422 100644 --- a/llvm/lib/Transforms/IPO/FunctionImport.cpp +++ b/llvm/lib/Transforms/IPO/FunctionImport.cpp @@ -125,6 +125,7 @@ static const GlobalValueSummary * selectCallee(const ModuleSummaryIndex &Index, ArrayRef<std::unique_ptr<GlobalValueSummary>> CalleeSummaryList, unsigned Threshold, StringRef CallerModulePath) { + // Find the first eligible callee (e.g. legality checks). auto It = llvm::find_if( CalleeSummaryList, [&](const std::unique_ptr<GlobalValueSummary> &SummaryPtr) { @@ -160,9 +161,6 @@ selectCallee(const ModuleSummaryIndex &Index, Summary->modulePath() != CallerModulePath) return false; - if (Summary->instCount() > Threshold) - return false; - if (Summary->notEligibleToImport()) return false; @@ -171,7 +169,19 @@ selectCallee(const ModuleSummaryIndex &Index, if (It == CalleeSummaryList.end()) return nullptr; - return cast<GlobalValueSummary>(It->get()); + // Now check if the first eligible callee is under the instruction + // threshold. Checking this on the first eligible callee ensures that + // we don't end up selecting different callees to import when we invoke + // this routine with different thresholds (when there are multiple copies, + // i.e. with weak or linkonce linkage). + auto *Summary = dyn_cast<FunctionSummary>(It->get()); + if (auto *AS = dyn_cast<AliasSummary>(It->get())) + Summary = cast<FunctionSummary>(&AS->getAliasee()); + assert(Summary && "Expected FunctionSummary, or alias to one"); + if (Summary->instCount() > Threshold) + return nullptr; + + return Summary; } using EdgeInfo = std::tuple<const FunctionSummary *, unsigned /* Threshold */, |

