Hi Chris,<br><br><div class="gmail_quote">2009/2/21 Chris Lattner <span dir="ltr"><<a href="mailto:clattner@apple.com" target="_blank">clattner@apple.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

On Feb 20, 2009, at 8:31 AM, Zhou Sheng wrote:<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Author: sheng<br>
Date: Fri Feb 20 10:31:35 2009<br>
New Revision: 65123<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=65123&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=65123&view=rev</a><br>
Log:<br>
patch to update the line number information in pass -mem2reg.<br>
Currently this pass will delete the variable declaration info,<br>
and keep the line number info. But the kept line number info is not updated,<br>
and some is redundant or not correct, this patch just updates those info.<br>
</blockquote>
<br>
Hi Sheng,<br>
<br>
High level question: why do you want mem2reg to do this?  Doesn't instcombine already do it?  If not, it should.</blockquote><div><br>Yes, instcombine already can do  this.  Sorry for the stupid check in, just rolled back<br>

 </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
+/// Remove the invalid or redundant debug information.<br>
+static void CleanDbgInfo(Function& F) {<br>
+  std::vector<Instruction*> DeadDbgs;<br>
+  for (Function::iterator BBI = F.begin(), BBE = F.end(); BBI != BBE; ++BBI) {<br>
+    if (BBI->size() <= 1)<br>
+      continue;<br>
</blockquote>
<br>
size() is O(n), please don't call it here.<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
+    for (BasicBlock::iterator I = BBI->begin(), E = BBI->getTerminator();<br>
+         I != E; ++I) {<br>
+      BasicBlock::iterator NextI = I;<br>
+      ++NextI;<br>
+      if (isa<DbgStopPointInst>(I) && isa<DbgStopPointInst>(NextI))<br>
+        DeadDbgs.push_back(I);<br>
</blockquote>
<br>
You don't need the temporary vector, just preincrement the iterator.<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
+      else if (isa<DbgStopPointInst>(I) && isa<BranchInst>(NextI))<br>
+        DeadDbgs.push_back(I);<br>
+    }<br>
</blockquote>
<br>
Deleting stoppoints before branches isn't correct.  You can have control flow within a line (e.g. ?: expressions) and the intermediate blocks need to get that stoppoint.<br><font color="#888888">
<br>
-Chris<br>
</font></blockquote></div><br>