Hi Currently , I have doing some experimental work by using llvm, Is it possible to drop the machine code once it has been generated for particular function while program executing. For example some *void test(int)* function has been executed on native machine , I want to drop the code before I start execute some other function in my long running program. Thanks. With regards Sri. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140425/d701406e/attachment.html>
On Fri, Apr 25, 2014 at 11:44:24PM +0100, Sri wrote:> Hi > Currently , I have doing some experimental work by using llvm, > Is it possible to drop the machine code once it has been generated for > particular function while program executing. For example some *void > test(int)* function has been executed on native machine , I want to drop > the code before I start execute some other function in my long running > program. >You can disassemble the code once it has been compiled. Mesa's llvmpipe driver does this: http://cgit.freedesktop.org/mesa/mesa/tree/src/gallium/auxiliary/gallivm/lp_bld_debug.cpp#n192 -Tom> Thanks. > > With regards > Sri.> _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Hi Tom Thanks for the reference , is there any llvm function that I could directly call to drop the generated machine code ? Currently I am having compiled llvm IR function and I could able to get generated native function pointer by using getpointertofunction, / Thanks With regards Sri. On 04/26/2014 12:05 AM, Tom Stellard wrote:> On Fri, Apr 25, 2014 at 11:44:24PM +0100, Sri wrote: >> Hi >> Currently , I have doing some experimental work by using llvm, >> Is it possible to drop the machine code once it has been generated for >> particular function while program executing. For example some *void >> test(int)* function has been executed on native machine , I want to drop >> the code before I start execute some other function in my long running >> program. >> > You can disassemble the code once it has been compiled. Mesa's llvmpipe > driver does this: > http://cgit.freedesktop.org/mesa/mesa/tree/src/gallium/auxiliary/gallivm/lp_bld_debug.cpp#n192 > > -Tom > >> Thanks. >> >> With regards >> Sri. >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
This isn't currently supported directly. It depends on what you're doing, which JIT you're using, how you use modules, and to what extent you're relying on LLVM to do linking for you. You can't safely drop a function's code if you have other functions in that module. You can't safely drop a module if there are other modules that have calls that you've already resolved to functions in the module you're dropping unless you have your own mechanism for unlinking those calls. The MCJIT currently does support dropping the memory for a module, but it involves destroying the MCJIT execution engine object. This works best if you use your own JIT memory manager and you steal the executable memory from the MCJIT, and delete the MCJIT after code is generated. Then your own memory manager can manage the memory however you like. This depends on not having LLVM call instructions resolve to any of the functions you would be dropping. WebKit is an example of a system that does this. Each function gets it's own module and all LLVM data structures are dropped once the code is compiled. Call instructions are only used for intrinsics and for runtime calls; source level calls are implemented as patchpoints and WebKit does all of the linking (and unlinking). Long story short, there is no shrink-wrapped solution but it's doable if you're willing to get dirty. -Fil> On Apr 25, 2014, at 3:44 PM, Sri <emdcdeveloper at gmail.com> wrote: > > Hi > Currently , I have doing some experimental work by using llvm, Is it possible to drop the machine code once it has been generated for particular function while program executing. For example some void test(int) function has been executed on native machine , I want to drop the code before I start execute some other function in my long running program. > > Thanks. > > With regards > Sri. > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140425/06d0c4a3/attachment.html>
Hi Filip Thank you for your detailed explanation, I was actually looking to implement an adaptive approach which is basically when some function executed more frequently, I was trying to drop that function and compiled and linked with new optimized function. I just did the following - whenever some function executed more times , I called-back to program, so I that I could be able to call freeMachineCodeForFunction (F) then I compiled that more frequent function with some kind of optimization. But , still I am getting previous function signature and not newest one. Could you please explain , why we can not use this freeMachineCodeForFunction for this purpose. If not, how we can hook some instruction in emitted machine code that will call back to our code in llvm. Thanks With regards Sri. On 04/26/2014 05:39 AM, Filip Pizlo wrote:> This isn't currently supported directly. It depends on what you're > doing, which JIT you're using, how you use modules, and to what extent > you're relying on LLVM to do linking for you. > > You can't safely drop a function's code if you have other functions in > that module. > > You can't safely drop a module if there are other modules that have > calls that you've already resolved to functions in the module you're > dropping unless you have your own mechanism for unlinking those calls. > > The MCJIT currently does support dropping the memory for a module, but > it involves destroying the MCJIT execution engine object. This works > best if you use your own JIT memory manager and you steal the > executable memory from the MCJIT, and delete the MCJIT after code is > generated. Then your own memory manager can manage the memory however > you like. This depends on not having LLVM call instructions resolve to > any of the functions you would be dropping. WebKit is an example of a > system that does this. Each function gets it's own module and all LLVM > data structures are dropped once the code is compiled. Call > instructions are only used for intrinsics and for runtime calls; > source level calls are implemented as patchpoints and WebKit does all > of the linking (and unlinking). > > Long story short, there is no shrink-wrapped solution but it's doable > if you're willing to get dirty. > > -Fil > > On Apr 25, 2014, at 3:44 PM, Sri <emdcdeveloper at gmail.com > <mailto:emdcdeveloper at gmail.com>> wrote: > >> Hi >> Currently , I have doing some experimental work by using >> llvm, Is it possible to drop the machine code once it has been >> generated for particular function while program executing. For >> example some *void test(int)* function has been executed on native >> machine , I want to drop the code before I start execute some other >> function in my long running program. >> >> Thanks. >> >> With regards >> Sri. >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu <mailto:LLVMdev at cs.uiuc.edu> http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140426/dbdda3af/attachment.html>