This repository was archived by the owner on Apr 27, 2026. It is now read-only.
forked from StrikerX3/Ymir
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinline.hpp
More file actions
85 lines (68 loc) · 2.66 KB
/
inline.hpp
File metadata and controls
85 lines (68 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#pragma once
/**
@file
@brief Macros for managing function inlining and flattening.
This header defines the following macros:
- `FORCE_INLINE` and `FORCE_INLINE_EX`: Forces function inlining and marks the function `inline`
- `NO_INLINE`: Prevents function inlining
- `FLATTEN` and `FLATTEN_EX`: Flattens the function
The `FORCE_INLINE_EX` and `FLATTEN_EX` are meant to be used in functions that heavily slow down compilation if inlined
or flattened. If `Ymir_EXTRA_INLINING` is defined, the macros behave exactly like their non-`EX` counterparts, otherwise
they do nothing. This only has an effect with Clang as the other compilers tend to choke on heavy inlining.
In Debug builds, these macros have no effect in order to not disrupt the debugging experience. The inline macros can be
disabled by defining `Ymir_DISABLE_FORCE_INLINE`. `Ymir_EXTRA_INLINING` has no effect in debug builds.
Note that `FORCE_INLINE` always marks the function `inline` even when disabled.
The macros use appropriate attributes for MSVC, Clang and GCC. For any other compiler, these macros do nothing.
*/
/**
@def FORCE_INLINE
@brief Forces function inlining and marks the function `inline`.
*/
/**
@def NO_INLINE
@brief Prevents function inlining.
*/
/**
@def FLATTEN
@brief Flattens the function.
Essentially inlines all functions called by the flattened function.
*/
/**
@def FORCE_INLINE_EX
@brief If `Ymir_EXTRA_INLINING` is defined, forces function inlining and marks the function `inline`.
For use with functions that heavily impact build times.
*/
/**
@def FLATTEN
@brief If `Ymir_EXTRA_INLINING` is defined, flattens the function.
Essentially inlines all functions called by the flattened function.
For use with functions that heavily impact build times.
*/
#if !defined(NDEBUG) || defined(Ymir_DISABLE_FORCE_INLINE)
#define FORCE_INLINE inline
#define NO_INLINE
#define FLATTEN
#elif defined(__clang__)
#define FORCE_INLINE [[gnu::always_inline]] inline
#define NO_INLINE [[gnu::noinline]]
#define FLATTEN [[gnu::flatten]]
#elif (defined(__GNUC__) || defined(__GNUG__))
#define FORCE_INLINE [[gnu::always_inline]] inline
#define NO_INLINE [[gnu::noinline]]
#define FLATTEN // GCC dies when [[gnu::flatten]] is (ab)used
#elif defined(_MSC_VER)
#define FORCE_INLINE [[msvc::forceinline]] inline
#define NO_INLINE [[msvc::noinline]]
#define FLATTEN // MSVC dies when [[msvc::flatten]] is (ab)used
#else
#define FORCE_INLINE inline
#define NO_INLINE
#define FLATTEN
#endif
#if Ymir_EXTRA_INLINING && defined(__clang__)
#define FORCE_INLINE_EX FORCE_INLINE
#define FLATTEN_EX FLATTEN
#else
#define FORCE_INLINE_EX inline
#define FLATTEN_EX
#endif