blob: 9601e9ae9a27be8cf87c040811fe83dbdd24a41a [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"
21
Daniel Dunbar46f45b92008-09-09 01:06:48 +000022#include "CGValue.h"
23
Daniel Dunbar88c2fa92009-02-03 05:31:23 +000024// FIXME: Restructure so we don't have to expose so much stuff.
25#include "ABIInfo.h"
26
Daniel Dunbar0dbe2272008-09-08 21:33:45 +000027namespace llvm {
Devang Patel761d7f72008-09-25 21:02:23 +000028 struct AttributeWithIndex;
Daniel Dunbar88c2fa92009-02-03 05:31:23 +000029 class Function;
30 class Type;
Daniel Dunbar0dbe2272008-09-08 21:33:45 +000031 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;
Daniel Dunbar7c086512008-09-09 23:14:03 +000041 class VarDecl;
Daniel Dunbar0dbe2272008-09-08 21:33:45 +000042
43namespace CodeGen {
Devang Patel761d7f72008-09-25 21:02:23 +000044 typedef llvm::SmallVector<llvm::AttributeWithIndex, 8> AttributeListType;
Daniel Dunbar0dbe2272008-09-08 21:33:45 +000045
46 /// CallArgList - Type for representing both the value and type of
47 /// arguments in a call.
Daniel Dunbar46f45b92008-09-09 01:06:48 +000048 typedef llvm::SmallVector<std::pair<RValue, QualType>, 16> CallArgList;
Daniel Dunbar0dbe2272008-09-08 21:33:45 +000049
Daniel Dunbar7c086512008-09-09 23:14:03 +000050 /// 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.
Mike Stump1eb44332009-09-09 15:08:12 +000053 typedef llvm::SmallVector<std::pair<const VarDecl*, QualType>,
Daniel Dunbar7c086512008-09-09 23:14:03 +000054 16> FunctionArgList;
Mike Stump1eb44332009-09-09 15:08:12 +000055
Daniel Dunbar0dbe2272008-09-08 21:33:45 +000056 /// CGFunctionInfo - Class to encapsulate the information about a
57 /// function definition.
Daniel Dunbar40a6be62009-02-03 00:07:12 +000058 class CGFunctionInfo : public llvm::FoldingSetNode {
Daniel Dunbar88c2fa92009-02-03 05:31:23 +000059 struct ArgInfo {
60 QualType type;
61 ABIArgInfo info;
62 };
63
Daniel Dunbarca6408c2009-09-12 00:59:20 +000064 /// The LLVM::CallingConv to use for this function (as specified by the
65 /// user).
Daniel Dunbarbac7c252009-09-11 22:24:53 +000066 unsigned CallingConvention;
67
Daniel Dunbarca6408c2009-09-12 00:59:20 +000068 /// The LLVM::CallingConv to actually use for this function, which may
69 /// depend on the ABI.
70 unsigned EffectiveCallingConvention;
71
John McCall04a67a62010-02-05 21:31:56 +000072 /// Whether this function is noreturn.
73 bool NoReturn;
74
Daniel Dunbar88c2fa92009-02-03 05:31:23 +000075 unsigned NumArgs;
76 ArgInfo *Args;
Daniel Dunbar0dbe2272008-09-08 21:33:45 +000077
78 public:
Daniel Dunbar88c2fa92009-02-03 05:31:23 +000079 typedef const ArgInfo *const_arg_iterator;
80 typedef ArgInfo *arg_iterator;
Daniel Dunbara0a99e02009-02-02 23:43:58 +000081
Daniel Dunbarbac7c252009-09-11 22:24:53 +000082 CGFunctionInfo(unsigned CallingConvention,
John McCall04a67a62010-02-05 21:31:56 +000083 bool NoReturn,
Daniel Dunbarbac7c252009-09-11 22:24:53 +000084 QualType ResTy,
Daniel Dunbar541b63b2009-02-02 23:23:47 +000085 const llvm::SmallVector<QualType, 16> &ArgTys);
Daniel Dunbar88c2fa92009-02-03 05:31:23 +000086 ~CGFunctionInfo() { delete[] Args; }
Daniel Dunbar0dbe2272008-09-08 21:33:45 +000087
Daniel Dunbar88c2fa92009-02-03 05:31:23 +000088 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; }
Daniel Dunbarbb36d332009-02-02 21:43:58 +000092
Daniel Dunbar4b5f0a42009-02-04 21:17:21 +000093 unsigned arg_size() const { return NumArgs; }
94
John McCall04a67a62010-02-05 21:31:56 +000095 bool isNoReturn() const { return NoReturn; }
96
Daniel Dunbarca6408c2009-09-12 00:59:20 +000097 /// getCallingConvention - Return the user specified calling
98 /// convention.
Daniel Dunbarbac7c252009-09-11 22:24:53 +000099 unsigned getCallingConvention() const { return CallingConvention; }
100
Daniel Dunbarca6408c2009-09-12 00:59:20 +0000101 /// 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
Daniel Dunbar88c2fa92009-02-03 05:31:23 +0000110 QualType getReturnType() const { return Args[0].type; }
111
112 ABIArgInfo &getReturnInfo() { return Args[0].info; }
113 const ABIArgInfo &getReturnInfo() const { return Args[0].info; }
Daniel Dunbar40a6be62009-02-03 00:07:12 +0000114
115 void Profile(llvm::FoldingSetNodeID &ID) {
Daniel Dunbarbac7c252009-09-11 22:24:53 +0000116 ID.AddInteger(getCallingConvention());
John McCall04a67a62010-02-05 21:31:56 +0000117 ID.AddBoolean(NoReturn);
Daniel Dunbar35e67d42009-02-05 00:00:23 +0000118 getReturnType().Profile(ID);
Daniel Dunbar88c2fa92009-02-03 05:31:23 +0000119 for (arg_iterator it = arg_begin(), ie = arg_end(); it != ie; ++it)
120 it->type.Profile(ID);
Daniel Dunbar40a6be62009-02-03 00:07:12 +0000121 }
122 template<class Iterator>
Mike Stump1eb44332009-09-09 15:08:12 +0000123 static void Profile(llvm::FoldingSetNodeID &ID,
Daniel Dunbarbac7c252009-09-11 22:24:53 +0000124 unsigned CallingConvention,
John McCall04a67a62010-02-05 21:31:56 +0000125 bool NoReturn,
Daniel Dunbar40a6be62009-02-03 00:07:12 +0000126 QualType ResTy,
127 Iterator begin,
128 Iterator end) {
Daniel Dunbarbac7c252009-09-11 22:24:53 +0000129 ID.AddInteger(CallingConvention);
John McCall04a67a62010-02-05 21:31:56 +0000130 ID.AddBoolean(NoReturn);
Daniel Dunbar40a6be62009-02-03 00:07:12 +0000131 ResTy.Profile(ID);
132 for (; begin != end; ++begin)
133 begin->Profile(ID);
134 }
Daniel Dunbar0dbe2272008-09-08 21:33:45 +0000135 };
Anders Carlsson31777a22009-12-24 19:08:58 +0000136
Anders Carlssond2490a92009-12-24 20:40:36 +0000137 /// ReturnValueSlot - Contains the address where the return value of a
138 /// function can be stored, and whether the address is volatile or not.
Anders Carlsson31777a22009-12-24 19:08:58 +0000139 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
Daniel Dunbar0dbe2272008-09-08 21:33:45 +0000153} // end namespace CodeGen
154} // end namespace clang
155
156#endif