[clang] [Clang] NFC: Move Arm type attributes to separate trailing object. (PR #78424)

2024-01-17 Thread Sander de Smalen via cfe-commits

https://github.com/sdesmalen-arm created 
https://github.com/llvm/llvm-project/pull/78424

This decouples the Arm type attributes from other bits, which means
the data will only be allocated when a function uses these Arm
attributes.

The first patch adds the bit `HasArmTypeAttributes` to
`FunctionTypeBitfields`, which grows from 62 bits to 63 bits.

In the second patch, I've moved this bit (`HasArmTypeAttributes`) to
`FunctionTypeExtraBitfields`, because it looks like the bits in
`FunctionTypeBitfields` are precious and we really don't want that struct
to grow beyond 64 bits.

I've split this out into two patches to explain the rationale, but those
can be squashed before merging.


>From 00748e8fe0a58ec350053487179c15cb988ad9f7 Mon Sep 17 00:00:00 2001
From: Sander de Smalen 
Date: Wed, 17 Jan 2024 09:27:21 +
Subject: [PATCH 1/2] [Clang] NFC: Move Arm type attributes to separate
 trailing object.

This decouples the Arm type attributes from other bits, which means
the data will only be allocated when a function uses these Arm
attributes.

The first patch adds the bit `HasArmTypeAttributes` to
`FunctionTypeBitfields`, which grows from 62 bits to 63 bits.

In the second patch, I've moved this bit (`HasArmTypeAttributes`) to
`FunctionTypeExtraBitfields`, because it looks like the bits in
`FunctionTypeBitfields` are precious and we really don't want that struct
to grow beyond 64 bits.

I've split this out into two patches to explain the rationale, but those
can be squashed before merging.
---
 clang/include/clang/AST/Type.h | 58 --
 clang/lib/AST/ASTContext.cpp   |  7 ++--
 clang/lib/AST/Type.cpp | 12 +--
 3 files changed, 55 insertions(+), 22 deletions(-)

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index a7efe78591635e..63624a7ff1c554 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -1754,6 +1754,10 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
 LLVM_PREFERRED_TYPE(bool)
 unsigned HasExtraBitfields : 1;
 
+/// Whether this function has a trailing object for Arm type attributes.
+LLVM_PREFERRED_TYPE(bool)
+unsigned HasArmTypeAttributes : 1;
+
 /// Whether the function is variadic.
 LLVM_PREFERRED_TYPE(bool)
 unsigned Variadic : 1;
@@ -4029,6 +4033,18 @@ class FunctionType : public Type {
   /// because TrailingObjects cannot handle repeated types.
   struct ExceptionType { QualType Type; };
 
+  /// A simple holder for various uncommon bits which do not fit in
+  /// FunctionTypeBitfields. Aligned to alignof(void *) to maintain the
+  /// alignment of subsequent objects in TrailingObjects.
+  struct alignas(void *) FunctionTypeExtraBitfields {
+/// The number of types in the exception specification.
+/// A whole unsigned is not needed here and according to
+/// [implimits] 8 bits would be enough here.
+unsigned NumExceptionType : 10;
+
+FunctionTypeExtraBitfields() : NumExceptionType(0) {}
+  };
+
   /// The AArch64 SME ACLE (Arm C/C++ Language Extensions) define a number
   /// of function type attributes that can be set on function types, including
   /// function pointers.
@@ -4042,7 +4058,8 @@ class FunctionType : public Type {
 SME_ZAMask = 0b111 << SME_ZAShift,
 
 SME_AttributeMask = 0b111'111 // We only support maximum 6 bits because of
-  // the bitmask in FunctionTypeExtraBitfields.
+  // the bitmask in FunctionTypeArmAttributes
+  // and ExtProtoInfo.
   };
 
   enum ArmStateValue : unsigned {
@@ -4057,20 +4074,15 @@ class FunctionType : public Type {
 return (ArmStateValue)((AttrBits & SME_ZAMask) >> SME_ZAShift);
   }
 
-  /// A simple holder for various uncommon bits which do not fit in
-  /// FunctionTypeBitfields. Aligned to alignof(void *) to maintain the
-  /// alignment of subsequent objects in TrailingObjects.
-  struct alignas(void *) FunctionTypeExtraBitfields {
-/// The number of types in the exception specification.
-/// A whole unsigned is not needed here and according to
-/// [implimits] 8 bits would be enough here.
-unsigned NumExceptionType : 10;
-
+  /// A holder for Arm type attributes as described in the Arm C/C++
+  /// Language extensions which are not particularly common to all
+  /// types and therefore accounted separately from FunctionTypeBitfields.
+  struct alignas(void *) FunctionTypeArmAttributes {
 /// Any AArch64 SME ACLE type attributes that need to be propagated
 /// on declarations and function pointers.
 unsigned AArch64SMEAttributes : 6;
-FunctionTypeExtraBitfields()
-: NumExceptionType(0), AArch64SMEAttributes(SME_NormalFunction) {}
+
+FunctionTypeArmAttributes() : AArch64SMEAttributes(SME_NormalFunction) {}
   };
 
 protected:
@@ -4169,7 +4181,8 @@ class FunctionProtoType final
   public llvm::FoldingSetNode,
  

[clang] [Clang] NFC: Move Arm type attributes to separate trailing object. (PR #78424)

2024-01-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Sander de Smalen (sdesmalen-arm)


Changes

This decouples the Arm type attributes from other bits, which means
the data will only be allocated when a function uses these Arm
attributes.

The first patch adds the bit `HasArmTypeAttributes` to
`FunctionTypeBitfields`, which grows from 62 bits to 63 bits.

In the second patch, I've moved this bit (`HasArmTypeAttributes`) to
`FunctionTypeExtraBitfields`, because it looks like the bits in
`FunctionTypeBitfields` are precious and we really don't want that struct
to grow beyond 64 bits.

I've split this out into two patches to explain the rationale, but those
can be squashed before merging.


---
Full diff: https://github.com/llvm/llvm-project/pull/78424.diff


3 Files Affected:

- (modified) clang/include/clang/AST/Type.h (+43-16) 
- (modified) clang/lib/AST/ASTContext.cpp (+4-3) 
- (modified) clang/lib/AST/Type.cpp (+10-2) 


``diff
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index a7efe78591635e..259e920acf9ff3 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -4029,6 +4029,22 @@ class FunctionType : public Type {
   /// because TrailingObjects cannot handle repeated types.
   struct ExceptionType { QualType Type; };
 
+  /// A simple holder for various uncommon bits which do not fit in
+  /// FunctionTypeBitfields. Aligned to alignof(void *) to maintain the
+  /// alignment of subsequent objects in TrailingObjects.
+  struct alignas(void *) FunctionTypeExtraBitfields {
+/// The number of types in the exception specification.
+/// A whole unsigned is not needed here and according to
+/// [implimits] 8 bits would be enough here.
+unsigned NumExceptionType : 10;
+
+LLVM_PREFERRED_TYPE(bool)
+unsigned HasArmTypeAttributes : 1;
+
+FunctionTypeExtraBitfields()
+: NumExceptionType(0), HasArmTypeAttributes(false) {}
+  };
+
   /// The AArch64 SME ACLE (Arm C/C++ Language Extensions) define a number
   /// of function type attributes that can be set on function types, including
   /// function pointers.
@@ -4042,7 +4058,8 @@ class FunctionType : public Type {
 SME_ZAMask = 0b111 << SME_ZAShift,
 
 SME_AttributeMask = 0b111'111 // We only support maximum 6 bits because of
-  // the bitmask in FunctionTypeExtraBitfields.
+  // the bitmask in FunctionTypeArmAttributes
+  // and ExtProtoInfo.
   };
 
   enum ArmStateValue : unsigned {
@@ -4057,20 +4074,15 @@ class FunctionType : public Type {
 return (ArmStateValue)((AttrBits & SME_ZAMask) >> SME_ZAShift);
   }
 
-  /// A simple holder for various uncommon bits which do not fit in
-  /// FunctionTypeBitfields. Aligned to alignof(void *) to maintain the
-  /// alignment of subsequent objects in TrailingObjects.
-  struct alignas(void *) FunctionTypeExtraBitfields {
-/// The number of types in the exception specification.
-/// A whole unsigned is not needed here and according to
-/// [implimits] 8 bits would be enough here.
-unsigned NumExceptionType : 10;
-
+  /// A holder for Arm type attributes as described in the Arm C/C++
+  /// Language extensions which are not particularly common to all
+  /// types and therefore accounted separately from FunctionTypeBitfields.
+  struct alignas(void *) FunctionTypeArmAttributes {
 /// Any AArch64 SME ACLE type attributes that need to be propagated
 /// on declarations and function pointers.
 unsigned AArch64SMEAttributes : 6;
-FunctionTypeExtraBitfields()
-: NumExceptionType(0), AArch64SMEAttributes(SME_NormalFunction) {}
+
+FunctionTypeArmAttributes() : AArch64SMEAttributes(SME_NormalFunction) {}
   };
 
 protected:
@@ -4169,7 +4181,8 @@ class FunctionProtoType final
   public llvm::FoldingSetNode,
   private llvm::TrailingObjects<
   FunctionProtoType, QualType, SourceLocation,
-  FunctionType::FunctionTypeExtraBitfields, 
FunctionType::ExceptionType,
+  FunctionType::FunctionTypeExtraBitfields,
+  FunctionType::FunctionTypeArmAttributes, FunctionType::ExceptionType,
   Expr *, FunctionDecl *, FunctionType::ExtParameterInfo, Qualifiers> {
   friend class ASTContext; // ASTContext creates these.
   friend TrailingObjects;
@@ -4276,7 +4289,11 @@ class FunctionProtoType final
 
 bool requiresFunctionProtoTypeExtraBitfields() const {
   return ExceptionSpec.Type == EST_Dynamic ||
- AArch64SMEAttributes != SME_NormalFunction;
+ requiresFunctionProtoTypeArmAttributes();
+}
+
+bool requiresFunctionProtoTypeArmAttributes() const {
+  return AArch64SMEAttributes != SME_NormalFunction;
 }
 
 void setArmSMEAttribute(AArch64SMETypeAttributes Kind, bool Enable = true) 
{
@@ -4296,6 +4313,10 @@ class FunctionProtoType final
 return isVariadic();
   }
 
+  unsigned numTrailingObj

[clang] [Clang] NFC: Move Arm type attributes to separate trailing object. (PR #78424)

2024-01-17 Thread Erich Keane via cfe-commits

https://github.com/erichkeane approved this pull request.

This way of moving these further away is alright with me.  If Aaron is OK with 
it, than I am too.  So please wait for his approval too.

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


[clang] [Clang] NFC: Move Arm type attributes to separate trailing object. (PR #78424)

2024-01-17 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman approved this pull request.

LGTM! Thank you!

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


[clang] [Clang] NFC: Move Arm type attributes to separate trailing object. (PR #78424)

2024-01-17 Thread Sander de Smalen via cfe-commits

https://github.com/sdesmalen-arm closed 
https://github.com/llvm/llvm-project/pull/78424
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits