Daniel Dunbar | 9c42652 | 2008-07-29 23:18:29 +0000 | [diff] [blame] | 1 | //===--- CodeGenModule.h - Per-Module state for LLVM CodeGen ----*- C++ -*-===// |
Chris Lattner | f97fe38 | 2007-05-24 06:29:05 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 5b12ab8 | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Chris Lattner | f97fe38 | 2007-05-24 06:29:05 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Mike Stump | 1676c5b | 2009-02-13 19:12:34 +0000 | [diff] [blame] | 10 | // This is the internal per-translation-unit state used for llvm translation. |
Chris Lattner | f97fe38 | 2007-05-24 06:29:05 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Chris Lattner | c18bfbb | 2008-02-29 17:10:38 +0000 | [diff] [blame] | 14 | #ifndef CLANG_CODEGEN_CODEGENMODULE_H |
| 15 | #define CLANG_CODEGEN_CODEGENMODULE_H |
Chris Lattner | f97fe38 | 2007-05-24 06:29:05 +0000 | [diff] [blame] | 16 | |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 17 | #include "CGVTables.h" |
| 18 | #include "CodeGenTypes.h" |
Dan Gohman | 75d69da | 2008-05-22 00:50:06 +0000 | [diff] [blame] | 19 | #include "clang/AST/Attr.h" |
Anders Carlsson | dae1abc | 2009-05-05 04:44:02 +0000 | [diff] [blame] | 20 | #include "clang/AST/DeclCXX.h" |
Anders Carlsson | 73fcc95 | 2009-09-11 00:07:24 +0000 | [diff] [blame] | 21 | #include "clang/AST/DeclObjC.h" |
Peter Collingbourne | ee781d5 | 2011-06-14 04:02:39 +0000 | [diff] [blame] | 22 | #include "clang/AST/GlobalDecl.h" |
Peter Collingbourne | 0ff0b37 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 23 | #include "clang/AST/Mangle.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 24 | #include "clang/Basic/ABI.h" |
| 25 | #include "clang/Basic/LangOptions.h" |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 26 | #include "clang/Basic/Module.h" |
Chris Lattner | b6984c4 | 2007-06-20 04:44:43 +0000 | [diff] [blame] | 27 | #include "llvm/ADT/DenseMap.h" |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 28 | #include "llvm/ADT/SetVector.h" |
Rafael Espindola | 2e42fec | 2010-03-04 18:17:24 +0000 | [diff] [blame] | 29 | #include "llvm/ADT/SmallPtrSet.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 30 | #include "llvm/ADT/StringMap.h" |
John McCall | 882987f | 2013-02-28 19:01:20 +0000 | [diff] [blame] | 31 | #include "llvm/IR/CallingConv.h" |
Chandler Carruth | ffd5551 | 2013-01-02 11:45:17 +0000 | [diff] [blame] | 32 | #include "llvm/IR/Module.h" |
Chandler Carruth | 61743af | 2014-03-04 11:18:19 +0000 | [diff] [blame] | 33 | #include "llvm/IR/ValueHandle.h" |
Peter Collingbourne | 41148a8 | 2013-07-09 22:03:30 +0000 | [diff] [blame] | 34 | #include "llvm/Transforms/Utils/SpecialCaseList.h" |
Anders Carlsson | 762e162 | 2009-01-04 02:08:04 +0000 | [diff] [blame] | 35 | |
Chris Lattner | f97fe38 | 2007-05-24 06:29:05 +0000 | [diff] [blame] | 36 | namespace llvm { |
| 37 | class Module; |
Chris Lattner | 2052bc8 | 2007-06-16 00:12:05 +0000 | [diff] [blame] | 38 | class Constant; |
John McCall | 23c29fe | 2011-06-24 21:55:10 +0000 | [diff] [blame] | 39 | class ConstantInt; |
Chris Lattner | 09153c0 | 2007-06-22 18:48:09 +0000 | [diff] [blame] | 40 | class Function; |
Nate Begeman | faae081 | 2008-04-19 04:17:09 +0000 | [diff] [blame] | 41 | class GlobalValue; |
Micah Villmow | dd31ca1 | 2012-10-08 16:25:52 +0000 | [diff] [blame] | 42 | class DataLayout; |
Eli Friedman | f6b091f | 2008-06-01 15:54:49 +0000 | [diff] [blame] | 43 | class FunctionType; |
Benjamin Kramer | 9cd050a | 2009-08-11 17:46:57 +0000 | [diff] [blame] | 44 | class LLVMContext; |
Justin Bogner | 837a6f6 | 2014-04-18 21:52:00 +0000 | [diff] [blame^] | 45 | class IndexedInstrProfReader; |
Chris Lattner | 23b7eb6 | 2007-06-15 23:05:46 +0000 | [diff] [blame] | 46 | } |
| 47 | |
Chris Lattner | f97fe38 | 2007-05-24 06:29:05 +0000 | [diff] [blame] | 48 | namespace clang { |
Anton Korobeynikov | 55bcea1 | 2010-01-10 12:58:08 +0000 | [diff] [blame] | 49 | class TargetCodeGenInfo; |
Chris Lattner | f97fe38 | 2007-05-24 06:29:05 +0000 | [diff] [blame] | 50 | class ASTContext; |
John McCall | a8ec7eb | 2013-03-07 21:37:17 +0000 | [diff] [blame] | 51 | class AtomicType; |
Chris Lattner | f97fe38 | 2007-05-24 06:29:05 +0000 | [diff] [blame] | 52 | class FunctionDecl; |
Daniel Dunbar | eb99810 | 2008-08-25 06:18:57 +0000 | [diff] [blame] | 53 | class IdentifierInfo; |
Chris Lattner | 4bd5596 | 2008-03-30 23:03:07 +0000 | [diff] [blame] | 54 | class ObjCMethodDecl; |
Anton Korobeynikov | 1200aca | 2008-06-01 14:13:53 +0000 | [diff] [blame] | 55 | class ObjCImplementationDecl; |
| 56 | class ObjCCategoryImplDecl; |
| 57 | class ObjCProtocolDecl; |
Chris Lattner | d7e7b8e | 2009-02-24 22:18:39 +0000 | [diff] [blame] | 58 | class ObjCEncodeExpr; |
Anders Carlsson | 6a60fa2 | 2009-02-12 17:55:02 +0000 | [diff] [blame] | 59 | class BlockExpr; |
Ken Dyck | 98ca794 | 2010-01-26 13:48:07 +0000 | [diff] [blame] | 60 | class CharUnits; |
Chris Lattner | 2052bc8 | 2007-06-16 00:12:05 +0000 | [diff] [blame] | 61 | class Decl; |
Oliver Hunt | aefc8fd | 2007-12-02 00:11:25 +0000 | [diff] [blame] | 62 | class Expr; |
Chris Lattner | d45aa2a | 2007-12-02 07:19:18 +0000 | [diff] [blame] | 63 | class Stmt; |
Sebastian Redl | 4a7eab2 | 2012-02-25 20:51:20 +0000 | [diff] [blame] | 64 | class InitListExpr; |
Daniel Dunbar | 6dfdf8c | 2008-08-10 20:25:57 +0000 | [diff] [blame] | 65 | class StringLiteral; |
Nate Begeman | 1c90620 | 2008-04-20 20:38:08 +0000 | [diff] [blame] | 66 | class NamedDecl; |
Daniel Dunbar | 9c42652 | 2008-07-29 23:18:29 +0000 | [diff] [blame] | 67 | class ValueDecl; |
Chris Lattner | 37bd2ec | 2007-12-18 08:16:44 +0000 | [diff] [blame] | 68 | class VarDecl; |
Sebastian Redl | 7dce772 | 2009-03-07 12:16:37 +0000 | [diff] [blame] | 69 | class LangOptions; |
Chandler Carruth | bc55fe2 | 2009-11-12 17:24:48 +0000 | [diff] [blame] | 70 | class CodeGenOptions; |
David Blaikie | 9c902b5 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 71 | class DiagnosticsEngine; |
Nate Begeman | faae081 | 2008-04-19 04:17:09 +0000 | [diff] [blame] | 72 | class AnnotateAttr; |
Anders Carlsson | eaa28f7 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 73 | class CXXDestructorDecl; |
Peter Collingbourne | 0ff0b37 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 74 | class MangleBuffer; |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 75 | class Module; |
Mike Stump | 1676c5b | 2009-02-13 19:12:34 +0000 | [diff] [blame] | 76 | |
Chris Lattner | f97fe38 | 2007-05-24 06:29:05 +0000 | [diff] [blame] | 77 | namespace CodeGen { |
| 78 | |
John McCall | a738c25 | 2011-03-09 04:27:21 +0000 | [diff] [blame] | 79 | class CallArgList; |
Lauro Ramos Venancio | 01a72ff | 2008-02-26 21:41:45 +0000 | [diff] [blame] | 80 | class CodeGenFunction; |
Dan Gohman | 947c9af | 2010-10-14 23:06:10 +0000 | [diff] [blame] | 81 | class CodeGenTBAA; |
John McCall | 5d865c32 | 2010-08-31 07:33:07 +0000 | [diff] [blame] | 82 | class CGCXXABI; |
Sanjiv Gupta | 15cb669 | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 83 | class CGDebugInfo; |
Daniel Dunbar | 89da6ad | 2008-08-13 00:59:25 +0000 | [diff] [blame] | 84 | class CGObjCRuntime; |
Peter Collingbourne | 2dbb708 | 2011-09-19 21:14:35 +0000 | [diff] [blame] | 85 | class CGOpenCLRuntime; |
Peter Collingbourne | fe88342 | 2011-10-06 18:29:37 +0000 | [diff] [blame] | 86 | class CGCUDARuntime; |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 87 | class BlockFieldFlags; |
John McCall | a738c25 | 2011-03-09 04:27:21 +0000 | [diff] [blame] | 88 | class FunctionArgList; |
Justin Bogner | ef512b9 | 2014-01-06 22:27:43 +0000 | [diff] [blame] | 89 | |
Chris Lattner | e000907 | 2010-06-27 06:32:58 +0000 | [diff] [blame] | 90 | struct OrderGlobalInits { |
Fariborz Jahanian | 89bdd14 | 2010-06-21 21:27:42 +0000 | [diff] [blame] | 91 | unsigned int priority; |
| 92 | unsigned int lex_order; |
| 93 | OrderGlobalInits(unsigned int p, unsigned int l) |
Chris Lattner | e000907 | 2010-06-27 06:32:58 +0000 | [diff] [blame] | 94 | : priority(p), lex_order(l) {} |
| 95 | |
| 96 | bool operator==(const OrderGlobalInits &RHS) const { |
| 97 | return priority == RHS.priority && |
| 98 | lex_order == RHS.lex_order; |
Fariborz Jahanian | 469b200 | 2010-06-22 00:23:08 +0000 | [diff] [blame] | 99 | } |
| 100 | |
Chris Lattner | e000907 | 2010-06-27 06:32:58 +0000 | [diff] [blame] | 101 | bool operator<(const OrderGlobalInits &RHS) const { |
Benjamin Kramer | a741b8c | 2014-03-03 20:26:46 +0000 | [diff] [blame] | 102 | return std::tie(priority, lex_order) < |
| 103 | std::tie(RHS.priority, RHS.lex_order); |
Fariborz Jahanian | 469b200 | 2010-06-22 00:23:08 +0000 | [diff] [blame] | 104 | } |
Chris Lattner | e000907 | 2010-06-27 06:32:58 +0000 | [diff] [blame] | 105 | }; |
John McCall | e3dc170 | 2011-02-15 09:22:45 +0000 | [diff] [blame] | 106 | |
| 107 | struct CodeGenTypeCache { |
John McCall | 9dc0db2 | 2011-05-15 01:53:33 +0000 | [diff] [blame] | 108 | /// void |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 109 | llvm::Type *VoidTy; |
John McCall | 9dc0db2 | 2011-05-15 01:53:33 +0000 | [diff] [blame] | 110 | |
Chris Lattner | ece0409 | 2012-02-07 00:39:47 +0000 | [diff] [blame] | 111 | /// i8, i16, i32, and i64 |
| 112 | llvm::IntegerType *Int8Ty, *Int16Ty, *Int32Ty, *Int64Ty; |
| 113 | /// float, double |
| 114 | llvm::Type *FloatTy, *DoubleTy; |
John McCall | e3dc170 | 2011-02-15 09:22:45 +0000 | [diff] [blame] | 115 | |
| 116 | /// int |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 117 | llvm::IntegerType *IntTy; |
John McCall | e3dc170 | 2011-02-15 09:22:45 +0000 | [diff] [blame] | 118 | |
John McCall | 9dc0db2 | 2011-05-15 01:53:33 +0000 | [diff] [blame] | 119 | /// intptr_t, size_t, and ptrdiff_t, which we assume are the same size. |
John McCall | e3dc170 | 2011-02-15 09:22:45 +0000 | [diff] [blame] | 120 | union { |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 121 | llvm::IntegerType *IntPtrTy; |
| 122 | llvm::IntegerType *SizeTy; |
| 123 | llvm::IntegerType *PtrDiffTy; |
John McCall | e3dc170 | 2011-02-15 09:22:45 +0000 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | /// void* in address space 0 |
| 127 | union { |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 128 | llvm::PointerType *VoidPtrTy; |
| 129 | llvm::PointerType *Int8PtrTy; |
John McCall | e3dc170 | 2011-02-15 09:22:45 +0000 | [diff] [blame] | 130 | }; |
| 131 | |
| 132 | /// void** in address space 0 |
| 133 | union { |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 134 | llvm::PointerType *VoidPtrPtrTy; |
| 135 | llvm::PointerType *Int8PtrPtrTy; |
John McCall | e3dc170 | 2011-02-15 09:22:45 +0000 | [diff] [blame] | 136 | }; |
| 137 | |
John McCall | c533cb7 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 138 | /// The width of a pointer into the generic address space. |
John McCall | e3dc170 | 2011-02-15 09:22:45 +0000 | [diff] [blame] | 139 | unsigned char PointerWidthInBits; |
John McCall | c533cb7 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 140 | |
John McCall | 7f16c42 | 2011-09-10 09:17:20 +0000 | [diff] [blame] | 141 | /// The size and alignment of a pointer into the generic address |
| 142 | /// space. |
| 143 | union { |
| 144 | unsigned char PointerAlignInBytes; |
| 145 | unsigned char PointerSizeInBytes; |
John McCall | b91cd66 | 2012-05-01 05:23:51 +0000 | [diff] [blame] | 146 | unsigned char SizeSizeInBytes; // sizeof(size_t) |
John McCall | 7f16c42 | 2011-09-10 09:17:20 +0000 | [diff] [blame] | 147 | }; |
John McCall | 882987f | 2013-02-28 19:01:20 +0000 | [diff] [blame] | 148 | |
| 149 | llvm::CallingConv::ID RuntimeCC; |
| 150 | llvm::CallingConv::ID getRuntimeCC() const { |
| 151 | return RuntimeCC; |
| 152 | } |
John McCall | e3dc170 | 2011-02-15 09:22:45 +0000 | [diff] [blame] | 153 | }; |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 154 | |
| 155 | struct RREntrypoints { |
| 156 | RREntrypoints() { memset(this, 0, sizeof(*this)); } |
| 157 | /// void objc_autoreleasePoolPop(void*); |
| 158 | llvm::Constant *objc_autoreleasePoolPop; |
| 159 | |
| 160 | /// void *objc_autoreleasePoolPush(void); |
| 161 | llvm::Constant *objc_autoreleasePoolPush; |
| 162 | }; |
| 163 | |
| 164 | struct ARCEntrypoints { |
| 165 | ARCEntrypoints() { memset(this, 0, sizeof(*this)); } |
| 166 | |
| 167 | /// id objc_autorelease(id); |
| 168 | llvm::Constant *objc_autorelease; |
| 169 | |
| 170 | /// id objc_autoreleaseReturnValue(id); |
| 171 | llvm::Constant *objc_autoreleaseReturnValue; |
| 172 | |
| 173 | /// void objc_copyWeak(id *dest, id *src); |
| 174 | llvm::Constant *objc_copyWeak; |
| 175 | |
| 176 | /// void objc_destroyWeak(id*); |
| 177 | llvm::Constant *objc_destroyWeak; |
| 178 | |
| 179 | /// id objc_initWeak(id*, id); |
| 180 | llvm::Constant *objc_initWeak; |
| 181 | |
| 182 | /// id objc_loadWeak(id*); |
| 183 | llvm::Constant *objc_loadWeak; |
| 184 | |
| 185 | /// id objc_loadWeakRetained(id*); |
| 186 | llvm::Constant *objc_loadWeakRetained; |
| 187 | |
| 188 | /// void objc_moveWeak(id *dest, id *src); |
| 189 | llvm::Constant *objc_moveWeak; |
| 190 | |
| 191 | /// id objc_retain(id); |
| 192 | llvm::Constant *objc_retain; |
| 193 | |
| 194 | /// id objc_retainAutorelease(id); |
| 195 | llvm::Constant *objc_retainAutorelease; |
| 196 | |
| 197 | /// id objc_retainAutoreleaseReturnValue(id); |
| 198 | llvm::Constant *objc_retainAutoreleaseReturnValue; |
| 199 | |
| 200 | /// id objc_retainAutoreleasedReturnValue(id); |
| 201 | llvm::Constant *objc_retainAutoreleasedReturnValue; |
| 202 | |
| 203 | /// id objc_retainBlock(id); |
| 204 | llvm::Constant *objc_retainBlock; |
| 205 | |
| 206 | /// void objc_release(id); |
| 207 | llvm::Constant *objc_release; |
| 208 | |
| 209 | /// id objc_storeStrong(id*, id); |
| 210 | llvm::Constant *objc_storeStrong; |
| 211 | |
| 212 | /// id objc_storeWeak(id*, id); |
| 213 | llvm::Constant *objc_storeWeak; |
| 214 | |
| 215 | /// A void(void) inline asm to use to mark that the return value of |
| 216 | /// a call will be immediately retain. |
| 217 | llvm::InlineAsm *retainAutoreleasedReturnValueMarker; |
John McCall | eff1884 | 2013-03-23 02:35:54 +0000 | [diff] [blame] | 218 | |
| 219 | /// void clang.arc.use(...); |
| 220 | llvm::Constant *clang_arc_use; |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 221 | }; |
Will Dietz | f54319c | 2013-01-18 11:30:38 +0000 | [diff] [blame] | 222 | |
Justin Bogner | e2ef2a0 | 2014-04-15 21:22:35 +0000 | [diff] [blame] | 223 | /// This class records statistics on instrumentation based profiling. |
| 224 | struct InstrProfStats { |
| 225 | InstrProfStats() : Visited(0), Missing(0), Mismatched(0) {} |
| 226 | bool isOutOfDate() { return Missing || Mismatched; } |
| 227 | uint32_t Visited; |
| 228 | uint32_t Missing; |
| 229 | uint32_t Mismatched; |
| 230 | }; |
| 231 | |
Mike Stump | 1676c5b | 2009-02-13 19:12:34 +0000 | [diff] [blame] | 232 | /// CodeGenModule - This class organizes the cross-function state that is used |
| 233 | /// while generating LLVM code. |
John McCall | e3dc170 | 2011-02-15 09:22:45 +0000 | [diff] [blame] | 234 | class CodeGenModule : public CodeGenTypeCache { |
Dmitri Gribenko | a664e5b | 2012-09-15 20:20:27 +0000 | [diff] [blame] | 235 | CodeGenModule(const CodeGenModule &) LLVM_DELETED_FUNCTION; |
| 236 | void operator=(const CodeGenModule &) LLVM_DELETED_FUNCTION; |
Anders Carlsson | 729a820 | 2009-02-24 04:21:31 +0000 | [diff] [blame] | 237 | |
Chris Lattner | ee7bd3b | 2009-09-12 22:45:21 +0000 | [diff] [blame] | 238 | typedef std::vector<std::pair<llvm::Constant*, int> > CtorList; |
Daniel Dunbar | 74aa7e1 | 2008-08-01 00:01:51 +0000 | [diff] [blame] | 239 | |
Chris Lattner | f97fe38 | 2007-05-24 06:29:05 +0000 | [diff] [blame] | 240 | ASTContext &Context; |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 241 | const LangOptions &LangOpts; |
Chandler Carruth | bc55fe2 | 2009-11-12 17:24:48 +0000 | [diff] [blame] | 242 | const CodeGenOptions &CodeGenOpts; |
Chris Lattner | 23b7eb6 | 2007-06-15 23:05:46 +0000 | [diff] [blame] | 243 | llvm::Module &TheModule; |
David Blaikie | 9c902b5 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 244 | DiagnosticsEngine &Diags; |
John McCall | c8e0170 | 2013-04-16 22:48:15 +0000 | [diff] [blame] | 245 | const llvm::DataLayout &TheDataLayout; |
| 246 | const TargetInfo &Target; |
Ahmed Charles | b898432 | 2014-03-07 20:03:18 +0000 | [diff] [blame] | 247 | std::unique_ptr<CGCXXABI> ABI; |
John McCall | c8e0170 | 2013-04-16 22:48:15 +0000 | [diff] [blame] | 248 | llvm::LLVMContext &VMContext; |
Anders Carlsson | ff971e8 | 2009-10-07 01:06:45 +0000 | [diff] [blame] | 249 | |
John McCall | c8e0170 | 2013-04-16 22:48:15 +0000 | [diff] [blame] | 250 | CodeGenTBAA *TBAA; |
| 251 | |
| 252 | mutable const TargetCodeGenInfo *TheTargetCodeGenInfo; |
| 253 | |
| 254 | // This should not be moved earlier, since its initialization depends on some |
| 255 | // of the previous reference members being already initialized and also checks |
| 256 | // if TheTargetCodeGenInfo is NULL |
| 257 | CodeGenTypes Types; |
| 258 | |
Anders Carlsson | a864caf | 2010-03-23 04:11:45 +0000 | [diff] [blame] | 259 | /// VTables - Holds information about C++ vtables. |
| 260 | CodeGenVTables VTables; |
Douglas Gregor | bc6a434 | 2010-04-08 16:07:47 +0000 | [diff] [blame] | 261 | |
Peter Collingbourne | e1d2099 | 2011-07-27 20:29:46 +0000 | [diff] [blame] | 262 | CGObjCRuntime* ObjCRuntime; |
Peter Collingbourne | 2dbb708 | 2011-09-19 21:14:35 +0000 | [diff] [blame] | 263 | CGOpenCLRuntime* OpenCLRuntime; |
Peter Collingbourne | fe88342 | 2011-10-06 18:29:37 +0000 | [diff] [blame] | 264 | CGCUDARuntime* CUDARuntime; |
Ted Kremenek | 2c674f6 | 2008-08-05 18:50:11 +0000 | [diff] [blame] | 265 | CGDebugInfo* DebugInfo; |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 266 | ARCEntrypoints *ARCData; |
Dan Gohman | 515a60d | 2012-02-16 00:57:37 +0000 | [diff] [blame] | 267 | llvm::MDNode *NoObjCARCExceptionsMetadata; |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 268 | RREntrypoints *RRData; |
Justin Bogner | 837a6f6 | 2014-04-18 21:52:00 +0000 | [diff] [blame^] | 269 | std::unique_ptr<llvm::IndexedInstrProfReader> PGOReader; |
Justin Bogner | e2ef2a0 | 2014-04-15 21:22:35 +0000 | [diff] [blame] | 270 | InstrProfStats PGOStats; |
Daniel Dunbar | e49df9b5 | 2008-07-30 16:32:24 +0000 | [diff] [blame] | 271 | |
Rafael Espindola | 2e42fec | 2010-03-04 18:17:24 +0000 | [diff] [blame] | 272 | // WeakRefReferences - A set of references that have only been seen via |
John McCall | c8e0170 | 2013-04-16 22:48:15 +0000 | [diff] [blame] | 273 | // a weakref so far. This is used to remove the weak of the reference if we |
| 274 | // ever see a direct reference or a definition. |
Rafael Espindola | 2e42fec | 2010-03-04 18:17:24 +0000 | [diff] [blame] | 275 | llvm::SmallPtrSet<llvm::GlobalValue*, 10> WeakRefReferences; |
| 276 | |
Chris Lattner | 4547094 | 2009-03-21 09:44:56 +0000 | [diff] [blame] | 277 | /// DeferredDecls - This contains all the decls which have definitions but |
| 278 | /// which are deferred for emission and therefore should only be output if |
| 279 | /// they are actually used. If a decl is in this, then it is known to have |
John McCall | 7ec5043 | 2010-03-19 23:29:14 +0000 | [diff] [blame] | 280 | /// not been referenced yet. |
| 281 | llvm::StringMap<GlobalDecl> DeferredDecls; |
Daniel Dunbar | 08b26a0 | 2009-02-13 20:29:50 +0000 | [diff] [blame] | 282 | |
Chris Lattner | 4547094 | 2009-03-21 09:44:56 +0000 | [diff] [blame] | 283 | /// DeferredDeclsToEmit - This is a list of deferred decls which we have seen |
| 284 | /// that *are* actually referenced. These get code generated when the module |
| 285 | /// is done. |
Rafael Espindola | c0ff744 | 2013-12-09 14:59:08 +0000 | [diff] [blame] | 286 | struct DeferredGlobal { |
| 287 | DeferredGlobal(llvm::GlobalValue *GV, GlobalDecl GD) : GV(GV), GD(GD) {} |
| 288 | llvm::AssertingVH<llvm::GlobalValue> GV; |
| 289 | GlobalDecl GD; |
| 290 | }; |
| 291 | std::vector<DeferredGlobal> DeferredDeclsToEmit; |
| 292 | void addDeferredDeclToEmit(llvm::GlobalValue *GV, GlobalDecl GD) { |
| 293 | DeferredDeclsToEmit.push_back(DeferredGlobal(GV, GD)); |
| 294 | } |
Daniel Dunbar | 7dd749e | 2009-04-15 22:08:45 +0000 | [diff] [blame] | 295 | |
Rafael Espindola | 208b5c0 | 2013-10-22 19:26:13 +0000 | [diff] [blame] | 296 | /// List of alias we have emitted. Used to make sure that what they point to |
| 297 | /// is defined once we get to the end of the of the translation unit. |
| 298 | std::vector<GlobalDecl> Aliases; |
| 299 | |
Rafael Espindola | 2e2995b | 2013-11-05 21:37:29 +0000 | [diff] [blame] | 300 | typedef llvm::StringMap<llvm::TrackingVH<llvm::Constant> > ReplacementsTy; |
| 301 | ReplacementsTy Replacements; |
| 302 | |
John McCall | 6bd2a89 | 2013-01-25 22:31:03 +0000 | [diff] [blame] | 303 | /// DeferredVTables - A queue of (optional) vtables to consider emitting. |
| 304 | std::vector<const CXXRecordDecl*> DeferredVTables; |
| 305 | |
Daniel Dunbar | 08b26a0 | 2009-02-13 20:29:50 +0000 | [diff] [blame] | 306 | /// LLVMUsed - List of global values which are required to be |
| 307 | /// present in the object file; bitcast to i8*. This is used for |
| 308 | /// forcing visibility of symbols which may otherwise be optimized |
| 309 | /// out. |
Chris Lattner | f41e87f | 2009-03-31 22:37:52 +0000 | [diff] [blame] | 310 | std::vector<llvm::WeakVH> LLVMUsed; |
Rafael Espindola | 060062a | 2014-03-06 22:15:10 +0000 | [diff] [blame] | 311 | std::vector<llvm::WeakVH> LLVMCompilerUsed; |
Mike Stump | 1676c5b | 2009-02-13 19:12:34 +0000 | [diff] [blame] | 312 | |
| 313 | /// GlobalCtors - Store the list of global constructors and their respective |
| 314 | /// priorities to be emitted when the translation unit is complete. |
Daniel Dunbar | 74aa7e1 | 2008-08-01 00:01:51 +0000 | [diff] [blame] | 315 | CtorList GlobalCtors; |
| 316 | |
Mike Stump | 1676c5b | 2009-02-13 19:12:34 +0000 | [diff] [blame] | 317 | /// GlobalDtors - Store the list of global destructors and their respective |
| 318 | /// priorities to be emitted when the translation unit is complete. |
Daniel Dunbar | 74aa7e1 | 2008-08-01 00:01:51 +0000 | [diff] [blame] | 319 | CtorList GlobalDtors; |
| 320 | |
Anders Carlsson | 2e2f4d2 | 2010-06-22 16:05:32 +0000 | [diff] [blame] | 321 | /// MangledDeclNames - A map of canonical GlobalDecls to their mangled names. |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 322 | llvm::DenseMap<GlobalDecl, StringRef> MangledDeclNames; |
Anders Carlsson | 2e2f4d2 | 2010-06-22 16:05:32 +0000 | [diff] [blame] | 323 | llvm::BumpPtrAllocator MangledNamesAllocator; |
| 324 | |
Julien Lerouge | 5a6b698 | 2011-09-09 22:41:49 +0000 | [diff] [blame] | 325 | /// Global annotations. |
Nate Begeman | 7fab578 | 2008-04-18 23:43:57 +0000 | [diff] [blame] | 326 | std::vector<llvm::Constant*> Annotations; |
Mike Stump | 1676c5b | 2009-02-13 19:12:34 +0000 | [diff] [blame] | 327 | |
Julien Lerouge | 5a6b698 | 2011-09-09 22:41:49 +0000 | [diff] [blame] | 328 | /// Map used to get unique annotation strings. |
| 329 | llvm::StringMap<llvm::Constant*> AnnotationStrings; |
| 330 | |
Anders Carlsson | b04ea61 | 2007-08-21 00:21:21 +0000 | [diff] [blame] | 331 | llvm::StringMap<llvm::Constant*> CFConstantStringMap; |
David Majnemer | 58e5bee | 2014-03-24 21:43:36 +0000 | [diff] [blame] | 332 | |
| 333 | llvm::StringMap<llvm::GlobalVariable *> Constant1ByteStringMap; |
| 334 | llvm::StringMap<llvm::GlobalVariable *> Constant2ByteStringMap; |
| 335 | llvm::StringMap<llvm::GlobalVariable *> Constant4ByteStringMap; |
Eli Friedman | 1c8d2ca | 2012-03-09 03:27:46 +0000 | [diff] [blame] | 336 | llvm::DenseMap<const Decl*, llvm::Constant *> StaticLocalDeclMap; |
John McCall | b88a566 | 2012-03-30 21:00:39 +0000 | [diff] [blame] | 337 | llvm::DenseMap<const Decl*, llvm::GlobalVariable*> StaticLocalDeclGuardMap; |
Richard Smith | e6c0144 | 2013-06-05 00:46:14 +0000 | [diff] [blame] | 338 | llvm::DenseMap<const Expr*, llvm::Constant *> MaterializedGlobalTemporaryMap; |
| 339 | |
Fariborz Jahanian | 1bed413 | 2012-01-08 19:13:23 +0000 | [diff] [blame] | 340 | llvm::DenseMap<QualType, llvm::Constant *> AtomicSetterHelperFnMap; |
| 341 | llvm::DenseMap<QualType, llvm::Constant *> AtomicGetterHelperFnMap; |
Daniel Dunbar | d644ad6 | 2008-08-23 18:37:06 +0000 | [diff] [blame] | 342 | |
Will Dietz | 949ec54 | 2013-11-08 01:09:22 +0000 | [diff] [blame] | 343 | /// Map used to get unique type descriptor constants for sanitizers. |
| 344 | llvm::DenseMap<QualType, llvm::Constant *> TypeDescriptorMap; |
| 345 | |
Richard Smith | df931ce | 2013-04-06 05:00:46 +0000 | [diff] [blame] | 346 | /// Map used to track internal linkage functions declared within |
| 347 | /// extern "C" regions. |
Richard Smith | f21c961 | 2013-04-13 01:28:18 +0000 | [diff] [blame] | 348 | typedef llvm::MapVector<IdentifierInfo *, |
| 349 | llvm::GlobalValue *> StaticExternCMap; |
Richard Smith | df931ce | 2013-04-06 05:00:46 +0000 | [diff] [blame] | 350 | StaticExternCMap StaticExternCValues; |
| 351 | |
Richard Smith | 2fd1d7a | 2013-04-19 16:42:07 +0000 | [diff] [blame] | 352 | /// \brief thread_local variables defined or used in this TU. |
| 353 | std::vector<std::pair<const VarDecl *, llvm::GlobalVariable *> > |
| 354 | CXXThreadLocals; |
| 355 | |
| 356 | /// \brief thread_local variables with initializers that need to run |
| 357 | /// before any thread_local variable in this TU is odr-used. |
| 358 | std::vector<llvm::Constant*> CXXThreadLocalInits; |
| 359 | |
Daniel Dunbar | fe06df4 | 2010-03-20 04:15:41 +0000 | [diff] [blame] | 360 | /// CXXGlobalInits - Global variables with initializers that need to run |
Anders Carlsson | b8be93f | 2009-08-08 23:24:23 +0000 | [diff] [blame] | 361 | /// before main. |
Eli Friedman | 5866fe3 | 2010-01-08 00:50:11 +0000 | [diff] [blame] | 362 | std::vector<llvm::Constant*> CXXGlobalInits; |
John McCall | 70013b6 | 2010-07-15 23:40:35 +0000 | [diff] [blame] | 363 | |
| 364 | /// When a C++ decl with an initializer is deferred, null is |
| 365 | /// appended to CXXGlobalInits, and the index of that null is placed |
| 366 | /// here so that the initializer will be performed in the correct |
| 367 | /// order. |
| 368 | llvm::DenseMap<const Decl*, unsigned> DelayedCXXInitPosition; |
Fariborz Jahanian | 9f2a4ee | 2010-06-21 18:45:05 +0000 | [diff] [blame] | 369 | |
Anton Korobeynikov | abed749 | 2012-11-06 22:44:45 +0000 | [diff] [blame] | 370 | typedef std::pair<OrderGlobalInits, llvm::Function*> GlobalInitData; |
| 371 | |
| 372 | struct GlobalInitPriorityCmp { |
| 373 | bool operator()(const GlobalInitData &LHS, |
| 374 | const GlobalInitData &RHS) const { |
| 375 | return LHS.first.priority < RHS.first.priority; |
| 376 | } |
| 377 | }; |
| 378 | |
Fariborz Jahanian | 9f2a4ee | 2010-06-21 18:45:05 +0000 | [diff] [blame] | 379 | /// - Global variables with initializers whose order of initialization |
| 380 | /// is set by init_priority attribute. |
Anton Korobeynikov | abed749 | 2012-11-06 22:44:45 +0000 | [diff] [blame] | 381 | SmallVector<GlobalInitData, 8> PrioritizedCXXGlobalInits; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 382 | |
Daniel Dunbar | fe06df4 | 2010-03-20 04:15:41 +0000 | [diff] [blame] | 383 | /// CXXGlobalDtors - Global destructor functions and arguments that need to |
| 384 | /// run on termination. |
Chris Lattner | 87233f7 | 2010-06-19 05:52:45 +0000 | [diff] [blame] | 385 | std::vector<std::pair<llvm::WeakVH,llvm::Constant*> > CXXGlobalDtors; |
Daniel Dunbar | fe06df4 | 2010-03-20 04:15:41 +0000 | [diff] [blame] | 386 | |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 387 | /// \brief The complete set of modules that has been imported. |
| 388 | llvm::SetVector<clang::Module *> ImportedModules; |
| 389 | |
Reid Kleckner | e43f0fe | 2013-05-08 13:44:39 +0000 | [diff] [blame] | 390 | /// \brief A vector of metadata strings. |
| 391 | SmallVector<llvm::Value *, 16> LinkerOptionsMetadata; |
| 392 | |
Douglas Gregor | abf4e0d | 2011-08-09 15:54:21 +0000 | [diff] [blame] | 393 | /// @name Cache for Objective-C runtime types |
| 394 | /// @{ |
| 395 | |
Mike Stump | 1676c5b | 2009-02-13 19:12:34 +0000 | [diff] [blame] | 396 | /// CFConstantStringClassRef - Cached reference to the class for constant |
| 397 | /// strings. This value has type int * but is actually an Obj-C class pointer. |
Fariborz Jahanian | d1b6778 | 2013-04-16 15:25:39 +0000 | [diff] [blame] | 398 | llvm::WeakVH CFConstantStringClassRef; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 399 | |
Fariborz Jahanian | 50c925f | 2010-10-19 17:19:29 +0000 | [diff] [blame] | 400 | /// ConstantStringClassRef - Cached reference to the class for constant |
Fariborz Jahanian | e804c28 | 2010-04-23 17:41:07 +0000 | [diff] [blame] | 401 | /// strings. This value has type int * but is actually an Obj-C class pointer. |
Fariborz Jahanian | d1b6778 | 2013-04-16 15:25:39 +0000 | [diff] [blame] | 402 | llvm::WeakVH ConstantStringClassRef; |
Fariborz Jahanian | e804c28 | 2010-04-23 17:41:07 +0000 | [diff] [blame] | 403 | |
Douglas Gregor | abf4e0d | 2011-08-09 15:54:21 +0000 | [diff] [blame] | 404 | /// \brief The LLVM type corresponding to NSConstantString. |
| 405 | llvm::StructType *NSConstantStringType; |
| 406 | |
Douglas Gregor | 636e200 | 2011-08-09 17:23:49 +0000 | [diff] [blame] | 407 | /// \brief The type used to describe the state of a fast enumeration in |
| 408 | /// Objective-C's for..in loop. |
| 409 | QualType ObjCFastEnumerationStateType; |
| 410 | |
Douglas Gregor | abf4e0d | 2011-08-09 15:54:21 +0000 | [diff] [blame] | 411 | /// @} |
| 412 | |
David Chisnall | 481e3a8 | 2010-01-23 02:40:42 +0000 | [diff] [blame] | 413 | /// Lazily create the Objective-C runtime |
| 414 | void createObjCRuntime(); |
| 415 | |
Peter Collingbourne | 2dbb708 | 2011-09-19 21:14:35 +0000 | [diff] [blame] | 416 | void createOpenCLRuntime(); |
Peter Collingbourne | fe88342 | 2011-10-06 18:29:37 +0000 | [diff] [blame] | 417 | void createCUDARuntime(); |
Peter Collingbourne | 2dbb708 | 2011-09-19 21:14:35 +0000 | [diff] [blame] | 418 | |
Rafael Espindola | 4fdc175 | 2011-12-19 14:41:01 +0000 | [diff] [blame] | 419 | bool isTriviallyRecursive(const FunctionDecl *F); |
Peter Collingbourne | 4d90dba | 2013-06-05 17:49:37 +0000 | [diff] [blame] | 420 | bool shouldEmitFunction(GlobalDecl GD); |
Daniel Dunbar | 900546d | 2010-07-16 00:00:15 +0000 | [diff] [blame] | 421 | |
| 422 | /// @name Cache for Blocks Runtime Globals |
| 423 | /// @{ |
| 424 | |
| 425 | llvm::Constant *NSConcreteGlobalBlock; |
| 426 | llvm::Constant *NSConcreteStackBlock; |
Daniel Dunbar | 3348e2d | 2010-07-16 00:00:19 +0000 | [diff] [blame] | 427 | |
Daniel Dunbar | 900546d | 2010-07-16 00:00:15 +0000 | [diff] [blame] | 428 | llvm::Constant *BlockObjectAssign; |
| 429 | llvm::Constant *BlockObjectDispose; |
| 430 | |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 431 | llvm::Type *BlockDescriptorType; |
| 432 | llvm::Type *GenericBlockLiteralType; |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 433 | |
| 434 | struct { |
| 435 | int GlobalUniqueCount; |
| 436 | } Block; |
Will Dietz | f54319c | 2013-01-18 11:30:38 +0000 | [diff] [blame] | 437 | |
Nadav Rotem | 1da3094 | 2013-03-23 06:43:35 +0000 | [diff] [blame] | 438 | /// void @llvm.lifetime.start(i64 %size, i8* nocapture <ptr>) |
| 439 | llvm::Constant *LifetimeStartFn; |
| 440 | |
| 441 | /// void @llvm.lifetime.end(i64 %size, i8* nocapture <ptr>) |
| 442 | llvm::Constant *LifetimeEndFn; |
| 443 | |
Fariborz Jahanian | 6362803 | 2012-06-26 16:06:38 +0000 | [diff] [blame] | 444 | GlobalDecl initializedGlobalDecl; |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 445 | |
Ahmed Charles | b898432 | 2014-03-07 20:03:18 +0000 | [diff] [blame] | 446 | std::unique_ptr<llvm::SpecialCaseList> SanitizerBlacklist; |
Will Dietz | f54319c | 2013-01-18 11:30:38 +0000 | [diff] [blame] | 447 | |
| 448 | const SanitizerOptions &SanOpts; |
| 449 | |
Daniel Dunbar | 900546d | 2010-07-16 00:00:15 +0000 | [diff] [blame] | 450 | /// @} |
Chris Lattner | f97fe38 | 2007-05-24 06:29:05 +0000 | [diff] [blame] | 451 | public: |
Chandler Carruth | bc55fe2 | 2009-11-12 17:24:48 +0000 | [diff] [blame] | 452 | CodeGenModule(ASTContext &C, const CodeGenOptions &CodeGenOpts, |
John McCall | 568d410 | 2013-04-16 22:48:20 +0000 | [diff] [blame] | 453 | llvm::Module &M, const llvm::DataLayout &TD, |
| 454 | DiagnosticsEngine &Diags); |
Ted Kremenek | 2c674f6 | 2008-08-05 18:50:11 +0000 | [diff] [blame] | 455 | |
Chris Lattner | a087ff9 | 2008-03-01 08:45:05 +0000 | [diff] [blame] | 456 | ~CodeGenModule(); |
Mike Stump | 1676c5b | 2009-02-13 19:12:34 +0000 | [diff] [blame] | 457 | |
Rafael Espindola | c0ff744 | 2013-12-09 14:59:08 +0000 | [diff] [blame] | 458 | void clear(); |
| 459 | |
Ted Kremenek | 2c674f6 | 2008-08-05 18:50:11 +0000 | [diff] [blame] | 460 | /// Release - Finalize LLVM code generation. |
| 461 | void Release(); |
Daniel Dunbar | 8d48059 | 2008-08-11 18:12:00 +0000 | [diff] [blame] | 462 | |
| 463 | /// getObjCRuntime() - Return a reference to the configured |
| 464 | /// Objective-C runtime. |
Mike Stump | 1676c5b | 2009-02-13 19:12:34 +0000 | [diff] [blame] | 465 | CGObjCRuntime &getObjCRuntime() { |
Peter Collingbourne | e1d2099 | 2011-07-27 20:29:46 +0000 | [diff] [blame] | 466 | if (!ObjCRuntime) createObjCRuntime(); |
| 467 | return *ObjCRuntime; |
Daniel Dunbar | 8d48059 | 2008-08-11 18:12:00 +0000 | [diff] [blame] | 468 | } |
Mike Stump | 1676c5b | 2009-02-13 19:12:34 +0000 | [diff] [blame] | 469 | |
Sylvestre Ledru | 33b5baf | 2012-09-27 10:16:10 +0000 | [diff] [blame] | 470 | /// hasObjCRuntime() - Return true iff an Objective-C runtime has |
Daniel Dunbar | 8d48059 | 2008-08-11 18:12:00 +0000 | [diff] [blame] | 471 | /// been configured. |
Peter Collingbourne | e1d2099 | 2011-07-27 20:29:46 +0000 | [diff] [blame] | 472 | bool hasObjCRuntime() { return !!ObjCRuntime; } |
Daniel Dunbar | 8d48059 | 2008-08-11 18:12:00 +0000 | [diff] [blame] | 473 | |
Peter Collingbourne | fe88342 | 2011-10-06 18:29:37 +0000 | [diff] [blame] | 474 | /// getOpenCLRuntime() - Return a reference to the configured OpenCL runtime. |
Peter Collingbourne | 2dbb708 | 2011-09-19 21:14:35 +0000 | [diff] [blame] | 475 | CGOpenCLRuntime &getOpenCLRuntime() { |
| 476 | assert(OpenCLRuntime != 0); |
| 477 | return *OpenCLRuntime; |
| 478 | } |
| 479 | |
Peter Collingbourne | fe88342 | 2011-10-06 18:29:37 +0000 | [diff] [blame] | 480 | /// getCUDARuntime() - Return a reference to the configured CUDA runtime. |
| 481 | CGCUDARuntime &getCUDARuntime() { |
| 482 | assert(CUDARuntime != 0); |
| 483 | return *CUDARuntime; |
| 484 | } |
| 485 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 486 | ARCEntrypoints &getARCEntrypoints() const { |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 487 | assert(getLangOpts().ObjCAutoRefCount && ARCData != 0); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 488 | return *ARCData; |
| 489 | } |
| 490 | |
| 491 | RREntrypoints &getRREntrypoints() const { |
| 492 | assert(RRData != 0); |
| 493 | return *RRData; |
| 494 | } |
| 495 | |
Justin Bogner | 837a6f6 | 2014-04-18 21:52:00 +0000 | [diff] [blame^] | 496 | InstrProfStats &getPGOStats() { return PGOStats; } |
| 497 | llvm::IndexedInstrProfReader *getPGOReader() const { return PGOReader.get(); } |
Justin Bogner | ef512b9 | 2014-01-06 22:27:43 +0000 | [diff] [blame] | 498 | |
Eli Friedman | 1c8d2ca | 2012-03-09 03:27:46 +0000 | [diff] [blame] | 499 | llvm::Constant *getStaticLocalDeclAddress(const VarDecl *D) { |
| 500 | return StaticLocalDeclMap[D]; |
Fariborz Jahanian | 3fef72f | 2010-04-18 21:01:23 +0000 | [diff] [blame] | 501 | } |
Fariborz Jahanian | 4d55b2d | 2010-04-19 18:15:02 +0000 | [diff] [blame] | 502 | void setStaticLocalDeclAddress(const VarDecl *D, |
Eli Friedman | 1c8d2ca | 2012-03-09 03:27:46 +0000 | [diff] [blame] | 503 | llvm::Constant *C) { |
| 504 | StaticLocalDeclMap[D] = C; |
Fariborz Jahanian | 3fef72f | 2010-04-18 21:01:23 +0000 | [diff] [blame] | 505 | } |
| 506 | |
John McCall | b88a566 | 2012-03-30 21:00:39 +0000 | [diff] [blame] | 507 | llvm::GlobalVariable *getStaticLocalDeclGuardAddress(const VarDecl *D) { |
| 508 | return StaticLocalDeclGuardMap[D]; |
| 509 | } |
| 510 | void setStaticLocalDeclGuardAddress(const VarDecl *D, |
| 511 | llvm::GlobalVariable *C) { |
| 512 | StaticLocalDeclGuardMap[D] = C; |
| 513 | } |
| 514 | |
Fariborz Jahanian | 1bed413 | 2012-01-08 19:13:23 +0000 | [diff] [blame] | 515 | llvm::Constant *getAtomicSetterHelperFnMap(QualType Ty) { |
| 516 | return AtomicSetterHelperFnMap[Ty]; |
Fariborz Jahanian | 7ff610b | 2012-01-06 22:33:54 +0000 | [diff] [blame] | 517 | } |
Fariborz Jahanian | 1bed413 | 2012-01-08 19:13:23 +0000 | [diff] [blame] | 518 | void setAtomicSetterHelperFnMap(QualType Ty, |
Fariborz Jahanian | 7ff610b | 2012-01-06 22:33:54 +0000 | [diff] [blame] | 519 | llvm::Constant *Fn) { |
Fariborz Jahanian | 1bed413 | 2012-01-08 19:13:23 +0000 | [diff] [blame] | 520 | AtomicSetterHelperFnMap[Ty] = Fn; |
| 521 | } |
| 522 | |
| 523 | llvm::Constant *getAtomicGetterHelperFnMap(QualType Ty) { |
| 524 | return AtomicGetterHelperFnMap[Ty]; |
| 525 | } |
| 526 | void setAtomicGetterHelperFnMap(QualType Ty, |
| 527 | llvm::Constant *Fn) { |
| 528 | AtomicGetterHelperFnMap[Ty] = Fn; |
Fariborz Jahanian | 7ff610b | 2012-01-06 22:33:54 +0000 | [diff] [blame] | 529 | } |
| 530 | |
Will Dietz | 949ec54 | 2013-11-08 01:09:22 +0000 | [diff] [blame] | 531 | llvm::Constant *getTypeDescriptor(QualType Ty) { |
| 532 | return TypeDescriptorMap[Ty]; |
| 533 | } |
| 534 | void setTypeDescriptor(QualType Ty, llvm::Constant *C) { |
| 535 | TypeDescriptorMap[Ty] = C; |
| 536 | } |
| 537 | |
Devang Patel | d6ffebb | 2011-03-07 18:45:56 +0000 | [diff] [blame] | 538 | CGDebugInfo *getModuleDebugInfo() { return DebugInfo; } |
Devang Patel | e65982c | 2011-03-07 18:29:53 +0000 | [diff] [blame] | 539 | |
Dan Gohman | 515a60d | 2012-02-16 00:57:37 +0000 | [diff] [blame] | 540 | llvm::MDNode *getNoObjCARCExceptionsMetadata() { |
| 541 | if (!NoObjCARCExceptionsMetadata) |
| 542 | NoObjCARCExceptionsMetadata = |
| 543 | llvm::MDNode::get(getLLVMContext(), |
| 544 | SmallVector<llvm::Value*,1>()); |
| 545 | return NoObjCARCExceptionsMetadata; |
| 546 | } |
| 547 | |
Chris Lattner | d1af2d2 | 2007-05-29 23:17:50 +0000 | [diff] [blame] | 548 | ASTContext &getContext() const { return Context; } |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 549 | const LangOptions &getLangOpts() const { return LangOpts; } |
John McCall | c8e0170 | 2013-04-16 22:48:15 +0000 | [diff] [blame] | 550 | const CodeGenOptions &getCodeGenOpts() const { return CodeGenOpts; } |
Chris Lattner | 23b7eb6 | 2007-06-15 23:05:46 +0000 | [diff] [blame] | 551 | llvm::Module &getModule() const { return TheModule; } |
David Blaikie | 9c902b5 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 552 | DiagnosticsEngine &getDiags() const { return Diags; } |
Micah Villmow | dd31ca1 | 2012-10-08 16:25:52 +0000 | [diff] [blame] | 553 | const llvm::DataLayout &getDataLayout() const { return TheDataLayout; } |
John McCall | c8e0170 | 2013-04-16 22:48:15 +0000 | [diff] [blame] | 554 | const TargetInfo &getTarget() const { return Target; } |
Alp Toker | 8286225 | 2013-12-28 21:58:40 +0000 | [diff] [blame] | 555 | CGCXXABI &getCXXABI() const { return *ABI; } |
Owen Anderson | 170229f | 2009-07-14 23:10:40 +0000 | [diff] [blame] | 556 | llvm::LLVMContext &getLLVMContext() { return VMContext; } |
John McCall | c8e0170 | 2013-04-16 22:48:15 +0000 | [diff] [blame] | 557 | |
John McCall | 53fcbd2 | 2011-02-26 08:07:02 +0000 | [diff] [blame] | 558 | bool shouldUseTBAA() const { return TBAA != 0; } |
| 559 | |
John McCall | c8e0170 | 2013-04-16 22:48:15 +0000 | [diff] [blame] | 560 | const TargetCodeGenInfo &getTargetCodeGenInfo(); |
| 561 | |
| 562 | CodeGenTypes &getTypes() { return Types; } |
| 563 | |
| 564 | CodeGenVTables &getVTables() { return VTables; } |
Timur Iskhodzhanov | 88fd439 | 2013-08-21 06:25:03 +0000 | [diff] [blame] | 565 | |
Timur Iskhodzhanov | 5877663 | 2013-11-05 15:54:58 +0000 | [diff] [blame] | 566 | ItaniumVTableContext &getItaniumVTableContext() { |
| 567 | return VTables.getItaniumVTableContext(); |
Timur Iskhodzhanov | e1ebc5f | 2013-10-09 11:33:51 +0000 | [diff] [blame] | 568 | } |
John McCall | c8e0170 | 2013-04-16 22:48:15 +0000 | [diff] [blame] | 569 | |
Timur Iskhodzhanov | 5877663 | 2013-11-05 15:54:58 +0000 | [diff] [blame] | 570 | MicrosoftVTableContext &getMicrosoftVTableContext() { |
| 571 | return VTables.getMicrosoftVTableContext(); |
Timur Iskhodzhanov | 88fd439 | 2013-08-21 06:25:03 +0000 | [diff] [blame] | 572 | } |
| 573 | |
Dan Gohman | 947c9af | 2010-10-14 23:06:10 +0000 | [diff] [blame] | 574 | llvm::MDNode *getTBAAInfo(QualType QTy); |
Kostya Serebryany | 141e46f | 2012-03-26 17:03:51 +0000 | [diff] [blame] | 575 | llvm::MDNode *getTBAAInfoForVTablePtr(); |
Dan Gohman | 22695fc | 2012-09-28 21:58:29 +0000 | [diff] [blame] | 576 | llvm::MDNode *getTBAAStructInfo(QualType QTy); |
Manman Ren | c451e57 | 2013-04-04 21:53:22 +0000 | [diff] [blame] | 577 | /// Return the MDNode in the type DAG for the given struct type. |
| 578 | llvm::MDNode *getTBAAStructTypeInfo(QualType QTy); |
| 579 | /// Return the path-aware tag for given base type, access node and offset. |
| 580 | llvm::MDNode *getTBAAStructTagInfo(QualType BaseTy, llvm::MDNode *AccessN, |
| 581 | uint64_t O); |
Dan Gohman | 947c9af | 2010-10-14 23:06:10 +0000 | [diff] [blame] | 582 | |
Richard Smith | e070fd2 | 2012-02-17 06:48:11 +0000 | [diff] [blame] | 583 | bool isTypeConstant(QualType QTy, bool ExcludeCtorDtor); |
| 584 | |
John McCall | a8ec7eb | 2013-03-07 21:37:17 +0000 | [diff] [blame] | 585 | bool isPaddedAtomicType(QualType type); |
| 586 | bool isPaddedAtomicType(const AtomicType *type); |
| 587 | |
Manman Ren | e1ad74e | 2013-04-11 23:02:56 +0000 | [diff] [blame] | 588 | /// Decorate the instruction with a TBAA tag. For scalar TBAA, the tag |
| 589 | /// is the same as the type. For struct-path aware TBAA, the tag |
| 590 | /// is different from the type: base type, access type and offset. |
| 591 | /// When ConvertTypeToTag is true, we create a tag based on the scalar type. |
| 592 | void DecorateInstruction(llvm::Instruction *Inst, |
| 593 | llvm::MDNode *TBAAInfo, |
| 594 | bool ConvertTypeToTag = true); |
Dan Gohman | 947c9af | 2010-10-14 23:06:10 +0000 | [diff] [blame] | 595 | |
John McCall | 23c29fe | 2011-06-24 21:55:10 +0000 | [diff] [blame] | 596 | /// getSize - Emit the given number of characters as a value of type size_t. |
| 597 | llvm::ConstantInt *getSize(CharUnits numChars); |
| 598 | |
Daniel Dunbar | f5f359f | 2009-04-14 06:00:08 +0000 | [diff] [blame] | 599 | /// setGlobalVisibility - Set the visibility for the given LLVM |
| 600 | /// GlobalValue. |
Anders Carlsson | c6a4789 | 2011-01-29 19:39:23 +0000 | [diff] [blame] | 601 | void setGlobalVisibility(llvm::GlobalValue *GV, const NamedDecl *D) const; |
Daniel Dunbar | f5f359f | 2009-04-14 06:00:08 +0000 | [diff] [blame] | 602 | |
Hans Wennborg | f60f6af | 2012-06-28 08:01:44 +0000 | [diff] [blame] | 603 | /// setTLSMode - Set the TLS mode for the given LLVM GlobalVariable |
| 604 | /// for the thread-local variable declaration D. |
| 605 | void setTLSMode(llvm::GlobalVariable *GV, const VarDecl &D) const; |
| 606 | |
Anders Carlsson | 537fdce | 2011-01-29 20:59:35 +0000 | [diff] [blame] | 607 | static llvm::GlobalValue::VisibilityTypes GetLLVMVisibility(Visibility V) { |
| 608 | switch (V) { |
| 609 | case DefaultVisibility: return llvm::GlobalValue::DefaultVisibility; |
| 610 | case HiddenVisibility: return llvm::GlobalValue::HiddenVisibility; |
| 611 | case ProtectedVisibility: return llvm::GlobalValue::ProtectedVisibility; |
| 612 | } |
| 613 | llvm_unreachable("unknown visibility!"); |
Anders Carlsson | 537fdce | 2011-01-29 20:59:35 +0000 | [diff] [blame] | 614 | } |
| 615 | |
John McCall | d432414 | 2010-02-19 01:32:20 +0000 | [diff] [blame] | 616 | llvm::Constant *GetAddrOfGlobal(GlobalDecl GD) { |
| 617 | if (isa<CXXConstructorDecl>(GD.getDecl())) |
| 618 | return GetAddrOfCXXConstructor(cast<CXXConstructorDecl>(GD.getDecl()), |
| 619 | GD.getCtorType()); |
| 620 | else if (isa<CXXDestructorDecl>(GD.getDecl())) |
| 621 | return GetAddrOfCXXDestructor(cast<CXXDestructorDecl>(GD.getDecl()), |
| 622 | GD.getDtorType()); |
| 623 | else if (isa<FunctionDecl>(GD.getDecl())) |
| 624 | return GetAddrOfFunction(GD); |
| 625 | else |
| 626 | return GetAddrOfGlobalVar(cast<VarDecl>(GD.getDecl())); |
| 627 | } |
| 628 | |
John McCall | c8e0170 | 2013-04-16 22:48:15 +0000 | [diff] [blame] | 629 | /// CreateOrReplaceCXXRuntimeVariable - Will return a global variable of the |
| 630 | /// given type. If a variable with a different type already exists then a new |
Anders Carlsson | da80af3 | 2011-01-29 18:20:20 +0000 | [diff] [blame] | 631 | /// variable with the right type will be created and all uses of the old |
| 632 | /// variable will be replaced with a bitcast to the new variable. |
| 633 | llvm::GlobalVariable * |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 634 | CreateOrReplaceCXXRuntimeVariable(StringRef Name, llvm::Type *Ty, |
Anders Carlsson | da80af3 | 2011-01-29 18:20:20 +0000 | [diff] [blame] | 635 | llvm::GlobalValue::LinkageTypes Linkage); |
| 636 | |
Peter Collingbourne | f44bdf9 | 2012-05-20 21:08:35 +0000 | [diff] [blame] | 637 | /// GetGlobalVarAddressSpace - Return the address space of the underlying |
| 638 | /// global variable for D, as determined by its declaration. Normally this |
| 639 | /// is the same as the address space of D's type, but in CUDA, address spaces |
| 640 | /// are associated with declarations, not types. |
| 641 | unsigned GetGlobalVarAddressSpace(const VarDecl *D, unsigned AddrSpace); |
| 642 | |
Mike Stump | 1676c5b | 2009-02-13 19:12:34 +0000 | [diff] [blame] | 643 | /// GetAddrOfGlobalVar - Return the llvm::Constant for the address of the |
Chris Lattner | 149927c | 2009-03-21 09:16:30 +0000 | [diff] [blame] | 644 | /// given global variable. If Ty is non-null and if the global doesn't exist, |
| 645 | /// then it will be greated with the specified type instead of whatever the |
| 646 | /// normal requested type would be. |
| 647 | llvm::Constant *GetAddrOfGlobalVar(const VarDecl *D, |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 648 | llvm::Type *Ty = 0); |
Daniel Dunbar | 9c42652 | 2008-07-29 23:18:29 +0000 | [diff] [blame] | 649 | |
John McCall | 3199634 | 2011-04-07 08:22:57 +0000 | [diff] [blame] | 650 | |
Chris Lattner | 832323e | 2009-03-21 08:53:37 +0000 | [diff] [blame] | 651 | /// GetAddrOfFunction - Return the address of the given function. If Ty is |
| 652 | /// non-null, then this function will use the specified type if it has to |
| 653 | /// create it. |
Rafael Espindola | 94abb8f | 2013-12-09 04:29:47 +0000 | [diff] [blame] | 654 | llvm::Constant *GetAddrOfFunction(GlobalDecl GD, llvm::Type *Ty = 0, |
| 655 | bool ForVTable = false, |
| 656 | bool DontDefer = false); |
Daniel Dunbar | c4baa06 | 2008-08-13 23:20:05 +0000 | [diff] [blame] | 657 | |
Anders Carlsson | 3f4336c | 2009-12-17 07:09:17 +0000 | [diff] [blame] | 658 | /// GetAddrOfRTTIDescriptor - Get the address of the RTTI descriptor |
| 659 | /// for the given type. |
John McCall | 48bf349 | 2010-04-30 01:15:21 +0000 | [diff] [blame] | 660 | llvm::Constant *GetAddrOfRTTIDescriptor(QualType Ty, bool ForEH = false); |
Anders Carlsson | fd7dfeb | 2009-12-11 02:46:30 +0000 | [diff] [blame] | 661 | |
Nico Weber | cf4ff586 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 662 | /// GetAddrOfUuidDescriptor - Get the address of a uuid descriptor . |
| 663 | llvm::Constant *GetAddrOfUuidDescriptor(const CXXUuidofExpr* E); |
| 664 | |
Anders Carlsson | cd836f0 | 2010-03-23 17:17:29 +0000 | [diff] [blame] | 665 | /// GetAddrOfThunk - Get the address of the thunk for the given global decl. |
Anders Carlsson | fe8a993 | 2011-02-06 17:15:43 +0000 | [diff] [blame] | 666 | llvm::Constant *GetAddrOfThunk(GlobalDecl GD, const ThunkInfo &Thunk); |
Anders Carlsson | cd836f0 | 2010-03-23 17:17:29 +0000 | [diff] [blame] | 667 | |
Rafael Espindola | 2e42fec | 2010-03-04 18:17:24 +0000 | [diff] [blame] | 668 | /// GetWeakRefReference - Get a reference to the target of VD. |
| 669 | llvm::Constant *GetWeakRefReference(const ValueDecl *VD); |
| 670 | |
Anders Carlsson | 84673e2 | 2010-01-31 01:36:53 +0000 | [diff] [blame] | 671 | /// GetNonVirtualBaseClassOffset - Returns the offset from a derived class to |
Anders Carlsson | 795213e | 2010-04-24 21:27:51 +0000 | [diff] [blame] | 672 | /// a class. Returns null if the offset is 0. |
Anders Carlsson | 8a64c1c | 2010-04-24 21:23:59 +0000 | [diff] [blame] | 673 | llvm::Constant * |
| 674 | GetNonVirtualBaseClassOffset(const CXXRecordDecl *ClassDecl, |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 675 | CastExpr::path_const_iterator PathBegin, |
| 676 | CastExpr::path_const_iterator PathEnd); |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 677 | |
John McCall | f9b056b | 2011-03-31 08:03:29 +0000 | [diff] [blame] | 678 | /// A pair of helper functions for a __block variable. |
| 679 | class ByrefHelpers : public llvm::FoldingSetNode { |
| 680 | public: |
| 681 | llvm::Constant *CopyHelper; |
| 682 | llvm::Constant *DisposeHelper; |
| 683 | |
| 684 | /// The alignment of the field. This is important because |
| 685 | /// different offsets to the field within the byref struct need to |
| 686 | /// have different helper functions. |
| 687 | CharUnits Alignment; |
| 688 | |
| 689 | ByrefHelpers(CharUnits alignment) : Alignment(alignment) {} |
| 690 | virtual ~ByrefHelpers(); |
| 691 | |
| 692 | void Profile(llvm::FoldingSetNodeID &id) const { |
| 693 | id.AddInteger(Alignment.getQuantity()); |
| 694 | profileImpl(id); |
| 695 | } |
| 696 | virtual void profileImpl(llvm::FoldingSetNodeID &id) const = 0; |
| 697 | |
| 698 | virtual bool needsCopy() const { return true; } |
| 699 | virtual void emitCopy(CodeGenFunction &CGF, |
| 700 | llvm::Value *dest, llvm::Value *src) = 0; |
| 701 | |
| 702 | virtual bool needsDispose() const { return true; } |
| 703 | virtual void emitDispose(CodeGenFunction &CGF, llvm::Value *field) = 0; |
| 704 | }; |
| 705 | |
| 706 | llvm::FoldingSet<ByrefHelpers> ByrefHelpersCache; |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 707 | |
John McCall | 147d021 | 2011-02-22 22:38:33 +0000 | [diff] [blame] | 708 | /// getUniqueBlockCount - Fetches the global unique block count. |
| 709 | int getUniqueBlockCount() { return ++Block.GlobalUniqueCount; } |
Fariborz Jahanian | 6362803 | 2012-06-26 16:06:38 +0000 | [diff] [blame] | 710 | |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 711 | /// getBlockDescriptorType - Fetches the type of a generic block |
| 712 | /// descriptor. |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 713 | llvm::Type *getBlockDescriptorType(); |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 714 | |
| 715 | /// getGenericBlockLiteralType - The type of a generic block literal. |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 716 | llvm::Type *getGenericBlockLiteralType(); |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 717 | |
| 718 | /// GetAddrOfGlobalBlock - Gets the address of a block which |
| 719 | /// requires no captures. |
| 720 | llvm::Constant *GetAddrOfGlobalBlock(const BlockExpr *BE, const char *); |
Anders Carlsson | 8a64c1c | 2010-04-24 21:23:59 +0000 | [diff] [blame] | 721 | |
Mike Stump | 1676c5b | 2009-02-13 19:12:34 +0000 | [diff] [blame] | 722 | /// GetAddrOfConstantCFString - Return a pointer to a constant CFString object |
| 723 | /// for the given string. |
Steve Naroff | e14b368 | 2009-04-01 13:55:36 +0000 | [diff] [blame] | 724 | llvm::Constant *GetAddrOfConstantCFString(const StringLiteral *Literal); |
Fariborz Jahanian | 63408e8 | 2010-04-22 20:26:39 +0000 | [diff] [blame] | 725 | |
Fariborz Jahanian | 50c925f | 2010-10-19 17:19:29 +0000 | [diff] [blame] | 726 | /// GetAddrOfConstantString - Return a pointer to a constant NSString object |
| 727 | /// for the given string. Or a user defined String object as defined via |
| 728 | /// -fconstant-string-class=class_name option. |
| 729 | llvm::Constant *GetAddrOfConstantString(const StringLiteral *Literal); |
Chris Lattner | 36fc879 | 2008-02-11 00:02:17 +0000 | [diff] [blame] | 730 | |
Eli Friedman | fcec630 | 2011-11-01 02:23:42 +0000 | [diff] [blame] | 731 | /// GetConstantArrayFromStringLiteral - Return a constant array for the given |
| 732 | /// string. |
| 733 | llvm::Constant *GetConstantArrayFromStringLiteral(const StringLiteral *E); |
| 734 | |
Mike Stump | 1676c5b | 2009-02-13 19:12:34 +0000 | [diff] [blame] | 735 | /// GetAddrOfConstantStringFromLiteral - Return a pointer to a constant array |
| 736 | /// for the given string literal. |
Daniel Dunbar | c4baa06 | 2008-08-13 23:20:05 +0000 | [diff] [blame] | 737 | llvm::Constant *GetAddrOfConstantStringFromLiteral(const StringLiteral *S); |
Daniel Dunbar | 6dfdf8c | 2008-08-10 20:25:57 +0000 | [diff] [blame] | 738 | |
Chris Lattner | d7e7b8e | 2009-02-24 22:18:39 +0000 | [diff] [blame] | 739 | /// GetAddrOfConstantStringFromObjCEncode - Return a pointer to a constant |
| 740 | /// array for the given ObjCEncodeExpr node. |
| 741 | llvm::Constant *GetAddrOfConstantStringFromObjCEncode(const ObjCEncodeExpr *); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 742 | |
Daniel Dunbar | c4baa06 | 2008-08-13 23:20:05 +0000 | [diff] [blame] | 743 | /// GetAddrOfConstantString - Returns a pointer to a character array |
Mike Stump | 1676c5b | 2009-02-13 19:12:34 +0000 | [diff] [blame] | 744 | /// containing the literal. This contents are exactly that of the given |
| 745 | /// string, i.e. it will not be null terminated automatically; see |
| 746 | /// GetAddrOfConstantCString. Note that whether the result is actually a |
| 747 | /// pointer to an LLVM constant depends on Feature.WriteableStrings. |
Daniel Dunbar | c4baa06 | 2008-08-13 23:20:05 +0000 | [diff] [blame] | 748 | /// |
| 749 | /// The result has pointer to array type. |
Daniel Dunbar | dfcf599 | 2008-10-17 21:56:50 +0000 | [diff] [blame] | 750 | /// |
| 751 | /// \param GlobalName If provided, the name to use for the global |
| 752 | /// (if one is created). |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 753 | llvm::Constant *GetAddrOfConstantString(StringRef Str, |
John McCall | 9b24df4 | 2011-08-04 01:03:22 +0000 | [diff] [blame] | 754 | const char *GlobalName=0, |
Ulrich Weigand | fa80642 | 2013-05-06 16:23:57 +0000 | [diff] [blame] | 755 | unsigned Alignment=0); |
Daniel Dunbar | c4baa06 | 2008-08-13 23:20:05 +0000 | [diff] [blame] | 756 | |
Mike Stump | 1676c5b | 2009-02-13 19:12:34 +0000 | [diff] [blame] | 757 | /// GetAddrOfConstantCString - Returns a pointer to a character array |
| 758 | /// containing the literal and a terminating '\0' character. The result has |
| 759 | /// pointer to array type. |
Daniel Dunbar | dfcf599 | 2008-10-17 21:56:50 +0000 | [diff] [blame] | 760 | /// |
Mike Stump | 1676c5b | 2009-02-13 19:12:34 +0000 | [diff] [blame] | 761 | /// \param GlobalName If provided, the name to use for the global (if one is |
| 762 | /// created). |
Daniel Dunbar | dfcf599 | 2008-10-17 21:56:50 +0000 | [diff] [blame] | 763 | llvm::Constant *GetAddrOfConstantCString(const std::string &str, |
John McCall | 9b24df4 | 2011-08-04 01:03:22 +0000 | [diff] [blame] | 764 | const char *GlobalName=0, |
Ulrich Weigand | fa80642 | 2013-05-06 16:23:57 +0000 | [diff] [blame] | 765 | unsigned Alignment=0); |
Richard Smith | 2d988f0 | 2011-11-22 22:48:32 +0000 | [diff] [blame] | 766 | |
| 767 | /// GetAddrOfConstantCompoundLiteral - Returns a pointer to a constant global |
| 768 | /// variable for the given file-scope compound literal expression. |
| 769 | llvm::Constant *GetAddrOfConstantCompoundLiteral(const CompoundLiteralExpr*E); |
Richard Smith | e6c0144 | 2013-06-05 00:46:14 +0000 | [diff] [blame] | 770 | |
| 771 | /// \brief Returns a pointer to a global variable representing a temporary |
| 772 | /// with static or thread storage duration. |
| 773 | llvm::Constant *GetAddrOfGlobalTemporary(const MaterializeTemporaryExpr *E, |
| 774 | const Expr *Inner); |
| 775 | |
Douglas Gregor | 636e200 | 2011-08-09 17:23:49 +0000 | [diff] [blame] | 776 | /// \brief Retrieve the record type that describes the state of an |
| 777 | /// Objective-C fast enumeration loop (for..in). |
| 778 | QualType getObjCFastEnumerationStateType(); |
| 779 | |
Anders Carlsson | e8eeffd | 2009-04-16 23:57:24 +0000 | [diff] [blame] | 780 | /// GetAddrOfCXXConstructor - Return the address of the constructor of the |
| 781 | /// given type. |
John McCall | 46288ef | 2011-03-09 08:12:35 +0000 | [diff] [blame] | 782 | llvm::GlobalValue *GetAddrOfCXXConstructor(const CXXConstructorDecl *ctor, |
| 783 | CXXCtorType ctorType, |
Rafael Espindola | 94abb8f | 2013-12-09 04:29:47 +0000 | [diff] [blame] | 784 | const CGFunctionInfo *fnInfo = 0, |
| 785 | bool DontDefer = false); |
Anders Carlsson | eaa28f7 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 786 | |
| 787 | /// GetAddrOfCXXDestructor - Return the address of the constructor of the |
| 788 | /// given type. |
John McCall | 46288ef | 2011-03-09 08:12:35 +0000 | [diff] [blame] | 789 | llvm::GlobalValue *GetAddrOfCXXDestructor(const CXXDestructorDecl *dtor, |
| 790 | CXXDtorType dtorType, |
Reid Kleckner | e7de47e | 2013-07-22 13:51:44 +0000 | [diff] [blame] | 791 | const CGFunctionInfo *fnInfo = 0, |
Rafael Espindola | 94abb8f | 2013-12-09 04:29:47 +0000 | [diff] [blame] | 792 | llvm::FunctionType *fnType = 0, |
| 793 | bool DontDefer = false); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 794 | |
Daniel Dunbar | fce4be8 | 2008-08-15 23:26:23 +0000 | [diff] [blame] | 795 | /// getBuiltinLibFunction - Given a builtin id for a function like |
| 796 | /// "__builtin_fabsf", return a Function* for "fabsf". |
Daniel Dunbar | ff0553e | 2009-09-14 04:33:21 +0000 | [diff] [blame] | 797 | llvm::Value *getBuiltinLibFunction(const FunctionDecl *FD, |
| 798 | unsigned BuiltinID); |
Daniel Dunbar | c4baa06 | 2008-08-13 23:20:05 +0000 | [diff] [blame] | 799 | |
Dmitri Gribenko | 44ebbd5 | 2013-05-05 00:41:58 +0000 | [diff] [blame] | 800 | llvm::Function *getIntrinsic(unsigned IID, ArrayRef<llvm::Type*> Tys = None); |
Daniel Dunbar | 9c42652 | 2008-07-29 23:18:29 +0000 | [diff] [blame] | 801 | |
Daniel Dunbar | fce4be8 | 2008-08-15 23:26:23 +0000 | [diff] [blame] | 802 | /// EmitTopLevelDecl - Emit code for a single top level declaration. |
| 803 | void EmitTopLevelDecl(Decl *D); |
Daniel Dunbar | 9c42652 | 2008-07-29 23:18:29 +0000 | [diff] [blame] | 804 | |
Rafael Espindola | df88f6f | 2012-03-08 15:51:03 +0000 | [diff] [blame] | 805 | /// HandleCXXStaticMemberVarInstantiation - Tell the consumer that this |
| 806 | // variable has been instantiated. |
| 807 | void HandleCXXStaticMemberVarInstantiation(VarDecl *VD); |
Rafael Espindola | 189fa74 | 2012-03-05 10:54:55 +0000 | [diff] [blame] | 808 | |
Richard Smith | df931ce | 2013-04-06 05:00:46 +0000 | [diff] [blame] | 809 | /// \brief If the declaration has internal linkage but is inside an |
| 810 | /// extern "C" linkage specification, prepare to emit an alias for it |
| 811 | /// to the expected name. |
| 812 | template<typename SomeDecl> |
| 813 | void MaybeHandleStaticInExternC(const SomeDecl *D, llvm::GlobalValue *GV); |
| 814 | |
Rafael Espindola | 060062a | 2014-03-06 22:15:10 +0000 | [diff] [blame] | 815 | /// Add a global to a list to be added to the llvm.used metadata. |
| 816 | void addUsedGlobal(llvm::GlobalValue *GV); |
| 817 | |
| 818 | /// Add a global to a list to be added to the llvm.compiler.used metadata. |
| 819 | void addCompilerUsedGlobal(llvm::GlobalValue *GV); |
Daniel Dunbar | 08b26a0 | 2009-02-13 20:29:50 +0000 | [diff] [blame] | 820 | |
Daniel Dunbar | fe06df4 | 2010-03-20 04:15:41 +0000 | [diff] [blame] | 821 | /// AddCXXDtorEntry - Add a destructor and object to add to the C++ global |
| 822 | /// destructor function. |
Chris Lattner | 87233f7 | 2010-06-19 05:52:45 +0000 | [diff] [blame] | 823 | void AddCXXDtorEntry(llvm::Constant *DtorFn, llvm::Constant *Object) { |
| 824 | CXXGlobalDtors.push_back(std::make_pair(DtorFn, Object)); |
| 825 | } |
Daniel Dunbar | fe06df4 | 2010-03-20 04:15:41 +0000 | [diff] [blame] | 826 | |
Chris Lattner | d480892 | 2009-03-22 21:03:39 +0000 | [diff] [blame] | 827 | /// CreateRuntimeFunction - Create a new runtime function with the specified |
| 828 | /// type and name. |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 829 | llvm::Constant *CreateRuntimeFunction(llvm::FunctionType *Ty, |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 830 | StringRef Name, |
Bill Wendling | 8594fcb | 2013-01-31 00:30:05 +0000 | [diff] [blame] | 831 | llvm::AttributeSet ExtraAttrs = |
| 832 | llvm::AttributeSet()); |
Chris Lattner | d480892 | 2009-03-22 21:03:39 +0000 | [diff] [blame] | 833 | /// CreateRuntimeVariable - Create a new runtime global variable with the |
| 834 | /// specified type and name. |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 835 | llvm::Constant *CreateRuntimeVariable(llvm::Type *Ty, |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 836 | StringRef Name); |
Daniel Dunbar | 23fd462 | 2008-10-01 00:49:24 +0000 | [diff] [blame] | 837 | |
Daniel Dunbar | 900546d | 2010-07-16 00:00:15 +0000 | [diff] [blame] | 838 | ///@name Custom Blocks Runtime Interfaces |
| 839 | ///@{ |
| 840 | |
| 841 | llvm::Constant *getNSConcreteGlobalBlock(); |
| 842 | llvm::Constant *getNSConcreteStackBlock(); |
| 843 | llvm::Constant *getBlockObjectAssign(); |
| 844 | llvm::Constant *getBlockObjectDispose(); |
| 845 | |
| 846 | ///@} |
| 847 | |
Nadav Rotem | 1da3094 | 2013-03-23 06:43:35 +0000 | [diff] [blame] | 848 | llvm::Constant *getLLVMLifetimeStartFn(); |
| 849 | llvm::Constant *getLLVMLifetimeEndFn(); |
| 850 | |
Devang Patel | 945b8ae | 2011-03-23 16:29:39 +0000 | [diff] [blame] | 851 | // UpdateCompleteType - Make sure that this type is translated. |
| 852 | void UpdateCompletedType(const TagDecl *TD); |
Daniel Dunbar | 38ad1e6 | 2009-02-17 18:43:32 +0000 | [diff] [blame] | 853 | |
John McCall | f3a8860 | 2011-02-03 08:15:49 +0000 | [diff] [blame] | 854 | llvm::Constant *getMemberPointerConstant(const UnaryOperator *e); |
| 855 | |
Richard Smith | dafff94 | 2012-01-14 04:30:29 +0000 | [diff] [blame] | 856 | /// EmitConstantInit - Try to emit the initializer for the given declaration |
| 857 | /// as a constant; returns 0 if the expression cannot be emitted as a |
| 858 | /// constant. |
| 859 | llvm::Constant *EmitConstantInit(const VarDecl &D, CodeGenFunction *CGF = 0); |
| 860 | |
Daniel Dunbar | 38ad1e6 | 2009-02-17 18:43:32 +0000 | [diff] [blame] | 861 | /// EmitConstantExpr - Try to emit the given expression as a |
| 862 | /// constant; returns 0 if the expression cannot be emitted as a |
| 863 | /// constant. |
Anders Carlsson | 80f97ab | 2009-04-08 04:48:15 +0000 | [diff] [blame] | 864 | llvm::Constant *EmitConstantExpr(const Expr *E, QualType DestType, |
| 865 | CodeGenFunction *CGF = 0); |
Daniel Dunbar | 38ad1e6 | 2009-02-17 18:43:32 +0000 | [diff] [blame] | 866 | |
Richard Smith | bc638767 | 2012-03-02 23:27:11 +0000 | [diff] [blame] | 867 | /// EmitConstantValue - Emit the given constant value as a constant, in the |
| 868 | /// type's scalar representation. |
Richard Smith | dafff94 | 2012-01-14 04:30:29 +0000 | [diff] [blame] | 869 | llvm::Constant *EmitConstantValue(const APValue &Value, QualType DestType, |
| 870 | CodeGenFunction *CGF = 0); |
| 871 | |
Richard Smith | bc638767 | 2012-03-02 23:27:11 +0000 | [diff] [blame] | 872 | /// EmitConstantValueForMemory - Emit the given constant value as a constant, |
| 873 | /// in the type's memory representation. |
| 874 | llvm::Constant *EmitConstantValueForMemory(const APValue &Value, |
| 875 | QualType DestType, |
| 876 | CodeGenFunction *CGF = 0); |
| 877 | |
Eli Friedman | 20bb5e0 | 2009-04-13 21:47:26 +0000 | [diff] [blame] | 878 | /// EmitNullConstant - Return the result of value-initializing the given |
| 879 | /// type, i.e. a null expression of the given type. This is usually, |
| 880 | /// but not always, an LLVM null constant. |
| 881 | llvm::Constant *EmitNullConstant(QualType T); |
| 882 | |
Eli Friedman | fde961d | 2011-10-14 02:27:24 +0000 | [diff] [blame] | 883 | /// EmitNullConstantForBase - Return a null constant appropriate for |
| 884 | /// zero-initializing a base class with the given type. This is usually, |
| 885 | /// but not always, an LLVM null constant. |
| 886 | llvm::Constant *EmitNullConstantForBase(const CXXRecordDecl *Record); |
| 887 | |
John McCall | 7ef5cb3 | 2011-03-18 02:56:14 +0000 | [diff] [blame] | 888 | /// Error - Emit a general error that something can't be done. |
Chandler Carruth | 8453795 | 2012-03-30 19:44:53 +0000 | [diff] [blame] | 889 | void Error(SourceLocation loc, StringRef error); |
John McCall | 7ef5cb3 | 2011-03-18 02:56:14 +0000 | [diff] [blame] | 890 | |
Daniel Dunbar | a7c8cf6 | 2008-08-16 00:56:44 +0000 | [diff] [blame] | 891 | /// ErrorUnsupported - Print out an error that codegen doesn't support the |
Daniel Dunbar | f2cf6d1 | 2008-09-04 03:43:08 +0000 | [diff] [blame] | 892 | /// specified stmt yet. |
David Blaikie | 4a9ec7b | 2013-08-19 21:02:26 +0000 | [diff] [blame] | 893 | void ErrorUnsupported(const Stmt *S, const char *Type); |
Mike Stump | 1676c5b | 2009-02-13 19:12:34 +0000 | [diff] [blame] | 894 | |
Daniel Dunbar | a7c8cf6 | 2008-08-16 00:56:44 +0000 | [diff] [blame] | 895 | /// ErrorUnsupported - Print out an error that codegen doesn't support the |
Chris Lattner | 38376f1 | 2008-01-12 07:05:38 +0000 | [diff] [blame] | 896 | /// specified decl yet. |
David Blaikie | 4a9ec7b | 2013-08-19 21:02:26 +0000 | [diff] [blame] | 897 | void ErrorUnsupported(const Decl *D, const char *Type); |
Dan Gohman | 75d69da | 2008-05-22 00:50:06 +0000 | [diff] [blame] | 898 | |
Daniel Dunbar | c3e7cff | 2009-04-17 00:48:04 +0000 | [diff] [blame] | 899 | /// SetInternalFunctionAttributes - Set the attributes on the LLVM |
| 900 | /// function for the given decl and function info. This applies |
| 901 | /// attributes necessary for handling the ABI as well as user |
| 902 | /// specified attributes like section. |
| 903 | void SetInternalFunctionAttributes(const Decl *D, llvm::Function *F, |
| 904 | const CGFunctionInfo &FI); |
Daniel Dunbar | 449a339 | 2008-09-04 23:41:35 +0000 | [diff] [blame] | 905 | |
Daniel Dunbar | aeddffc | 2009-04-14 07:08:30 +0000 | [diff] [blame] | 906 | /// SetLLVMFunctionAttributes - Set the LLVM function attributes |
| 907 | /// (sext, zext, etc). |
| 908 | void SetLLVMFunctionAttributes(const Decl *D, |
| 909 | const CGFunctionInfo &Info, |
| 910 | llvm::Function *F); |
Daniel Dunbar | c68897d | 2008-09-10 00:41:16 +0000 | [diff] [blame] | 911 | |
Daniel Dunbar | 3893257 | 2009-04-14 08:05:55 +0000 | [diff] [blame] | 912 | /// SetLLVMFunctionAttributesForDefinition - Set the LLVM function attributes |
| 913 | /// which only apply to a function definintion. |
| 914 | void SetLLVMFunctionAttributesForDefinition(const Decl *D, llvm::Function *F); |
| 915 | |
Sylvestre Ledru | 33b5baf | 2012-09-27 10:16:10 +0000 | [diff] [blame] | 916 | /// ReturnTypeUsesSRet - Return true iff the given type uses 'sret' when used |
Mike Stump | 1676c5b | 2009-02-13 19:12:34 +0000 | [diff] [blame] | 917 | /// as a return type. |
Daniel Dunbar | 6f2e839 | 2010-07-14 23:39:36 +0000 | [diff] [blame] | 918 | bool ReturnTypeUsesSRet(const CGFunctionInfo &FI); |
| 919 | |
Tim Northover | e77cc39 | 2014-03-29 13:28:05 +0000 | [diff] [blame] | 920 | /// ReturnSlotInterferesWithArgs - Return true iff the given type uses an |
| 921 | /// argument slot when 'sret' is used as a return type. |
| 922 | bool ReturnSlotInterferesWithArgs(const CGFunctionInfo &FI); |
| 923 | |
Sylvestre Ledru | 33b5baf | 2012-09-27 10:16:10 +0000 | [diff] [blame] | 924 | /// ReturnTypeUsesFPRet - Return true iff the given type uses 'fpret' when |
Anders Carlsson | 2f1a6c3 | 2011-10-31 16:27:11 +0000 | [diff] [blame] | 925 | /// used as a return type. |
Daniel Dunbar | 6f2e839 | 2010-07-14 23:39:36 +0000 | [diff] [blame] | 926 | bool ReturnTypeUsesFPRet(QualType ResultType); |
Daniel Dunbar | c68897d | 2008-09-10 00:41:16 +0000 | [diff] [blame] | 927 | |
Sylvestre Ledru | 33b5baf | 2012-09-27 10:16:10 +0000 | [diff] [blame] | 928 | /// ReturnTypeUsesFP2Ret - Return true iff the given type uses 'fp2ret' when |
Anders Carlsson | 2f1a6c3 | 2011-10-31 16:27:11 +0000 | [diff] [blame] | 929 | /// used as a return type. |
| 930 | bool ReturnTypeUsesFP2Ret(QualType ResultType); |
| 931 | |
Daniel Dunbar | 0ef3479 | 2009-09-12 00:59:20 +0000 | [diff] [blame] | 932 | /// ConstructAttributeList - Get the LLVM attributes and calling convention to |
| 933 | /// use for a particular function type. |
| 934 | /// |
| 935 | /// \param Info - The function type information. |
| 936 | /// \param TargetDecl - The decl these attributes are being constructed |
| 937 | /// for. If supplied the attributes applied to this decl may contribute to the |
| 938 | /// function attributes and calling convention. |
| 939 | /// \param PAL [out] - On return, the attribute list to use. |
| 940 | /// \param CallingConv [out] - On return, the LLVM calling convention to use. |
Daniel Dunbar | d931a87 | 2009-02-02 22:03:45 +0000 | [diff] [blame] | 941 | void ConstructAttributeList(const CGFunctionInfo &Info, |
| 942 | const Decl *TargetDecl, |
Daniel Dunbar | 0ef3479 | 2009-09-12 00:59:20 +0000 | [diff] [blame] | 943 | AttributeListType &PAL, |
Bill Wendling | f4d64cb | 2013-02-22 00:13:35 +0000 | [diff] [blame] | 944 | unsigned &CallingConv, |
| 945 | bool AttrOnCallSite); |
Daniel Dunbar | c68897d | 2008-09-10 00:41:16 +0000 | [diff] [blame] | 946 | |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 947 | StringRef getMangledName(GlobalDecl GD); |
Peter Collingbourne | 0ff0b37 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 948 | void getBlockMangledName(GlobalDecl GD, MangleBuffer &Buffer, |
| 949 | const BlockDecl *BD); |
Douglas Gregor | beecd58 | 2009-04-21 17:11:58 +0000 | [diff] [blame] | 950 | |
| 951 | void EmitTentativeDefinition(const VarDecl *D); |
Mike Stump | bc78a72 | 2009-07-31 18:25:34 +0000 | [diff] [blame] | 952 | |
Douglas Gregor | 88d292c | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 953 | void EmitVTable(CXXRecordDecl *Class, bool DefinitionRequired); |
| 954 | |
Timur Iskhodzhanov | 8b5987e | 2013-09-27 14:48:01 +0000 | [diff] [blame] | 955 | /// EmitFundamentalRTTIDescriptors - Emit the RTTI descriptors for the |
| 956 | /// builtin types. |
| 957 | void EmitFundamentalRTTIDescriptors(); |
| 958 | |
Reid Kleckner | e43f0fe | 2013-05-08 13:44:39 +0000 | [diff] [blame] | 959 | /// \brief Appends Opts to the "Linker Options" metadata value. |
| 960 | void AppendLinkerOptions(StringRef Opts); |
| 961 | |
Benjamin Kramer | 82dfc97 | 2013-06-04 09:13:21 +0000 | [diff] [blame] | 962 | /// \brief Appends a detect mismatch command to the linker options. |
Aaron Ballman | 5d041be | 2013-06-04 02:07:14 +0000 | [diff] [blame] | 963 | void AddDetectMismatch(StringRef Name, StringRef Value); |
| 964 | |
Reid Kleckner | e43f0fe | 2013-05-08 13:44:39 +0000 | [diff] [blame] | 965 | /// \brief Appends a dependent lib to the "Linker Options" metadata value. |
| 966 | void AddDependentLib(StringRef Lib); |
| 967 | |
Peter Collingbourne | 4d90dba | 2013-06-05 17:49:37 +0000 | [diff] [blame] | 968 | llvm::GlobalVariable::LinkageTypes getFunctionLinkage(GlobalDecl GD); |
John McCall | d432414 | 2010-02-19 01:32:20 +0000 | [diff] [blame] | 969 | |
Peter Collingbourne | 4d90dba | 2013-06-05 17:49:37 +0000 | [diff] [blame] | 970 | void setFunctionLinkage(GlobalDecl GD, llvm::GlobalValue *V) { |
| 971 | V->setLinkage(getFunctionLinkage(GD)); |
John McCall | 7cb0220 | 2010-05-25 04:30:21 +0000 | [diff] [blame] | 972 | } |
| 973 | |
Anders Carlsson | 11e5140 | 2010-04-17 20:15:18 +0000 | [diff] [blame] | 974 | /// getVTableLinkage - Return the appropriate linkage for the vtable, VTT, |
Douglas Gregor | ccecc1b | 2010-01-06 20:27:16 +0000 | [diff] [blame] | 975 | /// and type information of the given class. |
Anders Carlsson | 68d3424 | 2011-01-24 02:04:33 +0000 | [diff] [blame] | 976 | llvm::GlobalVariable::LinkageTypes getVTableLinkage(const CXXRecordDecl *RD); |
Ken Dyck | 98ca794 | 2010-01-26 13:48:07 +0000 | [diff] [blame] | 977 | |
| 978 | /// GetTargetTypeStoreSize - Return the store size, in character units, of |
| 979 | /// the given LLVM type. |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 980 | CharUnits GetTargetTypeStoreSize(llvm::Type *Ty) const; |
Fariborz Jahanian | 1518a5ec | 2010-10-27 16:21:54 +0000 | [diff] [blame] | 981 | |
| 982 | /// GetLLVMLinkageVarDefinition - Returns LLVM linkage for a global |
| 983 | /// variable. |
| 984 | llvm::GlobalValue::LinkageTypes |
Eli Friedman | 7e346a8 | 2013-07-01 20:22:57 +0000 | [diff] [blame] | 985 | GetLLVMLinkageVarDefinition(const VarDecl *D, bool isConstant); |
Fariborz Jahanian | 1518a5ec | 2010-10-27 16:21:54 +0000 | [diff] [blame] | 986 | |
Julien Lerouge | 5a6b698 | 2011-09-09 22:41:49 +0000 | [diff] [blame] | 987 | /// Emit all the global annotations. |
| 988 | void EmitGlobalAnnotations(); |
| 989 | |
| 990 | /// Emit an annotation string. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 991 | llvm::Constant *EmitAnnotationString(StringRef Str); |
Julien Lerouge | 5a6b698 | 2011-09-09 22:41:49 +0000 | [diff] [blame] | 992 | |
| 993 | /// Emit the annotation's translation unit. |
| 994 | llvm::Constant *EmitAnnotationUnit(SourceLocation Loc); |
| 995 | |
| 996 | /// Emit the annotation line number. |
| 997 | llvm::Constant *EmitAnnotationLineNo(SourceLocation L); |
| 998 | |
| 999 | /// EmitAnnotateAttr - Generate the llvm::ConstantStruct which contains the |
| 1000 | /// annotation information for a given GlobalValue. The annotation struct is |
| 1001 | /// {i8 *, i8 *, i8 *, i32}. The first field is a constant expression, the |
| 1002 | /// GlobalValue being annotated. The second field is the constant string |
| 1003 | /// created from the AnnotateAttr's annotation. The third field is a constant |
| 1004 | /// string containing the name of the translation unit. The fourth field is |
| 1005 | /// the line number in the file of the annotated value declaration. |
| 1006 | llvm::Constant *EmitAnnotateAttr(llvm::GlobalValue *GV, |
| 1007 | const AnnotateAttr *AA, |
| 1008 | SourceLocation L); |
| 1009 | |
| 1010 | /// Add global annotations that are set on D, for the global GV. Those |
| 1011 | /// annotations are emitted during finalization of the LLVM code. |
| 1012 | void AddGlobalAnnotations(const ValueDecl *D, llvm::GlobalValue *GV); |
| 1013 | |
Peter Collingbourne | 41148a8 | 2013-07-09 22:03:30 +0000 | [diff] [blame] | 1014 | const llvm::SpecialCaseList &getSanitizerBlacklist() const { |
Alexey Samsonov | d6e043b | 2013-08-12 11:48:05 +0000 | [diff] [blame] | 1015 | return *SanitizerBlacklist; |
Will Dietz | f54319c | 2013-01-18 11:30:38 +0000 | [diff] [blame] | 1016 | } |
| 1017 | |
| 1018 | const SanitizerOptions &getSanOpts() const { return SanOpts; } |
| 1019 | |
John McCall | 6bd2a89 | 2013-01-25 22:31:03 +0000 | [diff] [blame] | 1020 | void addDeferredVTable(const CXXRecordDecl *RD) { |
| 1021 | DeferredVTables.push_back(RD); |
| 1022 | } |
| 1023 | |
Reid Kleckner | e7de47e | 2013-07-22 13:51:44 +0000 | [diff] [blame] | 1024 | /// EmitGlobal - Emit code for a singal global function or var decl. Forward |
| 1025 | /// declarations are emitted lazily. |
| 1026 | void EmitGlobal(GlobalDecl D); |
| 1027 | |
Chris Lattner | 5bcdf24 | 2007-12-02 07:09:19 +0000 | [diff] [blame] | 1028 | private: |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 1029 | llvm::GlobalValue *GetGlobalValue(StringRef Ref); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1030 | |
Rafael Espindola | 94abb8f | 2013-12-09 04:29:47 +0000 | [diff] [blame] | 1031 | llvm::Constant * |
| 1032 | GetOrCreateLLVMFunction(StringRef MangledName, llvm::Type *Ty, GlobalDecl D, |
| 1033 | bool ForVTable, bool DontDefer = false, |
| 1034 | llvm::AttributeSet ExtraAttrs = llvm::AttributeSet()); |
| 1035 | |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 1036 | llvm::Constant *GetOrCreateLLVMGlobal(StringRef MangledName, |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 1037 | llvm::PointerType *PTy, |
Rafael Espindola | d661a85 | 2011-01-18 21:07:57 +0000 | [diff] [blame] | 1038 | const VarDecl *D, |
| 1039 | bool UnnamedAddr = false); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1040 | |
Daniel Dunbar | 3893257 | 2009-04-14 08:05:55 +0000 | [diff] [blame] | 1041 | /// SetCommonAttributes - Set attributes which are common to any |
| 1042 | /// form of a global definition (alias, Objective-C method, |
| 1043 | /// function, global variable). |
Daniel Dunbar | aeddffc | 2009-04-14 07:08:30 +0000 | [diff] [blame] | 1044 | /// |
Daniel Dunbar | 3893257 | 2009-04-14 08:05:55 +0000 | [diff] [blame] | 1045 | /// NOTE: This should only be called for definitions. |
| 1046 | void SetCommonAttributes(const Decl *D, llvm::GlobalValue *GV); |
Daniel Dunbar | 449a339 | 2008-09-04 23:41:35 +0000 | [diff] [blame] | 1047 | |
Daniel Dunbar | 3893257 | 2009-04-14 08:05:55 +0000 | [diff] [blame] | 1048 | /// SetFunctionDefinitionAttributes - Set attributes for a global definition. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1049 | void SetFunctionDefinitionAttributes(const FunctionDecl *D, |
Eli Friedman | 895771a | 2009-05-26 01:22:57 +0000 | [diff] [blame] | 1050 | llvm::GlobalValue *GV); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1051 | |
Daniel Dunbar | aeddffc | 2009-04-14 07:08:30 +0000 | [diff] [blame] | 1052 | /// SetFunctionAttributes - Set function attributes for a function |
| 1053 | /// declaration. |
Anders Carlsson | 6710c53 | 2010-02-06 02:44:09 +0000 | [diff] [blame] | 1054 | void SetFunctionAttributes(GlobalDecl GD, |
Eli Friedman | 895771a | 2009-05-26 01:22:57 +0000 | [diff] [blame] | 1055 | llvm::Function *F, |
| 1056 | bool IsIncompleteFunction); |
Nuno Lopes | b6f7953 | 2008-06-08 15:45:52 +0000 | [diff] [blame] | 1057 | |
Rafael Espindola | cd7743b | 2013-12-09 16:01:03 +0000 | [diff] [blame] | 1058 | void EmitGlobalDefinition(GlobalDecl D, llvm::GlobalValue *GV = 0); |
Daniel Dunbar | f0acf7b | 2009-02-19 07:15:39 +0000 | [diff] [blame] | 1059 | |
Rafael Espindola | cd7743b | 2013-12-09 16:01:03 +0000 | [diff] [blame] | 1060 | void EmitGlobalFunctionDefinition(GlobalDecl GD, llvm::GlobalValue *GV); |
Daniel Dunbar | 9c42652 | 2008-07-29 23:18:29 +0000 | [diff] [blame] | 1061 | void EmitGlobalVarDefinition(const VarDecl *D); |
John McCall | 7ec5043 | 2010-03-19 23:29:14 +0000 | [diff] [blame] | 1062 | void EmitAliasDefinition(GlobalDecl GD); |
Daniel Dunbar | 89654ee | 2008-08-26 08:29:31 +0000 | [diff] [blame] | 1063 | void EmitObjCPropertyImplementations(const ObjCImplementationDecl *D); |
Fariborz Jahanian | 0dec1e0 | 2010-04-28 21:28:56 +0000 | [diff] [blame] | 1064 | void EmitObjCIvarInitializations(ObjCImplementationDecl *D); |
Fariborz Jahanian | 1518a5ec | 2010-10-27 16:21:54 +0000 | [diff] [blame] | 1065 | |
Anders Carlsson | f747524 | 2009-04-15 15:55:24 +0000 | [diff] [blame] | 1066 | // C++ related functions. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1067 | |
Rafael Espindola | 3f643bd | 2013-11-04 18:38:59 +0000 | [diff] [blame] | 1068 | bool TryEmitDefinitionAsAlias(GlobalDecl Alias, GlobalDecl Target, |
| 1069 | bool InEveryTU); |
John McCall | f8ff7b9 | 2010-02-23 00:48:20 +0000 | [diff] [blame] | 1070 | bool TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D); |
John McCall | d432414 | 2010-02-19 01:32:20 +0000 | [diff] [blame] | 1071 | |
Anders Carlsson | 237f349 | 2009-04-01 00:58:25 +0000 | [diff] [blame] | 1072 | void EmitNamespace(const NamespaceDecl *D); |
Anders Carlsson | cbaeb9e | 2009-04-02 05:55:18 +0000 | [diff] [blame] | 1073 | void EmitLinkageSpec(const LinkageSpecDecl *D); |
Adrian Prantl | ffcf4ba | 2013-05-09 23:16:27 +0000 | [diff] [blame] | 1074 | void CompleteDIClassType(const CXXMethodDecl* D); |
Anders Carlsson | f747524 | 2009-04-15 15:55:24 +0000 | [diff] [blame] | 1075 | |
Anders Carlsson | f747524 | 2009-04-15 15:55:24 +0000 | [diff] [blame] | 1076 | /// EmitCXXConstructor - Emit a single constructor with the given type from |
| 1077 | /// a C++ constructor Decl. |
| 1078 | void EmitCXXConstructor(const CXXConstructorDecl *D, CXXCtorType Type); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1079 | |
Anders Carlsson | eaa28f7 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 1080 | /// EmitCXXDestructor - Emit a single destructor with the given type from |
| 1081 | /// a C++ destructor Decl. |
| 1082 | void EmitCXXDestructor(const CXXDestructorDecl *D, CXXDtorType Type); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1083 | |
Richard Smith | 2fd1d7a | 2013-04-19 16:42:07 +0000 | [diff] [blame] | 1084 | /// \brief Emit the function that initializes C++ thread_local variables. |
| 1085 | void EmitCXXThreadLocalInitFunc(); |
| 1086 | |
Daniel Dunbar | fe06df4 | 2010-03-20 04:15:41 +0000 | [diff] [blame] | 1087 | /// EmitCXXGlobalInitFunc - Emit the function that initializes C++ globals. |
Anders Carlsson | b8be93f | 2009-08-08 23:24:23 +0000 | [diff] [blame] | 1088 | void EmitCXXGlobalInitFunc(); |
Eli Friedman | 5866fe3 | 2010-01-08 00:50:11 +0000 | [diff] [blame] | 1089 | |
Daniel Dunbar | fe06df4 | 2010-03-20 04:15:41 +0000 | [diff] [blame] | 1090 | /// EmitCXXGlobalDtorFunc - Emit the function that destroys C++ globals. |
| 1091 | void EmitCXXGlobalDtorFunc(); |
| 1092 | |
Richard Smith | 6331c40 | 2012-02-13 22:16:19 +0000 | [diff] [blame] | 1093 | /// EmitCXXGlobalVarDeclInitFunc - Emit the function that initializes the |
| 1094 | /// specified global (if PerformInit is true) and registers its destructor. |
John McCall | cdf7ef5 | 2010-11-06 09:44:32 +0000 | [diff] [blame] | 1095 | void EmitCXXGlobalVarDeclInitFunc(const VarDecl *D, |
Richard Smith | 6331c40 | 2012-02-13 22:16:19 +0000 | [diff] [blame] | 1096 | llvm::GlobalVariable *Addr, |
| 1097 | bool PerformInit); |
Eli Friedman | 5866fe3 | 2010-01-08 00:50:11 +0000 | [diff] [blame] | 1098 | |
Daniel Dunbar | 74aa7e1 | 2008-08-01 00:01:51 +0000 | [diff] [blame] | 1099 | // FIXME: Hardcoding priority here is gross. |
Chris Lattner | e0be0df | 2009-05-12 21:21:08 +0000 | [diff] [blame] | 1100 | void AddGlobalCtor(llvm::Function *Ctor, int Priority=65535); |
| 1101 | void AddGlobalDtor(llvm::Function *Dtor, int Priority=65535); |
Daniel Dunbar | 9c42652 | 2008-07-29 23:18:29 +0000 | [diff] [blame] | 1102 | |
Mike Stump | 1676c5b | 2009-02-13 19:12:34 +0000 | [diff] [blame] | 1103 | /// EmitCtorList - Generates a global array of functions and priorities using |
| 1104 | /// the given list and name. This array will have appending linkage and is |
| 1105 | /// suitable for use as a LLVM constructor or destructor array. |
Daniel Dunbar | 74aa7e1 | 2008-08-01 00:01:51 +0000 | [diff] [blame] | 1106 | void EmitCtorList(const CtorList &Fns, const char *GlobalName); |
| 1107 | |
Rafael Espindola | adcc1d1 | 2010-03-27 02:52:14 +0000 | [diff] [blame] | 1108 | /// EmitFundamentalRTTIDescriptor - Emit the RTTI descriptors for the |
| 1109 | /// given type. |
| 1110 | void EmitFundamentalRTTIDescriptor(QualType Type); |
| 1111 | |
Daniel Dunbar | 99d2835 | 2009-03-09 23:53:08 +0000 | [diff] [blame] | 1112 | /// EmitDeferred - Emit any needed decls for which code generation |
| 1113 | /// was deferred. |
Dmitri Gribenko | b2aa923 | 2012-11-15 14:28:07 +0000 | [diff] [blame] | 1114 | void EmitDeferred(); |
Daniel Dunbar | 08b26a0 | 2009-02-13 20:29:50 +0000 | [diff] [blame] | 1115 | |
Rafael Espindola | 2e2995b | 2013-11-05 21:37:29 +0000 | [diff] [blame] | 1116 | /// Call replaceAllUsesWith on all pairs in Replacements. |
| 1117 | void applyReplacements(); |
| 1118 | |
Rafael Espindola | 208b5c0 | 2013-10-22 19:26:13 +0000 | [diff] [blame] | 1119 | void checkAliases(); |
| 1120 | |
John McCall | 6bd2a89 | 2013-01-25 22:31:03 +0000 | [diff] [blame] | 1121 | /// EmitDeferredVTables - Emit any vtables which we deferred and |
| 1122 | /// still have a use for. |
| 1123 | void EmitDeferredVTables(); |
| 1124 | |
Rafael Espindola | 060062a | 2014-03-06 22:15:10 +0000 | [diff] [blame] | 1125 | /// Emit the llvm.used and llvm.compiler.used metadata. |
| 1126 | void emitLLVMUsed(); |
Daniel Dunbar | 23fd462 | 2008-10-01 00:49:24 +0000 | [diff] [blame] | 1127 | |
Douglas Gregor | bc25ff4 | 2013-01-14 20:53:57 +0000 | [diff] [blame] | 1128 | /// \brief Emit the link options introduced by imported modules. |
| 1129 | void EmitModuleLinkOptions(); |
| 1130 | |
Richard Smith | df931ce | 2013-04-06 05:00:46 +0000 | [diff] [blame] | 1131 | /// \brief Emit aliases for internal-linkage declarations inside "C" language |
| 1132 | /// linkage specifications, giving them the "expected" name where possible. |
| 1133 | void EmitStaticExternCAliases(); |
| 1134 | |
John McCall | 09ae032 | 2010-07-06 23:57:41 +0000 | [diff] [blame] | 1135 | void EmitDeclMetadata(); |
| 1136 | |
Rafael Espindola | 3bfa468 | 2013-10-16 19:28:50 +0000 | [diff] [blame] | 1137 | /// \brief Emit the Clang version as llvm.ident metadata. |
| 1138 | void EmitVersionIdentMetadata(); |
| 1139 | |
Nick Lewycky | 85c011d | 2011-05-05 00:08:20 +0000 | [diff] [blame] | 1140 | /// EmitCoverageFile - Emit the llvm.gcov metadata used to tell LLVM where |
Nick Lewycky | 480cb99 | 2011-05-04 20:46:58 +0000 | [diff] [blame] | 1141 | /// to emit the .gcno and .gcda files in a way that persists in .bc files. |
Nick Lewycky | 85c011d | 2011-05-05 00:08:20 +0000 | [diff] [blame] | 1142 | void EmitCoverageFile(); |
Nick Lewycky | 480cb99 | 2011-05-04 20:46:58 +0000 | [diff] [blame] | 1143 | |
Nico Weber | cf4ff586 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 1144 | /// Emits the initializer for a uuidof string. |
| 1145 | llvm::Constant *EmitUuidofInitializer(StringRef uuidstr, QualType IIDType); |
| 1146 | |
Daniel Dunbar | 99d2835 | 2009-03-09 23:53:08 +0000 | [diff] [blame] | 1147 | /// MayDeferGeneration - Determine if the given decl can be emitted |
| 1148 | /// lazily; this is only relevant for definitions. The given decl |
| 1149 | /// must be either a function or var decl. |
Daniel Dunbar | 6b8720e | 2009-02-13 21:18:01 +0000 | [diff] [blame] | 1150 | bool MayDeferGeneration(const ValueDecl *D); |
John McCall | 0bdb1fd | 2010-09-16 06:16:50 +0000 | [diff] [blame] | 1151 | |
| 1152 | /// SimplifyPersonality - Check whether we can use a "simpler", more |
| 1153 | /// core exceptions personality function. |
| 1154 | void SimplifyPersonality(); |
Chris Lattner | f97fe38 | 2007-05-24 06:29:05 +0000 | [diff] [blame] | 1155 | }; |
| 1156 | } // end namespace CodeGen |
| 1157 | } // end namespace clang |
Chris Lattner | f97fe38 | 2007-05-24 06:29:05 +0000 | [diff] [blame] | 1158 | |
| 1159 | #endif |