<div class="gmail_quote">On Tue, Jul 6, 2010 at 11:07 AM, John McCall <span dir="ltr"><<a href="mailto:rjmccall@apple.com">rjmccall@apple.com</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;">

Author: rjmccall<br>
Date: Tue Jul  6 13:07:52 2010<br>
New Revision: 107677<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=107677&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=107677&view=rev</a><br>
Log:<br>
Provide an abstraction to save and restore the current insertion point of<br>
an IRBuilder.<br>
<br>
<br>
Modified:<br>
    llvm/trunk/include/llvm/Support/IRBuilder.h<br>
<br>
Modified: llvm/trunk/include/llvm/Support/IRBuilder.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/IRBuilder.h?rev=107677&r1=107676&r2=107677&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/IRBuilder.h?rev=107677&r1=107676&r2=107677&view=diff</a><br>


==============================================================================<br>
--- llvm/trunk/include/llvm/Support/IRBuilder.h (original)<br>
+++ llvm/trunk/include/llvm/Support/IRBuilder.h Tue Jul  6 13:07:52 2010<br>
@@ -97,6 +97,48 @@<br>
       I->setDebugLoc(CurDbgLocation);<br>
   }<br>
<br>
+  /// InsertPoint - A saved insertion point.<br>
+  class InsertPoint {<br>
+    BasicBlock *Block;<br>
+    BasicBlock::iterator Point;<br></blockquote><div><br>Can't we just store the BasicBlock::iterator? You can always walk from it (aka. Instruction*) to its parent BasicBlock.<br><br>Nick<br><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>
+  public:<br>
+    /// Creates a new insertion point which doesn't point to anything.<br>
+    InsertPoint() : Block(0) {}<br>
+<br>
+    /// Creates a new insertion point at the given location.<br>
+    InsertPoint(BasicBlock *InsertBlock, BasicBlock::iterator InsertPoint)<br>
+      : Block(InsertBlock), Point(InsertPoint) {}<br>
+<br>
+    /// isSet - Returns true if this insert point is set.<br>
+    bool isSet() const { return (Block != 0); }<br>
+<br>
+    llvm::BasicBlock *getBlock() const { return Block; }<br>
+    llvm::BasicBlock::iterator getPoint() const { return Point; }<br>
+  };<br>
+<br>
+  /// saveIP - Returns the current insert point.<br>
+  InsertPoint saveIP() const {<br>
+    return InsertPoint(GetInsertBlock(), GetInsertPoint());<br>
+  }<br>
+<br>
+  /// saveAndClearIP - Returns the current insert point, clearing it<br>
+  /// in the process.<br>
+  InsertPoint saveAndClearIP() {<br>
+    InsertPoint IP(GetInsertBlock(), GetInsertPoint());<br>
+    ClearInsertionPoint();<br>
+    return IP;<br>
+  }<br>
+<br>
+  /// restoreIP - Sets the current insert point to a previously-saved<br>
+  /// location.<br>
+  void restoreIP(InsertPoint IP) {<br>
+    if (IP.isSet())<br>
+      SetInsertPoint(IP.getBlock(), IP.getPoint());<br>
+    else<br>
+      ClearInsertionPoint();<br>
+  }<br>
+<br>
   //===--------------------------------------------------------------------===//<br>
   // Miscellaneous creation methods.<br>
   //===--------------------------------------------------------------------===//<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br>