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