Provide an abstraction to save and restore the current insertion point of

an IRBuilder.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@107677 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
John McCall 2010-07-06 18:07:52 +00:00
parent a5e82a5748
commit 5ed9eee61a

View File

@ -97,6 +97,48 @@ public:
I->setDebugLoc(CurDbgLocation);
}
/// InsertPoint - A saved insertion point.
class InsertPoint {
BasicBlock *Block;
BasicBlock::iterator Point;
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.
//===--------------------------------------------------------------------===//