[LLVMdev] Wrong behavior modifying and executing llvm::Function with JIT Engine

Adrian Ortega elfus0.1 at gmail.com
Sat Jun 28 19:56:06 PDT 2014


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>


More information about the llvm-dev mailing list