Daniel Dunbar | 0dbe227 | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 1 | //===----- 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 Dunbar | 40a6be6 | 2009-02-03 00:07:12 +0000 | [diff] [blame] | 18 | #include <llvm/ADT/FoldingSet.h> |
Daniel Dunbar | 0dbe227 | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 19 | #include "clang/AST/Type.h" |
| 20 | |
Daniel Dunbar | 46f45b9 | 2008-09-09 01:06:48 +0000 | [diff] [blame] | 21 | #include "CGValue.h" |
| 22 | |
Daniel Dunbar | 88c2fa9 | 2009-02-03 05:31:23 +0000 | [diff] [blame] | 23 | // FIXME: Restructure so we don't have to expose so much stuff. |
| 24 | #include "ABIInfo.h" |
| 25 | |
Daniel Dunbar | 0dbe227 | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 26 | namespace llvm { |
Devang Patel | 761d7f7 | 2008-09-25 21:02:23 +0000 | [diff] [blame] | 27 | struct AttributeWithIndex; |
Daniel Dunbar | 88c2fa9 | 2009-02-03 05:31:23 +0000 | [diff] [blame] | 28 | class Function; |
| 29 | class Type; |
Daniel Dunbar | 0dbe227 | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 30 | class Value; |
| 31 | |
| 32 | template<typename T, unsigned> class SmallVector; |
| 33 | } |
| 34 | |
| 35 | namespace clang { |
| 36 | class ASTContext; |
| 37 | class Decl; |
| 38 | class FunctionDecl; |
| 39 | class ObjCMethodDecl; |
Daniel Dunbar | 7c08651 | 2008-09-09 23:14:03 +0000 | [diff] [blame] | 40 | class VarDecl; |
Daniel Dunbar | 0dbe227 | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 41 | |
| 42 | namespace CodeGen { |
Devang Patel | 761d7f7 | 2008-09-25 21:02:23 +0000 | [diff] [blame] | 43 | typedef llvm::SmallVector<llvm::AttributeWithIndex, 8> AttributeListType; |
Daniel Dunbar | 0dbe227 | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 44 | |
| 45 | /// CallArgList - Type for representing both the value and type of |
| 46 | /// arguments in a call. |
Daniel Dunbar | 46f45b9 | 2008-09-09 01:06:48 +0000 | [diff] [blame] | 47 | typedef llvm::SmallVector<std::pair<RValue, QualType>, 16> CallArgList; |
Daniel Dunbar | 0dbe227 | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 48 | |
Daniel Dunbar | 7c08651 | 2008-09-09 23:14:03 +0000 | [diff] [blame] | 49 | /// 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 Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 52 | typedef llvm::SmallVector<std::pair<const VarDecl*, QualType>, |
Daniel Dunbar | 7c08651 | 2008-09-09 23:14:03 +0000 | [diff] [blame] | 53 | 16> FunctionArgList; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 54 | |
Daniel Dunbar | 0dbe227 | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 55 | /// CGFunctionInfo - Class to encapsulate the information about a |
| 56 | /// function definition. |
Daniel Dunbar | 40a6be6 | 2009-02-03 00:07:12 +0000 | [diff] [blame] | 57 | class CGFunctionInfo : public llvm::FoldingSetNode { |
Daniel Dunbar | 88c2fa9 | 2009-02-03 05:31:23 +0000 | [diff] [blame] | 58 | struct ArgInfo { |
| 59 | QualType type; |
| 60 | ABIArgInfo info; |
| 61 | }; |
| 62 | |
Daniel Dunbar | bac7c25 | 2009-09-11 22:24:53 +0000 | [diff] [blame^] | 63 | /// The LLVM::CallingConv to use for this function. |
| 64 | unsigned CallingConvention; |
| 65 | |
Daniel Dunbar | 88c2fa9 | 2009-02-03 05:31:23 +0000 | [diff] [blame] | 66 | unsigned NumArgs; |
| 67 | ArgInfo *Args; |
Daniel Dunbar | 0dbe227 | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 68 | |
| 69 | public: |
Daniel Dunbar | 88c2fa9 | 2009-02-03 05:31:23 +0000 | [diff] [blame] | 70 | typedef const ArgInfo *const_arg_iterator; |
| 71 | typedef ArgInfo *arg_iterator; |
Daniel Dunbar | a0a99e0 | 2009-02-02 23:43:58 +0000 | [diff] [blame] | 72 | |
Daniel Dunbar | bac7c25 | 2009-09-11 22:24:53 +0000 | [diff] [blame^] | 73 | CGFunctionInfo(unsigned CallingConvention, |
| 74 | QualType ResTy, |
Daniel Dunbar | 541b63b | 2009-02-02 23:23:47 +0000 | [diff] [blame] | 75 | const llvm::SmallVector<QualType, 16> &ArgTys); |
Daniel Dunbar | 88c2fa9 | 2009-02-03 05:31:23 +0000 | [diff] [blame] | 76 | ~CGFunctionInfo() { delete[] Args; } |
Daniel Dunbar | 0dbe227 | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 77 | |
Daniel Dunbar | 88c2fa9 | 2009-02-03 05:31:23 +0000 | [diff] [blame] | 78 | 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 Dunbar | bb36d33 | 2009-02-02 21:43:58 +0000 | [diff] [blame] | 82 | |
Daniel Dunbar | 4b5f0a4 | 2009-02-04 21:17:21 +0000 | [diff] [blame] | 83 | unsigned arg_size() const { return NumArgs; } |
| 84 | |
Daniel Dunbar | bac7c25 | 2009-09-11 22:24:53 +0000 | [diff] [blame^] | 85 | unsigned getCallingConvention() const { return CallingConvention; } |
| 86 | |
Daniel Dunbar | 88c2fa9 | 2009-02-03 05:31:23 +0000 | [diff] [blame] | 87 | 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 Dunbar | 40a6be6 | 2009-02-03 00:07:12 +0000 | [diff] [blame] | 91 | |
| 92 | void Profile(llvm::FoldingSetNodeID &ID) { |
Daniel Dunbar | bac7c25 | 2009-09-11 22:24:53 +0000 | [diff] [blame^] | 93 | ID.AddInteger(getCallingConvention()); |
Daniel Dunbar | 35e67d4 | 2009-02-05 00:00:23 +0000 | [diff] [blame] | 94 | getReturnType().Profile(ID); |
Daniel Dunbar | 88c2fa9 | 2009-02-03 05:31:23 +0000 | [diff] [blame] | 95 | for (arg_iterator it = arg_begin(), ie = arg_end(); it != ie; ++it) |
| 96 | it->type.Profile(ID); |
Daniel Dunbar | 40a6be6 | 2009-02-03 00:07:12 +0000 | [diff] [blame] | 97 | } |
| 98 | template<class Iterator> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 99 | static void Profile(llvm::FoldingSetNodeID &ID, |
Daniel Dunbar | bac7c25 | 2009-09-11 22:24:53 +0000 | [diff] [blame^] | 100 | unsigned CallingConvention, |
Daniel Dunbar | 40a6be6 | 2009-02-03 00:07:12 +0000 | [diff] [blame] | 101 | QualType ResTy, |
| 102 | Iterator begin, |
| 103 | Iterator end) { |
Daniel Dunbar | bac7c25 | 2009-09-11 22:24:53 +0000 | [diff] [blame^] | 104 | ID.AddInteger(CallingConvention); |
Daniel Dunbar | 40a6be6 | 2009-02-03 00:07:12 +0000 | [diff] [blame] | 105 | ResTy.Profile(ID); |
| 106 | for (; begin != end; ++begin) |
| 107 | begin->Profile(ID); |
| 108 | } |
Daniel Dunbar | 0dbe227 | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 109 | }; |
Daniel Dunbar | 0dbe227 | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 110 | } // end namespace CodeGen |
| 111 | } // end namespace clang |
| 112 | |
| 113 | #endif |