Add EIGEN_LAMBDA_ALWAYS_INLINE macro for MSVC lambda inlining

libeigen/eigen!2170

Closes #3033

Co-authored-by: Rasmus Munk Larsen <rmlarsen@gmail.com>
This commit is contained in:
Rasmus Munk Larsen
2026-02-20 21:28:47 -08:00
parent a87ecfb179
commit 95e8bc3267
2 changed files with 13 additions and 2 deletions

View File

@@ -1403,8 +1403,7 @@ EIGEN_DONT_INLINE void gebp_kernel<LhsScalar, RhsScalar, Index, DataMapper, mr,
// template instantiation of this generic lambda as a separate function,
// adding call overhead that causes 10-17 % regressions in LLT/TRSM
// for small-to-medium matrix sizes.
auto micro_panel = [&](auto mrp_tag, auto nrc_tag, auto& local_traits, Index i, Index j2)
__attribute__((always_inline)) {
auto micro_panel = [&](auto mrp_tag, auto nrc_tag, auto& local_traits, Index i, Index j2) EIGEN_LAMBDA_ALWAYS_INLINE {
constexpr int MrP = decltype(mrp_tag)::value;
constexpr int NrC = decltype(nrc_tag)::value;
using LTraits = std::remove_reference_t<decltype(local_traits)>;

View File

@@ -906,6 +906,18 @@
#define EIGEN_ALWAYS_INLINE EIGEN_STRONG_INLINE
#endif
// EIGEN_LAMBDA_ALWAYS_INLINE forces inlining of lambda functions.
// On GCC/Clang, __attribute__((always_inline)) works on lambdas.
// On MSVC, __forceinline cannot be applied to lambdas, but the
// [[msvc::forceinline]] attribute (available since VS 2022 17.1) can.
#if EIGEN_COMP_GNUC && !defined(SYCL_DEVICE_ONLY)
#define EIGEN_LAMBDA_ALWAYS_INLINE __attribute__((always_inline))
#elif EIGEN_COMP_MSVC >= 1931
#define EIGEN_LAMBDA_ALWAYS_INLINE [[msvc::forceinline]]
#else
#define EIGEN_LAMBDA_ALWAYS_INLINE
#endif
#if EIGEN_COMP_GNUC
#define EIGEN_DONT_INLINE __attribute__((noinline))
#elif EIGEN_COMP_MSVC