<div class="gmail_quote">On 27 May 2010 15:05, Nicolas Capens <span dir="ltr"><<a href="mailto:nicolas.capens@gmail.com">nicolas.capens@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div>Hi Chris,</div>
<div> </div>
<div>Thanks for pointing me to that presentation! It helped me come up with a strategy that I believe might work:</div>
<div> </div>
<div>1) Use CloneFunction() to make a copy of the original unspecialized (but optimized) function.</div>
<div>2) Specialize it using a custom function pass which identifies the specialization parameters and substitutes them with given run-time constants.</div></blockquote><div><br></div><div>Use llvm::CloneAndPruneFunctionInfo(). It lets you specify the constant replacements for values up front and therefore clones less by doing the constant folding as it goes.</div>
<div><br></div><div>Nick</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div>3) Run the function through a FunctionPassManager with some post-specialization optimization passes (dead code, etc).</div>
<div>4) Use getPointerToFunction() to generate the machine code.</div>
<div>5) Call freeMachineCodeForFunction() when I no longer need a specific specialization.</div>
<div> </div>
<div>I'm not entirely sure yet how to implement some of these steps in practice, but does this sound like the right approach or would you suggest something else? Can I call <font size="2">eraseFromParent() on the specialized function after step 4 or only at 5?</font></div>
<div> </div>
<div>Thank you!</div>
<div> </div><font color="#888888">
<div>Nicolas</div></font><div><div></div><div class="h5">
<div><br> </div>
<div class="gmail_quote">On Thu, May 27, 2010 at 6:44 PM, Chris Lattner <span dir="ltr"><<a href="mailto:clattner@apple.com" target="_blank">clattner@apple.com</a>></span> wrote:<br>
<blockquote style="border-left:#ccc 1px solid;margin:0px 0px 0px 0.8ex;padding-left:1ex" class="gmail_quote">
<div>
<div></div>
<div><br>On May 27, 2010, at 6:08 AM, Nicolas Capens wrote:<br><br>> Hi all,<br>><br>> I'm attempting to use LLVM for run-time code specialization, but I'm facing a performance hurdle. I'm currently performing the specialization during the AST to LLVM IR translation, but unfortunately this leads to relatively slow recompiles as LLVM has to perform all the heavy (optimization) passes over and over again.<br>
><br>> So I was hoping that by first creating unspecialized LLVM IR, optimizing that as much as possible, and then performing the specializations starting from this optimized IR, the recompiles would be significantly faster. Currently the mem2reg and instcombine passes take the majority of compilation time, which could be avoided using "deep" JIT specialization.<br>
><br>> So my question is how do I get started with this? Currently tracking the specialization parameters and caching the generated specialized functions is done outside of LLVM. So I imagine I'll have to somehow inform LLVM of the semi-constant values of the specialization parameters, without losing the original (optimized) IR. Can I add and remove specialized function instances at run-time?<br>
><br><br></div></div>Hi Nicolas,<br><br>Nate Begeman's "building an efficient JIT" talk about the llvm developer meeting last year (or the year before) is a great place to start looking for this sort of thing.<br>
<font color="#888888"><br>-Chris<br><br></font></blockquote></div><br>
</div></div><br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br>