llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-aarch64

Author: Louis Dionne (ldionne)

<details>
<summary>Changes</summary>

Apple arm64 cores use a 128-byte cache line, as reported by `sysctl -a`. 
However, Clang inherited the generic AArch64 value and was setting 
`__GCC_DESTRUCTIVE_SIZE` to  256 for Apple targets (see bce2cc15133a). While 
the value of 256 matches what GCC uses and is what's documented by ARM, 128 
seems to be a better value for Apple arm64 specifically, with 256 simply being 
wasteful.

Note that changing this value should in principle not be an issue since it (and 
constructive interference) are explicitly documented as being "ABI unstable" 
values, in the sense that users should not rely on them being stable.

Fixes #<!-- -->182951

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


4 Files Affected:

- (modified) clang/docs/ReleaseNotes.md (+6-1) 
- (modified) clang/lib/Basic/Targets/AArch64.h (+13) 
- (modified) clang/test/Preprocessor/init-aarch64.c (+2) 
- (modified) clang/test/Preprocessor/init.c (+2) 


``````````diff
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index b49a9db3d5fca..778e6c8b4cd6d 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -974,6 +974,11 @@ latest release, please see the [Clang Web 
Site](https://clang.llvm.org) or the
 
 #### Arm and AArch64 Support
 
+- On Apple AArch64 targets, `__GCC_DESTRUCTIVE_SIZE` is now `128` (down from 
`256`)
+  to match the 128-byte cache line used by Apple cores, avoiding needless
+  over-alignment. This value is implementation-defined and should not be 
relied upon
+  in an ABI-sensitive way.
+
 - Support has been added for the following processors (-mcpu identifiers in 
parenthesis):
 
   - Arm AGI CPU (armagicpu).
@@ -1119,7 +1124,7 @@ latest release, please see the [Clang Web 
Site](https://clang.llvm.org) or the
 
 - Fixed a crash in code completion when using a C-Style cast with a 
parenthesized
   operand in Objective-C++ mode. (#GH180125)
-- Fixed a crash when code completion is triggered inside an ill-formed 
lambda's trailing requires-clause. (#GH201632)  
+- Fixed a crash when code completion is triggered inside an ill-formed 
lambda's trailing requires-clause. (#GH201632)
 
 ### Static Analyzer
 
diff --git a/clang/lib/Basic/Targets/AArch64.h 
b/clang/lib/Basic/Targets/AArch64.h
index d619e24d82cb2..b6e707d8b4245 100644
--- a/clang/lib/Basic/Targets/AArch64.h
+++ b/clang/lib/Basic/Targets/AArch64.h
@@ -358,6 +358,12 @@ class LLVM_LIBRARY_VISIBILITY AppleMachOAArch64TargetInfo
   AppleMachOAArch64TargetInfo(const llvm::Triple &Triple,
                               const TargetOptions &Opts);
 
+  std::pair<unsigned, unsigned> hardwareInterferenceSizes() const override {
+    // Apple AArch64 cores use a 128-byte cache line, unlike the ARM-documented
+    // value of 256 used by the generic aarch64 triple.
+    return std::make_pair(128, 64);
+  }
+
 protected:
   void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
                     MacroBuilder &Builder) const override;
@@ -370,6 +376,13 @@ class LLVM_LIBRARY_VISIBILITY DarwinAArch64TargetInfo
 
   BuiltinVaListKind getBuiltinVaListKind() const override;
 
+  std::pair<unsigned, unsigned> hardwareInterferenceSizes() const override {
+    // Apple AArch64 cores use a 128-byte cache line, so 128 (not the generic
+    // AArch64 value of 256) is the right destructive interference size. These
+    // values are implementation-defined and not part of the ABI.
+    return std::make_pair(128, 64);
+  }
+
  protected:
   void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
                     MacroBuilder &Builder) const override;
diff --git a/clang/test/Preprocessor/init-aarch64.c 
b/clang/test/Preprocessor/init-aarch64.c
index 09e3fc926a309..c817a95c82c79 100644
--- a/clang/test/Preprocessor/init-aarch64.c
+++ b/clang/test/Preprocessor/init-aarch64.c
@@ -447,6 +447,8 @@
 // AARCH64-DARWIN: #define __FLT_MIN__ 1.17549435e-38F
 // AARCH64-DARWIN: #define __FLT_RADIX__ 2
 // AARCH64-DARWIN: #define __FUNCTION_MULTI_VERSIONING_SUPPORT_LEVEL 202430
+// AARCH64-DARWIN: #define __GCC_CONSTRUCTIVE_SIZE 64
+// AARCH64-DARWIN: #define __GCC_DESTRUCTIVE_SIZE 128
 // AARCH64-DARWIN: #define __INT16_C(c) c
 // AARCH64-DARWIN: #define __INT16_C_SUFFIX__
 // AARCH64-DARWIN: #define __INT16_FMTd__ "hd"
diff --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c
index ef7b76a29a1f5..c768d20dc0fd9 100644
--- a/clang/test/Preprocessor/init.c
+++ b/clang/test/Preprocessor/init.c
@@ -2422,6 +2422,8 @@
 // ARM-DARWIN-BAREMETAL-32: #define __PTRDIFF_TYPE__ int
 // ARM-DARWIN-BAREMETAL-32: #define __SIZE_TYPE__ long unsigned int
 
+// ARM-DARWIN-BAREMETAL-64: #define __GCC_CONSTRUCTIVE_SIZE 64
+// ARM-DARWIN-BAREMETAL-64: #define __GCC_DESTRUCTIVE_SIZE 128
 // ARM-DARWIN-BAREMETAL-64: #define __INTPTR_TYPE__ long int
 // ARM-DARWIN-BAREMETAL-64: #define __PTRDIFF_TYPE__ long int
 // ARM-DARWIN-BAREMETAL-64: #define __SIZE_TYPE__ long unsigned int

``````````

</details>


https://github.com/llvm/llvm-project/pull/208716
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to