This is an archive of the discontinued LLVM Phabricator instance.

[PGO] Handle and report overflow during profile merge for all types of data
ClosedPublic

Authored by slingn on Dec 15 2015, 4:22 PM.

Details

Summary

Surface counter overflow when merging profile data. Merging still occurs on overflow but counts saturate to the maximum representable value. Overflow is reported to the user.

Diff Detail

Repository
rL LLVM

Event Timeline

slingn updated this revision to Diff 42937.Dec 15 2015, 4:22 PM
slingn retitled this revision from to [PGO] Handle and report overflow during profile merge for all types of data.
slingn updated this object.
slingn added reviewers: davidxl, dnovillo, silvas.
slingn added a subscriber: llvm-commits.
davidxl added inline comments.Dec 15 2015, 4:35 PM
include/llvm/ProfileData/SampleProf.h
299 ↗(On Diff #42937)

May be introducing a macro for the repeated patterns:

#define SET_RESULT(R, FinalR) \

if (R != ....) \
   FinalR = R;
slingn updated this revision to Diff 43029.Dec 16 2015, 10:31 AM
slingn marked an inline comment as done.

Updated for davidxl, dnovillo feedback.

include/llvm/ProfileData/SampleProf.h
299 ↗(On Diff #42937)

Went with inline function implementation as discussed on llvm-commits.

davidxl added inline comments.Dec 16 2015, 10:40 AM
include/llvm/ProfileData/InstrProf.h
187 ↗(On Diff #43029)

Nit: how about UpdateResult -- it seems a better name.

include/llvm/ProfileData/SampleProf.h
145 ↗(On Diff #43029)

There are also lots of if(..) return patterns that can be simplified. This case you will need a macro:

#define RETURN_IF(Cond, Err) \

if(Cond) \
    return Err;
slingn added inline comments.Dec 16 2015, 10:45 AM
include/llvm/ProfileData/InstrProf.h
187 ↗(On Diff #43029)

How about 'MergeResult'?

include/llvm/ProfileData/SampleProf.h
145 ↗(On Diff #43029)

I don't think we want to add macros to header files like this as macros don't respect namespaces. I'll see if I can simplify in another way.

davidxl added inline comments.Dec 16 2015, 10:49 AM
include/llvm/ProfileData/InstrProf.h
187 ↗(On Diff #43029)

Sounds fine.

include/llvm/ProfileData/SampleProf.h
145 ↗(On Diff #43029)

you can undef it somewhere. Note that 'assert' before the change is a macro too :)

slingn added inline comments.Dec 16 2015, 11:17 AM
include/llvm/ProfileData/SampleProf.h
145 ↗(On Diff #43029)

Yes, macros are unavoidable. But I'd still prefer to avoid them. :)

In any case, I think this will be cleaned up quite a bit by D15385 - adding a fused multiply-add saturation function. I'll update that review to depend on this one.

slingn updated this revision to Diff 43043.Dec 16 2015, 11:29 AM

Updated for davidxl feedback.

This revision was automatically updated to reflect the committed changes.
llvm/trunk/test/tools/llvm-profdata/overflow-sample.test