This is an archive of the discontinued LLVM Phabricator instance.

[llvm-profdata] Add merge() to InstrProfRecord
ClosedPublic

Authored by slingn on Nov 18 2015, 1:52 PM.

Details

Summary

This change refactors two aspects of InstrProfRecord:

  1. Add a merge() method to InstrProfRecord (previously InstrProfWriter combineInstrProfRecords()) in order to better encapsulate this functionality and to make the InstrProfRecord and SampleRecord APIs more consistent.
  1. Make InstrProfRecord mergeValueProfData() a private method since it is only ever called internally by merge().

Diff Detail

Repository
rL LLVM

Event Timeline

slingn updated this revision to Diff 40556.Nov 18 2015, 1:52 PM
slingn retitled this revision from to [llvm-profdata] Add merge() to InstrProfRecord.
slingn updated this object.
slingn added reviewers: dnovillo, bogner, davidxl.
slingn added a subscriber: llvm-commits.
slingn updated this revision to Diff 40557.Nov 18 2015, 2:01 PM

Fix max function count calculation.

vsk added a subscriber: vsk.Nov 18 2015, 2:03 PM

Thanks, some inline comments --

include/llvm/ProfileData/InstrProf.h
323 ↗(On Diff #40556)

clang-format?

332 ↗(On Diff #40556)

Can you rangify this loop while we're at it?

417 ↗(On Diff #40556)

Rangify this one too.

lib/ProfileData/InstrProfWriter.cpp
107 ↗(On Diff #40557)

Is there a need to keep the iterator object around, since we have the value?

vsk added a comment.Nov 18 2015, 2:10 PM

I suppose it would be awkward to use ranged-for loops since it's indexing into two containers.

davidxl added inline comments.Nov 18 2015, 2:16 PM
lib/ProfileData/InstrProfWriter.cpp
104 ↗(On Diff #40557)

Better to do insert here and check if insertion actually happens or not.

slingn marked 3 inline comments as done.Nov 18 2015, 2:50 PM
slingn added inline comments.
include/llvm/ProfileData/InstrProf.h
332 ↗(On Diff #40557)

As vsk commented separately, a for-range loop would be awkward to use here (accessing two vectors in parallel by index).

417 ↗(On Diff #40557)

Same issue here with parallel vector access by index.

lib/ProfileData/InstrProfWriter.cpp
104 ↗(On Diff #40557)

Yes - much better. And also helps with addressing vsk's comment below.

slingn updated this revision to Diff 40568.Nov 18 2015, 3:03 PM
slingn marked an inline comment as done.

Address davidxl and vsk comments.

davidxl added inline comments.Nov 18 2015, 4:58 PM
lib/ProfileData/InstrProfWriter.cpp
104 ↗(On Diff #40568)

use std:make_pair(I.hash, InstrProfRecord()) to avoid side effect of making copies.

111 ↗(On Diff #40568)

else {

Dest = std::forward<InstrProfRecord>(I);

}

the std::forward is missing in the old code too which is less efficient.

davidxl added inline comments.Nov 18 2015, 8:43 PM
lib/ProfileData/InstrProfWriter.cpp
111 ↗(On Diff #40568)

Sorry, should be

Dest = std::move(I) or
Dest = static_cast<InstrProfRecord&&>(I)

silvas added a subscriber: silvas.Nov 18 2015, 9:30 PM
silvas added inline comments.
lib/ProfileData/InstrProfWriter.cpp
104 ↗(On Diff #40568)

small style nit: use std::tie to make this more readable.

slingn updated this revision to Diff 40684.Nov 19 2015, 11:30 AM
slingn marked 4 inline comments as done.

Updated for davidxl and ssilva comments.

davidxl accepted this revision.Nov 19 2015, 1:02 PM
davidxl edited edge metadata.

LGTM

This revision is now accepted and ready to land.Nov 19 2015, 1:02 PM
This revision was automatically updated to reflect the committed changes.