blob: 53432a2a9efd470da33f245f22498b0a6dcdcbbd [file] [log] [blame]
Daniel Dunbar3d7c90b2008-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 Dunbare0be8292009-02-03 00:07:12 +000018#include <llvm/ADT/FoldingSet.h>
Daniel Dunbar3d7c90b2008-09-08 21:33:45 +000019#include "clang/AST/Type.h"
20
Daniel Dunbar41cf9de2008-09-09 01:06:48 +000021#include "CGValue.h"
22
Daniel Dunbar313321e2009-02-03 05:31:23 +000023// FIXME: Restructure so we don't have to expose so much stuff.
24#include "ABIInfo.h"
25
Daniel Dunbar3d7c90b2008-09-08 21:33:45 +000026namespace llvm {
Devang Patel322300d2008-09-25 21:02:23 +000027 struct AttributeWithIndex;
Daniel Dunbar313321e2009-02-03 05:31:23 +000028 class Function;
29 class Type;
Daniel Dunbar3d7c90b2008-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 Dunbarbc915f42008-09-09 23:14:03 +000040 class VarDecl;
Daniel Dunbar3d7c90b2008-09-08 21:33:45 +000041
42namespace CodeGen {
Devang Patel322300d2008-09-25 21:02:23 +000043 typedef llvm::SmallVector<llvm::AttributeWithIndex, 8> AttributeListType;
Daniel Dunbar3d7c90b2008-09-08 21:33:45 +000044
45 /// CallArgList - Type for representing both the value and type of
46 /// arguments in a call.
Daniel Dunbar41cf9de2008-09-09 01:06:48 +000047 typedef llvm::SmallVector<std::pair<RValue, QualType>, 16> CallArgList;
Daniel Dunbar3d7c90b2008-09-08 21:33:45 +000048
Daniel Dunbarbc915f42008-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 Stump11289f42009-09-09 15:08:12 +000052 typedef llvm::SmallVector<std::pair<const VarDecl*, QualType>,
Daniel Dunbarbc915f42008-09-09 23:14:03 +000053 16> FunctionArgList;
Mike Stump11289f42009-09-09 15:08:12 +000054
Daniel Dunbar3d7c90b2008-09-08 21:33:45 +000055 /// CGFunctionInfo - Class to encapsulate the information about a
56 /// function definition.
Daniel Dunbare0be8292009-02-03 00:07:12 +000057 class CGFunctionInfo : public llvm::FoldingSetNode {
Daniel Dunbar313321e2009-02-03 05:31:23 +000058 struct ArgInfo {
59 QualType type;
60 ABIArgInfo info;
61 };
62
Daniel Dunbar7feafc72009-09-11 22:24:53 +000063 /// The LLVM::CallingConv to use for this function.
64 unsigned CallingConvention;
65
Daniel Dunbar313321e2009-02-03 05:31:23 +000066 unsigned NumArgs;
67 ArgInfo *Args;
Daniel Dunbar3d7c90b2008-09-08 21:33:45 +000068
69 public:
Daniel Dunbar313321e2009-02-03 05:31:23 +000070 typedef const ArgInfo *const_arg_iterator;
71 typedef ArgInfo *arg_iterator;
Daniel Dunbar3668cb22009-02-02 23:43:58 +000072
Daniel Dunbar7feafc72009-09-11 22:24:53 +000073 CGFunctionInfo(unsigned CallingConvention,
74 QualType ResTy,
Daniel Dunbarbf8c24a2009-02-02 23:23:47 +000075 const llvm::SmallVector<QualType, 16> &ArgTys);
Daniel Dunbar313321e2009-02-03 05:31:23 +000076 ~CGFunctionInfo() { delete[] Args; }
Daniel Dunbar3d7c90b2008-09-08 21:33:45 +000077
Daniel Dunbar313321e2009-02-03 05:31:23 +000078 const_arg_iterator arg_begin() const { return Args + 1; }
79 const_arg_iterator arg_end() const { return Args + 1 + NumArgs; }
80 arg_iterator arg_begin() { return Args + 1; }
81 arg_iterator arg_end() { return Args + 1 + NumArgs; }
Daniel Dunbar7633cbf2009-02-02 21:43:58 +000082
Daniel Dunbara45bdbb2009-02-04 21:17:21 +000083 unsigned arg_size() const { return NumArgs; }
84
Daniel Dunbar7feafc72009-09-11 22:24:53 +000085 unsigned getCallingConvention() const { return CallingConvention; }
86
Daniel Dunbar313321e2009-02-03 05:31:23 +000087 QualType getReturnType() const { return Args[0].type; }
88
89 ABIArgInfo &getReturnInfo() { return Args[0].info; }
90 const ABIArgInfo &getReturnInfo() const { return Args[0].info; }
Daniel Dunbare0be8292009-02-03 00:07:12 +000091
92 void Profile(llvm::FoldingSetNodeID &ID) {
Daniel Dunbar7feafc72009-09-11 22:24:53 +000093 ID.AddInteger(getCallingConvention());
Daniel Dunbarfff09f32009-02-05 00:00:23 +000094 getReturnType().Profile(ID);
Daniel Dunbar313321e2009-02-03 05:31:23 +000095 for (arg_iterator it = arg_begin(), ie = arg_end(); it != ie; ++it)
96 it->type.Profile(ID);
Daniel Dunbare0be8292009-02-03 00:07:12 +000097 }
98 template<class Iterator>
Mike Stump11289f42009-09-09 15:08:12 +000099 static void Profile(llvm::FoldingSetNodeID &ID,
Daniel Dunbar7feafc72009-09-11 22:24:53 +0000100 unsigned CallingConvention,
Daniel Dunbare0be8292009-02-03 00:07:12 +0000101 QualType ResTy,
102 Iterator begin,
103 Iterator end) {
Daniel Dunbar7feafc72009-09-11 22:24:53 +0000104 ID.AddInteger(CallingConvention);
Daniel Dunbare0be8292009-02-03 00:07:12 +0000105 ResTy.Profile(ID);
106 for (; begin != end; ++begin)
107 begin->Profile(ID);
108 }
Daniel Dunbar3d7c90b2008-09-08 21:33:45 +0000109 };
Daniel Dunbar3d7c90b2008-09-08 21:33:45 +0000110} // end namespace CodeGen
111} // end namespace clang
112
113#endif