libcopp  2.2.0
compile_optimize.h
Go to the documentation of this file.
1 // Copyright 2023 owent
2 #pragma once
3 
4 // ================ import/export ================
5 // @see https://gcc.gnu.org/wiki/Visibility
6 // @see http://releases.llvm.org/9.0.0/tools/clang/docs/AttributeReference.html
7 // 不支持 borland/sunpro_cc/xlcpp
8 
9 // ================ import/export: for compilers ================
10 #if defined(__GNUC__) && !defined(__ibmxl__)
11 // GNU C++/Clang
12 //
13 // Dynamic shared object (DSO) and dynamic-link library (DLL) support
14 //
15 # if __GNUC__ >= 4
16 # if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(__CYGWIN__)
17 // All Win32 development environments, including 64-bit Windows and MinGW, define
18 // _WIN32 or one of its variant spellings. Note that Cygwin is a POSIX environment,
19 // so does not define _WIN32 or its variants.
20 # ifndef UTIL_SYMBOL_EXPORT
21 # define UTIL_SYMBOL_EXPORT __attribute__((__dllexport__))
22 # endif
23 # ifndef UTIL_SYMBOL_IMPORT
24 # define UTIL_SYMBOL_IMPORT __attribute__((__dllimport__))
25 # endif
26 
27 # else
28 
29 # ifndef UTIL_SYMBOL_EXPORT
30 # define UTIL_SYMBOL_EXPORT __attribute__((visibility("default")))
31 # endif
32 # ifndef UTIL_SYMBOL_IMPORT
33 # define UTIL_SYMBOL_IMPORT __attribute__((visibility("default")))
34 # endif
35 # ifndef UTIL_SYMBOL_VISIBLE
36 # define UTIL_SYMBOL_VISIBLE __attribute__((visibility("default")))
37 # endif
38 # ifndef UTIL_SYMBOL_LOCAL
39 # define UTIL_SYMBOL_LOCAL __attribute__((visibility("hidden")))
40 # endif
41 
42 # endif
43 
44 # else
45 // config/platform/win32.hpp will define UTIL_SYMBOL_EXPORT, etc., unless already defined
46 # ifndef UTIL_SYMBOL_EXPORT
47 # define UTIL_SYMBOL_EXPORT
48 # endif
49 # ifndef UTIL_SYMBOL_IMPORT
50 # define UTIL_SYMBOL_IMPORT
51 # endif
52 # ifndef UTIL_SYMBOL_VISIBLE
53 # define UTIL_SYMBOL_VISIBLE
54 # endif
55 # ifndef UTIL_SYMBOL_LOCAL
56 # define UTIL_SYMBOL_LOCAL
57 # endif
58 
59 # endif
60 
61 #elif defined(_MSC_VER)
62 // Microsoft Visual C++
63 //
64 // Must remain the last #elif since some other vendors (Metrowerks, for
65 // example) also #define _MSC_VER
66 #else
67 #endif
68 // ---------------- import/export: for compilers ----------------
69 
70 // ================ import/export: for platform ================
71 // Default defines for UTIL_SYMBOL_EXPORT and UTIL_SYMBOL_IMPORT
72 // If a compiler doesn't support __declspec(dllexport)/__declspec(dllimport),
73 // its boost/config/compiler/ file must define UTIL_SYMBOL_EXPORT and
74 // UTIL_SYMBOL_IMPORT
75 #if !defined(UTIL_SYMBOL_EXPORT) && (defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(__CYGWIN__))
76 # ifndef UTIL_SYMBOL_EXPORT
77 # define UTIL_SYMBOL_EXPORT __declspec(dllexport)
78 # endif
79 # ifndef UTIL_SYMBOL_IMPORT
80 # define UTIL_SYMBOL_IMPORT __declspec(dllimport)
81 # endif
82 #endif
83 // ---------------- import/export: for platform ----------------
84 
85 #ifndef UTIL_SYMBOL_EXPORT
86 # define UTIL_SYMBOL_EXPORT
87 #endif
88 #ifndef UTIL_SYMBOL_IMPORT
89 # define UTIL_SYMBOL_IMPORT
90 #endif
91 #ifndef UTIL_SYMBOL_LOCAL
92 # define UTIL_SYMBOL_LOCAL
93 #endif
94 #ifndef UTIL_SYMBOL_VISIBLE
95 # define UTIL_SYMBOL_VISIBLE
96 #endif
97 
98 // ---------------- import/export ----------------
99 
100 // ================ __cdecl ================
101 #if defined(__GNUC__) || defined(__GNUG__)
102 # ifndef __cdecl
103 // see https://gcc.gnu.org/onlinedocs/gcc-4.0.0/gcc/Function-Attributes.html
104 // Intel x86 architecture specific calling conventions
105 # ifdef _M_IX86
106 # define __cdecl __attribute__((__cdecl__))
107 # else
108 # define __cdecl
109 # endif
110 # endif
111 #endif
112 // ---------------- __cdecl ----------------
113 
114 // ================ always inline ================
115 
116 #ifndef UTIL_FORCEINLINE
117 # if defined(__clang__)
118 # if __cplusplus >= 201103L
119 # define UTIL_FORCEINLINE [[gnu::always_inline]] inline
120 # else
121 # define UTIL_FORCEINLINE __attribute__((always_inline)) inline
122 # endif
123 # elif defined(__GNUC__) && __GNUC__ > 3
124 # if __cplusplus >= 201103L && (__GNUC__ * 100 + __GNUC_MINOR__) >= 408
125 # define UTIL_FORCEINLINE [[gnu::always_inline]] inline
126 # else
127 # define UTIL_FORCEINLINE __attribute__((always_inline)) inline
128 # endif
129 # elif defined(_MSC_VER)
130 # define UTIL_FORCEINLINE __forceinline
131 # else
132 # define UTIL_FORCEINLINE inline
133 # endif
134 #endif
135 
136 #ifndef UTIL_NOINLINE_NOCLONE
137 # if defined(__clang__)
138 # if __cplusplus >= 201103L
139 # define UTIL_NOINLINE_NOCLONE [[gnu::noinline]]
140 # else
141 # define UTIL_NOINLINE_NOCLONE __attribute__((noinline))
142 # endif
143 # elif defined(__GNUC__) && __GNUC__ > 3
144 # if __cplusplus >= 201103L && (__GNUC__ * 100 + __GNUC_MINOR__) >= 408
145 # define UTIL_NOINLINE_NOCLONE [[gnu::noinline, gnu::noclone]]
146 # else
147 # define UTIL_NOINLINE_NOCLONE __attribute__((noinline, noclone))
148 # endif
149 # elif defined(_MSC_VER)
150 # define UTIL_NOINLINE_NOCLONE __declspec(noinline)
151 # else
152 # define UTIL_NOINLINE_NOCLONE
153 # endif
154 #endif
155 
156 // #ifndef UTIL_TRIVIAL_ABI
157 // #define UTIL_TRIVIAL_ABI [[trivial_abi]]
158 // #define UTIL_TRIVIAL_ABI [[clang::trivial_abi]]
159 // #define UTIL_TRIVIAL_ABI __attribute__((trivial_abi))
160 // #endif