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-exception
6//
7//===----------------------------------------------------------------------===//
8// This header file defines macros for declaring attributes for functions,
9// types, and variables.
10//
11// These macros are used within llvm-libc and allow the compiler to optimize,
12// where applicable, certain function calls.
13//
14// Most macros here are exposing GCC or Clang features, and are stubbed out for
15// other compilers.
16
17#ifndef LLVM_LIBC_SRC___SUPPORT_MACROS_ATTRIBUTES_H
18#define LLVM_LIBC_SRC___SUPPORT_MACROS_ATTRIBUTES_H
19
20#include "properties/architectures.h"
21
22#ifndef __has_attribute
23#define __has_attribute(x) 0
24#endif
25
26#define LIBC_INLINE inline
27#define LIBC_INLINE_VAR inline
28#define LIBC_INLINE_ASM __asm__ __volatile__
29#define LIBC_UNUSED __attribute__((unused))
30
31#ifdef LIBC_TARGET_ARCH_IS_GPU
32#define LIBC_THREAD_LOCAL
33#else
34#define LIBC_THREAD_LOCAL thread_local
35#endif
36
37#if __cplusplus >= 202002L
38#define LIBC_CONSTINIT constinit
39#elif __has_attribute(__require_constant_initialization__)
40#define LIBC_CONSTINIT __attribute__((__require_constant_initialization__))
41#else
42#define LIBC_CONSTINIT
43#endif
44
45#if defined(__clang__) && __has_attribute(preferred_type)
46#define LIBC_PREFERED_TYPE(TYPE) [[clang::preferred_type(TYPE)]]
47#else
48#define LIBC_PREFERED_TYPE(TYPE)
49#endif
50
51#endif // LLVM_LIBC_SRC___SUPPORT_MACROS_ATTRIBUTES_H
52