mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
bpo-45116: Add the Py_ALWAYS_INLINE macro (GH-28390)
Add the Py_ALWAYS_INLINE macro to ask the compiler to always inline a static inline function. The compiler can ignore it and decides to not inline the function.
This commit is contained in:
parent
064464fc38
commit
6b41355128
3 changed files with 44 additions and 0 deletions
|
@ -557,6 +557,28 @@ extern "C" {
|
|||
#define _Py_HOT_FUNCTION
|
||||
#endif
|
||||
|
||||
// Ask the compiler to always inline a static inline function. The compiler can
|
||||
// ignore it and decides to not inline the function.
|
||||
//
|
||||
// It can be used to inline performance critical static inline functions when
|
||||
// building Python in debug mode with function inlining disabled. For example,
|
||||
// MSC disables function inlining when building in debug mode.
|
||||
//
|
||||
// Marking blindly a static inline function with Py_ALWAYS_INLINE can result in
|
||||
// worse performances (due to increased code size for example). The compiler is
|
||||
// usually smarter than the developer for the cost/benefit analysis.
|
||||
//
|
||||
// It must be specified before the function return type. Usage:
|
||||
//
|
||||
// static inline Py_ALWAYS_INLINE int random(void) { return 4; }
|
||||
#if defined(__GNUC__) || defined(__clang__) || defined(__INTEL_COMPILER)
|
||||
# define Py_ALWAYS_INLINE __attribute__((always_inline))
|
||||
#elif defined(_MSC_VER)
|
||||
# define Py_ALWAYS_INLINE __forceinline
|
||||
#else
|
||||
# define Py_ALWAYS_INLINE
|
||||
#endif
|
||||
|
||||
// Py_NO_INLINE
|
||||
// Disable inlining on a function. For example, it reduces the C stack
|
||||
// consumption: useful on LTO+PGO builds which heavily inline code (see
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue