<html><head><base href="x-msg://10251/"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Jun 28, 2011, at 8:40 AM, Jimborean Alexandra wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font-family: arial, helvetica, sans-serif; font-size: 10pt; color: rgb(0, 0, 0); "><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Hi LLVM devs,<br><br>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.<span class="Apple-converted-space"> </span><br>The problem comes when I need to send some information from the runtime system, back to the code.<span class="Apple-converted-space"> </span><br>I create one local variable :<span class="Apple-converted-space"> </span><br><br>lim = new AllocaInst(.......);<span class="Apple-converted-space"> </span><br><br>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. )<br>If I send the address of the  Value* lim as a param to the macro, it puts the hardcoded address (as expected). <span class="Apple-converted-space"> </span><br><br>std::stringstream out;<br>out.str(std::string()); out << &lim;<br></div></div></div></span></blockquote><div><br></div>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.</div><div><br></div><div>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...</div><div><br></div><div><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font-family: arial, helvetica, sans-serif; font-size: 10pt; color: rgb(0, 0, 0); "><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">creates the call:  <span class="Apple-converted-space"> </span><br>camus_macro_decision   0x7fffdf3172f0<br></div></div></div></span></blockquote><div><br></div>...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:</div><div><br></div><div>  llvm::Constant *fn = module.getOrInsertFunction("camus_macro_decision", fnType);</div><div>  builder.CreateCall(fn, lim);</div><div><br></div><div>Note that you probably want the alloca to be inserted in the entry block;  see the documentation for more on that.</div><div><br></div><div>John.</div></body></html>