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"
24 // FIXME: Restructure so we don't have to expose so much stuff.
28 struct AttributeWithIndex;
33 template<typename T, unsigned> class SmallVector;
44 typedef llvm::SmallVector<llvm::AttributeWithIndex, 8> AttributeListType;
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;
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>,
56 /// CGFunctionInfo - Class to encapsulate the information about a
57 /// function definition.
58 class CGFunctionInfo : public llvm::FoldingSetNode {
64 /// The LLVM::CallingConv to use for this function (as specified by the
66 unsigned CallingConvention;
68 /// The LLVM::CallingConv to actually use for this function, which may
69 /// depend on the ABI.
70 unsigned EffectiveCallingConvention;
76 typedef const ArgInfo *const_arg_iterator;
77 typedef ArgInfo *arg_iterator;
79 CGFunctionInfo(unsigned CallingConvention,
81 const llvm::SmallVector<QualType, 16> &ArgTys);
82 ~CGFunctionInfo() { delete[] Args; }
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; }
89 unsigned arg_size() const { return NumArgs; }
91 /// getCallingConvention - Return the user specified calling
93 unsigned getCallingConvention() const { return CallingConvention; }
95 /// getEffectiveCallingConvention - Return the actual calling convention to
96 /// use, which may depend on the ABI.
97 unsigned getEffectiveCallingConvention() const {
98 return EffectiveCallingConvention;
100 void setEffectiveCallingConvention(unsigned Value) {
101 EffectiveCallingConvention = Value;
104 QualType getReturnType() const { return Args[0].type; }
106 ABIArgInfo &getReturnInfo() { return Args[0].info; }
107 const ABIArgInfo &getReturnInfo() const { return Args[0].info; }
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);
115 template<class Iterator>
116 static void Profile(llvm::FoldingSetNodeID &ID,
117 unsigned CallingConvention,
121 ID.AddInteger(CallingConvention);
123 for (; begin != end; ++begin)
128 class ReturnValueSlot {
129 llvm::PointerIntPair<llvm::Value *, 1, bool> Value;
133 ReturnValueSlot(llvm::Value *Value, bool IsVolatile)
134 : Value(Value, IsVolatile) {}
136 bool isNull() const { return !getValue(); }
138 bool isVolatile() const { return Value.getInt(); }
139 llvm::Value *getValue() const { return Value.getPointer(); }
142 } // end namespace CodeGen
143 } // end namespace clang