Daniel Dunbar | cb46385 | 2008-11-01 01:53:16 +0000 | [diff] [blame] | 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 | |
Benjamin Kramer | 2f5db8b | 2014-08-13 16:25:19 +0000 | [diff] [blame] | 10 | #ifndef LLVM_CLANG_LIB_CODEGEN_CGBUILDER_H |
| 11 | #define LLVM_CLANG_LIB_CODEGEN_CGBUILDER_H |
Daniel Dunbar | cb46385 | 2008-11-01 01:53:16 +0000 | [diff] [blame] | 12 | |
Chandler Carruth | ffd5551 | 2013-01-02 11:45:17 +0000 | [diff] [blame] | 13 | #include "llvm/IR/IRBuilder.h" |
Daniel Dunbar | cb46385 | 2008-11-01 01:53:16 +0000 | [diff] [blame] | 14 | |
| 15 | namespace clang { |
| 16 | namespace CodeGen { |
John McCall | 1180f8e | 2010-07-03 09:25:20 +0000 | [diff] [blame] | 17 | |
Alexander Musman | 515ad8c | 2014-05-22 08:54:05 +0000 | [diff] [blame] | 18 | class CodeGenFunction; |
| 19 | |
| 20 | /// \brief This is an IRBuilder insertion helper that forwards to |
Sanjay Patel | 4a96d7c | 2014-09-10 16:59:01 +0000 | [diff] [blame] | 21 | /// CodeGenFunction::InsertHelper, which adds necessary metadata to |
Alexander Musman | 515ad8c | 2014-05-22 08:54:05 +0000 | [diff] [blame] | 22 | /// instructions. |
| 23 | template <bool PreserveNames> |
| 24 | class CGBuilderInserter |
| 25 | : protected llvm::IRBuilderDefaultInserter<PreserveNames> { |
| 26 | public: |
| 27 | CGBuilderInserter() : CGF(nullptr) {} |
| 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: |
Aaron Ballman | abc1892 | 2015-02-15 22:54:08 +0000 | [diff] [blame] | 36 | void operator=(const CGBuilderInserter &) = delete; |
Alexander Musman | 515ad8c | 2014-05-22 08:54:05 +0000 | [diff] [blame] | 37 | |
| 38 | CodeGenFunction *CGF; |
| 39 | }; |
| 40 | |
John McCall | 1180f8e | 2010-07-03 09:25:20 +0000 | [diff] [blame] | 41 | // Don't preserve names on values in an optimized build. |
Daniel Dunbar | 851eec1 | 2008-11-12 00:01:12 +0000 | [diff] [blame] | 42 | #ifdef NDEBUG |
Alexander Musman | 515ad8c | 2014-05-22 08:54:05 +0000 | [diff] [blame] | 43 | #define PreserveNames false |
Daniel Dunbar | 851eec1 | 2008-11-12 00:01:12 +0000 | [diff] [blame] | 44 | #else |
Alexander Musman | 515ad8c | 2014-05-22 08:54:05 +0000 | [diff] [blame] | 45 | #define PreserveNames true |
Daniel Dunbar | 851eec1 | 2008-11-12 00:01:12 +0000 | [diff] [blame] | 46 | #endif |
Alexander Musman | 515ad8c | 2014-05-22 08:54:05 +0000 | [diff] [blame] | 47 | typedef CGBuilderInserter<PreserveNames> CGBuilderInserterTy; |
| 48 | typedef llvm::IRBuilder<PreserveNames, llvm::ConstantFolder, |
| 49 | CGBuilderInserterTy> CGBuilderTy; |
| 50 | #undef PreserveNames |
John McCall | 1180f8e | 2010-07-03 09:25:20 +0000 | [diff] [blame] | 51 | |
Daniel Dunbar | cb46385 | 2008-11-01 01:53:16 +0000 | [diff] [blame] | 52 | } // end namespace CodeGen |
| 53 | } // end namespace clang |
| 54 | |
| 55 | #endif |