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