diff options
| author | Teresa Johnson <tejohnson@google.com> | 2017-07-15 04:53:05 +0000 |
|---|---|---|
| committer | Teresa Johnson <tejohnson@google.com> | 2017-07-15 04:53:05 +0000 |
| commit | 82b4fb1afe8a99bba68bdee746a995787b543356 (patch) | |
| tree | f2cf40550d4f24ad392fc2eeed520237132db267 /llvm/lib/Transforms/IPO | |
| parent | 1c71d5143a267850c71aa89c7448d400d7c07c21 (diff) | |
| download | bcm5719-llvm-82b4fb1afe8a99bba68bdee746a995787b543356.tar.gz bcm5719-llvm-82b4fb1afe8a99bba68bdee746a995787b543356.zip | |
[ThinLTO] Ensure we always select the same function copy to import
Summary:
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 due to reaching the callee via paths that
are shallower or hotter (when there are multiple copies, i.e. with
weak or linkonce linkage). We don't want to leave the decision of which
copy to import up to the backend.
Reviewers: mehdi_amini
Subscribers: inglorion, fhahn, llvm-commits
Differential Revision: https://reviews.llvm.org/D35436
llvm-svn: 308078
Diffstat (limited to 'llvm/lib/Transforms/IPO')
| -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 */, |

