================
@@ -47,6 +50,98 @@ ArgInfo TargetInfo::getNaturalAlignIndirect(const Type *Ty,
unsigned AddrSpace,
return ArgInfo::getIndirect(Ty->getAlignment(), ByVal, AddrSpace);
}
+const Type *TargetInfo::getI8Array(uint64_t NumBytes) const {
+ assert(NumBytes != 0 && "empty padding");
+ const Type *I8 = TB.getIntegerType(8, llvm::Align(1), /*Signed=*/false);
+ return TB.getArrayType(I8, NumBytes, NumBytes * 8);
+}
+
+const Type *TargetInfo::getStructOfTypes(llvm::ArrayRef<const Type *> Elems,
+ bool Packed) const {
+ assert(!Elems.empty() && "empty coerce sequence");
+ llvm::SmallVector<FieldInfo, 8> Fields;
+ Fields.reserve(Elems.size());
+ for (const Type *Elt : Elems)
+ Fields.emplace_back(Elt, /*OffsetInBits=*/0);
+
+ StructPacking Pack = Packed ? StructPacking::Packed : StructPacking::Default;
+ return TB.getRecordType(Fields, llvm::TypeSize::getFixed(0), llvm::Align(1),
+ /*UnadjustedAlign=*/llvm::Align(1), Pack);
+}
+
+const Type *TargetInfo::convertTypeForMem(const Type *Ty) const {
+ if (const auto *AT = dyn_cast<ArrayType>(Ty)) {
+ if (AT->isMatrixType())
+ return Ty;
+ const Type *Elt = convertTypeForMem(AT->getElementType());
+ if (Elt == AT->getElementType())
+ return Ty;
+ assert(AT->getSizeInBits().isFixed() &&
+ "converted array element changes a scalable size");
+ return TB.getArrayType(Elt, AT->getNumElements(),
+ AT->getSizeInBits().getFixedValue());
+ }
+
+ const auto *RT = dyn_cast<RecordType>(Ty);
+ if (!RT || RT->isUnion())
+ return Ty;
+
+ // Current callers can't get here with virtual bases. If we need to handle
+ // virtual bases in the future, we'll need explicit handling for that below.
+ assert(RT->getNumVirtualBaseClasses() == 0 && "record has a virtual base");
+
+ llvm::SmallVector<FieldInfo, 8> Members;
+ for (const FieldInfo &Base : RT->getBaseClasses()) {
+ if (!Base.FieldType->isEmptyRecord())
+ Members.push_back(FieldInfo(Base.FieldType, Base.OffsetInBits));
+ }
+ for (const FieldInfo &Field : RT->getFields()) {
+ if (!Field.isEmpty())
+ Members.push_back(FieldInfo(Field.FieldType, Field.OffsetInBits));
+ }
+ llvm::stable_sort(Members, [](const FieldInfo &A, const FieldInfo &B) {
+ return A.OffsetInBits < B.OffsetInBits;
+ });
+
+ llvm::SmallVector<FieldInfo, 8> Fields;
+ uint64_t Current = 0;
+ for (const FieldInfo &Member : Members) {
+ assert(!Member.FieldType->getSizeInBits().isScalable() &&
+ "scalable member has no fixed offset");
+ if (Member.OffsetInBits > Current) {
----------------
madhur13490 wrote:
`convertTypeForMem` never looks at whether Clang would make the IR struct
packed. Once Clang packs a struct, it writes out every gap explicitly, even
gaps that natural alignment would explain. This aborts at 128 bits too:
```
typedef struct __attribute__((packed)) {
fixed_bool_t p;
fixed_int32_t v __attribute__((aligned(16)));
fixed_bool_t q;
fixed_int32_t w;
} T;
```
Clang's padded type is { <2 x i8>, [14 x i8], <4 x i32>, <2 x i8>, <4 x i32>,
[14 x i8] } and ours is { <2 x i8>, <4 x i32>, <2 x i8>, <4 x i32> }.
https://github.com/llvm/llvm-project/pull/227504
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits