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