35 if (llvm::StructType *Ty = CGM.getHLSLRuntime().getHLSLBufferLayoutType(RT))
40 RecordDecls.push_back(RT->castAsCXXRecordDecl());
41 while (RecordDecls.back()->getNumBases()) {
44 "HLSL doesn't support multiple inheritance");
49 unsigned OffsetIdx = 0;
51 for (
const auto *FD : RD->fields())
52 FieldsWithOffset.emplace_back(FD, OffsetInfo[OffsetIdx++]);
54 if (!OffsetInfo.
empty())
55 llvm::stable_sort(FieldsWithOffset, [](
const auto &LHS,
const auto &RHS) {
61 for (
auto &[FD, Offset] : FieldsWithOffset) {
62 llvm::Type *LayoutType =
layOutType(FD->getType());
66 const llvm::DataLayout &DL = CGM.getDataLayout();
71 if (LayoutType->isAggregateType() ||
79 assert(PackOffset >= NextOffset &&
80 "Offset is invalid - would overlap with previous object");
81 NextOffset = PackOffset;
84 if (NextOffset > CurrentOffset) {
85 llvm::Type *Padding = CGM.getTargetCodeGenInfo().getHLSLPadding(
86 CGM, NextOffset - CurrentOffset);
87 assert(Padding &&
"No padding type for target?");
88 Layout.emplace_back(Padding);
89 CurrentOffset = NextOffset;
91 Layout.emplace_back(LayoutType);
92 CurrentOffset += Size;
97 const auto *
Decl = RT->castAsCXXRecordDecl();
99 Decl->getName().empty() ?
"anon" :
Decl->getQualifiedNameAsString();
101 llvm::StructType *NewTy = llvm::StructType::create(Layout, Name,
103 CGM.getHLSLRuntime().addHLSLBufferLayoutType(RT, NewTy);
107llvm::Type *HLSLBufferLayoutBuilder::padArrayElements(llvm::Type *EltTy,
115 if (Count < 2 || Padding.
isZero())
116 return llvm::ArrayType::get(EltTy, Count);
119 llvm::Type *PaddingTy =
121 assert(PaddingTy &&
"No padding type for target?");
123 llvm::StructType::get(Context, {EltTy, PaddingTy},
true);
124 return llvm::StructType::get(
125 Context, {llvm::ArrayType::get(PaddedEltTy, Count - 1), EltTy},
132 return padArrayElements(EltTy, Count);
140 llvm::ArrayType *MemTy =
142 return padArrayElements(MemTy->getElementType(), MemTy->getNumElements());
150 if (
const auto *AT = CGM.getContext().getAsConstantArrayType(Ty))
161 return CGM.getTypes().ConvertTypeForMem(Ty);
constexpr CharUnits CBufferRowSize
C Language Family Type Representation.
QualType getElementType() const
QualType getType() const
Retrieves the type of the base class.
Represents a C++ struct/union/class.
unsigned getNumBases() const
Retrieves the number of base classes of this class.
base_class_iterator bases_begin()
This is an opaque type for sizes expressed in character units.
bool isZero() const
Test whether the quantity equals zero.
CharUnits alignTo(CharUnits Align) const
Returns the next integer (mod 2**64) that is greater than or equal to this quantity and is a multiple...
static constexpr CharUnits fromQuantity(QuantityType Quantity)
Construct a CharUnits quantity from a raw integer type.
static CharUnits Zero()
Construct a CharUnits quantity of zero.
static const uint32_t Unspecified
static bool compareOffsets(uint32_t LHS, uint32_t RHS)
Comparison function for offsets received from operator[] suitable for use in a stable_sort.
const llvm::DataLayout & getDataLayout() const
const TargetCodeGenInfo & getTargetCodeGenInfo()
llvm::LLVMContext & getLLVMContext()
llvm::StructType * layOutStruct(const RecordType *StructType, const CGHLSLOffsetInfo &OffsetInfo)
Lays out a struct type following HLSL buffer rules and considering any explicit offset information.
llvm::Type * layOutArray(const ConstantArrayType *AT)
Lays out an array type following HLSL buffer rules.
llvm::Type * layOutMatrix(QualType Ty)
Lays out a matrix type following HLSL buffer rules.
llvm::Type * layOutType(QualType Type)
Lays out a type following HLSL buffer rules.
virtual llvm::Type * getHLSLPadding(CodeGenModule &CGM, CharUnits NumBytes) const
Return an LLVM type that corresponds to padding in HLSL types.
Represents the canonical version of C arrays with a specified constant size.
uint64_t getZExtSize() const
Return the size zero-extended as a uint64_t.
A (possibly-)qualified type.
CXXRecordDecl * castAsCXXRecordDecl() const
bool isConstantMatrixType() const
bool isHLSLResourceRecord() const
bool isStructureOrClassType() const
const T * getAsCanonical() const
If this type is canonically the specified type, return its canonical type cast to that specified type...
bool isHLSLResourceRecordArray() const
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
Top level wrappers for InstallAPI frontend operations.
U cast(CodeGen::Address addr)