Daniel Dunbar | 0dbe227 | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 1 | //===----- CGCall.h - Encapsulate calling convention details ----*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // These classes wrap the information about a call or function |
| 11 | // definition used to handle ABI compliancy. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #ifndef CLANG_CODEGEN_CGCALL_H |
| 16 | #define CLANG_CODEGEN_CGCALL_H |
| 17 | |
Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 18 | #include "CGValue.h" |
Reid Kleckner | 9b60195 | 2013-06-21 12:45:15 +0000 | [diff] [blame] | 19 | #include "EHScopeStack.h" |
Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 20 | #include "clang/AST/CanonicalType.h" |
| 21 | #include "clang/AST/Type.h" |
Anders Carlsson | 31777a2 | 2009-12-24 19:08:58 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/FoldingSet.h" |
Chandler Carruth | 3b844ba | 2013-01-02 11:45:17 +0000 | [diff] [blame] | 23 | #include "llvm/IR/Value.h" |
Daniel Dunbar | 46f45b9 | 2008-09-09 01:06:48 +0000 | [diff] [blame] | 24 | |
Daniel Dunbar | 88c2fa9 | 2009-02-03 05:31:23 +0000 | [diff] [blame] | 25 | // FIXME: Restructure so we don't have to expose so much stuff. |
| 26 | #include "ABIInfo.h" |
| 27 | |
Daniel Dunbar | 0dbe227 | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 28 | namespace llvm { |
Bill Wendling | b263bdf | 2013-01-27 02:46:53 +0000 | [diff] [blame] | 29 | class AttributeSet; |
Daniel Dunbar | 88c2fa9 | 2009-02-03 05:31:23 +0000 | [diff] [blame] | 30 | class Function; |
| 31 | class Type; |
Daniel Dunbar | 0dbe227 | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 32 | class Value; |
Daniel Dunbar | 0dbe227 | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | namespace clang { |
| 36 | class ASTContext; |
| 37 | class Decl; |
| 38 | class FunctionDecl; |
| 39 | class ObjCMethodDecl; |
Daniel Dunbar | 7c08651 | 2008-09-09 23:14:03 +0000 | [diff] [blame] | 40 | class VarDecl; |
Daniel Dunbar | 0dbe227 | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 41 | |
| 42 | namespace CodeGen { |
Bill Wendling | b263bdf | 2013-01-27 02:46:53 +0000 | [diff] [blame] | 43 | typedef SmallVector<llvm::AttributeSet, 8> AttributeListType; |
Daniel Dunbar | 0dbe227 | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 44 | |
Eli Friedman | c6d0782 | 2011-05-02 18:05:27 +0000 | [diff] [blame] | 45 | struct CallArg { |
| 46 | RValue RV; |
| 47 | QualType Ty; |
Eli Friedman | 55d4848 | 2011-05-26 00:10:27 +0000 | [diff] [blame] | 48 | bool NeedsCopy; |
| 49 | CallArg(RValue rv, QualType ty, bool needscopy) |
| 50 | : RV(rv), Ty(ty), NeedsCopy(needscopy) |
Eli Friedman | c6d0782 | 2011-05-02 18:05:27 +0000 | [diff] [blame] | 51 | { } |
| 52 | }; |
| 53 | |
Daniel Dunbar | 0dbe227 | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 54 | /// CallArgList - Type for representing both the value and type of |
| 55 | /// arguments in a call. |
John McCall | d26bc76 | 2011-03-09 04:27:21 +0000 | [diff] [blame] | 56 | class CallArgList : |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 57 | public SmallVector<CallArg, 16> { |
John McCall | 413ebdb | 2011-03-11 20:59:21 +0000 | [diff] [blame] | 58 | public: |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 59 | struct Writeback { |
John McCall | b6a6079 | 2013-03-23 02:35:54 +0000 | [diff] [blame] | 60 | /// The original argument. Note that the argument l-value |
| 61 | /// is potentially null. |
| 62 | LValue Source; |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 63 | |
| 64 | /// The temporary alloca. |
| 65 | llvm::Value *Temporary; |
John McCall | b6a6079 | 2013-03-23 02:35:54 +0000 | [diff] [blame] | 66 | |
| 67 | /// A value to "use" after the writeback, or null. |
| 68 | llvm::Value *ToUse; |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 69 | }; |
| 70 | |
Reid Kleckner | 9b60195 | 2013-06-21 12:45:15 +0000 | [diff] [blame] | 71 | struct CallArgCleanup { |
| 72 | EHScopeStack::stable_iterator Cleanup; |
| 73 | |
| 74 | /// The "is active" insertion point. This instruction is temporary and |
| 75 | /// will be removed after insertion. |
| 76 | llvm::Instruction *IsActiveIP; |
| 77 | }; |
| 78 | |
Eli Friedman | 55d4848 | 2011-05-26 00:10:27 +0000 | [diff] [blame] | 79 | void add(RValue rvalue, QualType type, bool needscopy = false) { |
| 80 | push_back(CallArg(rvalue, type, needscopy)); |
John McCall | 413ebdb | 2011-03-11 20:59:21 +0000 | [diff] [blame] | 81 | } |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 82 | |
| 83 | void addFrom(const CallArgList &other) { |
| 84 | insert(end(), other.begin(), other.end()); |
| 85 | Writebacks.insert(Writebacks.end(), |
| 86 | other.Writebacks.begin(), other.Writebacks.end()); |
| 87 | } |
| 88 | |
John McCall | b6a6079 | 2013-03-23 02:35:54 +0000 | [diff] [blame] | 89 | void addWriteback(LValue srcLV, llvm::Value *temporary, |
| 90 | llvm::Value *toUse) { |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 91 | Writeback writeback; |
John McCall | b6a6079 | 2013-03-23 02:35:54 +0000 | [diff] [blame] | 92 | writeback.Source = srcLV; |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 93 | writeback.Temporary = temporary; |
John McCall | b6a6079 | 2013-03-23 02:35:54 +0000 | [diff] [blame] | 94 | writeback.ToUse = toUse; |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 95 | Writebacks.push_back(writeback); |
| 96 | } |
| 97 | |
| 98 | bool hasWritebacks() const { return !Writebacks.empty(); } |
| 99 | |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 100 | typedef SmallVectorImpl<Writeback>::const_iterator writeback_iterator; |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 101 | writeback_iterator writeback_begin() const { return Writebacks.begin(); } |
| 102 | writeback_iterator writeback_end() const { return Writebacks.end(); } |
| 103 | |
Reid Kleckner | 9b60195 | 2013-06-21 12:45:15 +0000 | [diff] [blame] | 104 | void addArgCleanupDeactivation(EHScopeStack::stable_iterator Cleanup, |
| 105 | llvm::Instruction *IsActiveIP) { |
| 106 | CallArgCleanup ArgCleanup; |
| 107 | ArgCleanup.Cleanup = Cleanup; |
| 108 | ArgCleanup.IsActiveIP = IsActiveIP; |
| 109 | CleanupsToDeactivate.push_back(ArgCleanup); |
| 110 | } |
| 111 | |
| 112 | ArrayRef<CallArgCleanup> getCleanupsToDeactivate() const { |
| 113 | return CleanupsToDeactivate; |
| 114 | } |
| 115 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 116 | private: |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 117 | SmallVector<Writeback, 1> Writebacks; |
Reid Kleckner | 9b60195 | 2013-06-21 12:45:15 +0000 | [diff] [blame] | 118 | |
| 119 | /// Deactivate these cleanups immediately before making the call. This |
| 120 | /// is used to cleanup objects that are owned by the callee once the call |
| 121 | /// occurs. |
| 122 | SmallVector<CallArgCleanup, 1> CleanupsToDeactivate; |
John McCall | d26bc76 | 2011-03-09 04:27:21 +0000 | [diff] [blame] | 123 | }; |
Daniel Dunbar | 0dbe227 | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 124 | |
Daniel Dunbar | 7c08651 | 2008-09-09 23:14:03 +0000 | [diff] [blame] | 125 | /// FunctionArgList - Type for representing both the decl and type |
| 126 | /// of parameters to a function. The decl must be either a |
| 127 | /// ParmVarDecl or ImplicitParamDecl. |
Chris Lattner | 686775d | 2011-07-20 06:58:45 +0000 | [diff] [blame] | 128 | class FunctionArgList : public SmallVector<const VarDecl*, 16> { |
John McCall | d26bc76 | 2011-03-09 04:27:21 +0000 | [diff] [blame] | 129 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 130 | |
Anders Carlsson | d2490a9 | 2009-12-24 20:40:36 +0000 | [diff] [blame] | 131 | /// ReturnValueSlot - Contains the address where the return value of a |
| 132 | /// function can be stored, and whether the address is volatile or not. |
Anders Carlsson | 31777a2 | 2009-12-24 19:08:58 +0000 | [diff] [blame] | 133 | class ReturnValueSlot { |
| 134 | llvm::PointerIntPair<llvm::Value *, 1, bool> Value; |
| 135 | |
| 136 | public: |
| 137 | ReturnValueSlot() {} |
| 138 | ReturnValueSlot(llvm::Value *Value, bool IsVolatile) |
| 139 | : Value(Value, IsVolatile) {} |
| 140 | |
| 141 | bool isNull() const { return !getValue(); } |
| 142 | |
| 143 | bool isVolatile() const { return Value.getInt(); } |
| 144 | llvm::Value *getValue() const { return Value.getPointer(); } |
| 145 | }; |
| 146 | |
Daniel Dunbar | 0dbe227 | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 147 | } // end namespace CodeGen |
| 148 | } // end namespace clang |
| 149 | |
| 150 | #endif |