Page MenuHomePhabricator

Non-8-bit bytes showcase

Authored by JesperAntonsson on May 2 2019, 4:48 AM.



This patch set is meant to show the key addition of a BitsPerByte member of DataLayout and how this can be used in refactorings to remove magic numbers related to the assumption of 8-bit bytes.

Only a small number of such refactorings are shown, but should convey what they'd look like. An RFC will be sent to the llvm community with a suggestion for a way forward.

Diff Detail

Event Timeline

JesperAntonsson created this revision.May 2 2019, 4:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 2 2019, 4:48 AM
arsenm added a subscriber: arsenm.May 2 2019, 4:53 AM
arsenm added inline comments.

I believe this should be readonly


Should introduce a rounded size in bytes function somewhere

uabelho added a subscriber: uabelho.May 2 2019, 5:27 AM
riccibruno added inline comments.

That's an expensive division...

probinson added inline comments.

Maybe derive a pointer-type-size-in-bytes calculated in the ctor.
Or, as a more generic solution, derive shift/mask values from bits-per-byte, so the refactoring can replace multiply/divide with shifts. Or maybe with bitsToBytes and bytesToBits helper methods.

psnobl added a subscriber: psnobl.May 2 2019, 9:52 AM
Ka-Ka added a subscriber: Ka-Ka.May 7 2019, 12:26 AM

Added an inBytes() helper method. (We could contemplate putting this in DataLayout instead for more general use.) Adjusted READNONE to READONLY. Improved comments.

Will make a twin patch with a suggestion for "addressable units" terminology.

JesperAntonsson marked 2 inline comments as done.May 9 2019, 5:12 AM
JesperAntonsson added inline comments.

Yes, or we could perhaps make this a static constant in DataLayout and, for now, leave it to downstream target to make it a variable.

Daniel added a subscriber: Daniel.May 18 2019, 2:01 PM
Daniel added inline comments.May 18 2019, 2:20 PM

This looks fine as long as performance doesn't get worse after refactor. I don't see a performance hit here.

dmitry added a subscriber: dmitry.Oct 4 2019, 3:35 AM
dmitry added a comment.Oct 4 2019, 3:37 AM

Jesper Antonsson, do you plan to proceed working on this patch?

JesperAntonsson abandoned this revision.Oct 4 2019, 3:49 AM

I'll abandon this revision, as the suggestion didn't find community approval. I might do lesser things in this area, but if so, that'll be new patches.