summaryrefslogtreecommitdiffstats
path: root/llvm/lib/ProfileData/InstrProfWriter.cpp
diff options
context:
space:
mode:
authorNathan Slingerland <slingn@gmail.com>2015-12-15 17:37:09 +0000
committerNathan Slingerland <slingn@gmail.com>2015-12-15 17:37:09 +0000
commit7f5b47ddd46fb5bfc4cff67cb09bbf2d889d45cc (patch)
tree26e5733d95c97634fc29e41af391bc8e67d968b9 /llvm/lib/ProfileData/InstrProfWriter.cpp
parent78fd4f087b0832bdfef1c7db54bc234002e2ff30 (diff)
downloadbcm5719-llvm-7f5b47ddd46fb5bfc4cff67cb09bbf2d889d45cc.tar.gz
bcm5719-llvm-7f5b47ddd46fb5bfc4cff67cb09bbf2d889d45cc.zip
[llvm-profdata] Add support for weighted merge of profile data (2nd try)
Summary: This change adds support for specifying a weight when merging profile data with the llvm-profdata tool. Weights are specified by using the --weighted-input=<weight>,<filename> option. Input files not specified with this option (normal positional list after options) are given a default weight of 1. Adding support for arbitrary weighting of input profile data allows for relative importance to be placed on the input data from multiple training runs. Both sampled and instrumented profiles are supported. Reviewers: davidxl, dnovillo, bogner, silvas Subscribers: silvas, davidxl, llvm-commits Differential Revision: http://reviews.llvm.org/D15306 llvm-svn: 255659
Diffstat (limited to 'llvm/lib/ProfileData/InstrProfWriter.cpp')
-rw-r--r--llvm/lib/ProfileData/InstrProfWriter.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/llvm/lib/ProfileData/InstrProfWriter.cpp b/llvm/lib/ProfileData/InstrProfWriter.cpp
index 026912006b7..478cf80db7a 100644
--- a/llvm/lib/ProfileData/InstrProfWriter.cpp
+++ b/llvm/lib/ProfileData/InstrProfWriter.cpp
@@ -98,7 +98,8 @@ void InstrProfWriter::updateStringTableReferences(InstrProfRecord &I) {
I.updateStrings(&StringTable);
}
-std::error_code InstrProfWriter::addRecord(InstrProfRecord &&I) {
+std::error_code InstrProfWriter::addRecord(InstrProfRecord &&I,
+ uint64_t Weight) {
updateStringTableReferences(I);
auto &ProfileDataMap = FunctionData[I.Name];
@@ -113,9 +114,18 @@ std::error_code InstrProfWriter::addRecord(InstrProfRecord &&I) {
// We've never seen a function with this name and hash, add it.
Dest = std::move(I);
Result = instrprof_error::success;
+ if (Weight > 1) {
+ for (auto &Count : Dest.Counts) {
+ bool Overflowed;
+ Count = SaturatingMultiply(Count, Weight, &Overflowed);
+ if (Overflowed && Result == instrprof_error::success) {
+ Result = instrprof_error::counter_overflow;
+ }
+ }
+ }
} else {
// We're updating a function we've seen before.
- Result = Dest.merge(I);
+ Result = Dest.merge(I, Weight);
}
// We keep track of the max function count as we go for simplicity.
OpenPOWER on IntegriCloud