Hey all,<div><br></div><div>Thanks all for such comprehensive feedback and apologies for delayed thanks :) but every time i post on this mailing list i get so much more to know about llvm.</div><div><br></div><div>Thanks again!!</div>
<div>Manish<br><div><br><div class="gmail_quote">On Sat, Aug 27, 2011 at 11:30 PM, John Criswell <span dir="ltr"><<a href="mailto:criswell@illinois.edu">criswell@illinois.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div bgcolor="#FFFFFF" text="#000000">
Dear Manish,<br>
<br>
First, in answer to your original question: yes, there is a pass
that will convert constant expression GEPs used within LLVM
instructions into GEP instructions. SAFECode has a pass called
BreakConstantGEPs in
safecode/trunk/lib/ArrayBoundChecks/BreakConstantGEPs.cpp
(<a href="http://llvm.org/viewvc/llvm-project/safecode/trunk/lib/ArrayBoundChecks/BreakConstantGEPs.cpp?view=log" target="_blank">http://llvm.org/viewvc/llvm-project/safecode/trunk/lib/ArrayBoundChecks/BreakConstantGEPs.cpp?view=log</a>).
It works with LLVM 2.7; updating it to LLVM mainline should be
trivial.<br>
<br>
Second, to reiterate what others have said, you need to determine
whether doing this conversion is a good idea. Converting these
constant expressions into instructions may very well hurt
performance. Blindly doing the conversion is really a quick hack
(SAFECode for LLVM 2.7 employed this hack more often than it should
have; its performance was probably hurt as a result). If all you're
writing is an analysis pass, then you should make your analysis
smart enough to analyze GEP constant expressions as Nick advised.<br>
<br>
Third, for the curious, SAFECode had to convert constant expression
GEPs into GEP instructions due to its pointer rewriting feature.
Basically, I needed to perform a run-time check on the constant
expression GEP to make sure it was in bounds; if it was
out-of-bounds, the check had to return a rewritten pointer value
that would cause a fault on dereference (this is how SAFECode
permits out-of-bound pointers that are never dereferenced; see the
paper by Ruwase and Lam for more details).<br>
<br>
SAFECode converted *all* constant expression GEPs into GEP
instructions. It really should have converted only those that went
out of bounds (which were relatively few in real programs). That's
something I'll have to fix when I reintroduce BreakConstantGEPs into
mainline SAFECode.<br>
:)<br>
<br>
-- John T.<div><div></div><div class="h5"><br>
<br>
On 8/27/2011 2:31 PM, Manish Gupta wrote:
<blockquote type="cite">
<div>Hi Duncan,</div>
<div><br>
</div>
Why to break?
<div>I wish to analyse all the operands of getelemetptr
instructions. For which I iterate over the code and get the
instruction of interest by </div>
<div>getopcode == getelementptr. But the getelementptrs in this
form as in my last mail are getting away from my pass. So i wish
to break it. I have a work around if breaking is not possible,
but I think it may be a common requirement by other passes too. </div>
<div><br>
</div>
<div>Thanks!</div>
<div>Manish</div>
<div><br>
<div class="gmail_quote">On Sat, Aug 27, 2011 at 12:41 AM,
Duncan Sands <span dir="ltr"><<a href="mailto:baldrick@free.fr" target="_blank">baldrick@free.fr</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi
Manish,<br>
<div><br>
> I wish to iterate over all instructions (where opCode
== desired_opCode). I<br>
> could iterate over all the instruction expect the
nested instructions like:<br>
><br>
> %add.ptr229 = getelementptr inbounds i8*
getelementptr inbounds ([4096 x i8]*<br>
> @_Func1, i32 0, i32 0), i64 %idx.ext228<br>
<br>
</div>
this is not a nested instruction. The inner getelementptr
is a ConstantExpr<br>
(a constant) not an instruction.<br>
<div><br>
> I wish to break this nested instruction in two
instructions.<br>
<br>
</div>
Why?<br>
<br>
Ciao, Duncan.<br>
<div><br>
Please let me know<br>
> if there is already existing method in llvm to do the
job.<br>
><br>
> Thanks,<br>
> Manish<br>
><br>
><br>
</div>
> _______________________________________________<br>
> LLVM Developers mailing list<br>
> <a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>
<a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>
<a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
</blockquote>
</div>
<br>
</div>
<br>
<fieldset></fieldset>
<br>
<pre>_______________________________________________
LLVM Developers mailing list
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a>
</pre>
</blockquote>
<br>
</div></div></div>
</blockquote></div><br></div></div>