]> granicus.if.org Git - clang/blobdiff - lib/CodeGen/CGBuilder.h
Header guard canonicalization, clang part.
[clang] / lib / CodeGen / CGBuilder.h
index 33d868920dcbafaf0de8438c17287d1b69053613..5269fb81e7cc18d4a74e9a150c0eb75c6995177b 100644 (file)
@@ -7,67 +7,47 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef CLANG_CODEGEN_CGBUILDER_H
-#define CLANG_CODEGEN_CGBUILDER_H
+#ifndef LLVM_CLANG_LIB_CODEGEN_CGBUILDER_H
+#define LLVM_CLANG_LIB_CODEGEN_CGBUILDER_H
 
-#include "llvm/Support/IRBuilder.h"
+#include "llvm/IR/IRBuilder.h"
 
 namespace clang {
 namespace CodeGen {
 
+class CodeGenFunction;
+
+/// \brief This is an IRBuilder insertion helper that forwards to
+/// CodeGenFunction::InsertHelper, which adds nesessary metadata to
+/// instructions.
+template <bool PreserveNames>
+class CGBuilderInserter
+  : protected llvm::IRBuilderDefaultInserter<PreserveNames> {
+public:
+  CGBuilderInserter() : CGF(nullptr) {}
+  explicit CGBuilderInserter(CodeGenFunction *CGF) : CGF(CGF) {}
+
+protected:
+  /// \brief This forwards to CodeGenFunction::InsertHelper.
+  void InsertHelper(llvm::Instruction *I, const llvm::Twine &Name,
+                    llvm::BasicBlock *BB,
+                    llvm::BasicBlock::iterator InsertPt) const;
+private:
+  void operator=(const CGBuilderInserter &) LLVM_DELETED_FUNCTION;
+
+  CodeGenFunction *CGF;
+};
+
 // Don't preserve names on values in an optimized build.
 #ifdef NDEBUG
-typedef llvm::IRBuilder<false> CGBuilderSuperTy;
+#define PreserveNames false
 #else
-typedef llvm::IRBuilder<> CGBuilderSuperTy;
+#define PreserveNames true
 #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();
-  }
-};
+typedef CGBuilderInserter<PreserveNames> CGBuilderInserterTy;
+typedef llvm::IRBuilder<PreserveNames, llvm::ConstantFolder,
+                        CGBuilderInserterTy> CGBuilderTy;
+#undef PreserveNames
 
 }  // end namespace CodeGen
 }  // end namespace clang