[clang] [Clang] Amend SME attributes with support for ZT0. (PR #77941)

2024-01-23 Thread Simon Pilgrim via cfe-commits

RKSimon wrote:

@sdesmalen-arm This appears to be failing on some buildbots: 
https://lab.llvm.org/buildbot/#/builders/176/builds/8232
```
llvm-lit: 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls-2stage/llvm/llvm/utils/lit/lit/TestingConfig.py:152:
 fatal: unable to parse config file 
'/home/tcwg-buildbot/worker/clang-aarch64-sve-vls-2stage/stage2/runtimes/runtimes-bins/compiler-rt/unittests/lit.common.unit.configured',
 traceback: Traceback (most recent call last):
  File 
"/home/tcwg-buildbot/worker/clang-aarch64-sve-vls-2stage/llvm/llvm/utils/lit/lit/TestingConfig.py",
 line 140, in load_from_path
exec(compile(data, path, "exec"), cfg_globals, None)
  File 
"/home/tcwg-buildbot/worker/clang-aarch64-sve-vls-2stage/stage2/runtimes/runtimes-bins/compiler-rt/unittests/lit.common.unit.configured",
 line 23
config.aarch64_sme =
^
SyntaxError: invalid syntax
```

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


[clang] [Clang] Amend SME attributes with support for ZT0. (PR #77941)

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

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


[clang] [Clang] Amend SME attributes with support for ZT0. (PR #77941)

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

https://github.com/sdesmalen-arm updated 
https://github.com/llvm/llvm-project/pull/77941

>From c02435b095996fba3f34b13fad20b01849cee8e6 Mon Sep 17 00:00:00 2001
From: Sander de Smalen 
Date: Thu, 4 Jan 2024 14:03:04 +
Subject: [PATCH 1/3] [Clang] Amend SME attributes with support for ZT0.

This patch builds on top of #76971 and implements support for:
* __arm_new("zt0")
* __arm_in("zt0")
* __arm_out("zt0")
* __arm_inout("zt0")
* __arm_preserves("zt0")

The patch is ready for review but won't be able to land until LLVM
implements support for handling ZT0 state.
---
 clang/include/clang/AST/Type.h| 16 --
 clang/include/clang/Basic/Attr.td |  3 +
 .../clang/Basic/DiagnosticSemaKinds.td|  4 ++
 clang/lib/AST/TypePrinter.cpp |  8 +++
 clang/lib/CodeGen/CGCall.cpp  | 10 
 clang/lib/CodeGen/CodeGenModule.cpp   |  2 +
 clang/lib/Sema/SemaChecking.cpp   | 22 +++
 clang/lib/Sema/SemaDecl.cpp   | 11 
 clang/lib/Sema/SemaDeclAttr.cpp   |  8 +++
 clang/lib/Sema/SemaType.cpp   |  3 +
 .../aarch64-sme2-attrs.cpp| 57 +++
 ...-sme-func-attrs-without-target-feature.cpp |  2 +
 clang/test/Sema/aarch64-sme-func-attrs.c  | 45 +++
 13 files changed, 186 insertions(+), 5 deletions(-)
 create mode 100644 
clang/test/CodeGen/aarch64-sme2-intrinsics/aarch64-sme2-attrs.cpp

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 259e920acf9ff3b..ea425791fc97f05 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -4056,10 +4056,12 @@ class FunctionType : public Type {
 // Describes the value of the state using ArmStateValue.
 SME_ZAShift = 2,
 SME_ZAMask = 0b111 << SME_ZAShift,
+SME_ZT0Shift = 5,
+SME_ZT0Mask = 0b111 << SME_ZT0Shift,
 
-SME_AttributeMask = 0b111'111 // We only support maximum 6 bits because of
-  // the bitmask in FunctionTypeArmAttributes
-  // and ExtProtoInfo.
+SME_AttributeMask =
+0b111'111'11 // We can't support more than 8 bits because of
+ // the bitmask in FunctionTypeExtraBitfields.
   };
 
   enum ArmStateValue : unsigned {
@@ -4074,13 +4076,17 @@ class FunctionType : public Type {
 return (ArmStateValue)((AttrBits & SME_ZAMask) >> SME_ZAShift);
   }
 
+  static ArmStateValue getArmZT0State(unsigned AttrBits) {
+return (ArmStateValue)((AttrBits & SME_ZT0Mask) >> SME_ZT0Shift);
+  }
+
   /// 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;
+unsigned AArch64SMEAttributes : 8;
 
 FunctionTypeArmAttributes() : AArch64SMEAttributes(SME_NormalFunction) {}
   };
@@ -4266,7 +4272,7 @@ class FunctionProtoType final
 FunctionType::ExtInfo ExtInfo;
 unsigned Variadic : 1;
 unsigned HasTrailingReturn : 1;
-unsigned AArch64SMEAttributes : 6;
+unsigned AArch64SMEAttributes : 8;
 Qualifiers TypeQuals;
 RefQualifierKind RefQualifier = RQ_None;
 ExceptionSpecInfo ExceptionSpec;
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 78a9229aeaf081e..58838b01b4fd7ca 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2552,6 +2552,9 @@ def ArmNew : InheritableAttr, 
TargetSpecificAttr {
 bool isNewZA() const {
   return llvm::is_contained(newArgs(), "za");
 }
+bool isNewZT0() const {
+  return llvm::is_contained(newArgs(), "zt0");
+}
   }];
 }
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 501968cb7d5f992..e027e754477fcf4 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3706,10 +3706,14 @@ def err_sme_call_in_non_sme_target : Error<
   "call to a streaming function requires 'sme'">;
 def err_sme_za_call_no_za_state : Error<
   "call to a shared ZA function requires the caller to have ZA state">;
+def err_sme_zt0_call_no_zt0_state : Error<
+  "call to a shared ZT0 function requires the caller to have ZT0 state">;
 def err_sme_definition_using_sm_in_non_sme_target : Error<
   "function executed in streaming-SVE mode requires 'sme'">;
 def err_sme_definition_using_za_in_non_sme_target : Error<
   "function using ZA state requires 'sme'">;
+def err_sme_definition_using_zt0_in_non_sme2_target : Error<
+  "function using ZT0 state requires 'sme2'">;
 def err_conflicting_attributes_arm_state : Error<
 

[clang] [Clang] Amend SME attributes with support for ZT0. (PR #77941)

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

https://github.com/sdesmalen-arm updated 
https://github.com/llvm/llvm-project/pull/77941

>From 34da3f6446c826ec1d2c7f6eb8020d1c18146b51 Mon Sep 17 00:00:00 2001
From: Sander de Smalen 
Date: Thu, 4 Jan 2024 14:03:04 +
Subject: [PATCH 1/3] [Clang] Amend SME attributes with support for ZT0.

This patch builds on top of #76971 and implements support for:
* __arm_new("zt0")
* __arm_in("zt0")
* __arm_out("zt0")
* __arm_inout("zt0")
* __arm_preserves("zt0")

The patch is ready for review but won't be able to land until LLVM
implements support for handling ZT0 state.
---
 clang/include/clang/AST/Type.h| 16 --
 clang/include/clang/Basic/Attr.td |  3 +
 .../clang/Basic/DiagnosticSemaKinds.td|  4 ++
 clang/lib/AST/TypePrinter.cpp |  8 +++
 clang/lib/CodeGen/CGCall.cpp  | 10 
 clang/lib/CodeGen/CodeGenModule.cpp   |  2 +
 clang/lib/Sema/SemaChecking.cpp   | 22 +++
 clang/lib/Sema/SemaDecl.cpp   | 11 
 clang/lib/Sema/SemaDeclAttr.cpp   |  8 +++
 clang/lib/Sema/SemaType.cpp   |  3 +
 .../aarch64-sme2-attrs.cpp| 57 +++
 ...-sme-func-attrs-without-target-feature.cpp |  2 +
 clang/test/Sema/aarch64-sme-func-attrs.c  | 45 +++
 13 files changed, 186 insertions(+), 5 deletions(-)
 create mode 100644 
clang/test/CodeGen/aarch64-sme2-intrinsics/aarch64-sme2-attrs.cpp

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 259e920acf9ff3b..ea425791fc97f05 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -4056,10 +4056,12 @@ class FunctionType : public Type {
 // Describes the value of the state using ArmStateValue.
 SME_ZAShift = 2,
 SME_ZAMask = 0b111 << SME_ZAShift,
+SME_ZT0Shift = 5,
+SME_ZT0Mask = 0b111 << SME_ZT0Shift,
 
-SME_AttributeMask = 0b111'111 // We only support maximum 6 bits because of
-  // the bitmask in FunctionTypeArmAttributes
-  // and ExtProtoInfo.
+SME_AttributeMask =
+0b111'111'11 // We can't support more than 8 bits because of
+ // the bitmask in FunctionTypeExtraBitfields.
   };
 
   enum ArmStateValue : unsigned {
@@ -4074,13 +4076,17 @@ class FunctionType : public Type {
 return (ArmStateValue)((AttrBits & SME_ZAMask) >> SME_ZAShift);
   }
 
+  static ArmStateValue getArmZT0State(unsigned AttrBits) {
+return (ArmStateValue)((AttrBits & SME_ZT0Mask) >> SME_ZT0Shift);
+  }
+
   /// 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;
+unsigned AArch64SMEAttributes : 8;
 
 FunctionTypeArmAttributes() : AArch64SMEAttributes(SME_NormalFunction) {}
   };
@@ -4266,7 +4272,7 @@ class FunctionProtoType final
 FunctionType::ExtInfo ExtInfo;
 unsigned Variadic : 1;
 unsigned HasTrailingReturn : 1;
-unsigned AArch64SMEAttributes : 6;
+unsigned AArch64SMEAttributes : 8;
 Qualifiers TypeQuals;
 RefQualifierKind RefQualifier = RQ_None;
 ExceptionSpecInfo ExceptionSpec;
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 78a9229aeaf081e..58838b01b4fd7ca 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2552,6 +2552,9 @@ def ArmNew : InheritableAttr, 
TargetSpecificAttr {
 bool isNewZA() const {
   return llvm::is_contained(newArgs(), "za");
 }
+bool isNewZT0() const {
+  return llvm::is_contained(newArgs(), "zt0");
+}
   }];
 }
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 501968cb7d5f992..e027e754477fcf4 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3706,10 +3706,14 @@ def err_sme_call_in_non_sme_target : Error<
   "call to a streaming function requires 'sme'">;
 def err_sme_za_call_no_za_state : Error<
   "call to a shared ZA function requires the caller to have ZA state">;
+def err_sme_zt0_call_no_zt0_state : Error<
+  "call to a shared ZT0 function requires the caller to have ZT0 state">;
 def err_sme_definition_using_sm_in_non_sme_target : Error<
   "function executed in streaming-SVE mode requires 'sme'">;
 def err_sme_definition_using_za_in_non_sme_target : Error<
   "function using ZA state requires 'sme'">;
+def err_sme_definition_using_zt0_in_non_sme2_target : Error<
+  "function using ZT0 state requires 'sme2'">;
 def err_conflicting_attributes_arm_state : Error<
 

[clang] [Clang] Amend SME attributes with support for ZT0. (PR #77941)

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

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

I'm ok with this now.

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


[clang] [Clang] Amend SME attributes with support for ZT0. (PR #77941)

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

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

There should be a release note for the new functionality, but otherwise the 
changes LGTM. Please wait a bit in case @erichkeane has any other concerns.

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


[clang] [Clang] Amend SME attributes with support for ZT0. (PR #77941)

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

sdesmalen-arm wrote:

[rebased patch on top of #78424]

With the contentious part of adding new bits addressed in #78424 and 
@rsandifo-arm having reviewed and informally accepted the Arm/ZT0 side of the 
changes in this pull-request, are you happy to formally accept this PR 
@erichkeane / @AaronBallman?

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


[clang] [Clang] Amend SME attributes with support for ZT0. (PR #77941)

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

https://github.com/sdesmalen-arm updated 
https://github.com/llvm/llvm-project/pull/77941

>From 3be3f5f3a0176ec704c516961e1eff0d3713b084 Mon Sep 17 00:00:00 2001
From: Sander de Smalen 
Date: Thu, 4 Jan 2024 14:03:04 +
Subject: [PATCH 1/2] [Clang] Amend SME attributes with support for ZT0.

This patch builds on top of #76971 and implements support for:
* __arm_new("zt0")
* __arm_in("zt0")
* __arm_out("zt0")
* __arm_inout("zt0")
* __arm_preserves("zt0")

The patch is ready for review but won't be able to land until LLVM
implements support for handling ZT0 state.
---
 clang/include/clang/AST/Type.h| 16 --
 clang/include/clang/Basic/Attr.td |  3 +
 .../clang/Basic/DiagnosticSemaKinds.td|  4 ++
 clang/lib/AST/TypePrinter.cpp |  8 +++
 clang/lib/CodeGen/CGCall.cpp  | 10 
 clang/lib/CodeGen/CodeGenModule.cpp   |  2 +
 clang/lib/Sema/SemaChecking.cpp   | 22 +++
 clang/lib/Sema/SemaDecl.cpp   | 11 
 clang/lib/Sema/SemaDeclAttr.cpp   |  8 +++
 clang/lib/Sema/SemaType.cpp   |  3 +
 .../aarch64-sme2-attrs.cpp| 57 +++
 ...-sme-func-attrs-without-target-feature.cpp |  2 +
 clang/test/Sema/aarch64-sme-func-attrs.c  | 45 +++
 13 files changed, 186 insertions(+), 5 deletions(-)
 create mode 100644 
clang/test/CodeGen/aarch64-sme2-intrinsics/aarch64-sme2-attrs.cpp

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 259e920acf9ff3b..ea425791fc97f05 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -4056,10 +4056,12 @@ class FunctionType : public Type {
 // Describes the value of the state using ArmStateValue.
 SME_ZAShift = 2,
 SME_ZAMask = 0b111 << SME_ZAShift,
+SME_ZT0Shift = 5,
+SME_ZT0Mask = 0b111 << SME_ZT0Shift,
 
-SME_AttributeMask = 0b111'111 // We only support maximum 6 bits because of
-  // the bitmask in FunctionTypeArmAttributes
-  // and ExtProtoInfo.
+SME_AttributeMask =
+0b111'111'11 // We can't support more than 8 bits because of
+ // the bitmask in FunctionTypeExtraBitfields.
   };
 
   enum ArmStateValue : unsigned {
@@ -4074,13 +4076,17 @@ class FunctionType : public Type {
 return (ArmStateValue)((AttrBits & SME_ZAMask) >> SME_ZAShift);
   }
 
+  static ArmStateValue getArmZT0State(unsigned AttrBits) {
+return (ArmStateValue)((AttrBits & SME_ZT0Mask) >> SME_ZT0Shift);
+  }
+
   /// 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;
+unsigned AArch64SMEAttributes : 8;
 
 FunctionTypeArmAttributes() : AArch64SMEAttributes(SME_NormalFunction) {}
   };
@@ -4266,7 +4272,7 @@ class FunctionProtoType final
 FunctionType::ExtInfo ExtInfo;
 unsigned Variadic : 1;
 unsigned HasTrailingReturn : 1;
-unsigned AArch64SMEAttributes : 6;
+unsigned AArch64SMEAttributes : 8;
 Qualifiers TypeQuals;
 RefQualifierKind RefQualifier = RQ_None;
 ExceptionSpecInfo ExceptionSpec;
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 78a9229aeaf081e..58838b01b4fd7ca 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2552,6 +2552,9 @@ def ArmNew : InheritableAttr, 
TargetSpecificAttr {
 bool isNewZA() const {
   return llvm::is_contained(newArgs(), "za");
 }
+bool isNewZT0() const {
+  return llvm::is_contained(newArgs(), "zt0");
+}
   }];
 }
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 03b0122d1c08f75..600e602c33d6102 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3698,10 +3698,14 @@ def err_sme_call_in_non_sme_target : Error<
   "call to a streaming function requires 'sme'">;
 def err_sme_za_call_no_za_state : Error<
   "call to a shared ZA function requires the caller to have ZA state">;
+def err_sme_zt0_call_no_zt0_state : Error<
+  "call to a shared ZT0 function requires the caller to have ZT0 state">;
 def err_sme_definition_using_sm_in_non_sme_target : Error<
   "function executed in streaming-SVE mode requires 'sme'">;
 def err_sme_definition_using_za_in_non_sme_target : Error<
   "function using ZA state requires 'sme'">;
+def err_sme_definition_using_zt0_in_non_sme2_target : Error<
+  "function using ZT0 state requires 'sme2'">;
 def err_conflicting_attributes_arm_state : Error<
 

[clang] [Clang] Amend SME attributes with support for ZT0. (PR #77941)

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


@@ -4253,7 +4260,7 @@ class FunctionProtoType final
 FunctionType::ExtInfo ExtInfo;
 unsigned Variadic : 1;
 unsigned HasTrailingReturn : 1;
-unsigned AArch64SMEAttributes : 6;

sdesmalen-arm wrote:

Thanks for both your input! The Arm attributes will probably be used reasonably 
sparsely in the sense that they particularly target code to optimise using SME 
intrinsics/state. By not adding the attribute it will be a normal function that 
does not share any SME state. So I agree it makes sense to refactor the code a 
bit such that these attributes don't affect code that does not use any of these 
attributes.

I've created #78424 to do this, so that the Arm SME attributes will have their 
own TrailingObject and are therefore only allocated when a function uses the 
attributes. I hope that addresses the concerns! (When that patch lands, I'll 
rebase this one)

It will be more difficult to do something for ExtProtoInfo, given how this is 
designed, but as @AaronBallman says the struct is already huge and is allocated 
as-needed. My experiment showed that adding more bits didn't make a practical 
difference to the size of the ExtProtoInfo. Not sure if this can differ between 
compilers, but I didn't see it expanding the struct by a byte.

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


[clang] [Clang] Amend SME attributes with support for ZT0. (PR #77941)

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


@@ -4068,7 +4075,7 @@ class FunctionType : public Type {
 
 /// Any AArch64 SME ACLE type attributes that need to be propagated
 /// on declarations and function pointers.
-unsigned AArch64SMEAttributes : 6;
+unsigned AArch64SMEAttributes : 8;

erichkeane wrote:

Note that doing so is perhaps a breaking change for users, it DOES put us right 
up at 'imp-limits', but it is entirely possible that users are counting on us 
exceeding the minimum here.  And this is a reduction to a 'reasonable' number.

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


[clang] [Clang] Amend SME attributes with support for ZT0. (PR #77941)

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


@@ -4068,7 +4075,7 @@ class FunctionType : public Type {
 
 /// Any AArch64 SME ACLE type attributes that need to be propagated
 /// on declarations and function pointers.
-unsigned AArch64SMEAttributes : 6;
+unsigned AArch64SMEAttributes : 8;

AaronBallman wrote:

We could claw back these two bits by reducing `NumExceptionType` from 10 to 8.

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


[clang] [Clang] Amend SME attributes with support for ZT0. (PR #77941)

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


@@ -4253,7 +4260,7 @@ class FunctionProtoType final
 FunctionType::ExtInfo ExtInfo;
 unsigned Variadic : 1;
 unsigned HasTrailingReturn : 1;
-unsigned AArch64SMEAttributes : 6;

AaronBallman wrote:


Looking through the review which started introducing SME attributes, we went to 
pretty big lengths to try to keep that at zero-cost by figuring out the upper 
bounds. Now we're looking to expand those upper bounds because they were 
insufficient less than six months later.

So I'm also concerned about the extra memory pressures this adds because those 
pressures impact everyone, not just folks targeting AArch64 with these SME 
attributes. If we have to increase that pressure because this is needed 
functionality, I think it seems like the cost should be borne by the users 
using the new functionality instead of impacting everyone.


That said, `ExtInfo` and `FunctionTypeExtraBitfields` are the ones that needs 
to stay small; `ExtProtoInfo` is already huge thanks to `ExceptionSpecInfo` 
being 48 bytes. IIRC, `ExtProtoInfo` is allocated as-needed and so it can grow.

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


[clang] [Clang] Amend SME attributes with support for ZT0. (PR #77941)

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

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


[clang] [Clang] Amend SME attributes with support for ZT0. (PR #77941)

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

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


[clang] [Clang] Amend SME attributes with support for ZT0. (PR #77941)

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


@@ -4253,7 +4260,7 @@ class FunctionProtoType final
 FunctionType::ExtInfo ExtInfo;
 unsigned Variadic : 1;
 unsigned HasTrailingReturn : 1;
-unsigned AArch64SMEAttributes : 6;

erichkeane wrote:

Note that thanks to bitfield packing, this is expanding this struct an entire 
byte.

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


[clang] [Clang] Amend SME attributes with support for ZT0. (PR #77941)

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

https://github.com/erichkeane commented:

The additional size of ExtProtoInfo and FunctionType  are both, IMO, 
problematic, we should be shrinking these.

>This also make me wonder if we should be reserving some extra bits for future 
>state that may need adding?

The point is to minimize the size of these, since adding additional bits like 
this is limiting the code we can compile.  The 'extra bits' were an attempt to 
organize, not to minimize the size.

Why is the spec that this is from being so aggressive about modifying the types 
of functions?  This is causing some pretty annoying amounts of memory pressure 
in the compiler.  

IMO, we need to find some way to no longer store this information on the 
function type in a way that punishes every function.

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


[clang] [Clang] Amend SME attributes with support for ZT0. (PR #77941)

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

https://github.com/sdesmalen-arm updated 
https://github.com/llvm/llvm-project/pull/77941

>From 764e7aaecffb758e7a311c17a189ee605c623246 Mon Sep 17 00:00:00 2001
From: Sander de Smalen 
Date: Thu, 4 Jan 2024 14:03:04 +
Subject: [PATCH 1/2] [Clang] Amend SME attributes with support for ZT0.

This patch builds on top of #76971 and implements support for:
* __arm_new("zt0")
* __arm_in("zt0")
* __arm_out("zt0")
* __arm_inout("zt0")
* __arm_preserves("zt0")

The patch is ready for review but won't be able to land until LLVM
implements support for handling ZT0 state.
---
 clang/include/clang/AST/Type.h| 15 +++--
 clang/include/clang/Basic/Attr.td |  3 +
 .../clang/Basic/DiagnosticSemaKinds.td|  4 ++
 clang/lib/AST/TypePrinter.cpp |  8 +++
 clang/lib/CodeGen/CGCall.cpp  | 10 
 clang/lib/CodeGen/CodeGenModule.cpp   |  2 +
 clang/lib/Sema/SemaChecking.cpp   | 22 +++
 clang/lib/Sema/SemaDecl.cpp   | 11 
 clang/lib/Sema/SemaDeclAttr.cpp   |  8 +++
 clang/lib/Sema/SemaType.cpp   |  3 +
 .../aarch64-sme2-attrs.cpp| 57 +++
 ...-sme-func-attrs-without-target-feature.cpp |  2 +
 clang/test/Sema/aarch64-sme-func-attrs.c  | 45 +++
 13 files changed, 186 insertions(+), 4 deletions(-)
 create mode 100644 
clang/test/CodeGen/aarch64-sme2-intrinsics/aarch64-sme2-attrs.cpp

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index a7efe78591635e..a56401f9da0450 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -4040,9 +4040,12 @@ class FunctionType : public Type {
 // Describes the value of the state using ArmStateValue.
 SME_ZAShift = 2,
 SME_ZAMask = 0b111 << SME_ZAShift,
+SME_ZT0Shift = 5,
+SME_ZT0Mask = 0b111 << SME_ZT0Shift,
 
-SME_AttributeMask = 0b111'111 // We only support maximum 6 bits because of
-  // the bitmask in FunctionTypeExtraBitfields.
+SME_AttributeMask =
+0b111'111'11 // We can't support more than 8 bits because of
+ // the bitmask in FunctionTypeExtraBitfields.
   };
 
   enum ArmStateValue : unsigned {
@@ -4057,6 +4060,10 @@ class FunctionType : public Type {
 return (ArmStateValue)((AttrBits & SME_ZAMask) >> SME_ZAShift);
   }
 
+  static ArmStateValue getArmZT0State(unsigned AttrBits) {
+return (ArmStateValue)((AttrBits & SME_ZT0Mask) >> SME_ZT0Shift);
+  }
+
   /// 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.
@@ -4068,7 +4075,7 @@ class FunctionType : public Type {
 
 /// Any AArch64 SME ACLE type attributes that need to be propagated
 /// on declarations and function pointers.
-unsigned AArch64SMEAttributes : 6;
+unsigned AArch64SMEAttributes : 8;
 FunctionTypeExtraBitfields()
 : NumExceptionType(0), AArch64SMEAttributes(SME_NormalFunction) {}
   };
@@ -4253,7 +4260,7 @@ class FunctionProtoType final
 FunctionType::ExtInfo ExtInfo;
 unsigned Variadic : 1;
 unsigned HasTrailingReturn : 1;
-unsigned AArch64SMEAttributes : 6;
+unsigned AArch64SMEAttributes : 8;
 Qualifiers TypeQuals;
 RefQualifierKind RefQualifier = RQ_None;
 ExceptionSpecInfo ExceptionSpec;
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index b9ec720dd9e199..174d4e14bfa0ec 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2549,6 +2549,9 @@ def ArmNew : InheritableAttr, 
TargetSpecificAttr {
 bool isNewZA() const {
   return llvm::is_contained(newArgs(), "za");
 }
+bool isNewZT0() const {
+  return llvm::is_contained(newArgs(), "zt0");
+}
   }];
 }
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c50b188a1039ac..cca4a4419d0bf9 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3696,10 +3696,14 @@ def err_sme_call_in_non_sme_target : Error<
   "call to a streaming function requires 'sme'">;
 def err_sme_za_call_no_za_state : Error<
   "call to a shared ZA function requires the caller to have ZA state">;
+def err_sme_zt0_call_no_zt0_state : Error<
+  "call to a shared ZT0 function requires the caller to have ZT0 state">;
 def err_sme_definition_using_sm_in_non_sme_target : Error<
   "function executed in streaming-SVE mode requires 'sme'">;
 def err_sme_definition_using_za_in_non_sme_target : Error<
   "function using ZA state requires 'sme'">;
+def err_sme_definition_using_zt0_in_non_sme2_target : Error<
+  "function using ZT0 state requires 'sme2'">;
 def err_conflicting_attributes_arm_state : Error<
   "conflicting attributes for state 

[clang] [Clang] Amend SME attributes with support for ZT0. (PR #77941)

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

sdesmalen-arm wrote:

> I won't approve because of the growth in FunctionProtoType — someone more 
> qualified than me should sign off on that.

@AaronBallman or @erichkeane, would you be happy to sign off on this patch?

I think previously you raised concerns about the size of `ExtProtoInfo` when 
adding more bits to it. (This was discussed on 
https://reviews.llvm.org/D127762, but unfortunately this link currently results 
in a 404)

It's worth pointing out that extending `ExtProtoInfo` with some more bits 
doesn't change the actual size. It is 80 bytes at the moment and increasing it 
with 2 more bits doesn't change the total size of the struct. The size of 
`FunctionTypeExtraBitfields` will increase though, but I'm not sure if this is 
a problem because the comment above it says that these bits are uncommon to 
start with. I could shave off another two bits off `NumExceptionType` to avoid 
that, as the comment suggests 8 bits should be sufficient.

This also make me wonder if we should be reserving some extra bits for future 
state that may need adding?

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


[clang] [Clang] Amend SME attributes with support for ZT0. (PR #77941)

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

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


[clang] [Clang] Amend SME attributes with support for ZT0. (PR #77941)

2024-01-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Sander de Smalen (sdesmalen-arm)


Changes

This patch builds on top of #76971 and implements support for:
* __arm_new("zt0")
* __arm_in("zt0")
* __arm_out("zt0")
* __arm_inout("zt0")
* __arm_preserves("zt0")

I'll rebase this patch after I land #76971, as this is currently a
stacked pull-request on top of #76971.

The patch is ready for review but won't be able to land until LLVM
implements support for handling ZT0 state.

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


13 Files Affected:

- (modified) clang/include/clang/AST/Type.h (+11-4) 
- (modified) clang/include/clang/Basic/Attr.td (+3) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+4) 
- (modified) clang/lib/AST/TypePrinter.cpp (+8) 
- (modified) clang/lib/CodeGen/CGCall.cpp (+10) 
- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+2) 
- (modified) clang/lib/Sema/SemaChecking.cpp (+22) 
- (modified) clang/lib/Sema/SemaDecl.cpp (+11) 
- (modified) clang/lib/Sema/SemaDeclAttr.cpp (+8) 
- (modified) clang/lib/Sema/SemaType.cpp (+3) 
- (added) clang/test/CodeGen/aarch64-sme2-intrinsics/aarch64-sme2-attrs.cpp 
(+57) 
- (modified) clang/test/Sema/aarch64-sme-func-attrs-without-target-feature.cpp 
(+2) 
- (modified) clang/test/Sema/aarch64-sme-func-attrs.c (+45) 


``diff
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index a7efe78591635e0..a56401f9da0450b 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -4040,9 +4040,12 @@ class FunctionType : public Type {
 // Describes the value of the state using ArmStateValue.
 SME_ZAShift = 2,
 SME_ZAMask = 0b111 << SME_ZAShift,
+SME_ZT0Shift = 5,
+SME_ZT0Mask = 0b111 << SME_ZT0Shift,
 
-SME_AttributeMask = 0b111'111 // We only support maximum 6 bits because of
-  // the bitmask in FunctionTypeExtraBitfields.
+SME_AttributeMask =
+0b111'111'11 // We can't support more than 8 bits because of
+ // the bitmask in FunctionTypeExtraBitfields.
   };
 
   enum ArmStateValue : unsigned {
@@ -4057,6 +4060,10 @@ class FunctionType : public Type {
 return (ArmStateValue)((AttrBits & SME_ZAMask) >> SME_ZAShift);
   }
 
+  static ArmStateValue getArmZT0State(unsigned AttrBits) {
+return (ArmStateValue)((AttrBits & SME_ZT0Mask) >> SME_ZT0Shift);
+  }
+
   /// 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.
@@ -4068,7 +4075,7 @@ class FunctionType : public Type {
 
 /// Any AArch64 SME ACLE type attributes that need to be propagated
 /// on declarations and function pointers.
-unsigned AArch64SMEAttributes : 6;
+unsigned AArch64SMEAttributes : 8;
 FunctionTypeExtraBitfields()
 : NumExceptionType(0), AArch64SMEAttributes(SME_NormalFunction) {}
   };
@@ -4253,7 +4260,7 @@ class FunctionProtoType final
 FunctionType::ExtInfo ExtInfo;
 unsigned Variadic : 1;
 unsigned HasTrailingReturn : 1;
-unsigned AArch64SMEAttributes : 6;
+unsigned AArch64SMEAttributes : 8;
 Qualifiers TypeQuals;
 RefQualifierKind RefQualifier = RQ_None;
 ExceptionSpecInfo ExceptionSpec;
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index b9ec720dd9e199c..174d4e14bfa0ecb 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2549,6 +2549,9 @@ def ArmNew : InheritableAttr, 
TargetSpecificAttr {
 bool isNewZA() const {
   return llvm::is_contained(newArgs(), "za");
 }
+bool isNewZT0() const {
+  return llvm::is_contained(newArgs(), "zt0");
+}
   }];
 }
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c50b188a1039acb..cca4a4419d0bf94 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3696,10 +3696,14 @@ def err_sme_call_in_non_sme_target : Error<
   "call to a streaming function requires 'sme'">;
 def err_sme_za_call_no_za_state : Error<
   "call to a shared ZA function requires the caller to have ZA state">;
+def err_sme_zt0_call_no_zt0_state : Error<
+  "call to a shared ZT0 function requires the caller to have ZT0 state">;
 def err_sme_definition_using_sm_in_non_sme_target : Error<
   "function executed in streaming-SVE mode requires 'sme'">;
 def err_sme_definition_using_za_in_non_sme_target : Error<
   "function using ZA state requires 'sme'">;
+def err_sme_definition_using_zt0_in_non_sme2_target : Error<
+  "function using ZT0 state requires 'sme2'">;
 def err_conflicting_attributes_arm_state : Error<
   "conflicting attributes for state '%0'">;
 def err_unknown_arm_state : Error<
diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp

[clang] [Clang] Amend SME attributes with support for ZT0. (PR #77941)

2024-01-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Sander de Smalen (sdesmalen-arm)


Changes

This patch builds on top of #76971 and implements support for:
* __arm_new("zt0")
* __arm_in("zt0")
* __arm_out("zt0")
* __arm_inout("zt0")
* __arm_preserves("zt0")

I'll rebase this patch after I land #76971, as this is currently a
stacked pull-request on top of #76971.

The patch is ready for review but won't be able to land until LLVM
implements support for handling ZT0 state.

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


13 Files Affected:

- (modified) clang/include/clang/AST/Type.h (+11-4) 
- (modified) clang/include/clang/Basic/Attr.td (+3) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+4) 
- (modified) clang/lib/AST/TypePrinter.cpp (+8) 
- (modified) clang/lib/CodeGen/CGCall.cpp (+10) 
- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+2) 
- (modified) clang/lib/Sema/SemaChecking.cpp (+22) 
- (modified) clang/lib/Sema/SemaDecl.cpp (+11) 
- (modified) clang/lib/Sema/SemaDeclAttr.cpp (+8) 
- (modified) clang/lib/Sema/SemaType.cpp (+3) 
- (added) clang/test/CodeGen/aarch64-sme2-intrinsics/aarch64-sme2-attrs.cpp 
(+57) 
- (modified) clang/test/Sema/aarch64-sme-func-attrs-without-target-feature.cpp 
(+2) 
- (modified) clang/test/Sema/aarch64-sme-func-attrs.c (+45) 


``diff
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index a7efe78591635e0..a56401f9da0450b 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -4040,9 +4040,12 @@ class FunctionType : public Type {
 // Describes the value of the state using ArmStateValue.
 SME_ZAShift = 2,
 SME_ZAMask = 0b111 << SME_ZAShift,
+SME_ZT0Shift = 5,
+SME_ZT0Mask = 0b111 << SME_ZT0Shift,
 
-SME_AttributeMask = 0b111'111 // We only support maximum 6 bits because of
-  // the bitmask in FunctionTypeExtraBitfields.
+SME_AttributeMask =
+0b111'111'11 // We can't support more than 8 bits because of
+ // the bitmask in FunctionTypeExtraBitfields.
   };
 
   enum ArmStateValue : unsigned {
@@ -4057,6 +4060,10 @@ class FunctionType : public Type {
 return (ArmStateValue)((AttrBits & SME_ZAMask) >> SME_ZAShift);
   }
 
+  static ArmStateValue getArmZT0State(unsigned AttrBits) {
+return (ArmStateValue)((AttrBits & SME_ZT0Mask) >> SME_ZT0Shift);
+  }
+
   /// 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.
@@ -4068,7 +4075,7 @@ class FunctionType : public Type {
 
 /// Any AArch64 SME ACLE type attributes that need to be propagated
 /// on declarations and function pointers.
-unsigned AArch64SMEAttributes : 6;
+unsigned AArch64SMEAttributes : 8;
 FunctionTypeExtraBitfields()
 : NumExceptionType(0), AArch64SMEAttributes(SME_NormalFunction) {}
   };
@@ -4253,7 +4260,7 @@ class FunctionProtoType final
 FunctionType::ExtInfo ExtInfo;
 unsigned Variadic : 1;
 unsigned HasTrailingReturn : 1;
-unsigned AArch64SMEAttributes : 6;
+unsigned AArch64SMEAttributes : 8;
 Qualifiers TypeQuals;
 RefQualifierKind RefQualifier = RQ_None;
 ExceptionSpecInfo ExceptionSpec;
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index b9ec720dd9e199c..174d4e14bfa0ecb 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2549,6 +2549,9 @@ def ArmNew : InheritableAttr, 
TargetSpecificAttr {
 bool isNewZA() const {
   return llvm::is_contained(newArgs(), "za");
 }
+bool isNewZT0() const {
+  return llvm::is_contained(newArgs(), "zt0");
+}
   }];
 }
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c50b188a1039acb..cca4a4419d0bf94 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3696,10 +3696,14 @@ def err_sme_call_in_non_sme_target : Error<
   "call to a streaming function requires 'sme'">;
 def err_sme_za_call_no_za_state : Error<
   "call to a shared ZA function requires the caller to have ZA state">;
+def err_sme_zt0_call_no_zt0_state : Error<
+  "call to a shared ZT0 function requires the caller to have ZT0 state">;
 def err_sme_definition_using_sm_in_non_sme_target : Error<
   "function executed in streaming-SVE mode requires 'sme'">;
 def err_sme_definition_using_za_in_non_sme_target : Error<
   "function using ZA state requires 'sme'">;
+def err_sme_definition_using_zt0_in_non_sme2_target : Error<
+  "function using ZT0 state requires 'sme2'">;
 def err_conflicting_attributes_arm_state : Error<
   "conflicting attributes for state '%0'">;
 def err_unknown_arm_state : Error<
diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index 

[clang] [Clang] Amend SME attributes with support for ZT0. (PR #77941)

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

https://github.com/sdesmalen-arm updated 
https://github.com/llvm/llvm-project/pull/77941

>From 764e7aaecffb758e7a311c17a189ee605c623246 Mon Sep 17 00:00:00 2001
From: Sander de Smalen 
Date: Thu, 4 Jan 2024 14:03:04 +
Subject: [PATCH] [Clang] Amend SME attributes with support for ZT0.

This patch builds on top of #76971 and implements support for:
* __arm_new("zt0")
* __arm_in("zt0")
* __arm_out("zt0")
* __arm_inout("zt0")
* __arm_preserves("zt0")

The patch is ready for review but won't be able to land until LLVM
implements support for handling ZT0 state.
---
 clang/include/clang/AST/Type.h| 15 +++--
 clang/include/clang/Basic/Attr.td |  3 +
 .../clang/Basic/DiagnosticSemaKinds.td|  4 ++
 clang/lib/AST/TypePrinter.cpp |  8 +++
 clang/lib/CodeGen/CGCall.cpp  | 10 
 clang/lib/CodeGen/CodeGenModule.cpp   |  2 +
 clang/lib/Sema/SemaChecking.cpp   | 22 +++
 clang/lib/Sema/SemaDecl.cpp   | 11 
 clang/lib/Sema/SemaDeclAttr.cpp   |  8 +++
 clang/lib/Sema/SemaType.cpp   |  3 +
 .../aarch64-sme2-attrs.cpp| 57 +++
 ...-sme-func-attrs-without-target-feature.cpp |  2 +
 clang/test/Sema/aarch64-sme-func-attrs.c  | 45 +++
 13 files changed, 186 insertions(+), 4 deletions(-)
 create mode 100644 
clang/test/CodeGen/aarch64-sme2-intrinsics/aarch64-sme2-attrs.cpp

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index a7efe78591635e0..a56401f9da0450b 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -4040,9 +4040,12 @@ class FunctionType : public Type {
 // Describes the value of the state using ArmStateValue.
 SME_ZAShift = 2,
 SME_ZAMask = 0b111 << SME_ZAShift,
+SME_ZT0Shift = 5,
+SME_ZT0Mask = 0b111 << SME_ZT0Shift,
 
-SME_AttributeMask = 0b111'111 // We only support maximum 6 bits because of
-  // the bitmask in FunctionTypeExtraBitfields.
+SME_AttributeMask =
+0b111'111'11 // We can't support more than 8 bits because of
+ // the bitmask in FunctionTypeExtraBitfields.
   };
 
   enum ArmStateValue : unsigned {
@@ -4057,6 +4060,10 @@ class FunctionType : public Type {
 return (ArmStateValue)((AttrBits & SME_ZAMask) >> SME_ZAShift);
   }
 
+  static ArmStateValue getArmZT0State(unsigned AttrBits) {
+return (ArmStateValue)((AttrBits & SME_ZT0Mask) >> SME_ZT0Shift);
+  }
+
   /// 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.
@@ -4068,7 +4075,7 @@ class FunctionType : public Type {
 
 /// Any AArch64 SME ACLE type attributes that need to be propagated
 /// on declarations and function pointers.
-unsigned AArch64SMEAttributes : 6;
+unsigned AArch64SMEAttributes : 8;
 FunctionTypeExtraBitfields()
 : NumExceptionType(0), AArch64SMEAttributes(SME_NormalFunction) {}
   };
@@ -4253,7 +4260,7 @@ class FunctionProtoType final
 FunctionType::ExtInfo ExtInfo;
 unsigned Variadic : 1;
 unsigned HasTrailingReturn : 1;
-unsigned AArch64SMEAttributes : 6;
+unsigned AArch64SMEAttributes : 8;
 Qualifiers TypeQuals;
 RefQualifierKind RefQualifier = RQ_None;
 ExceptionSpecInfo ExceptionSpec;
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index b9ec720dd9e199c..174d4e14bfa0ecb 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2549,6 +2549,9 @@ def ArmNew : InheritableAttr, 
TargetSpecificAttr {
 bool isNewZA() const {
   return llvm::is_contained(newArgs(), "za");
 }
+bool isNewZT0() const {
+  return llvm::is_contained(newArgs(), "zt0");
+}
   }];
 }
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c50b188a1039acb..cca4a4419d0bf94 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3696,10 +3696,14 @@ def err_sme_call_in_non_sme_target : Error<
   "call to a streaming function requires 'sme'">;
 def err_sme_za_call_no_za_state : Error<
   "call to a shared ZA function requires the caller to have ZA state">;
+def err_sme_zt0_call_no_zt0_state : Error<
+  "call to a shared ZT0 function requires the caller to have ZT0 state">;
 def err_sme_definition_using_sm_in_non_sme_target : Error<
   "function executed in streaming-SVE mode requires 'sme'">;
 def err_sme_definition_using_za_in_non_sme_target : Error<
   "function using ZA state requires 'sme'">;
+def err_sme_definition_using_zt0_in_non_sme2_target : Error<
+  "function using ZT0 state requires 'sme2'">;
 def err_conflicting_attributes_arm_state : Error<
   "conflicting attributes for state 

[clang] [Clang] Amend SME attributes with support for ZT0. (PR #77941)

2024-01-12 Thread via cfe-commits

rsandifo-arm wrote:

LGTM from a spec point of view, although it might be worth having some tests 
that have different ZA state from ZT0.  (But maybe not, since the code to 
handle ZA and ZT0 is mostly orthogonal.)

I won't approve because of the growth in `FunctionProtoType` — someone more 
qualified than me should sign off on that.

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


[clang] [Clang] Amend SME attributes with support for ZT0. (PR #77941)

2024-01-12 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 9803de0e8e3abbbc94a4265d5847db435897a384 
6b8d1c8cc772a14a820ab1fdcd6d368b0117d170 -- 
clang/test/CodeGen/aarch64-sme2-intrinsics/aarch64-sme2-attrs.cpp 
clang/include/clang/AST/Type.h clang/include/clang/Basic/AttributeCommonInfo.h 
clang/include/clang/Basic/TokenKinds.h clang/include/clang/Sema/Sema.h 
clang/lib/AST/TypePrinter.cpp clang/lib/CodeGen/CGCall.cpp 
clang/lib/CodeGen/CodeGenModule.cpp clang/lib/Parse/ParseDecl.cpp 
clang/lib/Parse/ParseDeclCXX.cpp clang/lib/Parse/ParseTentative.cpp 
clang/lib/Sema/SemaChecking.cpp clang/lib/Sema/SemaDecl.cpp 
clang/lib/Sema/SemaDeclAttr.cpp clang/lib/Sema/SemaDeclCXX.cpp 
clang/lib/Sema/SemaExpr.cpp clang/lib/Sema/SemaOverload.cpp 
clang/lib/Sema/SemaType.cpp clang/test/AST/ast-dump-sme-attributes.cpp 
clang/test/CodeGen/aarch64-sme-intrinsics/aarch64-sme-attrs.cpp 
clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_add-i32.c 
clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_add-i64.c 
clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ld1.c 
clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ld1_vnum.c 
clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c 
clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_mopa-za32.c 
clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_mopa-za64.c 
clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_mops-za32.c 
clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_mops-za64.c 
clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_read.c 
clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_st1.c 
clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_st1_vnum.c 
clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_state_funs.c 
clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_str.c 
clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_write.c 
clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_zero.c 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_add.c 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_bmop.c 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_fp_dots.c 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_int_dots.c 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_ldr_str_zt.c 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt.c 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt_x2.c 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti2_lane_zt_x4.c 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti4_lane_zt.c 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti4_lane_zt_x2.c 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_luti4_lane_zt_x4.c 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mla.c 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mlal.c 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mlall.c 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mls.c 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mlsl.c 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mop.c 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_read.c 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_sub.c 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_vdot.c 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_write.c 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_zero_zt.c 
clang/test/Modules/aarch64-sme-keywords.cppm 
clang/test/Parser/c2x-attribute-keywords.c 
clang/test/Parser/cxx0x-keyword-attributes.cpp 
clang/test/Sema/aarch64-incompat-sm-builtin-calls.c 
clang/test/Sema/aarch64-sme-func-attrs-without-target-feature.cpp 
clang/test/Sema/aarch64-sme-func-attrs.c 
clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp 
clang/test/Sema/aarch64-sme-intrinsics/acle_sme_target.c 
clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_imm.cpp 
clang/utils/TableGen/ClangAttrEmitter.cpp clang/utils/TableGen/SveEmitter.cpp 
clang/utils/TableGen/TableGen.cpp clang/utils/TableGen/TableGenBackends.h
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 64d4cde1c9..089704618c 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -7542,9 +7542,10 @@ void Sema::checkCall(NamedDecl *FDecl, const 
FunctionProtoType *Proto,
   CallerHasZT0State = true;
 else if (const auto *FPT =
  CallerFD->getType()->getAs())
-  CallerHasZT0State = FunctionType::getArmZT0State(
- FPT->getExtProtoInfo().AArch64SMEAttributes) 
!=
- FunctionType::ARM_None;
+  CallerHasZT0State =
+  FunctionType::getArmZT0State(
+  FPT->getExtProtoInfo().AArch64SMEAttributes) !=
+  FunctionType::ARM_None;
   }
 
   if (!CallerHasZT0State)

``