clang API Documentation
00001 //===-- CGBuilder.h - Choose IRBuilder implementation ----------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 00010 #ifndef LLVM_CLANG_LIB_CODEGEN_CGBUILDER_H 00011 #define LLVM_CLANG_LIB_CODEGEN_CGBUILDER_H 00012 00013 #include "llvm/IR/IRBuilder.h" 00014 00015 namespace clang { 00016 namespace CodeGen { 00017 00018 class CodeGenFunction; 00019 00020 /// \brief This is an IRBuilder insertion helper that forwards to 00021 /// CodeGenFunction::InsertHelper, which adds necessary metadata to 00022 /// instructions. 00023 template <bool PreserveNames> 00024 class CGBuilderInserter 00025 : protected llvm::IRBuilderDefaultInserter<PreserveNames> { 00026 public: 00027 CGBuilderInserter() : CGF(nullptr) {} 00028 explicit CGBuilderInserter(CodeGenFunction *CGF) : CGF(CGF) {} 00029 00030 protected: 00031 /// \brief This forwards to CodeGenFunction::InsertHelper. 00032 void InsertHelper(llvm::Instruction *I, const llvm::Twine &Name, 00033 llvm::BasicBlock *BB, 00034 llvm::BasicBlock::iterator InsertPt) const; 00035 private: 00036 void operator=(const CGBuilderInserter &) LLVM_DELETED_FUNCTION; 00037 00038 CodeGenFunction *CGF; 00039 }; 00040 00041 // Don't preserve names on values in an optimized build. 00042 #ifdef NDEBUG 00043 #define PreserveNames false 00044 #else 00045 #define PreserveNames true 00046 #endif 00047 typedef CGBuilderInserter<PreserveNames> CGBuilderInserterTy; 00048 typedef llvm::IRBuilder<PreserveNames, llvm::ConstantFolder, 00049 CGBuilderInserterTy> CGBuilderTy; 00050 #undef PreserveNames 00051 00052 } // end namespace CodeGen 00053 } // end namespace clang 00054 00055 #endif