Adrian Ortega
2014-Jun-29 02:56 UTC
[LLVMdev] Wrong behavior modifying and executing llvm::Function with JIT Engine
Hello, The problem I'm having is that I modify a function body by using 'Value::replaceAllUsesWith' and then execute it with the JIT engine several times but I always get the output from the first iteration for all the iterations. This is what I do: I generate the following 2 functions on the fly based on the FunctionType of the declaration below in C code. define i32 @get_int_5(i32, i32) #1 { ret i32 5 } define i32 @get_int_10(i32, i32) #1 { ret i32 10 } I have the following C code: // This is only a declaration // I use this FunctionType to generate the functions above int sum(int a, int b); int get_int() { return sum(a,b); } I replace the call to 'sum()' by calling Value::replaceAllUsesWith for one of the functions generated above, run with JIT. I checked the code generated and it actually changes the call from 'sum()' to 'get_int_5()' and I get a 5 as return value when I call the function with the JIT execution engine. Then I repeat the previous step using 'Value::replaceAllUsesWith' for the next function I generated and run it with JIT. Then again the code generated is what I expected, this time function call changes from 'sum()' to 'get_int_10()', however the problem is I get a 5 instead of a 10. I tried 'recompileAndLinkFunction' as well as 'freeMachineCodeForFunction' and I always get the return value from the first function, and not the second as I should even though the generated code that I dump() says that it has the correct function call. I am using version 3.4 for both clang and llvm. And also I'm using the JIT Engine and not the MCJIT. Do you have have any idea why the references or 'uses' changes are not reflected in the code JIT'ed ? Regards. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140628/8143e8a7/attachment.html>
Yaron Keren
2014-Jun-29 03:40 UTC
[LLVMdev] Wrong behavior modifying and executing llvm::Function with JIT Engine
Hi Adrian, freeMachineCodeForFunction is required but recompileAndLinkFunction is not, you can use getFunction() always. Try to M->dump() calling M->getFunction() where M is the Module *. See if how the changes appear in the module dump as expected. Yaron 2014-06-29 5:56 GMT+03:00 Adrian Ortega <elfus0.1 at gmail.com>:> Hello, > > The problem I'm having is that I modify a function body by using > 'Value::replaceAllUsesWith' and then execute it with the JIT engine several > times but I always get the output from the first iteration for all the > iterations. > > This is what I do: > > > I generate the following 2 functions on the fly based on the FunctionType > of the declaration below in C code. > > > define i32 @get_int_5(i32, i32) #1 { > ret i32 5 > } > > define i32 @get_int_10(i32, i32) #1 { > ret i32 10 > } > > I have the following C code: > > > // This is only a declaration > // I use this FunctionType to generate the functions above > int sum(int a, int b); > > int get_int() > { > return sum(a,b); > } > > I replace the call to 'sum()' by calling Value::replaceAllUsesWith for > one of the functions generated above, run with JIT. I checked the code > generated and it actually changes the call from 'sum()' to 'get_int_5()' > and I get a 5 as return value when I call the function with the JIT > execution engine. > > Then I repeat the previous step using 'Value::replaceAllUsesWith' for the > next function I generated and run it with JIT. Then again the code > generated is what I expected, this time > function call changes from 'sum()' to 'get_int_10()', however the problem > is I get a 5 instead of a 10. > > I tried 'recompileAndLinkFunction' as well as 'freeMachineCodeForFunction' > and I always get the return value from the first function, and not the > second as I should even though the generated code that I dump() says that > it has the correct function call. > > I am using version 3.4 for both clang and llvm. And also I'm using the JIT > Engine and not the MCJIT. > > Do you have have any idea why the references or 'uses' changes are not > reflected in the code JIT'ed ? > > Regards. > > > > > > > > > _______________________________________________ > 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/20140629/7fbca722/attachment.html>
Yaron Keren
2014-Jun-29 03:48 UTC
[LLVMdev] Wrong behavior modifying and executing llvm::Function with JIT Engine
getFunction() -> getPointerToFunction() 2014-06-29 6:40 GMT+03:00 Yaron Keren <yaron.keren at gmail.com>:> Hi Adrian, > > freeMachineCodeForFunction is required but recompileAndLinkFunction is > not, > you can use getFunction() always. > > Try to M->dump() calling M->getFunction() where M is the Module *. > See if how the changes appear in the module dump as expected. > > Yaron > > > > > > 2014-06-29 5:56 GMT+03:00 Adrian Ortega <elfus0.1 at gmail.com>: > >> Hello, >> >> The problem I'm having is that I modify a function body by using >> 'Value::replaceAllUsesWith' and then execute it with the JIT engine several >> times but I always get the output from the first iteration for all the >> iterations. >> >> This is what I do: >> >> >> I generate the following 2 functions on the fly based on the FunctionType >> of the declaration below in C code. >> >> >> define i32 @get_int_5(i32, i32) #1 { >> ret i32 5 >> } >> >> define i32 @get_int_10(i32, i32) #1 { >> ret i32 10 >> } >> >> I have the following C code: >> >> >> // This is only a declaration >> // I use this FunctionType to generate the functions above >> int sum(int a, int b); >> >> int get_int() >> { >> return sum(a,b); >> } >> >> I replace the call to 'sum()' by calling Value::replaceAllUsesWith for >> one of the functions generated above, run with JIT. I checked the code >> generated and it actually changes the call from 'sum()' to 'get_int_5()' >> and I get a 5 as return value when I call the function with the JIT >> execution engine. >> >> Then I repeat the previous step using 'Value::replaceAllUsesWith' for the >> next function I generated and run it with JIT. Then again the code >> generated is what I expected, this time >> function call changes from 'sum()' to 'get_int_10()', however the problem >> is I get a 5 instead of a 10. >> >> I tried 'recompileAndLinkFunction' as well as >> 'freeMachineCodeForFunction' and I always get the return value from the >> first function, and not the second as I should even though the generated >> code that I dump() says that it has the correct function call. >> >> I am using version 3.4 for both clang and llvm. And also I'm using the >> JIT Engine and not the MCJIT. >> >> Do you have have any idea why the references or 'uses' changes are not >> reflected in the code JIT'ed ? >> >> Regards. >> >> >> >> >> >> >> >> >> _______________________________________________ >> 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/20140629/3c309c6f/attachment.html>