summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2010-07-03 09:25:20 +0000
committerJohn McCall <rjmccall@apple.com>2010-07-03 09:25:20 +0000
commit1180f8e90f4bad6c51718af8e3bfa414201dd38b (patch)
tree29762d4bd8e916181481ba5bad62bf07274b33d6 /clang/lib/CodeGen
parentc8f595212ffcb3e6d599e6a51e3065c0572191b9 (diff)
downloadbcm5719-llvm-1180f8e90f4bad6c51718af8e3bfa414201dd38b.tar.gz
bcm5719-llvm-1180f8e90f4bad6c51718af8e3bfa414201dd38b.zip
Provide convenience routines to save and restore the current insertion
point. llvm-svn: 107570
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r--clang/lib/CodeGen/CGBuilder.h55
1 files changed, 52 insertions, 3 deletions
diff --git a/clang/lib/CodeGen/CGBuilder.h b/clang/lib/CodeGen/CGBuilder.h
index ed56bd91377..33d868920dc 100644
--- a/clang/lib/CodeGen/CGBuilder.h
+++ b/clang/lib/CodeGen/CGBuilder.h
@@ -14,12 +14,61 @@
namespace clang {
namespace CodeGen {
- // Don't preserve names on values in an optimized build.
+
+// Don't preserve names on values in an optimized build.
#ifdef NDEBUG
- typedef llvm::IRBuilder<false> CGBuilderTy;
+typedef llvm::IRBuilder<false> CGBuilderSuperTy;
#else
- typedef llvm::IRBuilder<> CGBuilderTy;
+typedef llvm::IRBuilder<> CGBuilderSuperTy;
#endif
+
+/// IR generation's wrapper around an LLVM IRBuilder.
+class CGBuilderTy : public CGBuilderSuperTy {
+public:
+ CGBuilderTy(llvm::LLVMContext &Context) : CGBuilderSuperTy(Context) {}
+ CGBuilderTy(llvm::BasicBlock *Block) : CGBuilderSuperTy(Block) {}
+ CGBuilderTy(llvm::BasicBlock *Block, llvm::BasicBlock::iterator Point)
+ : CGBuilderSuperTy(Block, Point) {}
+
+ CGBuilderTy(const CGBuilderTy &Builder)
+ : CGBuilderSuperTy(Builder.getContext()) {
+
+ if (Builder.GetInsertBlock())
+ SetInsertPoint(Builder.GetInsertBlock(), Builder.GetInsertPoint());
+ }
+
+ /// A saved insertion point.
+ class InsertPoint {
+ llvm::BasicBlock *Block;
+ llvm::BasicBlock::iterator Point;
+
+ public:
+ InsertPoint(llvm::BasicBlock *Block, llvm::BasicBlock::iterator Point)
+ : Block(Block), Point(Point) {}
+
+ bool isSet() const { return (Block != 0); }
+ llvm::BasicBlock *getBlock() const { return Block; }
+ llvm::BasicBlock::iterator getPoint() const { return Point; }
+ };
+
+ InsertPoint saveIP() const {
+ return InsertPoint(GetInsertBlock(), GetInsertPoint());
+ }
+
+ InsertPoint saveAndClearIP() {
+ InsertPoint IP(GetInsertBlock(), GetInsertPoint());
+ ClearInsertionPoint();
+ return IP;
+ }
+
+ void restoreIP(InsertPoint IP) {
+ if (IP.isSet())
+ SetInsertPoint(IP.getBlock(), IP.getPoint());
+ else
+ ClearInsertionPoint();
+ }
+};
+
} // end namespace CodeGen
} // end namespace clang
OpenPOWER on IntegriCloud