[compiler-rt] bd6c93c - [ORC-RT] Add compiler abstraction header for the ORC runtime.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Tue May 18 08:44:31 PDT 2021


Author: Lang Hames
Date: 2021-05-18T08:44:15-07:00
New Revision: bd6c93c00432ee62a238934ba0e0078ebfb63cca

URL: https://github.com/llvm/llvm-project/commit/bd6c93c00432ee62a238934ba0e0078ebfb63cca
DIFF: https://github.com/llvm/llvm-project/commit/bd6c93c00432ee62a238934ba0e0078ebfb63cca.diff

LOG: [ORC-RT] Add compiler abstraction header for the ORC runtime.

This header provides helper macros to insulate the rest of the ORC runtime from
compiler specifics.

Added: 
    compiler-rt/lib/orc/compiler.h

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/orc/compiler.h b/compiler-rt/lib/orc/compiler.h
new file mode 100644
index 0000000000000..fcc4f2011adb4
--- /dev/null
+++ b/compiler-rt/lib/orc/compiler.h
@@ -0,0 +1,55 @@
+//===--------- compiler.h - Compiler abstraction support --------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file is a part of the ORC runtime support library.
+//
+// Most functionality in this file was swiped from llvm/Support/Compiler.h.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef ORC_RT_COMPILER_H
+#define ORC_RT_COMPILER_H
+
+#define ORC_RT_INTERFACE extern "C" __attribute__((visibility("default")))
+#define ORC_RT_HIDDEN __attribute__((visibility("hidden")))
+
+// Only use __has_cpp_attribute in C++ mode. GCC defines __has_cpp_attribute in
+// C mode, but the :: in __has_cpp_attribute(scoped::attribute) is invalid.
+#ifndef ORC_RT_HAS_CPP_ATTRIBUTE
+#if defined(__cplusplus) && defined(__has_cpp_attribute)
+#define ORC_RT_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
+#else
+#define ORC_RT_HAS_CPP_ATTRIBUTE(x) 0
+#endif
+#endif
+
+// Use the 'nodiscard' attribute in C++17 or newer mode.
+#if defined(__cplusplus) && __cplusplus > 201402L &&                           \
+    ORC_RT_HAS_CPP_ATTRIBUTE(nodiscard)
+#define ORC_RT_NODISCARD [[nodiscard]]
+#elif ORC_RT_HAS_CPP_ATTRIBUTE(clang::warn_unused_result)
+#define ORC_RT_NODISCARD [[clang::warn_unused_result]]
+// Clang in C++14 mode claims that it has the 'nodiscard' attribute, but also
+// warns in the pedantic mode that 'nodiscard' is a C++17 extension (PR33518).
+// Use the 'nodiscard' attribute in C++14 mode only with GCC.
+// TODO: remove this workaround when PR33518 is resolved.
+#elif defined(__GNUC__) && ORC_RT_HAS_CPP_ATTRIBUTE(nodiscard)
+#define ORC_RT_NODISCARD [[nodiscard]]
+#else
+#define ORC_RT_NODISCARD
+#endif
+
+#if __has_builtin(__builtin_expect)
+#define ORC_RT_LIKELY(EXPR) __builtin_expect((bool)(EXPR), true)
+#define ORC_RT_UNLIKELY(EXPR) __builtin_expect((bool)(EXPR), false)
+#else
+#define ORC_RT_LIKELY(EXPR) (EXPR)
+#define ORC_RT_UNLIKELY(EXPR) (EXPR)
+#endif
+
+#endif // ORC_RT_COMPILER_H


        


More information about the llvm-commits mailing list