38 Size structMemberOffset = 0;
39 Size maxMemberAlignment = 1;
41 for (uint32_t i = 0, e = structType.
getNumElements(); i < e; ++i) {
43 Size memberAlignment = 1;
47 structMemberOffset = llvm::alignTo(structMemberOffset, memberAlignment);
48 memberTypes.push_back(memberType);
53 assert(memberSize != std::numeric_limits<Size>().
max() ||
59 structMemberOffset += memberSize;
60 maxMemberAlignment =
std::max(maxMemberAlignment, memberAlignment);
67 size = llvm::alignTo(structMemberOffset, maxMemberAlignment);
68 alignment = maxMemberAlignment;
81 if (isa<spirv::ScalarType>(type)) {
82 alignment = getScalarTypeAlignment(type);
87 if (
auto structType = dyn_cast<spirv::StructType>(type))
89 if (
auto arrayType = dyn_cast<spirv::ArrayType>(type))
91 if (
auto vectorType = dyn_cast<VectorType>(type))
93 if (
auto matrixType = dyn_cast<spirv::MatrixType>(type))
95 if (
auto arrayType = dyn_cast<spirv::RuntimeArrayType>(type)) {
96 size = std::numeric_limits<Size>().max();
99 if (isa<spirv::PointerType>(type)) {
103 llvm_unreachable(
"unhandled SPIR-V type");
110 Type elementType = vectorType.getElementType();
111 Size elementSize = 0;
112 Size elementAlignment = 1;
120 size = elementSize * numElements;
121 alignment = numElements == 2 ? elementAlignment * 2 : elementAlignment * 4;
130 Size elementSize = 0;
131 Size elementAlignment = 1;
137 size = elementSize * numElements;
138 alignment = elementAlignment;
149 Size elementSize = 0;
150 Size elementAlignment = 1;
152 decorateType(elementType, elementSize, elementAlignment);
156 size = elementSize * numElements;
157 alignment = elementAlignment;
164 Size elementSize = 0;
171 VulkanLayoutUtils::getScalarTypeAlignment(
Type scalarType) {
184 auto ptrType = dyn_cast<spirv::PointerType>(type);
189 const spirv::StorageClass storageClass = ptrType.getStorageClass();
190 auto structType = dyn_cast<spirv::StructType>(ptrType.getPointeeType());
195 switch (storageClass) {
196 case spirv::StorageClass::Uniform:
197 case spirv::StorageClass::StorageBuffer:
198 case spirv::StorageClass::PushConstant:
199 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={}, ArrayRef< StructDecorationInfo > structDecorations={})
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...