Path: blob/main/contrib/llvm-project/compiler-rt/lib/orc/compiler.h
39566 views
//===--------- compiler.h - Compiler abstraction support --------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file is a part of the ORC runtime support library.9//10// Most functionality in this file was swiped from llvm/Support/Compiler.h.11//12//===----------------------------------------------------------------------===//1314#ifndef ORC_RT_COMPILER_H15#define ORC_RT_COMPILER_H1617#if defined(_WIN32)18#define ORC_RT_INTERFACE extern "C"19#define ORC_RT_HIDDEN20#define ORC_RT_IMPORT extern "C" __declspec(dllimport)21#else22#define ORC_RT_INTERFACE extern "C" __attribute__((visibility("default")))23#define ORC_RT_HIDDEN __attribute__((visibility("hidden")))24#define ORC_RT_IMPORT extern "C"25#endif2627#ifndef __has_builtin28# define __has_builtin(x) 029#endif3031// Only use __has_cpp_attribute in C++ mode. GCC defines __has_cpp_attribute in32// C mode, but the :: in __has_cpp_attribute(scoped::attribute) is invalid.33#ifndef ORC_RT_HAS_CPP_ATTRIBUTE34#if defined(__cplusplus) && defined(__has_cpp_attribute)35#define ORC_RT_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)36#else37#define ORC_RT_HAS_CPP_ATTRIBUTE(x) 038#endif39#endif4041// Use the 'nodiscard' attribute in C++17 or newer mode.42#if defined(__cplusplus) && __cplusplus > 201402L && \43ORC_RT_HAS_CPP_ATTRIBUTE(nodiscard)44#define ORC_RT_NODISCARD [[nodiscard]]45#elif ORC_RT_HAS_CPP_ATTRIBUTE(clang::warn_unused_result)46#define ORC_RT_NODISCARD [[clang::warn_unused_result]]47// Clang in C++14 mode claims that it has the 'nodiscard' attribute, but also48// warns in the pedantic mode that 'nodiscard' is a C++17 extension (PR33518).49// Use the 'nodiscard' attribute in C++14 mode only with GCC.50// TODO: remove this workaround when PR33518 is resolved.51#elif defined(__GNUC__) && ORC_RT_HAS_CPP_ATTRIBUTE(nodiscard)52#define ORC_RT_NODISCARD [[nodiscard]]53#else54#define ORC_RT_NODISCARD55#endif5657#if __has_builtin(__builtin_expect)58#define ORC_RT_LIKELY(EXPR) __builtin_expect((bool)(EXPR), true)59#define ORC_RT_UNLIKELY(EXPR) __builtin_expect((bool)(EXPR), false)60#else61#define ORC_RT_LIKELY(EXPR) (EXPR)62#define ORC_RT_UNLIKELY(EXPR) (EXPR)63#endif6465#if defined(__APPLE__)66#define ORC_RT_WEAK_IMPORT __attribute__((weak_import))67#elif defined(_WIN32)68#define ORC_RT_WEAK_IMPORT69#else70#define ORC_RT_WEAK_IMPORT __attribute__((weak))71#endif7273#endif // ORC_RT_COMPILER_H747576