[cfe-commits] r107570 - /cfe/trunk/lib/CodeGen/CGBuilder.h

Chris Lattner clattner at apple.com
Tue Jul 6 09:26:26 PDT 2010


On Jul 3, 2010, at 2:25 AM, John McCall wrote:

> Author: rjmccall
> Date: Sat Jul  3 04:25:20 2010
> New Revision: 107570
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=107570&view=rev
> Log:
> Provide convenience routines to save and restore the current insertion
> point.

Hi John,

Why not implement this in the main IRBuilder class?  There doesn't seem anything clang-specific here.

-Chris

> 
> 
> Modified:
>    cfe/trunk/lib/CodeGen/CGBuilder.h
> 
> Modified: cfe/trunk/lib/CodeGen/CGBuilder.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuilder.h?rev=107570&r1=107569&r2=107570&view=diff
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGBuilder.h (original)
> +++ cfe/trunk/lib/CodeGen/CGBuilder.h Sat Jul  3 04:25:20 2010
> @@ -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
> 
> 
> 
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits





More information about the cfe-commits mailing list