[LLVMdev] question about the LLVM JIT
Eric van Riet Paap
eric at vanrietpaap.nl
Wed Nov 29 15:17:26 PST 2006
>> <snip>.
>> void add_global_mapping(const char* name, void* address) {
>> GlobalVariable var(Type::IntTy, false,
>> GlobalVariable::ExternalLinkage, 0, name, gp_module);
>> gp_execution_engine->addGlobalMapping(&var, address);
>> }
>
> This is creating a new global variable on the stack, instead of
> finding the existing global variable in the module. Try something
> like this:
>
> gp_execution_engine->addGlobalMapping(YourModule->getNamedGlobal
> (name),
> address);
>
Hi Chris,
Thanks, that was simpler than I thought!
I actually thought I had to create a new global so it would be
available for the JIT when it gets to process the "%var = external
global int" line.
> <snip>
>
>> I do not see how I can tell the jit when this .ll code contains a
>> function that should overwrite a previous version of it.
>> For instance, when there is a function "int %func() { ret int 5 }"
>> and later I want this replaced by "int %func() { ret int 10 }".
>> If I remember correctly this gives a 'function already defined'
>> error message. I tried to use a seperate module for each call to
>> ParseAssemblyString + addModuleProvider.
>> In that way there was a problem with functions calling into other
>> modules. (which perhaps I could try to solve if would understand
>> addGlobalMapping better)
>
> This is somewhat tricky. To replace a function in-place like this,
> you should actually modify the function in the original module,
> then call EE->recompileAndRelinkFunction(fn). This will require
> some C++ code to delete the original function body, then splice the
> body of the new function into the old function.
For my purpose it would be ideal if I could give ParseAssemblyString
an additional option (or maybe set a global flag somehow) to indicate
what should happen when an already defined function is parsed. Would
something like this be possible and fit into llvm's design?
>>> Eric
More information about the llvm-dev
mailing list