This is an archive of the discontinued LLVM Phabricator instance.

[ProfileData] Use SoftInstrProfErrors to count soft errors
ClosedPublic

Authored by vsk on May 9 2016, 2:06 PM.

Details

Summary

This helper class will make the transition to Error/Expected easier.

The immediate benefit is that it keeps track of the number of soft errors encountered, which can help during debugging. The future benefit is that SoftInstrProfErrors can be made undroppable by adding a simple destructor: this lets us handle soft errors properly with a significantly reduced malloc overhead.

Another benefit is that it lets us delete some error-tracking code in the main "merge" and "scale" logic.

Diff Detail

Repository
rL LLVM

Event Timeline

vsk updated this revision to Diff 56625.May 9 2016, 2:06 PM
vsk retitled this revision from to [ProfileData] Use SoftInstrProfErrors to count soft errors.
vsk updated this object.
vsk added a reviewer: davidxl.
vsk added subscribers: lhames, llvm-commits.
vsk updated this revision to Diff 56628.May 9 2016, 2:08 PM
  • Small simplification, nfc.
lhames added a comment.May 9 2016, 3:28 PM

I like this. As you said - it's good balance between performance and error safety.

davidxl added inline comments.May 10 2016, 11:37 AM
include/llvm/ProfileData/InstrProf.h
287 ↗(On Diff #56628)

Add some comments to the class.

lib/ProfileData/InstrProfWriter.cpp
169 ↗(On Diff #56628)

Do we really need to pass down the instance reference through all the interfaces? I suppose there should be one singleton instance of error, so some global error update APIs will do?

vsk added inline comments.May 10 2016, 11:48 AM
lib/ProfileData/InstrProfWriter.cpp
169 ↗(On Diff #56628)

Good point. Wdyt of:

  1. Adding a SoftInstrProfErrors member to InstrProfRecord, along with a getError() method (eventually takeError()).
  2. Passing a SoftInstrProfErrors& to the InstrProfValueSiteRecord constructor.

That should un-clutter the interfaces.

A global SoftInstrProfErrors instance could see contention, and I'd like to avoid that. It would also make it awkward to enforce soft error handling once we move to Error/Expected: who would be responsible for handling errors which come out of a given record?

davidxl added inline comments.May 10 2016, 11:50 AM
lib/ProfileData/InstrProfWriter.cpp
169 ↗(On Diff #56628)

sounds good -- the error is per-instrRecord anyway.

vsk added inline comments.May 10 2016, 5:58 PM
lib/ProfileData/InstrProfWriter.cpp
169 ↗(On Diff #56628)

I wasn't able to add a SoftInstrProfErrors member to InstrProfRecord.

Maintaining a reference to a SIPE instance in InstrProfValueSiteRecord seems to be brittle. If an InstrProfRecord is moved/copied, each entry in IndirectCallSites has to be updated. After adding move/copy constructors to handle this, I found other cases where &InstrProfRecord.SIPE != &IndirectCallSites[I].SIPE but didn't finish investigating the issue. Given that there's extra bookkeeping overhead with this approach (space for the references + time to correct the references per move/copy), I'd prefer keeping the initial version of this patch.

I considered adding a SoftInstrProfErrors _reference_ to InstrProfRecords, but this would cause a lot of churn in the unit tests. I'm open to other approaches.

davidxl added inline comments.May 10 2016, 7:49 PM
lib/ProfileData/InstrProfWriter.cpp
169 ↗(On Diff #56628)

I think it is reasonable to make the InstrProfValueSiteRecord's interfaces to take SPIE reference as new parameter. Make SPIE member of InstrProfRecord and make its interface unchanged.

Would that work?

vsk updated this revision to Diff 56928.May 11 2016, 9:16 AM
  • Add some comments to the soft error counter class.
  • Per David's suggestion: add an error counter to InstrProfRecord, and pass it by reference into the InstrProfValueSiteRecord methods.
davidxl accepted this revision.May 11 2016, 12:37 PM
davidxl edited edge metadata.

lgtm

This revision is now accepted and ready to land.May 11 2016, 12:37 PM
This revision was automatically updated to reflect the committed changes.