CGCall.h revision 413ebdb1af6fb0d81845b61254daf02ba0449afd
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 /// CallArgList - Type for representing both the value and type of 48 /// arguments in a call. 49 class CallArgList : 50 public llvm::SmallVector<std::pair<RValue, QualType>, 16> { 51 public: 52 void add(RValue rvalue, QualType type) { 53 push_back(std::pair<RValue,QualType>(rvalue,type)); 54 } 55 }; 56 57 /// FunctionArgList - Type for representing both the decl and type 58 /// of parameters to a function. The decl must be either a 59 /// ParmVarDecl or ImplicitParamDecl. 60 class FunctionArgList : public llvm::SmallVector<const VarDecl*, 16> { 61 }; 62 63 /// CGFunctionInfo - Class to encapsulate the information about a 64 /// function definition. 65 class CGFunctionInfo : public llvm::FoldingSetNode { 66 struct ArgInfo { 67 CanQualType type; 68 ABIArgInfo info; 69 }; 70 71 /// The LLVM::CallingConv to use for this function (as specified by the 72 /// user). 73 unsigned CallingConvention; 74 75 /// The LLVM::CallingConv to actually use for this function, which may 76 /// depend on the ABI. 77 unsigned EffectiveCallingConvention; 78 79 /// Whether this function is noreturn. 80 bool NoReturn; 81 82 unsigned NumArgs; 83 ArgInfo *Args; 84 85 /// How many arguments to pass inreg. 86 unsigned RegParm; 87 88 public: 89 typedef const ArgInfo *const_arg_iterator; 90 typedef ArgInfo *arg_iterator; 91 92 CGFunctionInfo(unsigned CallingConvention, bool NoReturn, 93 unsigned RegParm, CanQualType ResTy, 94 const CanQualType *ArgTys, unsigned NumArgTys); 95 ~CGFunctionInfo() { delete[] Args; } 96 97 const_arg_iterator arg_begin() const { return Args + 1; } 98 const_arg_iterator arg_end() const { return Args + 1 + NumArgs; } 99 arg_iterator arg_begin() { return Args + 1; } 100 arg_iterator arg_end() { return Args + 1 + NumArgs; } 101 102 unsigned arg_size() const { return NumArgs; } 103 104 bool isNoReturn() const { return NoReturn; } 105 106 /// getCallingConvention - Return the user specified calling 107 /// convention. 108 unsigned getCallingConvention() const { return CallingConvention; } 109 110 /// getEffectiveCallingConvention - Return the actual calling convention to 111 /// use, which may depend on the ABI. 112 unsigned getEffectiveCallingConvention() const { 113 return EffectiveCallingConvention; 114 } 115 void setEffectiveCallingConvention(unsigned Value) { 116 EffectiveCallingConvention = Value; 117 } 118 119 unsigned getRegParm() const { return RegParm; } 120 121 CanQualType getReturnType() const { return Args[0].type; } 122 123 ABIArgInfo &getReturnInfo() { return Args[0].info; } 124 const ABIArgInfo &getReturnInfo() const { return Args[0].info; } 125 126 void Profile(llvm::FoldingSetNodeID &ID) { 127 ID.AddInteger(getCallingConvention()); 128 ID.AddBoolean(NoReturn); 129 ID.AddInteger(RegParm); 130 getReturnType().Profile(ID); 131 for (arg_iterator it = arg_begin(), ie = arg_end(); it != ie; ++it) 132 it->type.Profile(ID); 133 } 134 template<class Iterator> 135 static void Profile(llvm::FoldingSetNodeID &ID, 136 const FunctionType::ExtInfo &Info, 137 CanQualType ResTy, 138 Iterator begin, 139 Iterator end) { 140 ID.AddInteger(Info.getCC()); 141 ID.AddBoolean(Info.getNoReturn()); 142 ID.AddInteger(Info.getRegParm()); 143 ResTy.Profile(ID); 144 for (; begin != end; ++begin) { 145 CanQualType T = *begin; // force iterator to be over canonical types 146 T.Profile(ID); 147 } 148 } 149 }; 150 151 /// ReturnValueSlot - Contains the address where the return value of a 152 /// function can be stored, and whether the address is volatile or not. 153 class ReturnValueSlot { 154 llvm::PointerIntPair<llvm::Value *, 1, bool> Value; 155 156 public: 157 ReturnValueSlot() {} 158 ReturnValueSlot(llvm::Value *Value, bool IsVolatile) 159 : Value(Value, IsVolatile) {} 160 161 bool isNull() const { return !getValue(); } 162 163 bool isVolatile() const { return Value.getInt(); } 164 llvm::Value *getValue() const { return Value.getPointer(); } 165 }; 166 167} // end namespace CodeGen 168} // end namespace clang 169 170#endif 171