<div dir="ltr">Yeah, it's unfortunately a fair bit more complicated than that.<br><br>It's unlikely that LLVM or Clang would ever special-case the IR for std::function specifically. Generally the goal would be to find what parts of LLVM aren't able to see through the abstractions in std::function to optimize it generally.</div><br><div class="gmail_quote"><div dir="ltr">On Tue, May 29, 2018 at 12:44 PM Eleftherios Ioannidis via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space">I was afraid that was the case, since std::function is not a first-class object of LLVM.<div>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><br></div><div>“Treat this class (std::function) in a special way”</div><div><br></div><div>A better way would be to generalize for all callables, and say something along the lines of</div><div><br></div><div>“If a class has the () operator, see if you can inline that method”</div><div><br></div><div>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" target="_blank">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><br></div><div>Regards,</div><div>Lef</div></div><div style="word-wrap:break-word;line-break:after-white-space"><div><br></div><div><br></div><div><div><div><br><blockquote type="cite"><div>On May 29, 2018, at 2:53 PM, Friedman, Eli <<a href="mailto:efriedma@codeaurora.org" target="_blank">efriedma@codeaurora.org</a>> wrote:</div><br class="m_6169104898619758614Apple-interchange-newline"><div><div>On 5/29/2018 10:52 AM, Eleftherios Ioannidis via llvm-dev wrote:<br><blockquote type="cite">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></blockquote><br>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><br>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><br>-Eli<br><br>-- <br>Employee of Qualcomm Innovation Center, Inc.<br>Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project<br><br></div></div></blockquote></div><br></div></div></div>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>