CGCall.h revision 221345
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 18#include "llvm/ADT/FoldingSet.h" 19#include "llvm/Value.h" 20#include "clang/AST/Type.h" 21#include "clang/AST/CanonicalType.h" 22 23#include "CGValue.h" 24 25// FIXME: Restructure so we don't have to expose so much stuff. 26#include "ABIInfo.h" 27 28namespace llvm { 29 struct AttributeWithIndex; 30 class Function; 31 class Type; 32 class Value; 33 34 template<typename T, unsigned> class SmallVector; 35} 36 37namespace clang { 38 class ASTContext; 39 class Decl; 40 class FunctionDecl; 41 class ObjCMethodDecl; 42 class VarDecl; 43 44namespace CodeGen { 45 typedef llvm::SmallVector<llvm::AttributeWithIndex, 8> AttributeListType; 46 47 struct CallArg { 48 RValue RV; 49 QualType Ty; 50 CallArg(RValue rv, QualType ty) 51 : RV(rv), Ty(ty) 52 { } 53 }; 54 55 /// CallArgList - Type for representing both the value and type of 56 /// arguments in a call. 57 class CallArgList : 58 public llvm::SmallVector<CallArg, 16> { 59 public: 60 void add(RValue rvalue, QualType type) { 61 push_back(CallArg(rvalue, type)); 62 } 63 }; 64 65 /// FunctionArgList - Type for representing both the decl and type 66 /// of parameters to a function. The decl must be either a 67 /// ParmVarDecl or ImplicitParamDecl. 68 class FunctionArgList : public llvm::SmallVector<const VarDecl*, 16> { 69 }; 70 71 /// CGFunctionInfo - Class to encapsulate the information about a 72 /// function definition. 73 class CGFunctionInfo : public llvm::FoldingSetNode { 74 struct ArgInfo { 75 CanQualType type; 76 ABIArgInfo info; 77 }; 78 79 /// The LLVM::CallingConv to use for this function (as specified by the 80 /// user). 81 unsigned CallingConvention; 82 83 /// The LLVM::CallingConv to actually use for this function, which may 84 /// depend on the ABI. 85 unsigned EffectiveCallingConvention; 86 87 /// Whether this function is noreturn. 88 bool NoReturn; 89 90 unsigned NumArgs; 91 ArgInfo *Args; 92 93 /// How many arguments to pass inreg. 94 bool HasRegParm; 95 unsigned RegParm; 96 97 public: 98 typedef const ArgInfo *const_arg_iterator; 99 typedef ArgInfo *arg_iterator; 100 101 CGFunctionInfo(unsigned CallingConvention, bool NoReturn, 102 bool HasRegParm, unsigned RegParm, CanQualType ResTy, 103 const CanQualType *ArgTys, unsigned NumArgTys); 104 ~CGFunctionInfo() { delete[] Args; } 105 106 const_arg_iterator arg_begin() const { return Args + 1; } 107 const_arg_iterator arg_end() const { return Args + 1 + NumArgs; } 108 arg_iterator arg_begin() { return Args + 1; } 109 arg_iterator arg_end() { return Args + 1 + NumArgs; } 110 111 unsigned arg_size() const { return NumArgs; } 112 113 bool isNoReturn() const { return NoReturn; } 114 115 /// getCallingConvention - Return the user specified calling 116 /// convention. 117 unsigned getCallingConvention() const { return CallingConvention; } 118 119 /// getEffectiveCallingConvention - Return the actual calling convention to 120 /// use, which may depend on the ABI. 121 unsigned getEffectiveCallingConvention() const { 122 return EffectiveCallingConvention; 123 } 124 void setEffectiveCallingConvention(unsigned Value) { 125 EffectiveCallingConvention = Value; 126 } 127 128 bool getHasRegParm() const { return HasRegParm; } 129 unsigned getRegParm() const { return RegParm; } 130 131 CanQualType getReturnType() const { return Args[0].type; } 132 133 ABIArgInfo &getReturnInfo() { return Args[0].info; } 134 const ABIArgInfo &getReturnInfo() const { return Args[0].info; } 135 136 void Profile(llvm::FoldingSetNodeID &ID) { 137 ID.AddInteger(getCallingConvention()); 138 ID.AddBoolean(NoReturn); 139 ID.AddBoolean(HasRegParm); 140 ID.AddInteger(RegParm); 141 getReturnType().Profile(ID); 142 for (arg_iterator it = arg_begin(), ie = arg_end(); it != ie; ++it) 143 it->type.Profile(ID); 144 } 145 template<class Iterator> 146 static void Profile(llvm::FoldingSetNodeID &ID, 147 const FunctionType::ExtInfo &Info, 148 CanQualType ResTy, 149 Iterator begin, 150 Iterator end) { 151 ID.AddInteger(Info.getCC()); 152 ID.AddBoolean(Info.getNoReturn()); 153 ID.AddBoolean(Info.getHasRegParm()); 154 ID.AddInteger(Info.getRegParm()); 155 ResTy.Profile(ID); 156 for (; begin != end; ++begin) { 157 CanQualType T = *begin; // force iterator to be over canonical types 158 T.Profile(ID); 159 } 160 } 161 }; 162 163 /// ReturnValueSlot - Contains the address where the return value of a 164 /// function can be stored, and whether the address is volatile or not. 165 class ReturnValueSlot { 166 llvm::PointerIntPair<llvm::Value *, 1, bool> Value; 167 168 public: 169 ReturnValueSlot() {} 170 ReturnValueSlot(llvm::Value *Value, bool IsVolatile) 171 : Value(Value, IsVolatile) {} 172 173 bool isNull() const { return !getValue(); } 174 175 bool isVolatile() const { return Value.getInt(); } 176 llvm::Value *getValue() const { return Value.getPointer(); } 177 }; 178 179} // end namespace CodeGen 180} // end namespace clang 181 182#endif 183