This implements the __builtin_cpu_init and __builtin_cpu_supports builtin routines based on the compiler runtime changes in https://github.com/llvm/llvm-project/pull/85790. This is inspired by https://github.com/llvm/llvm-project/pull/85786. Major changes are a) a restriction in scope to only the builtins (which have a much narrower user interface), and the avoidance of false generality. This change deliberately only handles group 0 extensions (which happen to be all defined ones today), and avoids the tblgen changes from that review. I don't have an environment in which I can actually test this, but @BeMg has been kind enough to report that this appears to work as expected. Before this can make it into a release, we need a change such as https://github.com/llvm/llvm-project/pull/99958. The gcc docs claim that cpu_support can be called by "normal" code without calling the cpu_init routine because the init routine will have been called by a high priority constructor. Our current compiler-rt mechanism does not do this.
31 lines
986 B
C
31 lines
986 B
C
// RUN: %clang_cc1 -fsyntax-only -triple arm64-- -DARM -verify %s
|
|
// RUN: %clang_cc1 -fsyntax-only -triple x86_64-- -DX86 -verify %s
|
|
// RUN: %clang_cc1 -fsyntax-only -triple powerpc64-unknown-linux-gnu -DPPC \
|
|
// RUN: -verify %s
|
|
// RUN: %clang_cc1 -fsyntax-only -triple riscv32-unknown-linux-gnu -DRISCV \
|
|
// RUN: -verify %s
|
|
// RUN: %clang_cc1 -fsyntax-only -triple riscv64-unknown-linux-gnu -DRISCV \
|
|
// RUN: -verify %s
|
|
// expected-no-diagnostics
|
|
#if __has_builtin(__builtin_cpu_is)
|
|
# if defined(ARM) || defined(RISCV)
|
|
# error "ARM/RISCV shouldn't have __builtin_cpu_is"
|
|
# endif
|
|
#endif
|
|
|
|
#if __has_builtin(__builtin_cpu_init)
|
|
# if defined(ARM) || defined(PPC)
|
|
# error "ARM/PPC shouldn't have __builtin_cpu_init"
|
|
# endif
|
|
#else
|
|
# ifdef RISCV
|
|
# error "RISCV should have __builtin_cpu_init"
|
|
# endif
|
|
#endif
|
|
|
|
#if !__has_builtin(__builtin_cpu_supports)
|
|
# if defined(ARM) || defined(X86) || defined(RISCV)
|
|
# error "ARM/X86/RISCV should have __builtin_cpu_supports"
|
|
# endif
|
|
#endif
|