|
| 1 | +/*===-- include/flang/Runtime/api-attrs.h ---------------------------*- 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 | + |
| 10 | +/* |
| 11 | + * The file defines a set macros that can be used to apply |
| 12 | + * different attributes/pragmas to functions/variables |
| 13 | + * declared/defined/used in Flang runtime library. |
| 14 | + */ |
| 15 | + |
| 16 | +#ifndef FORTRAN_RUNTIME_API_ATTRS_H_ |
| 17 | +#define FORTRAN_RUNTIME_API_ATTRS_H_ |
| 18 | + |
| 19 | +/* |
| 20 | + * RT_EXT_API_GROUP_BEGIN/END pair is placed around definitions |
| 21 | + * of functions exported by Flang runtime library. They are the entry |
| 22 | + * points that are referenced in the Flang generated code. |
| 23 | + * The macros may be expanded into any construct that is valid to appear |
| 24 | + * at C++ module scope. |
| 25 | + */ |
| 26 | +#ifndef RT_EXT_API_GROUP_BEGIN |
| 27 | +#if defined(OMP_NOHOST_BUILD) |
| 28 | +#define RT_EXT_API_GROUP_BEGIN \ |
| 29 | + _Pragma("omp begin declare target device_type(nohost)") |
| 30 | +#elif defined(OMP_OFFLOAD_BUILD) |
| 31 | +#define RT_EXT_API_GROUP_BEGIN _Pragma("omp declare target") |
| 32 | +#else |
| 33 | +#define RT_EXT_API_GROUP_BEGIN |
| 34 | +#endif |
| 35 | +#endif /* !defined(RT_EXT_API_GROUP_BEGIN) */ |
| 36 | + |
| 37 | +#ifndef RT_EXT_API_GROUP_END |
| 38 | +#if defined(OMP_NOHOST_BUILD) || defined(OMP_OFFLOAD_BUILD) |
| 39 | +#define RT_EXT_API_GROUP_END _Pragma("omp end declare target") |
| 40 | +#else |
| 41 | +#define RT_EXT_API_GROUP_END |
| 42 | +#endif |
| 43 | +#endif /* !defined(RT_EXT_API_GROUP_END) */ |
| 44 | + |
| 45 | +/* |
| 46 | + * RT_VAR_GROUP_BEGIN/END pair is placed around definitions |
| 47 | + * of module scope variables referenced by Flang runtime (directly |
| 48 | + * or indirectly). |
| 49 | + * The macros may be expanded into any construct that is valid to appear |
| 50 | + * at C++ module scope. |
| 51 | + */ |
| 52 | +#ifndef RT_VAR_GROUP_BEGIN |
| 53 | +#define RT_VAR_GROUP_BEGIN RT_EXT_API_GROUP_BEGIN |
| 54 | +#endif /* !defined(RT_VAR_GROUP_BEGIN) */ |
| 55 | + |
| 56 | +#ifndef RT_VAR_GROUP_END |
| 57 | +#define RT_VAR_GROUP_END RT_EXT_API_GROUP_END |
| 58 | +#endif /* !defined(RT_VAR_GROUP_END) */ |
| 59 | + |
| 60 | +/* |
| 61 | + * Each non-exported function used by Flang runtime (e.g. via |
| 62 | + * calling it or taking its address, etc.) is marked with |
| 63 | + * RT_API_ATTRS. The macros is placed at both declaration and |
| 64 | + * definition of such a function. |
| 65 | + * The macros may be expanded into a construct that is valid |
| 66 | + * to appear as part of a C++ decl-specifier. |
| 67 | + */ |
| 68 | +#ifndef RT_API_ATTRS |
| 69 | +#if defined(__CUDACC__) || defined(__CUDA__) |
| 70 | +#define RT_API_ATTRS __host__ __device__ |
| 71 | +#else |
| 72 | +#define RT_API_ATTRS |
| 73 | +#endif |
| 74 | +#endif /* !defined(RT_API_ATTRS) */ |
| 75 | + |
| 76 | +/* |
| 77 | + * Each const/constexpr module scope variable referenced by Flang runtime |
| 78 | + * (directly or indirectly) is marked with RT_CONST_VAR_ATTRS. |
| 79 | + * The macros is placed at both declaration and definition of such a variable. |
| 80 | + * The macros may be expanded into a construct that is valid |
| 81 | + * to appear as part of a C++ decl-specifier. |
| 82 | + */ |
| 83 | +#ifndef RT_CONST_VAR_ATTRS |
| 84 | +#if defined(__CUDACC__) || defined(__CUDA__) |
| 85 | +#define RT_CONST_VAR_ATTRS __constant__ |
| 86 | +#else |
| 87 | +#define RT_CONST_VAR_ATTRS |
| 88 | +#endif |
| 89 | +#endif /* !defined(RT_CONST_VAR_ATTRS) */ |
| 90 | + |
| 91 | +#endif /* !FORTRAN_RUNTIME_API_ATTRS_H_ */ |
0 commit comments