blob: 95e561d6f9ad17c799976725d7a77754ad5d48d7 [file] [log] [blame]
Daniel Dunbara8f02052008-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 Dunbardcf19d12009-02-03 00:07:12 +000018#include <llvm/ADT/FoldingSet.h>
Daniel Dunbara8f02052008-09-08 21:33:45 +000019#include "clang/AST/Type.h"
20
Daniel Dunbar0a2da0f2008-09-09 01:06:48 +000021#include "CGValue.h"
22
Daniel Dunbare92e0ab2009-02-03 05:31:23 +000023// FIXME: Restructure so we don't have to expose so much stuff.
24#include "ABIInfo.h"
25
Daniel Dunbara8f02052008-09-08 21:33:45 +000026namespace llvm {
Devang Patela85a9ef2008-09-25 21:02:23 +000027 struct AttributeWithIndex;
Daniel Dunbare92e0ab2009-02-03 05:31:23 +000028 class Function;
29 class Type;
Daniel Dunbara8f02052008-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 Dunbar96816832008-09-09 23:14:03 +000040 class VarDecl;
Daniel Dunbara8f02052008-09-08 21:33:45 +000041
42namespace CodeGen {
Devang Patela85a9ef2008-09-25 21:02:23 +000043 typedef llvm::SmallVector<llvm::AttributeWithIndex, 8> AttributeListType;
Daniel Dunbara8f02052008-09-08 21:33:45 +000044
45 /// CallArgList - Type for representing both the value and type of
46 /// arguments in a call.
Daniel Dunbar0a2da0f2008-09-09 01:06:48 +000047 typedef llvm::SmallVector<std::pair<RValue, QualType>, 16> CallArgList;
Daniel Dunbara8f02052008-09-08 21:33:45 +000048
Daniel Dunbar96816832008-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.
52 typedef llvm::SmallVector<std::pair<const VarDecl*, QualType>,
53 16> FunctionArgList;
Daniel Dunbarbccb0682008-09-10 00:32:18 +000054
Daniel Dunbara8f02052008-09-08 21:33:45 +000055 /// CGFunctionInfo - Class to encapsulate the information about a
56 /// function definition.
Daniel Dunbardcf19d12009-02-03 00:07:12 +000057 class CGFunctionInfo : public llvm::FoldingSetNode {
Daniel Dunbare92e0ab2009-02-03 05:31:23 +000058 struct ArgInfo {
59 QualType type;
60 ABIArgInfo info;
61 };
62
63 unsigned NumArgs;
64 ArgInfo *Args;
Daniel Dunbara8f02052008-09-08 21:33:45 +000065
66 public:
Daniel Dunbare92e0ab2009-02-03 05:31:23 +000067 typedef const ArgInfo *const_arg_iterator;
68 typedef ArgInfo *arg_iterator;
Daniel Dunbar0b37ca82009-02-02 23:43:58 +000069
Daniel Dunbar34bda882009-02-02 23:23:47 +000070 CGFunctionInfo(QualType ResTy,
71 const llvm::SmallVector<QualType, 16> &ArgTys);
Daniel Dunbare92e0ab2009-02-03 05:31:23 +000072 ~CGFunctionInfo() { delete[] Args; }
Daniel Dunbara8f02052008-09-08 21:33:45 +000073
Daniel Dunbare92e0ab2009-02-03 05:31:23 +000074 const_arg_iterator arg_begin() const { return Args + 1; }
75 const_arg_iterator arg_end() const { return Args + 1 + NumArgs; }
76 arg_iterator arg_begin() { return Args + 1; }
77 arg_iterator arg_end() { return Args + 1 + NumArgs; }
Daniel Dunbar9fc15a82009-02-02 21:43:58 +000078
Daniel Dunbare92e0ab2009-02-03 05:31:23 +000079 QualType getReturnType() const { return Args[0].type; }
80
81 ABIArgInfo &getReturnInfo() { return Args[0].info; }
82 const ABIArgInfo &getReturnInfo() const { return Args[0].info; }
Daniel Dunbardcf19d12009-02-03 00:07:12 +000083
84 void Profile(llvm::FoldingSetNodeID &ID) {
Daniel Dunbare92e0ab2009-02-03 05:31:23 +000085 for (arg_iterator it = arg_begin(), ie = arg_end(); it != ie; ++it)
86 it->type.Profile(ID);
Daniel Dunbardcf19d12009-02-03 00:07:12 +000087 }
88 template<class Iterator>
89 static void Profile(llvm::FoldingSetNodeID &ID,
90 QualType ResTy,
91 Iterator begin,
92 Iterator end) {
93 ResTy.Profile(ID);
94 for (; begin != end; ++begin)
95 begin->Profile(ID);
96 }
Daniel Dunbara8f02052008-09-08 21:33:45 +000097 };
Daniel Dunbara8f02052008-09-08 21:33:45 +000098} // end namespace CodeGen
99} // end namespace clang
100
101#endif