clang 22.0.0git
|
Record with information about how a bitfield should be accessed. More...
Public Member Functions | |
CIRGenBitFieldInfo () | |
CIRGenBitFieldInfo (unsigned offset, unsigned size, bool isSigned, unsigned storageSize, clang::CharUnits storageOffset) | |
void | print (llvm::raw_ostream &os) const |
LLVM_DUMP_METHOD void | dump () const |
Public Attributes | |
unsigned | offset: 16 |
The offset within a contiguous run of bitfields that are represented as a single "field" within the cir.record type. | |
unsigned | size: 15 |
The total size of the bit-field, in bits. | |
unsigned | isSigned: 1 |
Whether the bit-field is signed. | |
unsigned | storageSize |
The storage size in bits which should be used when accessing this bitfield. | |
clang::CharUnits | storageOffset |
The offset of the bitfield storage from the start of the record. | |
unsigned | volatileOffset: 16 |
The offset within a contiguous run of bitfields that are represented as a single "field" within the cir.record type, taking into account the AAPCS rules for volatile bitfields. | |
unsigned | volatileStorageSize |
The storage size in bits which should be used when accessing this bitfield. | |
clang::CharUnits | volatileStorageOffset |
The offset of the bitfield storage from the start of the record. | |
llvm::StringRef | name |
The name of a bitfield. | |
mlir::Type | storageType |
Record with information about how a bitfield should be accessed.
This is very similar to what LLVM codegen does, once CIR evolves it's possible we can use a more higher level representation.
Often we lay out a sequence of bitfields as a contiguous sequence of bits. When the AST record layout does this, we represent it in CIR as a !cir.record type, which directly reflects the structure's layout, including bitfield packing and padding, using CIR types such as !cir.bool, !s8i, !u16i.
To access a particular bitfield in CIR, we use the operations cir.get_bitfield (GetBitfieldOp) or cir.set_bitfield (SetBitfieldOp). These operations rely on the bitfield_info attribute, which provides detailed metadata required for access, such as the size and offset of the bitfield, the type and size of the underlying storage, and whether the value is signed. The CIRGenRecordLayout also has a bitFields map which encodes which byte-sequence this bitfield falls within. Let's assume the following C struct:
struct S { char a, b, c; unsigned bits : 3; unsigned more_bits : 4; unsigned still_more_bits : 7; };
This will end up as the following cir.record. The bitfield members are represented by one !u16i value, and the array provides padding to align the struct to a 4-byte alignment.
!rec_S = !cir.record<struct "S" padded {!s8i, !s8i, !s8i, !u16i, !cir.array<!u8i x 3>}>
When generating code to access more_bits, we'll generate something essentially like this:
#bfi_more_bits = #cir.bitfield_info<name = "more_bits", storage_type = !u16i, size = 4, offset = 3, is_signed = false>
cir.func @store_field() { %0 = cir.alloca !rec_S, !cir.ptr<!rec_S>, ["s"] {alignment = 4 : i64} %1 = cir.const #cir.int<2> : !s32i %2 = cir.cast(integral, %1 : !s32i), !u32i %3 = cir.get_member %0[3] {name = "more_bits"} : !cir.ptr<!rec_S> -> !cir.ptr<!u16i> %4 = cir.set_bitfield(#bfi_more_bits, %3 : !cir.ptr<!u16i>, %2 : !u32i) -> !u32i cir.return }
Definition at line 68 of file CIRGenRecordLayout.h.
|
inline |
Definition at line 104 of file CIRGenRecordLayout.h.
References isSigned, offset, size, storageSize, volatileOffset, and volatileStorageSize.
|
inline |
Definition at line 108 of file CIRGenRecordLayout.h.
References isSigned, offset, size, storageOffset, and storageSize.
void CIRGenBitFieldInfo::dump | ( | ) | const |
Definition at line 761 of file CIRGenRecordLayoutBuilder.cpp.
References print().
void CIRGenBitFieldInfo::print | ( | llvm::raw_ostream & | os | ) | const |
Definition at line 749 of file CIRGenRecordLayoutBuilder.cpp.
References isSigned, name, offset, size, storageOffset, storageSize, volatileOffset, volatileStorageOffset, and volatileStorageSize.
Referenced by clang::CIRGen::CIRGenRecordLayout::print().
unsigned clang::CIRGen::CIRGenBitFieldInfo::isSigned |
Whether the bit-field is signed.
Definition at line 77 of file CIRGenRecordLayout.h.
Referenced by CIRGenBitFieldInfo(), CIRGenBitFieldInfo(), clang::CIRGen::CIRGenBuilderTy::createGetBitfield(), clang::CIRGen::CIRGenBuilderTy::createSetBitfield(), and print().
llvm::StringRef clang::CIRGen::CIRGenBitFieldInfo::name |
The name of a bitfield.
Definition at line 99 of file CIRGenRecordLayout.h.
Referenced by clang::CIRGen::CIRGenBuilderTy::createGetBitfield(), clang::CIRGen::CIRGenBuilderTy::createSetBitfield(), and print().
unsigned clang::CIRGen::CIRGenBitFieldInfo::offset |
The offset within a contiguous run of bitfields that are represented as a single "field" within the cir.record type.
This offset is in bits.
Definition at line 71 of file CIRGenRecordLayout.h.
Referenced by CIRGenBitFieldInfo(), CIRGenBitFieldInfo(), clang::CIRGen::CIRGenBuilderTy::createGetBitfield(), clang::CIRGen::CIRGenBuilderTy::createSetBitfield(), and print().
unsigned clang::CIRGen::CIRGenBitFieldInfo::size |
The total size of the bit-field, in bits.
Definition at line 74 of file CIRGenRecordLayout.h.
Referenced by CIRGenBitFieldInfo(), CIRGenBitFieldInfo(), clang::CIRGen::CIRGenBuilderTy::createGetBitfield(), clang::CIRGen::CIRGenBuilderTy::createSetBitfield(), and print().
clang::CharUnits clang::CIRGen::CIRGenBitFieldInfo::storageOffset |
The offset of the bitfield storage from the start of the record.
Definition at line 84 of file CIRGenRecordLayout.h.
Referenced by CIRGenBitFieldInfo(), and print().
unsigned clang::CIRGen::CIRGenBitFieldInfo::storageSize |
The storage size in bits which should be used when accessing this bitfield.
Definition at line 81 of file CIRGenRecordLayout.h.
Referenced by CIRGenBitFieldInfo(), CIRGenBitFieldInfo(), and print().
mlir::Type clang::CIRGen::CIRGenBitFieldInfo::storageType |
Definition at line 102 of file CIRGenRecordLayout.h.
Referenced by clang::CIRGen::CIRGenFunction::emitLValueForBitField().
unsigned clang::CIRGen::CIRGenBitFieldInfo::volatileOffset |
The offset within a contiguous run of bitfields that are represented as a single "field" within the cir.record type, taking into account the AAPCS rules for volatile bitfields.
This offset is in bits.
Definition at line 89 of file CIRGenRecordLayout.h.
Referenced by CIRGenBitFieldInfo(), clang::CIRGen::CIRGenBuilderTy::createGetBitfield(), clang::CIRGen::CIRGenBuilderTy::createSetBitfield(), clang::CIRGen::CIRGenFunction::emitLoadOfBitfieldLValue(), and print().
clang::CharUnits clang::CIRGen::CIRGenBitFieldInfo::volatileStorageOffset |
The offset of the bitfield storage from the start of the record.
Definition at line 96 of file CIRGenRecordLayout.h.
Referenced by print().
unsigned clang::CIRGen::CIRGenBitFieldInfo::volatileStorageSize |
The storage size in bits which should be used when accessing this bitfield.
Definition at line 93 of file CIRGenRecordLayout.h.
Referenced by CIRGenBitFieldInfo(), clang::CIRGen::CIRGenBuilderTy::createGetBitfield(), clang::CIRGen::CIRGenBuilderTy::createSetBitfield(), clang::CIRGen::CIRGenFunction::emitStoreThroughBitfieldLValue(), and print().