[LLVMdev] Constant function pointers and inlining
Joonas Govenius
joonas.govenius at gmail.com
Sat Jun 21 15:51:06 PDT 2008
On Thu, Jun 19, 2008 at 4:38 PM, Joonas Govenius
<joonas.govenius at gmail.com> wrote:
> However, once I get the
> GenericValue that points to the handler, I don't really know how to
> turn that to a constant function pointer in LLVM. What I do is rather
> complicated:
>
> Value* handler = ConstantExpr::getIntToPtr(
> ConstantInt::get(Type::Int32Ty,
> (unsigned int) engine->runFunction(get_handler, args).PointerVal),
> PointerType::get(handler_type, 0));
>
Ok, so I moved on to use the
ExecutionEngine::getGlobalValueAtAddress() to do the job:
void* handler_raw = GVTOP(engine->runFunction(get_handler, args));
Function* handler = (Function*) engine->getGlobalValueAtAddress(handler_raw);
That works great except that I have to make sure that the handler in
question has already been JIT compiled; otherwise handler_raw will
just contain a pointer to the corresponding codegen call instruction,
which getGlobalValueAtAddress() doesn't recognize.
Right now I'm ensuring compilation by calling
engine->getPointerToGlobal(mod->getFunction(handler_name)) beforehand
but that's no good because the whole point is that I'm not supposed to
know the handler_name string since it's internal to the Zend (PHP)
engine. Any ideas how I could force compilation and return the true
address of the handler from within the "get_handler" function without
actually calling the handler?
Thanks,
Joonas
More information about the llvm-dev
mailing list