<div dir="ltr">If you consider how std::sort works - it doesn't exist in the machine (or even LLVM IR) level without a specific type - so if you were to support something like std::sort in your language (JITed or not), it means some form of specialization of your types/functions based on other types.<br><br>So, yes, something like "own Sort function inside JIT" - if your language doesn't support a way to write this in the language itself (if it doesn't have anything like C++ templates or an equivalent generic thing).<br><br>Otherwise you can do something like qsort (which uses a function pointer to parameterize the comparison) & perhaps force or encourage the optimizer to inline and collapse away this indirection.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jul 3, 2019 at 3:43 PM Rajesh S R 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:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi LLVM devs,<div>The performance of C++ std::sort comes from being able to inline the comparator. For a JIT generated data type, using the comparator as a function call from std::sort may not be ideal. So, i was wondering how can we make a JIT-sort which is as good as statically compiled std::sort with comparator inlined.</div><div><br></div><div>What is the recommended way to pass a an existing function like std::sort into JIT so that it can optimize the whole program? For example, how do we generate the bytecode for existing function (say some external tools) and give to JIT runtime. Is there some code sample?</div><div><br></div><div>The alternative is to rollout my own Sort function inside JIT, but i don't want to do that and want to take this as an opportunity to learn the general approach of passing existing function definitions into JIT to do whole program optimization like inlining.</div><div><br></div><div>I found this <a href="https://stackoverflow.com/questions/10587250/fast-to-compile-efficient-sort-algorithm-for-jit-compilation" target="_blank">stackoverflow question </a>which is related to what I am asking for, but I don't see any final conclusion on this beyond incurring a function call for each comparison.</div><div><br></div><div>Thanks!</div><div><br></div><div>Rajesh S R</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="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>