[llvm-commits] [llvm] r107677 - /llvm/trunk/include/llvm/Support/IRBuilder.h
Nick Lewycky
nicholas at mxc.ca
Tue Jul 6 11:47:00 PDT 2010
On Tue, Jul 6, 2010 at 11:07 AM, John McCall <rjmccall at apple.com> wrote:
> Author: rjmccall
> Date: Tue Jul 6 13:07:52 2010
> New Revision: 107677
>
> URL: http://llvm.org/viewvc/llvm-project?rev=107677&view=rev
> Log:
> Provide an abstraction to save and restore the current insertion point of
> an IRBuilder.
>
>
> Modified:
> llvm/trunk/include/llvm/Support/IRBuilder.h
>
> Modified: llvm/trunk/include/llvm/Support/IRBuilder.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/IRBuilder.h?rev=107677&r1=107676&r2=107677&view=diff
>
> ==============================================================================
> --- llvm/trunk/include/llvm/Support/IRBuilder.h (original)
> +++ llvm/trunk/include/llvm/Support/IRBuilder.h Tue Jul 6 13:07:52 2010
> @@ -97,6 +97,48 @@
> I->setDebugLoc(CurDbgLocation);
> }
>
> + /// InsertPoint - A saved insertion point.
> + class InsertPoint {
> + BasicBlock *Block;
> + BasicBlock::iterator Point;
>
Can't we just store the BasicBlock::iterator? You can always walk from it
(aka. Instruction*) to its parent BasicBlock.
Nick
+
> + public:
> + /// Creates a new insertion point which doesn't point to anything.
> + InsertPoint() : Block(0) {}
> +
> + /// Creates a new insertion point at the given location.
> + InsertPoint(BasicBlock *InsertBlock, BasicBlock::iterator InsertPoint)
> + : Block(InsertBlock), Point(InsertPoint) {}
> +
> + /// isSet - Returns true if this insert point is set.
> + bool isSet() const { return (Block != 0); }
> +
> + llvm::BasicBlock *getBlock() const { return Block; }
> + llvm::BasicBlock::iterator getPoint() const { return Point; }
> + };
> +
> + /// saveIP - Returns the current insert point.
> + InsertPoint saveIP() const {
> + return InsertPoint(GetInsertBlock(), GetInsertPoint());
> + }
> +
> + /// saveAndClearIP - Returns the current insert point, clearing it
> + /// in the process.
> + InsertPoint saveAndClearIP() {
> + InsertPoint IP(GetInsertBlock(), GetInsertPoint());
> + ClearInsertionPoint();
> + return IP;
> + }
> +
> + /// restoreIP - Sets the current insert point to a previously-saved
> + /// location.
> + void restoreIP(InsertPoint IP) {
> + if (IP.isSet())
> + SetInsertPoint(IP.getBlock(), IP.getPoint());
> + else
> + ClearInsertionPoint();
> + }
> +
>
> //===--------------------------------------------------------------------===//
> // Miscellaneous creation methods.
>
> //===--------------------------------------------------------------------===//
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20100706/b9003c38/attachment.html>
More information about the llvm-commits
mailing list