Daniel Dunbar | 9c42652 | 2008-07-29 23:18:29 +0000 | [diff] [blame] | 1 | //===--- CodeGenModule.h - Per-Module state for LLVM CodeGen ----*- C++ -*-===// |
Chris Lattner | f97fe38 | 2007-05-24 06:29:05 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 5b12ab8 | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Chris Lattner | f97fe38 | 2007-05-24 06:29:05 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Mike Stump | 1676c5b | 2009-02-13 19:12:34 +0000 | [diff] [blame] | 10 | // This is the internal per-translation-unit state used for llvm translation. |
Chris Lattner | f97fe38 | 2007-05-24 06:29:05 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Benjamin Kramer | 2f5db8b | 2014-08-13 16:25:19 +0000 | [diff] [blame] | 14 | #ifndef LLVM_CLANG_LIB_CODEGEN_CODEGENMODULE_H |
| 15 | #define LLVM_CLANG_LIB_CODEGEN_CODEGENMODULE_H |
Chris Lattner | f97fe38 | 2007-05-24 06:29:05 +0000 | [diff] [blame] | 16 | |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 17 | #include "CGVTables.h" |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 18 | #include "CodeGenTypeCache.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 19 | #include "CodeGenTypes.h" |
Alexey Samsonov | 4b8de11 | 2014-08-01 21:35:28 +0000 | [diff] [blame] | 20 | #include "SanitizerMetadata.h" |
Dan Gohman | 75d69da | 2008-05-22 00:50:06 +0000 | [diff] [blame] | 21 | #include "clang/AST/Attr.h" |
Anders Carlsson | dae1abc | 2009-05-05 04:44:02 +0000 | [diff] [blame] | 22 | #include "clang/AST/DeclCXX.h" |
Anders Carlsson | 73fcc95 | 2009-09-11 00:07:24 +0000 | [diff] [blame] | 23 | #include "clang/AST/DeclObjC.h" |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 24 | #include "clang/AST/DeclOpenMP.h" |
Peter Collingbourne | ee781d5 | 2011-06-14 04:02:39 +0000 | [diff] [blame] | 25 | #include "clang/AST/GlobalDecl.h" |
Peter Collingbourne | 0ff0b37 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 26 | #include "clang/AST/Mangle.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 27 | #include "clang/Basic/ABI.h" |
| 28 | #include "clang/Basic/LangOptions.h" |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 29 | #include "clang/Basic/Module.h" |
Alexey Samsonov | 8d043e8 | 2014-10-15 19:57:45 +0000 | [diff] [blame] | 30 | #include "clang/Basic/SanitizerBlacklist.h" |
Chris Lattner | b6984c4 | 2007-06-20 04:44:43 +0000 | [diff] [blame] | 31 | #include "llvm/ADT/DenseMap.h" |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 32 | #include "llvm/ADT/SetVector.h" |
Rafael Espindola | 2e42fec | 2010-03-04 18:17:24 +0000 | [diff] [blame] | 33 | #include "llvm/ADT/SmallPtrSet.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 34 | #include "llvm/ADT/StringMap.h" |
Chandler Carruth | ffd5551 | 2013-01-02 11:45:17 +0000 | [diff] [blame] | 35 | #include "llvm/IR/Module.h" |
Chandler Carruth | 61743af | 2014-03-04 11:18:19 +0000 | [diff] [blame] | 36 | #include "llvm/IR/ValueHandle.h" |
Peter Collingbourne | dc13453 | 2016-01-16 00:31:22 +0000 | [diff] [blame] | 37 | #include "llvm/Transforms/Utils/SanitizerStats.h" |
Anders Carlsson | 762e162 | 2009-01-04 02:08:04 +0000 | [diff] [blame] | 38 | |
Chris Lattner | f97fe38 | 2007-05-24 06:29:05 +0000 | [diff] [blame] | 39 | namespace llvm { |
Rafael Espindola | 42ae745 | 2014-05-09 00:57:59 +0000 | [diff] [blame] | 40 | class Module; |
| 41 | class Constant; |
| 42 | class ConstantInt; |
| 43 | class Function; |
| 44 | class GlobalValue; |
| 45 | class DataLayout; |
| 46 | class FunctionType; |
| 47 | class LLVMContext; |
| 48 | class IndexedInstrProfReader; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 49 | } |
Chris Lattner | 23b7eb6 | 2007-06-15 23:05:46 +0000 | [diff] [blame] | 50 | |
Chris Lattner | f97fe38 | 2007-05-24 06:29:05 +0000 | [diff] [blame] | 51 | namespace clang { |
Rafael Espindola | 42ae745 | 2014-05-09 00:57:59 +0000 | [diff] [blame] | 52 | class ASTContext; |
| 53 | class AtomicType; |
| 54 | class FunctionDecl; |
| 55 | class IdentifierInfo; |
| 56 | class ObjCMethodDecl; |
| 57 | class ObjCImplementationDecl; |
| 58 | class ObjCCategoryImplDecl; |
| 59 | class ObjCProtocolDecl; |
| 60 | class ObjCEncodeExpr; |
| 61 | class BlockExpr; |
| 62 | class CharUnits; |
| 63 | class Decl; |
| 64 | class Expr; |
| 65 | class Stmt; |
| 66 | class InitListExpr; |
| 67 | class StringLiteral; |
| 68 | class NamedDecl; |
| 69 | class ValueDecl; |
| 70 | class VarDecl; |
| 71 | class LangOptions; |
| 72 | class CodeGenOptions; |
Adrian Prantl | e74f525 | 2015-06-30 02:26:03 +0000 | [diff] [blame] | 73 | class HeaderSearchOptions; |
| 74 | class PreprocessorOptions; |
Rafael Espindola | 42ae745 | 2014-05-09 00:57:59 +0000 | [diff] [blame] | 75 | class DiagnosticsEngine; |
| 76 | class AnnotateAttr; |
| 77 | class CXXDestructorDecl; |
Rafael Espindola | 42ae745 | 2014-05-09 00:57:59 +0000 | [diff] [blame] | 78 | class Module; |
Alex Lorenz | ee02499 | 2014-08-04 18:41:51 +0000 | [diff] [blame] | 79 | class CoverageSourceInfo; |
Mike Stump | 1676c5b | 2009-02-13 19:12:34 +0000 | [diff] [blame] | 80 | |
Chris Lattner | f97fe38 | 2007-05-24 06:29:05 +0000 | [diff] [blame] | 81 | namespace CodeGen { |
| 82 | |
Rafael Espindola | 42ae745 | 2014-05-09 00:57:59 +0000 | [diff] [blame] | 83 | class CallArgList; |
| 84 | class CodeGenFunction; |
| 85 | class CodeGenTBAA; |
| 86 | class CGCXXABI; |
| 87 | class CGDebugInfo; |
| 88 | class CGObjCRuntime; |
| 89 | class CGOpenCLRuntime; |
| 90 | class CGOpenMPRuntime; |
| 91 | class CGCUDARuntime; |
| 92 | class BlockFieldFlags; |
| 93 | class FunctionArgList; |
Alex Lorenz | ee02499 | 2014-08-04 18:41:51 +0000 | [diff] [blame] | 94 | class CoverageMappingModuleGen; |
John McCall | 12f2352 | 2016-04-04 18:33:08 +0000 | [diff] [blame] | 95 | class TargetCodeGenInfo; |
Justin Bogner | ef512b9 | 2014-01-06 22:27:43 +0000 | [diff] [blame] | 96 | |
Rafael Espindola | 42ae745 | 2014-05-09 00:57:59 +0000 | [diff] [blame] | 97 | struct OrderGlobalInits { |
| 98 | unsigned int priority; |
| 99 | unsigned int lex_order; |
| 100 | OrderGlobalInits(unsigned int p, unsigned int l) |
Chris Lattner | e000907 | 2010-06-27 06:32:58 +0000 | [diff] [blame] | 101 | : priority(p), lex_order(l) {} |
Rafael Espindola | 42ae745 | 2014-05-09 00:57:59 +0000 | [diff] [blame] | 102 | |
| 103 | bool operator==(const OrderGlobalInits &RHS) const { |
| 104 | return priority == RHS.priority && lex_order == RHS.lex_order; |
| 105 | } |
| 106 | |
| 107 | bool operator<(const OrderGlobalInits &RHS) const { |
| 108 | return std::tie(priority, lex_order) < |
| 109 | std::tie(RHS.priority, RHS.lex_order); |
| 110 | } |
| 111 | }; |
| 112 | |
John McCall | b04ecb7 | 2015-10-21 18:06:43 +0000 | [diff] [blame] | 113 | struct ObjCEntrypoints { |
| 114 | ObjCEntrypoints() { memset(this, 0, sizeof(*this)); } |
| 115 | |
Pete Cooper | 9486771 | 2016-03-21 20:50:03 +0000 | [diff] [blame] | 116 | /// void objc_autoreleasePoolPop(void*); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 117 | llvm::Constant *objc_autoreleasePoolPop; |
| 118 | |
| 119 | /// void *objc_autoreleasePoolPush(void); |
| 120 | llvm::Constant *objc_autoreleasePoolPush; |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 121 | |
| 122 | /// id objc_autorelease(id); |
| 123 | llvm::Constant *objc_autorelease; |
| 124 | |
| 125 | /// id objc_autoreleaseReturnValue(id); |
| 126 | llvm::Constant *objc_autoreleaseReturnValue; |
| 127 | |
| 128 | /// void objc_copyWeak(id *dest, id *src); |
| 129 | llvm::Constant *objc_copyWeak; |
| 130 | |
| 131 | /// void objc_destroyWeak(id*); |
| 132 | llvm::Constant *objc_destroyWeak; |
| 133 | |
| 134 | /// id objc_initWeak(id*, id); |
| 135 | llvm::Constant *objc_initWeak; |
| 136 | |
| 137 | /// id objc_loadWeak(id*); |
| 138 | llvm::Constant *objc_loadWeak; |
| 139 | |
| 140 | /// id objc_loadWeakRetained(id*); |
| 141 | llvm::Constant *objc_loadWeakRetained; |
| 142 | |
| 143 | /// void objc_moveWeak(id *dest, id *src); |
| 144 | llvm::Constant *objc_moveWeak; |
| 145 | |
| 146 | /// id objc_retain(id); |
| 147 | llvm::Constant *objc_retain; |
| 148 | |
| 149 | /// id objc_retainAutorelease(id); |
| 150 | llvm::Constant *objc_retainAutorelease; |
| 151 | |
| 152 | /// id objc_retainAutoreleaseReturnValue(id); |
| 153 | llvm::Constant *objc_retainAutoreleaseReturnValue; |
| 154 | |
| 155 | /// id objc_retainAutoreleasedReturnValue(id); |
| 156 | llvm::Constant *objc_retainAutoreleasedReturnValue; |
| 157 | |
| 158 | /// id objc_retainBlock(id); |
| 159 | llvm::Constant *objc_retainBlock; |
| 160 | |
| 161 | /// void objc_release(id); |
| 162 | llvm::Constant *objc_release; |
| 163 | |
| 164 | /// id objc_storeStrong(id*, id); |
| 165 | llvm::Constant *objc_storeStrong; |
| 166 | |
| 167 | /// id objc_storeWeak(id*, id); |
| 168 | llvm::Constant *objc_storeWeak; |
| 169 | |
John McCall | e399e5b | 2016-01-27 18:32:30 +0000 | [diff] [blame] | 170 | /// id objc_unsafeClaimAutoreleasedReturnValue(id); |
| 171 | llvm::Constant *objc_unsafeClaimAutoreleasedReturnValue; |
| 172 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 173 | /// A void(void) inline asm to use to mark that the return value of |
| 174 | /// a call will be immediately retain. |
| 175 | llvm::InlineAsm *retainAutoreleasedReturnValueMarker; |
John McCall | eff1884 | 2013-03-23 02:35:54 +0000 | [diff] [blame] | 176 | |
| 177 | /// void clang.arc.use(...); |
| 178 | llvm::Constant *clang_arc_use; |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 179 | }; |
Will Dietz | f54319c | 2013-01-18 11:30:38 +0000 | [diff] [blame] | 180 | |
Justin Bogner | e2ef2a0 | 2014-04-15 21:22:35 +0000 | [diff] [blame] | 181 | /// This class records statistics on instrumentation based profiling. |
Justin Bogner | 40b8ba1 | 2014-06-26 01:45:07 +0000 | [diff] [blame] | 182 | class InstrProfStats { |
| 183 | uint32_t VisitedInMainFile; |
| 184 | uint32_t MissingInMainFile; |
Justin Bogner | e2ef2a0 | 2014-04-15 21:22:35 +0000 | [diff] [blame] | 185 | uint32_t Visited; |
| 186 | uint32_t Missing; |
| 187 | uint32_t Mismatched; |
Justin Bogner | 40b8ba1 | 2014-06-26 01:45:07 +0000 | [diff] [blame] | 188 | |
| 189 | public: |
| 190 | InstrProfStats() |
| 191 | : VisitedInMainFile(0), MissingInMainFile(0), Visited(0), Missing(0), |
| 192 | Mismatched(0) {} |
| 193 | /// Record that we've visited a function and whether or not that function was |
| 194 | /// in the main source file. |
| 195 | void addVisited(bool MainFile) { |
| 196 | if (MainFile) |
| 197 | ++VisitedInMainFile; |
| 198 | ++Visited; |
| 199 | } |
| 200 | /// Record that a function we've visited has no profile data. |
| 201 | void addMissing(bool MainFile) { |
| 202 | if (MainFile) |
| 203 | ++MissingInMainFile; |
| 204 | ++Missing; |
| 205 | } |
| 206 | /// Record that a function we've visited has mismatched profile data. |
| 207 | void addMismatched(bool MainFile) { ++Mismatched; } |
| 208 | /// Whether or not the stats we've gathered indicate any potential problems. |
| 209 | bool hasDiagnostics() { return Missing || Mismatched; } |
| 210 | /// Report potential problems we've found to \c Diags. |
| 211 | void reportDiagnostics(DiagnosticsEngine &Diags, StringRef MainFile); |
Justin Bogner | e2ef2a0 | 2014-04-15 21:22:35 +0000 | [diff] [blame] | 212 | }; |
| 213 | |
John McCall | bd96e98 | 2015-09-08 08:21:11 +0000 | [diff] [blame] | 214 | /// A pair of helper functions for a __block variable. |
| 215 | class BlockByrefHelpers : public llvm::FoldingSetNode { |
| 216 | // MSVC requires this type to be complete in order to process this |
| 217 | // header. |
| 218 | public: |
| 219 | llvm::Constant *CopyHelper; |
| 220 | llvm::Constant *DisposeHelper; |
| 221 | |
| 222 | /// The alignment of the field. This is important because |
| 223 | /// different offsets to the field within the byref struct need to |
| 224 | /// have different helper functions. |
| 225 | CharUnits Alignment; |
| 226 | |
| 227 | BlockByrefHelpers(CharUnits alignment) : Alignment(alignment) {} |
| 228 | BlockByrefHelpers(const BlockByrefHelpers &) = default; |
| 229 | virtual ~BlockByrefHelpers(); |
| 230 | |
| 231 | void Profile(llvm::FoldingSetNodeID &id) const { |
| 232 | id.AddInteger(Alignment.getQuantity()); |
| 233 | profileImpl(id); |
| 234 | } |
| 235 | virtual void profileImpl(llvm::FoldingSetNodeID &id) const = 0; |
| 236 | |
| 237 | virtual bool needsCopy() const { return true; } |
| 238 | virtual void emitCopy(CodeGenFunction &CGF, Address dest, Address src) = 0; |
| 239 | |
| 240 | virtual bool needsDispose() const { return true; } |
| 241 | virtual void emitDispose(CodeGenFunction &CGF, Address field) = 0; |
| 242 | }; |
| 243 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 244 | /// This class organizes the cross-function state that is used while generating |
| 245 | /// LLVM code. |
John McCall | e3dc170 | 2011-02-15 09:22:45 +0000 | [diff] [blame] | 246 | class CodeGenModule : public CodeGenTypeCache { |
Aaron Ballman | abc1892 | 2015-02-15 22:54:08 +0000 | [diff] [blame] | 247 | CodeGenModule(const CodeGenModule &) = delete; |
| 248 | void operator=(const CodeGenModule &) = delete; |
Anders Carlsson | 729a820 | 2009-02-24 04:21:31 +0000 | [diff] [blame] | 249 | |
Keno Fischer | 76f4ab0 | 2014-12-30 08:12:39 +0000 | [diff] [blame] | 250 | public: |
Reid Kleckner | 563f0e8 | 2014-05-23 21:13:45 +0000 | [diff] [blame] | 251 | struct Structor { |
| 252 | Structor() : Priority(0), Initializer(nullptr), AssociatedData(nullptr) {} |
| 253 | Structor(int Priority, llvm::Constant *Initializer, |
| 254 | llvm::Constant *AssociatedData) |
| 255 | : Priority(Priority), Initializer(Initializer), |
| 256 | AssociatedData(AssociatedData) {} |
| 257 | int Priority; |
| 258 | llvm::Constant *Initializer; |
| 259 | llvm::Constant *AssociatedData; |
| 260 | }; |
| 261 | |
| 262 | typedef std::vector<Structor> CtorList; |
Daniel Dunbar | 74aa7e1 | 2008-08-01 00:01:51 +0000 | [diff] [blame] | 263 | |
Keno Fischer | 76f4ab0 | 2014-12-30 08:12:39 +0000 | [diff] [blame] | 264 | private: |
Chris Lattner | f97fe38 | 2007-05-24 06:29:05 +0000 | [diff] [blame] | 265 | ASTContext &Context; |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 266 | const LangOptions &LangOpts; |
Adrian Prantl | e74f525 | 2015-06-30 02:26:03 +0000 | [diff] [blame] | 267 | const HeaderSearchOptions &HeaderSearchOpts; // Only used for debug info. |
| 268 | const PreprocessorOptions &PreprocessorOpts; // Only used for debug info. |
Chandler Carruth | bc55fe2 | 2009-11-12 17:24:48 +0000 | [diff] [blame] | 269 | const CodeGenOptions &CodeGenOpts; |
Chris Lattner | 23b7eb6 | 2007-06-15 23:05:46 +0000 | [diff] [blame] | 270 | llvm::Module &TheModule; |
David Blaikie | 9c902b5 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 271 | DiagnosticsEngine &Diags; |
John McCall | c8e0170 | 2013-04-16 22:48:15 +0000 | [diff] [blame] | 272 | const TargetInfo &Target; |
Ahmed Charles | b898432 | 2014-03-07 20:03:18 +0000 | [diff] [blame] | 273 | std::unique_ptr<CGCXXABI> ABI; |
John McCall | c8e0170 | 2013-04-16 22:48:15 +0000 | [diff] [blame] | 274 | llvm::LLVMContext &VMContext; |
Anders Carlsson | ff971e8 | 2009-10-07 01:06:45 +0000 | [diff] [blame] | 275 | |
Reid Kleckner | 9305fd1 | 2016-04-13 23:37:17 +0000 | [diff] [blame] | 276 | std::unique_ptr<CodeGenTBAA> TBAA; |
John McCall | c8e0170 | 2013-04-16 22:48:15 +0000 | [diff] [blame] | 277 | |
Reid Kleckner | 9305fd1 | 2016-04-13 23:37:17 +0000 | [diff] [blame] | 278 | mutable std::unique_ptr<TargetCodeGenInfo> TheTargetCodeGenInfo; |
John McCall | c8e0170 | 2013-04-16 22:48:15 +0000 | [diff] [blame] | 279 | |
| 280 | // This should not be moved earlier, since its initialization depends on some |
| 281 | // of the previous reference members being already initialized and also checks |
| 282 | // if TheTargetCodeGenInfo is NULL |
| 283 | CodeGenTypes Types; |
| 284 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 285 | /// Holds information about C++ vtables. |
Anders Carlsson | a864caf | 2010-03-23 04:11:45 +0000 | [diff] [blame] | 286 | CodeGenVTables VTables; |
Douglas Gregor | bc6a434 | 2010-04-08 16:07:47 +0000 | [diff] [blame] | 287 | |
Reid Kleckner | 9305fd1 | 2016-04-13 23:37:17 +0000 | [diff] [blame] | 288 | std::unique_ptr<CGObjCRuntime> ObjCRuntime; |
| 289 | std::unique_ptr<CGOpenCLRuntime> OpenCLRuntime; |
| 290 | std::unique_ptr<CGOpenMPRuntime> OpenMPRuntime; |
| 291 | std::unique_ptr<CGCUDARuntime> CUDARuntime; |
| 292 | std::unique_ptr<CGDebugInfo> DebugInfo; |
| 293 | std::unique_ptr<ObjCEntrypoints> ObjCData; |
| 294 | llvm::MDNode *NoObjCARCExceptionsMetadata = nullptr; |
Justin Bogner | 837a6f6 | 2014-04-18 21:52:00 +0000 | [diff] [blame] | 295 | std::unique_ptr<llvm::IndexedInstrProfReader> PGOReader; |
Justin Bogner | e2ef2a0 | 2014-04-15 21:22:35 +0000 | [diff] [blame] | 296 | InstrProfStats PGOStats; |
Peter Collingbourne | dc13453 | 2016-01-16 00:31:22 +0000 | [diff] [blame] | 297 | std::unique_ptr<llvm::SanitizerStatReport> SanStats; |
Daniel Dunbar | e49df9b5 | 2008-07-30 16:32:24 +0000 | [diff] [blame] | 298 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 299 | // A set of references that have only been seen via a weakref so far. This is |
| 300 | // used to remove the weak of the reference if we ever see a direct reference |
| 301 | // or a definition. |
Rafael Espindola | 2e42fec | 2010-03-04 18:17:24 +0000 | [diff] [blame] | 302 | llvm::SmallPtrSet<llvm::GlobalValue*, 10> WeakRefReferences; |
| 303 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 304 | /// This contains all the decls which have definitions but/ which are deferred |
| 305 | /// for emission and therefore should only be output if they are actually |
| 306 | /// used. If a decl is in this, then it is known to have not been referenced |
| 307 | /// yet. |
Alp Toker | fb8d02b | 2014-06-05 22:10:59 +0000 | [diff] [blame] | 308 | std::map<StringRef, GlobalDecl> DeferredDecls; |
Daniel Dunbar | 08b26a0 | 2009-02-13 20:29:50 +0000 | [diff] [blame] | 309 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 310 | /// This is a list of deferred decls which we have seen that *are* actually |
| 311 | /// referenced. These get code generated when the module is done. |
Rafael Espindola | c0ff744 | 2013-12-09 14:59:08 +0000 | [diff] [blame] | 312 | struct DeferredGlobal { |
| 313 | DeferredGlobal(llvm::GlobalValue *GV, GlobalDecl GD) : GV(GV), GD(GD) {} |
Rafael Espindola | 6565e92 | 2015-01-23 05:26:38 +0000 | [diff] [blame] | 314 | llvm::TrackingVH<llvm::GlobalValue> GV; |
Rafael Espindola | c0ff744 | 2013-12-09 14:59:08 +0000 | [diff] [blame] | 315 | GlobalDecl GD; |
| 316 | }; |
| 317 | std::vector<DeferredGlobal> DeferredDeclsToEmit; |
| 318 | void addDeferredDeclToEmit(llvm::GlobalValue *GV, GlobalDecl GD) { |
Benjamin Kramer | 3204b15 | 2015-05-29 19:42:19 +0000 | [diff] [blame] | 319 | DeferredDeclsToEmit.emplace_back(GV, GD); |
Rafael Espindola | c0ff744 | 2013-12-09 14:59:08 +0000 | [diff] [blame] | 320 | } |
Daniel Dunbar | 7dd749e | 2009-04-15 22:08:45 +0000 | [diff] [blame] | 321 | |
Rafael Espindola | 208b5c0 | 2013-10-22 19:26:13 +0000 | [diff] [blame] | 322 | /// List of alias we have emitted. Used to make sure that what they point to |
| 323 | /// is defined once we get to the end of the of the translation unit. |
| 324 | std::vector<GlobalDecl> Aliases; |
| 325 | |
Rafael Espindola | 2e2995b | 2013-11-05 21:37:29 +0000 | [diff] [blame] | 326 | typedef llvm::StringMap<llvm::TrackingVH<llvm::Constant> > ReplacementsTy; |
| 327 | ReplacementsTy Replacements; |
| 328 | |
Andrey Bokhanko | cab5858 | 2015-08-31 13:20:44 +0000 | [diff] [blame] | 329 | /// List of global values to be replaced with something else. Used when we |
| 330 | /// want to replace a GlobalValue but can't identify it by its mangled name |
| 331 | /// anymore (because the name is already taken). |
| 332 | llvm::SmallVector<std::pair<llvm::GlobalValue *, llvm::Constant *>, 8> |
| 333 | GlobalValReplacements; |
| 334 | |
| 335 | /// Set of global decls for which we already diagnosed mangled name conflict. |
| 336 | /// Required to not issue a warning (on a mangling conflict) multiple times |
| 337 | /// for the same decl. |
| 338 | llvm::DenseSet<GlobalDecl> DiagnosedConflictingDefinitions; |
| 339 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 340 | /// A queue of (optional) vtables to consider emitting. |
John McCall | 6bd2a89 | 2013-01-25 22:31:03 +0000 | [diff] [blame] | 341 | std::vector<const CXXRecordDecl*> DeferredVTables; |
| 342 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 343 | /// List of global values which are required to be present in the object file; |
| 344 | /// bitcast to i8*. This is used for forcing visibility of symbols which may |
| 345 | /// otherwise be optimized out. |
Chris Lattner | f41e87f | 2009-03-31 22:37:52 +0000 | [diff] [blame] | 346 | std::vector<llvm::WeakVH> LLVMUsed; |
Rafael Espindola | 060062a | 2014-03-06 22:15:10 +0000 | [diff] [blame] | 347 | std::vector<llvm::WeakVH> LLVMCompilerUsed; |
Mike Stump | 1676c5b | 2009-02-13 19:12:34 +0000 | [diff] [blame] | 348 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 349 | /// Store the list of global constructors and their respective priorities to |
| 350 | /// be emitted when the translation unit is complete. |
Daniel Dunbar | 74aa7e1 | 2008-08-01 00:01:51 +0000 | [diff] [blame] | 351 | CtorList GlobalCtors; |
| 352 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 353 | /// Store the list of global destructors and their respective priorities to be |
| 354 | /// emitted when the translation unit is complete. |
Daniel Dunbar | 74aa7e1 | 2008-08-01 00:01:51 +0000 | [diff] [blame] | 355 | CtorList GlobalDtors; |
| 356 | |
Robert Lytton | 57765d5 | 2014-07-03 09:30:33 +0000 | [diff] [blame] | 357 | /// An ordered map of canonical GlobalDecls to their mangled names. |
| 358 | llvm::MapVector<GlobalDecl, StringRef> MangledDeclNames; |
Alp Toker | fb8d02b | 2014-06-05 22:10:59 +0000 | [diff] [blame] | 359 | llvm::StringMap<GlobalDecl, llvm::BumpPtrAllocator> Manglings; |
| 360 | |
Julien Lerouge | 5a6b698 | 2011-09-09 22:41:49 +0000 | [diff] [blame] | 361 | /// Global annotations. |
Nate Begeman | 7fab578 | 2008-04-18 23:43:57 +0000 | [diff] [blame] | 362 | std::vector<llvm::Constant*> Annotations; |
Mike Stump | 1676c5b | 2009-02-13 19:12:34 +0000 | [diff] [blame] | 363 | |
Julien Lerouge | 5a6b698 | 2011-09-09 22:41:49 +0000 | [diff] [blame] | 364 | /// Map used to get unique annotation strings. |
| 365 | llvm::StringMap<llvm::Constant*> AnnotationStrings; |
| 366 | |
David Blaikie | 2e80428 | 2015-04-05 22:47:07 +0000 | [diff] [blame] | 367 | llvm::StringMap<llvm::GlobalVariable *> CFConstantStringMap; |
David Majnemer | 58e5bee | 2014-03-24 21:43:36 +0000 | [diff] [blame] | 368 | |
Richard Smith | 00db2f1 | 2014-07-29 21:20:12 +0000 | [diff] [blame] | 369 | llvm::DenseMap<llvm::Constant *, llvm::GlobalVariable *> ConstantStringMap; |
Eli Friedman | 1c8d2ca | 2012-03-09 03:27:46 +0000 | [diff] [blame] | 370 | llvm::DenseMap<const Decl*, llvm::Constant *> StaticLocalDeclMap; |
John McCall | b88a566 | 2012-03-30 21:00:39 +0000 | [diff] [blame] | 371 | llvm::DenseMap<const Decl*, llvm::GlobalVariable*> StaticLocalDeclGuardMap; |
Richard Smith | e6c0144 | 2013-06-05 00:46:14 +0000 | [diff] [blame] | 372 | llvm::DenseMap<const Expr*, llvm::Constant *> MaterializedGlobalTemporaryMap; |
| 373 | |
Fariborz Jahanian | 1bed413 | 2012-01-08 19:13:23 +0000 | [diff] [blame] | 374 | llvm::DenseMap<QualType, llvm::Constant *> AtomicSetterHelperFnMap; |
| 375 | llvm::DenseMap<QualType, llvm::Constant *> AtomicGetterHelperFnMap; |
Daniel Dunbar | d644ad6 | 2008-08-23 18:37:06 +0000 | [diff] [blame] | 376 | |
Will Dietz | 949ec54 | 2013-11-08 01:09:22 +0000 | [diff] [blame] | 377 | /// Map used to get unique type descriptor constants for sanitizers. |
| 378 | llvm::DenseMap<QualType, llvm::Constant *> TypeDescriptorMap; |
| 379 | |
Richard Smith | df931ce | 2013-04-06 05:00:46 +0000 | [diff] [blame] | 380 | /// Map used to track internal linkage functions declared within |
| 381 | /// extern "C" regions. |
Richard Smith | f21c961 | 2013-04-13 01:28:18 +0000 | [diff] [blame] | 382 | typedef llvm::MapVector<IdentifierInfo *, |
| 383 | llvm::GlobalValue *> StaticExternCMap; |
Richard Smith | df931ce | 2013-04-06 05:00:46 +0000 | [diff] [blame] | 384 | StaticExternCMap StaticExternCValues; |
| 385 | |
Richard Smith | 2fd1d7a | 2013-04-19 16:42:07 +0000 | [diff] [blame] | 386 | /// \brief thread_local variables defined or used in this TU. |
Richard Smith | 5a99c49 | 2015-12-01 01:10:48 +0000 | [diff] [blame] | 387 | std::vector<const VarDecl *> CXXThreadLocals; |
Richard Smith | 2fd1d7a | 2013-04-19 16:42:07 +0000 | [diff] [blame] | 388 | |
| 389 | /// \brief thread_local variables with initializers that need to run |
| 390 | /// before any thread_local variable in this TU is odr-used. |
David Majnemer | b3341ea | 2014-10-05 05:05:40 +0000 | [diff] [blame] | 391 | std::vector<llvm::Function *> CXXThreadLocalInits; |
Richard Smith | 5a99c49 | 2015-12-01 01:10:48 +0000 | [diff] [blame] | 392 | std::vector<const VarDecl *> CXXThreadLocalInitVars; |
Richard Smith | 2fd1d7a | 2013-04-19 16:42:07 +0000 | [diff] [blame] | 393 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 394 | /// Global variables with initializers that need to run before main. |
David Majnemer | b3341ea | 2014-10-05 05:05:40 +0000 | [diff] [blame] | 395 | std::vector<llvm::Function *> CXXGlobalInits; |
John McCall | 70013b6 | 2010-07-15 23:40:35 +0000 | [diff] [blame] | 396 | |
| 397 | /// When a C++ decl with an initializer is deferred, null is |
| 398 | /// appended to CXXGlobalInits, and the index of that null is placed |
| 399 | /// here so that the initializer will be performed in the correct |
Reid Kleckner | e07140e | 2015-04-15 01:08:06 +0000 | [diff] [blame] | 400 | /// order. Once the decl is emitted, the index is replaced with ~0U to ensure |
| 401 | /// that we don't re-emit the initializer. |
John McCall | 70013b6 | 2010-07-15 23:40:35 +0000 | [diff] [blame] | 402 | llvm::DenseMap<const Decl*, unsigned> DelayedCXXInitPosition; |
Fariborz Jahanian | 9f2a4ee | 2010-06-21 18:45:05 +0000 | [diff] [blame] | 403 | |
Anton Korobeynikov | abed749 | 2012-11-06 22:44:45 +0000 | [diff] [blame] | 404 | typedef std::pair<OrderGlobalInits, llvm::Function*> GlobalInitData; |
| 405 | |
| 406 | struct GlobalInitPriorityCmp { |
| 407 | bool operator()(const GlobalInitData &LHS, |
| 408 | const GlobalInitData &RHS) const { |
| 409 | return LHS.first.priority < RHS.first.priority; |
| 410 | } |
| 411 | }; |
| 412 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 413 | /// Global variables with initializers whose order of initialization is set by |
| 414 | /// init_priority attribute. |
Anton Korobeynikov | abed749 | 2012-11-06 22:44:45 +0000 | [diff] [blame] | 415 | SmallVector<GlobalInitData, 8> PrioritizedCXXGlobalInits; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 416 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 417 | /// Global destructor functions and arguments that need to run on termination. |
Chris Lattner | 87233f7 | 2010-06-19 05:52:45 +0000 | [diff] [blame] | 418 | std::vector<std::pair<llvm::WeakVH,llvm::Constant*> > CXXGlobalDtors; |
Daniel Dunbar | fe06df4 | 2010-03-20 04:15:41 +0000 | [diff] [blame] | 419 | |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 420 | /// \brief The complete set of modules that has been imported. |
| 421 | llvm::SetVector<clang::Module *> ImportedModules; |
| 422 | |
Reid Kleckner | e43f0fe | 2013-05-08 13:44:39 +0000 | [diff] [blame] | 423 | /// \brief A vector of metadata strings. |
Duncan P. N. Exon Smith | fb49491 | 2014-12-09 18:39:32 +0000 | [diff] [blame] | 424 | SmallVector<llvm::Metadata *, 16> LinkerOptionsMetadata; |
Reid Kleckner | e43f0fe | 2013-05-08 13:44:39 +0000 | [diff] [blame] | 425 | |
Douglas Gregor | abf4e0d | 2011-08-09 15:54:21 +0000 | [diff] [blame] | 426 | /// @name Cache for Objective-C runtime types |
| 427 | /// @{ |
| 428 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [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 | d1b6778 | 2013-04-16 15:25:39 +0000 | [diff] [blame] | 431 | llvm::WeakVH CFConstantStringClassRef; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 432 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 433 | /// Cached reference to the class for constant strings. This value has type |
| 434 | /// int * but is actually an Obj-C class pointer. |
Fariborz Jahanian | d1b6778 | 2013-04-16 15:25:39 +0000 | [diff] [blame] | 435 | llvm::WeakVH ConstantStringClassRef; |
Fariborz Jahanian | e804c28 | 2010-04-23 17:41:07 +0000 | [diff] [blame] | 436 | |
Douglas Gregor | abf4e0d | 2011-08-09 15:54:21 +0000 | [diff] [blame] | 437 | /// \brief The LLVM type corresponding to NSConstantString. |
Reid Kleckner | 9305fd1 | 2016-04-13 23:37:17 +0000 | [diff] [blame] | 438 | llvm::StructType *NSConstantStringType = nullptr; |
| 439 | |
Douglas Gregor | 636e200 | 2011-08-09 17:23:49 +0000 | [diff] [blame] | 440 | /// \brief The type used to describe the state of a fast enumeration in |
| 441 | /// Objective-C's for..in loop. |
| 442 | QualType ObjCFastEnumerationStateType; |
| 443 | |
Douglas Gregor | abf4e0d | 2011-08-09 15:54:21 +0000 | [diff] [blame] | 444 | /// @} |
| 445 | |
David Chisnall | 481e3a8 | 2010-01-23 02:40:42 +0000 | [diff] [blame] | 446 | /// Lazily create the Objective-C runtime |
| 447 | void createObjCRuntime(); |
| 448 | |
Peter Collingbourne | 2dbb708 | 2011-09-19 21:14:35 +0000 | [diff] [blame] | 449 | void createOpenCLRuntime(); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 450 | void createOpenMPRuntime(); |
Peter Collingbourne | fe88342 | 2011-10-06 18:29:37 +0000 | [diff] [blame] | 451 | void createCUDARuntime(); |
Peter Collingbourne | 2dbb708 | 2011-09-19 21:14:35 +0000 | [diff] [blame] | 452 | |
Rafael Espindola | 4fdc175 | 2011-12-19 14:41:01 +0000 | [diff] [blame] | 453 | bool isTriviallyRecursive(const FunctionDecl *F); |
Peter Collingbourne | 4d90dba | 2013-06-05 17:49:37 +0000 | [diff] [blame] | 454 | bool shouldEmitFunction(GlobalDecl GD); |
Daniel Dunbar | 900546d | 2010-07-16 00:00:15 +0000 | [diff] [blame] | 455 | |
| 456 | /// @name Cache for Blocks Runtime Globals |
| 457 | /// @{ |
| 458 | |
Reid Kleckner | 9305fd1 | 2016-04-13 23:37:17 +0000 | [diff] [blame] | 459 | llvm::Constant *NSConcreteGlobalBlock = nullptr; |
| 460 | llvm::Constant *NSConcreteStackBlock = nullptr; |
Daniel Dunbar | 3348e2d | 2010-07-16 00:00:19 +0000 | [diff] [blame] | 461 | |
Reid Kleckner | 9305fd1 | 2016-04-13 23:37:17 +0000 | [diff] [blame] | 462 | llvm::Constant *BlockObjectAssign = nullptr; |
| 463 | llvm::Constant *BlockObjectDispose = nullptr; |
Daniel Dunbar | 900546d | 2010-07-16 00:00:15 +0000 | [diff] [blame] | 464 | |
Reid Kleckner | 9305fd1 | 2016-04-13 23:37:17 +0000 | [diff] [blame] | 465 | llvm::Type *BlockDescriptorType = nullptr; |
| 466 | llvm::Type *GenericBlockLiteralType = nullptr; |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 467 | |
| 468 | struct { |
| 469 | int GlobalUniqueCount; |
| 470 | } Block; |
Will Dietz | f54319c | 2013-01-18 11:30:38 +0000 | [diff] [blame] | 471 | |
Nadav Rotem | 1da3094 | 2013-03-23 06:43:35 +0000 | [diff] [blame] | 472 | /// void @llvm.lifetime.start(i64 %size, i8* nocapture <ptr>) |
Reid Kleckner | 9305fd1 | 2016-04-13 23:37:17 +0000 | [diff] [blame] | 473 | llvm::Constant *LifetimeStartFn = nullptr; |
Nadav Rotem | 1da3094 | 2013-03-23 06:43:35 +0000 | [diff] [blame] | 474 | |
| 475 | /// void @llvm.lifetime.end(i64 %size, i8* nocapture <ptr>) |
Reid Kleckner | 9305fd1 | 2016-04-13 23:37:17 +0000 | [diff] [blame] | 476 | llvm::Constant *LifetimeEndFn = nullptr; |
Nadav Rotem | 1da3094 | 2013-03-23 06:43:35 +0000 | [diff] [blame] | 477 | |
Fariborz Jahanian | 6362803 | 2012-06-26 16:06:38 +0000 | [diff] [blame] | 478 | GlobalDecl initializedGlobalDecl; |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 479 | |
Alexey Samsonov | 4b8de11 | 2014-08-01 21:35:28 +0000 | [diff] [blame] | 480 | std::unique_ptr<SanitizerMetadata> SanitizerMD; |
| 481 | |
Daniel Dunbar | 900546d | 2010-07-16 00:00:15 +0000 | [diff] [blame] | 482 | /// @} |
Alex Lorenz | ee02499 | 2014-08-04 18:41:51 +0000 | [diff] [blame] | 483 | |
| 484 | llvm::DenseMap<const Decl *, bool> DeferredEmptyCoverageMappingDecls; |
| 485 | |
| 486 | std::unique_ptr<CoverageMappingModuleGen> CoverageMapping; |
Peter Collingbourne | 25a80bf | 2015-09-08 23:01:30 +0000 | [diff] [blame] | 487 | |
| 488 | /// Mapping from canonical types to their metadata identifiers. We need to |
| 489 | /// maintain this mapping because identifiers may be formed from distinct |
| 490 | /// MDNodes. |
| 491 | llvm::DenseMap<QualType, llvm::Metadata *> MetadataIdMap; |
| 492 | |
Chris Lattner | f97fe38 | 2007-05-24 06:29:05 +0000 | [diff] [blame] | 493 | public: |
Mehdi Amini | ca3cf9e | 2015-07-24 16:04:29 +0000 | [diff] [blame] | 494 | CodeGenModule(ASTContext &C, const HeaderSearchOptions &headersearchopts, |
Adrian Prantl | e74f525 | 2015-06-30 02:26:03 +0000 | [diff] [blame] | 495 | const PreprocessorOptions &ppopts, |
Mehdi Amini | ca3cf9e | 2015-07-24 16:04:29 +0000 | [diff] [blame] | 496 | const CodeGenOptions &CodeGenOpts, llvm::Module &M, |
Alex Lorenz | ee02499 | 2014-08-04 18:41:51 +0000 | [diff] [blame] | 497 | DiagnosticsEngine &Diags, |
| 498 | CoverageSourceInfo *CoverageInfo = nullptr); |
Ted Kremenek | 2c674f6 | 2008-08-05 18:50:11 +0000 | [diff] [blame] | 499 | |
Chris Lattner | a087ff9 | 2008-03-01 08:45:05 +0000 | [diff] [blame] | 500 | ~CodeGenModule(); |
Mike Stump | 1676c5b | 2009-02-13 19:12:34 +0000 | [diff] [blame] | 501 | |
Rafael Espindola | c0ff744 | 2013-12-09 14:59:08 +0000 | [diff] [blame] | 502 | void clear(); |
| 503 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 504 | /// Finalize LLVM code generation. |
Ted Kremenek | 2c674f6 | 2008-08-05 18:50:11 +0000 | [diff] [blame] | 505 | void Release(); |
Daniel Dunbar | 8d48059 | 2008-08-11 18:12:00 +0000 | [diff] [blame] | 506 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 507 | /// Return a reference to the configured Objective-C runtime. |
Mike Stump | 1676c5b | 2009-02-13 19:12:34 +0000 | [diff] [blame] | 508 | CGObjCRuntime &getObjCRuntime() { |
Peter Collingbourne | e1d2099 | 2011-07-27 20:29:46 +0000 | [diff] [blame] | 509 | if (!ObjCRuntime) createObjCRuntime(); |
| 510 | return *ObjCRuntime; |
Daniel Dunbar | 8d48059 | 2008-08-11 18:12:00 +0000 | [diff] [blame] | 511 | } |
Mike Stump | 1676c5b | 2009-02-13 19:12:34 +0000 | [diff] [blame] | 512 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 513 | /// Return true iff an Objective-C runtime has been configured. |
Peter Collingbourne | e1d2099 | 2011-07-27 20:29:46 +0000 | [diff] [blame] | 514 | bool hasObjCRuntime() { return !!ObjCRuntime; } |
Daniel Dunbar | 8d48059 | 2008-08-11 18:12:00 +0000 | [diff] [blame] | 515 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 516 | /// Return a reference to the configured OpenCL runtime. |
Peter Collingbourne | 2dbb708 | 2011-09-19 21:14:35 +0000 | [diff] [blame] | 517 | CGOpenCLRuntime &getOpenCLRuntime() { |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 518 | assert(OpenCLRuntime != nullptr); |
Peter Collingbourne | 2dbb708 | 2011-09-19 21:14:35 +0000 | [diff] [blame] | 519 | return *OpenCLRuntime; |
| 520 | } |
| 521 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 522 | /// Return a reference to the configured OpenMP runtime. |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 523 | CGOpenMPRuntime &getOpenMPRuntime() { |
| 524 | assert(OpenMPRuntime != nullptr); |
| 525 | return *OpenMPRuntime; |
| 526 | } |
| 527 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 528 | /// Return a reference to the configured CUDA runtime. |
Peter Collingbourne | fe88342 | 2011-10-06 18:29:37 +0000 | [diff] [blame] | 529 | CGCUDARuntime &getCUDARuntime() { |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 530 | assert(CUDARuntime != nullptr); |
Peter Collingbourne | fe88342 | 2011-10-06 18:29:37 +0000 | [diff] [blame] | 531 | return *CUDARuntime; |
| 532 | } |
| 533 | |
John McCall | b04ecb7 | 2015-10-21 18:06:43 +0000 | [diff] [blame] | 534 | ObjCEntrypoints &getObjCEntrypoints() const { |
| 535 | assert(ObjCData != nullptr); |
| 536 | return *ObjCData; |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 537 | } |
| 538 | |
Justin Bogner | 837a6f6 | 2014-04-18 21:52:00 +0000 | [diff] [blame] | 539 | InstrProfStats &getPGOStats() { return PGOStats; } |
| 540 | llvm::IndexedInstrProfReader *getPGOReader() const { return PGOReader.get(); } |
Justin Bogner | ef512b9 | 2014-01-06 22:27:43 +0000 | [diff] [blame] | 541 | |
Alex Lorenz | ee02499 | 2014-08-04 18:41:51 +0000 | [diff] [blame] | 542 | CoverageMappingModuleGen *getCoverageMapping() const { |
| 543 | return CoverageMapping.get(); |
| 544 | } |
| 545 | |
Eli Friedman | 1c8d2ca | 2012-03-09 03:27:46 +0000 | [diff] [blame] | 546 | llvm::Constant *getStaticLocalDeclAddress(const VarDecl *D) { |
| 547 | return StaticLocalDeclMap[D]; |
Fariborz Jahanian | 3fef72f | 2010-04-18 21:01:23 +0000 | [diff] [blame] | 548 | } |
Fariborz Jahanian | 4d55b2d | 2010-04-19 18:15:02 +0000 | [diff] [blame] | 549 | void setStaticLocalDeclAddress(const VarDecl *D, |
Eli Friedman | 1c8d2ca | 2012-03-09 03:27:46 +0000 | [diff] [blame] | 550 | llvm::Constant *C) { |
| 551 | StaticLocalDeclMap[D] = C; |
Fariborz Jahanian | 3fef72f | 2010-04-18 21:01:23 +0000 | [diff] [blame] | 552 | } |
| 553 | |
Reid Kleckner | 453e056 | 2014-10-08 01:07:54 +0000 | [diff] [blame] | 554 | llvm::Constant * |
| 555 | getOrCreateStaticVarDecl(const VarDecl &D, |
| 556 | llvm::GlobalValue::LinkageTypes Linkage); |
| 557 | |
John McCall | b88a566 | 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 | |
Alp Toker | fb8d02b | 2014-06-05 22:10:59 +0000 | [diff] [blame] | 566 | bool lookupRepresentativeDecl(StringRef MangledName, |
| 567 | GlobalDecl &Result) const; |
| 568 | |
Fariborz Jahanian | 1bed413 | 2012-01-08 19:13:23 +0000 | [diff] [blame] | 569 | llvm::Constant *getAtomicSetterHelperFnMap(QualType Ty) { |
| 570 | return AtomicSetterHelperFnMap[Ty]; |
Fariborz Jahanian | 7ff610b | 2012-01-06 22:33:54 +0000 | [diff] [blame] | 571 | } |
Fariborz Jahanian | 1bed413 | 2012-01-08 19:13:23 +0000 | [diff] [blame] | 572 | void setAtomicSetterHelperFnMap(QualType Ty, |
Fariborz Jahanian | 7ff610b | 2012-01-06 22:33:54 +0000 | [diff] [blame] | 573 | llvm::Constant *Fn) { |
Fariborz Jahanian | 1bed413 | 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 | 7ff610b | 2012-01-06 22:33:54 +0000 | [diff] [blame] | 583 | } |
| 584 | |
Warren Hunt | 5c2b4ea | 2014-05-23 16:07:43 +0000 | [diff] [blame] | 585 | llvm::Constant *getTypeDescriptorFromMap(QualType Ty) { |
Will Dietz | 949ec54 | 2013-11-08 01:09:22 +0000 | [diff] [blame] | 586 | return TypeDescriptorMap[Ty]; |
| 587 | } |
Warren Hunt | 5c2b4ea | 2014-05-23 16:07:43 +0000 | [diff] [blame] | 588 | void setTypeDescriptorInMap(QualType Ty, llvm::Constant *C) { |
Will Dietz | 949ec54 | 2013-11-08 01:09:22 +0000 | [diff] [blame] | 589 | TypeDescriptorMap[Ty] = C; |
| 590 | } |
| 591 | |
Reid Kleckner | 9305fd1 | 2016-04-13 23:37:17 +0000 | [diff] [blame] | 592 | CGDebugInfo *getModuleDebugInfo() { return DebugInfo.get(); } |
Devang Patel | e65982c | 2011-03-07 18:29:53 +0000 | [diff] [blame] | 593 | |
Dan Gohman | 515a60d | 2012-02-16 00:57:37 +0000 | [diff] [blame] | 594 | llvm::MDNode *getNoObjCARCExceptionsMetadata() { |
| 595 | if (!NoObjCARCExceptionsMetadata) |
Duncan P. N. Exon Smith | fb49491 | 2014-12-09 18:39:32 +0000 | [diff] [blame] | 596 | NoObjCARCExceptionsMetadata = llvm::MDNode::get(getLLVMContext(), None); |
Dan Gohman | 515a60d | 2012-02-16 00:57:37 +0000 | [diff] [blame] | 597 | return NoObjCARCExceptionsMetadata; |
| 598 | } |
| 599 | |
Chris Lattner | d1af2d2 | 2007-05-29 23:17:50 +0000 | [diff] [blame] | 600 | ASTContext &getContext() const { return Context; } |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 601 | const LangOptions &getLangOpts() const { return LangOpts; } |
Adrian Prantl | e74f525 | 2015-06-30 02:26:03 +0000 | [diff] [blame] | 602 | const HeaderSearchOptions &getHeaderSearchOpts() |
| 603 | const { return HeaderSearchOpts; } |
| 604 | const PreprocessorOptions &getPreprocessorOpts() |
| 605 | const { return PreprocessorOpts; } |
John McCall | c8e0170 | 2013-04-16 22:48:15 +0000 | [diff] [blame] | 606 | const CodeGenOptions &getCodeGenOpts() const { return CodeGenOpts; } |
Chris Lattner | 23b7eb6 | 2007-06-15 23:05:46 +0000 | [diff] [blame] | 607 | llvm::Module &getModule() const { return TheModule; } |
David Blaikie | 9c902b5 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 608 | DiagnosticsEngine &getDiags() const { return Diags; } |
Mehdi Amini | ca3cf9e | 2015-07-24 16:04:29 +0000 | [diff] [blame] | 609 | const llvm::DataLayout &getDataLayout() const { |
| 610 | return TheModule.getDataLayout(); |
| 611 | } |
John McCall | c8e0170 | 2013-04-16 22:48:15 +0000 | [diff] [blame] | 612 | const TargetInfo &getTarget() const { return Target; } |
Rafael Espindola | 9f83473 | 2014-09-19 01:54:22 +0000 | [diff] [blame] | 613 | const llvm::Triple &getTriple() const; |
| 614 | bool supportsCOMDAT() const; |
Rafael Espindola | dbee8a7 | 2015-01-15 21:36:08 +0000 | [diff] [blame] | 615 | void maybeSetTrivialComdat(const Decl &D, llvm::GlobalObject &GO); |
Rafael Espindola | 9f83473 | 2014-09-19 01:54:22 +0000 | [diff] [blame] | 616 | |
Alp Toker | 8286225 | 2013-12-28 21:58:40 +0000 | [diff] [blame] | 617 | CGCXXABI &getCXXABI() const { return *ABI; } |
Owen Anderson | 170229f | 2009-07-14 23:10:40 +0000 | [diff] [blame] | 618 | llvm::LLVMContext &getLLVMContext() { return VMContext; } |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 619 | |
| 620 | bool shouldUseTBAA() const { return TBAA != nullptr; } |
John McCall | 53fcbd2 | 2011-02-26 08:07:02 +0000 | [diff] [blame] | 621 | |
John McCall | c8e0170 | 2013-04-16 22:48:15 +0000 | [diff] [blame] | 622 | const TargetCodeGenInfo &getTargetCodeGenInfo(); |
| 623 | |
| 624 | CodeGenTypes &getTypes() { return Types; } |
| 625 | |
| 626 | CodeGenVTables &getVTables() { return VTables; } |
Timur Iskhodzhanov | 88fd439 | 2013-08-21 06:25:03 +0000 | [diff] [blame] | 627 | |
Timur Iskhodzhanov | 5877663 | 2013-11-05 15:54:58 +0000 | [diff] [blame] | 628 | ItaniumVTableContext &getItaniumVTableContext() { |
| 629 | return VTables.getItaniumVTableContext(); |
Timur Iskhodzhanov | e1ebc5f | 2013-10-09 11:33:51 +0000 | [diff] [blame] | 630 | } |
John McCall | c8e0170 | 2013-04-16 22:48:15 +0000 | [diff] [blame] | 631 | |
Timur Iskhodzhanov | 5877663 | 2013-11-05 15:54:58 +0000 | [diff] [blame] | 632 | MicrosoftVTableContext &getMicrosoftVTableContext() { |
| 633 | return VTables.getMicrosoftVTableContext(); |
Timur Iskhodzhanov | 88fd439 | 2013-08-21 06:25:03 +0000 | [diff] [blame] | 634 | } |
| 635 | |
Keno Fischer | 76f4ab0 | 2014-12-30 08:12:39 +0000 | [diff] [blame] | 636 | CtorList &getGlobalCtors() { return GlobalCtors; } |
| 637 | CtorList &getGlobalDtors() { return GlobalDtors; } |
| 638 | |
Dan Gohman | 947c9af | 2010-10-14 23:06:10 +0000 | [diff] [blame] | 639 | llvm::MDNode *getTBAAInfo(QualType QTy); |
Kostya Serebryany | 141e46f | 2012-03-26 17:03:51 +0000 | [diff] [blame] | 640 | llvm::MDNode *getTBAAInfoForVTablePtr(); |
Dan Gohman | 22695fc | 2012-09-28 21:58:29 +0000 | [diff] [blame] | 641 | llvm::MDNode *getTBAAStructInfo(QualType QTy); |
Manman Ren | c451e57 | 2013-04-04 21:53:22 +0000 | [diff] [blame] | 642 | /// Return the path-aware tag for given base type, access node and offset. |
| 643 | llvm::MDNode *getTBAAStructTagInfo(QualType BaseTy, llvm::MDNode *AccessN, |
| 644 | uint64_t O); |
Dan Gohman | 947c9af | 2010-10-14 23:06:10 +0000 | [diff] [blame] | 645 | |
Richard Smith | e070fd2 | 2012-02-17 06:48:11 +0000 | [diff] [blame] | 646 | bool isTypeConstant(QualType QTy, bool ExcludeCtorDtor); |
| 647 | |
John McCall | a8ec7eb | 2013-03-07 21:37:17 +0000 | [diff] [blame] | 648 | bool isPaddedAtomicType(QualType type); |
| 649 | bool isPaddedAtomicType(const AtomicType *type); |
| 650 | |
Manman Ren | e1ad74e | 2013-04-11 23:02:56 +0000 | [diff] [blame] | 651 | /// Decorate the instruction with a TBAA tag. For scalar TBAA, the tag |
| 652 | /// is the same as the type. For struct-path aware TBAA, the tag |
| 653 | /// is different from the type: base type, access type and offset. |
| 654 | /// When ConvertTypeToTag is true, we create a tag based on the scalar type. |
Piotr Padlewski | 4b1ac72 | 2015-09-15 21:46:55 +0000 | [diff] [blame] | 655 | void DecorateInstructionWithTBAA(llvm::Instruction *Inst, |
| 656 | llvm::MDNode *TBAAInfo, |
| 657 | bool ConvertTypeToTag = true); |
| 658 | |
| 659 | /// Adds !invariant.barrier !tag to instruction |
| 660 | void DecorateInstructionWithInvariantGroup(llvm::Instruction *I, |
| 661 | const CXXRecordDecl *RD); |
Dan Gohman | 947c9af | 2010-10-14 23:06:10 +0000 | [diff] [blame] | 662 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 663 | /// Emit the given number of characters as a value of type size_t. |
John McCall | 23c29fe | 2011-06-24 21:55:10 +0000 | [diff] [blame] | 664 | llvm::ConstantInt *getSize(CharUnits numChars); |
| 665 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 666 | /// Set the visibility for the given LLVM GlobalValue. |
Anders Carlsson | c6a4789 | 2011-01-29 19:39:23 +0000 | [diff] [blame] | 667 | void setGlobalVisibility(llvm::GlobalValue *GV, const NamedDecl *D) const; |
Daniel Dunbar | f5f359f | 2009-04-14 06:00:08 +0000 | [diff] [blame] | 668 | |
David Majnemer | bb525f7c | 2014-10-15 22:38:23 +0000 | [diff] [blame] | 669 | /// Set the TLS mode for the given LLVM GlobalValue for the thread-local |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 670 | /// variable declaration D. |
David Majnemer | bb525f7c | 2014-10-15 22:38:23 +0000 | [diff] [blame] | 671 | void setTLSMode(llvm::GlobalValue *GV, const VarDecl &D) const; |
Hans Wennborg | f60f6af | 2012-06-28 08:01:44 +0000 | [diff] [blame] | 672 | |
Anders Carlsson | 537fdce | 2011-01-29 20:59:35 +0000 | [diff] [blame] | 673 | static llvm::GlobalValue::VisibilityTypes GetLLVMVisibility(Visibility V) { |
| 674 | switch (V) { |
| 675 | case DefaultVisibility: return llvm::GlobalValue::DefaultVisibility; |
| 676 | case HiddenVisibility: return llvm::GlobalValue::HiddenVisibility; |
| 677 | case ProtectedVisibility: return llvm::GlobalValue::ProtectedVisibility; |
| 678 | } |
| 679 | llvm_unreachable("unknown visibility!"); |
Anders Carlsson | 537fdce | 2011-01-29 20:59:35 +0000 | [diff] [blame] | 680 | } |
| 681 | |
Andrey Bokhanko | cab5858 | 2015-08-31 13:20:44 +0000 | [diff] [blame] | 682 | llvm::Constant *GetAddrOfGlobal(GlobalDecl GD, bool IsForDefinition = false); |
John McCall | d432414 | 2010-02-19 01:32:20 +0000 | [diff] [blame] | 683 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 684 | /// Will return a global variable of the given type. If a variable with a |
| 685 | /// different type already exists then a new variable with the right type |
| 686 | /// will be created and all uses of the old variable will be replaced with a |
| 687 | /// bitcast to the new variable. |
Anders Carlsson | da80af3 | 2011-01-29 18:20:20 +0000 | [diff] [blame] | 688 | llvm::GlobalVariable * |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 689 | CreateOrReplaceCXXRuntimeVariable(StringRef Name, llvm::Type *Ty, |
Anders Carlsson | da80af3 | 2011-01-29 18:20:20 +0000 | [diff] [blame] | 690 | llvm::GlobalValue::LinkageTypes Linkage); |
| 691 | |
Alexey Samsonov | 1444bb9 | 2014-10-17 00:20:19 +0000 | [diff] [blame] | 692 | llvm::Function * |
| 693 | CreateGlobalInitOrDestructFunction(llvm::FunctionType *ty, const Twine &name, |
Akira Hatanaka | 7791f1a4 | 2015-10-31 01:28:07 +0000 | [diff] [blame] | 694 | const CGFunctionInfo &FI, |
Alexey Samsonov | 1444bb9 | 2014-10-17 00:20:19 +0000 | [diff] [blame] | 695 | SourceLocation Loc = SourceLocation(), |
| 696 | bool TLS = false); |
David Majnemer | b3341ea | 2014-10-05 05:05:40 +0000 | [diff] [blame] | 697 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 698 | /// Return the address space of the underlying global variable for D, as |
| 699 | /// determined by its declaration. Normally this is the same as the address |
| 700 | /// space of D's type, but in CUDA, address spaces are associated with |
| 701 | /// declarations, not types. |
Peter Collingbourne | f44bdf9 | 2012-05-20 21:08:35 +0000 | [diff] [blame] | 702 | unsigned GetGlobalVarAddressSpace(const VarDecl *D, unsigned AddrSpace); |
| 703 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 704 | /// Return the llvm::Constant for the address of the given global variable. |
Andrey Bokhanko | 7aa88ce | 2016-01-14 10:41:16 +0000 | [diff] [blame] | 705 | /// If Ty is non-null and if the global doesn't exist, then it will be created |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 706 | /// with the specified type instead of whatever the normal requested type |
Andrey Bokhanko | 7aa88ce | 2016-01-14 10:41:16 +0000 | [diff] [blame] | 707 | /// would be. If IsForDefinition is true, it is guranteed that an actual |
| 708 | /// global with type Ty will be returned, not conversion of a variable with |
| 709 | /// the same mangled name but some other type. |
Chris Lattner | 149927c | 2009-03-21 09:16:30 +0000 | [diff] [blame] | 710 | llvm::Constant *GetAddrOfGlobalVar(const VarDecl *D, |
Andrey Bokhanko | 7aa88ce | 2016-01-14 10:41:16 +0000 | [diff] [blame] | 711 | llvm::Type *Ty = nullptr, |
| 712 | bool IsForDefinition = false); |
Daniel Dunbar | 9c42652 | 2008-07-29 23:18:29 +0000 | [diff] [blame] | 713 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 714 | /// Return the address of the given function. If Ty is non-null, then this |
| 715 | /// function will use the specified type if it has to create it. |
Hans Wennborg | 59dbe86 | 2015-09-29 20:56:43 +0000 | [diff] [blame] | 716 | llvm::Constant *GetAddrOfFunction(GlobalDecl GD, llvm::Type *Ty = nullptr, |
Rafael Espindola | 94abb8f | 2013-12-09 04:29:47 +0000 | [diff] [blame] | 717 | bool ForVTable = false, |
Andrey Bokhanko | cab5858 | 2015-08-31 13:20:44 +0000 | [diff] [blame] | 718 | bool DontDefer = false, |
| 719 | bool IsForDefinition = false); |
Daniel Dunbar | c4baa06 | 2008-08-13 23:20:05 +0000 | [diff] [blame] | 720 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 721 | /// Get the address of the RTTI descriptor for the given type. |
John McCall | 48bf349 | 2010-04-30 01:15:21 +0000 | [diff] [blame] | 722 | llvm::Constant *GetAddrOfRTTIDescriptor(QualType Ty, bool ForEH = false); |
Anders Carlsson | fd7dfeb | 2009-12-11 02:46:30 +0000 | [diff] [blame] | 723 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 724 | /// Get the address of a uuid descriptor . |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 725 | ConstantAddress GetAddrOfUuidDescriptor(const CXXUuidofExpr* E); |
Nico Weber | cf4ff586 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 726 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 727 | /// Get the address of the thunk for the given global decl. |
Anders Carlsson | fe8a993 | 2011-02-06 17:15:43 +0000 | [diff] [blame] | 728 | llvm::Constant *GetAddrOfThunk(GlobalDecl GD, const ThunkInfo &Thunk); |
Anders Carlsson | cd836f0 | 2010-03-23 17:17:29 +0000 | [diff] [blame] | 729 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 730 | /// Get a reference to the target of VD. |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 731 | ConstantAddress GetWeakRefReference(const ValueDecl *VD); |
| 732 | |
| 733 | /// Returns the assumed alignment of an opaque pointer to the given class. |
| 734 | CharUnits getClassPointerAlignment(const CXXRecordDecl *CD); |
| 735 | |
| 736 | /// Returns the assumed alignment of a virtual base of a class. |
| 737 | CharUnits getVBaseAlignment(CharUnits DerivedAlign, |
| 738 | const CXXRecordDecl *Derived, |
| 739 | const CXXRecordDecl *VBase); |
| 740 | |
| 741 | /// Given a class pointer with an actual known alignment, and the |
| 742 | /// expected alignment of an object at a dynamic offset w.r.t that |
| 743 | /// pointer, return the alignment to assume at the offset. |
| 744 | CharUnits getDynamicOffsetAlignment(CharUnits ActualAlign, |
| 745 | const CXXRecordDecl *Class, |
| 746 | CharUnits ExpectedTargetAlign); |
Rafael Espindola | 2e42fec | 2010-03-04 18:17:24 +0000 | [diff] [blame] | 747 | |
David Majnemer | c1709d3 | 2015-06-23 07:31:11 +0000 | [diff] [blame] | 748 | CharUnits |
| 749 | computeNonVirtualBaseClassOffset(const CXXRecordDecl *DerivedClass, |
| 750 | CastExpr::path_const_iterator Start, |
| 751 | CastExpr::path_const_iterator End); |
| 752 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 753 | /// Returns the offset from a derived class to a class. Returns null if the |
| 754 | /// offset is 0. |
Anders Carlsson | 8a64c1c | 2010-04-24 21:23:59 +0000 | [diff] [blame] | 755 | llvm::Constant * |
| 756 | GetNonVirtualBaseClassOffset(const CXXRecordDecl *ClassDecl, |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 757 | CastExpr::path_const_iterator PathBegin, |
| 758 | CastExpr::path_const_iterator PathEnd); |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 759 | |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 760 | llvm::FoldingSet<BlockByrefHelpers> ByrefHelpersCache; |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 761 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 762 | /// Fetches the global unique block count. |
John McCall | 147d021 | 2011-02-22 22:38:33 +0000 | [diff] [blame] | 763 | int getUniqueBlockCount() { return ++Block.GlobalUniqueCount; } |
Fariborz Jahanian | 6362803 | 2012-06-26 16:06:38 +0000 | [diff] [blame] | 764 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 765 | /// Fetches the type of a generic block descriptor. |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 766 | llvm::Type *getBlockDescriptorType(); |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 767 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 768 | /// The type of a generic block literal. |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 769 | llvm::Type *getGenericBlockLiteralType(); |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 770 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 771 | /// Gets the address of a block which requires no captures. |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 772 | llvm::Constant *GetAddrOfGlobalBlock(const BlockExpr *BE, const char *); |
Anders Carlsson | 8a64c1c | 2010-04-24 21:23:59 +0000 | [diff] [blame] | 773 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 774 | /// Return a pointer to a constant CFString object for the given string. |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 775 | ConstantAddress GetAddrOfConstantCFString(const StringLiteral *Literal); |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 776 | |
| 777 | /// Return a pointer to a constant NSString object for the given string. Or a |
| 778 | /// user defined String object as defined via |
Fariborz Jahanian | 50c925f | 2010-10-19 17:19:29 +0000 | [diff] [blame] | 779 | /// -fconstant-string-class=class_name option. |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 780 | ConstantAddress GetAddrOfConstantString(const StringLiteral *Literal); |
Chris Lattner | 36fc879 | 2008-02-11 00:02:17 +0000 | [diff] [blame] | 781 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 782 | /// Return a constant array for the given string. |
Eli Friedman | fcec630 | 2011-11-01 02:23:42 +0000 | [diff] [blame] | 783 | llvm::Constant *GetConstantArrayFromStringLiteral(const StringLiteral *E); |
| 784 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 785 | /// Return a pointer to a constant array for the given string literal. |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 786 | ConstantAddress |
Alexey Bataev | ec47478 | 2014-10-09 08:45:04 +0000 | [diff] [blame] | 787 | GetAddrOfConstantStringFromLiteral(const StringLiteral *S, |
| 788 | StringRef Name = ".str"); |
Daniel Dunbar | 6dfdf8c | 2008-08-10 20:25:57 +0000 | [diff] [blame] | 789 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 790 | /// Return a pointer to a constant array for the given ObjCEncodeExpr node. |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 791 | ConstantAddress |
Alexey Samsonov | b2cc23d | 2014-07-10 22:18:36 +0000 | [diff] [blame] | 792 | GetAddrOfConstantStringFromObjCEncode(const ObjCEncodeExpr *); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 793 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 794 | /// Returns a pointer to a character array containing the literal and a |
| 795 | /// terminating '\0' character. The result has pointer to array type. |
Daniel Dunbar | dfcf599 | 2008-10-17 21:56:50 +0000 | [diff] [blame] | 796 | /// |
Mike Stump | 1676c5b | 2009-02-13 19:12:34 +0000 | [diff] [blame] | 797 | /// \param GlobalName If provided, the name to use for the global (if one is |
| 798 | /// created). |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 799 | ConstantAddress |
Alexey Samsonov | b2cc23d | 2014-07-10 22:18:36 +0000 | [diff] [blame] | 800 | GetAddrOfConstantCString(const std::string &Str, |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 801 | const char *GlobalName = nullptr); |
Richard Smith | 2d988f0 | 2011-11-22 22:48:32 +0000 | [diff] [blame] | 802 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 803 | /// Returns a pointer to a constant global variable for the given file-scope |
| 804 | /// compound literal expression. |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 805 | ConstantAddress GetAddrOfConstantCompoundLiteral(const CompoundLiteralExpr*E); |
Richard Smith | e6c0144 | 2013-06-05 00:46:14 +0000 | [diff] [blame] | 806 | |
| 807 | /// \brief Returns a pointer to a global variable representing a temporary |
| 808 | /// with static or thread storage duration. |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 809 | ConstantAddress GetAddrOfGlobalTemporary(const MaterializeTemporaryExpr *E, |
Richard Smith | e6c0144 | 2013-06-05 00:46:14 +0000 | [diff] [blame] | 810 | const Expr *Inner); |
| 811 | |
Douglas Gregor | 636e200 | 2011-08-09 17:23:49 +0000 | [diff] [blame] | 812 | /// \brief Retrieve the record type that describes the state of an |
| 813 | /// Objective-C fast enumeration loop (for..in). |
| 814 | QualType getObjCFastEnumerationStateType(); |
Rafael Espindola | 8d2a19b | 2014-09-08 16:01:27 +0000 | [diff] [blame] | 815 | |
Rafael Espindola | 5368618 | 2014-09-15 19:34:18 +0000 | [diff] [blame] | 816 | // Produce code for this constructor/destructor. This method doesn't try |
| 817 | // to apply any ABI rules about which other constructors/destructors |
| 818 | // are needed or if they are alias to each other. |
| 819 | llvm::Function *codegenCXXStructor(const CXXMethodDecl *MD, |
| 820 | StructorType Type); |
| 821 | |
Rafael Espindola | 1ac0ec8 | 2014-09-11 15:42:06 +0000 | [diff] [blame] | 822 | /// Return the address of the constructor/destructor of the given type. |
Andrey Bokhanko | cab5858 | 2015-08-31 13:20:44 +0000 | [diff] [blame] | 823 | llvm::Constant * |
Rafael Espindola | 8d2a19b | 2014-09-08 16:01:27 +0000 | [diff] [blame] | 824 | getAddrOfCXXStructor(const CXXMethodDecl *MD, StructorType Type, |
| 825 | const CGFunctionInfo *FnInfo = nullptr, |
| 826 | llvm::FunctionType *FnType = nullptr, |
Andrey Bokhanko | cab5858 | 2015-08-31 13:20:44 +0000 | [diff] [blame] | 827 | bool DontDefer = false, bool IsForDefinition = false); |
Rafael Espindola | 8d2a19b | 2014-09-08 16:01:27 +0000 | [diff] [blame] | 828 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 829 | /// Given a builtin id for a function like "__builtin_fabsf", return a |
| 830 | /// Function* for "fabsf". |
Daniel Dunbar | ff0553e | 2009-09-14 04:33:21 +0000 | [diff] [blame] | 831 | llvm::Value *getBuiltinLibFunction(const FunctionDecl *FD, |
| 832 | unsigned BuiltinID); |
Daniel Dunbar | c4baa06 | 2008-08-13 23:20:05 +0000 | [diff] [blame] | 833 | |
Dmitri Gribenko | 44ebbd5 | 2013-05-05 00:41:58 +0000 | [diff] [blame] | 834 | llvm::Function *getIntrinsic(unsigned IID, ArrayRef<llvm::Type*> Tys = None); |
Daniel Dunbar | 9c42652 | 2008-07-29 23:18:29 +0000 | [diff] [blame] | 835 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 836 | /// Emit code for a single top level declaration. |
Daniel Dunbar | fce4be8 | 2008-08-15 23:26:23 +0000 | [diff] [blame] | 837 | void EmitTopLevelDecl(Decl *D); |
Daniel Dunbar | 9c42652 | 2008-07-29 23:18:29 +0000 | [diff] [blame] | 838 | |
Alex Lorenz | ee02499 | 2014-08-04 18:41:51 +0000 | [diff] [blame] | 839 | /// \brief Stored a deferred empty coverage mapping for an unused |
| 840 | /// and thus uninstrumented top level declaration. |
| 841 | void AddDeferredUnusedCoverageMapping(Decl *D); |
| 842 | |
| 843 | /// \brief Remove the deferred empty coverage mapping as this |
| 844 | /// declaration is actually instrumented. |
| 845 | void ClearUnusedCoverageMapping(const Decl *D); |
| 846 | |
| 847 | /// \brief Emit all the deferred coverage mappings |
| 848 | /// for the uninstrumented functions. |
| 849 | void EmitDeferredUnusedCoverageMappings(); |
| 850 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 851 | /// Tell the consumer that this variable has been instantiated. |
Rafael Espindola | df88f6f | 2012-03-08 15:51:03 +0000 | [diff] [blame] | 852 | void HandleCXXStaticMemberVarInstantiation(VarDecl *VD); |
Rafael Espindola | 189fa74 | 2012-03-05 10:54:55 +0000 | [diff] [blame] | 853 | |
Richard Smith | df931ce | 2013-04-06 05:00:46 +0000 | [diff] [blame] | 854 | /// \brief If the declaration has internal linkage but is inside an |
| 855 | /// extern "C" linkage specification, prepare to emit an alias for it |
| 856 | /// to the expected name. |
| 857 | template<typename SomeDecl> |
| 858 | void MaybeHandleStaticInExternC(const SomeDecl *D, llvm::GlobalValue *GV); |
| 859 | |
Rafael Espindola | 060062a | 2014-03-06 22:15:10 +0000 | [diff] [blame] | 860 | /// Add a global to a list to be added to the llvm.used metadata. |
| 861 | void addUsedGlobal(llvm::GlobalValue *GV); |
| 862 | |
| 863 | /// Add a global to a list to be added to the llvm.compiler.used metadata. |
| 864 | void addCompilerUsedGlobal(llvm::GlobalValue *GV); |
Daniel Dunbar | 08b26a0 | 2009-02-13 20:29:50 +0000 | [diff] [blame] | 865 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 866 | /// Add a destructor and object to add to the C++ global destructor function. |
Chris Lattner | 87233f7 | 2010-06-19 05:52:45 +0000 | [diff] [blame] | 867 | void AddCXXDtorEntry(llvm::Constant *DtorFn, llvm::Constant *Object) { |
Benjamin Kramer | 3204b15 | 2015-05-29 19:42:19 +0000 | [diff] [blame] | 868 | CXXGlobalDtors.emplace_back(DtorFn, Object); |
Chris Lattner | 87233f7 | 2010-06-19 05:52:45 +0000 | [diff] [blame] | 869 | } |
Daniel Dunbar | fe06df4 | 2010-03-20 04:15:41 +0000 | [diff] [blame] | 870 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 871 | /// Create a new runtime function with the specified type and name. |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 872 | llvm::Constant *CreateRuntimeFunction(llvm::FunctionType *Ty, |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 873 | StringRef Name, |
Bill Wendling | 8594fcb | 2013-01-31 00:30:05 +0000 | [diff] [blame] | 874 | llvm::AttributeSet ExtraAttrs = |
| 875 | llvm::AttributeSet()); |
Anton Korobeynikov | d90dd79 | 2014-12-02 16:04:58 +0000 | [diff] [blame] | 876 | /// Create a new compiler builtin function with the specified type and name. |
| 877 | llvm::Constant *CreateBuiltinFunction(llvm::FunctionType *Ty, |
| 878 | StringRef Name, |
| 879 | llvm::AttributeSet ExtraAttrs = |
| 880 | llvm::AttributeSet()); |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 881 | /// Create a new runtime global variable with the specified type and name. |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 882 | llvm::Constant *CreateRuntimeVariable(llvm::Type *Ty, |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 883 | StringRef Name); |
Daniel Dunbar | 23fd462 | 2008-10-01 00:49:24 +0000 | [diff] [blame] | 884 | |
Daniel Dunbar | 900546d | 2010-07-16 00:00:15 +0000 | [diff] [blame] | 885 | ///@name Custom Blocks Runtime Interfaces |
| 886 | ///@{ |
| 887 | |
| 888 | llvm::Constant *getNSConcreteGlobalBlock(); |
| 889 | llvm::Constant *getNSConcreteStackBlock(); |
| 890 | llvm::Constant *getBlockObjectAssign(); |
| 891 | llvm::Constant *getBlockObjectDispose(); |
| 892 | |
| 893 | ///@} |
| 894 | |
Nadav Rotem | 1da3094 | 2013-03-23 06:43:35 +0000 | [diff] [blame] | 895 | llvm::Constant *getLLVMLifetimeStartFn(); |
| 896 | llvm::Constant *getLLVMLifetimeEndFn(); |
| 897 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 898 | // Make sure that this type is translated. |
Devang Patel | 945b8ae | 2011-03-23 16:29:39 +0000 | [diff] [blame] | 899 | void UpdateCompletedType(const TagDecl *TD); |
Daniel Dunbar | 38ad1e6 | 2009-02-17 18:43:32 +0000 | [diff] [blame] | 900 | |
John McCall | f3a8860 | 2011-02-03 08:15:49 +0000 | [diff] [blame] | 901 | llvm::Constant *getMemberPointerConstant(const UnaryOperator *e); |
| 902 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 903 | /// Try to emit the initializer for the given declaration as a constant; |
| 904 | /// returns 0 if the expression cannot be emitted as a constant. |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 905 | llvm::Constant *EmitConstantInit(const VarDecl &D, |
| 906 | CodeGenFunction *CGF = nullptr); |
Richard Smith | dafff94 | 2012-01-14 04:30:29 +0000 | [diff] [blame] | 907 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 908 | /// Try to emit the given expression as a constant; returns 0 if the |
| 909 | /// expression cannot be emitted as a constant. |
Anders Carlsson | 80f97ab | 2009-04-08 04:48:15 +0000 | [diff] [blame] | 910 | llvm::Constant *EmitConstantExpr(const Expr *E, QualType DestType, |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 911 | CodeGenFunction *CGF = nullptr); |
Daniel Dunbar | 38ad1e6 | 2009-02-17 18:43:32 +0000 | [diff] [blame] | 912 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 913 | /// Emit the given constant value as a constant, in the type's scalar |
| 914 | /// representation. |
Richard Smith | dafff94 | 2012-01-14 04:30:29 +0000 | [diff] [blame] | 915 | llvm::Constant *EmitConstantValue(const APValue &Value, QualType DestType, |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 916 | CodeGenFunction *CGF = nullptr); |
Richard Smith | dafff94 | 2012-01-14 04:30:29 +0000 | [diff] [blame] | 917 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 918 | /// Emit the given constant value as a constant, in the type's memory |
| 919 | /// representation. |
Richard Smith | bc638767 | 2012-03-02 23:27:11 +0000 | [diff] [blame] | 920 | llvm::Constant *EmitConstantValueForMemory(const APValue &Value, |
| 921 | QualType DestType, |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 922 | CodeGenFunction *CGF = nullptr); |
Richard Smith | bc638767 | 2012-03-02 23:27:11 +0000 | [diff] [blame] | 923 | |
Alexey Bataev | 2bf9b4c | 2015-10-20 04:24:12 +0000 | [diff] [blame] | 924 | /// \brief Emit type info if type of an expression is a variably modified |
| 925 | /// type. Also emit proper debug info for cast types. |
| 926 | void EmitExplicitCastExprType(const ExplicitCastExpr *E, |
| 927 | CodeGenFunction *CGF = nullptr); |
| 928 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 929 | /// Return the result of value-initializing the given type, i.e. a null |
| 930 | /// expression of the given type. This is usually, but not always, an LLVM |
| 931 | /// null constant. |
Eli Friedman | 20bb5e0 | 2009-04-13 21:47:26 +0000 | [diff] [blame] | 932 | llvm::Constant *EmitNullConstant(QualType T); |
| 933 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 934 | /// Return a null constant appropriate for zero-initializing a base class with |
| 935 | /// the given type. This is usually, but not always, an LLVM null constant. |
Eli Friedman | fde961d | 2011-10-14 02:27:24 +0000 | [diff] [blame] | 936 | llvm::Constant *EmitNullConstantForBase(const CXXRecordDecl *Record); |
| 937 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 938 | /// Emit a general error that something can't be done. |
Chandler Carruth | 8453795 | 2012-03-30 19:44:53 +0000 | [diff] [blame] | 939 | void Error(SourceLocation loc, StringRef error); |
John McCall | 7ef5cb3 | 2011-03-18 02:56:14 +0000 | [diff] [blame] | 940 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 941 | /// Print out an error that codegen doesn't support the specified stmt yet. |
David Blaikie | 4a9ec7b | 2013-08-19 21:02:26 +0000 | [diff] [blame] | 942 | void ErrorUnsupported(const Stmt *S, const char *Type); |
Mike Stump | 1676c5b | 2009-02-13 19:12:34 +0000 | [diff] [blame] | 943 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 944 | /// Print out an error that codegen doesn't support the specified decl yet. |
David Blaikie | 4a9ec7b | 2013-08-19 21:02:26 +0000 | [diff] [blame] | 945 | void ErrorUnsupported(const Decl *D, const char *Type); |
Dan Gohman | 75d69da | 2008-05-22 00:50:06 +0000 | [diff] [blame] | 946 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 947 | /// Set the attributes on the LLVM function for the given decl and function |
| 948 | /// info. This applies attributes necessary for handling the ABI as well as |
| 949 | /// user specified attributes like section. |
Daniel Dunbar | c3e7cff | 2009-04-17 00:48:04 +0000 | [diff] [blame] | 950 | void SetInternalFunctionAttributes(const Decl *D, llvm::Function *F, |
| 951 | const CGFunctionInfo &FI); |
Daniel Dunbar | 449a339 | 2008-09-04 23:41:35 +0000 | [diff] [blame] | 952 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 953 | /// Set the LLVM function attributes (sext, zext, etc). |
Daniel Dunbar | aeddffc | 2009-04-14 07:08:30 +0000 | [diff] [blame] | 954 | void SetLLVMFunctionAttributes(const Decl *D, |
| 955 | const CGFunctionInfo &Info, |
| 956 | llvm::Function *F); |
Daniel Dunbar | c68897d | 2008-09-10 00:41:16 +0000 | [diff] [blame] | 957 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 958 | /// Set the LLVM function attributes which only apply to a function |
James Dennett | 64fa123 | 2014-08-15 20:04:40 +0000 | [diff] [blame] | 959 | /// definition. |
Daniel Dunbar | 3893257 | 2009-04-14 08:05:55 +0000 | [diff] [blame] | 960 | void SetLLVMFunctionAttributesForDefinition(const Decl *D, llvm::Function *F); |
| 961 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 962 | /// Return true iff the given type uses 'sret' when used as a return type. |
Daniel Dunbar | 6f2e839 | 2010-07-14 23:39:36 +0000 | [diff] [blame] | 963 | bool ReturnTypeUsesSRet(const CGFunctionInfo &FI); |
| 964 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 965 | /// Return true iff the given type uses an argument slot when 'sret' is used |
| 966 | /// as a return type. |
Tim Northover | e77cc39 | 2014-03-29 13:28:05 +0000 | [diff] [blame] | 967 | bool ReturnSlotInterferesWithArgs(const CGFunctionInfo &FI); |
| 968 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 969 | /// Return true iff the given type uses 'fpret' when used as a return type. |
Daniel Dunbar | 6f2e839 | 2010-07-14 23:39:36 +0000 | [diff] [blame] | 970 | bool ReturnTypeUsesFPRet(QualType ResultType); |
Daniel Dunbar | c68897d | 2008-09-10 00:41:16 +0000 | [diff] [blame] | 971 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 972 | /// Return true iff the given type uses 'fp2ret' when used as a return type. |
Anders Carlsson | 2f1a6c3 | 2011-10-31 16:27:11 +0000 | [diff] [blame] | 973 | bool ReturnTypeUsesFP2Ret(QualType ResultType); |
| 974 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 975 | /// Get the LLVM attributes and calling convention to use for a particular |
| 976 | /// function type. |
Daniel Dunbar | 0ef3479 | 2009-09-12 00:59:20 +0000 | [diff] [blame] | 977 | /// |
Chad Rosier | 7dbc9cf | 2016-01-06 14:35:46 +0000 | [diff] [blame] | 978 | /// \param Name - The function name. |
Daniel Dunbar | 0ef3479 | 2009-09-12 00:59:20 +0000 | [diff] [blame] | 979 | /// \param Info - The function type information. |
Samuel Antao | 798f11c | 2015-11-23 22:04:44 +0000 | [diff] [blame] | 980 | /// \param CalleeInfo - The callee information these attributes are being |
| 981 | /// constructed for. If valid, the attributes applied to this decl may |
| 982 | /// contribute to the function attributes and calling convention. |
Daniel Dunbar | 0ef3479 | 2009-09-12 00:59:20 +0000 | [diff] [blame] | 983 | /// \param PAL [out] - On return, the attribute list to use. |
| 984 | /// \param CallingConv [out] - On return, the LLVM calling convention to use. |
Chad Rosier | 7dbc9cf | 2016-01-06 14:35:46 +0000 | [diff] [blame] | 985 | void ConstructAttributeList(StringRef Name, const CGFunctionInfo &Info, |
Samuel Antao | 798f11c | 2015-11-23 22:04:44 +0000 | [diff] [blame] | 986 | CGCalleeInfo CalleeInfo, AttributeListType &PAL, |
| 987 | unsigned &CallingConv, bool AttrOnCallSite); |
Daniel Dunbar | c68897d | 2008-09-10 00:41:16 +0000 | [diff] [blame] | 988 | |
Eric Christopher | 2b90a64 | 2015-11-11 23:05:08 +0000 | [diff] [blame] | 989 | // Fills in the supplied string map with the set of target features for the |
| 990 | // passed in function. |
| 991 | void getFunctionFeatureMap(llvm::StringMap<bool> &FeatureMap, |
| 992 | const FunctionDecl *FD); |
| 993 | |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 994 | StringRef getMangledName(GlobalDecl GD); |
Alp Toker | fb8d02b | 2014-06-05 22:10:59 +0000 | [diff] [blame] | 995 | StringRef getBlockMangledName(GlobalDecl GD, const BlockDecl *BD); |
Douglas Gregor | beecd58 | 2009-04-21 17:11:58 +0000 | [diff] [blame] | 996 | |
| 997 | void EmitTentativeDefinition(const VarDecl *D); |
Mike Stump | bc78a72 | 2009-07-31 18:25:34 +0000 | [diff] [blame] | 998 | |
Nico Weber | b6a5d05 | 2015-01-15 04:07:35 +0000 | [diff] [blame] | 999 | void EmitVTable(CXXRecordDecl *Class); |
Douglas Gregor | 88d292c | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 1000 | |
David Majnemer | 929025d | 2016-01-26 19:30:26 +0000 | [diff] [blame] | 1001 | void RefreshTypeCacheForClass(const CXXRecordDecl *Class); |
| 1002 | |
Reid Kleckner | e43f0fe | 2013-05-08 13:44:39 +0000 | [diff] [blame] | 1003 | /// \brief Appends Opts to the "Linker Options" metadata value. |
| 1004 | void AppendLinkerOptions(StringRef Opts); |
| 1005 | |
Benjamin Kramer | 82dfc97 | 2013-06-04 09:13:21 +0000 | [diff] [blame] | 1006 | /// \brief Appends a detect mismatch command to the linker options. |
Aaron Ballman | 5d041be | 2013-06-04 02:07:14 +0000 | [diff] [blame] | 1007 | void AddDetectMismatch(StringRef Name, StringRef Value); |
| 1008 | |
Reid Kleckner | e43f0fe | 2013-05-08 13:44:39 +0000 | [diff] [blame] | 1009 | /// \brief Appends a dependent lib to the "Linker Options" metadata value. |
| 1010 | void AddDependentLib(StringRef Lib); |
| 1011 | |
Peter Collingbourne | 4d90dba | 2013-06-05 17:49:37 +0000 | [diff] [blame] | 1012 | llvm::GlobalVariable::LinkageTypes getFunctionLinkage(GlobalDecl GD); |
John McCall | d432414 | 2010-02-19 01:32:20 +0000 | [diff] [blame] | 1013 | |
Rafael Espindola | 6492636 | 2014-05-08 14:46:46 +0000 | [diff] [blame] | 1014 | void setFunctionLinkage(GlobalDecl GD, llvm::Function *F) { |
| 1015 | F->setLinkage(getFunctionLinkage(GD)); |
John McCall | 7cb0220 | 2010-05-25 04:30:21 +0000 | [diff] [blame] | 1016 | } |
| 1017 | |
Hans Wennborg | bb4f962 | 2015-05-28 17:44:56 +0000 | [diff] [blame] | 1018 | /// Set the DLL storage class on F. |
| 1019 | void setFunctionDLLStorageClass(GlobalDecl GD, llvm::Function *F); |
| 1020 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 1021 | /// Return the appropriate linkage for the vtable, VTT, and type information |
| 1022 | /// of the given class. |
Anders Carlsson | 68d3424 | 2011-01-24 02:04:33 +0000 | [diff] [blame] | 1023 | llvm::GlobalVariable::LinkageTypes getVTableLinkage(const CXXRecordDecl *RD); |
Ken Dyck | 98ca794 | 2010-01-26 13:48:07 +0000 | [diff] [blame] | 1024 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 1025 | /// Return the store size, in character units, of the given LLVM type. |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 1026 | CharUnits GetTargetTypeStoreSize(llvm::Type *Ty) const; |
Fariborz Jahanian | 1518a5ec | 2010-10-27 16:21:54 +0000 | [diff] [blame] | 1027 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 1028 | /// Returns LLVM linkage for a declarator. |
David Majnemer | 27d69db | 2014-04-28 22:17:59 +0000 | [diff] [blame] | 1029 | llvm::GlobalValue::LinkageTypes |
Hans Wennborg | 1a3a074 | 2014-05-14 19:54:53 +0000 | [diff] [blame] | 1030 | getLLVMLinkageForDeclarator(const DeclaratorDecl *D, GVALinkage Linkage, |
Hans Wennborg | 275efb9 | 2014-05-28 01:52:23 +0000 | [diff] [blame] | 1031 | bool IsConstantVariable); |
David Majnemer | 27d69db | 2014-04-28 22:17:59 +0000 | [diff] [blame] | 1032 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 1033 | /// Returns LLVM linkage for a declarator. |
David Majnemer | 27d69db | 2014-04-28 22:17:59 +0000 | [diff] [blame] | 1034 | llvm::GlobalValue::LinkageTypes |
| 1035 | getLLVMLinkageVarDefinition(const VarDecl *VD, bool IsConstant); |
| 1036 | |
Julien Lerouge | 5a6b698 | 2011-09-09 22:41:49 +0000 | [diff] [blame] | 1037 | /// Emit all the global annotations. |
| 1038 | void EmitGlobalAnnotations(); |
| 1039 | |
| 1040 | /// Emit an annotation string. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 1041 | llvm::Constant *EmitAnnotationString(StringRef Str); |
Julien Lerouge | 5a6b698 | 2011-09-09 22:41:49 +0000 | [diff] [blame] | 1042 | |
| 1043 | /// Emit the annotation's translation unit. |
| 1044 | llvm::Constant *EmitAnnotationUnit(SourceLocation Loc); |
| 1045 | |
| 1046 | /// Emit the annotation line number. |
| 1047 | llvm::Constant *EmitAnnotationLineNo(SourceLocation L); |
| 1048 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 1049 | /// Generate the llvm::ConstantStruct which contains the annotation |
| 1050 | /// information for a given GlobalValue. The annotation struct is |
Julien Lerouge | 5a6b698 | 2011-09-09 22:41:49 +0000 | [diff] [blame] | 1051 | /// {i8 *, i8 *, i8 *, i32}. The first field is a constant expression, the |
| 1052 | /// GlobalValue being annotated. The second field is the constant string |
| 1053 | /// created from the AnnotateAttr's annotation. The third field is a constant |
| 1054 | /// string containing the name of the translation unit. The fourth field is |
| 1055 | /// the line number in the file of the annotated value declaration. |
| 1056 | llvm::Constant *EmitAnnotateAttr(llvm::GlobalValue *GV, |
| 1057 | const AnnotateAttr *AA, |
| 1058 | SourceLocation L); |
| 1059 | |
| 1060 | /// Add global annotations that are set on D, for the global GV. Those |
| 1061 | /// annotations are emitted during finalization of the LLVM code. |
| 1062 | void AddGlobalAnnotations(const ValueDecl *D, llvm::GlobalValue *GV); |
| 1063 | |
Alexey Samsonov | 1444bb9 | 2014-10-17 00:20:19 +0000 | [diff] [blame] | 1064 | bool isInSanitizerBlacklist(llvm::Function *Fn, SourceLocation Loc) const; |
Will Dietz | f54319c | 2013-01-18 11:30:38 +0000 | [diff] [blame] | 1065 | |
Alexey Samsonov | a0ac3c2 | 2014-10-17 22:37:33 +0000 | [diff] [blame] | 1066 | bool isInSanitizerBlacklist(llvm::GlobalVariable *GV, SourceLocation Loc, |
| 1067 | QualType Ty, |
| 1068 | StringRef Category = StringRef()) const; |
| 1069 | |
Alexey Samsonov | 4b8de11 | 2014-08-01 21:35:28 +0000 | [diff] [blame] | 1070 | SanitizerMetadata *getSanitizerMetadata() { |
| 1071 | return SanitizerMD.get(); |
| 1072 | } |
Alexey Samsonov | 4f319cc | 2014-07-02 16:54:41 +0000 | [diff] [blame] | 1073 | |
John McCall | 6bd2a89 | 2013-01-25 22:31:03 +0000 | [diff] [blame] | 1074 | void addDeferredVTable(const CXXRecordDecl *RD) { |
| 1075 | DeferredVTables.push_back(RD); |
| 1076 | } |
| 1077 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 1078 | /// Emit code for a singal global function or var decl. Forward declarations |
| 1079 | /// are emitted lazily. |
Reid Kleckner | e7de47e | 2013-07-22 13:51:44 +0000 | [diff] [blame] | 1080 | void EmitGlobal(GlobalDecl D); |
| 1081 | |
Rafael Espindola | 02b77f4 | 2014-09-15 18:46:13 +0000 | [diff] [blame] | 1082 | bool TryEmitDefinitionAsAlias(GlobalDecl Alias, GlobalDecl Target, |
| 1083 | bool InEveryTU); |
| 1084 | bool TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D); |
| 1085 | |
| 1086 | /// Set attributes for a global definition. |
| 1087 | void setFunctionDefinitionAttributes(const FunctionDecl *D, |
| 1088 | llvm::Function *F); |
| 1089 | |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 1090 | llvm::GlobalValue *GetGlobalValue(StringRef Ref); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1091 | |
Rafael Espindola | 1e4df92 | 2014-09-16 15:18:21 +0000 | [diff] [blame] | 1092 | /// Set attributes which are common to any form of a global definition (alias, |
| 1093 | /// Objective-C method, function, global variable). |
| 1094 | /// |
| 1095 | /// NOTE: This should only be called for definitions. |
| 1096 | void SetCommonAttributes(const Decl *D, llvm::GlobalValue *GV); |
| 1097 | |
Dario Domizioli | c4fb8ca7 | 2014-09-19 22:06:24 +0000 | [diff] [blame] | 1098 | /// Set attributes which must be preserved by an alias. This includes common |
| 1099 | /// attributes (i.e. it includes a call to SetCommonAttributes). |
| 1100 | /// |
| 1101 | /// NOTE: This should only be called for definitions. |
| 1102 | void setAliasAttributes(const Decl *D, llvm::GlobalValue *GV); |
| 1103 | |
Rafael Espindola | 1e4df92 | 2014-09-16 15:18:21 +0000 | [diff] [blame] | 1104 | void addReplacement(StringRef Name, llvm::Constant *C); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 1105 | |
Andrey Bokhanko | cab5858 | 2015-08-31 13:20:44 +0000 | [diff] [blame] | 1106 | void addGlobalValReplacement(llvm::GlobalValue *GV, llvm::Constant *C); |
| 1107 | |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 1108 | /// \brief Emit a code for threadprivate directive. |
| 1109 | /// \param D Threadprivate declaration. |
| 1110 | void EmitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D); |
| 1111 | |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 1112 | /// \brief Emit a code for declare reduction construct. |
Alexey Bataev | c5b1d32 | 2016-03-04 09:22:22 +0000 | [diff] [blame] | 1113 | void EmitOMPDeclareReduction(const OMPDeclareReductionDecl *D, |
| 1114 | CodeGenFunction *CGF = nullptr); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 1115 | |
Peter Collingbourne | 3afb266 | 2016-04-28 17:09:37 +0000 | [diff] [blame] | 1116 | /// Returns whether the given record has hidden LTO visibility and therefore |
| 1117 | /// may participate in (single-module) CFI and whole-program vtable |
| 1118 | /// optimization. |
| 1119 | bool HasHiddenLTOVisibility(const CXXRecordDecl *RD); |
Peter Collingbourne | e570644 | 2015-07-09 19:56:14 +0000 | [diff] [blame] | 1120 | |
Peter Collingbourne | a4ccff3 | 2015-02-20 20:30:56 +0000 | [diff] [blame] | 1121 | /// Emit bit set entries for the given vtable using the given layout if |
| 1122 | /// vptr CFI is enabled. |
| 1123 | void EmitVTableBitSetEntries(llvm::GlobalVariable *VTable, |
| 1124 | const VTableLayout &VTLayout); |
| 1125 | |
Evgeniy Stepanov | fd6f92d | 2015-12-15 23:00:20 +0000 | [diff] [blame] | 1126 | /// Generate a cross-DSO type identifier for type. |
| 1127 | llvm::ConstantInt *CreateCfiIdForTypeMetadata(llvm::Metadata *MD); |
| 1128 | |
Peter Collingbourne | 25a80bf | 2015-09-08 23:01:30 +0000 | [diff] [blame] | 1129 | /// Create a metadata identifier for the given type. This may either be an |
| 1130 | /// MDString (for external identifiers) or a distinct unnamed MDNode (for |
| 1131 | /// internal identifiers). |
| 1132 | llvm::Metadata *CreateMetadataIdentifierForType(QualType T); |
| 1133 | |
Evgeniy Stepanov | fd6f92d | 2015-12-15 23:00:20 +0000 | [diff] [blame] | 1134 | /// Create a bitset entry for the given function and add it to BitsetsMD. |
| 1135 | void CreateFunctionBitSetEntry(const FunctionDecl *FD, llvm::Function *F); |
| 1136 | |
Evgeniy Stepanov | f31ea30 | 2016-02-03 22:18:55 +0000 | [diff] [blame] | 1137 | /// Returns whether this module needs the "all-vtables" bitset. |
| 1138 | bool NeedAllVtablesBitSet() const; |
| 1139 | |
Evgeniy Stepanov | fd6f92d | 2015-12-15 23:00:20 +0000 | [diff] [blame] | 1140 | /// Create a bitset entry for the given vtable and add it to BitsetsMD. |
| 1141 | void CreateVTableBitSetEntry(llvm::NamedMDNode *BitsetsMD, |
| 1142 | llvm::GlobalVariable *VTable, CharUnits Offset, |
| 1143 | const CXXRecordDecl *RD); |
Peter Collingbourne | 86d34a7 | 2015-06-17 19:08:05 +0000 | [diff] [blame] | 1144 | |
Reid Kleckner | fff8e7f | 2015-03-03 19:21:04 +0000 | [diff] [blame] | 1145 | /// \breif Get the declaration of std::terminate for the platform. |
| 1146 | llvm::Constant *getTerminateFn(); |
| 1147 | |
Peter Collingbourne | dc13453 | 2016-01-16 00:31:22 +0000 | [diff] [blame] | 1148 | llvm::SanitizerStatReport &getSanStats(); |
| 1149 | |
Rafael Espindola | 1e4df92 | 2014-09-16 15:18:21 +0000 | [diff] [blame] | 1150 | private: |
Rafael Espindola | 94abb8f | 2013-12-09 04:29:47 +0000 | [diff] [blame] | 1151 | llvm::Constant * |
| 1152 | GetOrCreateLLVMFunction(StringRef MangledName, llvm::Type *Ty, GlobalDecl D, |
| 1153 | bool ForVTable, bool DontDefer = false, |
David Majnemer | b9bd6fb | 2014-11-01 05:42:23 +0000 | [diff] [blame] | 1154 | bool IsThunk = false, |
Andrey Bokhanko | cab5858 | 2015-08-31 13:20:44 +0000 | [diff] [blame] | 1155 | llvm::AttributeSet ExtraAttrs = llvm::AttributeSet(), |
| 1156 | bool IsForDefinition = false); |
Rafael Espindola | 94abb8f | 2013-12-09 04:29:47 +0000 | [diff] [blame] | 1157 | |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 1158 | llvm::Constant *GetOrCreateLLVMGlobal(StringRef MangledName, |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 1159 | llvm::PointerType *PTy, |
Andrey Bokhanko | 7aa88ce | 2016-01-14 10:41:16 +0000 | [diff] [blame] | 1160 | const VarDecl *D, |
| 1161 | bool IsForDefinition = false); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1162 | |
Rafael Espindola | ee076a2 | 2014-05-13 18:45:53 +0000 | [diff] [blame] | 1163 | void setNonAliasAttributes(const Decl *D, llvm::GlobalObject *GO); |
Rafael Espindola | 502f65a | 2014-05-05 20:21:03 +0000 | [diff] [blame] | 1164 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 1165 | /// Set function attributes for a function declaration. |
David Majnemer | b9bd6fb | 2014-11-01 05:42:23 +0000 | [diff] [blame] | 1166 | void SetFunctionAttributes(GlobalDecl GD, llvm::Function *F, |
| 1167 | bool IsIncompleteFunction, bool IsThunk); |
Nuno Lopes | b6f7953 | 2008-06-08 15:45:52 +0000 | [diff] [blame] | 1168 | |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 1169 | void EmitGlobalDefinition(GlobalDecl D, llvm::GlobalValue *GV = nullptr); |
Daniel Dunbar | f0acf7b | 2009-02-19 07:15:39 +0000 | [diff] [blame] | 1170 | |
Rafael Espindola | cd7743b | 2013-12-09 16:01:03 +0000 | [diff] [blame] | 1171 | void EmitGlobalFunctionDefinition(GlobalDecl GD, llvm::GlobalValue *GV); |
Andrey Bokhanko | 7aa88ce | 2016-01-14 10:41:16 +0000 | [diff] [blame] | 1172 | void EmitGlobalVarDefinition(const VarDecl *D, bool IsTentative = false); |
John McCall | 7ec5043 | 2010-03-19 23:29:14 +0000 | [diff] [blame] | 1173 | void EmitAliasDefinition(GlobalDecl GD); |
Dmitry Polukhin | 85eda12 | 2016-04-11 07:48:59 +0000 | [diff] [blame] | 1174 | void emitIFuncDefinition(GlobalDecl GD); |
Daniel Dunbar | 89654ee | 2008-08-26 08:29:31 +0000 | [diff] [blame] | 1175 | void EmitObjCPropertyImplementations(const ObjCImplementationDecl *D); |
Fariborz Jahanian | 0dec1e0 | 2010-04-28 21:28:56 +0000 | [diff] [blame] | 1176 | void EmitObjCIvarInitializations(ObjCImplementationDecl *D); |
Fariborz Jahanian | 1518a5ec | 2010-10-27 16:21:54 +0000 | [diff] [blame] | 1177 | |
Anders Carlsson | f747524 | 2009-04-15 15:55:24 +0000 | [diff] [blame] | 1178 | // C++ related functions. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1179 | |
Anders Carlsson | 237f349 | 2009-04-01 00:58:25 +0000 | [diff] [blame] | 1180 | void EmitNamespace(const NamespaceDecl *D); |
Anders Carlsson | cbaeb9e | 2009-04-02 05:55:18 +0000 | [diff] [blame] | 1181 | void EmitLinkageSpec(const LinkageSpecDecl *D); |
Adrian Prantl | ffcf4ba | 2013-05-09 23:16:27 +0000 | [diff] [blame] | 1182 | void CompleteDIClassType(const CXXMethodDecl* D); |
Anders Carlsson | f747524 | 2009-04-15 15:55:24 +0000 | [diff] [blame] | 1183 | |
Richard Smith | 2fd1d7a | 2013-04-19 16:42:07 +0000 | [diff] [blame] | 1184 | /// \brief Emit the function that initializes C++ thread_local variables. |
| 1185 | void EmitCXXThreadLocalInitFunc(); |
| 1186 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 1187 | /// Emit the function that initializes C++ globals. |
Anders Carlsson | b8be93f | 2009-08-08 23:24:23 +0000 | [diff] [blame] | 1188 | void EmitCXXGlobalInitFunc(); |
Eli Friedman | 5866fe3 | 2010-01-08 00:50:11 +0000 | [diff] [blame] | 1189 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 1190 | /// Emit the function that destroys C++ globals. |
Daniel Dunbar | fe06df4 | 2010-03-20 04:15:41 +0000 | [diff] [blame] | 1191 | void EmitCXXGlobalDtorFunc(); |
| 1192 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 1193 | /// Emit the function that initializes the specified global (if PerformInit is |
| 1194 | /// true) and registers its destructor. |
John McCall | cdf7ef5 | 2010-11-06 09:44:32 +0000 | [diff] [blame] | 1195 | void EmitCXXGlobalVarDeclInitFunc(const VarDecl *D, |
Richard Smith | 6331c40 | 2012-02-13 22:16:19 +0000 | [diff] [blame] | 1196 | llvm::GlobalVariable *Addr, |
| 1197 | bool PerformInit); |
Eli Friedman | 5866fe3 | 2010-01-08 00:50:11 +0000 | [diff] [blame] | 1198 | |
Reid Kleckner | 1a711b1 | 2014-07-22 00:53:05 +0000 | [diff] [blame] | 1199 | void EmitPointerToInitFunc(const VarDecl *VD, llvm::GlobalVariable *Addr, |
| 1200 | llvm::Function *InitFunc, InitSegAttr *ISA); |
| 1201 | |
Daniel Dunbar | 74aa7e1 | 2008-08-01 00:01:51 +0000 | [diff] [blame] | 1202 | // FIXME: Hardcoding priority here is gross. |
Reid Kleckner | 563f0e8 | 2014-05-23 21:13:45 +0000 | [diff] [blame] | 1203 | void AddGlobalCtor(llvm::Function *Ctor, int Priority = 65535, |
Hans Wennborg | 59dbe86 | 2015-09-29 20:56:43 +0000 | [diff] [blame] | 1204 | llvm::Constant *AssociatedData = nullptr); |
Reid Kleckner | 563f0e8 | 2014-05-23 21:13:45 +0000 | [diff] [blame] | 1205 | void AddGlobalDtor(llvm::Function *Dtor, int Priority = 65535); |
Daniel Dunbar | 9c42652 | 2008-07-29 23:18:29 +0000 | [diff] [blame] | 1206 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 1207 | /// Generates a global array of functions and priorities using the given list |
| 1208 | /// and name. This array will have appending linkage and is suitable for use |
| 1209 | /// as a LLVM constructor or destructor array. |
Daniel Dunbar | 74aa7e1 | 2008-08-01 00:01:51 +0000 | [diff] [blame] | 1210 | void EmitCtorList(const CtorList &Fns, const char *GlobalName); |
| 1211 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 1212 | /// Emit any needed decls for which code generation was deferred. |
Dmitri Gribenko | b2aa923 | 2012-11-15 14:28:07 +0000 | [diff] [blame] | 1213 | void EmitDeferred(); |
Daniel Dunbar | 08b26a0 | 2009-02-13 20:29:50 +0000 | [diff] [blame] | 1214 | |
Rafael Espindola | 2e2995b | 2013-11-05 21:37:29 +0000 | [diff] [blame] | 1215 | /// Call replaceAllUsesWith on all pairs in Replacements. |
| 1216 | void applyReplacements(); |
| 1217 | |
Andrey Bokhanko | cab5858 | 2015-08-31 13:20:44 +0000 | [diff] [blame] | 1218 | /// Call replaceAllUsesWith on all pairs in GlobalValReplacements. |
| 1219 | void applyGlobalValReplacements(); |
| 1220 | |
Rafael Espindola | 208b5c0 | 2013-10-22 19:26:13 +0000 | [diff] [blame] | 1221 | void checkAliases(); |
| 1222 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 1223 | /// Emit any vtables which we deferred and still have a use for. |
John McCall | 6bd2a89 | 2013-01-25 22:31:03 +0000 | [diff] [blame] | 1224 | void EmitDeferredVTables(); |
| 1225 | |
Rafael Espindola | 060062a | 2014-03-06 22:15:10 +0000 | [diff] [blame] | 1226 | /// Emit the llvm.used and llvm.compiler.used metadata. |
| 1227 | void emitLLVMUsed(); |
Daniel Dunbar | 23fd462 | 2008-10-01 00:49:24 +0000 | [diff] [blame] | 1228 | |
Douglas Gregor | bc25ff4 | 2013-01-14 20:53:57 +0000 | [diff] [blame] | 1229 | /// \brief Emit the link options introduced by imported modules. |
| 1230 | void EmitModuleLinkOptions(); |
| 1231 | |
Richard Smith | df931ce | 2013-04-06 05:00:46 +0000 | [diff] [blame] | 1232 | /// \brief Emit aliases for internal-linkage declarations inside "C" language |
| 1233 | /// linkage specifications, giving them the "expected" name where possible. |
| 1234 | void EmitStaticExternCAliases(); |
| 1235 | |
John McCall | 09ae032 | 2010-07-06 23:57:41 +0000 | [diff] [blame] | 1236 | void EmitDeclMetadata(); |
| 1237 | |
Rafael Espindola | 3bfa468 | 2013-10-16 19:28:50 +0000 | [diff] [blame] | 1238 | /// \brief Emit the Clang version as llvm.ident metadata. |
| 1239 | void EmitVersionIdentMetadata(); |
| 1240 | |
Robert Lytton | 57765d5 | 2014-07-03 09:30:33 +0000 | [diff] [blame] | 1241 | /// Emits target specific Metadata for global declarations. |
| 1242 | void EmitTargetMetadata(); |
| 1243 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 1244 | /// Emit the llvm.gcov metadata used to tell LLVM where to emit the .gcno and |
| 1245 | /// .gcda files in a way that persists in .bc files. |
Nick Lewycky | 85c011d | 2011-05-05 00:08:20 +0000 | [diff] [blame] | 1246 | void EmitCoverageFile(); |
Nick Lewycky | 480cb99 | 2011-05-04 20:46:58 +0000 | [diff] [blame] | 1247 | |
Nico Weber | cf4ff586 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 1248 | /// Emits the initializer for a uuidof string. |
Nico Weber | 17d3a2c | 2014-09-08 16:26:36 +0000 | [diff] [blame] | 1249 | llvm::Constant *EmitUuidofInitializer(StringRef uuidstr); |
Nico Weber | cf4ff586 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 1250 | |
Hans Wennborg | 43a0f99 | 2015-01-10 01:19:48 +0000 | [diff] [blame] | 1251 | /// Determine whether the definition must be emitted; if this returns \c |
| 1252 | /// false, the definition can be emitted lazily if it's used. |
| 1253 | bool MustBeEmitted(const ValueDecl *D); |
| 1254 | |
| 1255 | /// Determine whether the definition can be emitted eagerly, or should be |
| 1256 | /// delayed until the end of the translation unit. This is relevant for |
| 1257 | /// definitions whose linkage can change, e.g. implicit function instantions |
| 1258 | /// which may later be explicitly instantiated. |
| 1259 | bool MayBeEmittedEagerly(const ValueDecl *D); |
John McCall | 0bdb1fd | 2010-09-16 06:16:50 +0000 | [diff] [blame] | 1260 | |
Rafael Espindola | e98ed2f | 2014-05-09 01:34:38 +0000 | [diff] [blame] | 1261 | /// Check whether we can use a "simpler", more core exceptions personality |
| 1262 | /// function. |
John McCall | 0bdb1fd | 2010-09-16 06:16:50 +0000 | [diff] [blame] | 1263 | void SimplifyPersonality(); |
Chris Lattner | f97fe38 | 2007-05-24 06:29:05 +0000 | [diff] [blame] | 1264 | }; |
| 1265 | } // end namespace CodeGen |
| 1266 | } // end namespace clang |
Chris Lattner | f97fe38 | 2007-05-24 06:29:05 +0000 | [diff] [blame] | 1267 | |
Hans Wennborg | 59dbe86 | 2015-09-29 20:56:43 +0000 | [diff] [blame] | 1268 | #endif // LLVM_CLANG_LIB_CODEGEN_CODEGENMODULE_H |