clang 19.0.0git
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
clang::CodeGen::CGBitFieldInfo Struct Reference

Structure with information about how a bitfield should be accessed. More...

#include "/home/buildbot/as-worker-4/publish-doxygen-docs/llvm-project/clang/lib/CodeGen/CGRecordLayout.h"

Public Member Functions

 CGBitFieldInfo ()
 
 CGBitFieldInfo (unsigned Offset, unsigned Size, bool IsSigned, unsigned StorageSize, CharUnits StorageOffset)
 
void print (raw_ostream &OS) const
 
void dump () const
 

Static Public Member Functions

static CGBitFieldInfo MakeInfo (class CodeGenTypes &Types, const FieldDecl *FD, uint64_t Offset, uint64_t Size, uint64_t StorageSize, CharUnits StorageOffset)
 Given a bit-field decl, build an appropriate helper object for accessing that field (which is expected to have the given offset and size).
 

Public Attributes

unsigned Offset: 16
 The offset within a contiguous run of bitfields that are represented as a single "field" within the LLVM struct 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.
 
CharUnits StorageOffset
 The offset of the bitfield storage from the start of the struct.
 
unsigned VolatileOffset: 16
 The offset within a contiguous run of bitfields that are represented as a single "field" within the LLVM struct 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.
 
CharUnits VolatileStorageOffset
 The offset of the bitfield storage from the start of the struct.
 

Detailed Description

Structure with information about how a bitfield should be accessed.

Often we layout a sequence of bitfields as a contiguous sequence of bits. When the AST record layout does this, we represent it in the LLVM IR's type as either a sequence of i8 members or a byte array to reserve the number of bytes touched without forcing any particular alignment beyond the basic character alignment.

Then accessing a particular bitfield involves converting this byte array into a single integer of that size (i24 or i40 – may not be power-of-two size), loading it, and shifting and masking to extract the particular subsequence of bits which make up that particular bitfield. This structure encodes the information used to construct the extraction code sequences. The CGRecordLayout also has a field index 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 LLVM type. The first array is the bitfield, and the second is the padding out to a 4-byte alignment.

t = type { i8, i8, i8, i8, i8, [3 x i8] }

When generating code to access more_bits, we'll generate something essentially like this:

define i32 @foo(t* base) { %0 = gep t* base, i32 0, i32 3 %2 = load i8* %1 %3 = lshr i8 %2, 3 %4 = and i8 %3, 15 %5 = zext i8 %4 to i32 ret i32 i }

Definition at line 65 of file CGRecordLayout.h.

Constructor & Destructor Documentation

◆ CGBitFieldInfo() [1/2]

clang::CodeGen::CGBitFieldInfo::CGBitFieldInfo ( )
inline

Definition at line 96 of file CGRecordLayout.h.

Referenced by MakeInfo().

◆ CGBitFieldInfo() [2/2]

clang::CodeGen::CGBitFieldInfo::CGBitFieldInfo ( unsigned  Offset,
unsigned  Size,
bool  IsSigned,
unsigned  StorageSize,
CharUnits  StorageOffset 
)
inline

Definition at line 100 of file CGRecordLayout.h.

Member Function Documentation

◆ dump()

LLVM_DUMP_METHOD void CGBitFieldInfo::dump ( ) const

Definition at line 1262 of file CGRecordLayoutBuilder.cpp.

References print().

◆ MakeInfo()

CGBitFieldInfo CGBitFieldInfo::MakeInfo ( class CodeGenTypes Types,
const FieldDecl FD,
uint64_t  Offset,
uint64_t  Size,
uint64_t  StorageSize,
CharUnits  StorageOffset 
)
static

Given a bit-field decl, build an appropriate helper object for accessing that field (which is expected to have the given offset and size).

Definition at line 1048 of file CGRecordLayoutBuilder.cpp.

References CGBitFieldInfo(), clang::CharUnits::fromQuantity(), clang::ValueDecl::getType(), IsSigned, clang::Type::isSignedIntegerOrEnumerationType(), Offset, Size, StorageOffset, and StorageSize.

Referenced by clang::CodeGen::CGObjCRuntime::EmitValueForIvarAtOffset().

◆ print()

void CGBitFieldInfo::print ( raw_ostream &  OS) const

Member Data Documentation

◆ IsSigned

unsigned clang::CodeGen::CGBitFieldInfo::IsSigned

Whether the bit-field is signed.

Definition at line 75 of file CGRecordLayout.h.

Referenced by MakeInfo(), and print().

◆ Offset

unsigned clang::CodeGen::CGBitFieldInfo::Offset

The offset within a contiguous run of bitfields that are represented as a single "field" within the LLVM struct type.

This offset is in bits.

Definition at line 68 of file CGRecordLayout.h.

Referenced by clang::CodeGen::CodeGenTypes::ComputeRecordLayout(), MakeInfo(), print(), and setUsedBits().

◆ Size

unsigned clang::CodeGen::CGBitFieldInfo::Size

The total size of the bit-field, in bits.

Definition at line 71 of file CGRecordLayout.h.

Referenced by clang::CodeGen::CodeGenTypes::ComputeRecordLayout(), MakeInfo(), print(), and setUsedBits().

◆ StorageOffset

CharUnits clang::CodeGen::CGBitFieldInfo::StorageOffset

The offset of the bitfield storage from the start of the struct.

Definition at line 82 of file CGRecordLayout.h.

Referenced by MakeInfo(), print(), and setUsedBits().

◆ StorageSize

unsigned clang::CodeGen::CGBitFieldInfo::StorageSize

The storage size in bits which should be used when accessing this bitfield.

Definition at line 79 of file CGRecordLayout.h.

Referenced by clang::CodeGen::CodeGenTypes::ComputeRecordLayout(), clang::CodeGen::CGObjCRuntime::EmitValueForIvarAtOffset(), MakeInfo(), print(), and setUsedBits().

◆ VolatileOffset

unsigned clang::CodeGen::CGBitFieldInfo::VolatileOffset

The offset within a contiguous run of bitfields that are represented as a single "field" within the LLVM struct type, taking into account the AAPCS rules for volatile bitfields.

This offset is in bits.

Definition at line 87 of file CGRecordLayout.h.

Referenced by print().

◆ VolatileStorageOffset

CharUnits clang::CodeGen::CGBitFieldInfo::VolatileStorageOffset

The offset of the bitfield storage from the start of the struct.

Definition at line 94 of file CGRecordLayout.h.

Referenced by print().

◆ VolatileStorageSize

unsigned clang::CodeGen::CGBitFieldInfo::VolatileStorageSize

The storage size in bits which should be used when accessing this bitfield.

Definition at line 91 of file CGRecordLayout.h.

Referenced by clang::CodeGen::CodeGenTypes::ComputeRecordLayout(), and print().


The documentation for this struct was generated from the following files: