1 //===----- CGCall.h - Encapsulate calling convention details ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // These classes wrap the information about a call or function
11 // definition used to handle ABI compliancy.
13 //===----------------------------------------------------------------------===//
15 #ifndef CLANG_CODEGEN_CGCALL_H
16 #define CLANG_CODEGEN_CGCALL_H
18 #include "llvm/ADT/FoldingSet.h"
19 #include "llvm/Value.h"
20 #include "clang/AST/Type.h"
21 #include "clang/AST/CanonicalType.h"
25 // FIXME: Restructure so we don't have to expose so much stuff.
29 struct AttributeWithIndex;
34 template<typename T, unsigned> class SmallVector;
45 typedef llvm::SmallVector<llvm::AttributeWithIndex, 8> AttributeListType;
47 /// CallArgList - Type for representing both the value and type of
48 /// arguments in a call.
50 public llvm::SmallVector<std::pair<RValue, QualType>, 16> {
52 void add(RValue rvalue, QualType type) {
53 push_back(std::pair<RValue,QualType>(rvalue,type));
57 /// FunctionArgList - Type for representing both the decl and type
58 /// of parameters to a function. The decl must be either a
59 /// ParmVarDecl or ImplicitParamDecl.
60 class FunctionArgList : public llvm::SmallVector<const VarDecl*, 16> {
63 /// CGFunctionInfo - Class to encapsulate the information about a
64 /// function definition.
65 class CGFunctionInfo : public llvm::FoldingSetNode {
71 /// The LLVM::CallingConv to use for this function (as specified by the
73 unsigned CallingConvention;
75 /// The LLVM::CallingConv to actually use for this function, which may
76 /// depend on the ABI.
77 unsigned EffectiveCallingConvention;
79 /// Whether this function is noreturn.
85 /// How many arguments to pass inreg.
89 typedef const ArgInfo *const_arg_iterator;
90 typedef ArgInfo *arg_iterator;
92 CGFunctionInfo(unsigned CallingConvention, bool NoReturn,
93 unsigned RegParm, CanQualType ResTy,
94 const CanQualType *ArgTys, unsigned NumArgTys);
95 ~CGFunctionInfo() { delete[] Args; }
97 const_arg_iterator arg_begin() const { return Args + 1; }
98 const_arg_iterator arg_end() const { return Args + 1 + NumArgs; }
99 arg_iterator arg_begin() { return Args + 1; }
100 arg_iterator arg_end() { return Args + 1 + NumArgs; }
102 unsigned arg_size() const { return NumArgs; }
104 bool isNoReturn() const { return NoReturn; }
106 /// getCallingConvention - Return the user specified calling
108 unsigned getCallingConvention() const { return CallingConvention; }
110 /// getEffectiveCallingConvention - Return the actual calling convention to
111 /// use, which may depend on the ABI.
112 unsigned getEffectiveCallingConvention() const {
113 return EffectiveCallingConvention;
115 void setEffectiveCallingConvention(unsigned Value) {
116 EffectiveCallingConvention = Value;
119 unsigned getRegParm() const { return RegParm; }
121 CanQualType getReturnType() const { return Args[0].type; }
123 ABIArgInfo &getReturnInfo() { return Args[0].info; }
124 const ABIArgInfo &getReturnInfo() const { return Args[0].info; }
126 void Profile(llvm::FoldingSetNodeID &ID) {
127 ID.AddInteger(getCallingConvention());
128 ID.AddBoolean(NoReturn);
129 ID.AddInteger(RegParm);
130 getReturnType().Profile(ID);
131 for (arg_iterator it = arg_begin(), ie = arg_end(); it != ie; ++it)
132 it->type.Profile(ID);
134 template<class Iterator>
135 static void Profile(llvm::FoldingSetNodeID &ID,
136 const FunctionType::ExtInfo &Info,
140 ID.AddInteger(Info.getCC());
141 ID.AddBoolean(Info.getNoReturn());
142 ID.AddInteger(Info.getRegParm());
144 for (; begin != end; ++begin) {
145 CanQualType T = *begin; // force iterator to be over canonical types
151 /// ReturnValueSlot - Contains the address where the return value of a
152 /// function can be stored, and whether the address is volatile or not.
153 class ReturnValueSlot {
154 llvm::PointerIntPair<llvm::Value *, 1, bool> Value;
158 ReturnValueSlot(llvm::Value *Value, bool IsVolatile)
159 : Value(Value, IsVolatile) {}
161 bool isNull() const { return !getValue(); }
163 bool isVolatile() const { return Value.getInt(); }
164 llvm::Value *getValue() const { return Value.getPointer(); }
167 } // end namespace CodeGen
168 } // end namespace clang