[LLVMdev] retrieve information from a macro inlined as x86_64 asm in LLVM IR
John McCall
rjmccall at apple.com
Tue Jun 28 09:09:46 PDT 2011
On Jun 28, 2011, at 8:40 AM, Jimborean Alexandra wrote:
> Hi LLVM devs,
>
> I work on a pass that creates multiple versions of a code region and switches between them. The decision about the version to be selected is taken by an external runtime system. I insert callbacks to this system in my code to pass the control of the execution. All callbacks are written in inline assembly, in macros.
> The problem comes when I need to send some information from the runtime system, back to the code.
> I create one local variable :
>
> lim = new AllocaInst(.......);
>
> and I want the value of %lim to be set by the runtime system. For this, I want to create a macro that takes as parameter the address of this variable, such that the runtime system can put the value it computes in this address, at runtime. (Similar to sending a parameter by reference. )
> If I send the address of the Value* lim as a param to the macro, it puts the hardcoded address (as expected).
>
> std::stringstream out;
> out.str(std::string()); out << &lim;
This is very confused. 'lim' is a local variable containing a pointer to an AllocaInst; taking its address will give you a pointer into the stack frame of the compiler, which is generally not even in the same process as where the code will run.
The value represented by an AllocaInst *is* the address of the allocated memory; just use that as an operand to the inline assembly. That said...
> creates the call:
> camus_macro_decision 0x7fffdf3172f0
...this is not valid x86-64 assembly at all. If you're just trying to call a function, passing the address of your local variable, just use an LLVM call instruction, like so:
llvm::Constant *fn = module.getOrInsertFunction("camus_macro_decision", fnType);
builder.CreateCall(fn, lim);
Note that you probably want the alloca to be inserted in the entry block; see the documentation for more on that.
John.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110628/c72e10b5/attachment.html>
More information about the llvm-dev
mailing list