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 | |
Anders Carlsson | 31777a2 | 2009-12-24 19:08:58 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/FoldingSet.h" |
| 19 | #include "llvm/Value.h" |
Daniel Dunbar | 0dbe227 | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 20 | #include "clang/AST/Type.h" |
John McCall | ead608a | 2010-02-26 00:48:12 +0000 | [diff] [blame] | 21 | #include "clang/AST/CanonicalType.h" |
Daniel Dunbar | 0dbe227 | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 22 | |
Daniel Dunbar | 46f45b9 | 2008-09-09 01:06:48 +0000 | [diff] [blame] | 23 | #include "CGValue.h" |
| 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 { |
Devang Patel | 761d7f7 | 2008-09-25 21:02:23 +0000 | [diff] [blame] | 29 | struct AttributeWithIndex; |
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; |
| 33 | |
| 34 | template<typename T, unsigned> class SmallVector; |
| 35 | } |
| 36 | |
| 37 | namespace clang { |
| 38 | class ASTContext; |
| 39 | class Decl; |
| 40 | class FunctionDecl; |
| 41 | class ObjCMethodDecl; |
Daniel Dunbar | 7c08651 | 2008-09-09 23:14:03 +0000 | [diff] [blame] | 42 | class VarDecl; |
Daniel Dunbar | 0dbe227 | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 43 | |
| 44 | namespace CodeGen { |
Devang Patel | 761d7f7 | 2008-09-25 21:02:23 +0000 | [diff] [blame] | 45 | typedef llvm::SmallVector<llvm::AttributeWithIndex, 8> AttributeListType; |
Daniel Dunbar | 0dbe227 | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 46 | |
| 47 | /// CallArgList - Type for representing both the value and type of |
| 48 | /// arguments in a call. |
Daniel Dunbar | 46f45b9 | 2008-09-09 01:06:48 +0000 | [diff] [blame] | 49 | typedef llvm::SmallVector<std::pair<RValue, QualType>, 16> CallArgList; |
Daniel Dunbar | 0dbe227 | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 50 | |
Daniel Dunbar | 7c08651 | 2008-09-09 23:14:03 +0000 | [diff] [blame] | 51 | /// FunctionArgList - Type for representing both the decl and type |
| 52 | /// of parameters to a function. The decl must be either a |
| 53 | /// ParmVarDecl or ImplicitParamDecl. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 54 | typedef llvm::SmallVector<std::pair<const VarDecl*, QualType>, |
Daniel Dunbar | 7c08651 | 2008-09-09 23:14:03 +0000 | [diff] [blame] | 55 | 16> FunctionArgList; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 56 | |
Daniel Dunbar | 0dbe227 | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 57 | /// CGFunctionInfo - Class to encapsulate the information about a |
| 58 | /// function definition. |
Daniel Dunbar | 40a6be6 | 2009-02-03 00:07:12 +0000 | [diff] [blame] | 59 | class CGFunctionInfo : public llvm::FoldingSetNode { |
Daniel Dunbar | 88c2fa9 | 2009-02-03 05:31:23 +0000 | [diff] [blame] | 60 | struct ArgInfo { |
John McCall | ead608a | 2010-02-26 00:48:12 +0000 | [diff] [blame] | 61 | CanQualType type; |
Daniel Dunbar | 88c2fa9 | 2009-02-03 05:31:23 +0000 | [diff] [blame] | 62 | ABIArgInfo info; |
| 63 | }; |
| 64 | |
Daniel Dunbar | ca6408c | 2009-09-12 00:59:20 +0000 | [diff] [blame] | 65 | /// The LLVM::CallingConv to use for this function (as specified by the |
| 66 | /// user). |
Daniel Dunbar | bac7c25 | 2009-09-11 22:24:53 +0000 | [diff] [blame] | 67 | unsigned CallingConvention; |
| 68 | |
Daniel Dunbar | ca6408c | 2009-09-12 00:59:20 +0000 | [diff] [blame] | 69 | /// The LLVM::CallingConv to actually use for this function, which may |
| 70 | /// depend on the ABI. |
| 71 | unsigned EffectiveCallingConvention; |
| 72 | |
John McCall | 04a67a6 | 2010-02-05 21:31:56 +0000 | [diff] [blame] | 73 | /// Whether this function is noreturn. |
| 74 | bool NoReturn; |
| 75 | |
Daniel Dunbar | 88c2fa9 | 2009-02-03 05:31:23 +0000 | [diff] [blame] | 76 | unsigned NumArgs; |
| 77 | ArgInfo *Args; |
Daniel Dunbar | 0dbe227 | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 78 | |
Rafael Espindola | 425ef72 | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 79 | /// How many arguments to pass inreg. |
| 80 | unsigned RegParm; |
| 81 | |
Daniel Dunbar | 0dbe227 | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 82 | public: |
Daniel Dunbar | 88c2fa9 | 2009-02-03 05:31:23 +0000 | [diff] [blame] | 83 | typedef const ArgInfo *const_arg_iterator; |
| 84 | typedef ArgInfo *arg_iterator; |
Daniel Dunbar | a0a99e0 | 2009-02-02 23:43:58 +0000 | [diff] [blame] | 85 | |
Daniel Dunbar | bac7c25 | 2009-09-11 22:24:53 +0000 | [diff] [blame] | 86 | CGFunctionInfo(unsigned CallingConvention, |
John McCall | 04a67a6 | 2010-02-05 21:31:56 +0000 | [diff] [blame] | 87 | bool NoReturn, |
Rafael Espindola | 425ef72 | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 88 | unsigned RegParm, |
John McCall | ead608a | 2010-02-26 00:48:12 +0000 | [diff] [blame] | 89 | CanQualType ResTy, |
| 90 | const llvm::SmallVectorImpl<CanQualType> &ArgTys); |
Daniel Dunbar | 88c2fa9 | 2009-02-03 05:31:23 +0000 | [diff] [blame] | 91 | ~CGFunctionInfo() { delete[] Args; } |
Daniel Dunbar | 0dbe227 | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 92 | |
Daniel Dunbar | 88c2fa9 | 2009-02-03 05:31:23 +0000 | [diff] [blame] | 93 | const_arg_iterator arg_begin() const { return Args + 1; } |
| 94 | const_arg_iterator arg_end() const { return Args + 1 + NumArgs; } |
| 95 | arg_iterator arg_begin() { return Args + 1; } |
| 96 | arg_iterator arg_end() { return Args + 1 + NumArgs; } |
Daniel Dunbar | bb36d33 | 2009-02-02 21:43:58 +0000 | [diff] [blame] | 97 | |
Daniel Dunbar | 4b5f0a4 | 2009-02-04 21:17:21 +0000 | [diff] [blame] | 98 | unsigned arg_size() const { return NumArgs; } |
| 99 | |
John McCall | 04a67a6 | 2010-02-05 21:31:56 +0000 | [diff] [blame] | 100 | bool isNoReturn() const { return NoReturn; } |
| 101 | |
Daniel Dunbar | ca6408c | 2009-09-12 00:59:20 +0000 | [diff] [blame] | 102 | /// getCallingConvention - Return the user specified calling |
| 103 | /// convention. |
Daniel Dunbar | bac7c25 | 2009-09-11 22:24:53 +0000 | [diff] [blame] | 104 | unsigned getCallingConvention() const { return CallingConvention; } |
| 105 | |
Daniel Dunbar | ca6408c | 2009-09-12 00:59:20 +0000 | [diff] [blame] | 106 | /// getEffectiveCallingConvention - Return the actual calling convention to |
| 107 | /// use, which may depend on the ABI. |
| 108 | unsigned getEffectiveCallingConvention() const { |
| 109 | return EffectiveCallingConvention; |
| 110 | } |
| 111 | void setEffectiveCallingConvention(unsigned Value) { |
| 112 | EffectiveCallingConvention = Value; |
| 113 | } |
| 114 | |
Rafael Espindola | 425ef72 | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 115 | unsigned getRegParm() const { return RegParm; } |
| 116 | |
John McCall | ead608a | 2010-02-26 00:48:12 +0000 | [diff] [blame] | 117 | CanQualType getReturnType() const { return Args[0].type; } |
Daniel Dunbar | 88c2fa9 | 2009-02-03 05:31:23 +0000 | [diff] [blame] | 118 | |
| 119 | ABIArgInfo &getReturnInfo() { return Args[0].info; } |
| 120 | const ABIArgInfo &getReturnInfo() const { return Args[0].info; } |
Daniel Dunbar | 40a6be6 | 2009-02-03 00:07:12 +0000 | [diff] [blame] | 121 | |
| 122 | void Profile(llvm::FoldingSetNodeID &ID) { |
Daniel Dunbar | bac7c25 | 2009-09-11 22:24:53 +0000 | [diff] [blame] | 123 | ID.AddInteger(getCallingConvention()); |
John McCall | 04a67a6 | 2010-02-05 21:31:56 +0000 | [diff] [blame] | 124 | ID.AddBoolean(NoReturn); |
Rafael Espindola | 425ef72 | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 125 | ID.AddInteger(RegParm); |
Daniel Dunbar | 35e67d4 | 2009-02-05 00:00:23 +0000 | [diff] [blame] | 126 | getReturnType().Profile(ID); |
Daniel Dunbar | 88c2fa9 | 2009-02-03 05:31:23 +0000 | [diff] [blame] | 127 | for (arg_iterator it = arg_begin(), ie = arg_end(); it != ie; ++it) |
| 128 | it->type.Profile(ID); |
Daniel Dunbar | 40a6be6 | 2009-02-03 00:07:12 +0000 | [diff] [blame] | 129 | } |
| 130 | template<class Iterator> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 131 | static void Profile(llvm::FoldingSetNodeID &ID, |
Rafael Espindola | 264ba48 | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 132 | const FunctionType::ExtInfo &Info, |
John McCall | ead608a | 2010-02-26 00:48:12 +0000 | [diff] [blame] | 133 | CanQualType ResTy, |
Daniel Dunbar | 40a6be6 | 2009-02-03 00:07:12 +0000 | [diff] [blame] | 134 | Iterator begin, |
| 135 | Iterator end) { |
Rafael Espindola | 264ba48 | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 136 | ID.AddInteger(Info.getCC()); |
| 137 | ID.AddBoolean(Info.getNoReturn()); |
Rafael Espindola | 425ef72 | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 138 | ID.AddInteger(Info.getRegParm()); |
Daniel Dunbar | 40a6be6 | 2009-02-03 00:07:12 +0000 | [diff] [blame] | 139 | ResTy.Profile(ID); |
John McCall | ead608a | 2010-02-26 00:48:12 +0000 | [diff] [blame] | 140 | for (; begin != end; ++begin) { |
| 141 | CanQualType T = *begin; // force iterator to be over canonical types |
| 142 | T.Profile(ID); |
| 143 | } |
Daniel Dunbar | 40a6be6 | 2009-02-03 00:07:12 +0000 | [diff] [blame] | 144 | } |
Daniel Dunbar | 0dbe227 | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 145 | }; |
Anders Carlsson | 31777a2 | 2009-12-24 19:08:58 +0000 | [diff] [blame] | 146 | |
Anders Carlsson | d2490a9 | 2009-12-24 20:40:36 +0000 | [diff] [blame] | 147 | /// ReturnValueSlot - Contains the address where the return value of a |
| 148 | /// function can be stored, and whether the address is volatile or not. |
Anders Carlsson | 31777a2 | 2009-12-24 19:08:58 +0000 | [diff] [blame] | 149 | class ReturnValueSlot { |
| 150 | llvm::PointerIntPair<llvm::Value *, 1, bool> Value; |
| 151 | |
| 152 | public: |
| 153 | ReturnValueSlot() {} |
| 154 | ReturnValueSlot(llvm::Value *Value, bool IsVolatile) |
| 155 | : Value(Value, IsVolatile) {} |
| 156 | |
| 157 | bool isNull() const { return !getValue(); } |
| 158 | |
| 159 | bool isVolatile() const { return Value.getInt(); } |
| 160 | llvm::Value *getValue() const { return Value.getPointer(); } |
| 161 | }; |
| 162 | |
Daniel Dunbar | 0dbe227 | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 163 | } // end namespace CodeGen |
| 164 | } // end namespace clang |
| 165 | |
| 166 | #endif |