[compiler-rt] [builtins] Refactor cpu_model support to reduce #if nesting. NFCI (PR #75635)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 15 10:16:30 PST 2023
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff 82e91b91ca0ceab5ee977295540643ce67153f89 336d1629f38a8681038f026c599a256761b522dc -- compiler-rt/lib/builtins/cpu_model/aarch64.c compiler-rt/lib/builtins/cpu_model/aarch64/fmv/android.inc compiler-rt/lib/builtins/cpu_model/aarch64/fmv/freebsd.inc compiler-rt/lib/builtins/cpu_model/aarch64/fmv/fucsia.inc compiler-rt/lib/builtins/cpu_model/aarch64/fmv/mrs.inc compiler-rt/lib/builtins/cpu_model/aarch64/fmv/sysauxv.inc compiler-rt/lib/builtins/cpu_model/aarch64/fmv/unimplemented.inc compiler-rt/lib/builtins/cpu_model/aarch64/lse_atomics/android.inc compiler-rt/lib/builtins/cpu_model/aarch64/lse_atomics/freebsd.inc compiler-rt/lib/builtins/cpu_model/aarch64/lse_atomics/fucsia.inc compiler-rt/lib/builtins/cpu_model/aarch64/lse_atomics/sysauxv.inc compiler-rt/lib/builtins/cpu_model/cpu_model.h compiler-rt/lib/builtins/cpu_model/x86.c
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/compiler-rt/lib/builtins/cpu_model/aarch64.c b/compiler-rt/lib/builtins/cpu_model/aarch64.c
index 98b0c4433d..dda25e16f4 100644
--- a/compiler-rt/lib/builtins/cpu_model/aarch64.c
+++ b/compiler-rt/lib/builtins/cpu_model/aarch64.c
@@ -7,17 +7,17 @@
//===----------------------------------------------------------------------===//
//
// This file is based on LLVM's lib/Support/Host.cpp.
-// It implements __aarch64_have_lse_atomics, __aarch64_cpu_features for AArch64.
+// It implements __aarch64_have_lse_atomics, __aarch64_cpu_features for
+// AArch64.
//
//===----------------------------------------------------------------------===//
#include "cpu_model.h"
#if !defined(__aarch64__)
-# error This file is intended only for aarch64-based targets
+#error This file is intended only for aarch64-based targets
#endif
-
#if __has_include(<sys/ifunc.h>)
#include <sys/ifunc.h>
#else
@@ -28,25 +28,23 @@ typedef struct __ifunc_arg_t {
} __ifunc_arg_t;
#endif // __has_include(<sys/ifunc.h>)
-
// LSE support detection for out-of-line atomics
// using HWCAP and Auxiliary vector
_Bool __aarch64_have_lse_atomics
__attribute__((visibility("hidden"), nocommon)) = false;
#if defined(__FreeBSD__)
-# include "lse_atomics/freebsd.inc"
+#include "lse_atomics/freebsd.inc"
#elif defined(__Fucsia__)
-# include "lse_atomics/fucsia.inc"
+#include "lse_atomics/fucsia.inc"
#elif defined(__ANDROID__)
-# include "lse_atomics/android.inc"
+#include "lse_atomics/android.inc"
#elif __has_include(<sys/auxv.h>)
-# include "lse_atomics/sysauxv.inc"
+#include "lse_atomics/sysauxv.inc"
#else
// When unimplemented, we leave __aarch64_have_lse_atomics initialized to false.
#endif
-
#if !defined(DISABLE_AARCH64_FMV)
// CPUFeatures must correspond to the same AArch64 features in
// AArch64TargetParser.h
@@ -124,19 +122,19 @@ struct {
} __aarch64_cpu_features __attribute__((visibility("hidden"), nocommon));
#if defined(__FreeBSD__)
-# include "aarch64/fmv/mrs.inc"
-# include "aarch64/fmv/freebsd.inc"
+#include "aarch64/fmv/freebsd.inc"
+#include "aarch64/fmv/mrs.inc"
#elif defined(__Fucsia__)
-# include "aarch64/fmv/mrs.inc"
-# include "aarch64/fmv/fucsia.inc"
+#include "aarch64/fmv/fucsia.inc"
+#include "aarch64/fmv/mrs.inc"
#elif defined(__ANDROID__)
-# include "aarch64/fmv/mrs.inc"
-# include "aarch64/fmv/android.inc"
+#include "aarch64/fmv/android.inc"
+#include "aarch64/fmv/mrs.inc"
#elif __has_include(<sys/auxv.h>)
-# include "aarch64/fmv/mrs.inc"
-# include "aarch64/fmv/sysauxv.inc"
+#include "aarch64/fmv/mrs.inc"
+#include "aarch64/fmv/sysauxv.inc"
#else
-# include "aarch64/fmv/unimplemented.inc"
+#include "aarch64/fmv/unimplemented.inc"
#endif
#endif // !defined(DISABLE_AARCH64_FMV)
\ No newline at end of file
diff --git a/compiler-rt/lib/builtins/cpu_model/aarch64/fmv/mrs.inc b/compiler-rt/lib/builtins/cpu_model/aarch64/fmv/mrs.inc
index 2759900226..282bda1156 100644
--- a/compiler-rt/lib/builtins/cpu_model/aarch64/fmv/mrs.inc
+++ b/compiler-rt/lib/builtins/cpu_model/aarch64/fmv/mrs.inc
@@ -1,11 +1,11 @@
#if __has_include(<sys/auxv.h>)
-# include <sys/auxv.h>
-# define HAVE_SYS_AUXV_H
+#include <sys/auxv.h>
+#define HAVE_SYS_AUXV_H
#endif
#if __has_include(<sys/hwcap.h>)
-# include <sys/hwcap.h>
-# define HAVE_SYS_HWCAP_H
+#include <sys/hwcap.h>
+#define HAVE_SYS_HWCAP_H
#endif
#ifndef _IFUNC_ARG_HWCAP
diff --git a/compiler-rt/lib/builtins/cpu_model/aarch64/fmv/unimplemented.inc b/compiler-rt/lib/builtins/cpu_model/aarch64/fmv/unimplemented.inc
index 394c400849..dc34624807 100644
--- a/compiler-rt/lib/builtins/cpu_model/aarch64/fmv/unimplemented.inc
+++ b/compiler-rt/lib/builtins/cpu_model/aarch64/fmv/unimplemented.inc
@@ -1,11 +1,8 @@
// On platforms that have not implemented this yet, we provide an implementation
// that does not claim support for any features by leaving
-// __aarch64_cpu_features.features initialized to 0.
+// __aarch64_cpu_features.features initialized to 0.
void __init_cpu_features_resolver(unsigned long hwcap,
- const __ifunc_arg_t *arg) {
-}
+ const __ifunc_arg_t *arg) {}
-void __init_cpu_features(void) {
-
-}
+void __init_cpu_features(void) {}
diff --git a/compiler-rt/lib/builtins/cpu_model/cpu_model.h b/compiler-rt/lib/builtins/cpu_model/cpu_model.h
index e4b728c731..e80e07bed4 100644
--- a/compiler-rt/lib/builtins/cpu_model/cpu_model.h
+++ b/compiler-rt/lib/builtins/cpu_model/cpu_model.h
@@ -23,14 +23,14 @@
#if __has_attribute(constructor)
#if __GNUC__ >= 9
-// Ordinarily init priorities below 101 are disallowed as they are reserved for the
-// implementation. However, we are the implementation, so silence the diagnostic,
-// since it doesn't apply to us.
+// Ordinarily init priorities below 101 are disallowed as they are reserved for
+// the implementation. However, we are the implementation, so silence the
+// diagnostic, since it doesn't apply to us.
#pragma GCC diagnostic ignored "-Wprio-ctor-dtor"
#endif
// We're choosing init priority 90 to force our constructors to run before any
-// constructors in the end user application (starting at priority 101). This value
-// matches the libgcc choice for the same functions.
+// constructors in the end user application (starting at priority 101). This
+// value matches the libgcc choice for the same functions.
#define CONSTRUCTOR_ATTRIBUTE __attribute__((constructor(90)))
#else
// FIXME: For MSVC, we should make a function pointer global in .CRT$X?? so that
diff --git a/compiler-rt/lib/builtins/cpu_model/x86.c b/compiler-rt/lib/builtins/cpu_model/x86.c
index 4a08a6d1ac..fad02767c5 100644
--- a/compiler-rt/lib/builtins/cpu_model/x86.c
+++ b/compiler-rt/lib/builtins/cpu_model/x86.c
@@ -15,16 +15,14 @@
#include "cpu_model.h"
#if !(defined(__i386__) || defined(_M_IX86) || defined(__x86_64__) || \
- defined(_M_X64))
-# error This file is intended only for x86-based targets
+ defined(_M_X64))
+#error This file is intended only for x86-based targets
#endif
#if defined(__GNUC__) || defined(__clang__) || defined(_MSC_VER)
#include <assert.h>
-
-
#ifdef _MSC_VER
#include <intrin.h>
#endif
@@ -300,12 +298,12 @@ static void detectX86FamilyModel(unsigned EAX, unsigned *Family,
}
}
-static const char *
-getIntelProcessorTypeAndSubtype(unsigned Family, unsigned Model,
- const unsigned *Features,
- unsigned *Type, unsigned *Subtype) {
-#define testFeature(F) \
- (Features[F / 32] & (1 << (F % 32))) != 0
+static const char *getIntelProcessorTypeAndSubtype(unsigned Family,
+ unsigned Model,
+ const unsigned *Features,
+ unsigned *Type,
+ unsigned *Subtype) {
+#define testFeature(F) (Features[F / 32] & (1 << (F % 32))) != 0
// We select CPU strings to match the code in Host.cpp, but we don't use them
// in compiler-rt.
@@ -338,7 +336,7 @@ getIntelProcessorTypeAndSubtype(unsigned Family, unsigned Model,
case 0x1e: // Intel(R) Core(TM) i7 CPU 870 @ 2.93GHz.
// As found in a Summer 2010 model iMac.
case 0x1f:
- case 0x2e: // Nehalem EX
+ case 0x2e: // Nehalem EX
CPU = "nehalem";
*Type = INTEL_COREI7;
*Subtype = INTEL_COREI7_NEHALEM;
@@ -359,7 +357,7 @@ getIntelProcessorTypeAndSubtype(unsigned Family, unsigned Model,
*Subtype = INTEL_COREI7_SANDYBRIDGE;
break;
case 0x3a:
- case 0x3e: // Ivy Bridge EP
+ case 0x3e: // Ivy Bridge EP
CPU = "ivybridge";
*Type = INTEL_COREI7;
*Subtype = INTEL_COREI7_IVYBRIDGE;
@@ -386,12 +384,12 @@ getIntelProcessorTypeAndSubtype(unsigned Family, unsigned Model,
break;
// Skylake:
- case 0x4e: // Skylake mobile
- case 0x5e: // Skylake desktop
- case 0x8e: // Kaby Lake mobile
- case 0x9e: // Kaby Lake desktop
- case 0xa5: // Comet Lake-H/S
- case 0xa6: // Comet Lake-U
+ case 0x4e: // Skylake mobile
+ case 0x5e: // Skylake desktop
+ case 0x8e: // Kaby Lake mobile
+ case 0x9e: // Kaby Lake desktop
+ case 0xa5: // Comet Lake-H/S
+ case 0xa6: // Comet Lake-U
CPU = "skylake";
*Type = INTEL_COREI7;
*Subtype = INTEL_COREI7_SKYLAKE;
@@ -590,10 +588,11 @@ getIntelProcessorTypeAndSubtype(unsigned Family, unsigned Model,
return CPU;
}
-static const char *
-getAMDProcessorTypeAndSubtype(unsigned Family, unsigned Model,
- const unsigned *Features,
- unsigned *Type, unsigned *Subtype) {
+static const char *getAMDProcessorTypeAndSubtype(unsigned Family,
+ unsigned Model,
+ const unsigned *Features,
+ unsigned *Type,
+ unsigned *Subtype) {
// We select CPU strings to match the code in Host.cpp, but we don't use them
// in compiler-rt.
const char *CPU = 0;
@@ -670,10 +669,8 @@ getAMDProcessorTypeAndSubtype(unsigned Family, unsigned Model,
*Subtype = AMDFAM19H_ZNVER3;
break;
}
- if ((Model >= 0x10 && Model <= 0x1f) ||
- (Model >= 0x60 && Model <= 0x74) ||
- (Model >= 0x78 && Model <= 0x7b) ||
- (Model >= 0xA0 && Model <= 0xAf)) {
+ if ((Model >= 0x10 && Model <= 0x1f) || (Model >= 0x60 && Model <= 0x74) ||
+ (Model >= 0x78 && Model <= 0x7b) || (Model >= 0xA0 && Model <= 0xAf)) {
CPU = "znver4";
*Subtype = AMDFAM19H_ZNVER4;
break; // "znver4"
@@ -691,8 +688,7 @@ static void getAvailableFeatures(unsigned ECX, unsigned EDX, unsigned MaxLeaf,
unsigned EAX = 0, EBX = 0;
#define hasFeature(F) ((Features[F / 32] >> (F % 32)) & 1)
-#define setFeature(F) \
- Features[F / 32] |= 1U << (F % 32)
+#define setFeature(F) Features[F / 32] |= 1U << (F % 32)
if ((EDX >> 15) & 1)
setFeature(FEATURE_CMOV);
``````````
</details>
https://github.com/llvm/llvm-project/pull/75635
More information about the llvm-commits
mailing list