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