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