Daniel Dunbar | 9c42652 | 2008-07-29 23:18:29 +0000 | [diff] [blame] | 1 | //===-- CodeGenFunction.h - Per-Function state for LLVM CodeGen -*- C++ -*-===// |
Chris Lattner | bed3144 | 2007-05-28 01:07:47 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 5b12ab8 | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Chris Lattner | bed3144 | 2007-05-28 01:07:47 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 10 | // This is the internal per-function state used for llvm translation. |
Chris Lattner | bed3144 | 2007-05-28 01:07:47 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Benjamin Kramer | 2f5db8b | 2014-08-13 16:25:19 +0000 | [diff] [blame] | 14 | #ifndef LLVM_CLANG_LIB_CODEGEN_CODEGENFUNCTION_H |
| 15 | #define LLVM_CLANG_LIB_CODEGEN_CODEGENFUNCTION_H |
Chris Lattner | bed3144 | 2007-05-28 01:07:47 +0000 | [diff] [blame] | 16 | |
Daniel Dunbar | cb46385 | 2008-11-01 01:53:16 +0000 | [diff] [blame] | 17 | #include "CGBuilder.h" |
Eric Christopher | a9d3497 | 2011-10-19 00:43:52 +0000 | [diff] [blame] | 18 | #include "CGDebugInfo.h" |
Alexander Musman | 515ad8c | 2014-05-22 08:54:05 +0000 | [diff] [blame] | 19 | #include "CGLoopInfo.h" |
Daniel Dunbar | 97db84c | 2008-08-23 03:46:30 +0000 | [diff] [blame] | 20 | #include "CGValue.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 21 | #include "CodeGenModule.h" |
Justin Bogner | ef512b9 | 2014-01-06 22:27:43 +0000 | [diff] [blame] | 22 | #include "CodeGenPGO.h" |
Chandler Carruth | 5553d0d | 2014-01-07 11:51:46 +0000 | [diff] [blame] | 23 | #include "EHScopeStack.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 24 | #include "clang/AST/CharUnits.h" |
| 25 | #include "clang/AST/ExprCXX.h" |
| 26 | #include "clang/AST/ExprObjC.h" |
| 27 | #include "clang/AST/Type.h" |
| 28 | #include "clang/Basic/ABI.h" |
Ben Langmuir | 3b4c30b | 2013-05-09 19:17:11 +0000 | [diff] [blame] | 29 | #include "clang/Basic/CapturedStmt.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 30 | #include "clang/Basic/TargetInfo.h" |
| 31 | #include "clang/Frontend/CodeGenOptions.h" |
| 32 | #include "llvm/ADT/ArrayRef.h" |
| 33 | #include "llvm/ADT/DenseMap.h" |
| 34 | #include "llvm/ADT/SmallVector.h" |
Chandler Carruth | 61743af | 2014-03-04 11:18:19 +0000 | [diff] [blame] | 35 | #include "llvm/IR/ValueHandle.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 36 | #include "llvm/Support/Debug.h" |
Daniel Dunbar | 97db84c | 2008-08-23 03:46:30 +0000 | [diff] [blame] | 37 | |
Chris Lattner | bed3144 | 2007-05-28 01:07:47 +0000 | [diff] [blame] | 38 | namespace llvm { |
Rafael Espindola | 42ae745 | 2014-05-09 00:57:59 +0000 | [diff] [blame] | 39 | class BasicBlock; |
| 40 | class LLVMContext; |
| 41 | class MDNode; |
| 42 | class Module; |
| 43 | class SwitchInst; |
| 44 | class Twine; |
| 45 | class Value; |
| 46 | class CallSite; |
Chris Lattner | 23b7eb6 | 2007-06-15 23:05:46 +0000 | [diff] [blame] | 47 | } |
| 48 | |
Chris Lattner | bed3144 | 2007-05-28 01:07:47 +0000 | [diff] [blame] | 49 | namespace clang { |
Rafael Espindola | 42ae745 | 2014-05-09 00:57:59 +0000 | [diff] [blame] | 50 | class ASTContext; |
| 51 | class BlockDecl; |
| 52 | class CXXDestructorDecl; |
| 53 | class CXXForRangeStmt; |
| 54 | class CXXTryStmt; |
| 55 | class Decl; |
| 56 | class LabelDecl; |
| 57 | class EnumConstantDecl; |
| 58 | class FunctionDecl; |
| 59 | class FunctionProtoType; |
| 60 | class LabelStmt; |
| 61 | class ObjCContainerDecl; |
| 62 | class ObjCInterfaceDecl; |
| 63 | class ObjCIvarDecl; |
| 64 | class ObjCMethodDecl; |
| 65 | class ObjCImplementationDecl; |
| 66 | class ObjCPropertyImplDecl; |
| 67 | class TargetInfo; |
| 68 | class TargetCodeGenInfo; |
| 69 | class VarDecl; |
| 70 | class ObjCForCollectionStmt; |
| 71 | class ObjCAtTryStmt; |
| 72 | class ObjCAtThrowStmt; |
| 73 | class ObjCAtSynchronizedStmt; |
| 74 | class ObjCAutoreleasePoolStmt; |
Devang Patel | 3e11cce | 2007-10-23 02:10:49 +0000 | [diff] [blame] | 75 | |
Chris Lattner | bed3144 | 2007-05-28 01:07:47 +0000 | [diff] [blame] | 76 | namespace CodeGen { |
Rafael Espindola | 42ae745 | 2014-05-09 00:57:59 +0000 | [diff] [blame] | 77 | class CodeGenTypes; |
| 78 | class CGFunctionInfo; |
| 79 | class CGRecordLayout; |
| 80 | class CGBlockInfo; |
| 81 | class CGCXXABI; |
| 82 | class BlockFlags; |
| 83 | class BlockFieldFlags; |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 84 | |
John McCall | 47fb950 | 2013-03-07 21:37:08 +0000 | [diff] [blame] | 85 | /// The kind of evaluation to perform on values of a particular |
| 86 | /// type. Basically, is the code in CGExprScalar, CGExprComplex, or |
| 87 | /// CGExprAgg? |
| 88 | /// |
| 89 | /// TODO: should vectors maybe be split out into their own thing? |
| 90 | enum TypeEvaluationKind { |
| 91 | TEK_Scalar, |
| 92 | TEK_Complex, |
| 93 | TEK_Aggregate |
| 94 | }; |
| 95 | |
David Blaikie | 1b5adb8 | 2014-07-10 20:42:59 +0000 | [diff] [blame] | 96 | class SuppressDebugLocation { |
| 97 | llvm::DebugLoc CurLoc; |
| 98 | llvm::IRBuilderBase &Builder; |
| 99 | public: |
| 100 | SuppressDebugLocation(llvm::IRBuilderBase &Builder) |
| 101 | : CurLoc(Builder.getCurrentDebugLocation()), Builder(Builder) { |
| 102 | Builder.SetCurrentDebugLocation(llvm::DebugLoc()); |
| 103 | } |
| 104 | ~SuppressDebugLocation() { |
| 105 | Builder.SetCurrentDebugLocation(CurLoc); |
| 106 | } |
| 107 | }; |
| 108 | |
Chris Lattner | bed3144 | 2007-05-28 01:07:47 +0000 | [diff] [blame] | 109 | /// CodeGenFunction - This class organizes the per-function state that is used |
| 110 | /// while generating LLVM code. |
John McCall | e3dc170 | 2011-02-15 09:22:45 +0000 | [diff] [blame] | 111 | class CodeGenFunction : public CodeGenTypeCache { |
Dmitri Gribenko | a664e5b | 2012-09-15 20:20:27 +0000 | [diff] [blame] | 112 | CodeGenFunction(const CodeGenFunction &) LLVM_DELETED_FUNCTION; |
| 113 | void operator=(const CodeGenFunction &) LLVM_DELETED_FUNCTION; |
John McCall | 5d865c32 | 2010-08-31 07:33:07 +0000 | [diff] [blame] | 114 | |
| 115 | friend class CGCXXABI; |
Chris Lattner | bda69f8 | 2007-08-26 23:13:56 +0000 | [diff] [blame] | 116 | public: |
John McCall | ad5d61e | 2010-07-23 21:56:41 +0000 | [diff] [blame] | 117 | /// A jump destination is an abstract label, branching to which may |
| 118 | /// require a jump out through normal cleanups. |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 119 | struct JumpDest { |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 120 | JumpDest() : Block(nullptr), ScopeDepth(), Index(0) {} |
John McCall | ad5d61e | 2010-07-23 21:56:41 +0000 | [diff] [blame] | 121 | JumpDest(llvm::BasicBlock *Block, |
| 122 | EHScopeStack::stable_iterator Depth, |
| 123 | unsigned Index) |
| 124 | : Block(Block), ScopeDepth(Depth), Index(Index) {} |
| 125 | |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 126 | bool isValid() const { return Block != nullptr; } |
John McCall | ad5d61e | 2010-07-23 21:56:41 +0000 | [diff] [blame] | 127 | llvm::BasicBlock *getBlock() const { return Block; } |
| 128 | EHScopeStack::stable_iterator getScopeDepth() const { return ScopeDepth; } |
| 129 | unsigned getDestIndex() const { return Index; } |
Michael J. Spencer | f5a1fbc | 2010-10-19 06:39:39 +0000 | [diff] [blame] | 130 | |
Nadav Rotem | 1da3094 | 2013-03-23 06:43:35 +0000 | [diff] [blame] | 131 | // This should be used cautiously. |
| 132 | void setScopeDepth(EHScopeStack::stable_iterator depth) { |
| 133 | ScopeDepth = depth; |
| 134 | } |
| 135 | |
John McCall | ad5d61e | 2010-07-23 21:56:41 +0000 | [diff] [blame] | 136 | private: |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 137 | llvm::BasicBlock *Block; |
| 138 | EHScopeStack::stable_iterator ScopeDepth; |
John McCall | ad5d61e | 2010-07-23 21:56:41 +0000 | [diff] [blame] | 139 | unsigned Index; |
| 140 | }; |
| 141 | |
Chris Lattner | bed3144 | 2007-05-28 01:07:47 +0000 | [diff] [blame] | 142 | CodeGenModule &CGM; // Per-module state. |
Daniel Dunbar | 1b44419 | 2009-11-13 05:51:54 +0000 | [diff] [blame] | 143 | const TargetInfo &Target; |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 144 | |
Chris Lattner | 96d7256 | 2007-08-21 16:57:55 +0000 | [diff] [blame] | 145 | typedef std::pair<llvm::Value *, llvm::Value *> ComplexPairTy; |
Alexander Musman | 515ad8c | 2014-05-22 08:54:05 +0000 | [diff] [blame] | 146 | LoopInfoStack LoopStack; |
Daniel Dunbar | cb46385 | 2008-11-01 01:53:16 +0000 | [diff] [blame] | 147 | CGBuilderTy Builder; |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 148 | |
Alexander Musman | 515ad8c | 2014-05-22 08:54:05 +0000 | [diff] [blame] | 149 | /// \brief CGBuilder insert helper. This function is called after an |
| 150 | /// instruction is created using Builder. |
| 151 | void InsertHelper(llvm::Instruction *I, const llvm::Twine &Name, |
| 152 | llvm::BasicBlock *BB, |
| 153 | llvm::BasicBlock::iterator InsertPt) const; |
| 154 | |
John McCall | dec348f7 | 2013-05-03 07:33:41 +0000 | [diff] [blame] | 155 | /// CurFuncDecl - Holds the Decl for the current outermost |
| 156 | /// non-closure context. |
Chris Lattner | 5696e7b | 2008-06-17 18:05:57 +0000 | [diff] [blame] | 157 | const Decl *CurFuncDecl; |
Chris Lattner | 28ec0cf | 2009-04-23 05:30:27 +0000 | [diff] [blame] | 158 | /// CurCodeDecl - This is the inner-most code context, which includes blocks. |
| 159 | const Decl *CurCodeDecl; |
Daniel Dunbar | d931a87 | 2009-02-02 22:03:45 +0000 | [diff] [blame] | 160 | const CGFunctionInfo *CurFnInfo; |
Chris Lattner | 4bd5596 | 2008-03-30 23:03:07 +0000 | [diff] [blame] | 161 | QualType FnRetTy; |
Chris Lattner | ac24820 | 2007-05-30 00:13:02 +0000 | [diff] [blame] | 162 | llvm::Function *CurFn; |
| 163 | |
Mike Stump | bee78dd | 2009-12-04 23:26:17 +0000 | [diff] [blame] | 164 | /// CurGD - The GlobalDecl for the current function being compiled. |
| 165 | GlobalDecl CurGD; |
Mike Stump | bee78dd | 2009-12-04 23:26:17 +0000 | [diff] [blame] | 166 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 167 | /// PrologueCleanupDepth - The cleanup depth enclosing all the |
| 168 | /// cleanups associated with the parameters. |
| 169 | EHScopeStack::stable_iterator PrologueCleanupDepth; |
| 170 | |
Daniel Dunbar | 54bb193 | 2008-09-09 21:00:17 +0000 | [diff] [blame] | 171 | /// ReturnBlock - Unified return block. |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 172 | JumpDest ReturnBlock; |
| 173 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 174 | /// ReturnValue - The temporary alloca to hold the return value. This is null |
Sylvestre Ledru | 33b5baf | 2012-09-27 10:16:10 +0000 | [diff] [blame] | 175 | /// iff the function has no return value. |
Eli Friedman | 4b1942c | 2009-12-04 02:43:40 +0000 | [diff] [blame] | 176 | llvm::Value *ReturnValue; |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 177 | |
Chris Lattner | 03df122 | 2007-06-02 04:53:11 +0000 | [diff] [blame] | 178 | /// AllocaInsertPoint - This is an instruction in the entry block before which |
| 179 | /// we prefer to insert allocas. |
Chris Lattner | 2739d2b | 2009-03-31 22:17:44 +0000 | [diff] [blame] | 180 | llvm::AssertingVH<llvm::Instruction> AllocaInsertPt; |
Daniel Dunbar | 88402ce | 2008-08-04 16:51:22 +0000 | [diff] [blame] | 181 | |
Ben Langmuir | 3b4c30b | 2013-05-09 19:17:11 +0000 | [diff] [blame] | 182 | /// \brief API for captured statement code generation. |
| 183 | class CGCapturedStmtInfo { |
| 184 | public: |
| 185 | explicit CGCapturedStmtInfo(const CapturedStmt &S, |
| 186 | CapturedRegionKind K = CR_Default) |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 187 | : Kind(K), ThisValue(nullptr), CXXThisFieldDecl(nullptr) { |
Ben Langmuir | 3b4c30b | 2013-05-09 19:17:11 +0000 | [diff] [blame] | 188 | |
| 189 | RecordDecl::field_iterator Field = |
| 190 | S.getCapturedRecordDecl()->field_begin(); |
| 191 | for (CapturedStmt::const_capture_iterator I = S.capture_begin(), |
| 192 | E = S.capture_end(); |
| 193 | I != E; ++I, ++Field) { |
| 194 | if (I->capturesThis()) |
| 195 | CXXThisFieldDecl = *Field; |
| 196 | else |
| 197 | CaptureFields[I->getCapturedVar()] = *Field; |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | virtual ~CGCapturedStmtInfo(); |
| 202 | |
| 203 | CapturedRegionKind getKind() const { return Kind; } |
| 204 | |
| 205 | void setContextValue(llvm::Value *V) { ThisValue = V; } |
| 206 | // \brief Retrieve the value of the context parameter. |
| 207 | llvm::Value *getContextValue() const { return ThisValue; } |
| 208 | |
| 209 | /// \brief Lookup the captured field decl for a variable. |
| 210 | const FieldDecl *lookup(const VarDecl *VD) const { |
| 211 | return CaptureFields.lookup(VD); |
| 212 | } |
| 213 | |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 214 | bool isCXXThisExprCaptured() const { return CXXThisFieldDecl != nullptr; } |
Ben Langmuir | 3b4c30b | 2013-05-09 19:17:11 +0000 | [diff] [blame] | 215 | FieldDecl *getThisFieldDecl() const { return CXXThisFieldDecl; } |
| 216 | |
| 217 | /// \brief Emit the captured statement body. |
| 218 | virtual void EmitBody(CodeGenFunction &CGF, Stmt *S) { |
Justin Bogner | 81ab90f | 2014-04-15 00:50:54 +0000 | [diff] [blame] | 219 | RegionCounter Cnt = CGF.getPGORegionCounter(S); |
| 220 | Cnt.beginRegion(CGF.Builder); |
Ben Langmuir | 3b4c30b | 2013-05-09 19:17:11 +0000 | [diff] [blame] | 221 | CGF.EmitStmt(S); |
| 222 | } |
| 223 | |
| 224 | /// \brief Get the name of the capture helper. |
| 225 | virtual StringRef getHelperName() const { return "__captured_stmt"; } |
| 226 | |
| 227 | private: |
| 228 | /// \brief The kind of captured statement being generated. |
| 229 | CapturedRegionKind Kind; |
| 230 | |
| 231 | /// \brief Keep the map between VarDecl and FieldDecl. |
| 232 | llvm::SmallDenseMap<const VarDecl *, FieldDecl *> CaptureFields; |
| 233 | |
| 234 | /// \brief The base address of the captured record, passed in as the first |
| 235 | /// argument of the parallel region function. |
| 236 | llvm::Value *ThisValue; |
| 237 | |
| 238 | /// \brief Captured 'this' type. |
| 239 | FieldDecl *CXXThisFieldDecl; |
| 240 | }; |
| 241 | CGCapturedStmtInfo *CapturedStmtInfo; |
| 242 | |
Nuno Lopes | 3d6311d | 2012-05-08 22:10:46 +0000 | [diff] [blame] | 243 | /// BoundsChecking - Emit run-time bounds checks. Higher values mean |
| 244 | /// potentially higher performance penalties. |
| 245 | unsigned char BoundsChecking; |
| 246 | |
Will Dietz | f54319c | 2013-01-18 11:30:38 +0000 | [diff] [blame] | 247 | /// \brief Sanitizer options to use for this function. |
| 248 | const SanitizerOptions *SanOpts; |
| 249 | |
Alexey Samsonov | 24cad99 | 2014-07-17 18:46:27 +0000 | [diff] [blame] | 250 | /// \brief True if CodeGen currently emits code implementing sanitizer checks. |
| 251 | bool IsSanitizerScope; |
| 252 | |
| 253 | /// \brief RAII object to set/unset CodeGenFunction::IsSanitizerScope. |
| 254 | class SanitizerScope { |
| 255 | CodeGenFunction *CGF; |
| 256 | public: |
| 257 | SanitizerScope(CodeGenFunction *CGF); |
| 258 | ~SanitizerScope(); |
| 259 | }; |
| 260 | |
Reid Kleckner | 1981944 | 2014-07-25 21:39:46 +0000 | [diff] [blame] | 261 | /// In C++, whether we are code generating a thunk. This controls whether we |
| 262 | /// should emit cleanups. |
| 263 | bool CurFuncIsThunk; |
| 264 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 265 | /// In ARC, whether we should autorelease the return value. |
| 266 | bool AutoreleaseResult; |
| 267 | |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 268 | const CodeGen::CGBlockInfo *BlockInfo; |
| 269 | llvm::Value *BlockPointer; |
| 270 | |
Eli Friedman | 9fbeba0 | 2012-02-11 02:57:39 +0000 | [diff] [blame] | 271 | llvm::DenseMap<const VarDecl *, FieldDecl *> LambdaCaptureFields; |
| 272 | FieldDecl *LambdaThisCaptureField; |
| 273 | |
Douglas Gregor | 9154b5d | 2010-05-17 15:52:46 +0000 | [diff] [blame] | 274 | /// \brief A mapping from NRVO variables to the flags used to indicate |
| 275 | /// when the NRVO has been applied to this variable. |
| 276 | llvm::DenseMap<const VarDecl *, llvm::Value *> NRVOFlags; |
Michael J. Spencer | f5a1fbc | 2010-10-19 06:39:39 +0000 | [diff] [blame] | 277 | |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 278 | EHScopeStack EHStack; |
Richard Smith | 736a947 | 2013-06-12 20:42:33 +0000 | [diff] [blame] | 279 | llvm::SmallVector<char, 256> LifetimeExtendedCleanupStack; |
| 280 | |
| 281 | /// Header for data within LifetimeExtendedCleanupStack. |
| 282 | struct LifetimeExtendedCleanupHeader { |
| 283 | /// The size of the following cleanup object. |
| 284 | size_t Size : 29; |
| 285 | /// The kind of cleanup to push: a value from the CleanupKind enumeration. |
| 286 | unsigned Kind : 3; |
| 287 | |
| 288 | size_t getSize() const { return Size; } |
| 289 | CleanupKind getKind() const { return static_cast<CleanupKind>(Kind); } |
| 290 | }; |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 291 | |
John McCall | ad5d61e | 2010-07-23 21:56:41 +0000 | [diff] [blame] | 292 | /// i32s containing the indexes of the cleanup destinations. |
| 293 | llvm::AllocaInst *NormalCleanupDest; |
John McCall | ad5d61e | 2010-07-23 21:56:41 +0000 | [diff] [blame] | 294 | |
| 295 | unsigned NextCleanupDestIndex; |
| 296 | |
John McCall | 08ef466 | 2011-11-10 08:15:53 +0000 | [diff] [blame] | 297 | /// FirstBlockInfo - The head of a singly-linked-list of block layouts. |
| 298 | CGBlockInfo *FirstBlockInfo; |
| 299 | |
John McCall | 8e4c74b | 2011-08-11 02:22:43 +0000 | [diff] [blame] | 300 | /// EHResumeBlock - Unified block containing a call to llvm.eh.resume. |
| 301 | llvm::BasicBlock *EHResumeBlock; |
| 302 | |
Bill Wendling | f0724e8 | 2011-09-19 20:31:14 +0000 | [diff] [blame] | 303 | /// The exception slot. All landing pads write the current exception pointer |
| 304 | /// into this alloca. |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 305 | llvm::Value *ExceptionSlot; |
| 306 | |
Bill Wendling | f0724e8 | 2011-09-19 20:31:14 +0000 | [diff] [blame] | 307 | /// The selector slot. Under the MandatoryCleanup model, all landing pads |
| 308 | /// write the current selector value into this alloca. |
John McCall | 9b382dd | 2011-05-28 21:13:02 +0000 | [diff] [blame] | 309 | llvm::AllocaInst *EHSelectorSlot; |
| 310 | |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 311 | /// Emits a landing pad for the current EH stack. |
| 312 | llvm::BasicBlock *EmitLandingPad(); |
| 313 | |
| 314 | llvm::BasicBlock *getInvokeDestImpl(); |
| 315 | |
John McCall | ce1de61 | 2011-01-26 04:00:11 +0000 | [diff] [blame] | 316 | template <class T> |
John McCall | cb5f77f | 2011-01-28 10:53:53 +0000 | [diff] [blame] | 317 | typename DominatingValue<T>::saved_type saveValueInCond(T value) { |
| 318 | return DominatingValue<T>::save(*this, value); |
John McCall | ce1de61 | 2011-01-26 04:00:11 +0000 | [diff] [blame] | 319 | } |
| 320 | |
Daniel Dunbar | d3dcb4f8 | 2008-09-28 01:03:14 +0000 | [diff] [blame] | 321 | public: |
Anders Carlsson | 33c1b65 | 2009-02-10 06:07:49 +0000 | [diff] [blame] | 322 | /// ObjCEHValueStack - Stack of Objective-C exception values, used for |
| 323 | /// rethrows. |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 324 | SmallVector<llvm::Value*, 8> ObjCEHValueStack; |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 325 | |
John McCall | 6b0feb7 | 2011-06-22 02:32:12 +0000 | [diff] [blame] | 326 | /// A class controlling the emission of a finally block. |
| 327 | class FinallyInfo { |
| 328 | /// Where the catchall's edge through the cleanup should go. |
| 329 | JumpDest RethrowDest; |
Anders Carlsson | 66c384a | 2009-02-08 07:46:24 +0000 | [diff] [blame] | 330 | |
John McCall | 6b0feb7 | 2011-06-22 02:32:12 +0000 | [diff] [blame] | 331 | /// A function to call to enter the catch. |
| 332 | llvm::Constant *BeginCatchFn; |
| 333 | |
| 334 | /// An i1 variable indicating whether or not the @finally is |
| 335 | /// running for an exception. |
| 336 | llvm::AllocaInst *ForEHVar; |
| 337 | |
| 338 | /// An i8* variable into which the exception pointer to rethrow |
| 339 | /// has been saved. |
| 340 | llvm::AllocaInst *SavedExnVar; |
| 341 | |
| 342 | public: |
| 343 | void enter(CodeGenFunction &CGF, const Stmt *Finally, |
| 344 | llvm::Constant *beginCatchFn, llvm::Constant *endCatchFn, |
| 345 | llvm::Constant *rethrowFn); |
| 346 | void exit(CodeGenFunction &CGF); |
| 347 | }; |
Mike Stump | aff69af | 2009-12-09 03:35:49 +0000 | [diff] [blame] | 348 | |
John McCall | ce1de61 | 2011-01-26 04:00:11 +0000 | [diff] [blame] | 349 | /// pushFullExprCleanup - Push a cleanup to be run at the end of the |
| 350 | /// current full-expression. Safe against the possibility that |
| 351 | /// we're currently inside a conditionally-evaluated expression. |
John McCall | e4df6c8 | 2011-01-28 08:37:24 +0000 | [diff] [blame] | 352 | template <class T, class A0> |
| 353 | void pushFullExprCleanup(CleanupKind kind, A0 a0) { |
| 354 | // If we're not in a conditional branch, or if none of the |
| 355 | // arguments requires saving, then use the unconditional cleanup. |
John McCall | 5fcf8da | 2011-07-12 00:15:30 +0000 | [diff] [blame] | 356 | if (!isInConditionalBranch()) |
| 357 | return EHStack.pushCleanup<T>(kind, a0); |
John McCall | e4df6c8 | 2011-01-28 08:37:24 +0000 | [diff] [blame] | 358 | |
John McCall | cb5f77f | 2011-01-28 10:53:53 +0000 | [diff] [blame] | 359 | typename DominatingValue<A0>::saved_type a0_saved = saveValueInCond(a0); |
John McCall | e4df6c8 | 2011-01-28 08:37:24 +0000 | [diff] [blame] | 360 | |
| 361 | typedef EHScopeStack::ConditionalCleanup1<T, A0> CleanupType; |
| 362 | EHStack.pushCleanup<CleanupType>(kind, a0_saved); |
| 363 | initFullExprCleanup(); |
| 364 | } |
| 365 | |
| 366 | /// pushFullExprCleanup - Push a cleanup to be run at the end of the |
| 367 | /// current full-expression. Safe against the possibility that |
| 368 | /// we're currently inside a conditionally-evaluated expression. |
John McCall | ce1de61 | 2011-01-26 04:00:11 +0000 | [diff] [blame] | 369 | template <class T, class A0, class A1> |
| 370 | void pushFullExprCleanup(CleanupKind kind, A0 a0, A1 a1) { |
| 371 | // If we're not in a conditional branch, or if none of the |
| 372 | // arguments requires saving, then use the unconditional cleanup. |
John McCall | 5fcf8da | 2011-07-12 00:15:30 +0000 | [diff] [blame] | 373 | if (!isInConditionalBranch()) |
| 374 | return EHStack.pushCleanup<T>(kind, a0, a1); |
John McCall | ce1de61 | 2011-01-26 04:00:11 +0000 | [diff] [blame] | 375 | |
John McCall | cb5f77f | 2011-01-28 10:53:53 +0000 | [diff] [blame] | 376 | typename DominatingValue<A0>::saved_type a0_saved = saveValueInCond(a0); |
| 377 | typename DominatingValue<A1>::saved_type a1_saved = saveValueInCond(a1); |
John McCall | ce1de61 | 2011-01-26 04:00:11 +0000 | [diff] [blame] | 378 | |
| 379 | typedef EHScopeStack::ConditionalCleanup2<T, A0, A1> CleanupType; |
John McCall | e4df6c8 | 2011-01-28 08:37:24 +0000 | [diff] [blame] | 380 | EHStack.pushCleanup<CleanupType>(kind, a0_saved, a1_saved); |
| 381 | initFullExprCleanup(); |
John McCall | ce1de61 | 2011-01-26 04:00:11 +0000 | [diff] [blame] | 382 | } |
| 383 | |
Douglas Gregor | 58df509 | 2011-06-22 16:12:01 +0000 | [diff] [blame] | 384 | /// pushFullExprCleanup - Push a cleanup to be run at the end of the |
| 385 | /// current full-expression. Safe against the possibility that |
| 386 | /// we're currently inside a conditionally-evaluated expression. |
| 387 | template <class T, class A0, class A1, class A2> |
| 388 | void pushFullExprCleanup(CleanupKind kind, A0 a0, A1 a1, A2 a2) { |
| 389 | // If we're not in a conditional branch, or if none of the |
| 390 | // arguments requires saving, then use the unconditional cleanup. |
| 391 | if (!isInConditionalBranch()) { |
John McCall | 5fcf8da | 2011-07-12 00:15:30 +0000 | [diff] [blame] | 392 | return EHStack.pushCleanup<T>(kind, a0, a1, a2); |
Douglas Gregor | 58df509 | 2011-06-22 16:12:01 +0000 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | typename DominatingValue<A0>::saved_type a0_saved = saveValueInCond(a0); |
| 396 | typename DominatingValue<A1>::saved_type a1_saved = saveValueInCond(a1); |
| 397 | typename DominatingValue<A2>::saved_type a2_saved = saveValueInCond(a2); |
| 398 | |
| 399 | typedef EHScopeStack::ConditionalCleanup3<T, A0, A1, A2> CleanupType; |
| 400 | EHStack.pushCleanup<CleanupType>(kind, a0_saved, a1_saved, a2_saved); |
| 401 | initFullExprCleanup(); |
| 402 | } |
| 403 | |
John McCall | 4bd0fb1 | 2011-07-12 16:41:08 +0000 | [diff] [blame] | 404 | /// pushFullExprCleanup - Push a cleanup to be run at the end of the |
| 405 | /// current full-expression. Safe against the possibility that |
| 406 | /// we're currently inside a conditionally-evaluated expression. |
| 407 | template <class T, class A0, class A1, class A2, class A3> |
| 408 | void pushFullExprCleanup(CleanupKind kind, A0 a0, A1 a1, A2 a2, A3 a3) { |
| 409 | // If we're not in a conditional branch, or if none of the |
| 410 | // arguments requires saving, then use the unconditional cleanup. |
| 411 | if (!isInConditionalBranch()) { |
| 412 | return EHStack.pushCleanup<T>(kind, a0, a1, a2, a3); |
| 413 | } |
| 414 | |
| 415 | typename DominatingValue<A0>::saved_type a0_saved = saveValueInCond(a0); |
| 416 | typename DominatingValue<A1>::saved_type a1_saved = saveValueInCond(a1); |
| 417 | typename DominatingValue<A2>::saved_type a2_saved = saveValueInCond(a2); |
| 418 | typename DominatingValue<A3>::saved_type a3_saved = saveValueInCond(a3); |
| 419 | |
| 420 | typedef EHScopeStack::ConditionalCleanup4<T, A0, A1, A2, A3> CleanupType; |
| 421 | EHStack.pushCleanup<CleanupType>(kind, a0_saved, a1_saved, |
| 422 | a2_saved, a3_saved); |
| 423 | initFullExprCleanup(); |
| 424 | } |
| 425 | |
Richard Smith | 736a947 | 2013-06-12 20:42:33 +0000 | [diff] [blame] | 426 | /// \brief Queue a cleanup to be pushed after finishing the current |
| 427 | /// full-expression. |
| 428 | template <class T, class A0, class A1, class A2, class A3> |
| 429 | void pushCleanupAfterFullExpr(CleanupKind Kind, A0 a0, A1 a1, A2 a2, A3 a3) { |
| 430 | assert(!isInConditionalBranch() && "can't defer conditional cleanup"); |
| 431 | |
| 432 | LifetimeExtendedCleanupHeader Header = { sizeof(T), Kind }; |
| 433 | |
| 434 | size_t OldSize = LifetimeExtendedCleanupStack.size(); |
| 435 | LifetimeExtendedCleanupStack.resize( |
| 436 | LifetimeExtendedCleanupStack.size() + sizeof(Header) + Header.Size); |
| 437 | |
| 438 | char *Buffer = &LifetimeExtendedCleanupStack[OldSize]; |
| 439 | new (Buffer) LifetimeExtendedCleanupHeader(Header); |
| 440 | new (Buffer + sizeof(Header)) T(a0, a1, a2, a3); |
| 441 | } |
| 442 | |
John McCall | f4beacd | 2011-11-10 10:43:54 +0000 | [diff] [blame] | 443 | /// Set up the last cleaup that was pushed as a conditional |
| 444 | /// full-expression cleanup. |
| 445 | void initFullExprCleanup(); |
| 446 | |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 447 | /// PushDestructorCleanup - Push a cleanup to call the |
| 448 | /// complete-object destructor of an object of the given type at the |
| 449 | /// given address. Does nothing if T is not a C++ class type with a |
| 450 | /// non-trivial destructor. |
| 451 | void PushDestructorCleanup(QualType T, llvm::Value *Addr); |
| 452 | |
John McCall | 8680f87 | 2010-07-21 06:29:51 +0000 | [diff] [blame] | 453 | /// PushDestructorCleanup - Push a cleanup to call the |
| 454 | /// complete-object variant of the given destructor on the object at |
| 455 | /// the given address. |
| 456 | void PushDestructorCleanup(const CXXDestructorDecl *Dtor, |
| 457 | llvm::Value *Addr); |
| 458 | |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 459 | /// PopCleanupBlock - Will pop the cleanup entry on the stack and |
| 460 | /// process all branch fixups. |
Adrian Prantl | dc237b5 | 2013-05-16 00:41:26 +0000 | [diff] [blame] | 461 | void PopCleanupBlock(bool FallThroughIsBranchThrough = false); |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 462 | |
John McCall | 824c2f5 | 2010-09-14 07:57:04 +0000 | [diff] [blame] | 463 | /// DeactivateCleanupBlock - Deactivates the given cleanup block. |
| 464 | /// The block cannot be reactivated. Pops it if it's the top of the |
| 465 | /// stack. |
John McCall | f4beacd | 2011-11-10 10:43:54 +0000 | [diff] [blame] | 466 | /// |
| 467 | /// \param DominatingIP - An instruction which is known to |
| 468 | /// dominate the current IP (if set) and which lies along |
| 469 | /// all paths of execution between the current IP and the |
| 470 | /// the point at which the cleanup comes into scope. |
| 471 | void DeactivateCleanupBlock(EHScopeStack::stable_iterator Cleanup, |
| 472 | llvm::Instruction *DominatingIP); |
John McCall | 824c2f5 | 2010-09-14 07:57:04 +0000 | [diff] [blame] | 473 | |
| 474 | /// ActivateCleanupBlock - Activates an initially-inactive cleanup. |
| 475 | /// Cannot be used to resurrect a deactivated cleanup. |
John McCall | f4beacd | 2011-11-10 10:43:54 +0000 | [diff] [blame] | 476 | /// |
| 477 | /// \param DominatingIP - An instruction which is known to |
| 478 | /// dominate the current IP (if set) and which lies along |
| 479 | /// all paths of execution between the current IP and the |
| 480 | /// the point at which the cleanup comes into scope. |
| 481 | void ActivateCleanupBlock(EHScopeStack::stable_iterator Cleanup, |
| 482 | llvm::Instruction *DominatingIP); |
John McCall | 612942d | 2010-08-13 21:20:51 +0000 | [diff] [blame] | 483 | |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 484 | /// \brief Enters a new scope for capturing cleanups, all of which |
| 485 | /// will be executed once the scope is exited. |
| 486 | class RunCleanupsScope { |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 487 | EHScopeStack::stable_iterator CleanupStackDepth; |
Richard Smith | 736a947 | 2013-06-12 20:42:33 +0000 | [diff] [blame] | 488 | size_t LifetimeExtendedCleanupStackSize; |
Douglas Gregor | 965f450 | 2009-11-24 16:43:22 +0000 | [diff] [blame] | 489 | bool OldDidCallStackSave; |
John McCall | 07e6026 | 2013-03-01 01:24:35 +0000 | [diff] [blame] | 490 | protected: |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 491 | bool PerformCleanup; |
John McCall | 07e6026 | 2013-03-01 01:24:35 +0000 | [diff] [blame] | 492 | private: |
Douglas Gregor | 965f450 | 2009-11-24 16:43:22 +0000 | [diff] [blame] | 493 | |
Dmitri Gribenko | a664e5b | 2012-09-15 20:20:27 +0000 | [diff] [blame] | 494 | RunCleanupsScope(const RunCleanupsScope &) LLVM_DELETED_FUNCTION; |
| 495 | void operator=(const RunCleanupsScope &) LLVM_DELETED_FUNCTION; |
Douglas Gregor | 965f450 | 2009-11-24 16:43:22 +0000 | [diff] [blame] | 496 | |
Eric Christopher | a9d3497 | 2011-10-19 00:43:52 +0000 | [diff] [blame] | 497 | protected: |
| 498 | CodeGenFunction& CGF; |
Will Dietz | f54319c | 2013-01-18 11:30:38 +0000 | [diff] [blame] | 499 | |
Douglas Gregor | 965f450 | 2009-11-24 16:43:22 +0000 | [diff] [blame] | 500 | public: |
| 501 | /// \brief Enter a new cleanup scope. |
Michael J. Spencer | f5a1fbc | 2010-10-19 06:39:39 +0000 | [diff] [blame] | 502 | explicit RunCleanupsScope(CodeGenFunction &CGF) |
Eric Christopher | a9d3497 | 2011-10-19 00:43:52 +0000 | [diff] [blame] | 503 | : PerformCleanup(true), CGF(CGF) |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 504 | { |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 505 | CleanupStackDepth = CGF.EHStack.stable_begin(); |
Richard Smith | 736a947 | 2013-06-12 20:42:33 +0000 | [diff] [blame] | 506 | LifetimeExtendedCleanupStackSize = |
| 507 | CGF.LifetimeExtendedCleanupStack.size(); |
Douglas Gregor | 965f450 | 2009-11-24 16:43:22 +0000 | [diff] [blame] | 508 | OldDidCallStackSave = CGF.DidCallStackSave; |
Argyrios Kyrtzidis | 9efa1ce | 2010-09-14 00:42:34 +0000 | [diff] [blame] | 509 | CGF.DidCallStackSave = false; |
Douglas Gregor | 965f450 | 2009-11-24 16:43:22 +0000 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | /// \brief Exit this cleanup scope, emitting any accumulated |
| 513 | /// cleanups. |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 514 | ~RunCleanupsScope() { |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 515 | if (PerformCleanup) { |
| 516 | CGF.DidCallStackSave = OldDidCallStackSave; |
Richard Smith | 736a947 | 2013-06-12 20:42:33 +0000 | [diff] [blame] | 517 | CGF.PopCleanupBlocks(CleanupStackDepth, |
| 518 | LifetimeExtendedCleanupStackSize); |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 519 | } |
| 520 | } |
| 521 | |
| 522 | /// \brief Determine whether this scope requires any cleanups. |
| 523 | bool requiresCleanups() const { |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 524 | return CGF.EHStack.stable_begin() != CleanupStackDepth; |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | /// \brief Force the emission of cleanups now, instead of waiting |
| 528 | /// until this object is destroyed. |
| 529 | void ForceCleanup() { |
| 530 | assert(PerformCleanup && "Already forced cleanup"); |
Douglas Gregor | 965f450 | 2009-11-24 16:43:22 +0000 | [diff] [blame] | 531 | CGF.DidCallStackSave = OldDidCallStackSave; |
Richard Smith | 736a947 | 2013-06-12 20:42:33 +0000 | [diff] [blame] | 532 | CGF.PopCleanupBlocks(CleanupStackDepth, |
| 533 | LifetimeExtendedCleanupStackSize); |
Douglas Gregor | 680f861 | 2009-11-24 21:15:44 +0000 | [diff] [blame] | 534 | PerformCleanup = false; |
Douglas Gregor | 965f450 | 2009-11-24 16:43:22 +0000 | [diff] [blame] | 535 | } |
| 536 | }; |
| 537 | |
Eric Christopher | a9d3497 | 2011-10-19 00:43:52 +0000 | [diff] [blame] | 538 | class LexicalScope: protected RunCleanupsScope { |
| 539 | SourceRange Range; |
Nadav Rotem | 1da3094 | 2013-03-23 06:43:35 +0000 | [diff] [blame] | 540 | SmallVector<const LabelDecl*, 4> Labels; |
| 541 | LexicalScope *ParentScope; |
Eric Christopher | a9d3497 | 2011-10-19 00:43:52 +0000 | [diff] [blame] | 542 | |
Dmitri Gribenko | a664e5b | 2012-09-15 20:20:27 +0000 | [diff] [blame] | 543 | LexicalScope(const LexicalScope &) LLVM_DELETED_FUNCTION; |
| 544 | void operator=(const LexicalScope &) LLVM_DELETED_FUNCTION; |
Eric Christopher | a9d3497 | 2011-10-19 00:43:52 +0000 | [diff] [blame] | 545 | |
| 546 | public: |
| 547 | /// \brief Enter a new cleanup scope. |
| 548 | explicit LexicalScope(CodeGenFunction &CGF, SourceRange Range) |
Nadav Rotem | 1da3094 | 2013-03-23 06:43:35 +0000 | [diff] [blame] | 549 | : RunCleanupsScope(CGF), Range(Range), ParentScope(CGF.CurLexicalScope) { |
| 550 | CGF.CurLexicalScope = this; |
Eric Christopher | a9d3497 | 2011-10-19 00:43:52 +0000 | [diff] [blame] | 551 | if (CGDebugInfo *DI = CGF.getDebugInfo()) |
| 552 | DI->EmitLexicalBlockStart(CGF.Builder, Range.getBegin()); |
| 553 | } |
| 554 | |
Nadav Rotem | 1da3094 | 2013-03-23 06:43:35 +0000 | [diff] [blame] | 555 | void addLabel(const LabelDecl *label) { |
| 556 | assert(PerformCleanup && "adding label to dead scope?"); |
| 557 | Labels.push_back(label); |
| 558 | } |
| 559 | |
Eric Christopher | a9d3497 | 2011-10-19 00:43:52 +0000 | [diff] [blame] | 560 | /// \brief Exit this cleanup scope, emitting any accumulated |
| 561 | /// cleanups. |
| 562 | ~LexicalScope() { |
Adrian Prantl | 5d5b67c | 2013-04-01 19:02:06 +0000 | [diff] [blame] | 563 | if (CGDebugInfo *DI = CGF.getDebugInfo()) |
| 564 | DI->EmitLexicalBlockEnd(CGF.Builder, Range.getEnd()); |
| 565 | |
Nadav Rotem | 1da3094 | 2013-03-23 06:43:35 +0000 | [diff] [blame] | 566 | // If we should perform a cleanup, force them now. Note that |
| 567 | // this ends the cleanup scope before rescoping any labels. |
| 568 | if (PerformCleanup) ForceCleanup(); |
Eric Christopher | a9d3497 | 2011-10-19 00:43:52 +0000 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | /// \brief Force the emission of cleanups now, instead of waiting |
| 572 | /// until this object is destroyed. |
| 573 | void ForceCleanup() { |
Nadav Rotem | 1da3094 | 2013-03-23 06:43:35 +0000 | [diff] [blame] | 574 | CGF.CurLexicalScope = ParentScope; |
Adrian Prantl | 5d5b67c | 2013-04-01 19:02:06 +0000 | [diff] [blame] | 575 | RunCleanupsScope::ForceCleanup(); |
| 576 | |
Nadav Rotem | 1da3094 | 2013-03-23 06:43:35 +0000 | [diff] [blame] | 577 | if (!Labels.empty()) |
| 578 | rescopeLabels(); |
Eric Christopher | a9d3497 | 2011-10-19 00:43:52 +0000 | [diff] [blame] | 579 | } |
Nadav Rotem | 1da3094 | 2013-03-23 06:43:35 +0000 | [diff] [blame] | 580 | |
| 581 | void rescopeLabels(); |
Eric Christopher | a9d3497 | 2011-10-19 00:43:52 +0000 | [diff] [blame] | 582 | }; |
| 583 | |
Anders Carlsson | b9fd57f | 2010-03-30 03:14:41 +0000 | [diff] [blame] | 584 | |
Richard Smith | 736a947 | 2013-06-12 20:42:33 +0000 | [diff] [blame] | 585 | /// \brief Takes the old cleanup stack size and emits the cleanup blocks |
| 586 | /// that have been added. |
Adrian Prantl | dc237b5 | 2013-05-16 00:41:26 +0000 | [diff] [blame] | 587 | void PopCleanupBlocks(EHScopeStack::stable_iterator OldCleanupStackSize); |
Anders Carlsson | b9fd57f | 2010-03-30 03:14:41 +0000 | [diff] [blame] | 588 | |
Richard Smith | 736a947 | 2013-06-12 20:42:33 +0000 | [diff] [blame] | 589 | /// \brief Takes the old cleanup stack size and emits the cleanup blocks |
| 590 | /// that have been added, then adds all lifetime-extended cleanups from |
| 591 | /// the given position to the stack. |
| 592 | void PopCleanupBlocks(EHScopeStack::stable_iterator OldCleanupStackSize, |
| 593 | size_t OldLifetimeExtendedStackSize); |
| 594 | |
John McCall | ad5d61e | 2010-07-23 21:56:41 +0000 | [diff] [blame] | 595 | void ResolveBranchFixups(llvm::BasicBlock *Target); |
| 596 | |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 597 | /// The given basic block lies in the current EH scope, but may be a |
| 598 | /// target of a potentially scope-crossing jump; get a stable handle |
| 599 | /// to which we can perform this jump later. |
John McCall | ad5d61e | 2010-07-23 21:56:41 +0000 | [diff] [blame] | 600 | JumpDest getJumpDestInCurrentScope(llvm::BasicBlock *Target) { |
John McCall | ba80390 | 2010-07-28 01:07:35 +0000 | [diff] [blame] | 601 | return JumpDest(Target, |
| 602 | EHStack.getInnermostNormalCleanup(), |
| 603 | NextCleanupDestIndex++); |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 604 | } |
Anders Carlsson | be0f76a | 2009-02-07 23:50:39 +0000 | [diff] [blame] | 605 | |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 606 | /// The given basic block lies in the current EH scope, but may be a |
| 607 | /// target of a potentially scope-crossing jump; get a stable handle |
| 608 | /// to which we can perform this jump later. |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 609 | JumpDest getJumpDestInCurrentScope(StringRef Name = StringRef()) { |
John McCall | ad5d61e | 2010-07-23 21:56:41 +0000 | [diff] [blame] | 610 | return getJumpDestInCurrentScope(createBasicBlock(Name)); |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | /// EmitBranchThroughCleanup - Emit a branch from the current insert |
| 614 | /// block through the normal cleanup handling code (if any) and then |
| 615 | /// on to \arg Dest. |
| 616 | void EmitBranchThroughCleanup(JumpDest Dest); |
Chris Lattner | bc204c8 | 2011-04-17 00:54:30 +0000 | [diff] [blame] | 617 | |
Justin Bogner | e25ffdf | 2014-01-21 00:35:11 +0000 | [diff] [blame] | 618 | /// isObviouslyBranchWithoutCleanups - Return true if a branch to the |
| 619 | /// specified destination obviously has no cleanups to run. 'false' is always |
| 620 | /// a conservatively correct answer for this method. |
| 621 | bool isObviouslyBranchWithoutCleanups(JumpDest Dest) const; |
| 622 | |
John McCall | 8e4c74b | 2011-08-11 02:22:43 +0000 | [diff] [blame] | 623 | /// popCatchScope - Pops the catch scope at the top of the EHScope |
| 624 | /// stack, emitting any required code (other than the catch handlers |
| 625 | /// themselves). |
| 626 | void popCatchScope(); |
John McCall | ad5d61e | 2010-07-23 21:56:41 +0000 | [diff] [blame] | 627 | |
David Chisnall | 9a837be | 2012-11-07 16:50:40 +0000 | [diff] [blame] | 628 | llvm::BasicBlock *getEHResumeBlock(bool isCleanup); |
John McCall | 8e4c74b | 2011-08-11 02:22:43 +0000 | [diff] [blame] | 629 | llvm::BasicBlock *getEHDispatchBlock(EHScopeStack::stable_iterator scope); |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 630 | |
John McCall | ce1de61 | 2011-01-26 04:00:11 +0000 | [diff] [blame] | 631 | /// An object to manage conditionally-evaluated expressions. |
| 632 | class ConditionalEvaluation { |
| 633 | llvm::BasicBlock *StartBB; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 634 | |
John McCall | ce1de61 | 2011-01-26 04:00:11 +0000 | [diff] [blame] | 635 | public: |
| 636 | ConditionalEvaluation(CodeGenFunction &CGF) |
| 637 | : StartBB(CGF.Builder.GetInsertBlock()) {} |
Michael J. Spencer | f5a1fbc | 2010-10-19 06:39:39 +0000 | [diff] [blame] | 638 | |
John McCall | ce1de61 | 2011-01-26 04:00:11 +0000 | [diff] [blame] | 639 | void begin(CodeGenFunction &CGF) { |
| 640 | assert(CGF.OutermostConditional != this); |
| 641 | if (!CGF.OutermostConditional) |
| 642 | CGF.OutermostConditional = this; |
| 643 | } |
| 644 | |
| 645 | void end(CodeGenFunction &CGF) { |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 646 | assert(CGF.OutermostConditional != nullptr); |
John McCall | ce1de61 | 2011-01-26 04:00:11 +0000 | [diff] [blame] | 647 | if (CGF.OutermostConditional == this) |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 648 | CGF.OutermostConditional = nullptr; |
John McCall | ce1de61 | 2011-01-26 04:00:11 +0000 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | /// Returns a block which will be executed prior to each |
| 652 | /// evaluation of the conditional code. |
| 653 | llvm::BasicBlock *getStartingBlock() const { |
| 654 | return StartBB; |
| 655 | } |
| 656 | }; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 657 | |
John McCall | 7f9c92a | 2010-09-17 00:50:28 +0000 | [diff] [blame] | 658 | /// isInConditionalBranch - Return true if we're currently emitting |
| 659 | /// one branch or the other of a conditional expression. |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 660 | bool isInConditionalBranch() const { return OutermostConditional != nullptr; } |
John McCall | ce1de61 | 2011-01-26 04:00:11 +0000 | [diff] [blame] | 661 | |
John McCall | f4beacd | 2011-11-10 10:43:54 +0000 | [diff] [blame] | 662 | void setBeforeOutermostConditional(llvm::Value *value, llvm::Value *addr) { |
| 663 | assert(isInConditionalBranch()); |
| 664 | llvm::BasicBlock *block = OutermostConditional->getStartingBlock(); |
| 665 | new llvm::StoreInst(value, addr, &block->back()); |
| 666 | } |
| 667 | |
John McCall | ce1de61 | 2011-01-26 04:00:11 +0000 | [diff] [blame] | 668 | /// An RAII object to record that we're evaluating a statement |
| 669 | /// expression. |
| 670 | class StmtExprEvaluation { |
| 671 | CodeGenFunction &CGF; |
| 672 | |
| 673 | /// We have to save the outermost conditional: cleanups in a |
| 674 | /// statement expression aren't conditional just because the |
| 675 | /// StmtExpr is. |
| 676 | ConditionalEvaluation *SavedOutermostConditional; |
| 677 | |
| 678 | public: |
| 679 | StmtExprEvaluation(CodeGenFunction &CGF) |
| 680 | : CGF(CGF), SavedOutermostConditional(CGF.OutermostConditional) { |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 681 | CGF.OutermostConditional = nullptr; |
John McCall | ce1de61 | 2011-01-26 04:00:11 +0000 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | ~StmtExprEvaluation() { |
| 685 | CGF.OutermostConditional = SavedOutermostConditional; |
| 686 | CGF.EnsureInsertPoint(); |
| 687 | } |
| 688 | }; |
John McCall | 1bf5846 | 2011-02-16 08:02:54 +0000 | [diff] [blame] | 689 | |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 690 | /// An object which temporarily prevents a value from being |
| 691 | /// destroyed by aggressive peephole optimizations that assume that |
| 692 | /// all uses of a value have been realized in the IR. |
| 693 | class PeepholeProtection { |
| 694 | llvm::Instruction *Inst; |
| 695 | friend class CodeGenFunction; |
| 696 | |
| 697 | public: |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 698 | PeepholeProtection() : Inst(nullptr) {} |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 699 | }; |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 700 | |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 701 | /// A non-RAII class containing all the information about a bound |
| 702 | /// opaque value. OpaqueValueMapping, below, is a RAII wrapper for |
| 703 | /// this which makes individual mappings very simple; using this |
| 704 | /// class directly is useful when you have a variable number of |
| 705 | /// opaque values or don't want the RAII functionality for some |
| 706 | /// reason. |
| 707 | class OpaqueValueMappingData { |
John McCall | 1bf5846 | 2011-02-16 08:02:54 +0000 | [diff] [blame] | 708 | const OpaqueValueExpr *OpaqueValue; |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 709 | bool BoundLValue; |
| 710 | CodeGenFunction::PeepholeProtection Protection; |
John McCall | 1bf5846 | 2011-02-16 08:02:54 +0000 | [diff] [blame] | 711 | |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 712 | OpaqueValueMappingData(const OpaqueValueExpr *ov, |
| 713 | bool boundLValue) |
| 714 | : OpaqueValue(ov), BoundLValue(boundLValue) {} |
John McCall | 1bf5846 | 2011-02-16 08:02:54 +0000 | [diff] [blame] | 715 | public: |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 716 | OpaqueValueMappingData() : OpaqueValue(nullptr) {} |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 717 | |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 718 | static bool shouldBindAsLValue(const Expr *expr) { |
John McCall | 9a54961 | 2011-11-08 22:54:08 +0000 | [diff] [blame] | 719 | // gl-values should be bound as l-values for obvious reasons. |
| 720 | // Records should be bound as l-values because IR generation |
| 721 | // always keeps them in memory. Expressions of function type |
| 722 | // act exactly like l-values but are formally required to be |
| 723 | // r-values in C. |
| 724 | return expr->isGLValue() || |
Fariborz Jahanian | 7741101 | 2014-02-14 19:37:25 +0000 | [diff] [blame] | 725 | expr->getType()->isFunctionType() || |
| 726 | hasAggregateEvaluationKind(expr->getType()); |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 727 | } |
| 728 | |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 729 | static OpaqueValueMappingData bind(CodeGenFunction &CGF, |
| 730 | const OpaqueValueExpr *ov, |
| 731 | const Expr *e) { |
| 732 | if (shouldBindAsLValue(ov)) |
| 733 | return bind(CGF, ov, CGF.EmitLValue(e)); |
| 734 | return bind(CGF, ov, CGF.EmitAnyExpr(e)); |
| 735 | } |
| 736 | |
| 737 | static OpaqueValueMappingData bind(CodeGenFunction &CGF, |
| 738 | const OpaqueValueExpr *ov, |
| 739 | const LValue &lv) { |
| 740 | assert(shouldBindAsLValue(ov)); |
| 741 | CGF.OpaqueLValues.insert(std::make_pair(ov, lv)); |
| 742 | return OpaqueValueMappingData(ov, true); |
| 743 | } |
| 744 | |
| 745 | static OpaqueValueMappingData bind(CodeGenFunction &CGF, |
| 746 | const OpaqueValueExpr *ov, |
| 747 | const RValue &rv) { |
| 748 | assert(!shouldBindAsLValue(ov)); |
| 749 | CGF.OpaqueRValues.insert(std::make_pair(ov, rv)); |
| 750 | |
| 751 | OpaqueValueMappingData data(ov, false); |
| 752 | |
| 753 | // Work around an extremely aggressive peephole optimization in |
| 754 | // EmitScalarConversion which assumes that all other uses of a |
| 755 | // value are extant. |
| 756 | data.Protection = CGF.protectFromPeepholes(rv); |
| 757 | |
| 758 | return data; |
| 759 | } |
| 760 | |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 761 | bool isValid() const { return OpaqueValue != nullptr; } |
| 762 | void clear() { OpaqueValue = nullptr; } |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 763 | |
| 764 | void unbind(CodeGenFunction &CGF) { |
| 765 | assert(OpaqueValue && "no data to unbind!"); |
| 766 | |
| 767 | if (BoundLValue) { |
| 768 | CGF.OpaqueLValues.erase(OpaqueValue); |
| 769 | } else { |
| 770 | CGF.OpaqueRValues.erase(OpaqueValue); |
| 771 | CGF.unprotectFromPeepholes(Protection); |
| 772 | } |
| 773 | } |
| 774 | }; |
| 775 | |
| 776 | /// An RAII object to set (and then clear) a mapping for an OpaqueValueExpr. |
| 777 | class OpaqueValueMapping { |
| 778 | CodeGenFunction &CGF; |
| 779 | OpaqueValueMappingData Data; |
| 780 | |
| 781 | public: |
| 782 | static bool shouldBindAsLValue(const Expr *expr) { |
| 783 | return OpaqueValueMappingData::shouldBindAsLValue(expr); |
| 784 | } |
| 785 | |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 786 | /// Build the opaque value mapping for the given conditional |
| 787 | /// operator if it's the GNU ?: extension. This is a common |
| 788 | /// enough pattern that the convenience operator is really |
| 789 | /// helpful. |
| 790 | /// |
| 791 | OpaqueValueMapping(CodeGenFunction &CGF, |
| 792 | const AbstractConditionalOperator *op) : CGF(CGF) { |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 793 | if (isa<ConditionalOperator>(op)) |
| 794 | // Leave Data empty. |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 795 | return; |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 796 | |
| 797 | const BinaryConditionalOperator *e = cast<BinaryConditionalOperator>(op); |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 798 | Data = OpaqueValueMappingData::bind(CGF, e->getOpaqueValue(), |
| 799 | e->getCommon()); |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 800 | } |
| 801 | |
John McCall | 1bf5846 | 2011-02-16 08:02:54 +0000 | [diff] [blame] | 802 | OpaqueValueMapping(CodeGenFunction &CGF, |
| 803 | const OpaqueValueExpr *opaqueValue, |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 804 | LValue lvalue) |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 805 | : CGF(CGF), Data(OpaqueValueMappingData::bind(CGF, opaqueValue, lvalue)) { |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | OpaqueValueMapping(CodeGenFunction &CGF, |
| 809 | const OpaqueValueExpr *opaqueValue, |
| 810 | RValue rvalue) |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 811 | : CGF(CGF), Data(OpaqueValueMappingData::bind(CGF, opaqueValue, rvalue)) { |
John McCall | 1bf5846 | 2011-02-16 08:02:54 +0000 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | void pop() { |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 815 | Data.unbind(CGF); |
| 816 | Data.clear(); |
John McCall | 1bf5846 | 2011-02-16 08:02:54 +0000 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | ~OpaqueValueMapping() { |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 820 | if (Data.isValid()) Data.unbind(CGF); |
John McCall | 1bf5846 | 2011-02-16 08:02:54 +0000 | [diff] [blame] | 821 | } |
| 822 | }; |
Fariborz Jahanian | a3e54bd | 2010-11-16 19:29:39 +0000 | [diff] [blame] | 823 | |
| 824 | /// getByrefValueFieldNumber - Given a declaration, returns the LLVM field |
| 825 | /// number that holds the value. |
| 826 | unsigned getByRefValueLLVMField(const ValueDecl *VD) const; |
Fariborz Jahanian | 2f2fa72 | 2011-01-26 23:08:27 +0000 | [diff] [blame] | 827 | |
| 828 | /// BuildBlockByrefAddress - Computes address location of the |
| 829 | /// variable which is declared as __block. |
| 830 | llvm::Value *BuildBlockByrefAddress(llvm::Value *BaseAddr, |
| 831 | const VarDecl *V); |
Chris Lattner | 2da04b3 | 2007-08-24 05:35:26 +0000 | [diff] [blame] | 832 | private: |
Chris Lattner | 6c4d255 | 2009-10-28 23:59:40 +0000 | [diff] [blame] | 833 | CGDebugInfo *DebugInfo; |
Devang Patel | d6ffebb | 2011-03-07 18:45:56 +0000 | [diff] [blame] | 834 | bool DisableDebugInfo; |
Mike Stump | c6ea7c1 | 2009-02-17 17:00:02 +0000 | [diff] [blame] | 835 | |
John McCall | 9b382dd | 2011-05-28 21:13:02 +0000 | [diff] [blame] | 836 | /// DidCallStackSave - Whether llvm.stacksave has been called. Used to avoid |
| 837 | /// calling llvm.stacksave for multiple VLAs in the same scope. |
| 838 | bool DidCallStackSave; |
| 839 | |
Mike Stump | e5311b0 | 2009-11-30 20:08:49 +0000 | [diff] [blame] | 840 | /// IndirectBranch - The first time an indirect goto is seen we create a block |
| 841 | /// with an indirect branch. Every time we see the address of a label taken, |
| 842 | /// we add the label to the indirect goto. Every subsequent indirect goto is |
| 843 | /// codegen'd as a jump to the IndirectBranch's basic block. |
Chris Lattner | 6c4d255 | 2009-10-28 23:59:40 +0000 | [diff] [blame] | 844 | llvm::IndirectBrInst *IndirectBranch; |
Daniel Dunbar | 88402ce | 2008-08-04 16:51:22 +0000 | [diff] [blame] | 845 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 846 | /// LocalDeclMap - This keeps track of the LLVM allocas or globals for local C |
| 847 | /// decls. |
John McCall | 351762c | 2011-02-07 10:33:21 +0000 | [diff] [blame] | 848 | typedef llvm::DenseMap<const Decl*, llvm::Value*> DeclMapTy; |
| 849 | DeclMapTy LocalDeclMap; |
Chris Lattner | 84915fa | 2007-06-02 04:16:21 +0000 | [diff] [blame] | 850 | |
Chris Lattner | ac24820 | 2007-05-30 00:13:02 +0000 | [diff] [blame] | 851 | /// LabelMap - This keeps track of the LLVM basic block for each C label. |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 852 | llvm::DenseMap<const LabelDecl*, JumpDest> LabelMap; |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 853 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 854 | // BreakContinueStack - This keeps track of where break and continue |
Bob Wilson | bf854f0 | 2014-02-17 19:21:09 +0000 | [diff] [blame] | 855 | // statements should jump to. |
Chris Lattner | e73e432 | 2007-07-16 21:28:45 +0000 | [diff] [blame] | 856 | struct BreakContinue { |
Bob Wilson | bf854f0 | 2014-02-17 19:21:09 +0000 | [diff] [blame] | 857 | BreakContinue(JumpDest Break, JumpDest Continue) |
| 858 | : BreakBlock(Break), ContinueBlock(Continue) {} |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 859 | |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 860 | JumpDest BreakBlock; |
| 861 | JumpDest ContinueBlock; |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 862 | }; |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 863 | SmallVector<BreakContinue, 8> BreakContinueStack; |
Daniel Dunbar | d3dcb4f8 | 2008-09-28 01:03:14 +0000 | [diff] [blame] | 864 | |
Justin Bogner | ef512b9 | 2014-01-06 22:27:43 +0000 | [diff] [blame] | 865 | CodeGenPGO PGO; |
| 866 | |
| 867 | public: |
| 868 | /// Get a counter for instrumentation of the region associated with the given |
| 869 | /// statement. |
| 870 | RegionCounter getPGORegionCounter(const Stmt *S) { |
| 871 | return RegionCounter(PGO, S); |
| 872 | } |
| 873 | private: |
| 874 | |
Zhongxing Xu | 82846ea | 2012-01-14 09:08:15 +0000 | [diff] [blame] | 875 | /// SwitchInsn - This is nearest current switch instruction. It is null if |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 876 | /// current context is not in a switch. |
Devang Patel | da5d6bb | 2007-10-04 23:45:31 +0000 | [diff] [blame] | 877 | llvm::SwitchInst *SwitchInsn; |
Justin Bogner | ef512b9 | 2014-01-06 22:27:43 +0000 | [diff] [blame] | 878 | /// The branch weights of SwitchInsn when doing instrumentation based PGO. |
| 879 | SmallVector<uint64_t, 16> *SwitchWeights; |
Devang Patel | da5d6bb | 2007-10-04 23:45:31 +0000 | [diff] [blame] | 880 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 881 | /// CaseRangeBlock - This block holds if condition check for last case |
Devang Patel | 49a44f3 | 2007-10-09 17:08:50 +0000 | [diff] [blame] | 882 | /// statement range in current switch instruction. |
Devang Patel | 1166312 | 2007-10-08 20:57:48 +0000 | [diff] [blame] | 883 | llvm::BasicBlock *CaseRangeBlock; |
| 884 | |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 885 | /// OpaqueLValues - Keeps track of the current set of opaque value |
John McCall | 1bf5846 | 2011-02-16 08:02:54 +0000 | [diff] [blame] | 886 | /// expressions. |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 887 | llvm::DenseMap<const OpaqueValueExpr *, LValue> OpaqueLValues; |
| 888 | llvm::DenseMap<const OpaqueValueExpr *, RValue> OpaqueRValues; |
John McCall | 1bf5846 | 2011-02-16 08:02:54 +0000 | [diff] [blame] | 889 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 890 | // VLASizeMap - This keeps track of the associated size for each VLA type. |
Eli Friedman | 04fddf0 | 2009-08-15 02:50:32 +0000 | [diff] [blame] | 891 | // We track this by the size expression rather than the type itself because |
| 892 | // in certain situations, like a const qualifier applied to an VLA typedef, |
| 893 | // multiple VLA types can share the same size expression. |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 894 | // FIXME: Maybe this could be a stack of maps that is pushed/popped as we |
| 895 | // enter/leave scopes. |
Eli Friedman | 04fddf0 | 2009-08-15 02:50:32 +0000 | [diff] [blame] | 896 | llvm::DenseMap<const Expr*, llvm::Value*> VLASizeMap; |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 897 | |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 898 | /// A block containing a single 'unreachable' instruction. Created |
| 899 | /// lazily by getUnreachableBlock(). |
| 900 | llvm::BasicBlock *UnreachableBlock; |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 901 | |
Adrian Prantl | 52bf3c4 | 2013-05-03 20:11:48 +0000 | [diff] [blame] | 902 | /// Counts of the number return expressions in the function. |
| 903 | unsigned NumReturnExprs; |
Adrian Prantl | 3be1054 | 2013-05-02 17:30:20 +0000 | [diff] [blame] | 904 | |
| 905 | /// Count the number of simple (constant) return expressions in the function. |
| 906 | unsigned NumSimpleReturnExprs; |
| 907 | |
Adrian Prantl | 52bf3c4 | 2013-05-03 20:11:48 +0000 | [diff] [blame] | 908 | /// The last regular (non-return) debug location (breakpoint) in the function. |
Adrian Prantl | e83b130 | 2014-01-07 22:05:52 +0000 | [diff] [blame] | 909 | SourceLocation LastStopPoint; |
Adrian Prantl | 3be1054 | 2013-05-02 17:30:20 +0000 | [diff] [blame] | 910 | |
Richard Smith | 852c9db | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 911 | public: |
| 912 | /// A scope within which we are constructing the fields of an object which |
| 913 | /// might use a CXXDefaultInitExpr. This stashes away a 'this' value to use |
| 914 | /// if we need to evaluate a CXXDefaultInitExpr within the evaluation. |
| 915 | class FieldConstructionScope { |
| 916 | public: |
| 917 | FieldConstructionScope(CodeGenFunction &CGF, llvm::Value *This) |
| 918 | : CGF(CGF), OldCXXDefaultInitExprThis(CGF.CXXDefaultInitExprThis) { |
| 919 | CGF.CXXDefaultInitExprThis = This; |
| 920 | } |
| 921 | ~FieldConstructionScope() { |
| 922 | CGF.CXXDefaultInitExprThis = OldCXXDefaultInitExprThis; |
| 923 | } |
| 924 | |
| 925 | private: |
| 926 | CodeGenFunction &CGF; |
| 927 | llvm::Value *OldCXXDefaultInitExprThis; |
| 928 | }; |
| 929 | |
| 930 | /// The scope of a CXXDefaultInitExpr. Within this scope, the value of 'this' |
| 931 | /// is overridden to be the object under construction. |
| 932 | class CXXDefaultInitExprScope { |
| 933 | public: |
| 934 | CXXDefaultInitExprScope(CodeGenFunction &CGF) |
| 935 | : CGF(CGF), OldCXXThisValue(CGF.CXXThisValue) { |
| 936 | CGF.CXXThisValue = CGF.CXXDefaultInitExprThis; |
| 937 | } |
| 938 | ~CXXDefaultInitExprScope() { |
| 939 | CGF.CXXThisValue = OldCXXThisValue; |
| 940 | } |
| 941 | |
| 942 | public: |
| 943 | CodeGenFunction &CGF; |
| 944 | llvm::Value *OldCXXThisValue; |
| 945 | }; |
| 946 | |
| 947 | private: |
Anders Carlsson | 82ba57c | 2009-11-25 03:15:49 +0000 | [diff] [blame] | 948 | /// CXXThisDecl - When generating code for a C++ member function, |
| 949 | /// this will hold the implicit 'this' declaration. |
Eli Friedman | 9fbeba0 | 2012-02-11 02:57:39 +0000 | [diff] [blame] | 950 | ImplicitParamDecl *CXXABIThisDecl; |
| 951 | llvm::Value *CXXABIThisValue; |
John McCall | 347132b | 2010-02-16 22:04:33 +0000 | [diff] [blame] | 952 | llvm::Value *CXXThisValue; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 953 | |
Richard Smith | 852c9db | 2013-04-20 22:23:05 +0000 | [diff] [blame] | 954 | /// The value of 'this' to use when evaluating CXXDefaultInitExprs within |
| 955 | /// this expression. |
| 956 | llvm::Value *CXXDefaultInitExprThis; |
| 957 | |
Timur Iskhodzhanov | ee6bc53 | 2013-02-13 08:37:51 +0000 | [diff] [blame] | 958 | /// CXXStructorImplicitParamDecl - When generating code for a constructor or |
| 959 | /// destructor, this will hold the implicit argument (e.g. VTT). |
| 960 | ImplicitParamDecl *CXXStructorImplicitParamDecl; |
| 961 | llvm::Value *CXXStructorImplicitParamValue; |
Michael J. Spencer | f5a1fbc | 2010-10-19 06:39:39 +0000 | [diff] [blame] | 962 | |
John McCall | ce1de61 | 2011-01-26 04:00:11 +0000 | [diff] [blame] | 963 | /// OutermostConditional - Points to the outermost active |
| 964 | /// conditional control. This is used so that we know if a |
| 965 | /// temporary should be destroyed conditionally. |
| 966 | ConditionalEvaluation *OutermostConditional; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 967 | |
Nadav Rotem | 1da3094 | 2013-03-23 06:43:35 +0000 | [diff] [blame] | 968 | /// The current lexical scope. |
| 969 | LexicalScope *CurLexicalScope; |
Anders Carlsson | 0168f4b | 2009-09-12 02:14:24 +0000 | [diff] [blame] | 970 | |
Adrian Prantl | dc237b5 | 2013-05-16 00:41:26 +0000 | [diff] [blame] | 971 | /// The current source location that should be used for exception |
| 972 | /// handling code. |
| 973 | SourceLocation CurEHLocation; |
| 974 | |
Anders Carlsson | 0168f4b | 2009-09-12 02:14:24 +0000 | [diff] [blame] | 975 | /// ByrefValueInfoMap - For each __block variable, contains a pair of the LLVM |
| 976 | /// type as well as the field number that contains the actual data. |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 977 | llvm::DenseMap<const ValueDecl *, std::pair<llvm::Type *, |
Anders Carlsson | 0168f4b | 2009-09-12 02:14:24 +0000 | [diff] [blame] | 978 | unsigned> > ByRefValueInfo; |
Michael J. Spencer | f5a1fbc | 2010-10-19 06:39:39 +0000 | [diff] [blame] | 979 | |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 980 | llvm::BasicBlock *TerminateLandingPad; |
Mike Stump | f5cbb08 | 2009-12-10 00:02:42 +0000 | [diff] [blame] | 981 | llvm::BasicBlock *TerminateHandler; |
Chris Lattner | f2f3870 | 2010-07-20 21:07:09 +0000 | [diff] [blame] | 982 | llvm::BasicBlock *TrapBB; |
Eli Friedman | d5bc94e | 2009-12-10 02:21:21 +0000 | [diff] [blame] | 983 | |
Tanya Lattner | bcffcdf | 2012-07-09 22:06:01 +0000 | [diff] [blame] | 984 | /// Add a kernel metadata node to the named metadata node 'opencl.kernels'. |
| 985 | /// In the kernel metadata node, reference the kernel function and metadata |
| 986 | /// nodes for its optional attribute qualifiers (OpenCL 1.1 6.7.2): |
Joey Gouly | aba589c | 2013-03-08 09:42:32 +0000 | [diff] [blame] | 987 | /// - A node for the vec_type_hint(<type>) qualifier contains string |
| 988 | /// "vec_type_hint", an undefined value of the <type> data type, |
| 989 | /// and a Boolean that is true if the <type> is integer and signed. |
Tanya Lattner | bcffcdf | 2012-07-09 22:06:01 +0000 | [diff] [blame] | 990 | /// - A node for the work_group_size_hint(X,Y,Z) qualifier contains string |
| 991 | /// "work_group_size_hint", and three 32-bit integers X, Y and Z. |
| 992 | /// - A node for the reqd_work_group_size(X,Y,Z) qualifier contains string |
| 993 | /// "reqd_work_group_size", and three 32-bit integers X, Y and Z. |
| 994 | void EmitOpenCLKernelMetadata(const FunctionDecl *FD, |
| 995 | llvm::Function *Fn); |
| 996 | |
Chris Lattner | bed3144 | 2007-05-28 01:07:47 +0000 | [diff] [blame] | 997 | public: |
Fariborz Jahanian | 6362803 | 2012-06-26 16:06:38 +0000 | [diff] [blame] | 998 | CodeGenFunction(CodeGenModule &cgm, bool suppressNewContext=false); |
John McCall | 08ef466 | 2011-11-10 08:15:53 +0000 | [diff] [blame] | 999 | ~CodeGenFunction(); |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1000 | |
John McCall | 8ed55a5 | 2010-09-02 09:58:18 +0000 | [diff] [blame] | 1001 | CodeGenTypes &getTypes() const { return CGM.getTypes(); } |
John McCall | 745ae28 | 2011-05-15 02:34:36 +0000 | [diff] [blame] | 1002 | ASTContext &getContext() const { return CGM.getContext(); } |
Devang Patel | d6ffebb | 2011-03-07 18:45:56 +0000 | [diff] [blame] | 1003 | CGDebugInfo *getDebugInfo() { |
| 1004 | if (DisableDebugInfo) |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 1005 | return nullptr; |
Devang Patel | d6ffebb | 2011-03-07 18:45:56 +0000 | [diff] [blame] | 1006 | return DebugInfo; |
| 1007 | } |
| 1008 | void disableDebugInfo() { DisableDebugInfo = true; } |
| 1009 | void enableDebugInfo() { DisableDebugInfo = false; } |
| 1010 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1011 | bool shouldUseFusedARCCalls() { |
| 1012 | return CGM.getCodeGenOpts().OptimizationLevel == 0; |
| 1013 | } |
Chris Lattner | 6db1fb8 | 2007-06-02 22:49:07 +0000 | [diff] [blame] | 1014 | |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1015 | const LangOptions &getLangOpts() const { return CGM.getLangOpts(); } |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 1016 | |
Bill Wendling | f0724e8 | 2011-09-19 20:31:14 +0000 | [diff] [blame] | 1017 | /// Returns a pointer to the function's exception object and selector slot, |
| 1018 | /// which is assigned in every landing pad. |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 1019 | llvm::Value *getExceptionSlot(); |
John McCall | 9b382dd | 2011-05-28 21:13:02 +0000 | [diff] [blame] | 1020 | llvm::Value *getEHSelectorSlot(); |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 1021 | |
Bill Wendling | 79a70e4 | 2011-09-15 18:57:19 +0000 | [diff] [blame] | 1022 | /// Returns the contents of the function's exception object and selector |
| 1023 | /// slots. |
| 1024 | llvm::Value *getExceptionFromSlot(); |
| 1025 | llvm::Value *getSelectorFromSlot(); |
| 1026 | |
John McCall | ad5d61e | 2010-07-23 21:56:41 +0000 | [diff] [blame] | 1027 | llvm::Value *getNormalCleanupDestSlot(); |
John McCall | ad5d61e | 2010-07-23 21:56:41 +0000 | [diff] [blame] | 1028 | |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 1029 | llvm::BasicBlock *getUnreachableBlock() { |
| 1030 | if (!UnreachableBlock) { |
| 1031 | UnreachableBlock = createBasicBlock("unreachable"); |
| 1032 | new llvm::UnreachableInst(getLLVMContext(), UnreachableBlock); |
| 1033 | } |
| 1034 | return UnreachableBlock; |
| 1035 | } |
| 1036 | |
| 1037 | llvm::BasicBlock *getInvokeDest() { |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 1038 | if (!EHStack.requiresLandingPad()) return nullptr; |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 1039 | return getInvokeDestImpl(); |
| 1040 | } |
Daniel Dunbar | 1234749 | 2009-02-23 17:26:39 +0000 | [diff] [blame] | 1041 | |
John McCall | c8e0170 | 2013-04-16 22:48:15 +0000 | [diff] [blame] | 1042 | const TargetInfo &getTarget() const { return Target; } |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 1043 | llvm::LLVMContext &getLLVMContext() { return CGM.getLLVMContext(); } |
Owen Anderson | ae86c19 | 2009-07-13 04:10:07 +0000 | [diff] [blame] | 1044 | |
Daniel Dunbar | 1234749 | 2009-02-23 17:26:39 +0000 | [diff] [blame] | 1045 | //===--------------------------------------------------------------------===// |
John McCall | 82fe67b | 2011-07-09 01:37:26 +0000 | [diff] [blame] | 1046 | // Cleanups |
| 1047 | //===--------------------------------------------------------------------===// |
| 1048 | |
| 1049 | typedef void Destroyer(CodeGenFunction &CGF, llvm::Value *addr, QualType ty); |
| 1050 | |
John McCall | 178360e | 2011-07-11 08:38:19 +0000 | [diff] [blame] | 1051 | void pushIrregularPartialArrayCleanup(llvm::Value *arrayBegin, |
| 1052 | llvm::Value *arrayEndPointer, |
| 1053 | QualType elementType, |
Peter Collingbourne | 1425b45 | 2012-01-26 03:33:36 +0000 | [diff] [blame] | 1054 | Destroyer *destroyer); |
John McCall | 178360e | 2011-07-11 08:38:19 +0000 | [diff] [blame] | 1055 | void pushRegularPartialArrayCleanup(llvm::Value *arrayBegin, |
| 1056 | llvm::Value *arrayEnd, |
| 1057 | QualType elementType, |
Peter Collingbourne | 1425b45 | 2012-01-26 03:33:36 +0000 | [diff] [blame] | 1058 | Destroyer *destroyer); |
John McCall | 82fe67b | 2011-07-09 01:37:26 +0000 | [diff] [blame] | 1059 | |
John McCall | 4bd0fb1 | 2011-07-12 16:41:08 +0000 | [diff] [blame] | 1060 | void pushDestroy(QualType::DestructionKind dtorKind, |
| 1061 | llvm::Value *addr, QualType type); |
John McCall | 12cc42a | 2013-02-01 05:11:40 +0000 | [diff] [blame] | 1062 | void pushEHDestroy(QualType::DestructionKind dtorKind, |
| 1063 | llvm::Value *addr, QualType type); |
John McCall | 82fe67b | 2011-07-09 01:37:26 +0000 | [diff] [blame] | 1064 | void pushDestroy(CleanupKind kind, llvm::Value *addr, QualType type, |
Peter Collingbourne | 1425b45 | 2012-01-26 03:33:36 +0000 | [diff] [blame] | 1065 | Destroyer *destroyer, bool useEHCleanupForArray); |
Richard Smith | 736a947 | 2013-06-12 20:42:33 +0000 | [diff] [blame] | 1066 | void pushLifetimeExtendedDestroy(CleanupKind kind, llvm::Value *addr, |
| 1067 | QualType type, Destroyer *destroyer, |
| 1068 | bool useEHCleanupForArray); |
Reid Kleckner | 314ef7b | 2014-02-01 00:04:45 +0000 | [diff] [blame] | 1069 | void pushStackRestore(CleanupKind kind, llvm::Value *SPMem); |
Peter Collingbourne | 1425b45 | 2012-01-26 03:33:36 +0000 | [diff] [blame] | 1070 | void emitDestroy(llvm::Value *addr, QualType type, Destroyer *destroyer, |
John McCall | 178360e | 2011-07-11 08:38:19 +0000 | [diff] [blame] | 1071 | bool useEHCleanupForArray); |
David Blaikie | ebe87e1 | 2013-08-27 23:57:18 +0000 | [diff] [blame] | 1072 | llvm::Function *generateDestroyHelper(llvm::Constant *addr, QualType type, |
Peter Collingbourne | 1425b45 | 2012-01-26 03:33:36 +0000 | [diff] [blame] | 1073 | Destroyer *destroyer, |
David Blaikie | ebe87e1 | 2013-08-27 23:57:18 +0000 | [diff] [blame] | 1074 | bool useEHCleanupForArray, |
| 1075 | const VarDecl *VD); |
John McCall | 82fe67b | 2011-07-09 01:37:26 +0000 | [diff] [blame] | 1076 | void emitArrayDestroy(llvm::Value *begin, llvm::Value *end, |
Peter Collingbourne | 1425b45 | 2012-01-26 03:33:36 +0000 | [diff] [blame] | 1077 | QualType type, Destroyer *destroyer, |
John McCall | 97eab0a | 2011-07-13 08:09:46 +0000 | [diff] [blame] | 1078 | bool checkZeroLength, bool useEHCleanup); |
John McCall | 82fe67b | 2011-07-09 01:37:26 +0000 | [diff] [blame] | 1079 | |
Peter Collingbourne | 1425b45 | 2012-01-26 03:33:36 +0000 | [diff] [blame] | 1080 | Destroyer *getDestroyer(QualType::DestructionKind destructionKind); |
John McCall | 4bd0fb1 | 2011-07-12 16:41:08 +0000 | [diff] [blame] | 1081 | |
John McCall | 82fe67b | 2011-07-09 01:37:26 +0000 | [diff] [blame] | 1082 | /// Determines whether an EH cleanup is required to destroy a type |
| 1083 | /// with the given destruction kind. |
| 1084 | bool needsEHCleanup(QualType::DestructionKind kind) { |
| 1085 | switch (kind) { |
| 1086 | case QualType::DK_none: |
| 1087 | return false; |
| 1088 | case QualType::DK_cxx_destructor: |
| 1089 | case QualType::DK_objc_weak_lifetime: |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1090 | return getLangOpts().Exceptions; |
John McCall | 82fe67b | 2011-07-09 01:37:26 +0000 | [diff] [blame] | 1091 | case QualType::DK_objc_strong_lifetime: |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1092 | return getLangOpts().Exceptions && |
John McCall | 82fe67b | 2011-07-09 01:37:26 +0000 | [diff] [blame] | 1093 | CGM.getCodeGenOpts().ObjCAutoRefCountExceptions; |
| 1094 | } |
| 1095 | llvm_unreachable("bad destruction kind"); |
| 1096 | } |
| 1097 | |
John McCall | 4bd0fb1 | 2011-07-12 16:41:08 +0000 | [diff] [blame] | 1098 | CleanupKind getCleanupKind(QualType::DestructionKind kind) { |
| 1099 | return (needsEHCleanup(kind) ? NormalAndEHCleanup : NormalCleanup); |
| 1100 | } |
| 1101 | |
John McCall | 82fe67b | 2011-07-09 01:37:26 +0000 | [diff] [blame] | 1102 | //===--------------------------------------------------------------------===// |
Daniel Dunbar | 1234749 | 2009-02-23 17:26:39 +0000 | [diff] [blame] | 1103 | // Objective-C |
| 1104 | //===--------------------------------------------------------------------===// |
| 1105 | |
Chris Lattner | 4bd5596 | 2008-03-30 23:03:07 +0000 | [diff] [blame] | 1106 | void GenerateObjCMethod(const ObjCMethodDecl *OMD); |
Daniel Dunbar | 89654ee | 2008-08-26 08:29:31 +0000 | [diff] [blame] | 1107 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1108 | void StartObjCMethod(const ObjCMethodDecl *MD, |
Devang Patel | e7ce540 | 2011-05-19 23:37:41 +0000 | [diff] [blame] | 1109 | const ObjCContainerDecl *CD, |
| 1110 | SourceLocation StartLoc); |
Daniel Dunbar | 89654ee | 2008-08-26 08:29:31 +0000 | [diff] [blame] | 1111 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1112 | /// GenerateObjCGetter - Synthesize an Objective-C property getter function. |
Fariborz Jahanian | 3d8552a | 2008-12-09 20:23:04 +0000 | [diff] [blame] | 1113 | void GenerateObjCGetter(ObjCImplementationDecl *IMP, |
| 1114 | const ObjCPropertyImplDecl *PID); |
John McCall | f4528ae | 2011-09-13 03:34:09 +0000 | [diff] [blame] | 1115 | void generateObjCGetterBody(const ObjCImplementationDecl *classImpl, |
Fariborz Jahanian | 4b501a2 | 2012-01-07 18:56:22 +0000 | [diff] [blame] | 1116 | const ObjCPropertyImplDecl *propImpl, |
Fariborz Jahanian | b5dd2cb | 2012-05-29 19:56:01 +0000 | [diff] [blame] | 1117 | const ObjCMethodDecl *GetterMothodDecl, |
Fariborz Jahanian | 4b501a2 | 2012-01-07 18:56:22 +0000 | [diff] [blame] | 1118 | llvm::Constant *AtomicHelperFn); |
Fariborz Jahanian | 302a3d4 | 2011-02-18 19:15:13 +0000 | [diff] [blame] | 1119 | |
Fariborz Jahanian | 0dec1e0 | 2010-04-28 21:28:56 +0000 | [diff] [blame] | 1120 | void GenerateObjCCtorDtorMethod(ObjCImplementationDecl *IMP, |
| 1121 | ObjCMethodDecl *MD, bool ctor); |
Daniel Dunbar | 89654ee | 2008-08-26 08:29:31 +0000 | [diff] [blame] | 1122 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1123 | /// GenerateObjCSetter - Synthesize an Objective-C property setter function |
| 1124 | /// for the given property. |
Fariborz Jahanian | 3d8552a | 2008-12-09 20:23:04 +0000 | [diff] [blame] | 1125 | void GenerateObjCSetter(ObjCImplementationDecl *IMP, |
| 1126 | const ObjCPropertyImplDecl *PID); |
John McCall | 7f16c42 | 2011-09-10 09:17:20 +0000 | [diff] [blame] | 1127 | void generateObjCSetterBody(const ObjCImplementationDecl *classImpl, |
Fariborz Jahanian | 7ff610b | 2012-01-06 22:33:54 +0000 | [diff] [blame] | 1128 | const ObjCPropertyImplDecl *propImpl, |
| 1129 | llvm::Constant *AtomicHelperFn); |
Fariborz Jahanian | 08b0f66 | 2010-04-13 00:38:05 +0000 | [diff] [blame] | 1130 | bool IndirectObjCSetterArg(const CGFunctionInfo &FI); |
Fariborz Jahanian | 7e9d52a | 2010-04-13 18:32:24 +0000 | [diff] [blame] | 1131 | bool IvarTypeWithAggrGCObjects(QualType Ty); |
Daniel Dunbar | 89654ee | 2008-08-26 08:29:31 +0000 | [diff] [blame] | 1132 | |
Mike Stump | cb2fbcb | 2009-02-21 20:00:35 +0000 | [diff] [blame] | 1133 | //===--------------------------------------------------------------------===// |
| 1134 | // Block Bits |
| 1135 | //===--------------------------------------------------------------------===// |
| 1136 | |
John McCall | 351762c | 2011-02-07 10:33:21 +0000 | [diff] [blame] | 1137 | llvm::Value *EmitBlockLiteral(const BlockExpr *); |
John McCall | 08ef466 | 2011-11-10 08:15:53 +0000 | [diff] [blame] | 1138 | llvm::Value *EmitBlockLiteral(const CGBlockInfo &Info); |
| 1139 | static void destroyBlockInfos(CGBlockInfo *info); |
Blaine Garst | fc83aa0 | 2010-02-23 21:51:17 +0000 | [diff] [blame] | 1140 | llvm::Constant *BuildDescriptorBlockDecl(const BlockExpr *, |
Fariborz Jahanian | c05349e | 2010-08-04 16:57:49 +0000 | [diff] [blame] | 1141 | const CGBlockInfo &Info, |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 1142 | llvm::StructType *, |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 1143 | llvm::Constant *BlockVarLayout); |
Mike Stump | cb2fbcb | 2009-02-21 20:00:35 +0000 | [diff] [blame] | 1144 | |
Fariborz Jahanian | 9b5528d | 2010-06-24 00:08:06 +0000 | [diff] [blame] | 1145 | llvm::Function *GenerateBlockFunction(GlobalDecl GD, |
John McCall | 351762c | 2011-02-07 10:33:21 +0000 | [diff] [blame] | 1146 | const CGBlockInfo &Info, |
Eli Friedman | 2495ab0 | 2012-02-25 02:48:22 +0000 | [diff] [blame] | 1147 | const DeclMapTy &ldm, |
| 1148 | bool IsLambdaConversionToBlock); |
Mike Stump | cb2fbcb | 2009-02-21 20:00:35 +0000 | [diff] [blame] | 1149 | |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 1150 | llvm::Constant *GenerateCopyHelperFunction(const CGBlockInfo &blockInfo); |
| 1151 | llvm::Constant *GenerateDestroyHelperFunction(const CGBlockInfo &blockInfo); |
Fariborz Jahanian | a08a747 | 2012-01-10 00:37:01 +0000 | [diff] [blame] | 1152 | llvm::Constant *GenerateObjCAtomicSetterCopyHelperFunction( |
| 1153 | const ObjCPropertyImplDecl *PID); |
| 1154 | llvm::Constant *GenerateObjCAtomicGetterCopyHelperFunction( |
| 1155 | const ObjCPropertyImplDecl *PID); |
Eli Friedman | ec75fec | 2012-02-28 01:08:45 +0000 | [diff] [blame] | 1156 | llvm::Value *EmitBlockCopyAndAutorelease(llvm::Value *Block, QualType Ty); |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 1157 | |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 1158 | void BuildBlockRelease(llvm::Value *DeclPtr, BlockFieldFlags flags); |
| 1159 | |
John McCall | 7306487 | 2011-03-31 01:59:53 +0000 | [diff] [blame] | 1160 | class AutoVarEmission; |
| 1161 | |
| 1162 | void emitByrefStructureInit(const AutoVarEmission &emission); |
| 1163 | void enterByrefCleanup(const AutoVarEmission &emission); |
| 1164 | |
John McCall | 351762c | 2011-02-07 10:33:21 +0000 | [diff] [blame] | 1165 | llvm::Value *LoadBlockStruct() { |
| 1166 | assert(BlockPointer && "no block pointer set!"); |
| 1167 | return BlockPointer; |
| 1168 | } |
Mike Stump | cb2fbcb | 2009-02-21 20:00:35 +0000 | [diff] [blame] | 1169 | |
John McCall | 87fe5d5 | 2010-05-20 01:18:31 +0000 | [diff] [blame] | 1170 | void AllocateBlockCXXThisPointer(const CXXThisExpr *E); |
John McCall | 113bee0 | 2012-03-10 09:33:50 +0000 | [diff] [blame] | 1171 | void AllocateBlockDecl(const DeclRefExpr *E); |
John McCall | 351762c | 2011-02-07 10:33:21 +0000 | [diff] [blame] | 1172 | llvm::Value *GetAddrOfBlockDecl(const VarDecl *var, bool ByRef); |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 1173 | llvm::Type *BuildByRefType(const VarDecl *var); |
Mike Stump | 97d01d5 | 2009-03-04 03:23:46 +0000 | [diff] [blame] | 1174 | |
John McCall | a738c25 | 2011-03-09 04:27:21 +0000 | [diff] [blame] | 1175 | void GenerateCode(GlobalDecl GD, llvm::Function *Fn, |
| 1176 | const CGFunctionInfo &FnInfo); |
Adrian Prantl | 42d71b9 | 2014-04-10 23:21:53 +0000 | [diff] [blame] | 1177 | /// \brief Emit code for the start of a function. |
| 1178 | /// \param Loc The location to be associated with the function. |
| 1179 | /// \param StartLoc The location of the function body. |
John McCall | dec348f7 | 2013-05-03 07:33:41 +0000 | [diff] [blame] | 1180 | void StartFunction(GlobalDecl GD, |
| 1181 | QualType RetTy, |
Daniel Dunbar | bc915f4 | 2008-09-09 23:14:03 +0000 | [diff] [blame] | 1182 | llvm::Function *Fn, |
John McCall | a738c25 | 2011-03-09 04:27:21 +0000 | [diff] [blame] | 1183 | const CGFunctionInfo &FnInfo, |
Daniel Dunbar | 354d278 | 2008-10-18 18:22:23 +0000 | [diff] [blame] | 1184 | const FunctionArgList &Args, |
Adrian Prantl | 22e66b4 | 2014-04-11 01:13:04 +0000 | [diff] [blame] | 1185 | SourceLocation Loc = SourceLocation(), |
| 1186 | SourceLocation StartLoc = SourceLocation()); |
Daniel Dunbar | 5c7e393 | 2008-11-11 23:11:34 +0000 | [diff] [blame] | 1187 | |
John McCall | b81884d | 2010-02-19 09:25:03 +0000 | [diff] [blame] | 1188 | void EmitConstructorBody(FunctionArgList &Args); |
| 1189 | void EmitDestructorBody(FunctionArgList &Args); |
Lang Hames | bf12274 | 2013-02-17 07:22:09 +0000 | [diff] [blame] | 1190 | void emitImplicitAssignmentOperatorBody(FunctionArgList &Args); |
Richard Smith | b47c36f | 2013-11-05 09:12:18 +0000 | [diff] [blame] | 1191 | void EmitFunctionBody(FunctionArgList &Args, const Stmt *Body); |
Bob Wilson | bf854f0 | 2014-02-17 19:21:09 +0000 | [diff] [blame] | 1192 | void EmitBlockWithFallThrough(llvm::BasicBlock *BB, RegionCounter &Cnt); |
John McCall | 89b12b3 | 2010-02-18 03:17:58 +0000 | [diff] [blame] | 1193 | |
Faisal Vali | 571df12 | 2013-09-29 08:45:24 +0000 | [diff] [blame] | 1194 | void EmitForwardingCallToLambda(const CXXMethodDecl *LambdaCallOperator, |
Eli Friedman | 2495ab0 | 2012-02-25 02:48:22 +0000 | [diff] [blame] | 1195 | CallArgList &CallArgs); |
Eli Friedman | 5a6d507 | 2012-02-16 01:37:33 +0000 | [diff] [blame] | 1196 | void EmitLambdaToBlockPointerBody(FunctionArgList &Args); |
Eli Friedman | 2495ab0 | 2012-02-25 02:48:22 +0000 | [diff] [blame] | 1197 | void EmitLambdaBlockInvokeBody(); |
Douglas Gregor | 355efbb | 2012-02-17 03:02:34 +0000 | [diff] [blame] | 1198 | void EmitLambdaDelegatingInvokeBody(const CXXMethodDecl *MD); |
| 1199 | void EmitLambdaStaticInvokeFunction(const CXXMethodDecl *MD); |
Eli Friedman | 5a6d507 | 2012-02-16 01:37:33 +0000 | [diff] [blame] | 1200 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1201 | /// EmitReturnBlock - Emit the unified return block, trying to avoid its |
| 1202 | /// emission when possible. |
David Blaikie | 357aafb | 2013-02-01 19:09:49 +0000 | [diff] [blame] | 1203 | void EmitReturnBlock(); |
Daniel Dunbar | fd346a3 | 2009-01-26 23:27:52 +0000 | [diff] [blame] | 1204 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1205 | /// FinishFunction - Complete IR generation of the current function. It is |
| 1206 | /// legal to call this function even if there is no current insertion point. |
Daniel Dunbar | 89654ee | 2008-08-26 08:29:31 +0000 | [diff] [blame] | 1207 | void FinishFunction(SourceLocation EndLoc=SourceLocation()); |
Daniel Dunbar | 613855c | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 1208 | |
Hans Wennborg | 88497d6 | 2013-11-15 17:24:45 +0000 | [diff] [blame] | 1209 | void StartThunk(llvm::Function *Fn, GlobalDecl GD, const CGFunctionInfo &FnInfo); |
| 1210 | |
Reid Kleckner | 3f76ac7 | 2014-07-26 01:30:05 +0000 | [diff] [blame] | 1211 | void EmitCallAndReturnForThunk(llvm::Value *Callee, const ThunkInfo *Thunk); |
Hans Wennborg | 88497d6 | 2013-11-15 17:24:45 +0000 | [diff] [blame] | 1212 | |
Reid Kleckner | ab2090d | 2014-07-26 01:34:32 +0000 | [diff] [blame] | 1213 | /// Emit a musttail call for a thunk with a potentially adjusted this pointer. |
| 1214 | void EmitMustTailThunk(const CXXMethodDecl *MD, llvm::Value *AdjustedThisPtr, |
| 1215 | llvm::Value *Callee); |
| 1216 | |
Anders Carlsson | bad991d | 2010-03-24 00:39:18 +0000 | [diff] [blame] | 1217 | /// GenerateThunk - Generate a thunk for the given method. |
John McCall | a738c25 | 2011-03-09 04:27:21 +0000 | [diff] [blame] | 1218 | void GenerateThunk(llvm::Function *Fn, const CGFunctionInfo &FnInfo, |
| 1219 | GlobalDecl GD, const ThunkInfo &Thunk); |
Michael J. Spencer | f5a1fbc | 2010-10-19 06:39:39 +0000 | [diff] [blame] | 1220 | |
Eli Friedman | 49a94b1 | 2011-05-06 17:27:27 +0000 | [diff] [blame] | 1221 | void GenerateVarArgsThunk(llvm::Function *Fn, const CGFunctionInfo &FnInfo, |
| 1222 | GlobalDecl GD, const ThunkInfo &Thunk); |
| 1223 | |
Douglas Gregor | 94f9a48 | 2010-05-05 05:51:00 +0000 | [diff] [blame] | 1224 | void EmitCtorPrologue(const CXXConstructorDecl *CD, CXXCtorType Type, |
| 1225 | FunctionArgList &Args); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1226 | |
Eli Friedman | 5f1a04f | 2012-02-14 02:31:03 +0000 | [diff] [blame] | 1227 | void EmitInitializerForField(FieldDecl *Field, LValue LHS, Expr *Init, |
| 1228 | ArrayRef<VarDecl *> ArrayIndexes); |
| 1229 | |
Anders Carlsson | e87fae9 | 2010-03-28 19:40:00 +0000 | [diff] [blame] | 1230 | /// InitializeVTablePointer - Initialize the vtable pointer of the given |
| 1231 | /// subobject. |
| 1232 | /// |
Michael J. Spencer | f5a1fbc | 2010-10-19 06:39:39 +0000 | [diff] [blame] | 1233 | void InitializeVTablePointer(BaseSubobject Base, |
Anders Carlsson | 652758c | 2010-04-20 05:22:15 +0000 | [diff] [blame] | 1234 | const CXXRecordDecl *NearestVBase, |
Ken Dyck | 3fb4c89 | 2011-03-23 01:04:18 +0000 | [diff] [blame] | 1235 | CharUnits OffsetFromNearestVBase, |
Anders Carlsson | e87fae9 | 2010-03-28 19:40:00 +0000 | [diff] [blame] | 1236 | const CXXRecordDecl *VTableClass); |
| 1237 | |
| 1238 | typedef llvm::SmallPtrSet<const CXXRecordDecl *, 4> VisitedVirtualBasesSetTy; |
Michael J. Spencer | f5a1fbc | 2010-10-19 06:39:39 +0000 | [diff] [blame] | 1239 | void InitializeVTablePointers(BaseSubobject Base, |
Anders Carlsson | 652758c | 2010-04-20 05:22:15 +0000 | [diff] [blame] | 1240 | const CXXRecordDecl *NearestVBase, |
Ken Dyck | 3fb4c89 | 2011-03-23 01:04:18 +0000 | [diff] [blame] | 1241 | CharUnits OffsetFromNearestVBase, |
Anders Carlsson | d589593 | 2010-03-28 21:07:49 +0000 | [diff] [blame] | 1242 | bool BaseIsNonVirtualPrimaryBase, |
Anders Carlsson | d589593 | 2010-03-28 21:07:49 +0000 | [diff] [blame] | 1243 | const CXXRecordDecl *VTableClass, |
| 1244 | VisitedVirtualBasesSetTy& VBases); |
Eli Friedman | bb5008a | 2009-12-08 06:46:18 +0000 | [diff] [blame] | 1245 | |
Anders Carlsson | d589593 | 2010-03-28 21:07:49 +0000 | [diff] [blame] | 1246 | void InitializeVTablePointers(const CXXRecordDecl *ClassDecl); |
Anders Carlsson | e87fae9 | 2010-03-28 19:40:00 +0000 | [diff] [blame] | 1247 | |
Dan Gohman | 8fc50c2 | 2010-10-26 18:44:08 +0000 | [diff] [blame] | 1248 | /// GetVTablePtr - Return the Value of the vtable pointer member pointed |
| 1249 | /// to by This. |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 1250 | llvm::Value *GetVTablePtr(llvm::Value *This, llvm::Type *Ty); |
Anders Carlsson | e87fae9 | 2010-03-28 19:40:00 +0000 | [diff] [blame] | 1251 | |
Benjamin Kramer | 7463ed7 | 2013-08-25 22:46:27 +0000 | [diff] [blame] | 1252 | |
| 1253 | /// CanDevirtualizeMemberFunctionCalls - Checks whether virtual calls on given |
| 1254 | /// expr can be devirtualized. |
| 1255 | bool CanDevirtualizeMemberFunctionCall(const Expr *Base, |
| 1256 | const CXXMethodDecl *MD); |
| 1257 | |
John McCall | f99a631 | 2010-07-21 05:30:47 +0000 | [diff] [blame] | 1258 | /// EnterDtorCleanups - Enter the cleanups necessary to complete the |
| 1259 | /// given phase of destruction for a destructor. The end result |
| 1260 | /// should call destructors on members and base classes in reverse |
| 1261 | /// order of their construction. |
| 1262 | void EnterDtorCleanups(const CXXDestructorDecl *Dtor, CXXDtorType Type); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1263 | |
Chris Lattner | 3c77a35 | 2010-06-22 00:03:40 +0000 | [diff] [blame] | 1264 | /// ShouldInstrumentFunction - Return true if the current function should be |
| 1265 | /// instrumented with __cyg_profile_func_* calls |
| 1266 | bool ShouldInstrumentFunction(); |
| 1267 | |
| 1268 | /// EmitFunctionInstrumentation - Emit LLVM code to call the specified |
| 1269 | /// instrumentation function with the current function and the call site, if |
| 1270 | /// function instrumentation is enabled. |
| 1271 | void EmitFunctionInstrumentation(const char *Fn); |
| 1272 | |
Roman Divacky | 178e0160 | 2011-02-10 16:52:03 +0000 | [diff] [blame] | 1273 | /// EmitMCountInstrumentation - Emit call to .mcount. |
| 1274 | void EmitMCountInstrumentation(); |
| 1275 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1276 | /// EmitFunctionProlog - Emit the target specific LLVM code to load the |
| 1277 | /// arguments for the given function. This is also responsible for naming the |
| 1278 | /// LLVM function arguments. |
Daniel Dunbar | d931a87 | 2009-02-02 22:03:45 +0000 | [diff] [blame] | 1279 | void EmitFunctionProlog(const CGFunctionInfo &FI, |
| 1280 | llvm::Function *Fn, |
Daniel Dunbar | 613855c | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 1281 | const FunctionArgList &Args); |
| 1282 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1283 | /// EmitFunctionEpilog - Emit the target specific LLVM code to return the |
| 1284 | /// given temporary. |
Nick Lewycky | 2d84e84 | 2013-10-02 02:29:49 +0000 | [diff] [blame] | 1285 | void EmitFunctionEpilog(const CGFunctionInfo &FI, bool EmitRetDbgLoc, |
| 1286 | SourceLocation EndLoc); |
Daniel Dunbar | 613855c | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 1287 | |
Mike Stump | 1d84921 | 2009-12-07 23:38:24 +0000 | [diff] [blame] | 1288 | /// EmitStartEHSpec - Emit the start of the exception spec. |
| 1289 | void EmitStartEHSpec(const Decl *D); |
| 1290 | |
| 1291 | /// EmitEndEHSpec - Emit the end of the exception spec. |
| 1292 | void EmitEndEHSpec(const Decl *D); |
| 1293 | |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 1294 | /// getTerminateLandingPad - Return a landing pad that just calls terminate. |
| 1295 | llvm::BasicBlock *getTerminateLandingPad(); |
| 1296 | |
| 1297 | /// getTerminateHandler - Return a handler (not a landing pad, just |
| 1298 | /// a catch handler) that just calls terminate. This is used when |
| 1299 | /// a terminate scope encloses a try. |
Mike Stump | 2b48887 | 2009-12-09 22:59:31 +0000 | [diff] [blame] | 1300 | llvm::BasicBlock *getTerminateHandler(); |
| 1301 | |
Chris Lattner | a5f58b0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 1302 | llvm::Type *ConvertTypeForMem(QualType T); |
| 1303 | llvm::Type *ConvertType(QualType T); |
| 1304 | llvm::Type *ConvertType(const TypeDecl *T) { |
John McCall | 6ce7472 | 2010-02-16 04:15:37 +0000 | [diff] [blame] | 1305 | return ConvertType(getContext().getTypeDeclType(T)); |
| 1306 | } |
Chris Lattner | 5506f8c | 2008-04-04 04:07:35 +0000 | [diff] [blame] | 1307 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1308 | /// LoadObjCSelf - Load the value of self. This function is only valid while |
| 1309 | /// generating code for an Objective-C method. |
Chris Lattner | 5506f8c | 2008-04-04 04:07:35 +0000 | [diff] [blame] | 1310 | llvm::Value *LoadObjCSelf(); |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1311 | |
| 1312 | /// TypeOfSelfObject - Return type of object that this self represents. |
Fariborz Jahanian | c88a70d | 2009-02-03 00:09:52 +0000 | [diff] [blame] | 1313 | QualType TypeOfSelfObject(); |
Chris Lattner | 5696e7b | 2008-06-17 18:05:57 +0000 | [diff] [blame] | 1314 | |
Chris Lattner | 54fb19e | 2007-06-22 22:02:34 +0000 | [diff] [blame] | 1315 | /// hasAggregateLLVMType - Return true if the specified AST type will map into |
| 1316 | /// an aggregate LLVM type or is void. |
John McCall | 47fb950 | 2013-03-07 21:37:08 +0000 | [diff] [blame] | 1317 | static TypeEvaluationKind getEvaluationKind(QualType T); |
| 1318 | |
| 1319 | static bool hasScalarEvaluationKind(QualType T) { |
| 1320 | return getEvaluationKind(T) == TEK_Scalar; |
| 1321 | } |
| 1322 | |
| 1323 | static bool hasAggregateEvaluationKind(QualType T) { |
| 1324 | return getEvaluationKind(T) == TEK_Aggregate; |
| 1325 | } |
Daniel Dunbar | 75283ff | 2008-11-11 02:29:29 +0000 | [diff] [blame] | 1326 | |
| 1327 | /// createBasicBlock - Create an LLVM basic block. |
Richard Smith | e30752c | 2012-10-09 19:52:38 +0000 | [diff] [blame] | 1328 | llvm::BasicBlock *createBasicBlock(const Twine &name = "", |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 1329 | llvm::Function *parent = nullptr, |
| 1330 | llvm::BasicBlock *before = nullptr) { |
Daniel Dunbar | 851eec1 | 2008-11-12 00:01:12 +0000 | [diff] [blame] | 1331 | #ifdef NDEBUG |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 1332 | return llvm::BasicBlock::Create(getLLVMContext(), "", parent, before); |
Daniel Dunbar | 851eec1 | 2008-11-12 00:01:12 +0000 | [diff] [blame] | 1333 | #else |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 1334 | return llvm::BasicBlock::Create(getLLVMContext(), name, parent, before); |
Daniel Dunbar | 851eec1 | 2008-11-12 00:01:12 +0000 | [diff] [blame] | 1335 | #endif |
Daniel Dunbar | 75283ff | 2008-11-11 02:29:29 +0000 | [diff] [blame] | 1336 | } |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1337 | |
Chris Lattner | ac24820 | 2007-05-30 00:13:02 +0000 | [diff] [blame] | 1338 | /// getBasicBlockForLabel - Return the LLVM basicblock that the specified |
| 1339 | /// label maps to. |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1340 | JumpDest getJumpDestForLabel(const LabelDecl *S); |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1341 | |
Mike Stump | e5311b0 | 2009-11-30 20:08:49 +0000 | [diff] [blame] | 1342 | /// SimplifyForwardingBlocks - If the given basic block is only a branch to |
| 1343 | /// another basic block, simplify it. This assumes that no other code could |
| 1344 | /// potentially reference the basic block. |
Daniel Dunbar | f77e292 | 2009-04-01 04:37:47 +0000 | [diff] [blame] | 1345 | void SimplifyForwardingBlocks(llvm::BasicBlock *BB); |
| 1346 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1347 | /// EmitBlock - Emit the given block \arg BB and set it as the insert point, |
| 1348 | /// adding a fall-through branch from the current insert block if |
| 1349 | /// necessary. It is legal to call this function even if there is no current |
| 1350 | /// insertion point. |
Daniel Dunbar | fcac22e | 2008-11-13 01:24:05 +0000 | [diff] [blame] | 1351 | /// |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1352 | /// IsFinished - If true, indicates that the caller has finished emitting |
| 1353 | /// branches to the given block and does not expect to emit code into it. This |
| 1354 | /// means the block can be ignored if it is unreachable. |
Daniel Dunbar | fcac22e | 2008-11-13 01:24:05 +0000 | [diff] [blame] | 1355 | void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false); |
Daniel Dunbar | 29ac59f | 2008-11-11 04:34:23 +0000 | [diff] [blame] | 1356 | |
John McCall | 8e4c74b | 2011-08-11 02:22:43 +0000 | [diff] [blame] | 1357 | /// EmitBlockAfterUses - Emit the given block somewhere hopefully |
| 1358 | /// near its uses, and leave the insertion point in it. |
| 1359 | void EmitBlockAfterUses(llvm::BasicBlock *BB); |
| 1360 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1361 | /// EmitBranch - Emit a branch to the specified basic block from the current |
| 1362 | /// insert block, taking care to avoid creation of branches from dummy |
| 1363 | /// blocks. It is legal to call this function even if there is no current |
| 1364 | /// insertion point. |
Daniel Dunbar | ab197eb | 2008-11-11 22:06:59 +0000 | [diff] [blame] | 1365 | /// |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1366 | /// This function clears the current insertion point. The caller should follow |
| 1367 | /// calls to this function with calls to Emit*Block prior to generation new |
| 1368 | /// code. |
Daniel Dunbar | c56e676 | 2008-11-11 09:41:28 +0000 | [diff] [blame] | 1369 | void EmitBranch(llvm::BasicBlock *Block); |
| 1370 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1371 | /// HaveInsertPoint - True if an insertion point is defined. If not, this |
| 1372 | /// indicates that the current code being emitted is unreachable. |
| 1373 | bool HaveInsertPoint() const { |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 1374 | return Builder.GetInsertBlock() != nullptr; |
Daniel Dunbar | 5c7e393 | 2008-11-11 23:11:34 +0000 | [diff] [blame] | 1375 | } |
| 1376 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1377 | /// EnsureInsertPoint - Ensure that an insertion point is defined so that |
| 1378 | /// emitted IR has a place to go. Note that by definition, if this function |
| 1379 | /// creates a block then that block is unreachable; callers may do better to |
| 1380 | /// detect when no insertion point is defined and simply skip IR generation. |
Daniel Dunbar | 5c7e393 | 2008-11-11 23:11:34 +0000 | [diff] [blame] | 1381 | void EnsureInsertPoint() { |
| 1382 | if (!HaveInsertPoint()) |
| 1383 | EmitBlock(createBasicBlock()); |
| 1384 | } |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1385 | |
Daniel Dunbar | a7c8cf6 | 2008-08-16 00:56:44 +0000 | [diff] [blame] | 1386 | /// ErrorUnsupported - Print out an error that codegen doesn't support the |
Chris Lattner | fc94434 | 2007-12-02 01:43:38 +0000 | [diff] [blame] | 1387 | /// specified stmt yet. |
David Blaikie | 4a9ec7b | 2013-08-19 21:02:26 +0000 | [diff] [blame] | 1388 | void ErrorUnsupported(const Stmt *S, const char *Type); |
Chris Lattner | 84915fa | 2007-06-02 04:16:21 +0000 | [diff] [blame] | 1389 | |
Chris Lattner | e9a6453 | 2007-06-22 21:44:33 +0000 | [diff] [blame] | 1390 | //===--------------------------------------------------------------------===// |
| 1391 | // Helpers |
| 1392 | //===--------------------------------------------------------------------===// |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1393 | |
Eli Friedman | a0544d6 | 2011-12-03 04:14:32 +0000 | [diff] [blame] | 1394 | LValue MakeAddrLValue(llvm::Value *V, QualType T, |
| 1395 | CharUnits Alignment = CharUnits()) { |
Dan Gohman | 947c9af | 2010-10-14 23:06:10 +0000 | [diff] [blame] | 1396 | return LValue::MakeAddr(V, T, Alignment, getContext(), |
| 1397 | CGM.getTBAAInfo(T)); |
Daniel Dunbar | 93b00a9 | 2010-08-21 02:53:44 +0000 | [diff] [blame] | 1398 | } |
John McCall | 4e8ca4f | 2012-07-02 23:58:38 +0000 | [diff] [blame] | 1399 | |
Eli Friedman | d20adbd | 2011-11-16 00:42:57 +0000 | [diff] [blame] | 1400 | LValue MakeNaturalAlignAddrLValue(llvm::Value *V, QualType T) { |
Eli Friedman | a0544d6 | 2011-12-03 04:14:32 +0000 | [diff] [blame] | 1401 | CharUnits Alignment; |
Fariborz Jahanian | bcd82af | 2014-08-05 18:37:48 +0000 | [diff] [blame] | 1402 | if (!T->isIncompleteType()) { |
Eli Friedman | a0544d6 | 2011-12-03 04:14:32 +0000 | [diff] [blame] | 1403 | Alignment = getContext().getTypeAlignInChars(T); |
Fariborz Jahanian | bcd82af | 2014-08-05 18:37:48 +0000 | [diff] [blame] | 1404 | unsigned MaxAlign = getContext().getLangOpts().MaxTypeAlign; |
| 1405 | if (MaxAlign && Alignment.getQuantity() > MaxAlign && |
| 1406 | !getContext().isAlignmentRequired(T)) |
| 1407 | Alignment = CharUnits::fromQuantity(MaxAlign); |
| 1408 | } |
Eli Friedman | d20adbd | 2011-11-16 00:42:57 +0000 | [diff] [blame] | 1409 | return LValue::MakeAddr(V, T, Alignment, getContext(), |
| 1410 | CGM.getTBAAInfo(T)); |
| 1411 | } |
Daniel Dunbar | 93b00a9 | 2010-08-21 02:53:44 +0000 | [diff] [blame] | 1412 | |
Chris Lattner | e9a6453 | 2007-06-22 21:44:33 +0000 | [diff] [blame] | 1413 | /// CreateTempAlloca - This creates a alloca and inserts it into the entry |
Daniel Dunbar | a7566f1 | 2010-02-09 02:48:28 +0000 | [diff] [blame] | 1414 | /// block. The caller is responsible for setting an appropriate alignment on |
| 1415 | /// the alloca. |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 1416 | llvm::AllocaInst *CreateTempAlloca(llvm::Type *Ty, |
Chris Lattner | 62ff6e8 | 2011-07-20 07:06:53 +0000 | [diff] [blame] | 1417 | const Twine &Name = "tmp"); |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1418 | |
John McCall | 2e6567a | 2010-04-22 01:10:34 +0000 | [diff] [blame] | 1419 | /// InitTempAlloca - Provide an initial value for the given alloca. |
| 1420 | void InitTempAlloca(llvm::AllocaInst *Alloca, llvm::Value *Value); |
| 1421 | |
Daniel Dunbar | d004918 | 2010-02-16 19:44:13 +0000 | [diff] [blame] | 1422 | /// CreateIRTemp - Create a temporary IR object of the given type, with |
| 1423 | /// appropriate alignment. This routine should only be used when an temporary |
| 1424 | /// value needs to be stored into an alloca (for example, to avoid explicit |
| 1425 | /// PHI construction), but the type is the IR type, not the type appropriate |
| 1426 | /// for storing in memory. |
Chris Lattner | 62ff6e8 | 2011-07-20 07:06:53 +0000 | [diff] [blame] | 1427 | llvm::AllocaInst *CreateIRTemp(QualType T, const Twine &Name = "tmp"); |
Daniel Dunbar | d004918 | 2010-02-16 19:44:13 +0000 | [diff] [blame] | 1428 | |
Daniel Dunbar | a7566f1 | 2010-02-09 02:48:28 +0000 | [diff] [blame] | 1429 | /// CreateMemTemp - Create a temporary memory object of the given type, with |
| 1430 | /// appropriate alignment. |
Chris Lattner | 62ff6e8 | 2011-07-20 07:06:53 +0000 | [diff] [blame] | 1431 | llvm::AllocaInst *CreateMemTemp(QualType T, const Twine &Name = "tmp"); |
Daniel Dunbar | a7566f1 | 2010-02-09 02:48:28 +0000 | [diff] [blame] | 1432 | |
John McCall | 7a626f6 | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 1433 | /// CreateAggTemp - Create a temporary memory object for the given |
| 1434 | /// aggregate type. |
Chris Lattner | 62ff6e8 | 2011-07-20 07:06:53 +0000 | [diff] [blame] | 1435 | AggValueSlot CreateAggTemp(QualType T, const Twine &Name = "tmp") { |
Eli Friedman | 38cd36d | 2011-12-03 02:13:40 +0000 | [diff] [blame] | 1436 | CharUnits Alignment = getContext().getTypeAlignInChars(T); |
Eli Friedman | c1d85b9 | 2011-12-03 00:54:26 +0000 | [diff] [blame] | 1437 | return AggValueSlot::forAddr(CreateMemTemp(T, Name), Alignment, |
| 1438 | T.getQualifiers(), |
John McCall | 8d6fc95 | 2011-08-25 20:40:09 +0000 | [diff] [blame] | 1439 | AggValueSlot::IsNotDestructed, |
John McCall | a5efa73 | 2011-08-25 23:04:34 +0000 | [diff] [blame] | 1440 | AggValueSlot::DoesNotNeedGCBarriers, |
Chad Rosier | 615ed1a | 2012-03-29 17:37:10 +0000 | [diff] [blame] | 1441 | AggValueSlot::IsNotAliased); |
John McCall | 7a626f6 | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 1442 | } |
| 1443 | |
Reid Kleckner | 314ef7b | 2014-02-01 00:04:45 +0000 | [diff] [blame] | 1444 | /// CreateInAllocaTmp - Create a temporary memory object for the given |
| 1445 | /// aggregate type. |
| 1446 | AggValueSlot CreateInAllocaTmp(QualType T, const Twine &Name = "inalloca"); |
| 1447 | |
John McCall | ad7c5c1 | 2011-02-08 08:22:06 +0000 | [diff] [blame] | 1448 | /// Emit a cast to void* in the appropriate address space. |
| 1449 | llvm::Value *EmitCastToVoidPtr(llvm::Value *value); |
| 1450 | |
Chris Lattner | 8394d79 | 2007-06-05 20:53:16 +0000 | [diff] [blame] | 1451 | /// EvaluateExprAsBool - Perform the usual unary conversions on the specified |
| 1452 | /// expression and compare the result against zero, returning an Int1Ty value. |
Chris Lattner | 23b7eb6 | 2007-06-15 23:05:46 +0000 | [diff] [blame] | 1453 | llvm::Value *EvaluateExprAsBool(const Expr *E); |
Chris Lattner | e9a6453 | 2007-06-22 21:44:33 +0000 | [diff] [blame] | 1454 | |
John McCall | a2342eb | 2010-12-05 02:00:02 +0000 | [diff] [blame] | 1455 | /// EmitIgnoredExpr - Emit an expression in a context which ignores the result. |
| 1456 | void EmitIgnoredExpr(const Expr *E); |
| 1457 | |
Chris Lattner | 4647a21 | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 1458 | /// EmitAnyExpr - Emit code to compute the specified expression which can have |
| 1459 | /// any type. The result is returned as an RValue struct. If this is an |
| 1460 | /// aggregate expression, the aggloc/agglocvolatile arguments indicate where |
| 1461 | /// the result should be returned. |
Mike Stump | ec3cbfe | 2009-05-26 22:03:21 +0000 | [diff] [blame] | 1462 | /// |
Dmitri Gribenko | adba9be | 2012-08-23 17:58:28 +0000 | [diff] [blame] | 1463 | /// \param ignoreResult True if the resulting value isn't used. |
John McCall | 7a626f6 | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 1464 | RValue EmitAnyExpr(const Expr *E, |
John McCall | 4e8ca4f | 2012-07-02 23:58:38 +0000 | [diff] [blame] | 1465 | AggValueSlot aggSlot = AggValueSlot::ignored(), |
| 1466 | bool ignoreResult = false); |
Devang Patel | 8ec4f83 | 2007-09-28 21:49:18 +0000 | [diff] [blame] | 1467 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1468 | // EmitVAListRef - Emit a "reference" to a va_list; this is either the address |
| 1469 | // or the value of the expression, depending on how va_list is defined. |
Eli Friedman | ddea0ad | 2009-01-20 17:46:04 +0000 | [diff] [blame] | 1470 | llvm::Value *EmitVAListRef(const Expr *E); |
| 1471 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1472 | /// EmitAnyExprToTemp - Similary to EmitAnyExpr(), however, the result will |
| 1473 | /// always be accessible even if no aggregate location is provided. |
John McCall | 7a626f6 | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 1474 | RValue EmitAnyExprToTemp(const Expr *E); |
Daniel Dunbar | 41cf9de | 2008-09-09 01:06:48 +0000 | [diff] [blame] | 1475 | |
John McCall | 91ca10f | 2011-03-08 09:11:50 +0000 | [diff] [blame] | 1476 | /// EmitAnyExprToMem - Emits the code necessary to evaluate an |
Chad Rosier | 615ed1a | 2012-03-29 17:37:10 +0000 | [diff] [blame] | 1477 | /// arbitrary expression into the given memory location. |
John McCall | 2188696 | 2010-04-21 10:05:39 +0000 | [diff] [blame] | 1478 | void EmitAnyExprToMem(const Expr *E, llvm::Value *Location, |
Chad Rosier | 615ed1a | 2012-03-29 17:37:10 +0000 | [diff] [blame] | 1479 | Qualifiers Quals, bool IsInitializer); |
John McCall | 2188696 | 2010-04-21 10:05:39 +0000 | [diff] [blame] | 1480 | |
John McCall | 91ca10f | 2011-03-08 09:11:50 +0000 | [diff] [blame] | 1481 | /// EmitExprAsInit - Emits the code necessary to initialize a |
| 1482 | /// location in memory with the given initializer. |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1483 | void EmitExprAsInit(const Expr *init, const ValueDecl *D, |
John McCall | 1553b19 | 2011-06-16 04:16:24 +0000 | [diff] [blame] | 1484 | LValue lvalue, bool capturedByInit); |
John McCall | 91ca10f | 2011-03-08 09:11:50 +0000 | [diff] [blame] | 1485 | |
Fariborz Jahanian | 7865220 | 2013-01-25 23:57:05 +0000 | [diff] [blame] | 1486 | /// hasVolatileMember - returns true if aggregate type has a volatile |
| 1487 | /// member. |
| 1488 | bool hasVolatileMember(QualType T) { |
| 1489 | if (const RecordType *RT = T->getAs<RecordType>()) { |
| 1490 | const RecordDecl *RD = cast<RecordDecl>(RT->getDecl()); |
| 1491 | return RD->hasVolatileMember(); |
| 1492 | } |
| 1493 | return false; |
| 1494 | } |
Arnaud A. de Grandmaison | 49c0446 | 2013-02-05 09:06:17 +0000 | [diff] [blame] | 1495 | /// EmitAggregateCopy - Emit an aggregate assignment. |
Benjamin Kramer | 1ca6691 | 2012-09-30 12:43:37 +0000 | [diff] [blame] | 1496 | /// |
| 1497 | /// The difference to EmitAggregateCopy is that tail padding is not copied. |
| 1498 | /// This is required for correctness when assigning non-POD structures in C++. |
| 1499 | void EmitAggregateAssign(llvm::Value *DestPtr, llvm::Value *SrcPtr, |
Fariborz Jahanian | 7865220 | 2013-01-25 23:57:05 +0000 | [diff] [blame] | 1500 | QualType EltTy) { |
| 1501 | bool IsVolatile = hasVolatileMember(EltTy); |
| 1502 | EmitAggregateCopy(DestPtr, SrcPtr, EltTy, IsVolatile, CharUnits::Zero(), |
| 1503 | true); |
Benjamin Kramer | 1ca6691 | 2012-09-30 12:43:37 +0000 | [diff] [blame] | 1504 | } |
| 1505 | |
Arnaud A. de Grandmaison | 49c0446 | 2013-02-05 09:06:17 +0000 | [diff] [blame] | 1506 | /// EmitAggregateCopy - Emit an aggregate copy. |
Mike Stump | 5e9e61b | 2009-05-23 22:29:41 +0000 | [diff] [blame] | 1507 | /// |
Sylvestre Ledru | 33b5baf | 2012-09-27 10:16:10 +0000 | [diff] [blame] | 1508 | /// \param isVolatile - True iff either the source or the destination is |
Mike Stump | 5e9e61b | 2009-05-23 22:29:41 +0000 | [diff] [blame] | 1509 | /// volatile. |
Benjamin Kramer | 1ca6691 | 2012-09-30 12:43:37 +0000 | [diff] [blame] | 1510 | /// \param isAssignment - If false, allow padding to be copied. This often |
| 1511 | /// yields more efficient. |
Daniel Dunbar | 0bc8e86 | 2008-09-09 20:49:46 +0000 | [diff] [blame] | 1512 | void EmitAggregateCopy(llvm::Value *DestPtr, llvm::Value *SrcPtr, |
Eli Friedman | 6d694a3 | 2011-12-05 22:23:28 +0000 | [diff] [blame] | 1513 | QualType EltTy, bool isVolatile=false, |
Benjamin Kramer | 1ca6691 | 2012-09-30 12:43:37 +0000 | [diff] [blame] | 1514 | CharUnits Alignment = CharUnits::Zero(), |
| 1515 | bool isAssignment = false); |
Daniel Dunbar | 0bc8e86 | 2008-09-09 20:49:46 +0000 | [diff] [blame] | 1516 | |
Devang Patel | da5d6bb | 2007-10-04 23:45:31 +0000 | [diff] [blame] | 1517 | /// StartBlock - Start new block named N. If insert block is a dummy block |
| 1518 | /// then reuse it. |
| 1519 | void StartBlock(const char *N); |
| 1520 | |
Anders Carlsson | 9396a89 | 2008-09-11 09:15:33 +0000 | [diff] [blame] | 1521 | /// GetAddrOfLocalVar - Return the address of a local variable. |
John McCall | 5d865c32 | 2010-08-31 07:33:07 +0000 | [diff] [blame] | 1522 | llvm::Value *GetAddrOfLocalVar(const VarDecl *VD) { |
| 1523 | llvm::Value *Res = LocalDeclMap[VD]; |
| 1524 | assert(Res && "Invalid argument to GetAddrOfLocalVar(), no decl!"); |
| 1525 | return Res; |
| 1526 | } |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1527 | |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 1528 | /// getOpaqueLValueMapping - Given an opaque value expression (which |
| 1529 | /// must be mapped to an l-value), return its mapping. |
| 1530 | const LValue &getOpaqueLValueMapping(const OpaqueValueExpr *e) { |
| 1531 | assert(OpaqueValueMapping::shouldBindAsLValue(e)); |
| 1532 | |
| 1533 | llvm::DenseMap<const OpaqueValueExpr*,LValue>::iterator |
| 1534 | it = OpaqueLValues.find(e); |
| 1535 | assert(it != OpaqueLValues.end() && "no mapping for opaque value!"); |
| 1536 | return it->second; |
| 1537 | } |
| 1538 | |
| 1539 | /// getOpaqueRValueMapping - Given an opaque value expression (which |
| 1540 | /// must be mapped to an r-value), return its mapping. |
| 1541 | const RValue &getOpaqueRValueMapping(const OpaqueValueExpr *e) { |
| 1542 | assert(!OpaqueValueMapping::shouldBindAsLValue(e)); |
| 1543 | |
| 1544 | llvm::DenseMap<const OpaqueValueExpr*,RValue>::iterator |
| 1545 | it = OpaqueRValues.find(e); |
| 1546 | assert(it != OpaqueRValues.end() && "no mapping for opaque value!"); |
John McCall | 1bf5846 | 2011-02-16 08:02:54 +0000 | [diff] [blame] | 1547 | return it->second; |
| 1548 | } |
| 1549 | |
Dan Gohman | 75d69da | 2008-05-22 00:50:06 +0000 | [diff] [blame] | 1550 | /// getAccessedFieldNo - Given an encoded value and a result number, return |
| 1551 | /// the input field number being accessed. |
| 1552 | static unsigned getAccessedFieldNo(unsigned Idx, const llvm::Constant *Elts); |
| 1553 | |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1554 | llvm::BlockAddress *GetAddrOfLabel(const LabelDecl *L); |
Chris Lattner | 2bb5cb4 | 2009-10-13 06:55:33 +0000 | [diff] [blame] | 1555 | llvm::BasicBlock *GetIndirectGotoBlock(); |
Daniel Dunbar | 88402ce | 2008-08-04 16:51:22 +0000 | [diff] [blame] | 1556 | |
Anders Carlsson | c0964b6 | 2010-05-22 17:35:42 +0000 | [diff] [blame] | 1557 | /// EmitNullInitialization - Generate code to set a value of the given type to |
| 1558 | /// null, If the type contains data member pointers, they will be initialized |
| 1559 | /// to -1 in accordance with the Itanium C++ ABI. |
| 1560 | void EmitNullInitialization(llvm::Value *DestPtr, QualType Ty); |
Anders Carlsson | 13abd7e | 2008-11-04 05:30:00 +0000 | [diff] [blame] | 1561 | |
| 1562 | // EmitVAArg - Generate code to get an argument from the passed in pointer |
| 1563 | // and update it accordingly. The return value is a pointer to the argument. |
| 1564 | // FIXME: We should be able to get rid of this method and use the va_arg |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1565 | // instruction in LLVM instead once it works well enough. |
Anders Carlsson | 13abd7e | 2008-11-04 05:30:00 +0000 | [diff] [blame] | 1566 | llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty); |
Anders Carlsson | e388a5b | 2008-12-20 20:27:15 +0000 | [diff] [blame] | 1567 | |
John McCall | 82fe67b | 2011-07-09 01:37:26 +0000 | [diff] [blame] | 1568 | /// emitArrayLength - Compute the length of an array, even if it's a |
| 1569 | /// VLA, and drill down to the base element type. |
| 1570 | llvm::Value *emitArrayLength(const ArrayType *arrayType, |
| 1571 | QualType &baseType, |
| 1572 | llvm::Value *&addr); |
| 1573 | |
John McCall | 23c29fe | 2011-06-24 21:55:10 +0000 | [diff] [blame] | 1574 | /// EmitVLASize - Capture all the sizes for the VLA expressions in |
| 1575 | /// the given variably-modified type and store them in the VLASizeMap. |
Daniel Dunbar | b6adc43 | 2009-07-19 06:58:07 +0000 | [diff] [blame] | 1576 | /// |
| 1577 | /// This function can be called with a null (unreachable) insert point. |
John McCall | 23c29fe | 2011-06-24 21:55:10 +0000 | [diff] [blame] | 1578 | void EmitVariablyModifiedType(QualType Ty); |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1579 | |
John McCall | 23c29fe | 2011-06-24 21:55:10 +0000 | [diff] [blame] | 1580 | /// getVLASize - Returns an LLVM value that corresponds to the size, |
| 1581 | /// in non-variably-sized elements, of a variable length array type, |
| 1582 | /// plus that largest non-variably-sized element type. Assumes that |
| 1583 | /// the type has already been emitted with EmitVariablyModifiedType. |
| 1584 | std::pair<llvm::Value*,QualType> getVLASize(const VariableArrayType *vla); |
| 1585 | std::pair<llvm::Value*,QualType> getVLASize(QualType vla); |
Anders Carlsson | ccbe920 | 2008-12-12 07:19:02 +0000 | [diff] [blame] | 1586 | |
Anders Carlsson | a5d077d | 2009-04-14 16:58:56 +0000 | [diff] [blame] | 1587 | /// LoadCXXThis - Load the value of 'this'. This function is only valid while |
| 1588 | /// generating code for an C++ member function. |
John McCall | 347132b | 2010-02-16 22:04:33 +0000 | [diff] [blame] | 1589 | llvm::Value *LoadCXXThis() { |
| 1590 | assert(CXXThisValue && "no 'this' value for this function"); |
| 1591 | return CXXThisValue; |
| 1592 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1593 | |
Anders Carlsson | e36a6b3 | 2010-01-02 01:01:18 +0000 | [diff] [blame] | 1594 | /// LoadCXXVTT - Load the VTT parameter to base constructors/destructors have |
| 1595 | /// virtual bases. |
Timur Iskhodzhanov | ee6bc53 | 2013-02-13 08:37:51 +0000 | [diff] [blame] | 1596 | // FIXME: Every place that calls LoadCXXVTT is something |
| 1597 | // that needs to be abstracted properly. |
John McCall | 347132b | 2010-02-16 22:04:33 +0000 | [diff] [blame] | 1598 | llvm::Value *LoadCXXVTT() { |
Timur Iskhodzhanov | ee6bc53 | 2013-02-13 08:37:51 +0000 | [diff] [blame] | 1599 | assert(CXXStructorImplicitParamValue && "no VTT value for this function"); |
| 1600 | return CXXStructorImplicitParamValue; |
| 1601 | } |
| 1602 | |
| 1603 | /// LoadCXXStructorImplicitParam - Load the implicit parameter |
| 1604 | /// for a constructor/destructor. |
| 1605 | llvm::Value *LoadCXXStructorImplicitParam() { |
| 1606 | assert(CXXStructorImplicitParamValue && |
| 1607 | "no implicit argument value for this function"); |
| 1608 | return CXXStructorImplicitParamValue; |
John McCall | 347132b | 2010-02-16 22:04:33 +0000 | [diff] [blame] | 1609 | } |
John McCall | 6ce7472 | 2010-02-16 04:15:37 +0000 | [diff] [blame] | 1610 | |
| 1611 | /// GetAddressOfBaseOfCompleteClass - Convert the given pointer to a |
Anders Carlsson | c4ba0cd | 2010-04-24 23:01:49 +0000 | [diff] [blame] | 1612 | /// complete class to the given direct base. |
| 1613 | llvm::Value * |
| 1614 | GetAddressOfDirectBaseInCompleteClass(llvm::Value *Value, |
| 1615 | const CXXRecordDecl *Derived, |
| 1616 | const CXXRecordDecl *Base, |
| 1617 | bool BaseIsVirtual); |
Anders Carlsson | bea9e74 | 2010-04-24 21:51:08 +0000 | [diff] [blame] | 1618 | |
Mike Stump | e5311b0 | 2009-11-30 20:08:49 +0000 | [diff] [blame] | 1619 | /// GetAddressOfBaseClass - This function will add the necessary delta to the |
| 1620 | /// load of 'this' and returns address of the base class. |
Michael J. Spencer | f5a1fbc | 2010-10-19 06:39:39 +0000 | [diff] [blame] | 1621 | llvm::Value *GetAddressOfBaseClass(llvm::Value *Value, |
Anders Carlsson | c4ba0cd | 2010-04-24 23:01:49 +0000 | [diff] [blame] | 1622 | const CXXRecordDecl *Derived, |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 1623 | CastExpr::path_const_iterator PathBegin, |
| 1624 | CastExpr::path_const_iterator PathEnd, |
Anders Carlsson | d829a02 | 2010-04-24 21:06:20 +0000 | [diff] [blame] | 1625 | bool NullCheckValue); |
| 1626 | |
Anders Carlsson | 8c79317 | 2009-11-23 17:57:54 +0000 | [diff] [blame] | 1627 | llvm::Value *GetAddressOfDerivedClass(llvm::Value *Value, |
Anders Carlsson | c4ba0cd | 2010-04-24 23:01:49 +0000 | [diff] [blame] | 1628 | const CXXRecordDecl *Derived, |
John McCall | cf14216 | 2010-08-07 06:22:56 +0000 | [diff] [blame] | 1629 | CastExpr::path_const_iterator PathBegin, |
| 1630 | CastExpr::path_const_iterator PathEnd, |
Anders Carlsson | 8c79317 | 2009-11-23 17:57:54 +0000 | [diff] [blame] | 1631 | bool NullCheckValue); |
| 1632 | |
Timur Iskhodzhanov | 57cbe5c | 2013-02-27 13:46:31 +0000 | [diff] [blame] | 1633 | /// GetVTTParameter - Return the VTT parameter that should be passed to a |
| 1634 | /// base constructor/destructor with virtual bases. |
| 1635 | /// FIXME: VTTs are Itanium ABI-specific, so the definition should move |
| 1636 | /// to ItaniumCXXABI.cpp together with all the references to VTT. |
| 1637 | llvm::Value *GetVTTParameter(GlobalDecl GD, bool ForVirtualBase, |
| 1638 | bool Delegating); |
| 1639 | |
John McCall | f8ff7b9 | 2010-02-23 00:48:20 +0000 | [diff] [blame] | 1640 | void EmitDelegateCXXConstructorCall(const CXXConstructorDecl *Ctor, |
| 1641 | CXXCtorType CtorType, |
Nick Lewycky | 2d84e84 | 2013-10-02 02:29:49 +0000 | [diff] [blame] | 1642 | const FunctionArgList &Args, |
| 1643 | SourceLocation Loc); |
Alexis Hunt | 61bc173 | 2011-05-01 07:04:31 +0000 | [diff] [blame] | 1644 | // It's important not to confuse this and the previous function. Delegating |
| 1645 | // constructors are the C++0x feature. The constructor delegate optimization |
| 1646 | // is used to reduce duplication in the base and complete consturctors where |
| 1647 | // they are substantially the same. |
| 1648 | void EmitDelegatingCXXConstructorCall(const CXXConstructorDecl *Ctor, |
| 1649 | const FunctionArgList &Args); |
Anders Carlsson | e11f9ce | 2010-05-02 23:20:53 +0000 | [diff] [blame] | 1650 | void EmitCXXConstructorCall(const CXXConstructorDecl *D, CXXCtorType Type, |
Douglas Gregor | 6153500 | 2013-01-31 05:50:40 +0000 | [diff] [blame] | 1651 | bool ForVirtualBase, bool Delegating, |
| 1652 | llvm::Value *This, |
Anders Carlsson | b7f8f59 | 2009-04-17 00:06:03 +0000 | [diff] [blame] | 1653 | CallExpr::const_arg_iterator ArgBeg, |
| 1654 | CallExpr::const_arg_iterator ArgEnd); |
Fariborz Jahanian | e988bda | 2010-11-13 21:53:34 +0000 | [diff] [blame] | 1655 | |
| 1656 | void EmitSynthesizedCXXCopyCtorCall(const CXXConstructorDecl *D, |
| 1657 | llvm::Value *This, llvm::Value *Src, |
| 1658 | CallExpr::const_arg_iterator ArgBeg, |
| 1659 | CallExpr::const_arg_iterator ArgEnd); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1660 | |
Fariborz Jahanian | 431c883 | 2009-08-19 20:55:16 +0000 | [diff] [blame] | 1661 | void EmitCXXAggrConstructorCall(const CXXConstructorDecl *D, |
Anders Carlsson | d49844b | 2009-09-23 02:45:36 +0000 | [diff] [blame] | 1662 | const ConstantArrayType *ArrayTy, |
Anders Carlsson | 3a202f6 | 2009-11-24 18:43:52 +0000 | [diff] [blame] | 1663 | llvm::Value *ArrayPtr, |
| 1664 | CallExpr::const_arg_iterator ArgBeg, |
Douglas Gregor | 05fc5be | 2010-07-21 01:10:17 +0000 | [diff] [blame] | 1665 | CallExpr::const_arg_iterator ArgEnd, |
| 1666 | bool ZeroInitialization = false); |
Michael J. Spencer | f5a1fbc | 2010-10-19 06:39:39 +0000 | [diff] [blame] | 1667 | |
Anders Carlsson | d49844b | 2009-09-23 02:45:36 +0000 | [diff] [blame] | 1668 | void EmitCXXAggrConstructorCall(const CXXConstructorDecl *D, |
| 1669 | llvm::Value *NumElements, |
Anders Carlsson | 3a202f6 | 2009-11-24 18:43:52 +0000 | [diff] [blame] | 1670 | llvm::Value *ArrayPtr, |
| 1671 | CallExpr::const_arg_iterator ArgBeg, |
Douglas Gregor | 05fc5be | 2010-07-21 01:10:17 +0000 | [diff] [blame] | 1672 | CallExpr::const_arg_iterator ArgEnd, |
| 1673 | bool ZeroInitialization = false); |
Anders Carlsson | b7f8f59 | 2009-04-17 00:06:03 +0000 | [diff] [blame] | 1674 | |
John McCall | 82fe67b | 2011-07-09 01:37:26 +0000 | [diff] [blame] | 1675 | static Destroyer destroyCXXObject; |
| 1676 | |
Anders Carlsson | 0a63741 | 2009-05-29 21:03:38 +0000 | [diff] [blame] | 1677 | void EmitCXXDestructorCall(const CXXDestructorDecl *D, CXXDtorType Type, |
Douglas Gregor | 6153500 | 2013-01-31 05:50:40 +0000 | [diff] [blame] | 1678 | bool ForVirtualBase, bool Delegating, |
| 1679 | llvm::Value *This); |
Michael J. Spencer | f5a1fbc | 2010-10-19 06:39:39 +0000 | [diff] [blame] | 1680 | |
John McCall | 99210dc | 2011-09-15 06:49:18 +0000 | [diff] [blame] | 1681 | void EmitNewArrayInitializer(const CXXNewExpr *E, QualType elementType, |
Richard Smith | 06a67e2 | 2014-06-03 06:58:52 +0000 | [diff] [blame] | 1682 | llvm::Value *NewPtr, llvm::Value *NumElements, |
| 1683 | llvm::Value *AllocSizeWithoutCookie); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1684 | |
Peter Collingbourne | 702b284 | 2011-11-27 22:09:22 +0000 | [diff] [blame] | 1685 | void EmitCXXTemporary(const CXXTemporary *Temporary, QualType TempType, |
| 1686 | llvm::Value *Ptr); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1687 | |
Anders Carlsson | 4a7b49b | 2009-05-31 01:40:14 +0000 | [diff] [blame] | 1688 | llvm::Value *EmitCXXNewExpr(const CXXNewExpr *E); |
Anders Carlsson | 81f0df9 | 2009-08-16 21:13:42 +0000 | [diff] [blame] | 1689 | void EmitCXXDeleteExpr(const CXXDeleteExpr *E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1690 | |
Eli Friedman | 24f5543 | 2009-11-18 00:57:03 +0000 | [diff] [blame] | 1691 | void EmitDeleteCall(const FunctionDecl *DeleteFD, llvm::Value *Ptr, |
| 1692 | QualType DeleteTy); |
| 1693 | |
Richard Smith | 760520b | 2014-06-03 23:27:44 +0000 | [diff] [blame] | 1694 | RValue EmitBuiltinNewDeleteCall(const FunctionProtoType *Type, |
| 1695 | const Expr *Arg, bool IsDelete); |
| 1696 | |
Mike Stump | c9b231c | 2009-11-15 08:09:41 +0000 | [diff] [blame] | 1697 | llvm::Value* EmitCXXTypeidExpr(const CXXTypeidExpr *E); |
Mike Stump | 6551170 | 2009-11-16 06:50:58 +0000 | [diff] [blame] | 1698 | llvm::Value *EmitDynamicCast(llvm::Value *V, const CXXDynamicCastExpr *DCE); |
Nico Weber | cf4ff586 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 1699 | llvm::Value* EmitCXXUuidofExpr(const CXXUuidofExpr *E); |
Mike Stump | c9b231c | 2009-11-15 08:09:41 +0000 | [diff] [blame] | 1700 | |
Richard Smith | 69d0d26 | 2012-08-24 00:54:33 +0000 | [diff] [blame] | 1701 | /// \brief Situations in which we might emit a check for the suitability of a |
| 1702 | /// pointer or glvalue. |
Richard Smith | 4d1458e | 2012-09-08 02:08:36 +0000 | [diff] [blame] | 1703 | enum TypeCheckKind { |
Richard Smith | 69d0d26 | 2012-08-24 00:54:33 +0000 | [diff] [blame] | 1704 | /// Checking the operand of a load. Must be suitably sized and aligned. |
Richard Smith | 4d1458e | 2012-09-08 02:08:36 +0000 | [diff] [blame] | 1705 | TCK_Load, |
Richard Smith | 69d0d26 | 2012-08-24 00:54:33 +0000 | [diff] [blame] | 1706 | /// Checking the destination of a store. Must be suitably sized and aligned. |
Richard Smith | 4d1458e | 2012-09-08 02:08:36 +0000 | [diff] [blame] | 1707 | TCK_Store, |
Richard Smith | 69d0d26 | 2012-08-24 00:54:33 +0000 | [diff] [blame] | 1708 | /// Checking the bound value in a reference binding. Must be suitably sized |
| 1709 | /// and aligned, but is not required to refer to an object (until the |
| 1710 | /// reference is used), per core issue 453. |
Richard Smith | 4d1458e | 2012-09-08 02:08:36 +0000 | [diff] [blame] | 1711 | TCK_ReferenceBinding, |
Richard Smith | 69d0d26 | 2012-08-24 00:54:33 +0000 | [diff] [blame] | 1712 | /// Checking the object expression in a non-static data member access. Must |
| 1713 | /// be an object within its lifetime. |
Richard Smith | 4d1458e | 2012-09-08 02:08:36 +0000 | [diff] [blame] | 1714 | TCK_MemberAccess, |
Richard Smith | 69d0d26 | 2012-08-24 00:54:33 +0000 | [diff] [blame] | 1715 | /// Checking the 'this' pointer for a call to a non-static member function. |
| 1716 | /// Must be an object within its lifetime. |
Richard Smith | 4d3110a | 2012-10-25 02:14:12 +0000 | [diff] [blame] | 1717 | TCK_MemberCall, |
| 1718 | /// Checking the 'this' pointer for a constructor call. |
Richard Smith | 2c5868c | 2013-02-13 21:18:23 +0000 | [diff] [blame] | 1719 | TCK_ConstructorCall, |
| 1720 | /// Checking the operand of a static_cast to a derived pointer type. Must be |
| 1721 | /// null or an object within its lifetime. |
| 1722 | TCK_DowncastPointer, |
| 1723 | /// Checking the operand of a static_cast to a derived reference type. Must |
| 1724 | /// be an object within its lifetime. |
| 1725 | TCK_DowncastReference |
Richard Smith | 69d0d26 | 2012-08-24 00:54:33 +0000 | [diff] [blame] | 1726 | }; |
| 1727 | |
Alexey Samsonov | ac4afe4 | 2014-07-07 23:59:57 +0000 | [diff] [blame] | 1728 | /// \brief Whether any type-checking sanitizers are enabled. If \c false, |
| 1729 | /// calls to EmitTypeCheck can be skipped. |
| 1730 | bool sanitizePerformTypeCheck() const; |
| 1731 | |
Richard Smith | 4d1458e | 2012-09-08 02:08:36 +0000 | [diff] [blame] | 1732 | /// \brief Emit a check that \p V is the address of storage of the |
Richard Smith | 69d0d26 | 2012-08-24 00:54:33 +0000 | [diff] [blame] | 1733 | /// appropriate size and alignment for an object of type \p Type. |
Richard Smith | e30752c | 2012-10-09 19:52:38 +0000 | [diff] [blame] | 1734 | void EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc, llvm::Value *V, |
Richard Smith | 4d1458e | 2012-09-08 02:08:36 +0000 | [diff] [blame] | 1735 | QualType Type, CharUnits Alignment = CharUnits::Zero()); |
Mike Stump | 3f6f9fe | 2009-12-16 02:57:00 +0000 | [diff] [blame] | 1736 | |
Richard Smith | 539e4a7 | 2013-02-23 02:53:19 +0000 | [diff] [blame] | 1737 | /// \brief Emit a check that \p Base points into an array object, which |
| 1738 | /// we can access at index \p Index. \p Accessed should be \c false if we |
| 1739 | /// this expression is used as an lvalue, for instance in "&Arr[Idx]". |
| 1740 | void EmitBoundsCheck(const Expr *E, const Expr *Base, llvm::Value *Index, |
| 1741 | QualType IndexType, bool Accessed); |
| 1742 | |
Chris Lattner | 116ce8f | 2010-01-09 21:40:03 +0000 | [diff] [blame] | 1743 | llvm::Value *EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV, |
| 1744 | bool isInc, bool isPre); |
| 1745 | ComplexPairTy EmitComplexPrePostIncDec(const UnaryOperator *E, LValue LV, |
| 1746 | bool isInc, bool isPre); |
Chris Lattner | 8394d79 | 2007-06-05 20:53:16 +0000 | [diff] [blame] | 1747 | //===--------------------------------------------------------------------===// |
Chris Lattner | 53621a5 | 2007-06-13 20:44:40 +0000 | [diff] [blame] | 1748 | // Declaration Emission |
Chris Lattner | 84915fa | 2007-06-02 04:16:21 +0000 | [diff] [blame] | 1749 | //===--------------------------------------------------------------------===// |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1750 | |
Daniel Dunbar | b6adc43 | 2009-07-19 06:58:07 +0000 | [diff] [blame] | 1751 | /// EmitDecl - Emit a declaration. |
| 1752 | /// |
| 1753 | /// This function can be called with a null (unreachable) insert point. |
Chris Lattner | 1ad38f8 | 2007-06-09 01:20:56 +0000 | [diff] [blame] | 1754 | void EmitDecl(const Decl &D); |
Daniel Dunbar | b6adc43 | 2009-07-19 06:58:07 +0000 | [diff] [blame] | 1755 | |
John McCall | 1c9c3fd | 2010-10-15 04:57:14 +0000 | [diff] [blame] | 1756 | /// EmitVarDecl - Emit a local variable declaration. |
Daniel Dunbar | b6adc43 | 2009-07-19 06:58:07 +0000 | [diff] [blame] | 1757 | /// |
| 1758 | /// This function can be called with a null (unreachable) insert point. |
John McCall | 1c9c3fd | 2010-10-15 04:57:14 +0000 | [diff] [blame] | 1759 | void EmitVarDecl(const VarDecl &D); |
Daniel Dunbar | b6adc43 | 2009-07-19 06:58:07 +0000 | [diff] [blame] | 1760 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1761 | void EmitScalarInit(const Expr *init, const ValueDecl *D, |
John McCall | 1553b19 | 2011-06-16 04:16:24 +0000 | [diff] [blame] | 1762 | LValue lvalue, bool capturedByInit); |
John McCall | d463132 | 2011-06-17 06:42:21 +0000 | [diff] [blame] | 1763 | void EmitScalarInit(llvm::Value *init, LValue lvalue); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1764 | |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 1765 | typedef void SpecialInitFn(CodeGenFunction &Init, const VarDecl &D, |
| 1766 | llvm::Value *Address); |
| 1767 | |
John McCall | 1c9c3fd | 2010-10-15 04:57:14 +0000 | [diff] [blame] | 1768 | /// EmitAutoVarDecl - Emit an auto variable declaration. |
Daniel Dunbar | b6adc43 | 2009-07-19 06:58:07 +0000 | [diff] [blame] | 1769 | /// |
| 1770 | /// This function can be called with a null (unreachable) insert point. |
John McCall | c533cb7 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 1771 | void EmitAutoVarDecl(const VarDecl &D); |
| 1772 | |
| 1773 | class AutoVarEmission { |
| 1774 | friend class CodeGenFunction; |
| 1775 | |
John McCall | 9e2e22f | 2011-02-22 07:16:58 +0000 | [diff] [blame] | 1776 | const VarDecl *Variable; |
John McCall | c533cb7 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 1777 | |
| 1778 | /// The alignment of the variable. |
| 1779 | CharUnits Alignment; |
| 1780 | |
| 1781 | /// The address of the alloca. Null if the variable was emitted |
| 1782 | /// as a global constant. |
| 1783 | llvm::Value *Address; |
| 1784 | |
| 1785 | llvm::Value *NRVOFlag; |
| 1786 | |
| 1787 | /// True if the variable is a __block variable. |
| 1788 | bool IsByRef; |
| 1789 | |
| 1790 | /// True if the variable is of aggregate type and has a constant |
| 1791 | /// initializer. |
| 1792 | bool IsConstantAggregate; |
| 1793 | |
Nadav Rotem | 1da3094 | 2013-03-23 06:43:35 +0000 | [diff] [blame] | 1794 | /// Non-null if we should use lifetime annotations. |
| 1795 | llvm::Value *SizeForLifetimeMarkers; |
| 1796 | |
John McCall | 9e2e22f | 2011-02-22 07:16:58 +0000 | [diff] [blame] | 1797 | struct Invalid {}; |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 1798 | AutoVarEmission(Invalid) : Variable(nullptr) {} |
John McCall | 9e2e22f | 2011-02-22 07:16:58 +0000 | [diff] [blame] | 1799 | |
John McCall | c533cb7 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 1800 | AutoVarEmission(const VarDecl &variable) |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 1801 | : Variable(&variable), Address(nullptr), NRVOFlag(nullptr), |
Nadav Rotem | 1da3094 | 2013-03-23 06:43:35 +0000 | [diff] [blame] | 1802 | IsByRef(false), IsConstantAggregate(false), |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 1803 | SizeForLifetimeMarkers(nullptr) {} |
John McCall | c533cb7 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 1804 | |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 1805 | bool wasEmittedAsGlobal() const { return Address == nullptr; } |
John McCall | c533cb7 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 1806 | |
| 1807 | public: |
John McCall | 9e2e22f | 2011-02-22 07:16:58 +0000 | [diff] [blame] | 1808 | static AutoVarEmission invalid() { return AutoVarEmission(Invalid()); } |
| 1809 | |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 1810 | bool useLifetimeMarkers() const { |
| 1811 | return SizeForLifetimeMarkers != nullptr; |
| 1812 | } |
Nadav Rotem | 1da3094 | 2013-03-23 06:43:35 +0000 | [diff] [blame] | 1813 | llvm::Value *getSizeForLifetimeMarkers() const { |
| 1814 | assert(useLifetimeMarkers()); |
| 1815 | return SizeForLifetimeMarkers; |
| 1816 | } |
| 1817 | |
| 1818 | /// Returns the raw, allocated address, which is not necessarily |
| 1819 | /// the address of the object itself. |
| 1820 | llvm::Value *getAllocatedAddress() const { |
| 1821 | return Address; |
| 1822 | } |
| 1823 | |
John McCall | c533cb7 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 1824 | /// Returns the address of the object within this declaration. |
| 1825 | /// Note that this does not chase the forwarding pointer for |
| 1826 | /// __block decls. |
| 1827 | llvm::Value *getObjectAddress(CodeGenFunction &CGF) const { |
| 1828 | if (!IsByRef) return Address; |
| 1829 | |
| 1830 | return CGF.Builder.CreateStructGEP(Address, |
John McCall | 9e2e22f | 2011-02-22 07:16:58 +0000 | [diff] [blame] | 1831 | CGF.getByRefValueLLVMField(Variable), |
| 1832 | Variable->getNameAsString()); |
John McCall | c533cb7 | 2011-02-22 06:44:22 +0000 | [diff] [blame] | 1833 | } |
| 1834 | }; |
| 1835 | AutoVarEmission EmitAutoVarAlloca(const VarDecl &var); |
| 1836 | void EmitAutoVarInit(const AutoVarEmission &emission); |
| 1837 | void EmitAutoVarCleanups(const AutoVarEmission &emission); |
John McCall | 82fe67b | 2011-07-09 01:37:26 +0000 | [diff] [blame] | 1838 | void emitAutoVarTypeCleanup(const AutoVarEmission &emission, |
| 1839 | QualType::DestructionKind dtorKind); |
Daniel Dunbar | b6adc43 | 2009-07-19 06:58:07 +0000 | [diff] [blame] | 1840 | |
John McCall | 1c9c3fd | 2010-10-15 04:57:14 +0000 | [diff] [blame] | 1841 | void EmitStaticVarDecl(const VarDecl &D, |
| 1842 | llvm::GlobalValue::LinkageTypes Linkage); |
Daniel Dunbar | a94ecd2 | 2008-08-16 03:19:19 +0000 | [diff] [blame] | 1843 | |
| 1844 | /// EmitParmDecl - Emit a ParmVarDecl or an ImplicitParamDecl. |
Reid Kleckner | 314ef7b | 2014-02-01 00:04:45 +0000 | [diff] [blame] | 1845 | void EmitParmDecl(const VarDecl &D, llvm::Value *Arg, bool ArgIsPointer, |
| 1846 | unsigned ArgNo); |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1847 | |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 1848 | /// protectFromPeepholes - Protect a value that we're intending to |
| 1849 | /// store to the side, but which will probably be used later, from |
| 1850 | /// aggressive peepholing optimizations that might delete it. |
| 1851 | /// |
| 1852 | /// Pass the result to unprotectFromPeepholes to declare that |
| 1853 | /// protection is no longer required. |
| 1854 | /// |
| 1855 | /// There's no particular reason why this shouldn't apply to |
| 1856 | /// l-values, it's just that no existing peepholes work on pointers. |
| 1857 | PeepholeProtection protectFromPeepholes(RValue rvalue); |
| 1858 | void unprotectFromPeepholes(PeepholeProtection protection); |
| 1859 | |
Chris Lattner | 84915fa | 2007-06-02 04:16:21 +0000 | [diff] [blame] | 1860 | //===--------------------------------------------------------------------===// |
Chris Lattner | 308f431 | 2007-05-29 23:50:05 +0000 | [diff] [blame] | 1861 | // Statement Emission |
| 1862 | //===--------------------------------------------------------------------===// |
| 1863 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1864 | /// EmitStopPoint - Emit a debug stoppoint if we are emitting debug info. |
Daniel Dunbar | 5fc2871 | 2008-11-12 08:21:33 +0000 | [diff] [blame] | 1865 | void EmitStopPoint(const Stmt *S); |
| 1866 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1867 | /// EmitStmt - Emit the code for the statement \arg S. It is legal to call |
| 1868 | /// this function even if there is no current insertion point. |
| 1869 | /// |
| 1870 | /// This function may clear the current insertion point; callers should use |
| 1871 | /// EnsureInsertPoint if they wish to subsequently generate code without first |
| 1872 | /// calling EmitBlock, EmitBranch, or EmitStmt. |
Chris Lattner | 308f431 | 2007-05-29 23:50:05 +0000 | [diff] [blame] | 1873 | void EmitStmt(const Stmt *S); |
Daniel Dunbar | 5c7e393 | 2008-11-11 23:11:34 +0000 | [diff] [blame] | 1874 | |
Daniel Dunbar | 5fc2871 | 2008-11-12 08:21:33 +0000 | [diff] [blame] | 1875 | /// EmitSimpleStmt - Try to emit a "simple" statement which does not |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1876 | /// necessarily require an insertion point or debug information; typically |
| 1877 | /// because the statement amounts to a jump or a container of other |
| 1878 | /// statements. |
Daniel Dunbar | 5fc2871 | 2008-11-12 08:21:33 +0000 | [diff] [blame] | 1879 | /// |
| 1880 | /// \return True if the statement was handled. |
| 1881 | bool EmitSimpleStmt(const Stmt *S); |
| 1882 | |
Eli Friedman | 4871a46 | 2013-06-10 22:04:49 +0000 | [diff] [blame] | 1883 | llvm::Value *EmitCompoundStmt(const CompoundStmt &S, bool GetLast = false, |
| 1884 | AggValueSlot AVS = AggValueSlot::ignored()); |
| 1885 | llvm::Value *EmitCompoundStmtWithoutScope(const CompoundStmt &S, |
| 1886 | bool GetLast = false, |
| 1887 | AggValueSlot AVS = |
| 1888 | AggValueSlot::ignored()); |
Daniel Dunbar | 5c7e393 | 2008-11-11 23:11:34 +0000 | [diff] [blame] | 1889 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1890 | /// EmitLabel - Emit the block for the given label. It is legal to call this |
| 1891 | /// function even if there is no current insertion point. |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1892 | void EmitLabel(const LabelDecl *D); // helper for EmitLabelStmt. |
Daniel Dunbar | 5c7e393 | 2008-11-11 23:11:34 +0000 | [diff] [blame] | 1893 | |
Chris Lattner | ac24820 | 2007-05-30 00:13:02 +0000 | [diff] [blame] | 1894 | void EmitLabelStmt(const LabelStmt &S); |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 1895 | void EmitAttributedStmt(const AttributedStmt &S); |
Chris Lattner | ac24820 | 2007-05-30 00:13:02 +0000 | [diff] [blame] | 1896 | void EmitGotoStmt(const GotoStmt &S); |
Daniel Dunbar | 88402ce | 2008-08-04 16:51:22 +0000 | [diff] [blame] | 1897 | void EmitIndirectGotoStmt(const IndirectGotoStmt &S); |
Chris Lattner | 5269c03 | 2007-05-30 21:03:58 +0000 | [diff] [blame] | 1898 | void EmitIfStmt(const IfStmt &S); |
Aaron Ballman | b06b15a | 2014-06-06 12:40:24 +0000 | [diff] [blame] | 1899 | |
| 1900 | void EmitCondBrHints(llvm::LLVMContext &Context, llvm::BranchInst *CondBr, |
| 1901 | const ArrayRef<const Attr *> &Attrs); |
| 1902 | void EmitWhileStmt(const WhileStmt &S, |
| 1903 | const ArrayRef<const Attr *> &Attrs = None); |
| 1904 | void EmitDoStmt(const DoStmt &S, const ArrayRef<const Attr *> &Attrs = None); |
| 1905 | void EmitForStmt(const ForStmt &S, |
| 1906 | const ArrayRef<const Attr *> &Attrs = None); |
Chris Lattner | 3f3dbee | 2007-06-02 03:19:07 +0000 | [diff] [blame] | 1907 | void EmitReturnStmt(const ReturnStmt &S); |
Chris Lattner | 1ad38f8 | 2007-06-09 01:20:56 +0000 | [diff] [blame] | 1908 | void EmitDeclStmt(const DeclStmt &S); |
Daniel Dunbar | 5fc2871 | 2008-11-12 08:21:33 +0000 | [diff] [blame] | 1909 | void EmitBreakStmt(const BreakStmt &S); |
| 1910 | void EmitContinueStmt(const ContinueStmt &S); |
Devang Patel | da5d6bb | 2007-10-04 23:45:31 +0000 | [diff] [blame] | 1911 | void EmitSwitchStmt(const SwitchStmt &S); |
| 1912 | void EmitDefaultStmt(const DefaultStmt &S); |
| 1913 | void EmitCaseStmt(const CaseStmt &S); |
Devang Patel | 1166312 | 2007-10-08 20:57:48 +0000 | [diff] [blame] | 1914 | void EmitCaseStmtRange(const CaseStmt &S); |
Chad Rosier | 6051bb9 | 2012-08-28 18:54:39 +0000 | [diff] [blame] | 1915 | void EmitAsmStmt(const AsmStmt &S); |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1916 | |
Anders Carlsson | 2e744e8 | 2008-08-30 19:51:14 +0000 | [diff] [blame] | 1917 | void EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S); |
Anders Carlsson | 1963b0c | 2008-09-09 10:04:29 +0000 | [diff] [blame] | 1918 | void EmitObjCAtTryStmt(const ObjCAtTryStmt &S); |
| 1919 | void EmitObjCAtThrowStmt(const ObjCAtThrowStmt &S); |
Chris Lattner | e132e24 | 2008-11-15 21:26:17 +0000 | [diff] [blame] | 1920 | void EmitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt &S); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1921 | void EmitObjCAutoreleasePoolStmt(const ObjCAutoreleasePoolStmt &S); |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1922 | |
John McCall | b609d3f | 2010-07-07 06:56:46 +0000 | [diff] [blame] | 1923 | void EnterCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock = false); |
| 1924 | void ExitCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock = false); |
John McCall | b81884d | 2010-02-19 09:25:03 +0000 | [diff] [blame] | 1925 | |
Anders Carlsson | 52d78a5 | 2009-09-27 18:58:34 +0000 | [diff] [blame] | 1926 | void EmitCXXTryStmt(const CXXTryStmt &S); |
Reid Kleckner | 543a16c | 2013-09-16 21:46:30 +0000 | [diff] [blame] | 1927 | void EmitSEHTryStmt(const SEHTryStmt &S); |
Nico Weber | 9b98207 | 2014-07-07 00:12:30 +0000 | [diff] [blame] | 1928 | void EmitSEHLeaveStmt(const SEHLeaveStmt &S); |
Aaron Ballman | b06b15a | 2014-06-06 12:40:24 +0000 | [diff] [blame] | 1929 | void EmitCXXForRangeStmt(const CXXForRangeStmt &S, |
| 1930 | const ArrayRef<const Attr *> &Attrs = None); |
Michael J. Spencer | f5a1fbc | 2010-10-19 06:39:39 +0000 | [diff] [blame] | 1931 | |
Ben Langmuir | 3b4c30b | 2013-05-09 19:17:11 +0000 | [diff] [blame] | 1932 | llvm::Function *EmitCapturedStmt(const CapturedStmt &S, CapturedRegionKind K); |
Alexey Bataev | aca7fcf | 2014-06-30 02:55:54 +0000 | [diff] [blame] | 1933 | llvm::Function *GenerateCapturedStmtFunction(const CapturedStmt &S); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1934 | llvm::Value *GenerateCapturedStmtArgument(const CapturedStmt &S); |
| 1935 | |
| 1936 | void EmitOMPParallelDirective(const OMPParallelDirective &S); |
Alexander Musman | 515ad8c | 2014-05-22 08:54:05 +0000 | [diff] [blame] | 1937 | void EmitOMPSimdDirective(const OMPSimdDirective &S); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1938 | void EmitOMPForDirective(const OMPForDirective &S); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1939 | void EmitOMPSectionsDirective(const OMPSectionsDirective &S); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1940 | void EmitOMPSectionDirective(const OMPSectionDirective &S); |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1941 | void EmitOMPSingleDirective(const OMPSingleDirective &S); |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1942 | void EmitOMPMasterDirective(const OMPMasterDirective &S); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1943 | void EmitOMPCriticalDirective(const OMPCriticalDirective &S); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1944 | void EmitOMPParallelForDirective(const OMPParallelForDirective &S); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1945 | void EmitOMPParallelSectionsDirective(const OMPParallelSectionsDirective &S); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1946 | void EmitOMPTaskDirective(const OMPTaskDirective &S); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1947 | void EmitOMPTaskyieldDirective(const OMPTaskyieldDirective &S); |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1948 | void EmitOMPBarrierDirective(const OMPBarrierDirective &S); |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1949 | void EmitOMPTaskwaitDirective(const OMPTaskwaitDirective &S); |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1950 | void EmitOMPFlushDirective(const OMPFlushDirective &S); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1951 | void EmitOMPOrderedDirective(const OMPOrderedDirective &S); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1952 | void EmitOMPAtomicDirective(const OMPAtomicDirective &S); |
Ben Langmuir | 3b4c30b | 2013-05-09 19:17:11 +0000 | [diff] [blame] | 1953 | |
Chris Lattner | 208ae96 | 2007-05-30 17:57:17 +0000 | [diff] [blame] | 1954 | //===--------------------------------------------------------------------===// |
Chris Lattner | d7f5886 | 2007-06-02 05:24:33 +0000 | [diff] [blame] | 1955 | // LValue Expression Emission |
| 1956 | //===--------------------------------------------------------------------===// |
Chris Lattner | 8394d79 | 2007-06-05 20:53:16 +0000 | [diff] [blame] | 1957 | |
Daniel Dunbar | c79407f | 2009-02-05 07:09:07 +0000 | [diff] [blame] | 1958 | /// GetUndefRValue - Get an appropriate 'undef' rvalue for the given type. |
| 1959 | RValue GetUndefRValue(QualType Ty); |
| 1960 | |
Daniel Dunbar | bb197e4 | 2009-01-09 16:50:52 +0000 | [diff] [blame] | 1961 | /// EmitUnsupportedRValue - Emit a dummy r-value using the type of E |
| 1962 | /// and issue an ErrorUnsupported style diagnostic (using the |
| 1963 | /// provided Name). |
| 1964 | RValue EmitUnsupportedRValue(const Expr *E, |
| 1965 | const char *Name); |
| 1966 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1967 | /// EmitUnsupportedLValue - Emit a dummy l-value using the type of E and issue |
| 1968 | /// an ErrorUnsupported style diagnostic (using the provided Name). |
Daniel Dunbar | f2e6988 | 2008-08-25 20:45:57 +0000 | [diff] [blame] | 1969 | LValue EmitUnsupportedLValue(const Expr *E, |
| 1970 | const char *Name); |
| 1971 | |
Chris Lattner | 8394d79 | 2007-06-05 20:53:16 +0000 | [diff] [blame] | 1972 | /// EmitLValue - Emit code to compute a designator that specifies the location |
| 1973 | /// of the expression. |
| 1974 | /// |
| 1975 | /// This can return one of two things: a simple address or a bitfield |
| 1976 | /// reference. In either case, the LLVM Value* in the LValue structure is |
| 1977 | /// guaranteed to be an LLVM pointer type. |
| 1978 | /// |
| 1979 | /// If this returns a bitfield reference, nothing about the pointee type of |
| 1980 | /// the LLVM value is known: For example, it may not be a pointer to an |
| 1981 | /// integer. |
| 1982 | /// |
| 1983 | /// If this returns a normal address, and if the lvalue's C type is fixed |
| 1984 | /// size, this method guarantees that the returned pointer type will point to |
| 1985 | /// an LLVM type of the same size of the lvalue's type. If the lvalue has a |
| 1986 | /// variable length type, this is not possible. |
| 1987 | /// |
Chris Lattner | d7f5886 | 2007-06-02 05:24:33 +0000 | [diff] [blame] | 1988 | LValue EmitLValue(const Expr *E); |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 1989 | |
Richard Smith | 4d1458e | 2012-09-08 02:08:36 +0000 | [diff] [blame] | 1990 | /// \brief Same as EmitLValue but additionally we generate checking code to |
| 1991 | /// guard against undefined behavior. This is only suitable when we know |
| 1992 | /// that the address will be used to access the object. |
| 1993 | LValue EmitCheckedLValue(const Expr *E, TypeCheckKind TCK); |
Mike Stump | 3f6f9fe | 2009-12-16 02:57:00 +0000 | [diff] [blame] | 1994 | |
Nick Lewycky | 2d84e84 | 2013-10-02 02:29:49 +0000 | [diff] [blame] | 1995 | RValue convertTempToRValue(llvm::Value *addr, QualType type, |
| 1996 | SourceLocation Loc); |
John McCall | 47fb950 | 2013-03-07 21:37:08 +0000 | [diff] [blame] | 1997 | |
John McCall | a8ec7eb | 2013-03-07 21:37:17 +0000 | [diff] [blame] | 1998 | void EmitAtomicInit(Expr *E, LValue lvalue); |
| 1999 | |
Nick Lewycky | 2d84e84 | 2013-10-02 02:29:49 +0000 | [diff] [blame] | 2000 | RValue EmitAtomicLoad(LValue lvalue, SourceLocation loc, |
John McCall | a8ec7eb | 2013-03-07 21:37:17 +0000 | [diff] [blame] | 2001 | AggValueSlot slot = AggValueSlot::ignored()); |
| 2002 | |
| 2003 | void EmitAtomicStore(RValue rvalue, LValue lvalue, bool isInit); |
| 2004 | |
John McCall | 3a7f692 | 2010-10-27 20:58:56 +0000 | [diff] [blame] | 2005 | /// EmitToMemory - Change a scalar value from its value |
| 2006 | /// representation to its in-memory representation. |
| 2007 | llvm::Value *EmitToMemory(llvm::Value *Value, QualType Ty); |
| 2008 | |
| 2009 | /// EmitFromMemory - Change a scalar value from its memory |
| 2010 | /// representation to its value representation. |
| 2011 | llvm::Value *EmitFromMemory(llvm::Value *Value, QualType Ty); |
| 2012 | |
Daniel Dunbar | 1d42546 | 2009-02-10 00:57:50 +0000 | [diff] [blame] | 2013 | /// EmitLoadOfScalar - Load a scalar value from an address, taking |
| 2014 | /// care to appropriately convert from the memory representation to |
| 2015 | /// the LLVM value representation. |
Mike Stump | c6ea7c1 | 2009-02-17 17:00:02 +0000 | [diff] [blame] | 2016 | llvm::Value *EmitLoadOfScalar(llvm::Value *Addr, bool Volatile, |
Dan Gohman | 947c9af | 2010-10-14 23:06:10 +0000 | [diff] [blame] | 2017 | unsigned Alignment, QualType Ty, |
Nick Lewycky | 2d84e84 | 2013-10-02 02:29:49 +0000 | [diff] [blame] | 2018 | SourceLocation Loc, |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 2019 | llvm::MDNode *TBAAInfo = nullptr, |
Manman Ren | c451e57 | 2013-04-04 21:53:22 +0000 | [diff] [blame] | 2020 | QualType TBAABaseTy = QualType(), |
| 2021 | uint64_t TBAAOffset = 0); |
John McCall | 55e1fbc | 2011-06-25 02:11:03 +0000 | [diff] [blame] | 2022 | |
| 2023 | /// EmitLoadOfScalar - Load a scalar value from an address, taking |
| 2024 | /// care to appropriately convert from the memory representation to |
| 2025 | /// the LLVM value representation. The l-value must be a simple |
| 2026 | /// l-value. |
Nick Lewycky | 2d84e84 | 2013-10-02 02:29:49 +0000 | [diff] [blame] | 2027 | llvm::Value *EmitLoadOfScalar(LValue lvalue, SourceLocation Loc); |
Daniel Dunbar | 1d42546 | 2009-02-10 00:57:50 +0000 | [diff] [blame] | 2028 | |
| 2029 | /// EmitStoreOfScalar - Store a scalar value to an address, taking |
| 2030 | /// care to appropriately convert from the memory representation to |
| 2031 | /// the LLVM value representation. |
Mike Stump | c6ea7c1 | 2009-02-17 17:00:02 +0000 | [diff] [blame] | 2032 | void EmitStoreOfScalar(llvm::Value *Value, llvm::Value *Addr, |
Dan Gohman | 947c9af | 2010-10-14 23:06:10 +0000 | [diff] [blame] | 2033 | bool Volatile, unsigned Alignment, QualType Ty, |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 2034 | llvm::MDNode *TBAAInfo = nullptr, bool isInit = false, |
Manman Ren | c451e57 | 2013-04-04 21:53:22 +0000 | [diff] [blame] | 2035 | QualType TBAABaseTy = QualType(), |
| 2036 | uint64_t TBAAOffset = 0); |
John McCall | 55e1fbc | 2011-06-25 02:11:03 +0000 | [diff] [blame] | 2037 | |
| 2038 | /// EmitStoreOfScalar - Store a scalar value to an address, taking |
| 2039 | /// care to appropriately convert from the memory representation to |
| 2040 | /// the LLVM value representation. The l-value must be a simple |
David Chisnall | fa35df6 | 2012-01-16 17:27:18 +0000 | [diff] [blame] | 2041 | /// l-value. The isInit flag indicates whether this is an initialization. |
| 2042 | /// If so, atomic qualifiers are ignored and the store is always non-atomic. |
| 2043 | void EmitStoreOfScalar(llvm::Value *value, LValue lvalue, bool isInit=false); |
Daniel Dunbar | 1d42546 | 2009-02-10 00:57:50 +0000 | [diff] [blame] | 2044 | |
Chris Lattner | 8394d79 | 2007-06-05 20:53:16 +0000 | [diff] [blame] | 2045 | /// EmitLoadOfLValue - Given an expression that represents a value lvalue, |
| 2046 | /// this method emits the address of the lvalue, then loads the result as an |
| 2047 | /// rvalue, returning the rvalue. |
Nick Lewycky | 2d84e84 | 2013-10-02 02:29:49 +0000 | [diff] [blame] | 2048 | RValue EmitLoadOfLValue(LValue V, SourceLocation Loc); |
John McCall | 55e1fbc | 2011-06-25 02:11:03 +0000 | [diff] [blame] | 2049 | RValue EmitLoadOfExtVectorElementLValue(LValue V); |
| 2050 | RValue EmitLoadOfBitfieldLValue(LValue LV); |
Renato Golin | 230c5eb | 2014-05-19 18:15:42 +0000 | [diff] [blame] | 2051 | RValue EmitLoadOfGlobalRegLValue(LValue LV); |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 2052 | |
Chris Lattner | 8394d79 | 2007-06-05 20:53:16 +0000 | [diff] [blame] | 2053 | /// EmitStoreThroughLValue - Store the specified rvalue into the specified |
| 2054 | /// lvalue, where both are guaranteed to the have the same type, and that type |
| 2055 | /// is 'Ty'. |
David Chisnall | fa35df6 | 2012-01-16 17:27:18 +0000 | [diff] [blame] | 2056 | void EmitStoreThroughLValue(RValue Src, LValue Dst, bool isInit=false); |
John McCall | 55e1fbc | 2011-06-25 02:11:03 +0000 | [diff] [blame] | 2057 | void EmitStoreThroughExtVectorComponentLValue(RValue Src, LValue Dst); |
Renato Golin | 230c5eb | 2014-05-19 18:15:42 +0000 | [diff] [blame] | 2058 | void EmitStoreThroughGlobalRegLValue(RValue Src, LValue Dst); |
Daniel Dunbar | 9b1335e | 2008-11-19 09:36:46 +0000 | [diff] [blame] | 2059 | |
Nick Lewycky | 2d84e84 | 2013-10-02 02:29:49 +0000 | [diff] [blame] | 2060 | /// EmitStoreThroughBitfieldLValue - Store Src into Dst with same constraints |
| 2061 | /// as EmitStoreThroughLValue. |
Daniel Dunbar | 9b1335e | 2008-11-19 09:36:46 +0000 | [diff] [blame] | 2062 | /// |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 2063 | /// \param Result [out] - If non-null, this will be set to a Value* for the |
| 2064 | /// bit-field contents after the store, appropriate for use as the result of |
| 2065 | /// an assignment to the bit-field. |
John McCall | 55e1fbc | 2011-06-25 02:11:03 +0000 | [diff] [blame] | 2066 | void EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst, |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 2067 | llvm::Value **Result=nullptr); |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 2068 | |
John McCall | 4f29b49 | 2010-11-16 23:07:28 +0000 | [diff] [blame] | 2069 | /// Emit an l-value for an assignment (simple or compound) of complex type. |
| 2070 | LValue EmitComplexAssignmentLValue(const BinaryOperator *E); |
John McCall | a2342eb | 2010-12-05 02:00:02 +0000 | [diff] [blame] | 2071 | LValue EmitComplexCompoundAssignmentLValue(const CompoundAssignOperator *E); |
Eli Friedman | f045007 | 2013-06-12 01:40:06 +0000 | [diff] [blame] | 2072 | LValue EmitScalarCompooundAssignWithComplex(const CompoundAssignOperator *E, |
| 2073 | llvm::Value *&Result); |
John McCall | 4f29b49 | 2010-11-16 23:07:28 +0000 | [diff] [blame] | 2074 | |
Chris Lattner | 57540c5 | 2011-04-15 05:22:18 +0000 | [diff] [blame] | 2075 | // Note: only available for agg return types |
Daniel Dunbar | 8cde00a | 2008-09-04 03:20:13 +0000 | [diff] [blame] | 2076 | LValue EmitBinaryOperatorLValue(const BinaryOperator *E); |
John McCall | a2342eb | 2010-12-05 02:00:02 +0000 | [diff] [blame] | 2077 | LValue EmitCompoundAssignmentLValue(const CompoundAssignOperator *E); |
Daniel Dunbar | 8d9dc4a | 2009-02-11 20:59:32 +0000 | [diff] [blame] | 2078 | // Note: only available for agg return types |
Christopher Lamb | d91c3d4 | 2007-12-29 05:02:41 +0000 | [diff] [blame] | 2079 | LValue EmitCallExprLValue(const CallExpr *E); |
Daniel Dunbar | 8d9dc4a | 2009-02-11 20:59:32 +0000 | [diff] [blame] | 2080 | // Note: only available for agg return types |
| 2081 | LValue EmitVAArgExprLValue(const VAArgExpr *E); |
Chris Lattner | d7f5886 | 2007-06-02 05:24:33 +0000 | [diff] [blame] | 2082 | LValue EmitDeclRefLValue(const DeclRefExpr *E); |
Renato Golin | 230c5eb | 2014-05-19 18:15:42 +0000 | [diff] [blame] | 2083 | LValue EmitReadRegister(const VarDecl *VD); |
Chris Lattner | 4347e369 | 2007-06-06 04:54:52 +0000 | [diff] [blame] | 2084 | LValue EmitStringLiteralLValue(const StringLiteral *E); |
Chris Lattner | d7e7b8e | 2009-02-24 22:18:39 +0000 | [diff] [blame] | 2085 | LValue EmitObjCEncodeExprLValue(const ObjCEncodeExpr *E); |
Chris Lattner | 6307f19 | 2008-08-10 01:53:14 +0000 | [diff] [blame] | 2086 | LValue EmitPredefinedLValue(const PredefinedExpr *E); |
Chris Lattner | 8394d79 | 2007-06-05 20:53:16 +0000 | [diff] [blame] | 2087 | LValue EmitUnaryOpLValue(const UnaryOperator *E); |
Richard Smith | 539e4a7 | 2013-02-23 02:53:19 +0000 | [diff] [blame] | 2088 | LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E, |
| 2089 | bool Accessed = false); |
Nate Begeman | ce4d7fc | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 2090 | LValue EmitExtVectorElementExpr(const ExtVectorElementExpr *E); |
Devang Patel | 3e11cce | 2007-10-23 02:10:49 +0000 | [diff] [blame] | 2091 | LValue EmitMemberExpr(const MemberExpr *E); |
Fariborz Jahanian | 531c16f | 2009-12-09 23:35:29 +0000 | [diff] [blame] | 2092 | LValue EmitObjCIsaExpr(const ObjCIsaExpr *E); |
Eli Friedman | 9fd8b68 | 2008-05-13 23:18:27 +0000 | [diff] [blame] | 2093 | LValue EmitCompoundLiteralLValue(const CompoundLiteralExpr *E); |
Richard Smith | bb653bd | 2012-05-14 21:57:21 +0000 | [diff] [blame] | 2094 | LValue EmitInitListLValue(const InitListExpr *E); |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 2095 | LValue EmitConditionalOperatorLValue(const AbstractConditionalOperator *E); |
Chris Lattner | 28bcf1a | 2009-03-18 18:28:57 +0000 | [diff] [blame] | 2096 | LValue EmitCastLValue(const CastExpr *E); |
Douglas Gregor | fe31481 | 2011-06-21 17:03:29 +0000 | [diff] [blame] | 2097 | LValue EmitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E); |
John McCall | 1bf5846 | 2011-02-16 08:02:54 +0000 | [diff] [blame] | 2098 | LValue EmitOpaqueValueLValue(const OpaqueValueExpr *e); |
Fariborz Jahanian | 91b2fa2 | 2014-08-19 17:17:40 +0000 | [diff] [blame^] | 2099 | |
| 2100 | llvm::Value *EmitExtVectorElementLValue(LValue V); |
Michael J. Spencer | f5a1fbc | 2010-10-19 06:39:39 +0000 | [diff] [blame] | 2101 | |
Nick Lewycky | 2d84e84 | 2013-10-02 02:29:49 +0000 | [diff] [blame] | 2102 | RValue EmitRValueForField(LValue LV, const FieldDecl *FD, SourceLocation Loc); |
Anton Korobeynikov | 4215ca7 | 2012-04-13 11:22:00 +0000 | [diff] [blame] | 2103 | |
John McCall | 7133505 | 2012-03-10 03:05:10 +0000 | [diff] [blame] | 2104 | class ConstantEmission { |
| 2105 | llvm::PointerIntPair<llvm::Constant*, 1, bool> ValueAndIsReference; |
| 2106 | ConstantEmission(llvm::Constant *C, bool isReference) |
| 2107 | : ValueAndIsReference(C, isReference) {} |
| 2108 | public: |
| 2109 | ConstantEmission() {} |
| 2110 | static ConstantEmission forReference(llvm::Constant *C) { |
| 2111 | return ConstantEmission(C, true); |
| 2112 | } |
| 2113 | static ConstantEmission forValue(llvm::Constant *C) { |
| 2114 | return ConstantEmission(C, false); |
| 2115 | } |
| 2116 | |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 2117 | LLVM_EXPLICIT operator bool() const { |
| 2118 | return ValueAndIsReference.getOpaqueValue() != nullptr; |
| 2119 | } |
John McCall | 7133505 | 2012-03-10 03:05:10 +0000 | [diff] [blame] | 2120 | |
| 2121 | bool isReference() const { return ValueAndIsReference.getInt(); } |
| 2122 | LValue getReferenceLValue(CodeGenFunction &CGF, Expr *refExpr) const { |
| 2123 | assert(isReference()); |
| 2124 | return CGF.MakeNaturalAlignAddrLValue(ValueAndIsReference.getPointer(), |
| 2125 | refExpr->getType()); |
| 2126 | } |
| 2127 | |
| 2128 | llvm::Constant *getValue() const { |
| 2129 | assert(!isReference()); |
| 2130 | return ValueAndIsReference.getPointer(); |
| 2131 | } |
| 2132 | }; |
| 2133 | |
John McCall | 113bee0 | 2012-03-10 09:33:50 +0000 | [diff] [blame] | 2134 | ConstantEmission tryEmitAsConstant(DeclRefExpr *refExpr); |
John McCall | 7133505 | 2012-03-10 03:05:10 +0000 | [diff] [blame] | 2135 | |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 2136 | RValue EmitPseudoObjectRValue(const PseudoObjectExpr *e, |
| 2137 | AggValueSlot slot = AggValueSlot::ignored()); |
| 2138 | LValue EmitPseudoObjectLValue(const PseudoObjectExpr *e); |
| 2139 | |
Daniel Dunbar | 722f424 | 2009-04-22 05:08:15 +0000 | [diff] [blame] | 2140 | llvm::Value *EmitIvarOffset(const ObjCInterfaceDecl *Interface, |
Daniel Dunbar | 1c64e5d | 2008-09-24 04:00:38 +0000 | [diff] [blame] | 2141 | const ObjCIvarDecl *Ivar); |
Eli Friedman | 7f1ff60 | 2012-04-16 03:54:45 +0000 | [diff] [blame] | 2142 | LValue EmitLValueForField(LValue Base, const FieldDecl* Field); |
John McCall | dec348f7 | 2013-05-03 07:33:41 +0000 | [diff] [blame] | 2143 | LValue EmitLValueForLambdaField(const FieldDecl *Field); |
Michael J. Spencer | f5a1fbc | 2010-10-19 06:39:39 +0000 | [diff] [blame] | 2144 | |
Anders Carlsson | db78f0a | 2010-01-29 05:24:29 +0000 | [diff] [blame] | 2145 | /// EmitLValueForFieldInitialization - Like EmitLValueForField, except that |
| 2146 | /// if the Field is a reference, this will return the address of the reference |
| 2147 | /// and not the address of the value stored in the reference. |
Eli Friedman | 7f1ff60 | 2012-04-16 03:54:45 +0000 | [diff] [blame] | 2148 | LValue EmitLValueForFieldInitialization(LValue Base, |
| 2149 | const FieldDecl* Field); |
Michael J. Spencer | f5a1fbc | 2010-10-19 06:39:39 +0000 | [diff] [blame] | 2150 | |
Fariborz Jahanian | c88a70d | 2009-02-03 00:09:52 +0000 | [diff] [blame] | 2151 | LValue EmitLValueForIvar(QualType ObjectTy, |
| 2152 | llvm::Value* Base, const ObjCIvarDecl *Ivar, |
Daniel Dunbar | 1c64e5d | 2008-09-24 04:00:38 +0000 | [diff] [blame] | 2153 | unsigned CVRQualifiers); |
| 2154 | |
Anders Carlsson | 3be22e2 | 2009-05-30 23:23:33 +0000 | [diff] [blame] | 2155 | LValue EmitCXXConstructLValue(const CXXConstructExpr *E); |
Anders Carlsson | fd2af0c | 2009-05-30 23:30:54 +0000 | [diff] [blame] | 2156 | LValue EmitCXXBindTemporaryLValue(const CXXBindTemporaryExpr *E); |
Eli Friedman | 5bc1712 | 2012-02-08 05:34:55 +0000 | [diff] [blame] | 2157 | LValue EmitLambdaLValue(const LambdaExpr *E); |
Mike Stump | c9b231c | 2009-11-15 08:09:41 +0000 | [diff] [blame] | 2158 | LValue EmitCXXTypeidLValue(const CXXTypeidExpr *E); |
Nico Weber | cf4ff586 | 2012-10-11 10:13:44 +0000 | [diff] [blame] | 2159 | LValue EmitCXXUuidofLValue(const CXXUuidofExpr *E); |
Michael J. Spencer | f5a1fbc | 2010-10-19 06:39:39 +0000 | [diff] [blame] | 2160 | |
Daniel Dunbar | c8317a4 | 2008-08-23 10:51:21 +0000 | [diff] [blame] | 2161 | LValue EmitObjCMessageExprLValue(const ObjCMessageExpr *E); |
Chris Lattner | 4bd5596 | 2008-03-30 23:03:07 +0000 | [diff] [blame] | 2162 | LValue EmitObjCIvarRefLValue(const ObjCIvarRefExpr *E); |
Chris Lattner | a4185c5 | 2009-04-25 19:35:26 +0000 | [diff] [blame] | 2163 | LValue EmitStmtExprLValue(const StmtExpr *E); |
Fariborz Jahanian | ffba662 | 2009-10-22 22:57:31 +0000 | [diff] [blame] | 2164 | LValue EmitPointerToDataMemberBinaryExpr(const BinaryOperator *E); |
Fariborz Jahanian | 9240f3d | 2010-06-17 19:56:20 +0000 | [diff] [blame] | 2165 | LValue EmitObjCSelectorLValue(const ObjCSelectorExpr *E); |
Yunzhong Gao | 0ebf1bb | 2013-08-30 08:53:09 +0000 | [diff] [blame] | 2166 | void EmitDeclRefExprDbgValue(const DeclRefExpr *E, llvm::Constant *Init); |
John McCall | c07a0c7 | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 2167 | |
Chris Lattner | d7f5886 | 2007-06-02 05:24:33 +0000 | [diff] [blame] | 2168 | //===--------------------------------------------------------------------===// |
Chris Lattner | 6278e6a | 2007-08-11 00:04:45 +0000 | [diff] [blame] | 2169 | // Scalar Expression Emission |
Chris Lattner | 208ae96 | 2007-05-30 17:57:17 +0000 | [diff] [blame] | 2170 | //===--------------------------------------------------------------------===// |
| 2171 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 2172 | /// EmitCall - Generate a call of the given function, expecting the given |
| 2173 | /// result type, and using the given argument list which specifies both the |
| 2174 | /// LLVM arguments and the types they were derived from. |
Daniel Dunbar | cdbb5e3 | 2009-02-20 18:06:48 +0000 | [diff] [blame] | 2175 | /// |
Mike Stump | e5311b0 | 2009-11-30 20:08:49 +0000 | [diff] [blame] | 2176 | /// \param TargetDecl - If given, the decl of the function in a direct call; |
| 2177 | /// used to set attributes on the call (noreturn, etc.). |
Daniel Dunbar | d931a87 | 2009-02-02 22:03:45 +0000 | [diff] [blame] | 2178 | RValue EmitCall(const CGFunctionInfo &FnInfo, |
| 2179 | llvm::Value *Callee, |
Anders Carlsson | 61a401c | 2009-12-24 19:25:24 +0000 | [diff] [blame] | 2180 | ReturnValueSlot ReturnValue, |
Daniel Dunbar | cdbb5e3 | 2009-02-20 18:06:48 +0000 | [diff] [blame] | 2181 | const CallArgList &Args, |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 2182 | const Decl *TargetDecl = nullptr, |
| 2183 | llvm::Instruction **callOrInvoke = nullptr); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2184 | |
Anders Carlsson | 0435ed5 | 2009-12-24 19:08:58 +0000 | [diff] [blame] | 2185 | RValue EmitCall(QualType FnType, llvm::Value *Callee, |
Peter Collingbourne | b453cd6 | 2013-10-20 21:29:19 +0000 | [diff] [blame] | 2186 | SourceLocation CallLoc, |
Anders Carlsson | 1749083 | 2009-12-24 20:40:36 +0000 | [diff] [blame] | 2187 | ReturnValueSlot ReturnValue, |
Anders Carlsson | 3a9463b | 2009-05-27 01:22:39 +0000 | [diff] [blame] | 2188 | CallExpr::const_arg_iterator ArgBeg, |
| 2189 | CallExpr::const_arg_iterator ArgEnd, |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 2190 | const Decl *TargetDecl = nullptr); |
Michael J. Spencer | f5a1fbc | 2010-10-19 06:39:39 +0000 | [diff] [blame] | 2191 | RValue EmitCallExpr(const CallExpr *E, |
Anders Carlsson | 1749083 | 2009-12-24 20:40:36 +0000 | [diff] [blame] | 2192 | ReturnValueSlot ReturnValue = ReturnValueSlot()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2193 | |
John McCall | 882987f | 2013-02-28 19:01:20 +0000 | [diff] [blame] | 2194 | llvm::CallInst *EmitRuntimeCall(llvm::Value *callee, |
| 2195 | const Twine &name = ""); |
| 2196 | llvm::CallInst *EmitRuntimeCall(llvm::Value *callee, |
| 2197 | ArrayRef<llvm::Value*> args, |
| 2198 | const Twine &name = ""); |
| 2199 | llvm::CallInst *EmitNounwindRuntimeCall(llvm::Value *callee, |
| 2200 | const Twine &name = ""); |
| 2201 | llvm::CallInst *EmitNounwindRuntimeCall(llvm::Value *callee, |
| 2202 | ArrayRef<llvm::Value*> args, |
| 2203 | const Twine &name = ""); |
| 2204 | |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 2205 | llvm::CallSite EmitCallOrInvoke(llvm::Value *Callee, |
Chris Lattner | 54b1677 | 2011-07-23 17:14:25 +0000 | [diff] [blame] | 2206 | ArrayRef<llvm::Value *> Args, |
Chris Lattner | 62ff6e8 | 2011-07-20 07:06:53 +0000 | [diff] [blame] | 2207 | const Twine &Name = ""); |
Jay Foad | 5bd375a | 2011-07-15 08:37:34 +0000 | [diff] [blame] | 2208 | llvm::CallSite EmitCallOrInvoke(llvm::Value *Callee, |
Chris Lattner | 62ff6e8 | 2011-07-20 07:06:53 +0000 | [diff] [blame] | 2209 | const Twine &Name = ""); |
John McCall | 882987f | 2013-02-28 19:01:20 +0000 | [diff] [blame] | 2210 | llvm::CallSite EmitRuntimeCallOrInvoke(llvm::Value *callee, |
| 2211 | ArrayRef<llvm::Value*> args, |
| 2212 | const Twine &name = ""); |
| 2213 | llvm::CallSite EmitRuntimeCallOrInvoke(llvm::Value *callee, |
| 2214 | const Twine &name = ""); |
| 2215 | void EmitNoreturnRuntimeCallOrInvoke(llvm::Value *callee, |
| 2216 | ArrayRef<llvm::Value*> args); |
John McCall | bd30929 | 2010-07-06 01:34:17 +0000 | [diff] [blame] | 2217 | |
Fariborz Jahanian | 47609b0 | 2011-01-20 17:19:02 +0000 | [diff] [blame] | 2218 | llvm::Value *BuildAppleKextVirtualCall(const CXXMethodDecl *MD, |
| 2219 | NestedNameSpecifier *Qual, |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 2220 | llvm::Type *Ty); |
Fariborz Jahanian | 265c325 | 2011-02-01 23:22:34 +0000 | [diff] [blame] | 2221 | |
| 2222 | llvm::Value *BuildAppleKextVirtualDestructorCall(const CXXDestructorDecl *DD, |
| 2223 | CXXDtorType Type, |
Fariborz Jahanian | 7f6f81b | 2011-02-03 19:27:17 +0000 | [diff] [blame] | 2224 | const CXXRecordDecl *RD); |
Anders Carlsson | e828c36 | 2009-11-13 04:45:41 +0000 | [diff] [blame] | 2225 | |
Anders Carlsson | bd7d11f | 2009-05-11 23:37:08 +0000 | [diff] [blame] | 2226 | RValue EmitCXXMemberCall(const CXXMethodDecl *MD, |
Richard Smith | e30752c | 2012-10-09 19:52:38 +0000 | [diff] [blame] | 2227 | SourceLocation CallLoc, |
Anders Carlsson | bd7d11f | 2009-05-11 23:37:08 +0000 | [diff] [blame] | 2228 | llvm::Value *Callee, |
Anders Carlsson | bfb3671 | 2009-12-24 21:13:40 +0000 | [diff] [blame] | 2229 | ReturnValueSlot ReturnValue, |
Anders Carlsson | bd7d11f | 2009-05-11 23:37:08 +0000 | [diff] [blame] | 2230 | llvm::Value *This, |
Timur Iskhodzhanov | ee6bc53 | 2013-02-13 08:37:51 +0000 | [diff] [blame] | 2231 | llvm::Value *ImplicitParam, |
| 2232 | QualType ImplicitParamTy, |
Anders Carlsson | bd7d11f | 2009-05-11 23:37:08 +0000 | [diff] [blame] | 2233 | CallExpr::const_arg_iterator ArgBeg, |
| 2234 | CallExpr::const_arg_iterator ArgEnd); |
Anders Carlsson | bfb3671 | 2009-12-24 21:13:40 +0000 | [diff] [blame] | 2235 | RValue EmitCXXMemberCallExpr(const CXXMemberCallExpr *E, |
| 2236 | ReturnValueSlot ReturnValue); |
| 2237 | RValue EmitCXXMemberPointerCallExpr(const CXXMemberCallExpr *E, |
| 2238 | ReturnValueSlot ReturnValue); |
Ted Kremenek | 08e1711 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 2239 | |
Anders Carlsson | c36783e | 2011-05-08 20:32:23 +0000 | [diff] [blame] | 2240 | llvm::Value *EmitCXXOperatorMemberCallee(const CXXOperatorCallExpr *E, |
| 2241 | const CXXMethodDecl *MD, |
| 2242 | llvm::Value *This); |
Anders Carlsson | 4034a95 | 2009-05-27 04:18:27 +0000 | [diff] [blame] | 2243 | RValue EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E, |
Anders Carlsson | bfb3671 | 2009-12-24 21:13:40 +0000 | [diff] [blame] | 2244 | const CXXMethodDecl *MD, |
| 2245 | ReturnValueSlot ReturnValue); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2246 | |
Peter Collingbourne | fe88342 | 2011-10-06 18:29:37 +0000 | [diff] [blame] | 2247 | RValue EmitCUDAKernelCallExpr(const CUDAKernelCallExpr *E, |
| 2248 | ReturnValueSlot ReturnValue); |
| 2249 | |
Michael J. Spencer | f5a1fbc | 2010-10-19 06:39:39 +0000 | [diff] [blame] | 2250 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2251 | RValue EmitBuiltinExpr(const FunctionDecl *FD, |
Daniel Dunbar | 8eb018a | 2009-02-16 22:43:43 +0000 | [diff] [blame] | 2252 | unsigned BuiltinID, const CallExpr *E); |
Chris Lattner | 8394d79 | 2007-06-05 20:53:16 +0000 | [diff] [blame] | 2253 | |
Anders Carlsson | bfb3671 | 2009-12-24 21:13:40 +0000 | [diff] [blame] | 2254 | RValue EmitBlockCallExpr(const CallExpr *E, ReturnValueSlot ReturnValue); |
Mike Stump | c6ea7c1 | 2009-02-17 17:00:02 +0000 | [diff] [blame] | 2255 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 2256 | /// EmitTargetBuiltinExpr - Emit the given builtin call. Returns 0 if the call |
| 2257 | /// is unhandled by the current target. |
Daniel Dunbar | eca513d | 2008-10-10 00:24:54 +0000 | [diff] [blame] | 2258 | llvm::Value *EmitTargetBuiltinExpr(unsigned BuiltinID, const CallExpr *E); |
| 2259 | |
Kevin Qin | 1718af6 | 2013-11-14 02:45:18 +0000 | [diff] [blame] | 2260 | llvm::Value *EmitAArch64CompareBuiltinExpr(llvm::Value *Op, llvm::Type *Ty, |
| 2261 | const llvm::CmpInst::Predicate Fp, |
| 2262 | const llvm::CmpInst::Predicate Ip, |
| 2263 | const llvm::Twine &Name = ""); |
Chris Lattner | 5cc15e0 | 2010-03-03 19:03:45 +0000 | [diff] [blame] | 2264 | llvm::Value *EmitARMBuiltinExpr(unsigned BuiltinID, const CallExpr *E); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2265 | |
| 2266 | llvm::Value *EmitCommonNeonBuiltinExpr(unsigned BuiltinID, |
| 2267 | unsigned LLVMIntrinsic, |
| 2268 | unsigned AltLLVMIntrinsic, |
| 2269 | const char *NameHint, |
| 2270 | unsigned Modifier, |
| 2271 | const CallExpr *E, |
Tim Northover | 027b4ee | 2014-01-31 10:46:45 +0000 | [diff] [blame] | 2272 | SmallVectorImpl<llvm::Value *> &Ops, |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 2273 | llvm::Value *Align = nullptr); |
Tim Northover | 8fe03d6 | 2014-02-21 11:57:24 +0000 | [diff] [blame] | 2274 | llvm::Function *LookupNeonLLVMIntrinsic(unsigned IntrinsicID, |
| 2275 | unsigned Modifier, llvm::Type *ArgTy, |
| 2276 | const CallExpr *E); |
Michael J. Spencer | f5a1fbc | 2010-10-19 06:39:39 +0000 | [diff] [blame] | 2277 | llvm::Value *EmitNeonCall(llvm::Function *F, |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 2278 | SmallVectorImpl<llvm::Value*> &O, |
Bob Wilson | 482afae | 2010-12-08 22:37:56 +0000 | [diff] [blame] | 2279 | const char *name, |
Nate Begeman | 91e1fea | 2010-06-14 05:21:25 +0000 | [diff] [blame] | 2280 | unsigned shift = 0, bool rightshift = false); |
Bob Wilson | 210f6dd | 2010-12-07 22:40:02 +0000 | [diff] [blame] | 2281 | llvm::Value *EmitNeonSplat(llvm::Value *V, llvm::Constant *Idx); |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 2282 | llvm::Value *EmitNeonShiftVector(llvm::Value *V, llvm::Type *Ty, |
Nate Begeman | 91e1fea | 2010-06-14 05:21:25 +0000 | [diff] [blame] | 2283 | bool negateForRightShift); |
Amaury de la Vieuville | 21bf6ed | 2013-10-04 13:13:15 +0000 | [diff] [blame] | 2284 | llvm::Value *EmitNeonRShiftImm(llvm::Value *Vec, llvm::Value *Amt, |
| 2285 | llvm::Type *Ty, bool usgn, const char *name); |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 2286 | // Helper functions for EmitAArch64BuiltinExpr. |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2287 | llvm::Value *vectorWrapScalar8(llvm::Value *Op); |
| 2288 | llvm::Value *vectorWrapScalar16(llvm::Value *Op); |
| 2289 | llvm::Value *emitVectorWrappedScalar8Intrinsic( |
| 2290 | unsigned Int, SmallVectorImpl<llvm::Value *> &Ops, const char *Name); |
| 2291 | llvm::Value *emitVectorWrappedScalar16Intrinsic( |
| 2292 | unsigned Int, SmallVectorImpl<llvm::Value *> &Ops, const char *Name); |
Tim Northover | 573cbee | 2014-05-24 12:52:07 +0000 | [diff] [blame] | 2293 | llvm::Value *EmitAArch64BuiltinExpr(unsigned BuiltinID, const CallExpr *E); |
Tim Northover | a2ee433 | 2014-03-29 15:09:45 +0000 | [diff] [blame] | 2294 | llvm::Value *EmitNeon64Call(llvm::Function *F, |
| 2295 | llvm::SmallVectorImpl<llvm::Value *> &O, |
| 2296 | const char *name); |
Michael J. Spencer | f5a1fbc | 2010-10-19 06:39:39 +0000 | [diff] [blame] | 2297 | |
Bill Wendling | f1a3fca | 2012-02-22 09:30:11 +0000 | [diff] [blame] | 2298 | llvm::Value *BuildVector(ArrayRef<llvm::Value*> Ops); |
Anders Carlsson | 895af08 | 2007-12-09 23:17:02 +0000 | [diff] [blame] | 2299 | llvm::Value *EmitX86BuiltinExpr(unsigned BuiltinID, const CallExpr *E); |
| 2300 | llvm::Value *EmitPPCBuiltinExpr(unsigned BuiltinID, const CallExpr *E); |
Matt Arsenault | 56f008d | 2014-06-24 20:45:01 +0000 | [diff] [blame] | 2301 | llvm::Value *EmitR600BuiltinExpr(unsigned BuiltinID, const CallExpr *E); |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 2302 | |
Daniel Dunbar | 66912a1 | 2008-08-20 00:28:19 +0000 | [diff] [blame] | 2303 | llvm::Value *EmitObjCProtocolExpr(const ObjCProtocolExpr *E); |
Chris Lattner | 2da04b3 | 2007-08-24 05:35:26 +0000 | [diff] [blame] | 2304 | llvm::Value *EmitObjCStringLiteral(const ObjCStringLiteral *E); |
Patrick Beard | 0caa394 | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 2305 | llvm::Value *EmitObjCBoxedExpr(const ObjCBoxedExpr *E); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2306 | llvm::Value *EmitObjCArrayLiteral(const ObjCArrayLiteral *E); |
| 2307 | llvm::Value *EmitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E); |
| 2308 | llvm::Value *EmitObjCCollectionLiteral(const Expr *E, |
Fariborz Jahanian | 413297c | 2014-08-06 18:13:46 +0000 | [diff] [blame] | 2309 | const ObjCMethodDecl *MethodWithObjects, |
| 2310 | const ObjCMethodDecl *AllocMethod); |
Chris Lattner | b1d329d | 2008-06-24 17:04:18 +0000 | [diff] [blame] | 2311 | llvm::Value *EmitObjCSelectorExpr(const ObjCSelectorExpr *E); |
John McCall | 78a1511 | 2010-05-22 01:48:05 +0000 | [diff] [blame] | 2312 | RValue EmitObjCMessageExpr(const ObjCMessageExpr *E, |
| 2313 | ReturnValueSlot Return = ReturnValueSlot()); |
Chris Lattner | b1d329d | 2008-06-24 17:04:18 +0000 | [diff] [blame] | 2314 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 2315 | /// Retrieves the default cleanup kind for an ARC cleanup. |
| 2316 | /// Except under -fobjc-arc-eh, ARC cleanups are normal-only. |
| 2317 | CleanupKind getARCCleanupKind() { |
| 2318 | return CGM.getCodeGenOpts().ObjCAutoRefCountExceptions |
| 2319 | ? NormalAndEHCleanup : NormalCleanup; |
| 2320 | } |
| 2321 | |
| 2322 | // ARC primitives. |
| 2323 | void EmitARCInitWeak(llvm::Value *value, llvm::Value *addr); |
| 2324 | void EmitARCDestroyWeak(llvm::Value *addr); |
| 2325 | llvm::Value *EmitARCLoadWeak(llvm::Value *addr); |
| 2326 | llvm::Value *EmitARCLoadWeakRetained(llvm::Value *addr); |
| 2327 | llvm::Value *EmitARCStoreWeak(llvm::Value *value, llvm::Value *addr, |
| 2328 | bool ignored); |
| 2329 | void EmitARCCopyWeak(llvm::Value *dst, llvm::Value *src); |
| 2330 | void EmitARCMoveWeak(llvm::Value *dst, llvm::Value *src); |
| 2331 | llvm::Value *EmitARCRetainAutorelease(QualType type, llvm::Value *value); |
| 2332 | llvm::Value *EmitARCRetainAutoreleaseNonBlock(llvm::Value *value); |
John McCall | 55e1fbc | 2011-06-25 02:11:03 +0000 | [diff] [blame] | 2333 | llvm::Value *EmitARCStoreStrong(LValue lvalue, llvm::Value *value, |
John McCall | cdda29c | 2013-03-13 03:10:54 +0000 | [diff] [blame] | 2334 | bool resultIgnored); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 2335 | llvm::Value *EmitARCStoreStrongCall(llvm::Value *addr, llvm::Value *value, |
John McCall | cdda29c | 2013-03-13 03:10:54 +0000 | [diff] [blame] | 2336 | bool resultIgnored); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 2337 | llvm::Value *EmitARCRetain(QualType type, llvm::Value *value); |
| 2338 | llvm::Value *EmitARCRetainNonBlock(llvm::Value *value); |
John McCall | ff61303 | 2011-10-04 06:23:45 +0000 | [diff] [blame] | 2339 | llvm::Value *EmitARCRetainBlock(llvm::Value *value, bool mandatory); |
John McCall | cdda29c | 2013-03-13 03:10:54 +0000 | [diff] [blame] | 2340 | void EmitARCDestroyStrong(llvm::Value *addr, ARCPreciseLifetime_t precise); |
| 2341 | void EmitARCRelease(llvm::Value *value, ARCPreciseLifetime_t precise); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 2342 | llvm::Value *EmitARCAutorelease(llvm::Value *value); |
| 2343 | llvm::Value *EmitARCAutoreleaseReturnValue(llvm::Value *value); |
| 2344 | llvm::Value *EmitARCRetainAutoreleaseReturnValue(llvm::Value *value); |
| 2345 | llvm::Value *EmitARCRetainAutoreleasedReturnValue(llvm::Value *value); |
| 2346 | |
| 2347 | std::pair<LValue,llvm::Value*> |
| 2348 | EmitARCStoreAutoreleasing(const BinaryOperator *e); |
| 2349 | std::pair<LValue,llvm::Value*> |
| 2350 | EmitARCStoreStrong(const BinaryOperator *e, bool ignored); |
| 2351 | |
John McCall | 248512a | 2011-10-01 10:32:24 +0000 | [diff] [blame] | 2352 | llvm::Value *EmitObjCThrowOperand(const Expr *expr); |
| 2353 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 2354 | llvm::Value *EmitObjCProduceObject(QualType T, llvm::Value *Ptr); |
| 2355 | llvm::Value *EmitObjCConsumeObject(QualType T, llvm::Value *Ptr); |
| 2356 | llvm::Value *EmitObjCExtendObjectLifetime(QualType T, llvm::Value *Ptr); |
| 2357 | |
John McCall | ff61303 | 2011-10-04 06:23:45 +0000 | [diff] [blame] | 2358 | llvm::Value *EmitARCExtendBlockObject(const Expr *expr); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 2359 | llvm::Value *EmitARCRetainScalarExpr(const Expr *expr); |
| 2360 | llvm::Value *EmitARCRetainAutoreleaseScalarExpr(const Expr *expr); |
| 2361 | |
Craig Topper | 00bbdcf | 2014-06-28 23:22:23 +0000 | [diff] [blame] | 2362 | void EmitARCIntrinsicUse(ArrayRef<llvm::Value*> values); |
John McCall | eff1884 | 2013-03-23 02:35:54 +0000 | [diff] [blame] | 2363 | |
John McCall | 82fe67b | 2011-07-09 01:37:26 +0000 | [diff] [blame] | 2364 | static Destroyer destroyARCStrongImprecise; |
| 2365 | static Destroyer destroyARCStrongPrecise; |
| 2366 | static Destroyer destroyARCWeak; |
| 2367 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 2368 | void EmitObjCAutoreleasePoolPop(llvm::Value *Ptr); |
| 2369 | llvm::Value *EmitObjCAutoreleasePoolPush(); |
| 2370 | llvm::Value *EmitObjCMRRAutoreleasePoolPush(); |
| 2371 | void EmitObjCAutoreleasePoolCleanup(llvm::Value *Ptr); |
| 2372 | void EmitObjCMRRAutoreleasePoolPop(llvm::Value *Ptr); |
| 2373 | |
Richard Smith | a1c9d4d | 2013-06-12 23:38:09 +0000 | [diff] [blame] | 2374 | /// \brief Emits a reference binding to the passed in expression. |
| 2375 | RValue EmitReferenceBindingToExpr(const Expr *E); |
Anders Carlsson | ab0ddb5 | 2010-01-31 18:34:51 +0000 | [diff] [blame] | 2376 | |
Chris Lattner | 6278e6a | 2007-08-11 00:04:45 +0000 | [diff] [blame] | 2377 | //===--------------------------------------------------------------------===// |
Chris Lattner | bda69f8 | 2007-08-26 23:13:56 +0000 | [diff] [blame] | 2378 | // Expression Emission |
Chris Lattner | 6278e6a | 2007-08-11 00:04:45 +0000 | [diff] [blame] | 2379 | //===--------------------------------------------------------------------===// |
Chris Lattner | bda69f8 | 2007-08-26 23:13:56 +0000 | [diff] [blame] | 2380 | |
| 2381 | // Expressions are broken into three classes: scalar, complex, aggregate. |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 2382 | |
| 2383 | /// EmitScalarExpr - Emit the computation of the specified expression of LLVM |
| 2384 | /// scalar type, returning the result. |
Anders Carlsson | 5b106a7 | 2009-08-16 07:36:22 +0000 | [diff] [blame] | 2385 | llvm::Value *EmitScalarExpr(const Expr *E , bool IgnoreResultAssign = false); |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 2386 | |
Chris Lattner | 3474c20 | 2007-08-26 06:48:56 +0000 | [diff] [blame] | 2387 | /// EmitScalarConversion - Emit a conversion from the specified type to the |
| 2388 | /// specified destination type, both of which are LLVM scalar types. |
| 2389 | llvm::Value *EmitScalarConversion(llvm::Value *Src, QualType SrcTy, |
| 2390 | QualType DstTy); |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 2391 | |
Chris Lattner | 42e6b81 | 2007-08-26 16:34:22 +0000 | [diff] [blame] | 2392 | /// EmitComplexToScalarConversion - Emit a conversion from the specified |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 2393 | /// complex type to the specified destination type, where the destination type |
| 2394 | /// is an LLVM scalar type. |
Chris Lattner | 42e6b81 | 2007-08-26 16:34:22 +0000 | [diff] [blame] | 2395 | llvm::Value *EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy, |
| 2396 | QualType DstTy); |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 2397 | |
| 2398 | |
John McCall | 7a626f6 | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 2399 | /// EmitAggExpr - Emit the computation of the specified expression |
| 2400 | /// of aggregate type. The result is computed into the given slot, |
| 2401 | /// which may be null to indicate that the value is not needed. |
John McCall | 4e8ca4f | 2012-07-02 23:58:38 +0000 | [diff] [blame] | 2402 | void EmitAggExpr(const Expr *E, AggValueSlot AS); |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 2403 | |
Daniel Dunbar | d0bc7b9 | 2010-02-05 19:38:31 +0000 | [diff] [blame] | 2404 | /// EmitAggExprToLValue - Emit the computation of the specified expression of |
| 2405 | /// aggregate type into a temporary LValue. |
| 2406 | LValue EmitAggExprToLValue(const Expr *E); |
| 2407 | |
Fariborz Jahanian | 5f21d2f | 2009-07-08 01:18:33 +0000 | [diff] [blame] | 2408 | /// EmitGCMemmoveCollectable - Emit special API for structs with object |
| 2409 | /// pointers. |
| 2410 | void EmitGCMemmoveCollectable(llvm::Value *DestPtr, llvm::Value *SrcPtr, |
Fariborz Jahanian | 879d726 | 2009-08-31 19:33:16 +0000 | [diff] [blame] | 2411 | QualType Ty); |
Fariborz Jahanian | 5f21d2f | 2009-07-08 01:18:33 +0000 | [diff] [blame] | 2412 | |
John McCall | 1bd2556 | 2011-06-24 23:21:27 +0000 | [diff] [blame] | 2413 | /// EmitExtendGCLifetime - Given a pointer to an Objective-C object, |
| 2414 | /// make sure it survives garbage collection until this point. |
| 2415 | void EmitExtendGCLifetime(llvm::Value *object); |
| 2416 | |
Chris Lattner | cbfc73b | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 2417 | /// EmitComplexExpr - Emit the computation of the specified expression of |
Chris Lattner | 08b15df | 2007-08-23 23:43:33 +0000 | [diff] [blame] | 2418 | /// complex type, returning the result. |
John McCall | 07bb196 | 2010-11-16 10:08:07 +0000 | [diff] [blame] | 2419 | ComplexPairTy EmitComplexExpr(const Expr *E, |
| 2420 | bool IgnoreReal = false, |
| 2421 | bool IgnoreImag = false); |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 2422 | |
John McCall | 47fb950 | 2013-03-07 21:37:08 +0000 | [diff] [blame] | 2423 | /// EmitComplexExprIntoLValue - Emit the given expression of complex |
| 2424 | /// type and place its result into the specified l-value. |
| 2425 | void EmitComplexExprIntoLValue(const Expr *E, LValue dest, bool isInit); |
Daniel Dunbar | 4b8c6db | 2008-08-30 05:35:15 +0000 | [diff] [blame] | 2426 | |
John McCall | 47fb950 | 2013-03-07 21:37:08 +0000 | [diff] [blame] | 2427 | /// EmitStoreOfComplex - Store a complex number into the specified l-value. |
| 2428 | void EmitStoreOfComplex(ComplexPairTy V, LValue dest, bool isInit); |
| 2429 | |
| 2430 | /// EmitLoadOfComplex - Load a complex number from the specified l-value. |
Nick Lewycky | 2d84e84 | 2013-10-02 02:29:49 +0000 | [diff] [blame] | 2431 | ComplexPairTy EmitLoadOfComplex(LValue src, SourceLocation loc); |
Chris Lattner | b781dc79 | 2008-05-08 05:58:21 +0000 | [diff] [blame] | 2432 | |
John McCall | 1c9c3fd | 2010-10-15 04:57:14 +0000 | [diff] [blame] | 2433 | /// CreateStaticVarDecl - Create a zero-initialized LLVM global for |
| 2434 | /// a static local variable. |
Eli Bendersky | cb39943 | 2014-03-24 22:05:38 +0000 | [diff] [blame] | 2435 | llvm::Constant *CreateStaticVarDecl(const VarDecl &D, |
Eli Bendersky | cb39943 | 2014-03-24 22:05:38 +0000 | [diff] [blame] | 2436 | llvm::GlobalValue::LinkageTypes Linkage); |
Michael J. Spencer | f5a1fbc | 2010-10-19 06:39:39 +0000 | [diff] [blame] | 2437 | |
Chandler Carruth | 8453795 | 2012-03-30 19:44:53 +0000 | [diff] [blame] | 2438 | /// AddInitializerToStaticVarDecl - Add the initializer for 'D' to the |
| 2439 | /// global variable that has already been created for it. If the initializer |
| 2440 | /// has a different type than GV does, this may free GV and return a different |
| 2441 | /// one. Otherwise it just returns GV. |
| 2442 | llvm::GlobalVariable * |
| 2443 | AddInitializerToStaticVarDecl(const VarDecl &D, |
| 2444 | llvm::GlobalVariable *GV); |
Michael J. Spencer | f5a1fbc | 2010-10-19 06:39:39 +0000 | [diff] [blame] | 2445 | |
Daniel Dunbar | 22a87f9 | 2009-02-25 19:24:29 +0000 | [diff] [blame] | 2446 | |
Anders Carlsson | f40886a | 2009-08-08 21:45:14 +0000 | [diff] [blame] | 2447 | /// EmitCXXGlobalVarDeclInit - Create the initializer for a C++ |
| 2448 | /// variable with global storage. |
Richard Smith | 6331c40 | 2012-02-13 22:16:19 +0000 | [diff] [blame] | 2449 | void EmitCXXGlobalVarDeclInit(const VarDecl &D, llvm::Constant *DeclPtr, |
| 2450 | bool PerformInit); |
Anders Carlsson | f40886a | 2009-08-08 21:45:14 +0000 | [diff] [blame] | 2451 | |
John McCall | c84ed6a | 2012-05-01 06:13:13 +0000 | [diff] [blame] | 2452 | /// Call atexit() with a function that passes the given argument to |
| 2453 | /// the given function. |
David Blaikie | ebe87e1 | 2013-08-27 23:57:18 +0000 | [diff] [blame] | 2454 | void registerGlobalDtorWithAtExit(const VarDecl &D, llvm::Constant *fn, |
| 2455 | llvm::Constant *addr); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2456 | |
John McCall | cdf7ef5 | 2010-11-06 09:44:32 +0000 | [diff] [blame] | 2457 | /// Emit code in this function to perform a guarded variable |
| 2458 | /// initialization. Guarded initializations are used when it's not |
| 2459 | /// possible to prove that an initialization will be done exactly |
| 2460 | /// once, e.g. with a static local variable or a static data member |
| 2461 | /// of a class template. |
Chandler Carruth | 8453795 | 2012-03-30 19:44:53 +0000 | [diff] [blame] | 2462 | void EmitCXXGuardedInit(const VarDecl &D, llvm::GlobalVariable *DeclPtr, |
Richard Smith | 6331c40 | 2012-02-13 22:16:19 +0000 | [diff] [blame] | 2463 | bool PerformInit); |
John McCall | 68ff037 | 2010-09-08 01:44:27 +0000 | [diff] [blame] | 2464 | |
Daniel Dunbar | fe06df4 | 2010-03-20 04:15:41 +0000 | [diff] [blame] | 2465 | /// GenerateCXXGlobalInitFunc - Generates code for initializing global |
| 2466 | /// variables. |
| 2467 | void GenerateCXXGlobalInitFunc(llvm::Function *Fn, |
Benjamin Kramer | 139cfc2 | 2013-04-26 21:32:52 +0000 | [diff] [blame] | 2468 | ArrayRef<llvm::Constant *> Decls, |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 2469 | llvm::GlobalVariable *Guard = nullptr); |
Daniel Dunbar | fe06df4 | 2010-03-20 04:15:41 +0000 | [diff] [blame] | 2470 | |
John McCall | ee08c53 | 2012-04-06 18:21:03 +0000 | [diff] [blame] | 2471 | /// GenerateCXXGlobalDtorsFunc - Generates code for destroying global |
Daniel Dunbar | fe06df4 | 2010-03-20 04:15:41 +0000 | [diff] [blame] | 2472 | /// variables. |
John McCall | ee08c53 | 2012-04-06 18:21:03 +0000 | [diff] [blame] | 2473 | void GenerateCXXGlobalDtorsFunc(llvm::Function *Fn, |
| 2474 | const std::vector<std::pair<llvm::WeakVH, |
| 2475 | llvm::Constant*> > &DtorsAndObjects); |
Daniel Dunbar | fe06df4 | 2010-03-20 04:15:41 +0000 | [diff] [blame] | 2476 | |
John McCall | a738c25 | 2011-03-09 04:27:21 +0000 | [diff] [blame] | 2477 | void GenerateCXXGlobalVarDeclInitFunc(llvm::Function *Fn, |
| 2478 | const VarDecl *D, |
Richard Smith | 6331c40 | 2012-02-13 22:16:19 +0000 | [diff] [blame] | 2479 | llvm::GlobalVariable *Addr, |
| 2480 | bool PerformInit); |
Daniel Dunbar | fe06df4 | 2010-03-20 04:15:41 +0000 | [diff] [blame] | 2481 | |
John McCall | 7a626f6 | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 2482 | void EmitCXXConstructExpr(const CXXConstructExpr *E, AggValueSlot Dest); |
Fariborz Jahanian | e988bda | 2010-11-13 21:53:34 +0000 | [diff] [blame] | 2483 | |
| 2484 | void EmitSynthesizedCXXCopyCtor(llvm::Value *Dest, llvm::Value *Src, |
Fariborz Jahanian | 5019809 | 2010-12-02 17:02:11 +0000 | [diff] [blame] | 2485 | const Expr *Exp); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2486 | |
John McCall | 08ef466 | 2011-11-10 08:15:53 +0000 | [diff] [blame] | 2487 | void enterFullExpression(const ExprWithCleanups *E) { |
| 2488 | if (E->getNumObjects() == 0) return; |
| 2489 | enterNonTrivialFullExpression(E); |
| 2490 | } |
| 2491 | void enterNonTrivialFullExpression(const ExprWithCleanups *E); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2492 | |
Richard Smith | ea85232 | 2013-05-07 21:53:22 +0000 | [diff] [blame] | 2493 | void EmitCXXThrowExpr(const CXXThrowExpr *E, bool KeepInsertionPoint = true); |
Douglas Gregor | c278d1b | 2010-05-16 00:44:00 +0000 | [diff] [blame] | 2494 | |
Eli Friedman | c370a7e | 2012-02-09 03:32:31 +0000 | [diff] [blame] | 2495 | void EmitLambdaExpr(const LambdaExpr *E, AggValueSlot Dest); |
| 2496 | |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 2497 | RValue EmitAtomicExpr(AtomicExpr *E, llvm::Value *Dest = nullptr); |
Eli Friedman | df14b3a | 2011-10-11 02:20:01 +0000 | [diff] [blame] | 2498 | |
Daniel Dunbar | 88402ce | 2008-08-04 16:51:22 +0000 | [diff] [blame] | 2499 | //===--------------------------------------------------------------------===// |
Julien Lerouge | 5a6b698 | 2011-09-09 22:41:49 +0000 | [diff] [blame] | 2500 | // Annotations Emission |
| 2501 | //===--------------------------------------------------------------------===// |
| 2502 | |
| 2503 | /// Emit an annotation call (intrinsic or builtin). |
| 2504 | llvm::Value *EmitAnnotationCall(llvm::Value *AnnotationFn, |
| 2505 | llvm::Value *AnnotatedVal, |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2506 | StringRef AnnotationStr, |
Julien Lerouge | 5a6b698 | 2011-09-09 22:41:49 +0000 | [diff] [blame] | 2507 | SourceLocation Location); |
| 2508 | |
| 2509 | /// Emit local annotations for the local variable V, declared by D. |
| 2510 | void EmitVarAnnotations(const VarDecl *D, llvm::Value *V); |
| 2511 | |
| 2512 | /// Emit field annotations for the given field & value. Returns the |
| 2513 | /// annotation result. |
| 2514 | llvm::Value *EmitFieldAnnotations(const FieldDecl *D, llvm::Value *V); |
| 2515 | |
| 2516 | //===--------------------------------------------------------------------===// |
Daniel Dunbar | 88402ce | 2008-08-04 16:51:22 +0000 | [diff] [blame] | 2517 | // Internal Helpers |
| 2518 | //===--------------------------------------------------------------------===// |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 2519 | |
Chris Lattner | 5b1964b | 2008-11-11 07:41:27 +0000 | [diff] [blame] | 2520 | /// ContainsLabel - Return true if the statement contains a label in it. If |
| 2521 | /// this statement is not executed normally, it not containing a label means |
| 2522 | /// that we can just remove the code. |
| 2523 | static bool ContainsLabel(const Stmt *S, bool IgnoreCaseStmts = false); |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 2524 | |
Chris Lattner | 29911cc | 2011-02-28 00:18:40 +0000 | [diff] [blame] | 2525 | /// containsBreak - Return true if the statement contains a break out of it. |
| 2526 | /// If the statement (recursively) contains a switch or loop with a break |
| 2527 | /// inside of it, this is fine. |
| 2528 | static bool containsBreak(const Stmt *S); |
| 2529 | |
Daniel Dunbar | 682712c | 2008-11-12 10:12:14 +0000 | [diff] [blame] | 2530 | /// ConstantFoldsToSimpleInteger - If the specified expression does not fold |
Chris Lattner | 41c6ab5 | 2011-02-27 23:02:32 +0000 | [diff] [blame] | 2531 | /// to a constant, or if it does but contains a label, return false. If it |
| 2532 | /// constant folds return true and set the boolean result in Result. |
| 2533 | bool ConstantFoldsToSimpleInteger(const Expr *Cond, bool &Result); |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 2534 | |
Chris Lattner | 29911cc | 2011-02-28 00:18:40 +0000 | [diff] [blame] | 2535 | /// ConstantFoldsToSimpleInteger - If the specified expression does not fold |
| 2536 | /// to a constant, or if it does but contains a label, return false. If it |
| 2537 | /// constant folds return true and set the folded value. |
Richard Trieu | c320c74 | 2012-07-23 20:21:35 +0000 | [diff] [blame] | 2538 | bool ConstantFoldsToSimpleInteger(const Expr *Cond, llvm::APSInt &Result); |
Chris Lattner | 29911cc | 2011-02-28 00:18:40 +0000 | [diff] [blame] | 2539 | |
Chris Lattner | cd43929 | 2008-11-12 08:04:58 +0000 | [diff] [blame] | 2540 | /// EmitBranchOnBoolExpr - Emit a branch on a boolean condition (e.g. for an |
| 2541 | /// if statement) to the specified blocks. Based on the condition, this might |
| 2542 | /// try to simplify the codegen of the conditional based on the branch. |
Justin Bogner | ef512b9 | 2014-01-06 22:27:43 +0000 | [diff] [blame] | 2543 | /// TrueCount should be the number of times we expect the condition to |
| 2544 | /// evaluate to true based on PGO data. |
Chris Lattner | b7a9e16 | 2008-11-12 07:46:33 +0000 | [diff] [blame] | 2545 | void EmitBranchOnBoolExpr(const Expr *Cond, llvm::BasicBlock *TrueBlock, |
Justin Bogner | ef512b9 | 2014-01-06 22:27:43 +0000 | [diff] [blame] | 2546 | llvm::BasicBlock *FalseBlock, uint64_t TrueCount); |
Mike Stump | ba6a0c4 | 2009-12-14 21:58:14 +0000 | [diff] [blame] | 2547 | |
Richard Smith | e30752c | 2012-10-09 19:52:38 +0000 | [diff] [blame] | 2548 | /// \brief Emit a description of a type in a format suitable for passing to |
| 2549 | /// a runtime sanitizer handler. |
| 2550 | llvm::Constant *EmitCheckTypeDescriptor(QualType T); |
| 2551 | |
| 2552 | /// \brief Convert a value into a format suitable for passing to a runtime |
| 2553 | /// sanitizer handler. |
| 2554 | llvm::Value *EmitCheckValue(llvm::Value *V); |
| 2555 | |
| 2556 | /// \brief Emit a description of a source location in a format suitable for |
| 2557 | /// passing to a runtime sanitizer handler. |
| 2558 | llvm::Constant *EmitCheckSourceLocation(SourceLocation Loc); |
| 2559 | |
Will Dietz | 88e0233 | 2012-12-02 19:50:33 +0000 | [diff] [blame] | 2560 | /// \brief Specify under what conditions this check can be recovered |
| 2561 | enum CheckRecoverableKind { |
| 2562 | /// Always terminate program execution if this check fails |
| 2563 | CRK_Unrecoverable, |
| 2564 | /// Check supports recovering, allows user to specify which |
| 2565 | CRK_Recoverable, |
| 2566 | /// Runtime conditionally aborts, always need to support recovery. |
| 2567 | CRK_AlwaysRecoverable |
| 2568 | }; |
| 2569 | |
Richard Smith | de67068 | 2012-11-01 22:15:34 +0000 | [diff] [blame] | 2570 | /// \brief Create a basic block that will call a handler function in a |
| 2571 | /// sanitizer runtime with the provided arguments, and create a conditional |
| 2572 | /// branch to it. |
Richard Smith | e30752c | 2012-10-09 19:52:38 +0000 | [diff] [blame] | 2573 | void EmitCheck(llvm::Value *Checked, StringRef CheckName, |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2574 | ArrayRef<llvm::Constant *> StaticArgs, |
| 2575 | ArrayRef<llvm::Value *> DynamicArgs, |
Will Dietz | 88e0233 | 2012-12-02 19:50:33 +0000 | [diff] [blame] | 2576 | CheckRecoverableKind Recoverable); |
Michael J. Spencer | f5a1fbc | 2010-10-19 06:39:39 +0000 | [diff] [blame] | 2577 | |
Richard Smith | de67068 | 2012-11-01 22:15:34 +0000 | [diff] [blame] | 2578 | /// \brief Create a basic block that will call the trap intrinsic, and emit a |
| 2579 | /// conditional branch to it, for the -ftrapv checks. |
Chad Rosier | ae229d5 | 2013-01-29 23:31:22 +0000 | [diff] [blame] | 2580 | void EmitTrapCheck(llvm::Value *Checked); |
Richard Smith | de67068 | 2012-11-01 22:15:34 +0000 | [diff] [blame] | 2581 | |
Anders Carlsson | 093bdff | 2010-03-30 03:27:09 +0000 | [diff] [blame] | 2582 | /// EmitCallArg - Emit a single call argument. |
John McCall | 32ea969 | 2011-03-11 20:59:21 +0000 | [diff] [blame] | 2583 | void EmitCallArg(CallArgList &args, const Expr *E, QualType ArgType); |
Anders Carlsson | 093bdff | 2010-03-30 03:27:09 +0000 | [diff] [blame] | 2584 | |
John McCall | 23f6626 | 2010-05-26 22:34:26 +0000 | [diff] [blame] | 2585 | /// EmitDelegateCallArg - We are performing a delegate call; that |
| 2586 | /// is, the current function is delegating to another one. Produce |
| 2587 | /// a r-value suitable for passing the given parameter. |
Nick Lewycky | 2d84e84 | 2013-10-02 02:29:49 +0000 | [diff] [blame] | 2588 | void EmitDelegateCallArg(CallArgList &args, const VarDecl *param, |
| 2589 | SourceLocation loc); |
John McCall | 23f6626 | 2010-05-26 22:34:26 +0000 | [diff] [blame] | 2590 | |
Peter Collingbourne | 95fd2ca | 2011-10-27 19:19:51 +0000 | [diff] [blame] | 2591 | /// SetFPAccuracy - Set the minimum required accuracy of the given floating |
| 2592 | /// point operation, expressed as the maximum relative error in ulp. |
Duncan Sands | e81111c | 2012-04-10 08:23:07 +0000 | [diff] [blame] | 2593 | void SetFPAccuracy(llvm::Value *Val, float Accuracy); |
Peter Collingbourne | 95fd2ca | 2011-10-27 19:19:51 +0000 | [diff] [blame] | 2594 | |
Chris Lattner | cd43929 | 2008-11-12 08:04:58 +0000 | [diff] [blame] | 2595 | private: |
Rafael Espindola | 5c0034a | 2012-03-24 16:50:34 +0000 | [diff] [blame] | 2596 | llvm::MDNode *getRangeForLoadFromType(QualType Ty); |
Daniel Dunbar | 1c64e5d | 2008-09-24 04:00:38 +0000 | [diff] [blame] | 2597 | void EmitReturnOfRValue(RValue RV, QualType Ty); |
| 2598 | |
Reid Kleckner | 314ef7b | 2014-02-01 00:04:45 +0000 | [diff] [blame] | 2599 | void deferPlaceholderReplacement(llvm::Instruction *Old, llvm::Value *New); |
| 2600 | |
| 2601 | llvm::SmallVector<std::pair<llvm::Instruction *, llvm::Value *>, 4> |
| 2602 | DeferredReplacements; |
| 2603 | |
Daniel Dunbar | 8fc81b0 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 2604 | /// ExpandTypeFromArgs - Reconstruct a structure of type \arg Ty |
| 2605 | /// from function arguments into \arg Dst. See ABIArgInfo::Expand. |
| 2606 | /// |
| 2607 | /// \param AI - The first function argument of the expansion. |
| 2608 | /// \return The argument following the last expanded function |
| 2609 | /// argument. |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 2610 | llvm::Function::arg_iterator |
Daniel Dunbar | 8fc81b0 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 2611 | ExpandTypeFromArgs(QualType Ty, LValue Dst, |
| 2612 | llvm::Function::arg_iterator AI); |
| 2613 | |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 2614 | /// ExpandTypeToArgs - Expand an RValue \arg Src, with the LLVM type for \arg |
| 2615 | /// Ty, into individual arguments on the provided vector \arg Args. See |
| 2616 | /// ABIArgInfo::Expand. |
| 2617 | void ExpandTypeToArgs(QualType Ty, RValue Src, |
Craig Topper | 5603df4 | 2013-07-05 19:34:19 +0000 | [diff] [blame] | 2618 | SmallVectorImpl<llvm::Value *> &Args, |
Chris Lattner | d59d867 | 2011-07-12 06:29:11 +0000 | [diff] [blame] | 2619 | llvm::FunctionType *IRFuncTy); |
Anders Carlsson | 03aaf11 | 2009-01-11 19:40:10 +0000 | [diff] [blame] | 2620 | |
Chad Rosier | 59df25b | 2012-08-23 20:00:18 +0000 | [diff] [blame] | 2621 | llvm::Value* EmitAsmInput(const TargetInfo::ConstraintInfo &Info, |
Anders Carlsson | 03aaf11 | 2009-01-11 19:40:10 +0000 | [diff] [blame] | 2622 | const Expr *InputExpr, std::string &ConstraintStr); |
Mike Stump | fc49682 | 2009-02-08 23:14:22 +0000 | [diff] [blame] | 2623 | |
Chad Rosier | 59df25b | 2012-08-23 20:00:18 +0000 | [diff] [blame] | 2624 | llvm::Value* EmitAsmInputLValue(const TargetInfo::ConstraintInfo &Info, |
Eli Friedman | eca55af | 2010-07-16 00:55:21 +0000 | [diff] [blame] | 2625 | LValue InputValue, QualType InputType, |
Nick Lewycky | 2d84e84 | 2013-10-02 02:29:49 +0000 | [diff] [blame] | 2626 | std::string &ConstraintStr, |
| 2627 | SourceLocation Loc); |
Eli Friedman | eca55af | 2010-07-16 00:55:21 +0000 | [diff] [blame] | 2628 | |
Reid Kleckner | 89077a1 | 2013-12-17 19:46:40 +0000 | [diff] [blame] | 2629 | public: |
Anders Carlsson | 60ce3fe | 2009-04-08 20:47:54 +0000 | [diff] [blame] | 2630 | /// EmitCallArgs - Emit call arguments for a function. |
Reid Kleckner | 739756c | 2013-12-04 19:23:12 +0000 | [diff] [blame] | 2631 | template <typename T> |
| 2632 | void EmitCallArgs(CallArgList &Args, const T *CallArgTypeInfo, |
Anders Carlsson | 60ce3fe | 2009-04-08 20:47:54 +0000 | [diff] [blame] | 2633 | CallExpr::const_arg_iterator ArgBeg, |
Adrian Prantl | ca64c3e | 2013-07-26 20:42:57 +0000 | [diff] [blame] | 2634 | CallExpr::const_arg_iterator ArgEnd, |
| 2635 | bool ForceColumnInfo = false) { |
Reid Kleckner | 739756c | 2013-12-04 19:23:12 +0000 | [diff] [blame] | 2636 | if (CallArgTypeInfo) { |
| 2637 | EmitCallArgs(Args, CallArgTypeInfo->isVariadic(), |
Alp Toker | 9cacbab | 2014-01-20 20:26:09 +0000 | [diff] [blame] | 2638 | CallArgTypeInfo->param_type_begin(), |
| 2639 | CallArgTypeInfo->param_type_end(), ArgBeg, ArgEnd, |
Reid Kleckner | 739756c | 2013-12-04 19:23:12 +0000 | [diff] [blame] | 2640 | ForceColumnInfo); |
| 2641 | } else { |
Alp Toker | 9cacbab | 2014-01-20 20:26:09 +0000 | [diff] [blame] | 2642 | // T::param_type_iterator might not have a default ctor. |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 2643 | const QualType *NoIter = nullptr; |
Reid Kleckner | 739756c | 2013-12-04 19:23:12 +0000 | [diff] [blame] | 2644 | EmitCallArgs(Args, /*AllowExtraArguments=*/true, NoIter, NoIter, ArgBeg, |
| 2645 | ArgEnd, ForceColumnInfo); |
| 2646 | } |
| 2647 | } |
Adrian Prantl | ca64c3e | 2013-07-26 20:42:57 +0000 | [diff] [blame] | 2648 | |
Reid Kleckner | 739756c | 2013-12-04 19:23:12 +0000 | [diff] [blame] | 2649 | template<typename ArgTypeIterator> |
| 2650 | void EmitCallArgs(CallArgList& Args, |
| 2651 | bool AllowExtraArguments, |
| 2652 | ArgTypeIterator ArgTypeBeg, |
| 2653 | ArgTypeIterator ArgTypeEnd, |
| 2654 | CallExpr::const_arg_iterator ArgBeg, |
| 2655 | CallExpr::const_arg_iterator ArgEnd, |
| 2656 | bool ForceColumnInfo = false) { |
| 2657 | SmallVector<QualType, 16> ArgTypes; |
Adrian Prantl | ca64c3e | 2013-07-26 20:42:57 +0000 | [diff] [blame] | 2658 | CallExpr::const_arg_iterator Arg = ArgBeg; |
Anders Carlsson | 60ce3fe | 2009-04-08 20:47:54 +0000 | [diff] [blame] | 2659 | |
Anders Carlsson | 603d6af | 2009-04-18 20:20:22 +0000 | [diff] [blame] | 2660 | // First, use the argument types that the type info knows about |
Reid Kleckner | 739756c | 2013-12-04 19:23:12 +0000 | [diff] [blame] | 2661 | for (ArgTypeIterator I = ArgTypeBeg, E = ArgTypeEnd; I != E; ++I, ++Arg) { |
| 2662 | assert(Arg != ArgEnd && "Running over edge of argument list!"); |
Fariborz Jahanian | 8fb87ae | 2010-09-24 17:30:16 +0000 | [diff] [blame] | 2663 | #ifndef NDEBUG |
Reid Kleckner | 739756c | 2013-12-04 19:23:12 +0000 | [diff] [blame] | 2664 | QualType ArgType = *I; |
| 2665 | QualType ActualArgType = Arg->getType(); |
| 2666 | if (ArgType->isPointerType() && ActualArgType->isPointerType()) { |
| 2667 | QualType ActualBaseType = |
Fariborz Jahanian | 8fb87ae | 2010-09-24 17:30:16 +0000 | [diff] [blame] | 2668 | ActualArgType->getAs<PointerType>()->getPointeeType(); |
Reid Kleckner | 739756c | 2013-12-04 19:23:12 +0000 | [diff] [blame] | 2669 | QualType ArgBaseType = |
Fariborz Jahanian | 8fb87ae | 2010-09-24 17:30:16 +0000 | [diff] [blame] | 2670 | ArgType->getAs<PointerType>()->getPointeeType(); |
Reid Kleckner | 739756c | 2013-12-04 19:23:12 +0000 | [diff] [blame] | 2671 | if (ArgBaseType->isVariableArrayType()) { |
| 2672 | if (const VariableArrayType *VAT = |
| 2673 | getContext().getAsVariableArrayType(ActualBaseType)) { |
| 2674 | if (!VAT->getSizeExpr()) |
| 2675 | ActualArgType = ArgType; |
Fariborz Jahanian | 8fb87ae | 2010-09-24 17:30:16 +0000 | [diff] [blame] | 2676 | } |
| 2677 | } |
Anders Carlsson | 603d6af | 2009-04-18 20:20:22 +0000 | [diff] [blame] | 2678 | } |
Reid Kleckner | 739756c | 2013-12-04 19:23:12 +0000 | [diff] [blame] | 2679 | assert(getContext().getCanonicalType(ArgType.getNonReferenceType()). |
| 2680 | getTypePtr() == |
| 2681 | getContext().getCanonicalType(ActualArgType).getTypePtr() && |
| 2682 | "type mismatch in call argument!"); |
| 2683 | #endif |
| 2684 | ArgTypes.push_back(*I); |
Anders Carlsson | 603d6af | 2009-04-18 20:20:22 +0000 | [diff] [blame] | 2685 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2686 | |
Reid Kleckner | 739756c | 2013-12-04 19:23:12 +0000 | [diff] [blame] | 2687 | // Either we've emitted all the call args, or we have a call to variadic |
| 2688 | // function or some other call that allows extra arguments. |
| 2689 | assert((Arg == ArgEnd || AllowExtraArguments) && |
| 2690 | "Extra arguments in non-variadic function!"); |
| 2691 | |
Anders Carlsson | 603d6af | 2009-04-18 20:20:22 +0000 | [diff] [blame] | 2692 | // If we still have any arguments, emit them using the type of the argument. |
Reid Kleckner | 739756c | 2013-12-04 19:23:12 +0000 | [diff] [blame] | 2693 | for (; Arg != ArgEnd; ++Arg) |
| 2694 | ArgTypes.push_back(Arg->getType()); |
Adrian Prantl | ca64c3e | 2013-07-26 20:42:57 +0000 | [diff] [blame] | 2695 | |
Reid Kleckner | 739756c | 2013-12-04 19:23:12 +0000 | [diff] [blame] | 2696 | EmitCallArgs(Args, ArgTypes, ArgBeg, ArgEnd, ForceColumnInfo); |
Anders Carlsson | 603d6af | 2009-04-18 20:20:22 +0000 | [diff] [blame] | 2697 | } |
John McCall | d4f4b7f | 2010-03-03 04:15:11 +0000 | [diff] [blame] | 2698 | |
Reid Kleckner | 739756c | 2013-12-04 19:23:12 +0000 | [diff] [blame] | 2699 | void EmitCallArgs(CallArgList &Args, ArrayRef<QualType> ArgTypes, |
| 2700 | CallExpr::const_arg_iterator ArgBeg, |
Richard Smith | 760520b | 2014-06-03 23:27:44 +0000 | [diff] [blame] | 2701 | CallExpr::const_arg_iterator ArgEnd, |
| 2702 | bool ForceColumnInfo = false); |
Reid Kleckner | 739756c | 2013-12-04 19:23:12 +0000 | [diff] [blame] | 2703 | |
Reid Kleckner | 89077a1 | 2013-12-17 19:46:40 +0000 | [diff] [blame] | 2704 | private: |
John McCall | d4f4b7f | 2010-03-03 04:15:11 +0000 | [diff] [blame] | 2705 | const TargetCodeGenInfo &getTargetHooks() const { |
| 2706 | return CGM.getTargetCodeGenInfo(); |
| 2707 | } |
John McCall | 09ae032 | 2010-07-06 23:57:41 +0000 | [diff] [blame] | 2708 | |
| 2709 | void EmitDeclMetadata(); |
John McCall | f9b056b | 2011-03-31 08:03:29 +0000 | [diff] [blame] | 2710 | |
| 2711 | CodeGenModule::ByrefHelpers * |
Chris Lattner | 2192fe5 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 2712 | buildByrefHelpers(llvm::StructType &byrefType, |
John McCall | f9b056b | 2011-03-31 08:03:29 +0000 | [diff] [blame] | 2713 | const AutoVarEmission &emission); |
Dan Gohman | 515a60d | 2012-02-16 00:57:37 +0000 | [diff] [blame] | 2714 | |
| 2715 | void AddObjCARCExceptionMetadata(llvm::Instruction *Inst); |
Jay Foad | b0f3344 | 2012-03-02 18:34:30 +0000 | [diff] [blame] | 2716 | |
Eli Friedman | a5dd568 | 2012-08-23 03:10:17 +0000 | [diff] [blame] | 2717 | /// GetPointeeAlignment - Given an expression with a pointer type, emit the |
| 2718 | /// value and compute our best estimate of the alignment of the pointee. |
| 2719 | std::pair<llvm::Value*, unsigned> EmitPointerWithAlignment(const Expr *Addr); |
Chris Lattner | bed3144 | 2007-05-28 01:07:47 +0000 | [diff] [blame] | 2720 | }; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2721 | |
John McCall | ce1de61 | 2011-01-26 04:00:11 +0000 | [diff] [blame] | 2722 | /// Helper class with most of the code for saving a value for a |
| 2723 | /// conditional expression cleanup. |
John McCall | cb5f77f | 2011-01-28 10:53:53 +0000 | [diff] [blame] | 2724 | struct DominatingLLVMValue { |
John McCall | ce1de61 | 2011-01-26 04:00:11 +0000 | [diff] [blame] | 2725 | typedef llvm::PointerIntPair<llvm::Value*, 1, bool> saved_type; |
| 2726 | |
| 2727 | /// Answer whether the given value needs extra work to be saved. |
| 2728 | static bool needsSaving(llvm::Value *value) { |
| 2729 | // If it's not an instruction, we don't need to save. |
| 2730 | if (!isa<llvm::Instruction>(value)) return false; |
| 2731 | |
| 2732 | // If it's an instruction in the entry block, we don't need to save. |
| 2733 | llvm::BasicBlock *block = cast<llvm::Instruction>(value)->getParent(); |
| 2734 | return (block != &block->getParent()->getEntryBlock()); |
| 2735 | } |
| 2736 | |
| 2737 | /// Try to save the given value. |
| 2738 | static saved_type save(CodeGenFunction &CGF, llvm::Value *value) { |
| 2739 | if (!needsSaving(value)) return saved_type(value, false); |
| 2740 | |
| 2741 | // Otherwise we need an alloca. |
| 2742 | llvm::Value *alloca = |
| 2743 | CGF.CreateTempAlloca(value->getType(), "cond-cleanup.save"); |
| 2744 | CGF.Builder.CreateStore(value, alloca); |
| 2745 | |
| 2746 | return saved_type(alloca, true); |
| 2747 | } |
| 2748 | |
| 2749 | static llvm::Value *restore(CodeGenFunction &CGF, saved_type value) { |
| 2750 | if (!value.getInt()) return value.getPointer(); |
| 2751 | return CGF.Builder.CreateLoad(value.getPointer()); |
| 2752 | } |
| 2753 | }; |
| 2754 | |
John McCall | cb5f77f | 2011-01-28 10:53:53 +0000 | [diff] [blame] | 2755 | /// A partial specialization of DominatingValue for llvm::Values that |
| 2756 | /// might be llvm::Instructions. |
| 2757 | template <class T> struct DominatingPointer<T,true> : DominatingLLVMValue { |
| 2758 | typedef T *type; |
John McCall | ce1de61 | 2011-01-26 04:00:11 +0000 | [diff] [blame] | 2759 | static type restore(CodeGenFunction &CGF, saved_type value) { |
John McCall | cb5f77f | 2011-01-28 10:53:53 +0000 | [diff] [blame] | 2760 | return static_cast<T*>(DominatingLLVMValue::restore(CGF, value)); |
| 2761 | } |
| 2762 | }; |
| 2763 | |
| 2764 | /// A specialization of DominatingValue for RValue. |
| 2765 | template <> struct DominatingValue<RValue> { |
| 2766 | typedef RValue type; |
| 2767 | class saved_type { |
| 2768 | enum Kind { ScalarLiteral, ScalarAddress, AggregateLiteral, |
| 2769 | AggregateAddress, ComplexAddress }; |
| 2770 | |
| 2771 | llvm::Value *Value; |
| 2772 | Kind K; |
| 2773 | saved_type(llvm::Value *v, Kind k) : Value(v), K(k) {} |
| 2774 | |
| 2775 | public: |
| 2776 | static bool needsSaving(RValue value); |
| 2777 | static saved_type save(CodeGenFunction &CGF, RValue value); |
| 2778 | RValue restore(CodeGenFunction &CGF); |
| 2779 | |
| 2780 | // implementations in CGExprCXX.cpp |
| 2781 | }; |
| 2782 | |
| 2783 | static bool needsSaving(type value) { |
| 2784 | return saved_type::needsSaving(value); |
| 2785 | } |
| 2786 | static saved_type save(CodeGenFunction &CGF, type value) { |
| 2787 | return saved_type::save(CGF, value); |
| 2788 | } |
| 2789 | static type restore(CodeGenFunction &CGF, saved_type value) { |
| 2790 | return value.restore(CGF); |
John McCall | ce1de61 | 2011-01-26 04:00:11 +0000 | [diff] [blame] | 2791 | } |
| 2792 | }; |
| 2793 | |
Chris Lattner | bed3144 | 2007-05-28 01:07:47 +0000 | [diff] [blame] | 2794 | } // end namespace CodeGen |
| 2795 | } // end namespace clang |
Fariborz Jahanian | 715fdd5 | 2012-01-29 20:27:13 +0000 | [diff] [blame] | 2796 | |
Chris Lattner | bed3144 | 2007-05-28 01:07:47 +0000 | [diff] [blame] | 2797 | #endif |