blob: 6610659131f7edb85a0e4a45e1b77b78b8465869 [file] [log] [blame]
Daniel Dunbarcb463852008-11-01 01:53:16 +00001//===-- 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 Kramer2f5db8b2014-08-13 16:25:19 +000010#ifndef LLVM_CLANG_LIB_CODEGEN_CGBUILDER_H
11#define LLVM_CLANG_LIB_CODEGEN_CGBUILDER_H
Daniel Dunbarcb463852008-11-01 01:53:16 +000012
Chandler Carruthffd55512013-01-02 11:45:17 +000013#include "llvm/IR/IRBuilder.h"
Daniel Dunbarcb463852008-11-01 01:53:16 +000014
15namespace clang {
16namespace CodeGen {
John McCall1180f8e2010-07-03 09:25:20 +000017
Alexander Musman515ad8c2014-05-22 08:54:05 +000018class CodeGenFunction;
19
20/// \brief This is an IRBuilder insertion helper that forwards to
Sanjay Patel4a96d7c2014-09-10 16:59:01 +000021/// CodeGenFunction::InsertHelper, which adds necessary metadata to
Alexander Musman515ad8c2014-05-22 08:54:05 +000022/// instructions.
23template <bool PreserveNames>
24class CGBuilderInserter
25 : protected llvm::IRBuilderDefaultInserter<PreserveNames> {
26public:
27 CGBuilderInserter() : CGF(nullptr) {}
28 explicit CGBuilderInserter(CodeGenFunction *CGF) : CGF(CGF) {}
29
30protected:
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;
35private:
Aaron Ballmanabc18922015-02-15 22:54:08 +000036 void operator=(const CGBuilderInserter &) = delete;
Alexander Musman515ad8c2014-05-22 08:54:05 +000037
38 CodeGenFunction *CGF;
39};
40
John McCall1180f8e2010-07-03 09:25:20 +000041// Don't preserve names on values in an optimized build.
Daniel Dunbar851eec12008-11-12 00:01:12 +000042#ifdef NDEBUG
Alexander Musman515ad8c2014-05-22 08:54:05 +000043#define PreserveNames false
Daniel Dunbar851eec12008-11-12 00:01:12 +000044#else
Alexander Musman515ad8c2014-05-22 08:54:05 +000045#define PreserveNames true
Daniel Dunbar851eec12008-11-12 00:01:12 +000046#endif
Alexander Musman515ad8c2014-05-22 08:54:05 +000047typedef CGBuilderInserter<PreserveNames> CGBuilderInserterTy;
48typedef llvm::IRBuilder<PreserveNames, llvm::ConstantFolder,
49 CGBuilderInserterTy> CGBuilderTy;
50#undef PreserveNames
John McCall1180f8e2010-07-03 09:25:20 +000051
Daniel Dunbarcb463852008-11-01 01:53:16 +000052} // end namespace CodeGen
53} // end namespace clang
54
55#endif