| 1 | //===-- cpu_model_common.c - Utilities for cpu model detection ----*- C -*-===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file implements common utilities for runtime cpu model detection. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #ifndef COMPILER_RT_LIB_BUILTINS_CPU_MODEL_COMMON_H |
| 14 | #define COMPILER_RT_LIB_BUILTINS_CPU_MODEL_COMMON_H |
| 15 | |
| 16 | #define bool int |
| 17 | #define true 1 |
| 18 | #define false 0 |
| 19 | |
| 20 | #ifndef __has_attribute |
| 21 | #define __has_attribute(attr) 0 |
| 22 | #endif |
| 23 | |
| 24 | #if __has_attribute(constructor) |
| 25 | #if __GNUC__ >= 9 |
| 26 | // Ordinarily init priorities below 101 are disallowed as they are reserved for |
| 27 | // the implementation. However, we are the implementation, so silence the |
| 28 | // diagnostic, since it doesn't apply to us. |
| 29 | #pragma GCC diagnostic ignored "-Wprio-ctor-dtor" |
| 30 | #endif |
| 31 | // We're choosing init priority 90 to force our constructors to run before any |
| 32 | // constructors in the end user application (starting at priority 101). This |
| 33 | // value matches the libgcc choice for the same functions. |
| 34 | #ifdef _WIN32 |
| 35 | // Contructor that replaces the ifunc runs currently with prio 10, see |
| 36 | // the LowerIFuncPass. The resolver of FMV depends on the cpu features so set |
| 37 | // the priority to 9. |
| 38 | #define CONSTRUCTOR_PRIORITY 9 |
| 39 | #else |
| 40 | #define CONSTRUCTOR_PRIORITY 90 |
| 41 | #endif |
| 42 | #define CONSTRUCTOR_ATTRIBUTE __attribute__((constructor(CONSTRUCTOR_PRIORITY))) |
| 43 | #else |
| 44 | // FIXME: For MSVC, we should make a function pointer global in .CRT$X?? so that |
| 45 | // this runs during initialization. |
| 46 | #define CONSTRUCTOR_ATTRIBUTE |
| 47 | #endif |
| 48 | |
| 49 | #endif |
| 50 | |