1 //===-- CGBuilder.h - Choose IRBuilder implementation  ----------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLVM_CLANG_LIB_CODEGEN_CGBUILDER_H
11 #define LLVM_CLANG_LIB_CODEGEN_CGBUILDER_H
12 
13 #include "llvm/IR/IRBuilder.h"
14 
15 namespace clang {
16 namespace CodeGen {
17 
18 class CodeGenFunction;
19 
20 /// \brief This is an IRBuilder insertion helper that forwards to
21 /// CodeGenFunction::InsertHelper, which adds necessary metadata to
22 /// instructions.
23 template <bool PreserveNames>
24 class CGBuilderInserter
25   : protected llvm::IRBuilderDefaultInserter<PreserveNames> {
26 public:
CGBuilderInserter()27   CGBuilderInserter() : CGF(nullptr) {}
CGBuilderInserter(CodeGenFunction * CGF)28   explicit CGBuilderInserter(CodeGenFunction *CGF) : CGF(CGF) {}
29 
30 protected:
31   /// \brief This forwards to CodeGenFunction::InsertHelper.
32   void InsertHelper(llvm::Instruction *I, const llvm::Twine &Name,
33                     llvm::BasicBlock *BB,
34                     llvm::BasicBlock::iterator InsertPt) const;
35 private:
36   void operator=(const CGBuilderInserter &) = delete;
37 
38   CodeGenFunction *CGF;
39 };
40 
41 // Don't preserve names on values in an optimized build.
42 #ifdef NDEBUG
43 #define PreserveNames false
44 #else
45 #define PreserveNames true
46 #endif
47 typedef CGBuilderInserter<PreserveNames> CGBuilderInserterTy;
48 typedef llvm::IRBuilder<PreserveNames, llvm::ConstantFolder,
49                         CGBuilderInserterTy> CGBuilderTy;
50 #undef PreserveNames
51 
52 }  // end namespace CodeGen
53 }  // end namespace clang
54 
55 #endif
56