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