clang 20.0.0git
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
clang::CodeGen::ConstantAggregateBuilderBase Class Reference

A concrete base class for struct and array aggregate initializer builders. More...

#include "clang/CodeGen/ConstantInitBuilder.h"

Classes

class  PlaceholderPosition
 An opaque class to hold the abstract position of a placeholder. More...
 

Public Member Functions

 ConstantAggregateBuilderBase (const ConstantAggregateBuilderBase &)=delete
 
ConstantAggregateBuilderBaseoperator= (const ConstantAggregateBuilderBase &)=delete
 
 ConstantAggregateBuilderBase (ConstantAggregateBuilderBase &&other)
 
ConstantAggregateBuilderBaseoperator= (ConstantAggregateBuilderBase &&other)=delete
 
size_t size () const
 Return the number of elements that have been added to this struct or array.
 
bool empty () const
 Return true if no elements have yet been added to this struct or array.
 
void abandon ()
 Abandon this builder completely.
 
void add (llvm::Constant *value)
 Add a new value to this initializer.
 
void addSize (CharUnits size)
 Add an integer value of type size_t.
 
void addInt (llvm::IntegerType *intTy, uint64_t value, bool isSigned=false)
 Add an integer value of a specific type.
 
void addSignedPointer (llvm::Constant *Pointer, const PointerAuthSchema &Schema, GlobalDecl CalleeDecl, QualType CalleeType)
 Add a signed pointer using the given pointer authentication schema.
 
void addNullPointer (llvm::PointerType *ptrTy)
 Add a null pointer of a specific type.
 
void addAll (llvm::ArrayRef< llvm::Constant * > values)
 Add a bunch of new values to this initializer.
 
void addRelativeOffset (llvm::IntegerType *type, llvm::Constant *target)
 Add a relative offset to the given target address, i.e.
 
void addRelativeOffsetToPosition (llvm::IntegerType *type, llvm::Constant *target, size_t position)
 Same as addRelativeOffset(), but instead relative to an element in this aggregate, identified by its index.
 
void addTaggedRelativeOffset (llvm::IntegerType *type, llvm::Constant *address, unsigned tag)
 Add a relative offset to the target address, plus a small constant offset.
 
CharUnits getNextOffsetFromGlobal () const
 Return the offset from the start of the initializer to the next position, assuming no padding is required prior to it.
 
PlaceholderPosition addPlaceholder ()
 Add a placeholder value to the structure.
 
PlaceholderPosition addPlaceholderWithSize (llvm::Type *expectedType)
 Add a placeholder, giving the expected type that will be filled in.
 
void fillPlaceholderWithInt (PlaceholderPosition position, llvm::IntegerType *type, uint64_t value, bool isSigned=false)
 Fill a previously-added placeholder.
 
void fillPlaceholder (PlaceholderPosition position, llvm::Constant *value)
 Fill a previously-added placeholder.
 
llvm::Constant * getAddrOfCurrentPosition (llvm::Type *type)
 Produce an address which will eventually point to the next position to be filled.
 
llvm::Constant * getAddrOfPosition (llvm::Type *type, size_t position)
 Produce an address which points to a position in the aggregate being constructed.
 
llvm::ArrayRef< llvm::Constant * > getGEPIndicesToCurrentPosition (llvm::SmallVectorImpl< llvm::Constant * > &indices)
 

Protected Member Functions

llvm::SmallVectorImpl< llvm::Constant * > & getBuffer ()
 
const llvm::SmallVectorImpl< llvm::Constant * > & getBuffer () const
 
 ConstantAggregateBuilderBase (ConstantInitBuilderBase &builder, ConstantAggregateBuilderBase *parent)
 
 ~ConstantAggregateBuilderBase ()
 
void markFinished ()
 
llvm::Constant * finishArray (llvm::Type *eltTy)
 
llvm::Constant * finishStruct (llvm::StructType *structTy)
 

Protected Attributes

ConstantInitBuilderBaseBuilder
 
ConstantAggregateBuilderBaseParent
 
size_t Begin
 
size_t CachedOffsetEnd = 0
 
bool Finished = false
 
bool Frozen = false
 
bool Packed = false
 
CharUnits CachedOffsetFromGlobal
 

Detailed Description

A concrete base class for struct and array aggregate initializer builders.

Definition at line 100 of file ConstantInitBuilder.h.

Constructor & Destructor Documentation

◆ ConstantAggregateBuilderBase() [1/3]

clang::CodeGen::ConstantAggregateBuilderBase::ConstantAggregateBuilderBase ( ConstantInitBuilderBase builder,
ConstantAggregateBuilderBase parent 
)
inlineprotected

Definition at line 119 of file ConstantInitBuilder.h.

References Frozen.

◆ ~ConstantAggregateBuilderBase()

clang::CodeGen::ConstantAggregateBuilderBase::~ConstantAggregateBuilderBase ( )
inlineprotected

Definition at line 131 of file ConstantInitBuilder.h.

References Finished.

◆ ConstantAggregateBuilderBase() [2/3]

clang::CodeGen::ConstantAggregateBuilderBase::ConstantAggregateBuilderBase ( const ConstantAggregateBuilderBase )
delete

◆ ConstantAggregateBuilderBase() [3/3]

clang::CodeGen::ConstantAggregateBuilderBase::ConstantAggregateBuilderBase ( ConstantAggregateBuilderBase &&  other)
inline

Definition at line 158 of file ConstantInitBuilder.h.

Member Function Documentation

◆ abandon()

void clang::CodeGen::ConstantAggregateBuilderBase::abandon ( )
inline

Abandon this builder completely.

Definition at line 183 of file ConstantInitBuilder.h.

References Begin, and markFinished().

◆ add()

void clang::CodeGen::ConstantAggregateBuilderBase::add ( llvm::Constant *  value)
inline

Add a new value to this initializer.

Definition at line 189 of file ConstantInitBuilder.h.

References Builder, Finished, and Frozen.

Referenced by addInt(), addNullPointer(), addRelativeOffset(), addRelativeOffsetToPosition(), addSignedPointer(), addSize(), and addTaggedRelativeOffset().

◆ addAll()

void clang::CodeGen::ConstantAggregateBuilderBase::addAll ( llvm::ArrayRef< llvm::Constant * >  values)
inline

Add a bunch of new values to this initializer.

Definition at line 216 of file ConstantInitBuilder.h.

References Builder, Finished, and Frozen.

◆ addInt()

void clang::CodeGen::ConstantAggregateBuilderBase::addInt ( llvm::IntegerType *  intTy,
uint64_t  value,
bool  isSigned = false 
)
inline

Add an integer value of a specific type.

Definition at line 200 of file ConstantInitBuilder.h.

References add().

◆ addNullPointer()

void clang::CodeGen::ConstantAggregateBuilderBase::addNullPointer ( llvm::PointerType *  ptrTy)
inline

Add a null pointer of a specific type.

Definition at line 211 of file ConstantInitBuilder.h.

References add().

◆ addPlaceholder()

PlaceholderPosition clang::CodeGen::ConstantAggregateBuilderBase::addPlaceholder ( )
inline

Add a placeholder value to the structure.

The returned position can be used to set the value later; it will not be invalidated by any intermediate operations except (1) filling the same position or (2) finishing the entire builder.

This is useful for emitting certain kinds of structure which contain some sort of summary field, generally a count, before any of the data. By emitting a placeholder first, the structure can be emitted eagerly.

Definition at line 281 of file ConstantInitBuilder.h.

References Builder, Finished, and Frozen.

Referenced by addPlaceholderWithSize().

◆ addPlaceholderWithSize()

ConstantAggregateBuilderBase::PlaceholderPosition ConstantAggregateBuilderBase::addPlaceholderWithSize ( llvm::Type *  expectedType)

◆ addRelativeOffset()

void clang::CodeGen::ConstantAggregateBuilderBase::addRelativeOffset ( llvm::IntegerType *  type,
llvm::Constant *  target 
)
inline

Add a relative offset to the given target address, i.e.

the static difference between the target address and the address of the relative offset. The target must be known to be defined in the current linkage unit. The offset will have the given integer type, which must be no wider than intptr_t. Some targets may not fully support this operation.

Definition at line 228 of file ConstantInitBuilder.h.

References add(), and clang::ast_matchers::type.

◆ addRelativeOffsetToPosition()

void clang::CodeGen::ConstantAggregateBuilderBase::addRelativeOffsetToPosition ( llvm::IntegerType *  type,
llvm::Constant *  target,
size_t  position 
)
inline

Same as addRelativeOffset(), but instead relative to an element in this aggregate, identified by its index.

Definition at line 234 of file ConstantInitBuilder.h.

References add(), and clang::ast_matchers::type.

◆ addSignedPointer()

void ConstantAggregateBuilderBase::addSignedPointer ( llvm::Constant *  Pointer,
const PointerAuthSchema Schema,
GlobalDecl  CalleeDecl,
QualType  CalleeType 
)

Add a signed pointer using the given pointer authentication schema.

Sign the given pointer and add it to the constant initializer currently being built.

Definition at line 302 of file ConstantInitBuilder.cpp.

References add(), Builder, getAddrOfCurrentPosition(), clang::CodeGen::CodeGenModule::getConstantSignedPointer(), clang::PointerAuthSchema::isAddressDiscriminated(), Pointer, and clang::CodeGen::CodeGenModule::shouldSignPointer().

◆ addSize()

void ConstantAggregateBuilderBase::addSize ( CharUnits  size)

Add an integer value of type size_t.

Definition at line 124 of file ConstantInitBuilder.cpp.

References add(), Builder, clang::CodeGen::CodeGenModule::getSize(), and size().

◆ addTaggedRelativeOffset()

void clang::CodeGen::ConstantAggregateBuilderBase::addTaggedRelativeOffset ( llvm::IntegerType *  type,
llvm::Constant *  address,
unsigned  tag 
)
inline

Add a relative offset to the target address, plus a small constant offset.

This is primarily useful when the relative offset is known to be a multiple of (say) four and therefore the tag can be used to express an extra two bits of information.

Definition at line 243 of file ConstantInitBuilder.h.

References add(), and clang::ast_matchers::type.

◆ empty()

bool clang::CodeGen::ConstantAggregateBuilderBase::empty ( ) const
inline

Return true if no elements have yet been added to this struct or array.

Definition at line 178 of file ConstantInitBuilder.h.

References size().

◆ fillPlaceholder()

void clang::CodeGen::ConstantAggregateBuilderBase::fillPlaceholder ( PlaceholderPosition  position,
llvm::Constant *  value 
)
inline

Fill a previously-added placeholder.

Definition at line 299 of file ConstantInitBuilder.h.

References Builder, Finished, and Frozen.

Referenced by fillPlaceholderWithInt().

◆ fillPlaceholderWithInt()

void clang::CodeGen::ConstantAggregateBuilderBase::fillPlaceholderWithInt ( PlaceholderPosition  position,
llvm::IntegerType *  type,
uint64_t  value,
bool  isSigned = false 
)
inline

Fill a previously-added placeholder.

Definition at line 292 of file ConstantInitBuilder.h.

References fillPlaceholder(), and clang::ast_matchers::type.

◆ finishArray()

llvm::Constant * ConstantAggregateBuilderBase::finishArray ( llvm::Type *  eltTy)
protected

Definition at line 263 of file ConstantInitBuilder.cpp.

References Begin, getBuffer(), markFinished(), and clang::ast_matchers::type.

◆ finishStruct()

llvm::Constant * ConstantAggregateBuilderBase::finishStruct ( llvm::StructType *  structTy)
protected

◆ getAddrOfCurrentPosition()

llvm::Constant * ConstantAggregateBuilderBase::getAddrOfCurrentPosition ( llvm::Type *  type)

Produce an address which will eventually point to the next position to be filled.

This is computed with an indexed getelementptr rather than by computing offsets.

The returned pointer will have type T*, where T is the given type. This type can differ from the type of the actual element.

Definition at line 168 of file ConstantInitBuilder.cpp.

References Builder, getGEPIndicesToCurrentPosition(), clang::CodeGen::CodeGenModule::getModule(), and clang::ast_matchers::type.

Referenced by addSignedPointer().

◆ getAddrOfPosition()

llvm::Constant * ConstantAggregateBuilderBase::getAddrOfPosition ( llvm::Type *  type,
size_t  position 
)

Produce an address which points to a position in the aggregate being constructed.

This is computed with an indexed getelementptr rather than by computing offsets.

The returned pointer will have type T*, where T is the given type. This type can differ from the type of the actual element.

Definition at line 154 of file ConstantInitBuilder.cpp.

References Begin, Builder, clang::CodeGen::CodeGenModule::getModule(), and clang::ast_matchers::type.

◆ getBuffer() [1/2]

llvm::SmallVectorImpl< llvm::Constant * > & clang::CodeGen::ConstantAggregateBuilderBase::getBuffer ( )
inlineprotected

Definition at line 111 of file ConstantInitBuilder.h.

References Builder.

Referenced by finishArray(), finishStruct(), and size().

◆ getBuffer() [2/2]

const llvm::SmallVectorImpl< llvm::Constant * > & clang::CodeGen::ConstantAggregateBuilderBase::getBuffer ( ) const
inlineprotected

Definition at line 115 of file ConstantInitBuilder.h.

References Builder.

◆ getGEPIndicesToCurrentPosition()

llvm::ArrayRef< llvm::Constant * > clang::CodeGen::ConstantAggregateBuilderBase::getGEPIndicesToCurrentPosition ( llvm::SmallVectorImpl< llvm::Constant * > &  indices)
inline

Definition at line 323 of file ConstantInitBuilder.h.

References Builder.

Referenced by getAddrOfCurrentPosition().

◆ getNextOffsetFromGlobal()

CharUnits clang::CodeGen::ConstantAggregateBuilderBase::getNextOffsetFromGlobal ( ) const
inline

Return the offset from the start of the initializer to the next position, assuming no padding is required prior to it.

This operation will not succeed if any unsized placeholders are currently in place in the initializer.

Definition at line 259 of file ConstantInitBuilder.h.

References Builder, Finished, and Frozen.

Referenced by addPlaceholderWithSize().

◆ markFinished()

void clang::CodeGen::ConstantAggregateBuilderBase::markFinished ( )
inlineprotected

Definition at line 135 of file ConstantInitBuilder.h.

References Builder, Finished, Frozen, and Parent.

Referenced by abandon(), finishArray(), and finishStruct().

◆ operator=() [1/2]

ConstantAggregateBuilderBase & clang::CodeGen::ConstantAggregateBuilderBase::operator= ( const ConstantAggregateBuilderBase )
delete

◆ operator=() [2/2]

ConstantAggregateBuilderBase & clang::CodeGen::ConstantAggregateBuilderBase::operator= ( ConstantAggregateBuilderBase &&  other)
delete

◆ size()

size_t clang::CodeGen::ConstantAggregateBuilderBase::size ( ) const
inline

Return the number of elements that have been added to this struct or array.

Definition at line 170 of file ConstantInitBuilder.h.

References Begin, getBuffer(), and size().

Referenced by addSize(), empty(), and size().

Member Data Documentation

◆ Begin

size_t clang::CodeGen::ConstantAggregateBuilderBase::Begin
protected

Definition at line 104 of file ConstantInitBuilder.h.

Referenced by abandon(), finishArray(), finishStruct(), getAddrOfPosition(), and size().

◆ Builder

ConstantInitBuilderBase& clang::CodeGen::ConstantAggregateBuilderBase::Builder
protected

◆ CachedOffsetEnd

size_t clang::CodeGen::ConstantAggregateBuilderBase::CachedOffsetEnd = 0
mutableprotected

Definition at line 105 of file ConstantInitBuilder.h.

Referenced by addPlaceholderWithSize().

◆ CachedOffsetFromGlobal

CharUnits clang::CodeGen::ConstantAggregateBuilderBase::CachedOffsetFromGlobal
mutableprotected

Definition at line 109 of file ConstantInitBuilder.h.

Referenced by addPlaceholderWithSize().

◆ Finished

bool clang::CodeGen::ConstantAggregateBuilderBase::Finished = false
protected

◆ Frozen

bool clang::CodeGen::ConstantAggregateBuilderBase::Frozen = false
protected

◆ Packed

bool clang::CodeGen::ConstantAggregateBuilderBase::Packed = false
protected

Definition at line 108 of file ConstantInitBuilder.h.

Referenced by addPlaceholderWithSize(), and finishStruct().

◆ Parent

ConstantAggregateBuilderBase* clang::CodeGen::ConstantAggregateBuilderBase::Parent
protected

Definition at line 103 of file ConstantInitBuilder.h.

Referenced by markFinished().


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