[llvm-branch-commits] [llvm] [clang] [compiler-rt] [builtins][arm64] Build __init_cpu_features_resolver on Apple platforms (PR #73685)

2023-12-01 Thread Jon Roelofs via llvm-branch-commits

https://github.com/jroelofs updated 
https://github.com/llvm/llvm-project/pull/73685

>From 603983e237e73b2d939bf9ee12e39ecc7983f7f1 Mon Sep 17 00:00:00 2001
From: Jon Roelofs 
Date: Wed, 29 Nov 2023 14:21:54 -0800
Subject: [PATCH] add a note about the dispatch_once block

Created using spr 1.3.4
---
 compiler-rt/lib/builtins/cpu_model.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/compiler-rt/lib/builtins/cpu_model.c 
b/compiler-rt/lib/builtins/cpu_model.c
index 5f5182859080c49..001467a9f7ff511 100644
--- a/compiler-rt/lib/builtins/cpu_model.c
+++ b/compiler-rt/lib/builtins/cpu_model.c
@@ -1285,6 +1285,14 @@ static bool isKnownAndSupported(const char *name) {
 }
 
 void __init_cpu_features_resolver(void) {
+  // On Darwin platforms, this may be called concurrently by multiple threads
+  // because the resolvers that use it are called lazily at runtime (unlike on
+  // ELF platforms, where IFuncs are resolved serially at load time).  This
+  // function's effect on __aarch64_cpu_features should be idempotent, but even
+  // so we need dispatch_once to resolve the race condition.  Dispatch is
+  // available through libSystem, which we need anyway for the sysctl, so this
+  // does not add a new dependency.
+
   static dispatch_once_t onceToken = 0;
   dispatch_once(, ^{
 // 
https://developer.apple.com/documentation/kernel/1387446-sysctlbyname/determining_instruction_set_characteristics

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [clang] [compiler-rt] [builtins][arm64] Build __init_cpu_features_resolver on Apple platforms (PR #73685)

2023-12-01 Thread Jon Roelofs via llvm-branch-commits

https://github.com/jroelofs updated 
https://github.com/llvm/llvm-project/pull/73685

>From 603983e237e73b2d939bf9ee12e39ecc7983f7f1 Mon Sep 17 00:00:00 2001
From: Jon Roelofs 
Date: Wed, 29 Nov 2023 14:21:54 -0800
Subject: [PATCH] add a note about the dispatch_once block

Created using spr 1.3.4
---
 compiler-rt/lib/builtins/cpu_model.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/compiler-rt/lib/builtins/cpu_model.c 
b/compiler-rt/lib/builtins/cpu_model.c
index 5f5182859080c49..001467a9f7ff511 100644
--- a/compiler-rt/lib/builtins/cpu_model.c
+++ b/compiler-rt/lib/builtins/cpu_model.c
@@ -1285,6 +1285,14 @@ static bool isKnownAndSupported(const char *name) {
 }
 
 void __init_cpu_features_resolver(void) {
+  // On Darwin platforms, this may be called concurrently by multiple threads
+  // because the resolvers that use it are called lazily at runtime (unlike on
+  // ELF platforms, where IFuncs are resolved serially at load time).  This
+  // function's effect on __aarch64_cpu_features should be idempotent, but even
+  // so we need dispatch_once to resolve the race condition.  Dispatch is
+  // available through libSystem, which we need anyway for the sysctl, so this
+  // does not add a new dependency.
+
   static dispatch_once_t onceToken = 0;
   dispatch_once(, ^{
 // 
https://developer.apple.com/documentation/kernel/1387446-sysctlbyname/determining_instruction_set_characteristics

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [clang] [compiler-rt] [builtins][arm64] Build __init_cpu_features_resolver on Apple platforms (PR #73685)

2023-11-29 Thread Fangrui Song via llvm-branch-commits

https://github.com/MaskRay edited 
https://github.com/llvm/llvm-project/pull/73685
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [clang] [compiler-rt] [builtins][arm64] Build __init_cpu_features_resolver on Apple platforms (PR #73685)

2023-11-29 Thread Fangrui Song via llvm-branch-commits


@@ -1259,6 +1270,64 @@ struct {
   // As features grows new fields could be added
 } __aarch64_cpu_features __attribute__((visibility("hidden"), nocommon));
 
+#if defined(__APPLE__)
+#include 
+#if TARGET_OS_OSX || TARGET_OS_IPHONE
+#include 
+#include 
+
+static bool isKnownAndSupported(const char *name) {
+  int32_t val = 0;
+  size_t size = sizeof(val);
+  if (sysctlbyname(name, , , NULL, 0))
+return false;
+  return val;
+}
+
+void __init_cpu_features_resolver(void) {
+  static dispatch_once_t onceToken = 0;
+  dispatch_once(, ^{

MaskRay wrote:

I am not familiar with blocks. Does this introduce any dependency on libcalls? 
Can this reuse `if (__aarch64_cpu_features.features)` used by ELF?

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


[llvm-branch-commits] [llvm] [clang] [compiler-rt] [builtins][arm64] Build __init_cpu_features_resolver on Apple platforms (PR #73685)

2023-11-29 Thread Jon Roelofs via llvm-branch-commits

jroelofs wrote:

This is part of a patch series:
* #73686
* #73688
* #73687
* #73685

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


[llvm-branch-commits] [llvm] [clang] [compiler-rt] [builtins][arm64] Build __init_cpu_features_resolver on Apple platforms (PR #73685)

2023-11-29 Thread Jon Roelofs via llvm-branch-commits

https://github.com/jroelofs updated 
https://github.com/llvm/llvm-project/pull/73685


___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [clang] [compiler-rt] [builtins][arm64] Build __init_cpu_features_resolver on Apple platforms (PR #73685)

2023-11-28 Thread Jon Roelofs via llvm-branch-commits


@@ -556,6 +556,8 @@ void X86AsmPrinter::emitGlobalIFunc(Module , const 
GlobalIFunc ) {
   JMP.setOpcode(X86::JMP_4);
   JMP.addOperand(MCOperand::createExpr(lowerConstant(GI.getResolver(;
   OutStreamer->emitInstruction(JMP, *Subtarget);
+
+  // FIXME: do the manual .symbol_resolver lowering that we did in 
AArch64AsmPrinter.

jroelofs wrote:

- [ ] FIXME: This comment belongs in a different commit in the patch stack.

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


[llvm-branch-commits] [llvm] [clang] [compiler-rt] [builtins][arm64] Build __init_cpu_features_resolver on Apple platforms (PR #73685)

2023-11-28 Thread via llvm-branch-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 802e1c6b0b6e343d97a2549d05e0cb33dec09363 
24f8f639f9fb654838b78d8f14a06805e4772628 -- 
compiler-rt/lib/builtins/cpu_model.c llvm/lib/Target/X86/X86AsmPrinter.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/lib/Target/X86/X86AsmPrinter.cpp 
b/llvm/lib/Target/X86/X86AsmPrinter.cpp
index 37158900d2..e7a242d029 100644
--- a/llvm/lib/Target/X86/X86AsmPrinter.cpp
+++ b/llvm/lib/Target/X86/X86AsmPrinter.cpp
@@ -557,7 +557,8 @@ void X86AsmPrinter::emitGlobalIFunc(Module , const 
GlobalIFunc ) {
   JMP.addOperand(MCOperand::createExpr(lowerConstant(GI.getResolver(;
   OutStreamer->emitInstruction(JMP, *Subtarget);
 
-  // FIXME: do the manual .symbol_resolver lowering that we did in 
AArch64AsmPrinter.
+  // FIXME: do the manual .symbol_resolver lowering that we did in
+  // AArch64AsmPrinter.
 }
 
 static bool printAsmMRegister(const X86AsmPrinter , const MachineOperand ,

``




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