1 //===-- CGBuilder.h - Choose IRBuilder implementation ----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef CLANG_CODEGEN_CGBUILDER_H
11 #define CLANG_CODEGEN_CGBUILDER_H
13 #include "llvm/Support/IRBuilder.h"
18 // Don't preserve names on values in an optimized build.
20 typedef llvm::IRBuilder<false> CGBuilderSuperTy;
22 typedef llvm::IRBuilder<> CGBuilderSuperTy;
25 /// IR generation's wrapper around an LLVM IRBuilder.
26 class CGBuilderTy : public CGBuilderSuperTy {
28 CGBuilderTy(llvm::LLVMContext &Context) : CGBuilderSuperTy(Context) {}
29 CGBuilderTy(llvm::BasicBlock *Block) : CGBuilderSuperTy(Block) {}
30 CGBuilderTy(llvm::BasicBlock *Block, llvm::BasicBlock::iterator Point)
31 : CGBuilderSuperTy(Block, Point) {}
33 CGBuilderTy(const CGBuilderTy &Builder)
34 : CGBuilderSuperTy(Builder.getContext()) {
36 if (Builder.GetInsertBlock())
37 SetInsertPoint(Builder.GetInsertBlock(), Builder.GetInsertPoint());
40 /// A saved insertion point.
42 llvm::BasicBlock *Block;
43 llvm::BasicBlock::iterator Point;
46 InsertPoint(llvm::BasicBlock *Block, llvm::BasicBlock::iterator Point)
47 : Block(Block), Point(Point) {}
49 bool isSet() const { return (Block != 0); }
50 llvm::BasicBlock *getBlock() const { return Block; }
51 llvm::BasicBlock::iterator getPoint() const { return Point; }
54 InsertPoint saveIP() const {
55 return InsertPoint(GetInsertBlock(), GetInsertPoint());
58 InsertPoint saveAndClearIP() {
59 InsertPoint IP(GetInsertBlock(), GetInsertPoint());
60 ClearInsertionPoint();
64 void restoreIP(InsertPoint IP) {
66 SetInsertPoint(IP.getBlock(), IP.getPoint());
68 ClearInsertionPoint();
72 } // end namespace CodeGen
73 } // end namespace clang