39 Size structMemberOffset = 0;
40 Size maxMemberAlignment = 1;
42 for (uint32_t i = 0, e = structType.
getNumElements(); i < e; ++i) {
44 Size memberAlignment = 1;
48 structMemberOffset = llvm::alignTo(structMemberOffset, memberAlignment);
49 memberTypes.push_back(memberType);
54 assert(memberSize != std::numeric_limits<Size>().
max() ||
60 structMemberOffset += memberSize;
61 maxMemberAlignment =
std::max(maxMemberAlignment, memberAlignment);
68 size = llvm::alignTo(structMemberOffset, maxMemberAlignment);
69 alignment = maxMemberAlignment;
82 if (isa<spirv::ScalarType>(type)) {
83 alignment = getScalarTypeAlignment(type);
88 if (
auto structType = dyn_cast<spirv::StructType>(type))
90 if (
auto arrayType = dyn_cast<spirv::ArrayType>(type))
92 if (
auto vectorType = dyn_cast<VectorType>(type))
94 if (
auto matrixType = dyn_cast<spirv::MatrixType>(type))
96 if (
auto arrayType = dyn_cast<spirv::RuntimeArrayType>(type)) {
97 size = std::numeric_limits<Size>().max();
100 if (isa<spirv::PointerType>(type)) {
104 llvm_unreachable(
"unhandled SPIR-V type");
111 Type elementType = vectorType.getElementType();
112 Size elementSize = 0;
113 Size elementAlignment = 1;
121 size = elementSize * numElements;
122 alignment = numElements == 2 ? elementAlignment * 2 : elementAlignment * 4;
131 Size elementSize = 0;
132 Size elementAlignment = 1;
138 size = elementSize * numElements;
139 alignment = elementAlignment;
150 Size elementSize = 0;
151 Size elementAlignment = 1;
153 decorateType(elementType, elementSize, elementAlignment);
157 size = elementSize * numElements;
158 alignment = elementAlignment;
165 Size elementSize = 0;
172 VulkanLayoutUtils::getScalarTypeAlignment(
Type scalarType) {
185 auto ptrType = dyn_cast<spirv::PointerType>(type);
190 const spirv::StorageClass storageClass = ptrType.getStorageClass();
191 auto structType = dyn_cast<spirv::StructType>(ptrType.getPointeeType());
196 switch (storageClass) {
197 case spirv::StorageClass::Uniform:
198 case spirv::StorageClass::StorageBuffer:
199 case spirv::StorageClass::PushConstant:
200 case spirv::StorageClass::PhysicalStorageBuffer:
static Value max(ImplicitLocOpBuilder &builder, Value value, Value bound)
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
unsigned getIntOrFloatBitWidth() const
Return the bit width of an integer or a float type, assert failure on other types.
static bool isLegalType(Type type)
Checks whether a type is legal in terms of Vulkan layout info decoration.
static spirv::StructType decorateType(spirv::StructType structType)
Returns a new StructType with layout decoration.
Type getElementType() const
unsigned getNumElements() const
static ArrayType get(Type elementType, unsigned elementCount)
unsigned getNumElements() const
Returns total number of elements (rows*columns).
static MatrixType get(Type columnType, uint32_t columnCount)
Type getColumnType() const
unsigned getNumColumns() const
Returns the number of columns.
Type getElementType() const
Returns the elements' type (i.e, single element type).
Type getElementType() const
static RuntimeArrayType get(Type elementType)
void getMemberDecorations(SmallVectorImpl< StructType::MemberDecorationInfo > &memberDecorations) const
bool isIdentified() const
Returns true if the StructType is identified.
unsigned getNumElements() const
Type getElementType(unsigned) const
static StructType get(ArrayRef< Type > memberTypes, ArrayRef< OffsetInfo > offsetInfo={}, ArrayRef< MemberDecorationInfo > memberDecorations={})
Construct a literal StructType with at least one member.
Include the generated interface declarations.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...