| Daniel Dunbar | bd012ff | 2008-07-29 23:18:29 +0000 | [diff] [blame] | 1 | //===--- CodeGenModule.h - Per-Module state for LLVM CodeGen ----*- C++ -*-===// |
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| Chris Lattner | 0bc735f | 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. |
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| Mike Stump | ecc90e9 | 2009-02-13 19:12:34 +0000 | [diff] [blame] | 10 | // This is the internal per-translation-unit state used for llvm translation. |
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| Chris Lattner | ef52a2f | 2008-02-29 17:10:38 +0000 | [diff] [blame] | 14 | #ifndef CLANG_CODEGEN_CODEGENMODULE_H |
| 15 | #define CLANG_CODEGEN_CODEGENMODULE_H |
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 16 | |
| Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 17 | #include "CGVTables.h" |
| 18 | #include "CodeGenTypes.h" |
| Stephen Hines | ef82254 | 2014-07-21 00:47:37 -0700 | [diff] [blame^] | 19 | #include "SanitizerBlacklist.h" |
| Dan Gohman | 4f8d123 | 2008-05-22 00:50:06 +0000 | [diff] [blame] | 20 | #include "clang/AST/Attr.h" |
| Anders Carlsson | 2a131fb | 2009-05-05 04:44:02 +0000 | [diff] [blame] | 21 | #include "clang/AST/DeclCXX.h" |
| Anders Carlsson | 0ff8baf | 2009-09-11 00:07:24 +0000 | [diff] [blame] | 22 | #include "clang/AST/DeclObjC.h" |
| Peter Collingbourne | fd05ca0 | 2011-06-14 04:02:39 +0000 | [diff] [blame] | 23 | #include "clang/AST/GlobalDecl.h" |
| Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 24 | #include "clang/AST/Mangle.h" |
| Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 25 | #include "clang/Basic/ABI.h" |
| 26 | #include "clang/Basic/LangOptions.h" |
| Douglas Gregor | b6cbe51 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 27 | #include "clang/Basic/Module.h" |
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 28 | #include "llvm/ADT/DenseMap.h" |
| Douglas Gregor | b6cbe51 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 29 | #include "llvm/ADT/SetVector.h" |
| Rafael Espindola | 6a83670 | 2010-03-04 18:17:24 +0000 | [diff] [blame] | 30 | #include "llvm/ADT/SmallPtrSet.h" |
| Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 31 | #include "llvm/ADT/StringMap.h" |
| John McCall | bd7370a | 2013-02-28 19:01:20 +0000 | [diff] [blame] | 32 | #include "llvm/IR/CallingConv.h" |
| Chandler Carruth | 3b844ba | 2013-01-02 11:45:17 +0000 | [diff] [blame] | 33 | #include "llvm/IR/Module.h" |
| Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 34 | #include "llvm/IR/ValueHandle.h" |
| Anders Carlsson | b723f75 | 2009-01-04 02:08:04 +0000 | [diff] [blame] | 35 | |
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 36 | namespace llvm { |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 37 | class Module; |
| 38 | class Constant; |
| 39 | class ConstantInt; |
| 40 | class Function; |
| 41 | class GlobalValue; |
| 42 | class DataLayout; |
| 43 | class FunctionType; |
| 44 | class LLVMContext; |
| 45 | class IndexedInstrProfReader; |
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | namespace clang { |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 49 | class TargetCodeGenInfo; |
| 50 | class ASTContext; |
| 51 | class AtomicType; |
| 52 | class FunctionDecl; |
| 53 | class IdentifierInfo; |
| 54 | class ObjCMethodDecl; |
| 55 | class ObjCImplementationDecl; |
| 56 | class ObjCCategoryImplDecl; |
| 57 | class ObjCProtocolDecl; |
| 58 | class ObjCEncodeExpr; |
| 59 | class BlockExpr; |
| 60 | class CharUnits; |
| 61 | class Decl; |
| 62 | class Expr; |
| 63 | class Stmt; |
| 64 | class InitListExpr; |
| 65 | class StringLiteral; |
| 66 | class NamedDecl; |
| 67 | class ValueDecl; |
| 68 | class VarDecl; |
| 69 | class LangOptions; |
| 70 | class CodeGenOptions; |
| 71 | class DiagnosticsEngine; |
| 72 | class AnnotateAttr; |
| 73 | class CXXDestructorDecl; |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 74 | class Module; |
| Mike Stump | ecc90e9 | 2009-02-13 19:12:34 +0000 | [diff] [blame] | 75 | |
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 76 | namespace CodeGen { |
| 77 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 78 | class CallArgList; |
| 79 | class CodeGenFunction; |
| 80 | class CodeGenTBAA; |
| 81 | class CGCXXABI; |
| 82 | class CGDebugInfo; |
| 83 | class CGObjCRuntime; |
| 84 | class CGOpenCLRuntime; |
| 85 | class CGOpenMPRuntime; |
| 86 | class CGCUDARuntime; |
| 87 | class BlockFieldFlags; |
| 88 | class FunctionArgList; |
| Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 89 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 90 | struct OrderGlobalInits { |
| 91 | unsigned int priority; |
| 92 | unsigned int lex_order; |
| 93 | OrderGlobalInits(unsigned int p, unsigned int l) |
| Chris Lattner | ec2830d | 2010-06-27 06:32:58 +0000 | [diff] [blame] | 94 | : priority(p), lex_order(l) {} |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 95 | |
| 96 | bool operator==(const OrderGlobalInits &RHS) const { |
| 97 | return priority == RHS.priority && lex_order == RHS.lex_order; |
| 98 | } |
| 99 | |
| 100 | bool operator<(const OrderGlobalInits &RHS) const { |
| 101 | return std::tie(priority, lex_order) < |
| 102 | std::tie(RHS.priority, RHS.lex_order); |
| 103 | } |
| 104 | }; |
| 105 | |
| 106 | struct CodeGenTypeCache { |
| 107 | /// void |
| 108 | llvm::Type *VoidTy; |
| 109 | |
| 110 | /// i8, i16, i32, and i64 |
| 111 | llvm::IntegerType *Int8Ty, *Int16Ty, *Int32Ty, *Int64Ty; |
| 112 | /// float, double |
| 113 | llvm::Type *FloatTy, *DoubleTy; |
| 114 | |
| 115 | /// int |
| 116 | llvm::IntegerType *IntTy; |
| 117 | |
| 118 | /// intptr_t, size_t, and ptrdiff_t, which we assume are the same size. |
| 119 | union { |
| 120 | llvm::IntegerType *IntPtrTy; |
| 121 | llvm::IntegerType *SizeTy; |
| 122 | llvm::IntegerType *PtrDiffTy; |
| Chris Lattner | ec2830d | 2010-06-27 06:32:58 +0000 | [diff] [blame] | 123 | }; |
| John McCall | 5936e33 | 2011-02-15 09:22:45 +0000 | [diff] [blame] | 124 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 125 | /// void* in address space 0 |
| 126 | union { |
| 127 | llvm::PointerType *VoidPtrTy; |
| 128 | llvm::PointerType *Int8PtrTy; |
| John McCall | 5936e33 | 2011-02-15 09:22:45 +0000 | [diff] [blame] | 129 | }; |
| John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 130 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 131 | /// void** in address space 0 |
| 132 | union { |
| 133 | llvm::PointerType *VoidPtrPtrTy; |
| 134 | llvm::PointerType *Int8PtrPtrTy; |
| 135 | }; |
| 136 | |
| 137 | /// The width of a pointer into the generic address space. |
| 138 | unsigned char PointerWidthInBits; |
| 139 | |
| 140 | /// The size and alignment of a pointer into the generic address |
| 141 | /// space. |
| 142 | union { |
| 143 | unsigned char PointerAlignInBytes; |
| 144 | unsigned char PointerSizeInBytes; |
| 145 | unsigned char SizeSizeInBytes; // sizeof(size_t) |
| 146 | }; |
| 147 | |
| 148 | llvm::CallingConv::ID RuntimeCC; |
| 149 | llvm::CallingConv::ID getRuntimeCC() const { return RuntimeCC; } |
| 150 | }; |
| 151 | |
| John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 152 | struct RREntrypoints { |
| 153 | RREntrypoints() { memset(this, 0, sizeof(*this)); } |
| 154 | /// void objc_autoreleasePoolPop(void*); |
| 155 | llvm::Constant *objc_autoreleasePoolPop; |
| 156 | |
| 157 | /// void *objc_autoreleasePoolPush(void); |
| 158 | llvm::Constant *objc_autoreleasePoolPush; |
| 159 | }; |
| 160 | |
| 161 | struct ARCEntrypoints { |
| 162 | ARCEntrypoints() { memset(this, 0, sizeof(*this)); } |
| 163 | |
| 164 | /// id objc_autorelease(id); |
| 165 | llvm::Constant *objc_autorelease; |
| 166 | |
| 167 | /// id objc_autoreleaseReturnValue(id); |
| 168 | llvm::Constant *objc_autoreleaseReturnValue; |
| 169 | |
| 170 | /// void objc_copyWeak(id *dest, id *src); |
| 171 | llvm::Constant *objc_copyWeak; |
| 172 | |
| 173 | /// void objc_destroyWeak(id*); |
| 174 | llvm::Constant *objc_destroyWeak; |
| 175 | |
| 176 | /// id objc_initWeak(id*, id); |
| 177 | llvm::Constant *objc_initWeak; |
| 178 | |
| 179 | /// id objc_loadWeak(id*); |
| 180 | llvm::Constant *objc_loadWeak; |
| 181 | |
| 182 | /// id objc_loadWeakRetained(id*); |
| 183 | llvm::Constant *objc_loadWeakRetained; |
| 184 | |
| 185 | /// void objc_moveWeak(id *dest, id *src); |
| 186 | llvm::Constant *objc_moveWeak; |
| 187 | |
| 188 | /// id objc_retain(id); |
| 189 | llvm::Constant *objc_retain; |
| 190 | |
| 191 | /// id objc_retainAutorelease(id); |
| 192 | llvm::Constant *objc_retainAutorelease; |
| 193 | |
| 194 | /// id objc_retainAutoreleaseReturnValue(id); |
| 195 | llvm::Constant *objc_retainAutoreleaseReturnValue; |
| 196 | |
| 197 | /// id objc_retainAutoreleasedReturnValue(id); |
| 198 | llvm::Constant *objc_retainAutoreleasedReturnValue; |
| 199 | |
| 200 | /// id objc_retainBlock(id); |
| 201 | llvm::Constant *objc_retainBlock; |
| 202 | |
| 203 | /// void objc_release(id); |
| 204 | llvm::Constant *objc_release; |
| 205 | |
| 206 | /// id objc_storeStrong(id*, id); |
| 207 | llvm::Constant *objc_storeStrong; |
| 208 | |
| 209 | /// id objc_storeWeak(id*, id); |
| 210 | llvm::Constant *objc_storeWeak; |
| 211 | |
| 212 | /// A void(void) inline asm to use to mark that the return value of |
| 213 | /// a call will be immediately retain. |
| 214 | llvm::InlineAsm *retainAutoreleasedReturnValueMarker; |
| John McCall | b6a6079 | 2013-03-23 02:35:54 +0000 | [diff] [blame] | 215 | |
| 216 | /// void clang.arc.use(...); |
| 217 | llvm::Constant *clang_arc_use; |
| John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 218 | }; |
| Will Dietz | 4f45bc0 | 2013-01-18 11:30:38 +0000 | [diff] [blame] | 219 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 220 | /// This class records statistics on instrumentation based profiling. |
| Stephen Hines | ef82254 | 2014-07-21 00:47:37 -0700 | [diff] [blame^] | 221 | class InstrProfStats { |
| 222 | uint32_t VisitedInMainFile; |
| 223 | uint32_t MissingInMainFile; |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 224 | uint32_t Visited; |
| 225 | uint32_t Missing; |
| 226 | uint32_t Mismatched; |
| Stephen Hines | ef82254 | 2014-07-21 00:47:37 -0700 | [diff] [blame^] | 227 | |
| 228 | public: |
| 229 | InstrProfStats() |
| 230 | : VisitedInMainFile(0), MissingInMainFile(0), Visited(0), Missing(0), |
| 231 | Mismatched(0) {} |
| 232 | /// Record that we've visited a function and whether or not that function was |
| 233 | /// in the main source file. |
| 234 | void addVisited(bool MainFile) { |
| 235 | if (MainFile) |
| 236 | ++VisitedInMainFile; |
| 237 | ++Visited; |
| 238 | } |
| 239 | /// Record that a function we've visited has no profile data. |
| 240 | void addMissing(bool MainFile) { |
| 241 | if (MainFile) |
| 242 | ++MissingInMainFile; |
| 243 | ++Missing; |
| 244 | } |
| 245 | /// Record that a function we've visited has mismatched profile data. |
| 246 | void addMismatched(bool MainFile) { ++Mismatched; } |
| 247 | /// Whether or not the stats we've gathered indicate any potential problems. |
| 248 | bool hasDiagnostics() { return Missing || Mismatched; } |
| 249 | /// Report potential problems we've found to \c Diags. |
| 250 | void reportDiagnostics(DiagnosticsEngine &Diags, StringRef MainFile); |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 251 | }; |
| 252 | |
| 253 | /// This class organizes the cross-function state that is used while generating |
| 254 | /// LLVM code. |
| John McCall | 5936e33 | 2011-02-15 09:22:45 +0000 | [diff] [blame] | 255 | class CodeGenModule : public CodeGenTypeCache { |
| Dmitri Gribenko | f56faa0 | 2012-09-15 20:20:27 +0000 | [diff] [blame] | 256 | CodeGenModule(const CodeGenModule &) LLVM_DELETED_FUNCTION; |
| 257 | void operator=(const CodeGenModule &) LLVM_DELETED_FUNCTION; |
| Anders Carlsson | 8a219ce | 2009-02-24 04:21:31 +0000 | [diff] [blame] | 258 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 259 | struct Structor { |
| 260 | Structor() : Priority(0), Initializer(nullptr), AssociatedData(nullptr) {} |
| 261 | Structor(int Priority, llvm::Constant *Initializer, |
| 262 | llvm::Constant *AssociatedData) |
| 263 | : Priority(Priority), Initializer(Initializer), |
| 264 | AssociatedData(AssociatedData) {} |
| 265 | int Priority; |
| 266 | llvm::Constant *Initializer; |
| 267 | llvm::Constant *AssociatedData; |
| 268 | }; |
| 269 | |
| 270 | typedef std::vector<Structor> CtorList; |
| Daniel Dunbar | 6bfed7e | 2008-08-01 00:01:51 +0000 | [diff] [blame] | 271 | |
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 272 | ASTContext &Context; |
| David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 273 | const LangOptions &LangOpts; |
| Chandler Carruth | 2811ccf | 2009-11-12 17:24:48 +0000 | [diff] [blame] | 274 | const CodeGenOptions &CodeGenOpts; |
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 275 | llvm::Module &TheModule; |
| David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 276 | DiagnosticsEngine &Diags; |
| John McCall | 64aa4b3 | 2013-04-16 22:48:15 +0000 | [diff] [blame] | 277 | const llvm::DataLayout &TheDataLayout; |
| 278 | const TargetInfo &Target; |
| Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 279 | std::unique_ptr<CGCXXABI> ABI; |
| John McCall | 64aa4b3 | 2013-04-16 22:48:15 +0000 | [diff] [blame] | 280 | llvm::LLVMContext &VMContext; |
| Anders Carlsson | b540491 | 2009-10-07 01:06:45 +0000 | [diff] [blame] | 281 | |
| John McCall | 64aa4b3 | 2013-04-16 22:48:15 +0000 | [diff] [blame] | 282 | CodeGenTBAA *TBAA; |
| 283 | |
| 284 | mutable const TargetCodeGenInfo *TheTargetCodeGenInfo; |
| 285 | |
| 286 | // This should not be moved earlier, since its initialization depends on some |
| 287 | // of the previous reference members being already initialized and also checks |
| 288 | // if TheTargetCodeGenInfo is NULL |
| 289 | CodeGenTypes Types; |
| 290 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 291 | /// Holds information about C++ vtables. |
| Anders Carlsson | af44035 | 2010-03-23 04:11:45 +0000 | [diff] [blame] | 292 | CodeGenVTables VTables; |
| Douglas Gregor | e17ad2f | 2010-04-08 16:07:47 +0000 | [diff] [blame] | 293 | |
| Peter Collingbourne | e926523 | 2011-07-27 20:29:46 +0000 | [diff] [blame] | 294 | CGObjCRuntime* ObjCRuntime; |
| Peter Collingbourne | 8c25fc5 | 2011-09-19 21:14:35 +0000 | [diff] [blame] | 295 | CGOpenCLRuntime* OpenCLRuntime; |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 296 | CGOpenMPRuntime* OpenMPRuntime; |
| Peter Collingbourne | 6c0aa5f | 2011-10-06 18:29:37 +0000 | [diff] [blame] | 297 | CGCUDARuntime* CUDARuntime; |
| Ted Kremenek | 815c78f | 2008-08-05 18:50:11 +0000 | [diff] [blame] | 298 | CGDebugInfo* DebugInfo; |
| John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 299 | ARCEntrypoints *ARCData; |
| Dan Gohman | b49bd27 | 2012-02-16 00:57:37 +0000 | [diff] [blame] | 300 | llvm::MDNode *NoObjCARCExceptionsMetadata; |
| John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 301 | RREntrypoints *RRData; |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 302 | std::unique_ptr<llvm::IndexedInstrProfReader> PGOReader; |
| 303 | InstrProfStats PGOStats; |
| Daniel Dunbar | 9986eab | 2008-07-30 16:32:24 +0000 | [diff] [blame] | 304 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 305 | // A set of references that have only been seen via a weakref so far. This is |
| 306 | // used to remove the weak of the reference if we ever see a direct reference |
| 307 | // or a definition. |
| Rafael Espindola | 6a83670 | 2010-03-04 18:17:24 +0000 | [diff] [blame] | 308 | llvm::SmallPtrSet<llvm::GlobalValue*, 10> WeakRefReferences; |
| 309 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 310 | /// This contains all the decls which have definitions but/ which are deferred |
| 311 | /// for emission and therefore should only be output if they are actually |
| 312 | /// used. If a decl is in this, then it is known to have not been referenced |
| 313 | /// yet. |
| Stephen Hines | ef82254 | 2014-07-21 00:47:37 -0700 | [diff] [blame^] | 314 | std::map<StringRef, GlobalDecl> DeferredDecls; |
| Daniel Dunbar | 0269871 | 2009-02-13 20:29:50 +0000 | [diff] [blame] | 315 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 316 | /// This is a list of deferred decls which we have seen that *are* actually |
| 317 | /// referenced. These get code generated when the module is done. |
| Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 318 | struct DeferredGlobal { |
| 319 | DeferredGlobal(llvm::GlobalValue *GV, GlobalDecl GD) : GV(GV), GD(GD) {} |
| 320 | llvm::AssertingVH<llvm::GlobalValue> GV; |
| 321 | GlobalDecl GD; |
| 322 | }; |
| 323 | std::vector<DeferredGlobal> DeferredDeclsToEmit; |
| 324 | void addDeferredDeclToEmit(llvm::GlobalValue *GV, GlobalDecl GD) { |
| 325 | DeferredDeclsToEmit.push_back(DeferredGlobal(GV, GD)); |
| 326 | } |
| Daniel Dunbar | 03f5ad9 | 2009-04-15 22:08:45 +0000 | [diff] [blame] | 327 | |
| Rafael Espindola | d205498 | 2013-10-22 19:26:13 +0000 | [diff] [blame] | 328 | /// List of alias we have emitted. Used to make sure that what they point to |
| 329 | /// is defined once we get to the end of the of the translation unit. |
| 330 | std::vector<GlobalDecl> Aliases; |
| 331 | |
| Rafael Espindola | 61a0a75 | 2013-11-05 21:37:29 +0000 | [diff] [blame] | 332 | typedef llvm::StringMap<llvm::TrackingVH<llvm::Constant> > ReplacementsTy; |
| 333 | ReplacementsTy Replacements; |
| 334 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 335 | /// A queue of (optional) vtables to consider emitting. |
| John McCall | d5617ee | 2013-01-25 22:31:03 +0000 | [diff] [blame] | 336 | std::vector<const CXXRecordDecl*> DeferredVTables; |
| 337 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 338 | /// List of global values which are required to be present in the object file; |
| 339 | /// bitcast to i8*. This is used for forcing visibility of symbols which may |
| 340 | /// otherwise be optimized out. |
| Chris Lattner | 35f38a2 | 2009-03-31 22:37:52 +0000 | [diff] [blame] | 341 | std::vector<llvm::WeakVH> LLVMUsed; |
| Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 342 | std::vector<llvm::WeakVH> LLVMCompilerUsed; |
| Mike Stump | ecc90e9 | 2009-02-13 19:12:34 +0000 | [diff] [blame] | 343 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 344 | /// Store the list of global constructors and their respective priorities to |
| 345 | /// be emitted when the translation unit is complete. |
| Daniel Dunbar | 6bfed7e | 2008-08-01 00:01:51 +0000 | [diff] [blame] | 346 | CtorList GlobalCtors; |
| 347 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 348 | /// Store the list of global destructors and their respective priorities to be |
| 349 | /// emitted when the translation unit is complete. |
| Daniel Dunbar | 6bfed7e | 2008-08-01 00:01:51 +0000 | [diff] [blame] | 350 | CtorList GlobalDtors; |
| 351 | |
| Stephen Hines | ef82254 | 2014-07-21 00:47:37 -0700 | [diff] [blame^] | 352 | /// An ordered map of canonical GlobalDecls to their mangled names. |
| 353 | llvm::MapVector<GlobalDecl, StringRef> MangledDeclNames; |
| 354 | llvm::StringMap<GlobalDecl, llvm::BumpPtrAllocator> Manglings; |
| 355 | |
| Julien Lerouge | 77f68bb | 2011-09-09 22:41:49 +0000 | [diff] [blame] | 356 | /// Global annotations. |
| Nate Begeman | 532485c | 2008-04-18 23:43:57 +0000 | [diff] [blame] | 357 | std::vector<llvm::Constant*> Annotations; |
| Mike Stump | ecc90e9 | 2009-02-13 19:12:34 +0000 | [diff] [blame] | 358 | |
| Julien Lerouge | 77f68bb | 2011-09-09 22:41:49 +0000 | [diff] [blame] | 359 | /// Map used to get unique annotation strings. |
| 360 | llvm::StringMap<llvm::Constant*> AnnotationStrings; |
| 361 | |
| Anders Carlsson | c9e2091 | 2007-08-21 00:21:21 +0000 | [diff] [blame] | 362 | llvm::StringMap<llvm::Constant*> CFConstantStringMap; |
| Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 363 | |
| 364 | llvm::StringMap<llvm::GlobalVariable *> Constant1ByteStringMap; |
| 365 | llvm::StringMap<llvm::GlobalVariable *> Constant2ByteStringMap; |
| 366 | llvm::StringMap<llvm::GlobalVariable *> Constant4ByteStringMap; |
| Eli Friedman | 71cba34 | 2012-03-09 03:27:46 +0000 | [diff] [blame] | 367 | llvm::DenseMap<const Decl*, llvm::Constant *> StaticLocalDeclMap; |
| John McCall | 355bba7 | 2012-03-30 21:00:39 +0000 | [diff] [blame] | 368 | llvm::DenseMap<const Decl*, llvm::GlobalVariable*> StaticLocalDeclGuardMap; |
| Richard Smith | 211c8dd | 2013-06-05 00:46:14 +0000 | [diff] [blame] | 369 | llvm::DenseMap<const Expr*, llvm::Constant *> MaterializedGlobalTemporaryMap; |
| 370 | |
| Fariborz Jahanian | b08cfb3 | 2012-01-08 19:13:23 +0000 | [diff] [blame] | 371 | llvm::DenseMap<QualType, llvm::Constant *> AtomicSetterHelperFnMap; |
| 372 | llvm::DenseMap<QualType, llvm::Constant *> AtomicGetterHelperFnMap; |
| Daniel Dunbar | 3e9df99 | 2008-08-23 18:37:06 +0000 | [diff] [blame] | 373 | |
| Will Dietz | 562d45c | 2013-11-08 01:09:22 +0000 | [diff] [blame] | 374 | /// Map used to get unique type descriptor constants for sanitizers. |
| 375 | llvm::DenseMap<QualType, llvm::Constant *> TypeDescriptorMap; |
| 376 | |
| Richard Smith | 0024937 | 2013-04-06 05:00:46 +0000 | [diff] [blame] | 377 | /// Map used to track internal linkage functions declared within |
| 378 | /// extern "C" regions. |
| Richard Smith | 84083b7 | 2013-04-13 01:28:18 +0000 | [diff] [blame] | 379 | typedef llvm::MapVector<IdentifierInfo *, |
| 380 | llvm::GlobalValue *> StaticExternCMap; |
| Richard Smith | 0024937 | 2013-04-06 05:00:46 +0000 | [diff] [blame] | 381 | StaticExternCMap StaticExternCValues; |
| 382 | |
| Richard Smith | b80a16e | 2013-04-19 16:42:07 +0000 | [diff] [blame] | 383 | /// \brief thread_local variables defined or used in this TU. |
| 384 | std::vector<std::pair<const VarDecl *, llvm::GlobalVariable *> > |
| 385 | CXXThreadLocals; |
| 386 | |
| 387 | /// \brief thread_local variables with initializers that need to run |
| 388 | /// before any thread_local variable in this TU is odr-used. |
| 389 | std::vector<llvm::Constant*> CXXThreadLocalInits; |
| 390 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 391 | /// Global variables with initializers that need to run before main. |
| Eli Friedman | 6c6bda3 | 2010-01-08 00:50:11 +0000 | [diff] [blame] | 392 | std::vector<llvm::Constant*> CXXGlobalInits; |
| John McCall | bf40cb5 | 2010-07-15 23:40:35 +0000 | [diff] [blame] | 393 | |
| 394 | /// When a C++ decl with an initializer is deferred, null is |
| 395 | /// appended to CXXGlobalInits, and the index of that null is placed |
| 396 | /// here so that the initializer will be performed in the correct |
| 397 | /// order. |
| 398 | llvm::DenseMap<const Decl*, unsigned> DelayedCXXInitPosition; |
| Fariborz Jahanian | 9f967c5 | 2010-06-21 18:45:05 +0000 | [diff] [blame] | 399 | |
| Anton Korobeynikov | 4179ddd | 2012-11-06 22:44:45 +0000 | [diff] [blame] | 400 | typedef std::pair<OrderGlobalInits, llvm::Function*> GlobalInitData; |
| 401 | |
| 402 | struct GlobalInitPriorityCmp { |
| 403 | bool operator()(const GlobalInitData &LHS, |
| 404 | const GlobalInitData &RHS) const { |
| 405 | return LHS.first.priority < RHS.first.priority; |
| 406 | } |
| 407 | }; |
| 408 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 409 | /// Global variables with initializers whose order of initialization is set by |
| 410 | /// init_priority attribute. |
| Anton Korobeynikov | 4179ddd | 2012-11-06 22:44:45 +0000 | [diff] [blame] | 411 | SmallVector<GlobalInitData, 8> PrioritizedCXXGlobalInits; |
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 412 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 413 | /// Global destructor functions and arguments that need to run on termination. |
| Chris Lattner | 810112e | 2010-06-19 05:52:45 +0000 | [diff] [blame] | 414 | std::vector<std::pair<llvm::WeakVH,llvm::Constant*> > CXXGlobalDtors; |
| Daniel Dunbar | efb0fa9 | 2010-03-20 04:15:41 +0000 | [diff] [blame] | 415 | |
| Douglas Gregor | b6cbe51 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 416 | /// \brief The complete set of modules that has been imported. |
| 417 | llvm::SetVector<clang::Module *> ImportedModules; |
| 418 | |
| Reid Kleckner | 3190ca9 | 2013-05-08 13:44:39 +0000 | [diff] [blame] | 419 | /// \brief A vector of metadata strings. |
| 420 | SmallVector<llvm::Value *, 16> LinkerOptionsMetadata; |
| 421 | |
| Douglas Gregor | 45c4ea7 | 2011-08-09 15:54:21 +0000 | [diff] [blame] | 422 | /// @name Cache for Objective-C runtime types |
| 423 | /// @{ |
| 424 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 425 | /// Cached reference to the class for constant strings. This value has type |
| 426 | /// int * but is actually an Obj-C class pointer. |
| Fariborz Jahanian | 428edb7 | 2013-04-16 15:25:39 +0000 | [diff] [blame] | 427 | llvm::WeakVH CFConstantStringClassRef; |
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 428 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 429 | /// Cached reference to the class for constant strings. This value has type |
| 430 | /// int * but is actually an Obj-C class pointer. |
| Fariborz Jahanian | 428edb7 | 2013-04-16 15:25:39 +0000 | [diff] [blame] | 431 | llvm::WeakVH ConstantStringClassRef; |
| Fariborz Jahanian | 2bb5dda | 2010-04-23 17:41:07 +0000 | [diff] [blame] | 432 | |
| Douglas Gregor | 45c4ea7 | 2011-08-09 15:54:21 +0000 | [diff] [blame] | 433 | /// \brief The LLVM type corresponding to NSConstantString. |
| 434 | llvm::StructType *NSConstantStringType; |
| 435 | |
| Douglas Gregor | 0815b57 | 2011-08-09 17:23:49 +0000 | [diff] [blame] | 436 | /// \brief The type used to describe the state of a fast enumeration in |
| 437 | /// Objective-C's for..in loop. |
| 438 | QualType ObjCFastEnumerationStateType; |
| 439 | |
| Douglas Gregor | 45c4ea7 | 2011-08-09 15:54:21 +0000 | [diff] [blame] | 440 | /// @} |
| 441 | |
| David Chisnall | 0d13f6f | 2010-01-23 02:40:42 +0000 | [diff] [blame] | 442 | /// Lazily create the Objective-C runtime |
| 443 | void createObjCRuntime(); |
| 444 | |
| Peter Collingbourne | 8c25fc5 | 2011-09-19 21:14:35 +0000 | [diff] [blame] | 445 | void createOpenCLRuntime(); |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 446 | void createOpenMPRuntime(); |
| Peter Collingbourne | 6c0aa5f | 2011-10-06 18:29:37 +0000 | [diff] [blame] | 447 | void createCUDARuntime(); |
| Peter Collingbourne | 8c25fc5 | 2011-09-19 21:14:35 +0000 | [diff] [blame] | 448 | |
| Rafael Espindola | bcf6b98 | 2011-12-19 14:41:01 +0000 | [diff] [blame] | 449 | bool isTriviallyRecursive(const FunctionDecl *F); |
| Peter Collingbourne | 144a31f | 2013-06-05 17:49:37 +0000 | [diff] [blame] | 450 | bool shouldEmitFunction(GlobalDecl GD); |
| Daniel Dunbar | 673431a | 2010-07-16 00:00:15 +0000 | [diff] [blame] | 451 | |
| 452 | /// @name Cache for Blocks Runtime Globals |
| 453 | /// @{ |
| 454 | |
| 455 | llvm::Constant *NSConcreteGlobalBlock; |
| 456 | llvm::Constant *NSConcreteStackBlock; |
| Daniel Dunbar | 754b9fb | 2010-07-16 00:00:19 +0000 | [diff] [blame] | 457 | |
| Daniel Dunbar | 673431a | 2010-07-16 00:00:15 +0000 | [diff] [blame] | 458 | llvm::Constant *BlockObjectAssign; |
| 459 | llvm::Constant *BlockObjectDispose; |
| 460 | |
| Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 461 | llvm::Type *BlockDescriptorType; |
| 462 | llvm::Type *GenericBlockLiteralType; |
| John McCall | d16c2cf | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 463 | |
| 464 | struct { |
| 465 | int GlobalUniqueCount; |
| 466 | } Block; |
| Will Dietz | 4f45bc0 | 2013-01-18 11:30:38 +0000 | [diff] [blame] | 467 | |
| Nadav Rotem | 495cfa4 | 2013-03-23 06:43:35 +0000 | [diff] [blame] | 468 | /// void @llvm.lifetime.start(i64 %size, i8* nocapture <ptr>) |
| 469 | llvm::Constant *LifetimeStartFn; |
| 470 | |
| 471 | /// void @llvm.lifetime.end(i64 %size, i8* nocapture <ptr>) |
| 472 | llvm::Constant *LifetimeEndFn; |
| 473 | |
| Fariborz Jahanian | 4904bf4 | 2012-06-26 16:06:38 +0000 | [diff] [blame] | 474 | GlobalDecl initializedGlobalDecl; |
| John McCall | d16c2cf | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 475 | |
| Stephen Hines | ef82254 | 2014-07-21 00:47:37 -0700 | [diff] [blame^] | 476 | SanitizerBlacklist SanitizerBL; |
| Will Dietz | 4f45bc0 | 2013-01-18 11:30:38 +0000 | [diff] [blame] | 477 | |
| Daniel Dunbar | 673431a | 2010-07-16 00:00:15 +0000 | [diff] [blame] | 478 | /// @} |
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 479 | public: |
| Chandler Carruth | 2811ccf | 2009-11-12 17:24:48 +0000 | [diff] [blame] | 480 | CodeGenModule(ASTContext &C, const CodeGenOptions &CodeGenOpts, |
| John McCall | 3abae09 | 2013-04-16 22:48:20 +0000 | [diff] [blame] | 481 | llvm::Module &M, const llvm::DataLayout &TD, |
| 482 | DiagnosticsEngine &Diags); |
| Ted Kremenek | 815c78f | 2008-08-05 18:50:11 +0000 | [diff] [blame] | 483 | |
| Chris Lattner | 2b94fe3 | 2008-03-01 08:45:05 +0000 | [diff] [blame] | 484 | ~CodeGenModule(); |
| Mike Stump | ecc90e9 | 2009-02-13 19:12:34 +0000 | [diff] [blame] | 485 | |
| Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 486 | void clear(); |
| 487 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 488 | /// Finalize LLVM code generation. |
| Ted Kremenek | 815c78f | 2008-08-05 18:50:11 +0000 | [diff] [blame] | 489 | void Release(); |
| Daniel Dunbar | 208ff5e | 2008-08-11 18:12:00 +0000 | [diff] [blame] | 490 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 491 | /// Return a reference to the configured Objective-C runtime. |
| Mike Stump | ecc90e9 | 2009-02-13 19:12:34 +0000 | [diff] [blame] | 492 | CGObjCRuntime &getObjCRuntime() { |
| Peter Collingbourne | e926523 | 2011-07-27 20:29:46 +0000 | [diff] [blame] | 493 | if (!ObjCRuntime) createObjCRuntime(); |
| 494 | return *ObjCRuntime; |
| Daniel Dunbar | 208ff5e | 2008-08-11 18:12:00 +0000 | [diff] [blame] | 495 | } |
| Mike Stump | ecc90e9 | 2009-02-13 19:12:34 +0000 | [diff] [blame] | 496 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 497 | /// Return true iff an Objective-C runtime has been configured. |
| Peter Collingbourne | e926523 | 2011-07-27 20:29:46 +0000 | [diff] [blame] | 498 | bool hasObjCRuntime() { return !!ObjCRuntime; } |
| Daniel Dunbar | 208ff5e | 2008-08-11 18:12:00 +0000 | [diff] [blame] | 499 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 500 | /// Return a reference to the configured OpenCL runtime. |
| Peter Collingbourne | 8c25fc5 | 2011-09-19 21:14:35 +0000 | [diff] [blame] | 501 | CGOpenCLRuntime &getOpenCLRuntime() { |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 502 | assert(OpenCLRuntime != nullptr); |
| Peter Collingbourne | 8c25fc5 | 2011-09-19 21:14:35 +0000 | [diff] [blame] | 503 | return *OpenCLRuntime; |
| 504 | } |
| 505 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 506 | /// Return a reference to the configured OpenMP runtime. |
| 507 | CGOpenMPRuntime &getOpenMPRuntime() { |
| 508 | assert(OpenMPRuntime != nullptr); |
| 509 | return *OpenMPRuntime; |
| 510 | } |
| 511 | |
| 512 | /// Return a reference to the configured CUDA runtime. |
| Peter Collingbourne | 6c0aa5f | 2011-10-06 18:29:37 +0000 | [diff] [blame] | 513 | CGCUDARuntime &getCUDARuntime() { |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 514 | assert(CUDARuntime != nullptr); |
| Peter Collingbourne | 6c0aa5f | 2011-10-06 18:29:37 +0000 | [diff] [blame] | 515 | return *CUDARuntime; |
| 516 | } |
| 517 | |
| John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 518 | ARCEntrypoints &getARCEntrypoints() const { |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 519 | assert(getLangOpts().ObjCAutoRefCount && ARCData != nullptr); |
| John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 520 | return *ARCData; |
| 521 | } |
| 522 | |
| 523 | RREntrypoints &getRREntrypoints() const { |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 524 | assert(RRData != nullptr); |
| John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 525 | return *RRData; |
| 526 | } |
| 527 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 528 | InstrProfStats &getPGOStats() { return PGOStats; } |
| 529 | llvm::IndexedInstrProfReader *getPGOReader() const { return PGOReader.get(); } |
| Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 530 | |
| Eli Friedman | 71cba34 | 2012-03-09 03:27:46 +0000 | [diff] [blame] | 531 | llvm::Constant *getStaticLocalDeclAddress(const VarDecl *D) { |
| 532 | return StaticLocalDeclMap[D]; |
| Fariborz Jahanian | 65ad5a4 | 2010-04-18 21:01:23 +0000 | [diff] [blame] | 533 | } |
| Fariborz Jahanian | 63326a5 | 2010-04-19 18:15:02 +0000 | [diff] [blame] | 534 | void setStaticLocalDeclAddress(const VarDecl *D, |
| Eli Friedman | 71cba34 | 2012-03-09 03:27:46 +0000 | [diff] [blame] | 535 | llvm::Constant *C) { |
| 536 | StaticLocalDeclMap[D] = C; |
| Fariborz Jahanian | 65ad5a4 | 2010-04-18 21:01:23 +0000 | [diff] [blame] | 537 | } |
| 538 | |
| John McCall | 355bba7 | 2012-03-30 21:00:39 +0000 | [diff] [blame] | 539 | llvm::GlobalVariable *getStaticLocalDeclGuardAddress(const VarDecl *D) { |
| 540 | return StaticLocalDeclGuardMap[D]; |
| 541 | } |
| 542 | void setStaticLocalDeclGuardAddress(const VarDecl *D, |
| 543 | llvm::GlobalVariable *C) { |
| 544 | StaticLocalDeclGuardMap[D] = C; |
| 545 | } |
| 546 | |
| Stephen Hines | ef82254 | 2014-07-21 00:47:37 -0700 | [diff] [blame^] | 547 | bool lookupRepresentativeDecl(StringRef MangledName, |
| 548 | GlobalDecl &Result) const; |
| 549 | |
| Fariborz Jahanian | b08cfb3 | 2012-01-08 19:13:23 +0000 | [diff] [blame] | 550 | llvm::Constant *getAtomicSetterHelperFnMap(QualType Ty) { |
| 551 | return AtomicSetterHelperFnMap[Ty]; |
| Fariborz Jahanian | cd93b96 | 2012-01-06 22:33:54 +0000 | [diff] [blame] | 552 | } |
| Fariborz Jahanian | b08cfb3 | 2012-01-08 19:13:23 +0000 | [diff] [blame] | 553 | void setAtomicSetterHelperFnMap(QualType Ty, |
| Fariborz Jahanian | cd93b96 | 2012-01-06 22:33:54 +0000 | [diff] [blame] | 554 | llvm::Constant *Fn) { |
| Fariborz Jahanian | b08cfb3 | 2012-01-08 19:13:23 +0000 | [diff] [blame] | 555 | AtomicSetterHelperFnMap[Ty] = Fn; |
| 556 | } |
| 557 | |
| 558 | llvm::Constant *getAtomicGetterHelperFnMap(QualType Ty) { |
| 559 | return AtomicGetterHelperFnMap[Ty]; |
| 560 | } |
| 561 | void setAtomicGetterHelperFnMap(QualType Ty, |
| 562 | llvm::Constant *Fn) { |
| 563 | AtomicGetterHelperFnMap[Ty] = Fn; |
| Fariborz Jahanian | cd93b96 | 2012-01-06 22:33:54 +0000 | [diff] [blame] | 564 | } |
| 565 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 566 | llvm::Constant *getTypeDescriptorFromMap(QualType Ty) { |
| Will Dietz | 562d45c | 2013-11-08 01:09:22 +0000 | [diff] [blame] | 567 | return TypeDescriptorMap[Ty]; |
| 568 | } |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 569 | void setTypeDescriptorInMap(QualType Ty, llvm::Constant *C) { |
| Will Dietz | 562d45c | 2013-11-08 01:09:22 +0000 | [diff] [blame] | 570 | TypeDescriptorMap[Ty] = C; |
| 571 | } |
| 572 | |
| Devang Patel | aa11289 | 2011-03-07 18:45:56 +0000 | [diff] [blame] | 573 | CGDebugInfo *getModuleDebugInfo() { return DebugInfo; } |
| Devang Patel | 5de7a0e | 2011-03-07 18:29:53 +0000 | [diff] [blame] | 574 | |
| Dan Gohman | b49bd27 | 2012-02-16 00:57:37 +0000 | [diff] [blame] | 575 | llvm::MDNode *getNoObjCARCExceptionsMetadata() { |
| 576 | if (!NoObjCARCExceptionsMetadata) |
| 577 | NoObjCARCExceptionsMetadata = |
| 578 | llvm::MDNode::get(getLLVMContext(), |
| 579 | SmallVector<llvm::Value*,1>()); |
| 580 | return NoObjCARCExceptionsMetadata; |
| 581 | } |
| 582 | |
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 583 | ASTContext &getContext() const { return Context; } |
| David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 584 | const LangOptions &getLangOpts() const { return LangOpts; } |
| John McCall | 64aa4b3 | 2013-04-16 22:48:15 +0000 | [diff] [blame] | 585 | const CodeGenOptions &getCodeGenOpts() const { return CodeGenOpts; } |
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 586 | llvm::Module &getModule() const { return TheModule; } |
| David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 587 | DiagnosticsEngine &getDiags() const { return Diags; } |
| Micah Villmow | 25a6a84 | 2012-10-08 16:25:52 +0000 | [diff] [blame] | 588 | const llvm::DataLayout &getDataLayout() const { return TheDataLayout; } |
| John McCall | 64aa4b3 | 2013-04-16 22:48:15 +0000 | [diff] [blame] | 589 | const TargetInfo &getTarget() const { return Target; } |
| Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 590 | CGCXXABI &getCXXABI() const { return *ABI; } |
| Owen Anderson | a1cf15f | 2009-07-14 23:10:40 +0000 | [diff] [blame] | 591 | llvm::LLVMContext &getLLVMContext() { return VMContext; } |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 592 | |
| 593 | bool shouldUseTBAA() const { return TBAA != nullptr; } |
| John McCall | bc7fbf0 | 2011-02-26 08:07:02 +0000 | [diff] [blame] | 594 | |
| John McCall | 64aa4b3 | 2013-04-16 22:48:15 +0000 | [diff] [blame] | 595 | const TargetCodeGenInfo &getTargetCodeGenInfo(); |
| 596 | |
| 597 | CodeGenTypes &getTypes() { return Types; } |
| 598 | |
| 599 | CodeGenVTables &getVTables() { return VTables; } |
| Timur Iskhodzhanov | 8f189a9 | 2013-08-21 06:25:03 +0000 | [diff] [blame] | 600 | |
| Timur Iskhodzhanov | 5f0db58 | 2013-11-05 15:54:58 +0000 | [diff] [blame] | 601 | ItaniumVTableContext &getItaniumVTableContext() { |
| 602 | return VTables.getItaniumVTableContext(); |
| Timur Iskhodzhanov | f074658 | 2013-10-09 11:33:51 +0000 | [diff] [blame] | 603 | } |
| John McCall | 64aa4b3 | 2013-04-16 22:48:15 +0000 | [diff] [blame] | 604 | |
| Timur Iskhodzhanov | 5f0db58 | 2013-11-05 15:54:58 +0000 | [diff] [blame] | 605 | MicrosoftVTableContext &getMicrosoftVTableContext() { |
| 606 | return VTables.getMicrosoftVTableContext(); |
| Timur Iskhodzhanov | 8f189a9 | 2013-08-21 06:25:03 +0000 | [diff] [blame] | 607 | } |
| 608 | |
| Dan Gohman | 3d5aff5 | 2010-10-14 23:06:10 +0000 | [diff] [blame] | 609 | llvm::MDNode *getTBAAInfo(QualType QTy); |
| Kostya Serebryany | 8cb4a07 | 2012-03-26 17:03:51 +0000 | [diff] [blame] | 610 | llvm::MDNode *getTBAAInfoForVTablePtr(); |
| Dan Gohman | b22c7dc | 2012-09-28 21:58:29 +0000 | [diff] [blame] | 611 | llvm::MDNode *getTBAAStructInfo(QualType QTy); |
| Manman Ren | b37a73d | 2013-04-04 21:53:22 +0000 | [diff] [blame] | 612 | /// Return the MDNode in the type DAG for the given struct type. |
| 613 | llvm::MDNode *getTBAAStructTypeInfo(QualType QTy); |
| 614 | /// Return the path-aware tag for given base type, access node and offset. |
| 615 | llvm::MDNode *getTBAAStructTagInfo(QualType BaseTy, llvm::MDNode *AccessN, |
| 616 | uint64_t O); |
| Dan Gohman | 3d5aff5 | 2010-10-14 23:06:10 +0000 | [diff] [blame] | 617 | |
| Richard Smith | a9b21d2 | 2012-02-17 06:48:11 +0000 | [diff] [blame] | 618 | bool isTypeConstant(QualType QTy, bool ExcludeCtorDtor); |
| 619 | |
| John McCall | 9eda3ab | 2013-03-07 21:37:17 +0000 | [diff] [blame] | 620 | bool isPaddedAtomicType(QualType type); |
| 621 | bool isPaddedAtomicType(const AtomicType *type); |
| 622 | |
| Manman Ren | ca83518 | 2013-04-11 23:02:56 +0000 | [diff] [blame] | 623 | /// Decorate the instruction with a TBAA tag. For scalar TBAA, the tag |
| 624 | /// is the same as the type. For struct-path aware TBAA, the tag |
| 625 | /// is different from the type: base type, access type and offset. |
| 626 | /// When ConvertTypeToTag is true, we create a tag based on the scalar type. |
| 627 | void DecorateInstruction(llvm::Instruction *Inst, |
| 628 | llvm::MDNode *TBAAInfo, |
| 629 | bool ConvertTypeToTag = true); |
| Dan Gohman | 3d5aff5 | 2010-10-14 23:06:10 +0000 | [diff] [blame] | 630 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 631 | /// Emit the given number of characters as a value of type size_t. |
| John McCall | bc8d40d | 2011-06-24 21:55:10 +0000 | [diff] [blame] | 632 | llvm::ConstantInt *getSize(CharUnits numChars); |
| 633 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 634 | /// Set the visibility for the given LLVM GlobalValue. |
| Anders Carlsson | 0ffeaad | 2011-01-29 19:39:23 +0000 | [diff] [blame] | 635 | void setGlobalVisibility(llvm::GlobalValue *GV, const NamedDecl *D) const; |
| Daniel Dunbar | 04d4078 | 2009-04-14 06:00:08 +0000 | [diff] [blame] | 636 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 637 | /// Set the TLS mode for the given LLVM GlobalVariable for the thread-local |
| 638 | /// variable declaration D. |
| Hans Wennborg | de981f3 | 2012-06-28 08:01:44 +0000 | [diff] [blame] | 639 | void setTLSMode(llvm::GlobalVariable *GV, const VarDecl &D) const; |
| 640 | |
| Anders Carlsson | c7e98fa | 2011-01-29 20:59:35 +0000 | [diff] [blame] | 641 | static llvm::GlobalValue::VisibilityTypes GetLLVMVisibility(Visibility V) { |
| 642 | switch (V) { |
| 643 | case DefaultVisibility: return llvm::GlobalValue::DefaultVisibility; |
| 644 | case HiddenVisibility: return llvm::GlobalValue::HiddenVisibility; |
| 645 | case ProtectedVisibility: return llvm::GlobalValue::ProtectedVisibility; |
| 646 | } |
| 647 | llvm_unreachable("unknown visibility!"); |
| Anders Carlsson | c7e98fa | 2011-01-29 20:59:35 +0000 | [diff] [blame] | 648 | } |
| 649 | |
| John McCall | d46f985 | 2010-02-19 01:32:20 +0000 | [diff] [blame] | 650 | llvm::Constant *GetAddrOfGlobal(GlobalDecl GD) { |
| 651 | if (isa<CXXConstructorDecl>(GD.getDecl())) |
| 652 | return GetAddrOfCXXConstructor(cast<CXXConstructorDecl>(GD.getDecl()), |
| 653 | GD.getCtorType()); |
| 654 | else if (isa<CXXDestructorDecl>(GD.getDecl())) |
| 655 | return GetAddrOfCXXDestructor(cast<CXXDestructorDecl>(GD.getDecl()), |
| 656 | GD.getDtorType()); |
| 657 | else if (isa<FunctionDecl>(GD.getDecl())) |
| 658 | return GetAddrOfFunction(GD); |
| 659 | else |
| 660 | return GetAddrOfGlobalVar(cast<VarDecl>(GD.getDecl())); |
| 661 | } |
| 662 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 663 | /// Will return a global variable of the given type. If a variable with a |
| 664 | /// different type already exists then a new variable with the right type |
| 665 | /// will be created and all uses of the old variable will be replaced with a |
| 666 | /// bitcast to the new variable. |
| Anders Carlsson | 3bd6202 | 2011-01-29 18:20:20 +0000 | [diff] [blame] | 667 | llvm::GlobalVariable * |
| Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 668 | CreateOrReplaceCXXRuntimeVariable(StringRef Name, llvm::Type *Ty, |
| Anders Carlsson | 3bd6202 | 2011-01-29 18:20:20 +0000 | [diff] [blame] | 669 | llvm::GlobalValue::LinkageTypes Linkage); |
| 670 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 671 | /// Return the address space of the underlying global variable for D, as |
| 672 | /// determined by its declaration. Normally this is the same as the address |
| 673 | /// space of D's type, but in CUDA, address spaces are associated with |
| 674 | /// declarations, not types. |
| Peter Collingbourne | 4dc34eb | 2012-05-20 21:08:35 +0000 | [diff] [blame] | 675 | unsigned GetGlobalVarAddressSpace(const VarDecl *D, unsigned AddrSpace); |
| 676 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 677 | /// Return the llvm::Constant for the address of the given global variable. |
| 678 | /// If Ty is non-null and if the global doesn't exist, then it will be greated |
| 679 | /// with the specified type instead of whatever the normal requested type |
| 680 | /// would be. |
| Chris Lattner | 570585c | 2009-03-21 09:16:30 +0000 | [diff] [blame] | 681 | llvm::Constant *GetAddrOfGlobalVar(const VarDecl *D, |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 682 | llvm::Type *Ty = nullptr); |
| Daniel Dunbar | bd012ff | 2008-07-29 23:18:29 +0000 | [diff] [blame] | 683 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 684 | /// Return the address of the given function. If Ty is non-null, then this |
| 685 | /// function will use the specified type if it has to create it. |
| Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 686 | llvm::Constant *GetAddrOfFunction(GlobalDecl GD, llvm::Type *Ty = 0, |
| 687 | bool ForVTable = false, |
| 688 | bool DontDefer = false); |
| Daniel Dunbar | 6143293 | 2008-08-13 23:20:05 +0000 | [diff] [blame] | 689 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 690 | /// Get the address of the RTTI descriptor for the given type. |
| John McCall | 9dffe6f | 2010-04-30 01:15:21 +0000 | [diff] [blame] | 691 | llvm::Constant *GetAddrOfRTTIDescriptor(QualType Ty, bool ForEH = false); |
| Anders Carlsson | 31b7f52 | 2009-12-11 02:46:30 +0000 | [diff] [blame] | 692 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 693 | /// Get the address of a uuid descriptor . |
| Nico Weber | c5f8046 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 694 | llvm::Constant *GetAddrOfUuidDescriptor(const CXXUuidofExpr* E); |
| 695 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 696 | /// Get the address of the thunk for the given global decl. |
| Anders Carlsson | 84c49e4 | 2011-02-06 17:15:43 +0000 | [diff] [blame] | 697 | llvm::Constant *GetAddrOfThunk(GlobalDecl GD, const ThunkInfo &Thunk); |
| Anders Carlsson | 19879c9 | 2010-03-23 17:17:29 +0000 | [diff] [blame] | 698 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 699 | /// Get a reference to the target of VD. |
| Rafael Espindola | 6a83670 | 2010-03-04 18:17:24 +0000 | [diff] [blame] | 700 | llvm::Constant *GetWeakRefReference(const ValueDecl *VD); |
| 701 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 702 | /// Returns the offset from a derived class to a class. Returns null if the |
| 703 | /// offset is 0. |
| Anders Carlsson | a04efdf | 2010-04-24 21:23:59 +0000 | [diff] [blame] | 704 | llvm::Constant * |
| 705 | GetNonVirtualBaseClassOffset(const CXXRecordDecl *ClassDecl, |
| John McCall | f871d0c | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 706 | CastExpr::path_const_iterator PathBegin, |
| 707 | CastExpr::path_const_iterator PathEnd); |
| John McCall | d16c2cf | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 708 | |
| John McCall | f0c11f7 | 2011-03-31 08:03:29 +0000 | [diff] [blame] | 709 | /// A pair of helper functions for a __block variable. |
| 710 | class ByrefHelpers : public llvm::FoldingSetNode { |
| 711 | public: |
| 712 | llvm::Constant *CopyHelper; |
| 713 | llvm::Constant *DisposeHelper; |
| 714 | |
| 715 | /// The alignment of the field. This is important because |
| 716 | /// different offsets to the field within the byref struct need to |
| 717 | /// have different helper functions. |
| 718 | CharUnits Alignment; |
| 719 | |
| 720 | ByrefHelpers(CharUnits alignment) : Alignment(alignment) {} |
| 721 | virtual ~ByrefHelpers(); |
| 722 | |
| 723 | void Profile(llvm::FoldingSetNodeID &id) const { |
| 724 | id.AddInteger(Alignment.getQuantity()); |
| 725 | profileImpl(id); |
| 726 | } |
| 727 | virtual void profileImpl(llvm::FoldingSetNodeID &id) const = 0; |
| 728 | |
| 729 | virtual bool needsCopy() const { return true; } |
| 730 | virtual void emitCopy(CodeGenFunction &CGF, |
| 731 | llvm::Value *dest, llvm::Value *src) = 0; |
| 732 | |
| 733 | virtual bool needsDispose() const { return true; } |
| 734 | virtual void emitDispose(CodeGenFunction &CGF, llvm::Value *field) = 0; |
| 735 | }; |
| 736 | |
| 737 | llvm::FoldingSet<ByrefHelpers> ByrefHelpersCache; |
| John McCall | d16c2cf | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 738 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 739 | /// Fetches the global unique block count. |
| John McCall | 8178df3 | 2011-02-22 22:38:33 +0000 | [diff] [blame] | 740 | int getUniqueBlockCount() { return ++Block.GlobalUniqueCount; } |
| Fariborz Jahanian | 4904bf4 | 2012-06-26 16:06:38 +0000 | [diff] [blame] | 741 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 742 | /// Fetches the type of a generic block descriptor. |
| Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 743 | llvm::Type *getBlockDescriptorType(); |
| John McCall | d16c2cf | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 744 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 745 | /// The type of a generic block literal. |
| Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 746 | llvm::Type *getGenericBlockLiteralType(); |
| John McCall | d16c2cf | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 747 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 748 | /// Gets the address of a block which requires no captures. |
| John McCall | d16c2cf | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 749 | llvm::Constant *GetAddrOfGlobalBlock(const BlockExpr *BE, const char *); |
| Anders Carlsson | a04efdf | 2010-04-24 21:23:59 +0000 | [diff] [blame] | 750 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 751 | /// Return a pointer to a constant CFString object for the given string. |
| Steve Naroff | 8d4141f | 2009-04-01 13:55:36 +0000 | [diff] [blame] | 752 | llvm::Constant *GetAddrOfConstantCFString(const StringLiteral *Literal); |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 753 | |
| 754 | /// Return a pointer to a constant NSString object for the given string. Or a |
| 755 | /// user defined String object as defined via |
| Fariborz Jahanian | 4c73307 | 2010-10-19 17:19:29 +0000 | [diff] [blame] | 756 | /// -fconstant-string-class=class_name option. |
| 757 | llvm::Constant *GetAddrOfConstantString(const StringLiteral *Literal); |
| Chris Lattner | a7ad98f | 2008-02-11 00:02:17 +0000 | [diff] [blame] | 758 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 759 | /// Return a constant array for the given string. |
| Eli Friedman | 64f45a2 | 2011-11-01 02:23:42 +0000 | [diff] [blame] | 760 | llvm::Constant *GetConstantArrayFromStringLiteral(const StringLiteral *E); |
| 761 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 762 | /// Return a pointer to a constant array for the given string literal. |
| Daniel Dunbar | 6143293 | 2008-08-13 23:20:05 +0000 | [diff] [blame] | 763 | llvm::Constant *GetAddrOfConstantStringFromLiteral(const StringLiteral *S); |
| Daniel Dunbar | 1e04976 | 2008-08-10 20:25:57 +0000 | [diff] [blame] | 764 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 765 | /// Return a pointer to a constant array for the given ObjCEncodeExpr node. |
| Chris Lattner | eaf2bb8 | 2009-02-24 22:18:39 +0000 | [diff] [blame] | 766 | llvm::Constant *GetAddrOfConstantStringFromObjCEncode(const ObjCEncodeExpr *); |
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 767 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 768 | /// Returns a pointer to a character array containing the literal and a |
| 769 | /// terminating '\0' character. The result has pointer to array type. |
| Daniel Dunbar | 5fabf9d | 2008-10-17 21:56:50 +0000 | [diff] [blame] | 770 | /// |
| Mike Stump | ecc90e9 | 2009-02-13 19:12:34 +0000 | [diff] [blame] | 771 | /// \param GlobalName If provided, the name to use for the global (if one is |
| 772 | /// created). |
| Daniel Dunbar | 5fabf9d | 2008-10-17 21:56:50 +0000 | [diff] [blame] | 773 | llvm::Constant *GetAddrOfConstantCString(const std::string &str, |
| Stephen Hines | ef82254 | 2014-07-21 00:47:37 -0700 | [diff] [blame^] | 774 | const char *GlobalName = nullptr, |
| 775 | unsigned Alignment = 0); |
| Richard Smith | 7401cf5 | 2011-11-22 22:48:32 +0000 | [diff] [blame] | 776 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 777 | /// Returns a pointer to a constant global variable for the given file-scope |
| 778 | /// compound literal expression. |
| Richard Smith | 7401cf5 | 2011-11-22 22:48:32 +0000 | [diff] [blame] | 779 | llvm::Constant *GetAddrOfConstantCompoundLiteral(const CompoundLiteralExpr*E); |
| Richard Smith | 211c8dd | 2013-06-05 00:46:14 +0000 | [diff] [blame] | 780 | |
| 781 | /// \brief Returns a pointer to a global variable representing a temporary |
| 782 | /// with static or thread storage duration. |
| 783 | llvm::Constant *GetAddrOfGlobalTemporary(const MaterializeTemporaryExpr *E, |
| 784 | const Expr *Inner); |
| 785 | |
| Douglas Gregor | 0815b57 | 2011-08-09 17:23:49 +0000 | [diff] [blame] | 786 | /// \brief Retrieve the record type that describes the state of an |
| 787 | /// Objective-C fast enumeration loop (for..in). |
| 788 | QualType getObjCFastEnumerationStateType(); |
| 789 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 790 | /// Return the address of the constructor of the given type. |
| 791 | llvm::GlobalValue * |
| 792 | GetAddrOfCXXConstructor(const CXXConstructorDecl *ctor, CXXCtorType ctorType, |
| 793 | const CGFunctionInfo *fnInfo = nullptr, |
| 794 | bool DontDefer = false); |
| Anders Carlsson | 27ae536 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 795 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 796 | /// Return the address of the constructor of the given type. |
| 797 | llvm::GlobalValue * |
| 798 | GetAddrOfCXXDestructor(const CXXDestructorDecl *dtor, |
| 799 | CXXDtorType dtorType, |
| 800 | const CGFunctionInfo *fnInfo = nullptr, |
| 801 | llvm::FunctionType *fnType = nullptr, |
| 802 | bool DontDefer = false); |
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 803 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 804 | /// Given a builtin id for a function like "__builtin_fabsf", return a |
| 805 | /// Function* for "fabsf". |
| Daniel Dunbar | 34771b5 | 2009-09-14 04:33:21 +0000 | [diff] [blame] | 806 | llvm::Value *getBuiltinLibFunction(const FunctionDecl *FD, |
| 807 | unsigned BuiltinID); |
| Daniel Dunbar | 6143293 | 2008-08-13 23:20:05 +0000 | [diff] [blame] | 808 | |
| Dmitri Gribenko | 5543169 | 2013-05-05 00:41:58 +0000 | [diff] [blame] | 809 | llvm::Function *getIntrinsic(unsigned IID, ArrayRef<llvm::Type*> Tys = None); |
| Daniel Dunbar | bd012ff | 2008-07-29 23:18:29 +0000 | [diff] [blame] | 810 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 811 | /// Emit code for a single top level declaration. |
| Daniel Dunbar | 41071de | 2008-08-15 23:26:23 +0000 | [diff] [blame] | 812 | void EmitTopLevelDecl(Decl *D); |
| Daniel Dunbar | bd012ff | 2008-07-29 23:18:29 +0000 | [diff] [blame] | 813 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 814 | /// Tell the consumer that this variable has been instantiated. |
| Rafael Espindola | 0250393 | 2012-03-08 15:51:03 +0000 | [diff] [blame] | 815 | void HandleCXXStaticMemberVarInstantiation(VarDecl *VD); |
| Rafael Espindola | 234fe65 | 2012-03-05 10:54:55 +0000 | [diff] [blame] | 816 | |
| Richard Smith | 0024937 | 2013-04-06 05:00:46 +0000 | [diff] [blame] | 817 | /// \brief If the declaration has internal linkage but is inside an |
| 818 | /// extern "C" linkage specification, prepare to emit an alias for it |
| 819 | /// to the expected name. |
| 820 | template<typename SomeDecl> |
| 821 | void MaybeHandleStaticInExternC(const SomeDecl *D, llvm::GlobalValue *GV); |
| 822 | |
| Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 823 | /// Add a global to a list to be added to the llvm.used metadata. |
| 824 | void addUsedGlobal(llvm::GlobalValue *GV); |
| 825 | |
| 826 | /// Add a global to a list to be added to the llvm.compiler.used metadata. |
| 827 | void addCompilerUsedGlobal(llvm::GlobalValue *GV); |
| Daniel Dunbar | 0269871 | 2009-02-13 20:29:50 +0000 | [diff] [blame] | 828 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 829 | /// Add a destructor and object to add to the C++ global destructor function. |
| Chris Lattner | 810112e | 2010-06-19 05:52:45 +0000 | [diff] [blame] | 830 | void AddCXXDtorEntry(llvm::Constant *DtorFn, llvm::Constant *Object) { |
| 831 | CXXGlobalDtors.push_back(std::make_pair(DtorFn, Object)); |
| 832 | } |
| Daniel Dunbar | efb0fa9 | 2010-03-20 04:15:41 +0000 | [diff] [blame] | 833 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 834 | /// Create a new runtime function with the specified type and name. |
| Chris Lattner | 2acc6e3 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 835 | llvm::Constant *CreateRuntimeFunction(llvm::FunctionType *Ty, |
| Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 836 | StringRef Name, |
| Bill Wendling | c4c62fd | 2013-01-31 00:30:05 +0000 | [diff] [blame] | 837 | llvm::AttributeSet ExtraAttrs = |
| 838 | llvm::AttributeSet()); |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 839 | /// Create a new runtime global variable with the specified type and name. |
| Chris Lattner | 2acc6e3 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 840 | llvm::Constant *CreateRuntimeVariable(llvm::Type *Ty, |
| Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 841 | StringRef Name); |
| Daniel Dunbar | f1968f2 | 2008-10-01 00:49:24 +0000 | [diff] [blame] | 842 | |
| Daniel Dunbar | 673431a | 2010-07-16 00:00:15 +0000 | [diff] [blame] | 843 | ///@name Custom Blocks Runtime Interfaces |
| 844 | ///@{ |
| 845 | |
| 846 | llvm::Constant *getNSConcreteGlobalBlock(); |
| 847 | llvm::Constant *getNSConcreteStackBlock(); |
| 848 | llvm::Constant *getBlockObjectAssign(); |
| 849 | llvm::Constant *getBlockObjectDispose(); |
| 850 | |
| 851 | ///@} |
| 852 | |
| Nadav Rotem | 495cfa4 | 2013-03-23 06:43:35 +0000 | [diff] [blame] | 853 | llvm::Constant *getLLVMLifetimeStartFn(); |
| 854 | llvm::Constant *getLLVMLifetimeEndFn(); |
| 855 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 856 | // Make sure that this type is translated. |
| Devang Patel | e80d567 | 2011-03-23 16:29:39 +0000 | [diff] [blame] | 857 | void UpdateCompletedType(const TagDecl *TD); |
| Daniel Dunbar | d60f2fb | 2009-02-17 18:43:32 +0000 | [diff] [blame] | 858 | |
| John McCall | 5808ce4 | 2011-02-03 08:15:49 +0000 | [diff] [blame] | 859 | llvm::Constant *getMemberPointerConstant(const UnaryOperator *e); |
| 860 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 861 | /// Try to emit the initializer for the given declaration as a constant; |
| 862 | /// returns 0 if the expression cannot be emitted as a constant. |
| 863 | llvm::Constant *EmitConstantInit(const VarDecl &D, |
| 864 | CodeGenFunction *CGF = nullptr); |
| Richard Smith | 2d6a567 | 2012-01-14 04:30:29 +0000 | [diff] [blame] | 865 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 866 | /// Try to emit the given expression as a constant; returns 0 if the |
| 867 | /// expression cannot be emitted as a constant. |
| Anders Carlsson | e9352cc | 2009-04-08 04:48:15 +0000 | [diff] [blame] | 868 | llvm::Constant *EmitConstantExpr(const Expr *E, QualType DestType, |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 869 | CodeGenFunction *CGF = nullptr); |
| Daniel Dunbar | d60f2fb | 2009-02-17 18:43:32 +0000 | [diff] [blame] | 870 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 871 | /// Emit the given constant value as a constant, in the type's scalar |
| 872 | /// representation. |
| Richard Smith | 2d6a567 | 2012-01-14 04:30:29 +0000 | [diff] [blame] | 873 | llvm::Constant *EmitConstantValue(const APValue &Value, QualType DestType, |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 874 | CodeGenFunction *CGF = nullptr); |
| Richard Smith | 2d6a567 | 2012-01-14 04:30:29 +0000 | [diff] [blame] | 875 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 876 | /// Emit the given constant value as a constant, in the type's memory |
| 877 | /// representation. |
| Richard Smith | a3ca41f | 2012-03-02 23:27:11 +0000 | [diff] [blame] | 878 | llvm::Constant *EmitConstantValueForMemory(const APValue &Value, |
| 879 | QualType DestType, |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 880 | CodeGenFunction *CGF = nullptr); |
| Richard Smith | a3ca41f | 2012-03-02 23:27:11 +0000 | [diff] [blame] | 881 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 882 | /// Return the result of value-initializing the given type, i.e. a null |
| 883 | /// expression of the given type. This is usually, but not always, an LLVM |
| 884 | /// null constant. |
| Eli Friedman | 0f59312 | 2009-04-13 21:47:26 +0000 | [diff] [blame] | 885 | llvm::Constant *EmitNullConstant(QualType T); |
| 886 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 887 | /// Return a null constant appropriate for zero-initializing a base class with |
| 888 | /// the given type. This is usually, but not always, an LLVM null constant. |
| Eli Friedman | 2ed7cb6 | 2011-10-14 02:27:24 +0000 | [diff] [blame] | 889 | llvm::Constant *EmitNullConstantForBase(const CXXRecordDecl *Record); |
| 890 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 891 | /// Emit a general error that something can't be done. |
| Chandler Carruth | 0f30a12 | 2012-03-30 19:44:53 +0000 | [diff] [blame] | 892 | void Error(SourceLocation loc, StringRef error); |
| John McCall | 3209669 | 2011-03-18 02:56:14 +0000 | [diff] [blame] | 893 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 894 | /// Print out an error that codegen doesn't support the specified stmt yet. |
| David Blaikie | 0a1c862 | 2013-08-19 21:02:26 +0000 | [diff] [blame] | 895 | void ErrorUnsupported(const Stmt *S, const char *Type); |
| Mike Stump | ecc90e9 | 2009-02-13 19:12:34 +0000 | [diff] [blame] | 896 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 897 | /// Print out an error that codegen doesn't support the specified decl yet. |
| David Blaikie | 0a1c862 | 2013-08-19 21:02:26 +0000 | [diff] [blame] | 898 | void ErrorUnsupported(const Decl *D, const char *Type); |
| Dan Gohman | 4f8d123 | 2008-05-22 00:50:06 +0000 | [diff] [blame] | 899 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 900 | /// Set the attributes on the LLVM function for the given decl and function |
| 901 | /// info. This applies attributes necessary for handling the ABI as well as |
| 902 | /// user specified attributes like section. |
| Daniel Dunbar | 0e4f40e | 2009-04-17 00:48:04 +0000 | [diff] [blame] | 903 | void SetInternalFunctionAttributes(const Decl *D, llvm::Function *F, |
| 904 | const CGFunctionInfo &FI); |
| Daniel Dunbar | f80519b | 2008-09-04 23:41:35 +0000 | [diff] [blame] | 905 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 906 | /// Set the LLVM function attributes (sext, zext, etc). |
| Daniel Dunbar | 7dbd819 | 2009-04-14 07:08:30 +0000 | [diff] [blame] | 907 | void SetLLVMFunctionAttributes(const Decl *D, |
| 908 | const CGFunctionInfo &Info, |
| 909 | llvm::Function *F); |
| Daniel Dunbar | b768807 | 2008-09-10 00:41:16 +0000 | [diff] [blame] | 910 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 911 | /// Set the LLVM function attributes which only apply to a function |
| 912 | /// definintion. |
| Daniel Dunbar | 7c65e99 | 2009-04-14 08:05:55 +0000 | [diff] [blame] | 913 | void SetLLVMFunctionAttributesForDefinition(const Decl *D, llvm::Function *F); |
| 914 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 915 | /// Return true iff the given type uses 'sret' when used as a return type. |
| Daniel Dunbar | dacf9dd | 2010-07-14 23:39:36 +0000 | [diff] [blame] | 916 | bool ReturnTypeUsesSRet(const CGFunctionInfo &FI); |
| 917 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 918 | /// Return true iff the given type uses an argument slot when 'sret' is used |
| 919 | /// as a return type. |
| Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 920 | bool ReturnSlotInterferesWithArgs(const CGFunctionInfo &FI); |
| 921 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 922 | /// Return true iff the given type uses 'fpret' when used as a return type. |
| Daniel Dunbar | dacf9dd | 2010-07-14 23:39:36 +0000 | [diff] [blame] | 923 | bool ReturnTypeUsesFPRet(QualType ResultType); |
| Daniel Dunbar | b768807 | 2008-09-10 00:41:16 +0000 | [diff] [blame] | 924 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 925 | /// Return true iff the given type uses 'fp2ret' when used as a return type. |
| Anders Carlsson | eea6480 | 2011-10-31 16:27:11 +0000 | [diff] [blame] | 926 | bool ReturnTypeUsesFP2Ret(QualType ResultType); |
| 927 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 928 | /// Get the LLVM attributes and calling convention to use for a particular |
| 929 | /// function type. |
| Daniel Dunbar | ca6408c | 2009-09-12 00:59:20 +0000 | [diff] [blame] | 930 | /// |
| 931 | /// \param Info - The function type information. |
| 932 | /// \param TargetDecl - The decl these attributes are being constructed |
| 933 | /// for. If supplied the attributes applied to this decl may contribute to the |
| 934 | /// function attributes and calling convention. |
| 935 | /// \param PAL [out] - On return, the attribute list to use. |
| 936 | /// \param CallingConv [out] - On return, the LLVM calling convention to use. |
| Daniel Dunbar | 88b5396 | 2009-02-02 22:03:45 +0000 | [diff] [blame] | 937 | void ConstructAttributeList(const CGFunctionInfo &Info, |
| 938 | const Decl *TargetDecl, |
| Daniel Dunbar | ca6408c | 2009-09-12 00:59:20 +0000 | [diff] [blame] | 939 | AttributeListType &PAL, |
| Bill Wendling | 94236e7 | 2013-02-22 00:13:35 +0000 | [diff] [blame] | 940 | unsigned &CallingConv, |
| 941 | bool AttrOnCallSite); |
| Daniel Dunbar | b768807 | 2008-09-10 00:41:16 +0000 | [diff] [blame] | 942 | |
| Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 943 | StringRef getMangledName(GlobalDecl GD); |
| Stephen Hines | ef82254 | 2014-07-21 00:47:37 -0700 | [diff] [blame^] | 944 | StringRef getBlockMangledName(GlobalDecl GD, const BlockDecl *BD); |
| Douglas Gregor | b6c8c8b | 2009-04-21 17:11:58 +0000 | [diff] [blame] | 945 | |
| 946 | void EmitTentativeDefinition(const VarDecl *D); |
| Mike Stump | f121677 | 2009-07-31 18:25:34 +0000 | [diff] [blame] | 947 | |
| Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 948 | void EmitVTable(CXXRecordDecl *Class, bool DefinitionRequired); |
| 949 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 950 | /// Emit the RTTI descriptors for the builtin types. |
| Timur Iskhodzhanov | a53d7a0 | 2013-09-27 14:48:01 +0000 | [diff] [blame] | 951 | void EmitFundamentalRTTIDescriptors(); |
| 952 | |
| Reid Kleckner | 3190ca9 | 2013-05-08 13:44:39 +0000 | [diff] [blame] | 953 | /// \brief Appends Opts to the "Linker Options" metadata value. |
| 954 | void AppendLinkerOptions(StringRef Opts); |
| 955 | |
| Benjamin Kramer | 785f1e7 | 2013-06-04 09:13:21 +0000 | [diff] [blame] | 956 | /// \brief Appends a detect mismatch command to the linker options. |
| Aaron Ballman | a7ff62f | 2013-06-04 02:07:14 +0000 | [diff] [blame] | 957 | void AddDetectMismatch(StringRef Name, StringRef Value); |
| 958 | |
| Reid Kleckner | 3190ca9 | 2013-05-08 13:44:39 +0000 | [diff] [blame] | 959 | /// \brief Appends a dependent lib to the "Linker Options" metadata value. |
| 960 | void AddDependentLib(StringRef Lib); |
| 961 | |
| Peter Collingbourne | 144a31f | 2013-06-05 17:49:37 +0000 | [diff] [blame] | 962 | llvm::GlobalVariable::LinkageTypes getFunctionLinkage(GlobalDecl GD); |
| John McCall | d46f985 | 2010-02-19 01:32:20 +0000 | [diff] [blame] | 963 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 964 | void setFunctionLinkage(GlobalDecl GD, llvm::Function *F) { |
| 965 | F->setLinkage(getFunctionLinkage(GD)); |
| John McCall | 8b24233 | 2010-05-25 04:30:21 +0000 | [diff] [blame] | 966 | } |
| 967 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 968 | /// Return the appropriate linkage for the vtable, VTT, and type information |
| 969 | /// of the given class. |
| Anders Carlsson | 3a717f7 | 2011-01-24 02:04:33 +0000 | [diff] [blame] | 970 | llvm::GlobalVariable::LinkageTypes getVTableLinkage(const CXXRecordDecl *RD); |
| Ken Dyck | 687cc4a | 2010-01-26 13:48:07 +0000 | [diff] [blame] | 971 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 972 | /// Return the store size, in character units, of the given LLVM type. |
| Chris Lattner | 2acc6e3 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 973 | CharUnits GetTargetTypeStoreSize(llvm::Type *Ty) const; |
| Fariborz Jahanian | 354e712 | 2010-10-27 16:21:54 +0000 | [diff] [blame] | 974 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 975 | /// Returns LLVM linkage for a declarator. |
| 976 | llvm::GlobalValue::LinkageTypes |
| 977 | getLLVMLinkageForDeclarator(const DeclaratorDecl *D, GVALinkage Linkage, |
| 978 | bool IsConstantVariable); |
| 979 | |
| 980 | /// Returns LLVM linkage for a declarator. |
| 981 | llvm::GlobalValue::LinkageTypes |
| 982 | getLLVMLinkageVarDefinition(const VarDecl *VD, bool IsConstant); |
| 983 | |
| Julien Lerouge | 77f68bb | 2011-09-09 22:41:49 +0000 | [diff] [blame] | 984 | /// Emit all the global annotations. |
| 985 | void EmitGlobalAnnotations(); |
| 986 | |
| 987 | /// Emit an annotation string. |
| Dmitri Gribenko | cfa88f8 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 988 | llvm::Constant *EmitAnnotationString(StringRef Str); |
| Julien Lerouge | 77f68bb | 2011-09-09 22:41:49 +0000 | [diff] [blame] | 989 | |
| 990 | /// Emit the annotation's translation unit. |
| 991 | llvm::Constant *EmitAnnotationUnit(SourceLocation Loc); |
| 992 | |
| 993 | /// Emit the annotation line number. |
| 994 | llvm::Constant *EmitAnnotationLineNo(SourceLocation L); |
| 995 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 996 | /// Generate the llvm::ConstantStruct which contains the annotation |
| 997 | /// information for a given GlobalValue. The annotation struct is |
| Julien Lerouge | 77f68bb | 2011-09-09 22:41:49 +0000 | [diff] [blame] | 998 | /// {i8 *, i8 *, i8 *, i32}. The first field is a constant expression, the |
| 999 | /// GlobalValue being annotated. The second field is the constant string |
| 1000 | /// created from the AnnotateAttr's annotation. The third field is a constant |
| 1001 | /// string containing the name of the translation unit. The fourth field is |
| 1002 | /// the line number in the file of the annotated value declaration. |
| 1003 | llvm::Constant *EmitAnnotateAttr(llvm::GlobalValue *GV, |
| 1004 | const AnnotateAttr *AA, |
| 1005 | SourceLocation L); |
| 1006 | |
| 1007 | /// Add global annotations that are set on D, for the global GV. Those |
| 1008 | /// annotations are emitted during finalization of the LLVM code. |
| 1009 | void AddGlobalAnnotations(const ValueDecl *D, llvm::GlobalValue *GV); |
| 1010 | |
| Stephen Hines | ef82254 | 2014-07-21 00:47:37 -0700 | [diff] [blame^] | 1011 | const SanitizerBlacklist &getSanitizerBlacklist() const { |
| 1012 | return SanitizerBL; |
| Will Dietz | 4f45bc0 | 2013-01-18 11:30:38 +0000 | [diff] [blame] | 1013 | } |
| 1014 | |
| Stephen Hines | ef82254 | 2014-07-21 00:47:37 -0700 | [diff] [blame^] | 1015 | void reportGlobalToASan(llvm::GlobalVariable *GV, SourceLocation Loc, |
| 1016 | bool IsDynInit = false); |
| Will Dietz | 4f45bc0 | 2013-01-18 11:30:38 +0000 | [diff] [blame] | 1017 | |
| John McCall | d5617ee | 2013-01-25 22:31:03 +0000 | [diff] [blame] | 1018 | void addDeferredVTable(const CXXRecordDecl *RD) { |
| 1019 | DeferredVTables.push_back(RD); |
| 1020 | } |
| 1021 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1022 | /// Emit code for a singal global function or var decl. Forward declarations |
| 1023 | /// are emitted lazily. |
| Reid Kleckner | a4130ba | 2013-07-22 13:51:44 +0000 | [diff] [blame] | 1024 | void EmitGlobal(GlobalDecl D); |
| 1025 | |
| Chris Lattner | 9cd4fe4 | 2007-12-02 07:09:19 +0000 | [diff] [blame] | 1026 | private: |
| Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 1027 | llvm::GlobalValue *GetGlobalValue(StringRef Ref); |
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1028 | |
| Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1029 | llvm::Constant * |
| 1030 | GetOrCreateLLVMFunction(StringRef MangledName, llvm::Type *Ty, GlobalDecl D, |
| 1031 | bool ForVTable, bool DontDefer = false, |
| 1032 | llvm::AttributeSet ExtraAttrs = llvm::AttributeSet()); |
| 1033 | |
| Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 1034 | llvm::Constant *GetOrCreateLLVMGlobal(StringRef MangledName, |
| Chris Lattner | 2acc6e3 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 1035 | llvm::PointerType *PTy, |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1036 | const VarDecl *D); |
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1037 | |
| Stephen Hines | ef82254 | 2014-07-21 00:47:37 -0700 | [diff] [blame^] | 1038 | llvm::StringMapEntry<llvm::GlobalVariable *> * |
| 1039 | getConstantStringMapEntry(StringRef Str, int CharByteWidth); |
| 1040 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1041 | /// Set attributes which are common to any form of a global definition (alias, |
| 1042 | /// Objective-C method, function, global variable). |
| Daniel Dunbar | 7dbd819 | 2009-04-14 07:08:30 +0000 | [diff] [blame] | 1043 | /// |
| Daniel Dunbar | 7c65e99 | 2009-04-14 08:05:55 +0000 | [diff] [blame] | 1044 | /// NOTE: This should only be called for definitions. |
| 1045 | void SetCommonAttributes(const Decl *D, llvm::GlobalValue *GV); |
| Daniel Dunbar | f80519b | 2008-09-04 23:41:35 +0000 | [diff] [blame] | 1046 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1047 | void setNonAliasAttributes(const Decl *D, llvm::GlobalObject *GO); |
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1048 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1049 | /// Set attributes for a global definition. |
| 1050 | void setFunctionDefinitionAttributes(const FunctionDecl *D, |
| 1051 | llvm::Function *F); |
| 1052 | |
| 1053 | /// Set function attributes for a function declaration. |
| Anders Carlsson | b2bcf1c | 2010-02-06 02:44:09 +0000 | [diff] [blame] | 1054 | void SetFunctionAttributes(GlobalDecl GD, |
| Eli Friedman | c6c14d1 | 2009-05-26 01:22:57 +0000 | [diff] [blame] | 1055 | llvm::Function *F, |
| 1056 | bool IsIncompleteFunction); |
| Nuno Lopes | d4cbda6 | 2008-06-08 15:45:52 +0000 | [diff] [blame] | 1057 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1058 | void EmitGlobalDefinition(GlobalDecl D, llvm::GlobalValue *GV = nullptr); |
| Daniel Dunbar | d5d3180 | 2009-02-19 07:15:39 +0000 | [diff] [blame] | 1059 | |
| Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1060 | void EmitGlobalFunctionDefinition(GlobalDecl GD, llvm::GlobalValue *GV); |
| Daniel Dunbar | bd012ff | 2008-07-29 23:18:29 +0000 | [diff] [blame] | 1061 | void EmitGlobalVarDefinition(const VarDecl *D); |
| John McCall | f746aa6 | 2010-03-19 23:29:14 +0000 | [diff] [blame] | 1062 | void EmitAliasDefinition(GlobalDecl GD); |
| Daniel Dunbar | af05bb9 | 2008-08-26 08:29:31 +0000 | [diff] [blame] | 1063 | void EmitObjCPropertyImplementations(const ObjCImplementationDecl *D); |
| Fariborz Jahanian | 109dfc6 | 2010-04-28 21:28:56 +0000 | [diff] [blame] | 1064 | void EmitObjCIvarInitializations(ObjCImplementationDecl *D); |
| Fariborz Jahanian | 354e712 | 2010-10-27 16:21:54 +0000 | [diff] [blame] | 1065 | |
| Anders Carlsson | 95d4e5d | 2009-04-15 15:55:24 +0000 | [diff] [blame] | 1066 | // C++ related functions. |
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1067 | |
| Rafael Espindola | 71fdc12 | 2013-11-04 18:38:59 +0000 | [diff] [blame] | 1068 | bool TryEmitDefinitionAsAlias(GlobalDecl Alias, GlobalDecl Target, |
| 1069 | bool InEveryTU); |
| John McCall | c0bf462 | 2010-02-23 00:48:20 +0000 | [diff] [blame] | 1070 | bool TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D); |
| John McCall | d46f985 | 2010-02-19 01:32:20 +0000 | [diff] [blame] | 1071 | |
| Anders Carlsson | 984e068 | 2009-04-01 00:58:25 +0000 | [diff] [blame] | 1072 | void EmitNamespace(const NamespaceDecl *D); |
| Anders Carlsson | 91e20dd | 2009-04-02 05:55:18 +0000 | [diff] [blame] | 1073 | void EmitLinkageSpec(const LinkageSpecDecl *D); |
| Adrian Prantl | 0a050f7 | 2013-05-09 23:16:27 +0000 | [diff] [blame] | 1074 | void CompleteDIClassType(const CXXMethodDecl* D); |
| Anders Carlsson | 95d4e5d | 2009-04-15 15:55:24 +0000 | [diff] [blame] | 1075 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1076 | /// Emit a single constructor with the given type from a C++ constructor Decl. |
| Anders Carlsson | 95d4e5d | 2009-04-15 15:55:24 +0000 | [diff] [blame] | 1077 | void EmitCXXConstructor(const CXXConstructorDecl *D, CXXCtorType Type); |
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1078 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1079 | /// Emit a single destructor with the given type from a C++ destructor Decl. |
| Anders Carlsson | 27ae536 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 1080 | void EmitCXXDestructor(const CXXDestructorDecl *D, CXXDtorType Type); |
| Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1081 | |
| Richard Smith | b80a16e | 2013-04-19 16:42:07 +0000 | [diff] [blame] | 1082 | /// \brief Emit the function that initializes C++ thread_local variables. |
| 1083 | void EmitCXXThreadLocalInitFunc(); |
| 1084 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1085 | /// Emit the function that initializes C++ globals. |
| Anders Carlsson | 89ed31d | 2009-08-08 23:24:23 +0000 | [diff] [blame] | 1086 | void EmitCXXGlobalInitFunc(); |
| Eli Friedman | 6c6bda3 | 2010-01-08 00:50:11 +0000 | [diff] [blame] | 1087 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1088 | /// Emit the function that destroys C++ globals. |
| Daniel Dunbar | efb0fa9 | 2010-03-20 04:15:41 +0000 | [diff] [blame] | 1089 | void EmitCXXGlobalDtorFunc(); |
| 1090 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1091 | /// Emit the function that initializes the specified global (if PerformInit is |
| 1092 | /// true) and registers its destructor. |
| John McCall | 3030eb8 | 2010-11-06 09:44:32 +0000 | [diff] [blame] | 1093 | void EmitCXXGlobalVarDeclInitFunc(const VarDecl *D, |
| Richard Smith | 7ca4850 | 2012-02-13 22:16:19 +0000 | [diff] [blame] | 1094 | llvm::GlobalVariable *Addr, |
| 1095 | bool PerformInit); |
| Eli Friedman | 6c6bda3 | 2010-01-08 00:50:11 +0000 | [diff] [blame] | 1096 | |
| Daniel Dunbar | 6bfed7e | 2008-08-01 00:01:51 +0000 | [diff] [blame] | 1097 | // FIXME: Hardcoding priority here is gross. |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1098 | void AddGlobalCtor(llvm::Function *Ctor, int Priority = 65535, |
| 1099 | llvm::Constant *AssociatedData = 0); |
| 1100 | void AddGlobalDtor(llvm::Function *Dtor, int Priority = 65535); |
| Daniel Dunbar | bd012ff | 2008-07-29 23:18:29 +0000 | [diff] [blame] | 1101 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1102 | /// Generates a global array of functions and priorities using the given list |
| 1103 | /// and name. This array will have appending linkage and is suitable for use |
| 1104 | /// as a LLVM constructor or destructor array. |
| Daniel Dunbar | 6bfed7e | 2008-08-01 00:01:51 +0000 | [diff] [blame] | 1105 | void EmitCtorList(const CtorList &Fns, const char *GlobalName); |
| 1106 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1107 | /// Emit the RTTI descriptors for the given type. |
| Rafael Espindola | d1a5c31 | 2010-03-27 02:52:14 +0000 | [diff] [blame] | 1108 | void EmitFundamentalRTTIDescriptor(QualType Type); |
| 1109 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1110 | /// Emit any needed decls for which code generation was deferred. |
| Dmitri Gribenko | c4a7790 | 2012-11-15 14:28:07 +0000 | [diff] [blame] | 1111 | void EmitDeferred(); |
| Daniel Dunbar | 0269871 | 2009-02-13 20:29:50 +0000 | [diff] [blame] | 1112 | |
| Rafael Espindola | 61a0a75 | 2013-11-05 21:37:29 +0000 | [diff] [blame] | 1113 | /// Call replaceAllUsesWith on all pairs in Replacements. |
| 1114 | void applyReplacements(); |
| 1115 | |
| Rafael Espindola | d205498 | 2013-10-22 19:26:13 +0000 | [diff] [blame] | 1116 | void checkAliases(); |
| 1117 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1118 | /// Emit any vtables which we deferred and still have a use for. |
| John McCall | d5617ee | 2013-01-25 22:31:03 +0000 | [diff] [blame] | 1119 | void EmitDeferredVTables(); |
| 1120 | |
| Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1121 | /// Emit the llvm.used and llvm.compiler.used metadata. |
| 1122 | void emitLLVMUsed(); |
| Daniel Dunbar | f1968f2 | 2008-10-01 00:49:24 +0000 | [diff] [blame] | 1123 | |
| Douglas Gregor | 858afb3 | 2013-01-14 20:53:57 +0000 | [diff] [blame] | 1124 | /// \brief Emit the link options introduced by imported modules. |
| 1125 | void EmitModuleLinkOptions(); |
| 1126 | |
| Richard Smith | 0024937 | 2013-04-06 05:00:46 +0000 | [diff] [blame] | 1127 | /// \brief Emit aliases for internal-linkage declarations inside "C" language |
| 1128 | /// linkage specifications, giving them the "expected" name where possible. |
| 1129 | void EmitStaticExternCAliases(); |
| 1130 | |
| John McCall | 744016d | 2010-07-06 23:57:41 +0000 | [diff] [blame] | 1131 | void EmitDeclMetadata(); |
| 1132 | |
| Rafael Espindola | 9686f12 | 2013-10-16 19:28:50 +0000 | [diff] [blame] | 1133 | /// \brief Emit the Clang version as llvm.ident metadata. |
| 1134 | void EmitVersionIdentMetadata(); |
| 1135 | |
| Stephen Hines | ef82254 | 2014-07-21 00:47:37 -0700 | [diff] [blame^] | 1136 | /// Emits target specific Metadata for global declarations. |
| 1137 | void EmitTargetMetadata(); |
| 1138 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1139 | /// Emit the llvm.gcov metadata used to tell LLVM where to emit the .gcno and |
| 1140 | /// .gcda files in a way that persists in .bc files. |
| Nick Lewycky | 3dc0541 | 2011-05-05 00:08:20 +0000 | [diff] [blame] | 1141 | void EmitCoverageFile(); |
| Nick Lewycky | 5ea4f44 | 2011-05-04 20:46:58 +0000 | [diff] [blame] | 1142 | |
| Nico Weber | c5f8046 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 1143 | /// Emits the initializer for a uuidof string. |
| 1144 | llvm::Constant *EmitUuidofInitializer(StringRef uuidstr, QualType IIDType); |
| 1145 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1146 | /// Determine if the given decl can be emitted lazily; this is only relevant |
| 1147 | /// for definitions. The given decl must be either a function or var decl. |
| Daniel Dunbar | 73241df | 2009-02-13 21:18:01 +0000 | [diff] [blame] | 1148 | bool MayDeferGeneration(const ValueDecl *D); |
| John McCall | b259383 | 2010-09-16 06:16:50 +0000 | [diff] [blame] | 1149 | |
| Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1150 | /// Check whether we can use a "simpler", more core exceptions personality |
| 1151 | /// function. |
| John McCall | b259383 | 2010-09-16 06:16:50 +0000 | [diff] [blame] | 1152 | void SimplifyPersonality(); |
| Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1153 | }; |
| 1154 | } // end namespace CodeGen |
| 1155 | } // end namespace clang |
| 1156 | |
| 1157 | #endif |