[clang] [CIR] Flatten structs with bitfields in CallConvLowering (PR #245599)

Steffen Larsen via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 27 00:40:50 PST 2026


================
@@ -99,15 +99,29 @@ cir::StructType getUnionFlattenType(cir::UnionType unionTy,
                               cir::RecordType::getAllDataKinds(fields));
 }
 
+/// The struct \p structTy is flattened as: itself, or if it has bit-fields,
+/// the storage of each member that owns bytes.  This matches its LLVM type.
+cir::StructType getStructFlattenType(cir::StructType structTy) {
+  if (!llvm::any_of(structTy.getMembers(), llvm::IsaPred<cir::BitFieldType>))
+    return structTy;
+  SmallVector<mlir::Type> fields;
----------------
steffenlarsen wrote:

I'm not sure if it's worth it, but we could count the non-owning members early and reserve:

```suggestion
  size_t numNonOwn = 0;
  if (!llvm::count_if(structTy.getMembers(), [&numNonOwn](mlir::Type member) {
        auto bfTy = mlir::dyn_cast<cir::BitFieldType>(member);
        if (!bfTy.ownsBytes())
          ++numNonOwn;
        return bfTy;
      }))
    return structTy;
  SmallVector<mlir::Type> fields;
  fields.reserve(structTy.getNumMembers() - numNonOwn);
```

https://github.com/llvm/llvm-project/pull/245599


More information about the cfe-commits mailing list