[clang] [NFC] Refactor ConstantArrayType size storage (PR #85716)

Eli Friedman via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 25 14:58:35 PDT 2024


================
@@ -3182,34 +3182,100 @@ class ArrayType : public Type, public llvm::FoldingSetNode {
 /// For example, the canonical type for 'int A[4 + 4*100]' is a
 /// ConstantArrayType where the element type is 'int' and the size is 404.
 class ConstantArrayType final
-    : public ArrayType,
-      private llvm::TrailingObjects<ConstantArrayType, const Expr *> {
+    : public ArrayType {
   friend class ASTContext; // ASTContext creates these.
-  friend TrailingObjects;
 
-  llvm::APInt Size; // Allows us to unique the type.
+  struct ExternalSize {
+    ExternalSize(const llvm::APInt &Sz, const Expr *SE)
+        : Size(Sz), SizeExpr(SE) {}
+    llvm::APInt Size; // Allows us to unique the type.
+    const Expr *SizeExpr;
+  };
+  struct InlineSize {
+    InlineSize(uint64_t TSz, uint64_t Sz) : ByteWidth(TSz), Size(Sz) {}
+    uint64_t ByteWidth : 4;
+    uint64_t Size : 60;
+  };
+  union {
+    struct InlineSize I;
+    ExternalSize *SizePtr;
+  };
----------------
efriedma-quic wrote:

If I'm reading this correctly, this actually saves 8 bytes over the current representation?  That's nice.

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


More information about the cfe-commits mailing list