diff options
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. |

