blob: 3d81165b1bf134ec30ab18c6cb7936f3ce574938 [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
Anders Carlsson31777a22009-12-24 19:08:58 +000018#include "llvm/ADT/FoldingSet.h"
19#include "llvm/Value.h"
Daniel Dunbar0dbe2272008-09-08 21:33:45 +000020#include "clang/AST/Type.h"
John McCallead608a2010-02-26 00:48:12 +000021#include "clang/AST/CanonicalType.h"
Daniel Dunbar0dbe2272008-09-08 21:33:45 +000022
Daniel Dunbar46f45b92008-09-09 01:06:48 +000023#include "CGValue.h"
24
Daniel Dunbar88c2fa92009-02-03 05:31:23 +000025// FIXME: Restructure so we don't have to expose so much stuff.
26#include "ABIInfo.h"
27
Daniel Dunbar0dbe2272008-09-08 21:33:45 +000028namespace llvm {
Devang Patel761d7f72008-09-25 21:02:23 +000029 struct AttributeWithIndex;
Daniel Dunbar88c2fa92009-02-03 05:31:23 +000030 class Function;
31 class Type;
Daniel Dunbar0dbe2272008-09-08 21:33:45 +000032 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;
Daniel Dunbar7c086512008-09-09 23:14:03 +000042 class VarDecl;
Daniel Dunbar0dbe2272008-09-08 21:33:45 +000043
44namespace CodeGen {
Devang Patel761d7f72008-09-25 21:02:23 +000045 typedef llvm::SmallVector<llvm::AttributeWithIndex, 8> AttributeListType;
Daniel Dunbar0dbe2272008-09-08 21:33:45 +000046
47 /// CallArgList - Type for representing both the value and type of
48 /// arguments in a call.
Daniel Dunbar46f45b92008-09-09 01:06:48 +000049 typedef llvm::SmallVector<std::pair<RValue, QualType>, 16> CallArgList;
Daniel Dunbar0dbe2272008-09-08 21:33:45 +000050
Daniel Dunbar7c086512008-09-09 23:14:03 +000051 /// 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.
Mike Stump1eb44332009-09-09 15:08:12 +000054 typedef llvm::SmallVector<std::pair<const VarDecl*, QualType>,
Daniel Dunbar7c086512008-09-09 23:14:03 +000055 16> FunctionArgList;
Mike Stump1eb44332009-09-09 15:08:12 +000056
Daniel Dunbar0dbe2272008-09-08 21:33:45 +000057 /// CGFunctionInfo - Class to encapsulate the information about a
58 /// function definition.
Daniel Dunbar40a6be62009-02-03 00:07:12 +000059 class CGFunctionInfo : public llvm::FoldingSetNode {
Daniel Dunbar88c2fa92009-02-03 05:31:23 +000060 struct ArgInfo {
John McCallead608a2010-02-26 00:48:12 +000061 CanQualType type;
Daniel Dunbar88c2fa92009-02-03 05:31:23 +000062 ABIArgInfo info;
63 };
64
Daniel Dunbarca6408c2009-09-12 00:59:20 +000065 /// The LLVM::CallingConv to use for this function (as specified by the
66 /// user).
Daniel Dunbarbac7c252009-09-11 22:24:53 +000067 unsigned CallingConvention;
68
Daniel Dunbarca6408c2009-09-12 00:59:20 +000069 /// The LLVM::CallingConv to actually use for this function, which may
70 /// depend on the ABI.
71 unsigned EffectiveCallingConvention;
72
John McCall04a67a62010-02-05 21:31:56 +000073 /// Whether this function is noreturn.
74 bool NoReturn;
75
Daniel Dunbar88c2fa92009-02-03 05:31:23 +000076 unsigned NumArgs;
77 ArgInfo *Args;
Daniel Dunbar0dbe2272008-09-08 21:33:45 +000078
79 public:
Daniel Dunbar88c2fa92009-02-03 05:31:23 +000080 typedef const ArgInfo *const_arg_iterator;
81 typedef ArgInfo *arg_iterator;
Daniel Dunbara0a99e02009-02-02 23:43:58 +000082
Daniel Dunbarbac7c252009-09-11 22:24:53 +000083 CGFunctionInfo(unsigned CallingConvention,
John McCall04a67a62010-02-05 21:31:56 +000084 bool NoReturn,
John McCallead608a2010-02-26 00:48:12 +000085 CanQualType ResTy,
86 const llvm::SmallVectorImpl<CanQualType> &ArgTys);
Daniel Dunbar88c2fa92009-02-03 05:31:23 +000087 ~CGFunctionInfo() { delete[] Args; }
Daniel Dunbar0dbe2272008-09-08 21:33:45 +000088
Daniel Dunbar88c2fa92009-02-03 05:31:23 +000089 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; }
Daniel Dunbarbb36d332009-02-02 21:43:58 +000093
Daniel Dunbar4b5f0a42009-02-04 21:17:21 +000094 unsigned arg_size() const { return NumArgs; }
95
John McCall04a67a62010-02-05 21:31:56 +000096 bool isNoReturn() const { return NoReturn; }
97
Daniel Dunbarca6408c2009-09-12 00:59:20 +000098 /// getCallingConvention - Return the user specified calling
99 /// convention.
Daniel Dunbarbac7c252009-09-11 22:24:53 +0000100 unsigned getCallingConvention() const { return CallingConvention; }
101
Daniel Dunbarca6408c2009-09-12 00:59:20 +0000102 /// 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
John McCallead608a2010-02-26 00:48:12 +0000111 CanQualType getReturnType() const { return Args[0].type; }
Daniel Dunbar88c2fa92009-02-03 05:31:23 +0000112
113 ABIArgInfo &getReturnInfo() { return Args[0].info; }
114 const ABIArgInfo &getReturnInfo() const { return Args[0].info; }
Daniel Dunbar40a6be62009-02-03 00:07:12 +0000115
116 void Profile(llvm::FoldingSetNodeID &ID) {
Daniel Dunbarbac7c252009-09-11 22:24:53 +0000117 ID.AddInteger(getCallingConvention());
John McCall04a67a62010-02-05 21:31:56 +0000118 ID.AddBoolean(NoReturn);
Daniel Dunbar35e67d42009-02-05 00:00:23 +0000119 getReturnType().Profile(ID);
Daniel Dunbar88c2fa92009-02-03 05:31:23 +0000120 for (arg_iterator it = arg_begin(), ie = arg_end(); it != ie; ++it)
121 it->type.Profile(ID);
Daniel Dunbar40a6be62009-02-03 00:07:12 +0000122 }
123 template<class Iterator>
Mike Stump1eb44332009-09-09 15:08:12 +0000124 static void Profile(llvm::FoldingSetNodeID &ID,
Daniel Dunbarbac7c252009-09-11 22:24:53 +0000125 unsigned CallingConvention,
John McCall04a67a62010-02-05 21:31:56 +0000126 bool NoReturn,
John McCallead608a2010-02-26 00:48:12 +0000127 CanQualType ResTy,
Daniel Dunbar40a6be62009-02-03 00:07:12 +0000128 Iterator begin,
129 Iterator end) {
Daniel Dunbarbac7c252009-09-11 22:24:53 +0000130 ID.AddInteger(CallingConvention);
John McCall04a67a62010-02-05 21:31:56 +0000131 ID.AddBoolean(NoReturn);
Daniel Dunbar40a6be62009-02-03 00:07:12 +0000132 ResTy.Profile(ID);
John McCallead608a2010-02-26 00:48:12 +0000133 for (; begin != end; ++begin) {
134 CanQualType T = *begin; // force iterator to be over canonical types
135 T.Profile(ID);
136 }
Daniel Dunbar40a6be62009-02-03 00:07:12 +0000137 }
Daniel Dunbar0dbe2272008-09-08 21:33:45 +0000138 };
Anders Carlsson31777a22009-12-24 19:08:58 +0000139
Anders Carlssond2490a92009-12-24 20:40:36 +0000140 /// ReturnValueSlot - Contains the address where the return value of a
141 /// function can be stored, and whether the address is volatile or not.
Anders Carlsson31777a22009-12-24 19:08:58 +0000142 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
Daniel Dunbar0dbe2272008-09-08 21:33:45 +0000156} // end namespace CodeGen
157} // end namespace clang
158
159#endif