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.
49 typedef llvm::SmallVector<std::pair<RValue, QualType>, 16> CallArgList;
51 /// FunctionArgList - Type for representing both the decl and type
52 /// of parameters to a function. The decl must be either a
53 /// ParmVarDecl or ImplicitParamDecl.
54 typedef llvm::SmallVector<std::pair<const VarDecl*, QualType>,
57 /// CGFunctionInfo - Class to encapsulate the information about a
58 /// function definition.
59 class CGFunctionInfo : public llvm::FoldingSetNode {
65 /// The LLVM::CallingConv to use for this function (as specified by the
67 unsigned CallingConvention;
69 /// The LLVM::CallingConv to actually use for this function, which may
70 /// depend on the ABI.
71 unsigned EffectiveCallingConvention;
73 /// Whether this function is noreturn.
79 /// How many arguments to pass inreg.
83 typedef const ArgInfo *const_arg_iterator;
84 typedef ArgInfo *arg_iterator;
86 CGFunctionInfo(unsigned CallingConvention, bool NoReturn,
87 unsigned RegParm, CanQualType ResTy,
88 const CanQualType *ArgTys, unsigned NumArgTys);
89 ~CGFunctionInfo() { delete[] Args; }
91 const_arg_iterator arg_begin() const { return Args + 1; }
92 const_arg_iterator arg_end() const { return Args + 1 + NumArgs; }
93 arg_iterator arg_begin() { return Args + 1; }
94 arg_iterator arg_end() { return Args + 1 + NumArgs; }
96 unsigned arg_size() const { return NumArgs; }
98 bool isNoReturn() const { return NoReturn; }
100 /// getCallingConvention - Return the user specified calling
102 unsigned getCallingConvention() const { return CallingConvention; }
104 /// getEffectiveCallingConvention - Return the actual calling convention to
105 /// use, which may depend on the ABI.
106 unsigned getEffectiveCallingConvention() const {
107 return EffectiveCallingConvention;
109 void setEffectiveCallingConvention(unsigned Value) {
110 EffectiveCallingConvention = Value;
113 unsigned getRegParm() const { return RegParm; }
115 CanQualType getReturnType() const { return Args[0].type; }
117 ABIArgInfo &getReturnInfo() { return Args[0].info; }
118 const ABIArgInfo &getReturnInfo() const { return Args[0].info; }
120 void Profile(llvm::FoldingSetNodeID &ID) {
121 ID.AddInteger(getCallingConvention());
122 ID.AddBoolean(NoReturn);
123 ID.AddInteger(RegParm);
124 getReturnType().Profile(ID);
125 for (arg_iterator it = arg_begin(), ie = arg_end(); it != ie; ++it)
126 it->type.Profile(ID);
128 template<class Iterator>
129 static void Profile(llvm::FoldingSetNodeID &ID,
130 const FunctionType::ExtInfo &Info,
134 ID.AddInteger(Info.getCC());
135 ID.AddBoolean(Info.getNoReturn());
136 ID.AddInteger(Info.getRegParm());
138 for (; begin != end; ++begin) {
139 CanQualType T = *begin; // force iterator to be over canonical types
145 /// ReturnValueSlot - Contains the address where the return value of a
146 /// function can be stored, and whether the address is volatile or not.
147 class ReturnValueSlot {
148 llvm::PointerIntPair<llvm::Value *, 1, bool> Value;
152 ReturnValueSlot(llvm::Value *Value, bool IsVolatile)
153 : Value(Value, IsVolatile) {}
155 bool isNull() const { return !getValue(); }
157 bool isVolatile() const { return Value.getInt(); }
158 llvm::Value *getValue() const { return Value.getPointer(); }
161 } // end namespace CodeGen
162 } // end namespace clang