[clang] [clang] Better bitfield access units (PR #65742)
John McCall via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 8 16:40:52 PST 2024
================
@@ -442,79 +455,235 @@ CGRecordLowering::accumulateBitFields(RecordDecl::field_iterator Field,
return;
}
- // Check if OffsetInRecord (the size in bits of the current run) is better
- // as a single field run. When OffsetInRecord has legal integer width, and
- // its bitfield offset is naturally aligned, it is better to make the
- // bitfield a separate storage component so as it can be accessed directly
- // with lower cost.
- auto IsBetterAsSingleFieldRun = [&](uint64_t OffsetInRecord,
- uint64_t StartBitOffset) {
- if (!Types.getCodeGenOpts().FineGrainedBitfieldAccesses)
- return false;
- if (OffsetInRecord < 8 || !llvm::isPowerOf2_64(OffsetInRecord) ||
- !DataLayout.fitsInLegalInteger(OffsetInRecord))
- return false;
- // Make sure StartBitOffset is naturally aligned if it is treated as an
- // IType integer.
- if (StartBitOffset %
- Context.toBits(getAlignment(getIntNType(OffsetInRecord))) !=
- 0)
- return false;
- return true;
+ // The SysV ABI can overlap bitfield storage units with both other bitfield
+ // storage units /and/ other non-bitfield data members. Such overlap, in the
+ // absence of packing, is always complete -- one storage unit is entirely
+ // within another. However, llvm cannot represent that -- it's structures are
+ // entirely flat. We place bitfields in 'access units', which are similar to
+ // the SysV storage units, but a clang-specific concept.
+
+ // It can be advantageous to concatenate two adjacent access units, if the
+ // concenation can be read or written in a single instruction.
+
+ // We do two passes.
+
+ // a) allocate bitfields into the smallest access units they can
+ // fit. This results in a set of integral-typed access units.
----------------
rjmccall wrote:
It's understood that the access units will be integer-typed. You should explain what you mean by "can fit", though. It looks like: bit-fields are merged whenever they start at a non-exact byte boundary.
https://github.com/llvm/llvm-project/pull/65742
More information about the cfe-commits
mailing list