Skip to content

Commit

Permalink
Partly mitigate bad Clang inlining decision
Browse files Browse the repository at this point in the history
Because a visitor is wrapped several times during visitation it cases extra
temporaries usage and useless store and loads that can only be optimized if
the `visitation_impl` is inlined into the function that creates the wrapper.
Clang inliner decides not to inline functions even with small-sized switches,
resulting in a poor visitation code. Forceinline mark on those internal functions perceptibly improves the situation, though does not mitigate it
completely.

LLVM ticket https://bugs.llvm.org/show_bug.cgi?id=41491
  • Loading branch information
Kojoley committed Apr 14, 2019
1 parent 74ea828 commit dd9b0c9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion include/boost/variant/detail/visitation_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ template <
, typename Visitor, typename VoidPtrCV
, typename NoBackupFlag
>
inline typename Visitor::result_type
BOOST_FORCEINLINE typename Visitor::result_type
visitation_impl(
const int internal_which, const int logical_which
, Visitor& visitor, VoidPtrCV storage
Expand Down
6 changes: 3 additions & 3 deletions include/boost/variant/variant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2355,7 +2355,7 @@ class variant
#endif// !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)

template <typename Visitor, typename VoidPtrCV>
static typename Visitor::result_type
BOOST_FORCEINLINE static typename Visitor::result_type
internal_apply_visitor_impl(
int internal_which
, int logical_which
Expand All @@ -2380,7 +2380,7 @@ class variant
}

template <typename Visitor>
typename Visitor::result_type
BOOST_FORCEINLINE typename Visitor::result_type
internal_apply_visitor(Visitor& visitor)
{
return internal_apply_visitor_impl(
Expand All @@ -2389,7 +2389,7 @@ class variant
}

template <typename Visitor>
typename Visitor::result_type
BOOST_FORCEINLINE typename Visitor::result_type
internal_apply_visitor(Visitor& visitor) const
{
return internal_apply_visitor_impl(
Expand Down

0 comments on commit dd9b0c9

Please sign in to comment.