blob: ebf801dcaad1e9f3b5f8dfebb7933bf57667eef0 [file] [log] [blame]
Daniel Dunbar0dbe2272008-09-08 21:33:45 +00001//===----- 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
Daniel Dunbar40a6be62009-02-03 00:07:12 +000018#include <llvm/ADT/FoldingSet.h>
Daniel Dunbar0dbe2272008-09-08 21:33:45 +000019#include "clang/AST/Type.h"
20
Daniel Dunbar46f45b92008-09-09 01:06:48 +000021#include "CGValue.h"
22
Daniel Dunbar88c2fa92009-02-03 05:31:23 +000023// FIXME: Restructure so we don't have to expose so much stuff.
24#include "ABIInfo.h"
25
Daniel Dunbar0dbe2272008-09-08 21:33:45 +000026namespace llvm {
Devang Patel761d7f72008-09-25 21:02:23 +000027 struct AttributeWithIndex;
Daniel Dunbar88c2fa92009-02-03 05:31:23 +000028 class Function;
29 class Type;
Daniel Dunbar0dbe2272008-09-08 21:33:45 +000030 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;
Daniel Dunbar7c086512008-09-09 23:14:03 +000040 class VarDecl;
Daniel Dunbar0dbe2272008-09-08 21:33:45 +000041
42namespace CodeGen {
Devang Patel761d7f72008-09-25 21:02:23 +000043 typedef llvm::SmallVector<llvm::AttributeWithIndex, 8> AttributeListType;
Daniel Dunbar0dbe2272008-09-08 21:33:45 +000044
45 /// CallArgList - Type for representing both the value and type of
46 /// arguments in a call.
Daniel Dunbar46f45b92008-09-09 01:06:48 +000047 typedef llvm::SmallVector<std::pair<RValue, QualType>, 16> CallArgList;
Daniel Dunbar0dbe2272008-09-08 21:33:45 +000048
Daniel Dunbar7c086512008-09-09 23:14:03 +000049 /// 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.
Mike Stump1eb44332009-09-09 15:08:12 +000052 typedef llvm::SmallVector<std::pair<const VarDecl*, QualType>,
Daniel Dunbar7c086512008-09-09 23:14:03 +000053 16> FunctionArgList;
Mike Stump1eb44332009-09-09 15:08:12 +000054
Daniel Dunbar0dbe2272008-09-08 21:33:45 +000055 /// CGFunctionInfo - Class to encapsulate the information about a
56 /// function definition.
Daniel Dunbar40a6be62009-02-03 00:07:12 +000057 class CGFunctionInfo : public llvm::FoldingSetNode {
Daniel Dunbar88c2fa92009-02-03 05:31:23 +000058 struct ArgInfo {
59 QualType type;
60 ABIArgInfo info;
61 };
62
Daniel Dunbarca6408c2009-09-12 00:59:20 +000063 /// The LLVM::CallingConv to use for this function (as specified by the
64 /// user).
Daniel Dunbarbac7c252009-09-11 22:24:53 +000065 unsigned CallingConvention;
66
Daniel Dunbarca6408c2009-09-12 00:59:20 +000067 /// The LLVM::CallingConv to actually use for this function, which may
68 /// depend on the ABI.
69 unsigned EffectiveCallingConvention;
70
Daniel Dunbar88c2fa92009-02-03 05:31:23 +000071 unsigned NumArgs;
72 ArgInfo *Args;
Daniel Dunbar0dbe2272008-09-08 21:33:45 +000073
74 public:
Daniel Dunbar88c2fa92009-02-03 05:31:23 +000075 typedef const ArgInfo *const_arg_iterator;
76 typedef ArgInfo *arg_iterator;
Daniel Dunbara0a99e02009-02-02 23:43:58 +000077
Daniel Dunbarbac7c252009-09-11 22:24:53 +000078 CGFunctionInfo(unsigned CallingConvention,
79 QualType ResTy,
Daniel Dunbar541b63b2009-02-02 23:23:47 +000080 const llvm::SmallVector<QualType, 16> &ArgTys);
Daniel Dunbar88c2fa92009-02-03 05:31:23 +000081 ~CGFunctionInfo() { delete[] Args; }
Daniel Dunbar0dbe2272008-09-08 21:33:45 +000082
Daniel Dunbar88c2fa92009-02-03 05:31:23 +000083 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; }
Daniel Dunbarbb36d332009-02-02 21:43:58 +000087
Daniel Dunbar4b5f0a42009-02-04 21:17:21 +000088 unsigned arg_size() const { return NumArgs; }
89
Daniel Dunbarca6408c2009-09-12 00:59:20 +000090 /// getCallingConvention - Return the user specified calling
91 /// convention.
Daniel Dunbarbac7c252009-09-11 22:24:53 +000092 unsigned getCallingConvention() const { return CallingConvention; }
93
Daniel Dunbarca6408c2009-09-12 00:59:20 +000094 /// 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
Daniel Dunbar88c2fa92009-02-03 05:31:23 +0000103 QualType getReturnType() const { return Args[0].type; }
104
105 ABIArgInfo &getReturnInfo() { return Args[0].info; }
106 const ABIArgInfo &getReturnInfo() const { return Args[0].info; }
Daniel Dunbar40a6be62009-02-03 00:07:12 +0000107
108 void Profile(llvm::FoldingSetNodeID &ID) {
Daniel Dunbarbac7c252009-09-11 22:24:53 +0000109 ID.AddInteger(getCallingConvention());
Daniel Dunbar35e67d42009-02-05 00:00:23 +0000110 getReturnType().Profile(ID);
Daniel Dunbar88c2fa92009-02-03 05:31:23 +0000111 for (arg_iterator it = arg_begin(), ie = arg_end(); it != ie; ++it)
112 it->type.Profile(ID);
Daniel Dunbar40a6be62009-02-03 00:07:12 +0000113 }
114 template<class Iterator>
Mike Stump1eb44332009-09-09 15:08:12 +0000115 static void Profile(llvm::FoldingSetNodeID &ID,
Daniel Dunbarbac7c252009-09-11 22:24:53 +0000116 unsigned CallingConvention,
Daniel Dunbar40a6be62009-02-03 00:07:12 +0000117 QualType ResTy,
118 Iterator begin,
119 Iterator end) {
Daniel Dunbarbac7c252009-09-11 22:24:53 +0000120 ID.AddInteger(CallingConvention);
Daniel Dunbar40a6be62009-02-03 00:07:12 +0000121 ResTy.Profile(ID);
122 for (; begin != end; ++begin)
123 begin->Profile(ID);
124 }
Daniel Dunbar0dbe2272008-09-08 21:33:45 +0000125 };
Daniel Dunbar0dbe2272008-09-08 21:33:45 +0000126} // end namespace CodeGen
127} // end namespace clang
128
129#endif