This is an archive of the discontinued LLVM Phabricator instance.

[opt-viewer] Python 3 support in opt-viewer.py
ClosedPublic

Authored by modocache on Jun 26 2017, 3:00 PM.

Details

Summary

Minor changes that allow opt-stats.py to support both Python 2 and 3.
In addition to the same dictionary iterator changes that were necessary
in https://reviews.llvm.org/D34564, this diff also:

  • Explcitly converts strings to bytes when reading from and writing to stdin and stdout.
  • No longer uses dictionaries as a sort key for optimization remarks. Dictionary sort order in Python 2 is pretty esoteric anyway, so it's not clear that the additional sorting had a benefit for end users (for details, https://stackoverflow.com/a/3484456/679254 is a good resource on Python 2 dictionary sort order).

Event Timeline

modocache created this revision.Jun 26 2017, 3:00 PM
anemet added inline comments.Jun 29 2017, 6:12 AM
utils/opt-viewer/opt-viewer.py
193–195

The idea for sticking r.dict at the end was to have a deterministic index page. This allows diffing the before and after html directories to make sure a change is in fact NFC.

Is dict no longer available in Python3?

modocache planned changes to this revision.Jun 29 2017, 9:19 AM
modocache added inline comments.
utils/opt-viewer/opt-viewer.py
193–195

dict is still available in Python 3, but it doesn't have a built-in sort order (that is, it no longer implements __cmp__). For details, see: https://stackoverflow.com/a/22334235/679254.

In any case, sorry about that, I'll take another look. Maybe instead of comparing the dict representation of the remark, I could compare more of its comparable attributes?

fhahn removed a subscriber: fhahn.Jun 29 2017, 9:40 AM

Keying on the pass name and demangled function when necessary prevents any non-determinism in the index ordering.

anemet accepted this revision.Jun 29 2017, 11:34 AM

LGTM, one suggestion below.

utils/opt-viewer/opt-viewer.py
193–195

Can we use r.Function to avoid calling the demangler?

This revision is now accepted and ready to land.Jun 29 2017, 11:34 AM

Yes, good catch. Use function name instead of demangled function name.

modocache closed this revision.Jun 29 2017, 11:47 AM