Daniel Dunbar | 3d7c90b | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 1 | //===----- CGCall.h - Encapsulate calling convention details ----*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Daniel Dunbar | 3d7c90b | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // These classes wrap the information about a call or function |
| 10 | // definition used to handle ABI compliancy. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Benjamin Kramer | 2f5db8b | 2014-08-13 16:25:19 +0000 | [diff] [blame] | 14 | #ifndef LLVM_CLANG_LIB_CODEGEN_CGCALL_H |
| 15 | #define LLVM_CLANG_LIB_CODEGEN_CGCALL_H |
Daniel Dunbar | 3d7c90b | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 16 | |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 17 | #include "CGValue.h" |
Reid Kleckner | 23f4c4b | 2013-06-21 12:45:15 +0000 | [diff] [blame] | 18 | #include "EHScopeStack.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 19 | #include "clang/AST/CanonicalType.h" |
Peter Collingbourne | ea21100 | 2018-02-05 23:09:13 +0000 | [diff] [blame] | 20 | #include "clang/AST/GlobalDecl.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 21 | #include "clang/AST/Type.h" |
Chandler Carruth | ffd5551 | 2013-01-02 11:45:17 +0000 | [diff] [blame] | 22 | #include "llvm/IR/Value.h" |
Daniel Dunbar | 41cf9de | 2008-09-09 01:06:48 +0000 | [diff] [blame] | 23 | |
Daniel Dunbar | 313321e | 2009-02-03 05:31:23 +0000 | [diff] [blame] | 24 | // FIXME: Restructure so we don't have to expose so much stuff. |
| 25 | #include "ABIInfo.h" |
| 26 | |
Daniel Dunbar | 3d7c90b | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 27 | namespace llvm { |
Reid Kleckner | de86482 | 2017-03-21 16:57:30 +0000 | [diff] [blame] | 28 | class AttributeList; |
| 29 | class Function; |
| 30 | class Type; |
| 31 | class Value; |
Daniel Dunbar | 3d7c90b | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | namespace clang { |
| 35 | class ASTContext; |
| 36 | class Decl; |
| 37 | class FunctionDecl; |
| 38 | class ObjCMethodDecl; |
Daniel Dunbar | bc915f4 | 2008-09-09 23:14:03 +0000 | [diff] [blame] | 39 | class VarDecl; |
Daniel Dunbar | 3d7c90b | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 40 | |
| 41 | namespace CodeGen { |
Daniel Dunbar | 3d7c90b | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 42 | |
Reid Kleckner | de86482 | 2017-03-21 16:57:30 +0000 | [diff] [blame] | 43 | /// Abstract information about a function or function prototype. |
| 44 | class CGCalleeInfo { |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 45 | /// The function prototype of the callee. |
Reid Kleckner | de86482 | 2017-03-21 16:57:30 +0000 | [diff] [blame] | 46 | const FunctionProtoType *CalleeProtoTy; |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 47 | /// The function declaration of the callee. |
Erich Keane | de6480a3 | 2018-11-13 15:48:08 +0000 | [diff] [blame] | 48 | GlobalDecl CalleeDecl; |
John McCall | b92ab1a | 2016-10-26 23:46:34 +0000 | [diff] [blame] | 49 | |
Reid Kleckner | de86482 | 2017-03-21 16:57:30 +0000 | [diff] [blame] | 50 | public: |
Erich Keane | de6480a3 | 2018-11-13 15:48:08 +0000 | [diff] [blame] | 51 | explicit CGCalleeInfo() : CalleeProtoTy(nullptr), CalleeDecl() {} |
| 52 | CGCalleeInfo(const FunctionProtoType *calleeProtoTy, GlobalDecl calleeDecl) |
Reid Kleckner | de86482 | 2017-03-21 16:57:30 +0000 | [diff] [blame] | 53 | : CalleeProtoTy(calleeProtoTy), CalleeDecl(calleeDecl) {} |
| 54 | CGCalleeInfo(const FunctionProtoType *calleeProtoTy) |
Erich Keane | de6480a3 | 2018-11-13 15:48:08 +0000 | [diff] [blame] | 55 | : CalleeProtoTy(calleeProtoTy), CalleeDecl() {} |
| 56 | CGCalleeInfo(GlobalDecl calleeDecl) |
Reid Kleckner | de86482 | 2017-03-21 16:57:30 +0000 | [diff] [blame] | 57 | : CalleeProtoTy(nullptr), CalleeDecl(calleeDecl) {} |
John McCall | b92ab1a | 2016-10-26 23:46:34 +0000 | [diff] [blame] | 58 | |
Reid Kleckner | de86482 | 2017-03-21 16:57:30 +0000 | [diff] [blame] | 59 | const FunctionProtoType *getCalleeFunctionProtoType() const { |
| 60 | return CalleeProtoTy; |
| 61 | } |
Erich Keane | de6480a3 | 2018-11-13 15:48:08 +0000 | [diff] [blame] | 62 | const GlobalDecl getCalleeDecl() const { return CalleeDecl; } |
John McCall | b92ab1a | 2016-10-26 23:46:34 +0000 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | /// All available information about a concrete callee. |
| 66 | class CGCallee { |
| 67 | enum class SpecialKind : uintptr_t { |
| 68 | Invalid, |
| 69 | Builtin, |
| 70 | PseudoDestructor, |
Peter Collingbourne | ea21100 | 2018-02-05 23:09:13 +0000 | [diff] [blame] | 71 | Virtual, |
John McCall | b92ab1a | 2016-10-26 23:46:34 +0000 | [diff] [blame] | 72 | |
Peter Collingbourne | ea21100 | 2018-02-05 23:09:13 +0000 | [diff] [blame] | 73 | Last = Virtual |
John McCall | b92ab1a | 2016-10-26 23:46:34 +0000 | [diff] [blame] | 74 | }; |
| 75 | |
John McCall | aaae302 | 2016-11-07 21:13:27 +0000 | [diff] [blame] | 76 | struct BuiltinInfoStorage { |
| 77 | const FunctionDecl *Decl; |
| 78 | unsigned ID; |
| 79 | }; |
| 80 | struct PseudoDestructorInfoStorage { |
| 81 | const CXXPseudoDestructorExpr *Expr; |
| 82 | }; |
Peter Collingbourne | ea21100 | 2018-02-05 23:09:13 +0000 | [diff] [blame] | 83 | struct VirtualInfoStorage { |
| 84 | const CallExpr *CE; |
| 85 | GlobalDecl MD; |
| 86 | Address Addr; |
| 87 | llvm::FunctionType *FTy; |
| 88 | }; |
John McCall | aaae302 | 2016-11-07 21:13:27 +0000 | [diff] [blame] | 89 | |
John McCall | b92ab1a | 2016-10-26 23:46:34 +0000 | [diff] [blame] | 90 | SpecialKind KindOrFunctionPointer; |
| 91 | union { |
| 92 | CGCalleeInfo AbstractInfo; |
John McCall | aaae302 | 2016-11-07 21:13:27 +0000 | [diff] [blame] | 93 | BuiltinInfoStorage BuiltinInfo; |
| 94 | PseudoDestructorInfoStorage PseudoDestructorInfo; |
Peter Collingbourne | ea21100 | 2018-02-05 23:09:13 +0000 | [diff] [blame] | 95 | VirtualInfoStorage VirtualInfo; |
John McCall | b92ab1a | 2016-10-26 23:46:34 +0000 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | explicit CGCallee(SpecialKind kind) : KindOrFunctionPointer(kind) {} |
| 99 | |
| 100 | CGCallee(const FunctionDecl *builtinDecl, unsigned builtinID) |
| 101 | : KindOrFunctionPointer(SpecialKind::Builtin) { |
| 102 | BuiltinInfo.Decl = builtinDecl; |
| 103 | BuiltinInfo.ID = builtinID; |
| 104 | } |
| 105 | |
| 106 | public: |
| 107 | CGCallee() : KindOrFunctionPointer(SpecialKind::Invalid) {} |
| 108 | |
| 109 | /// Construct a callee. Call this constructor directly when this |
| 110 | /// isn't a direct call. |
| 111 | CGCallee(const CGCalleeInfo &abstractInfo, llvm::Value *functionPtr) |
| 112 | : KindOrFunctionPointer(SpecialKind(uintptr_t(functionPtr))) { |
| 113 | AbstractInfo = abstractInfo; |
| 114 | assert(functionPtr && "configuring callee without function pointer"); |
| 115 | assert(functionPtr->getType()->isPointerTy()); |
| 116 | assert(functionPtr->getType()->getPointerElementType()->isFunctionTy()); |
| 117 | } |
| 118 | |
| 119 | static CGCallee forBuiltin(unsigned builtinID, |
| 120 | const FunctionDecl *builtinDecl) { |
| 121 | CGCallee result(SpecialKind::Builtin); |
| 122 | result.BuiltinInfo.Decl = builtinDecl; |
| 123 | result.BuiltinInfo.ID = builtinID; |
| 124 | return result; |
| 125 | } |
| 126 | |
| 127 | static CGCallee forPseudoDestructor(const CXXPseudoDestructorExpr *E) { |
| 128 | CGCallee result(SpecialKind::PseudoDestructor); |
| 129 | result.PseudoDestructorInfo.Expr = E; |
| 130 | return result; |
| 131 | } |
| 132 | |
| 133 | static CGCallee forDirect(llvm::Constant *functionPtr, |
| 134 | const CGCalleeInfo &abstractInfo = CGCalleeInfo()) { |
| 135 | return CGCallee(abstractInfo, functionPtr); |
| 136 | } |
| 137 | |
James Y Knight | 9871db0 | 2019-02-05 16:42:33 +0000 | [diff] [blame] | 138 | static CGCallee |
| 139 | forDirect(llvm::FunctionCallee functionPtr, |
| 140 | const CGCalleeInfo &abstractInfo = CGCalleeInfo()) { |
| 141 | return CGCallee(abstractInfo, functionPtr.getCallee()); |
| 142 | } |
| 143 | |
Peter Collingbourne | ea21100 | 2018-02-05 23:09:13 +0000 | [diff] [blame] | 144 | static CGCallee forVirtual(const CallExpr *CE, GlobalDecl MD, Address Addr, |
| 145 | llvm::FunctionType *FTy) { |
| 146 | CGCallee result(SpecialKind::Virtual); |
| 147 | result.VirtualInfo.CE = CE; |
| 148 | result.VirtualInfo.MD = MD; |
| 149 | result.VirtualInfo.Addr = Addr; |
| 150 | result.VirtualInfo.FTy = FTy; |
| 151 | return result; |
| 152 | } |
| 153 | |
John McCall | b92ab1a | 2016-10-26 23:46:34 +0000 | [diff] [blame] | 154 | bool isBuiltin() const { |
| 155 | return KindOrFunctionPointer == SpecialKind::Builtin; |
| 156 | } |
| 157 | const FunctionDecl *getBuiltinDecl() const { |
| 158 | assert(isBuiltin()); |
| 159 | return BuiltinInfo.Decl; |
| 160 | } |
| 161 | unsigned getBuiltinID() const { |
| 162 | assert(isBuiltin()); |
| 163 | return BuiltinInfo.ID; |
| 164 | } |
| 165 | |
| 166 | bool isPseudoDestructor() const { |
| 167 | return KindOrFunctionPointer == SpecialKind::PseudoDestructor; |
| 168 | } |
| 169 | const CXXPseudoDestructorExpr *getPseudoDestructorExpr() const { |
| 170 | assert(isPseudoDestructor()); |
| 171 | return PseudoDestructorInfo.Expr; |
| 172 | } |
| 173 | |
| 174 | bool isOrdinary() const { |
| 175 | return uintptr_t(KindOrFunctionPointer) > uintptr_t(SpecialKind::Last); |
| 176 | } |
Peter Collingbourne | ea21100 | 2018-02-05 23:09:13 +0000 | [diff] [blame] | 177 | CGCalleeInfo getAbstractInfo() const { |
| 178 | if (isVirtual()) |
Erich Keane | de6480a3 | 2018-11-13 15:48:08 +0000 | [diff] [blame] | 179 | return VirtualInfo.MD; |
John McCall | b92ab1a | 2016-10-26 23:46:34 +0000 | [diff] [blame] | 180 | assert(isOrdinary()); |
| 181 | return AbstractInfo; |
| 182 | } |
| 183 | llvm::Value *getFunctionPointer() const { |
| 184 | assert(isOrdinary()); |
| 185 | return reinterpret_cast<llvm::Value*>(uintptr_t(KindOrFunctionPointer)); |
| 186 | } |
John McCall | b92ab1a | 2016-10-26 23:46:34 +0000 | [diff] [blame] | 187 | void setFunctionPointer(llvm::Value *functionPtr) { |
| 188 | assert(isOrdinary()); |
| 189 | KindOrFunctionPointer = SpecialKind(uintptr_t(functionPtr)); |
| 190 | } |
Peter Collingbourne | ea21100 | 2018-02-05 23:09:13 +0000 | [diff] [blame] | 191 | |
| 192 | bool isVirtual() const { |
| 193 | return KindOrFunctionPointer == SpecialKind::Virtual; |
| 194 | } |
| 195 | const CallExpr *getVirtualCallExpr() const { |
| 196 | assert(isVirtual()); |
| 197 | return VirtualInfo.CE; |
| 198 | } |
| 199 | GlobalDecl getVirtualMethodDecl() const { |
| 200 | assert(isVirtual()); |
| 201 | return VirtualInfo.MD; |
| 202 | } |
| 203 | Address getThisAddress() const { |
| 204 | assert(isVirtual()); |
| 205 | return VirtualInfo.Addr; |
| 206 | } |
James Y Knight | cfe8cd7 | 2019-02-07 01:15:41 +0000 | [diff] [blame] | 207 | llvm::FunctionType *getVirtualFunctionType() const { |
| 208 | assert(isVirtual()); |
| 209 | return VirtualInfo.FTy; |
Peter Collingbourne | ea21100 | 2018-02-05 23:09:13 +0000 | [diff] [blame] | 210 | } |
John McCall | 9831b84 | 2018-02-06 18:52:44 +0000 | [diff] [blame] | 211 | |
| 212 | /// If this is a delayed callee computation of some sort, prepare |
| 213 | /// a concrete callee. |
| 214 | CGCallee prepareConcreteCallee(CodeGenFunction &CGF) const; |
John McCall | b92ab1a | 2016-10-26 23:46:34 +0000 | [diff] [blame] | 215 | }; |
| 216 | |
Eli Friedman | f4258eb | 2011-05-02 18:05:27 +0000 | [diff] [blame] | 217 | struct CallArg { |
Yaxun Liu | 5b330e8 | 2018-03-15 15:25:19 +0000 | [diff] [blame] | 218 | private: |
| 219 | union { |
| 220 | RValue RV; |
| 221 | LValue LV; /// The argument is semantically a load from this l-value. |
| 222 | }; |
| 223 | bool HasLV; |
| 224 | |
| 225 | /// A data-flow flag to make sure getRValue and/or copyInto are not |
| 226 | /// called twice for duplicated IR emission. |
| 227 | mutable bool IsUsed; |
| 228 | |
| 229 | public: |
Eli Friedman | f4258eb | 2011-05-02 18:05:27 +0000 | [diff] [blame] | 230 | QualType Ty; |
Yaxun Liu | 5b330e8 | 2018-03-15 15:25:19 +0000 | [diff] [blame] | 231 | CallArg(RValue rv, QualType ty) |
| 232 | : RV(rv), HasLV(false), IsUsed(false), Ty(ty) {} |
| 233 | CallArg(LValue lv, QualType ty) |
| 234 | : LV(lv), HasLV(true), IsUsed(false), Ty(ty) {} |
| 235 | bool hasLValue() const { return HasLV; } |
| 236 | QualType getType() const { return Ty; } |
| 237 | |
| 238 | /// \returns an independent RValue. If the CallArg contains an LValue, |
| 239 | /// a temporary copy is returned. |
| 240 | RValue getRValue(CodeGenFunction &CGF) const; |
| 241 | |
| 242 | LValue getKnownLValue() const { |
| 243 | assert(HasLV && !IsUsed); |
| 244 | return LV; |
| 245 | } |
| 246 | RValue getKnownRValue() const { |
| 247 | assert(!HasLV && !IsUsed); |
| 248 | return RV; |
| 249 | } |
| 250 | void setRValue(RValue _RV) { |
| 251 | assert(!HasLV); |
| 252 | RV = _RV; |
| 253 | } |
| 254 | |
| 255 | bool isAggregate() const { return HasLV || RV.isAggregate(); } |
| 256 | |
| 257 | void copyInto(CodeGenFunction &CGF, Address A) const; |
Eli Friedman | f4258eb | 2011-05-02 18:05:27 +0000 | [diff] [blame] | 258 | }; |
| 259 | |
Daniel Dunbar | 3d7c90b | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 260 | /// CallArgList - Type for representing both the value and type of |
| 261 | /// arguments in a call. |
John McCall | a738c25 | 2011-03-09 04:27:21 +0000 | [diff] [blame] | 262 | class CallArgList : |
Yaxun Liu | d938982 | 2018-03-14 15:02:28 +0000 | [diff] [blame] | 263 | public SmallVector<CallArg, 8> { |
John McCall | 32ea969 | 2011-03-11 20:59:21 +0000 | [diff] [blame] | 264 | public: |
Reid Kleckner | 7c2f9e8 | 2015-10-08 00:17:45 +0000 | [diff] [blame] | 265 | CallArgList() : StackBase(nullptr) {} |
Reid Kleckner | 314ef7b | 2014-02-01 00:04:45 +0000 | [diff] [blame] | 266 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 267 | struct Writeback { |
John McCall | eff1884 | 2013-03-23 02:35:54 +0000 | [diff] [blame] | 268 | /// The original argument. Note that the argument l-value |
| 269 | /// is potentially null. |
| 270 | LValue Source; |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 271 | |
| 272 | /// The temporary alloca. |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 273 | Address Temporary; |
John McCall | eff1884 | 2013-03-23 02:35:54 +0000 | [diff] [blame] | 274 | |
| 275 | /// A value to "use" after the writeback, or null. |
| 276 | llvm::Value *ToUse; |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 277 | }; |
| 278 | |
Reid Kleckner | 23f4c4b | 2013-06-21 12:45:15 +0000 | [diff] [blame] | 279 | struct CallArgCleanup { |
| 280 | EHScopeStack::stable_iterator Cleanup; |
| 281 | |
| 282 | /// The "is active" insertion point. This instruction is temporary and |
| 283 | /// will be removed after insertion. |
| 284 | llvm::Instruction *IsActiveIP; |
| 285 | }; |
| 286 | |
Yaxun Liu | 5b330e8 | 2018-03-15 15:25:19 +0000 | [diff] [blame] | 287 | void add(RValue rvalue, QualType type) { push_back(CallArg(rvalue, type)); } |
| 288 | |
| 289 | void addUncopiedAggregate(LValue LV, QualType type) { |
| 290 | push_back(CallArg(LV, type)); |
John McCall | 32ea969 | 2011-03-11 20:59:21 +0000 | [diff] [blame] | 291 | } |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 292 | |
Richard Smith | 762672a | 2016-09-28 19:09:10 +0000 | [diff] [blame] | 293 | /// Add all the arguments from another CallArgList to this one. After doing |
| 294 | /// this, the old CallArgList retains its list of arguments, but must not |
| 295 | /// be used to emit a call. |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 296 | void addFrom(const CallArgList &other) { |
| 297 | insert(end(), other.begin(), other.end()); |
| 298 | Writebacks.insert(Writebacks.end(), |
| 299 | other.Writebacks.begin(), other.Writebacks.end()); |
Richard Smith | 762672a | 2016-09-28 19:09:10 +0000 | [diff] [blame] | 300 | CleanupsToDeactivate.insert(CleanupsToDeactivate.end(), |
| 301 | other.CleanupsToDeactivate.begin(), |
| 302 | other.CleanupsToDeactivate.end()); |
| 303 | assert(!(StackBase && other.StackBase) && "can't merge stackbases"); |
| 304 | if (!StackBase) |
| 305 | StackBase = other.StackBase; |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 306 | } |
| 307 | |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 308 | void addWriteback(LValue srcLV, Address temporary, |
John McCall | eff1884 | 2013-03-23 02:35:54 +0000 | [diff] [blame] | 309 | llvm::Value *toUse) { |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 310 | Writeback writeback = { srcLV, temporary, toUse }; |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 311 | Writebacks.push_back(writeback); |
| 312 | } |
| 313 | |
| 314 | bool hasWritebacks() const { return !Writebacks.empty(); } |
| 315 | |
Aaron Ballman | 36a7fa8 | 2014-03-17 17:22:27 +0000 | [diff] [blame] | 316 | typedef llvm::iterator_range<SmallVectorImpl<Writeback>::const_iterator> |
| 317 | writeback_const_range; |
| 318 | |
| 319 | writeback_const_range writebacks() const { |
| 320 | return writeback_const_range(Writebacks.begin(), Writebacks.end()); |
| 321 | } |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 322 | |
Reid Kleckner | 23f4c4b | 2013-06-21 12:45:15 +0000 | [diff] [blame] | 323 | void addArgCleanupDeactivation(EHScopeStack::stable_iterator Cleanup, |
| 324 | llvm::Instruction *IsActiveIP) { |
| 325 | CallArgCleanup ArgCleanup; |
| 326 | ArgCleanup.Cleanup = Cleanup; |
| 327 | ArgCleanup.IsActiveIP = IsActiveIP; |
| 328 | CleanupsToDeactivate.push_back(ArgCleanup); |
| 329 | } |
| 330 | |
| 331 | ArrayRef<CallArgCleanup> getCleanupsToDeactivate() const { |
| 332 | return CleanupsToDeactivate; |
| 333 | } |
| 334 | |
Reid Kleckner | 314ef7b | 2014-02-01 00:04:45 +0000 | [diff] [blame] | 335 | void allocateArgumentMemory(CodeGenFunction &CGF); |
| 336 | llvm::Instruction *getStackBase() const { return StackBase; } |
Nico Weber | 8cdb3f9 | 2015-08-25 18:43:32 +0000 | [diff] [blame] | 337 | void freeArgumentMemory(CodeGenFunction &CGF) const; |
Reid Kleckner | 314ef7b | 2014-02-01 00:04:45 +0000 | [diff] [blame] | 338 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 339 | /// Returns if we're using an inalloca struct to pass arguments in |
Reid Kleckner | 314ef7b | 2014-02-01 00:04:45 +0000 | [diff] [blame] | 340 | /// memory. |
| 341 | bool isUsingInAlloca() const { return StackBase; } |
| 342 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 343 | private: |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 344 | SmallVector<Writeback, 1> Writebacks; |
Reid Kleckner | 23f4c4b | 2013-06-21 12:45:15 +0000 | [diff] [blame] | 345 | |
| 346 | /// Deactivate these cleanups immediately before making the call. This |
| 347 | /// is used to cleanup objects that are owned by the callee once the call |
| 348 | /// occurs. |
| 349 | SmallVector<CallArgCleanup, 1> CleanupsToDeactivate; |
Reid Kleckner | 314ef7b | 2014-02-01 00:04:45 +0000 | [diff] [blame] | 350 | |
| 351 | /// The stacksave call. It dominates all of the argument evaluation. |
| 352 | llvm::CallInst *StackBase; |
John McCall | a738c25 | 2011-03-09 04:27:21 +0000 | [diff] [blame] | 353 | }; |
Daniel Dunbar | 3d7c90b | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 354 | |
Daniel Dunbar | bc915f4 | 2008-09-09 23:14:03 +0000 | [diff] [blame] | 355 | /// FunctionArgList - Type for representing both the decl and type |
| 356 | /// of parameters to a function. The decl must be either a |
| 357 | /// ParmVarDecl or ImplicitParamDecl. |
Chris Lattner | 01cf8db | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 358 | class FunctionArgList : public SmallVector<const VarDecl*, 16> { |
John McCall | a738c25 | 2011-03-09 04:27:21 +0000 | [diff] [blame] | 359 | }; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 360 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 361 | /// ReturnValueSlot - Contains the address where the return value of a |
Anders Carlsson | 1749083 | 2009-12-24 20:40:36 +0000 | [diff] [blame] | 362 | /// function can be stored, and whether the address is volatile or not. |
Anders Carlsson | 0435ed5 | 2009-12-24 19:08:58 +0000 | [diff] [blame] | 363 | class ReturnValueSlot { |
Leny Kholodov | 6aab111 | 2015-06-08 10:23:49 +0000 | [diff] [blame] | 364 | llvm::PointerIntPair<llvm::Value *, 2, unsigned int> Value; |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 365 | CharUnits Alignment; |
Leny Kholodov | 6aab111 | 2015-06-08 10:23:49 +0000 | [diff] [blame] | 366 | |
| 367 | // Return value slot flags |
| 368 | enum Flags { |
| 369 | IS_VOLATILE = 0x1, |
| 370 | IS_UNUSED = 0x2, |
| 371 | }; |
Anders Carlsson | 0435ed5 | 2009-12-24 19:08:58 +0000 | [diff] [blame] | 372 | |
| 373 | public: |
| 374 | ReturnValueSlot() {} |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 375 | ReturnValueSlot(Address Addr, bool IsVolatile, bool IsUnused = false) |
| 376 | : Value(Addr.isValid() ? Addr.getPointer() : nullptr, |
| 377 | (IsVolatile ? IS_VOLATILE : 0) | (IsUnused ? IS_UNUSED : 0)), |
| 378 | Alignment(Addr.isValid() ? Addr.getAlignment() : CharUnits::Zero()) {} |
Anders Carlsson | 0435ed5 | 2009-12-24 19:08:58 +0000 | [diff] [blame] | 379 | |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 380 | bool isNull() const { return !getValue().isValid(); } |
Leny Kholodov | 6aab111 | 2015-06-08 10:23:49 +0000 | [diff] [blame] | 381 | |
| 382 | bool isVolatile() const { return Value.getInt() & IS_VOLATILE; } |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 383 | Address getValue() const { return Address(Value.getPointer(), Alignment); } |
Leny Kholodov | 6aab111 | 2015-06-08 10:23:49 +0000 | [diff] [blame] | 384 | bool isUnused() const { return Value.getInt() & IS_UNUSED; } |
Anders Carlsson | 0435ed5 | 2009-12-24 19:08:58 +0000 | [diff] [blame] | 385 | }; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 386 | |
Daniel Dunbar | 3d7c90b | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 387 | } // end namespace CodeGen |
| 388 | } // end namespace clang |
| 389 | |
| 390 | #endif |