<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">I was afraid that was the case, since std::function is not a first-class object of LLVM.<div class="">Every implementation that I can think of that inlines std::function intrinsically seems a bit awkward, in the way that it will be along the lines:</div><div class=""><br class=""></div><div class="">“Treat this class (std::function) in a special way”</div><div class=""><br class=""></div><div class="">A better way would be to generalize for all callables, and say something along the lines of</div><div class=""><br class=""></div><div class="">“If a class has the () operator, see if you can inline that method”</div><div class=""><br class=""></div><div class="">But that too is too specific to C++ and I’m afraid high-level operator semantics will be lost by the time it turns to byte code. Seems to me, the sane solution would be for clang++ to treat std::function as an LLVM function type (<a href="https://llvm.org/docs/LangRef.html#function-type" class="">https://llvm.org/docs/LangRef.html#function-type</a>) instead of a class object and then the road to these optimizations will open. But I have not looked at the gritty details of the clang implementation, so I could be way off. Anybody willing to step in and fill the blanks would be appreciated.</div><div class=""><br class=""></div><div class="">Regards,</div><div class="">Lef</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><div class=""><div><br class=""><blockquote type="cite" class=""><div class="">On May 29, 2018, at 2:53 PM, Friedman, Eli <<a href="mailto:efriedma@codeaurora.org" class="">efriedma@codeaurora.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">On 5/29/2018 10:52 AM, Eleftherios Ioannidis via llvm-dev wrote:<br class=""><blockquote type="cite" class="">However that doesn't seem to be the case, does the inliner not get triggered if the functions are passed as objects (std::function) or am I using the wrong `opt` invokation?<br class=""></blockquote><br class="">In general, the inliner can only inline direct function calls (not virtual calls, or calls through a function pointer or std::function); otherwise, it doesn't know what to inline.<br class=""><br class="">In some cases, optimizations can prove that an indirect call actually calls some specific function, but your testcase isn't one of those cases.  In particular, the implementation of std::function is kind of hard for the optimizer to deal with. This could probably be improved.<br class=""><br class="">-Eli<br class=""><br class="">-- <br class="">Employee of Qualcomm Innovation Center, Inc.<br class="">Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project<br class=""><br class=""></div></div></blockquote></div><br class=""></div></div></body></html>