diff options
| author | Dehao Chen <dehao@google.com> | 2016-04-26 04:59:11 +0000 |
|---|---|---|
| committer | Dehao Chen <dehao@google.com> | 2016-04-26 04:59:11 +0000 |
| commit | 5d6d4841eda8ec1eee5c170a920702e4a5d7bd71 (patch) | |
| tree | 01966914050c5b25eea140fb5ff786dd15d06c02 /llvm/lib | |
| parent | d6e92135bd5b419be68b16d8991953e2a8648785 (diff) | |
| download | bcm5719-llvm-5d6d4841eda8ec1eee5c170a920702e4a5d7bd71.tar.gz bcm5719-llvm-5d6d4841eda8ec1eee5c170a920702e4a5d7bd71.zip | |
Tune basic block annotation algorithm.
Summary:
Instead of using maximum IR weight as the basic block weight, this patch uses the voting algorithm to find the most likely weight for the basic block. This can effectively avoid the cases when some IRs are annotated incorrectly due to code motion of the profiled binary.
This patch also updates propagate.ll unittest to include discriminator in the input file so that it is testing something meaningful.
Reviewers: davidxl, dnovillo
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D19301
llvm-svn: 267519
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Transforms/IPO/SampleProfile.cpp | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/llvm/lib/Transforms/IPO/SampleProfile.cpp b/llvm/lib/Transforms/IPO/SampleProfile.cpp index fb9ea88c036..3017df6f970 100644 --- a/llvm/lib/Transforms/IPO/SampleProfile.cpp +++ b/llvm/lib/Transforms/IPO/SampleProfile.cpp @@ -502,19 +502,22 @@ SampleProfileLoader::getInstWeight(const Instruction &Inst) const { /// \returns the weight for \p BB. ErrorOr<uint64_t> SampleProfileLoader::getBlockWeight(const BasicBlock *BB) const { - bool Found = false; - uint64_t Weight = 0; + DenseMap<uint64_t, uint64_t> CM; for (auto &I : BB->getInstList()) { const ErrorOr<uint64_t> &R = getInstWeight(I); - if (R && R.get() >= Weight) { - Weight = R.get(); - Found = true; + if (R) CM[R.get()]++; + } + if (CM.size() == 0) return std::error_code(); + uint64_t W = 0, C = 0; + for (const auto &C_W : CM) { + if (C_W.second == W) { + C = std::max(C, C_W.first); + } else if (C_W.second > W) { + C = C_W.first; + W = C_W.second; } } - if (Found) - return Weight; - else - return std::error_code(); + return C; } /// \brief Compute and store the weights of every basic block. |

