================
@@ -225,17 +235,88 @@ void RecordType::complete(ArrayRef<Type> members, bool 
packed, bool padded) {
 
//===----------------------------------------------------------------------===//
 
 llvm::TypeSize
-RecordType::getTypeSizeInBits(const ::mlir::DataLayout &dataLayout,
-                              ::mlir::DataLayoutEntryListRef params) const {
-  assert(!cir::MissingFeatures::recordTypeLayoutInfo());
-  return llvm::TypeSize::getFixed(8);
+RecordType::getTypeSizeInBits(const mlir::DataLayout &dataLayout,
+                              mlir::DataLayoutEntryListRef params) const {
+  if (isUnion()) {
+    // TODO(CIR): Implement union layout.
+    return llvm::TypeSize::getFixed(8);
+  }
+
+  unsigned recordSize = computeStructSize(dataLayout);
+  return llvm::TypeSize::getFixed(recordSize * 8);
 }
 
 uint64_t
 RecordType::getABIAlignment(const ::mlir::DataLayout &dataLayout,
                             ::mlir::DataLayoutEntryListRef params) const {
-  assert(!cir::MissingFeatures::recordTypeLayoutInfo());
-  return 4;
+  if (isUnion()) {
+    // TODO(CIR): Implement union layout.
+    return 8;
+  }
+
+  // Packed structures always have an ABI alignment of 1.
+  if (getPacked())
+    return 1;
+  return computeStructAlignment(dataLayout);
+}
+
+unsigned
+RecordType::computeStructSize(const mlir::DataLayout &dataLayout) const {
----------------
andykaylor wrote:

This matches what the LLVM dialect does for `LLVMStructType::getTypeSizeInBits` 
except for the asserts about things already being aligned. I'm going to try 
this in the incubator. If the asserts do hold, I think I can remove the 
alignment calculations from this function.

https://github.com/llvm/llvm-project/pull/136036
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to