70 lines · c
1//===-- Portable attributes -------------------------------------*- 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-exception6//7//===----------------------------------------------------------------------===//8// This header file defines a set of macros for checking the presence of9// important compiler and platform features. Such macros can be used to10// produce portable code by parameterizing compilation based on the presence or11// lack of a given feature.12 13#ifndef LLVM_LIBC_SRC___SUPPORT_MACROS_CONFIG_H14#define LLVM_LIBC_SRC___SUPPORT_MACROS_CONFIG_H15 16#include "src/__support/macros/properties/architectures.h"17#include "src/__support/macros/properties/compiler.h"18 19#ifdef LIBC_COMPILER_IS_MSVC20#include <intrin.h>21#endif // LIBC_COMPILER_IS_MSVC22 23// Workaround for compilers that do not support builtin detection.24// FIXME: This is only required for the GPU portion which should be moved.25#ifndef __has_builtin26#define __has_builtin(b) 027#endif28 29// Compiler feature-detection.30// clang.llvm.org/docs/LanguageExtensions.html#has-feature-and-has-extension31#ifdef __has_feature32#define LIBC_HAS_FEATURE(f) __has_feature(f)33#else34#define LIBC_HAS_FEATURE(f) 035#endif36 37#ifdef LIBC_COMPILER_IS_MSVC38 39// __builtin_trap replacement40#ifdef LIBC_TARGET_ARCH_IS_X8641#define __builtin_trap __ud242#else // arm6443#define __builtin_trap() __break(1)44#endif45 46#define __builtin_expect(value, expectation) (value)47#define __builtin_unreachable() __assume(0)48 49#define __builtin_prefetch(X, Y, Z)50 51#endif // LIBC_COMPILER_IS_MSVC52 53#ifdef __clang__54// Declare a LIBC_NAMESPACE with hidden visibility. `namespace55// LIBC_NAMESPACE_DECL {` should be used around all declarations and definitions56// for libc internals as opposed to just `namespace LIBC_NAMESPACE {`. This57// ensures that all declarations within this namespace have hidden58// visibility, which optimizes codegen for uses of symbols defined in other59// translation units in ways that can be necessary for correctness by avoiding60// dynamic relocations. This does not affect the public C symbols which are61// controlled independently via `LLVM_LIBC_FUNCTION_ATTR`.62#define LIBC_NAMESPACE_DECL [[gnu::visibility("hidden")]] LIBC_NAMESPACE63#else64// TODO(#98548): GCC emits a warning when using the visibility attribute which65// needs to be diagnosed and addressed.66#define LIBC_NAMESPACE_DECL LIBC_NAMESPACE67#endif68 69#endif // LLVM_LIBC_SRC___SUPPORT_MACROS_CONFIG_H70