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