Thank you guys for the tips, now it's working!<br>The problem was really concerned on the BasicBlock::iterator invalidation.<br><br>Best regards,<br>Alysson<br><br><div class="gmail_quote">On Mon, Jun 21, 2010 at 12:40 AM, Nick Lewycky <span dir="ltr"><<a href="mailto:nicholas@mxc.ca">nicholas@mxc.ca</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="im">Alysson wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi LLVMers,<br>
<br>
     I am working on my llvm school project optimization pass. It's<br>
relatively simple, and it tries to remove redundant bitcast instructions<br>
followed by load instructions. At first, I'm using as input a bytecode<br>
generated by a simple Java test program.<br>
     I've already found the reduntant instructions by looking at it's<br>
CFG, and I also could implement the code to substitute their references,<br>
in order to eliminate all dependencies on these instructions (the number<br>
of their uses are changed to zero).<br>
    The point is that when I finally attempt to remove the redundant<br>
unused instructions from the generated code, there is a seg fault error.<br>
    To remove them, I'm using this function:<br>
<br>
void EraseInst(Instruction &I) {<br>
             assert(I.use_empty() && "Cannot erase used instructions!");<br>
             I.eraseFromParent();<br>
}<br>
</blockquote>
<br></div>
The problem is in how you use it:<br>
<br>
  for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; I++) {              <br>
    if (I->use_empty() && dyn_cast<LoadInst>(I)) {<br>
      errs() << "*****Instruction unused*****" << "\n";<br>
      errs() << *I << "\n";<br>
      EraseInst(*I);<br>
    }<br>
  }<br>
<br>
Once you call EraseInst, you can't use it again in the I++ part of your for loop. You'll have to restructure your loop so that you increment before erasing your instruction, and erase the one you haven't incremented yet.<br>


<br>
Nick<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="im">
<br>
So please, if anyone could help me on this, i would be very grateful!<br>
<br>
PS: It's also following my pass and the bytecode used for tests.<br>
<br>
Thanks for the attention,<br>
Alysson<br>
<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>
</blockquote>
<br>
</blockquote></div><br>