<div dir="ltr">Hi Evan,<div><br></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Thanks for the pointer to ORC -- it looks like the runFunction there is a copy-paste from MCJIT (minus the finalize() stuff).</blockquote><div><br></div><div>The runFunction method in OrcMCJITReplacement is just a copy-paste, but OrcMCJITReplacement only exists for direct backwards-compatibility with MCJIT. In general ORC doesn't have any equivalent of runFunction. Instead, it just has symbol lookup (via findSymbol) and leaves it to the user to cast the resulting TargetAddress to an appropriate function pointer and marshal arguments/returns.</div><div><br></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">The basic approach I am using is to add a function to TargetMachine called runFunctionNatively:<br></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"> </blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">  virtual GenericValue runFunctionNatively(Function *F, void *FPtr, ArrayRef<GenericValue> ArgValues);<br></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"> </blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">This houses most of the duplicated code currently in runFunction, and can then be called from either MCJIT or </blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">OrcMCJITReplacement. I then have an override for X86TargetMachine that uses the register trick.</blockquote></div><div style="font-size:13px"><br></div><div style="font-size:13px">Very cool that you got this working. It's a good fit for MCJIT as it stands (though I'd want to keep it in ExecutionEngine, rather than move it to TargetMachine). For Orc it might make sense to put it in ORCABISupport and drop the Function* argument (in favor of some sort of calling-convention description), since we want to make sure users can free Modules after compiling the code.</div><div style="font-size:13px"><br></div><div style="font-size:13px"><br></div><div style="font-size:13px"><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">I agree a generic implementation would be ideal, but I don't know how to do a generic dynamic dispatch in C. Lacking that generic implementation, would you be interested in seeing what I have so far?</blockquote></div><div><br></div><div>I can think of one (rather heavyweight) answer: We depend on libClang. This solution would preclude including the feature in LLVMCore (we'd need to create some sort of LLVM JIT-extras project) and kill performance for the initial call, but it would be generic and work on remote-JITs.</div><div><br></div><div>Out of interest: How dynamic are your function signatures? If you know them ahead of time (even if they're very complex) you can handle this by just casting to an appropriate function pointer type and calling. If the function signatures are dynamic (as in a REPL) then the usual answer is to use whatever fronted you used for the rest of the program to generate the main-like expression function, then call that. I can imagine that there might be use cases where neither of these are appropriate though.</div><div><br></div><div>- Lang.</div></div><span class="im" style="font-size:13px"></span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jul 15, 2016 at 11:48 AM, Evan Miller <span dir="ltr"><<a href="mailto:emmiller@gmail.com" target="_blank">emmiller@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 dir="ltr">Hi Lang,<div><br></div><div>Thanks for the reply. Responses below.</div><div class="gmail_extra"><br><div class="gmail_quote"><span class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div>As far as I know nobody is actively working on MCJIT any more. I've been working on the next generation of LLVM JIT APIs (ORC - see include/llvm/ExecutionEngine/Orc) for a while now, but they don't have functionality for running arbitrary functions yet.<br></div></div></blockquote><div><br></div></span><div>Thanks for the pointer to ORC -- it looks like the runFunction there is a copy-paste from MCJIT (minus the finalize() stuff).</div><span class=""><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><span><div><span style="font-size:12.800000190734863px">Definitely. I'd be happy to see something like this in ORC, and I think there would be other people who would appreciate it too.</span></div></span></div></blockquote><div><br></div></span><div>The basic approach I am using is to add a function to TargetMachine called runFunctionNatively:</div><div><br></div><div><div>  virtual GenericValue runFunctionNatively(Function *F, void *FPtr, ArrayRef<GenericValue> ArgValues);</div></div><div><br></div><div>This houses most of the duplicated code currently in runFunction, and can then be called from either MCJIT or OrcMCJITReplacement. I then have an override for X86TargetMachine that uses the register trick.</div><span class=""><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><span><div>I'd like to see a generic implementation that can handle all architectures first, maybe with an specialized version for specific ABIs as an optimization.<br></div></span></div></blockquote><div><br></div></span><div>I agree a generic implementation would be ideal, but I don't know how to do a generic dynamic dispatch in C. Lacking that generic implementation, would you be interested in seeing what I have so far?</div><div><br></div><div>Thanks!</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>Evan</div><div> </div></font></span></div><div data-smartmail="gmail_signature"></div>
</div></div>
</blockquote></div><br></div>