This is an archive of the discontinued LLVM Phabricator instance.

[clang][NFC]: bitfield storage units
Needs ReviewPublic

Authored by urnathan on Aug 14 2023, 1:05 PM.

Details

Reviewers
asb
jyknight
Summary

I'm working on a problem with clang's bitfield storage[*] allocation -- it can create unaligned storage types in (say) char-aligned structures, and that is leading to unnecessary loads and stores.

But first, I found the current code confusing for a number of reasons:

  1. The call to IsBetterAsSingleFieldRun and setting of StartFieldAsSingleRun when handling the first field of a run is unnecessary. At the second field we would otherwise immediately call IsBetterAsSingleFieldRun with the same values. So just do that, and have no earlier call.
  1. There's an awful lot of negation going on:

2.1) We're trying to figure out whether to append to the current run, but call IsBetterAsSingleFieldRun. Let's just invert the semantics and rename it.

2.2) the handling of zero-width break points. Just apply DeMorgan's law a few time, and one's left with a single negation meaning 'not (a zero-width bitfield with either of these target properties)'

  1. The parameter names for tlhe lambda are confusing. OffsetInRecord is not the offset in the containing structure -- it's the offset of this bitfield from the start of the current allocation unit. StartBitOffset shadows an outer local name. (We happen to always pass that as the value, but then maybe capturing it would be a better approach?)

See D158886 for additional tests about access units.

  • The naming here is unfortunately confusing. the SysV ABI describes bitfield allocation in terms of 'storage units' -- those are different to these storage units, which might better be termed 'access units', as that's how llvm accesses the data. To be clear, this is not changing the ABI.

Diff Detail

Event Timeline

urnathan created this revision.Aug 14 2023, 1:05 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 14 2023, 1:05 PM
urnathan requested review of this revision.Aug 14 2023, 1:05 PM
urnathan edited the summary of this revision. (Show Details)Aug 25 2023, 1:42 PM
urnathan edited reviewers, added: jyknight; removed: rsmith.