blob: 041d1df0b03d071b6460c2a6e82b6dd084ff6d84 [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
Daniel Dunbar88c2fa92009-02-03 05:31:23 +000072 unsigned NumArgs;
73 ArgInfo *Args;
Daniel Dunbar0dbe2272008-09-08 21:33:45 +000074
75 public:
Daniel Dunbar88c2fa92009-02-03 05:31:23 +000076 typedef const ArgInfo *const_arg_iterator;
77 typedef ArgInfo *arg_iterator;
Daniel Dunbara0a99e02009-02-02 23:43:58 +000078
Daniel Dunbarbac7c252009-09-11 22:24:53 +000079 CGFunctionInfo(unsigned CallingConvention,
80 QualType ResTy,
Daniel Dunbar541b63b2009-02-02 23:23:47 +000081 const llvm::SmallVector<QualType, 16> &ArgTys);
Daniel Dunbar88c2fa92009-02-03 05:31:23 +000082 ~CGFunctionInfo() { delete[] Args; }
Daniel Dunbar0dbe2272008-09-08 21:33:45 +000083
Daniel Dunbar88c2fa92009-02-03 05:31:23 +000084 const_arg_iterator arg_begin() const { return Args + 1; }
85 const_arg_iterator arg_end() const { return Args + 1 + NumArgs; }
86 arg_iterator arg_begin() { return Args + 1; }
87 arg_iterator arg_end() { return Args + 1 + NumArgs; }
Daniel Dunbarbb36d332009-02-02 21:43:58 +000088
Daniel Dunbar4b5f0a42009-02-04 21:17:21 +000089 unsigned arg_size() const { return NumArgs; }
90
Daniel Dunbarca6408c2009-09-12 00:59:20 +000091 /// getCallingConvention - Return the user specified calling
92 /// convention.
Daniel Dunbarbac7c252009-09-11 22:24:53 +000093 unsigned getCallingConvention() const { return CallingConvention; }
94
Daniel Dunbarca6408c2009-09-12 00:59:20 +000095 /// getEffectiveCallingConvention - Return the actual calling convention to
96 /// use, which may depend on the ABI.
97 unsigned getEffectiveCallingConvention() const {
98 return EffectiveCallingConvention;
99 }
100 void setEffectiveCallingConvention(unsigned Value) {
101 EffectiveCallingConvention = Value;
102 }
103
Daniel Dunbar88c2fa92009-02-03 05:31:23 +0000104 QualType getReturnType() const { return Args[0].type; }
105
106 ABIArgInfo &getReturnInfo() { return Args[0].info; }
107 const ABIArgInfo &getReturnInfo() const { return Args[0].info; }
Daniel Dunbar40a6be62009-02-03 00:07:12 +0000108
109 void Profile(llvm::FoldingSetNodeID &ID) {
Daniel Dunbarbac7c252009-09-11 22:24:53 +0000110 ID.AddInteger(getCallingConvention());
Daniel Dunbar35e67d42009-02-05 00:00:23 +0000111 getReturnType().Profile(ID);
Daniel Dunbar88c2fa92009-02-03 05:31:23 +0000112 for (arg_iterator it = arg_begin(), ie = arg_end(); it != ie; ++it)
113 it->type.Profile(ID);
Daniel Dunbar40a6be62009-02-03 00:07:12 +0000114 }
115 template<class Iterator>
Mike Stump1eb44332009-09-09 15:08:12 +0000116 static void Profile(llvm::FoldingSetNodeID &ID,
Daniel Dunbarbac7c252009-09-11 22:24:53 +0000117 unsigned CallingConvention,
Daniel Dunbar40a6be62009-02-03 00:07:12 +0000118 QualType ResTy,
119 Iterator begin,
120 Iterator end) {
Daniel Dunbarbac7c252009-09-11 22:24:53 +0000121 ID.AddInteger(CallingConvention);
Daniel Dunbar40a6be62009-02-03 00:07:12 +0000122 ResTy.Profile(ID);
123 for (; begin != end; ++begin)
124 begin->Profile(ID);
125 }
Daniel Dunbar0dbe2272008-09-08 21:33:45 +0000126 };
Anders Carlsson31777a22009-12-24 19:08:58 +0000127
128 class ReturnValueSlot {
129 llvm::PointerIntPair<llvm::Value *, 1, bool> Value;
130
131 public:
132 ReturnValueSlot() {}
133 ReturnValueSlot(llvm::Value *Value, bool IsVolatile)
134 : Value(Value, IsVolatile) {}
135
136 bool isNull() const { return !getValue(); }
137
138 bool isVolatile() const { return Value.getInt(); }
139 llvm::Value *getValue() const { return Value.getPointer(); }
140 };
141
Daniel Dunbar0dbe2272008-09-08 21:33:45 +0000142} // end namespace CodeGen
143} // end namespace clang
144
145#endif