CGCall.h revision 201361
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
18#include "llvm/ADT/FoldingSet.h"
19#include "llvm/Value.h"
20#include "clang/AST/Type.h"
21
22#include "CGValue.h"
23
24// FIXME: Restructure so we don't have to expose so much stuff.
25#include "ABIInfo.h"
26
27namespace llvm {
28  struct AttributeWithIndex;
29  class Function;
30  class Type;
31  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;
41  class VarDecl;
42
43namespace CodeGen {
44  typedef llvm::SmallVector<llvm::AttributeWithIndex, 8> AttributeListType;
45
46  /// CallArgList - Type for representing both the value and type of
47  /// arguments in a call.
48  typedef llvm::SmallVector<std::pair<RValue, QualType>, 16> CallArgList;
49
50  /// 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.
53  typedef llvm::SmallVector<std::pair<const VarDecl*, QualType>,
54                            16> FunctionArgList;
55
56  /// CGFunctionInfo - Class to encapsulate the information about a
57  /// function definition.
58  class CGFunctionInfo : public llvm::FoldingSetNode {
59    struct ArgInfo {
60      QualType type;
61      ABIArgInfo info;
62    };
63
64    /// The LLVM::CallingConv to use for this function (as specified by the
65    /// user).
66    unsigned CallingConvention;
67
68    /// The LLVM::CallingConv to actually use for this function, which may
69    /// depend on the ABI.
70    unsigned EffectiveCallingConvention;
71
72    unsigned NumArgs;
73    ArgInfo *Args;
74
75  public:
76    typedef const ArgInfo *const_arg_iterator;
77    typedef ArgInfo *arg_iterator;
78
79    CGFunctionInfo(unsigned CallingConvention,
80                   QualType ResTy,
81                   const llvm::SmallVector<QualType, 16> &ArgTys);
82    ~CGFunctionInfo() { delete[] Args; }
83
84    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; }
88
89    unsigned  arg_size() const { return NumArgs; }
90
91    /// getCallingConvention - Return the user specified calling
92    /// convention.
93    unsigned getCallingConvention() const { return CallingConvention; }
94
95    /// 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
104    QualType getReturnType() const { return Args[0].type; }
105
106    ABIArgInfo &getReturnInfo() { return Args[0].info; }
107    const ABIArgInfo &getReturnInfo() const { return Args[0].info; }
108
109    void Profile(llvm::FoldingSetNodeID &ID) {
110      ID.AddInteger(getCallingConvention());
111      getReturnType().Profile(ID);
112      for (arg_iterator it = arg_begin(), ie = arg_end(); it != ie; ++it)
113        it->type.Profile(ID);
114    }
115    template<class Iterator>
116    static void Profile(llvm::FoldingSetNodeID &ID,
117                        unsigned CallingConvention,
118                        QualType ResTy,
119                        Iterator begin,
120                        Iterator end) {
121      ID.AddInteger(CallingConvention);
122      ResTy.Profile(ID);
123      for (; begin != end; ++begin)
124        begin->Profile(ID);
125    }
126  };
127
128  /// ReturnValueSlot - Contains the address where the return value of a
129  /// function can be stored, and whether the address is volatile or not.
130  class ReturnValueSlot {
131    llvm::PointerIntPair<llvm::Value *, 1, bool> Value;
132
133  public:
134    ReturnValueSlot() {}
135    ReturnValueSlot(llvm::Value *Value, bool IsVolatile)
136      : Value(Value, IsVolatile) {}
137
138    bool isNull() const { return !getValue(); }
139
140    bool isVolatile() const { return Value.getInt(); }
141    llvm::Value *getValue() const { return Value.getPointer(); }
142  };
143
144}  // end namespace CodeGen
145}  // end namespace clang
146
147#endif
148