<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On 16 October 2015 at 11:39, Irini Stavrakantonaki via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
<br>
On 16/10/15 12:59, David Chisnall wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On 16 Oct 2015, at 10:44, Irini Stavrakantonaki via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Following call instruction contains a GEP instruction as its first operand<br>
</blockquote>
No it doesn’t.  It contains a GEP constant expression.  This is a bit confusing at first, especially when working with IRBuilder, which can sometimes give you constant expressions when you think that you’re asking for instructions.  The constant expression, unlike an instruction, has no variable operands and no side effects, and so is guaranteed to be constant.<br>
<br>
There are passes that will do the opposite of what you’re requesting (turn side-effect-free instructions with constant operands into constant expressions), but nothing to work the other way around.  This makes some things easier (you can easily see that the operand to the call is a constant, without having to look at the sequence of operations that generates it), but other things more difficult (you need to handle GEP instructions and GEP constant expressions).<br>
<br>
It would be quite nice to have a set of adaptor classes for the operations that can be either constant expressions or instructions, for use in the places where you don’t care which (just as CallSite wraps either an invoke or a call, in places that don’t need to handle them differently).  There are a few thing that do make this easier:<br>
<br>
- Both Instruction and ConstantExpression are subclasses of Value<br>
<br>
- (I think) the OpCode for both will be the same, so you can switch on that and then only cast further if you care.<br>
<br>
David<br>
<br>
</blockquote>
<br></span>
Thanks, David. I had misunderstood and thought that arguments were GEP instructions.<br>
Being GEP constant expressions, solves my issue!<br>
Thanks a lot again,<br></blockquote><div><br></div><div>I think it's important to understand that this is not ALWAYS the case. The operands can be either a constant expression or an instruction.<br><br></div><div>For example:<br> <br></div><div>     char *a;<br></div><div>     int x;<br></div><div><br></div><div>     if(cond) a = "%d";<br></div><div>     else a = "%x";<br></div><div>     printf(a, x);<br><br></div><div>In this case, the compiler may still be able to convert to constant expression for `a`, depending on if it's able to deduce `cond`. But if `cond` is not "constant", `a` will be a GEP instruction, not a constant expression.<br></div><div>(Of course, the compiler will probably also warn that passing a variable to printf is a bad idea, but that's a different matter)<br><br>--<br></div><div>Mats<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
--istavrak<div class="HOEnZb"><div class="h5"><br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</div></div></blockquote></div><br></div></div>