2008-09-09 01:33:45 +04:00
|
|
|
//===----- CGCall.h - Encapsulate calling convention details ----*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// These classes wrap the information about a call or function
|
|
|
|
// definition used to handle ABI compliancy.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef CLANG_CODEGEN_CGCALL_H
|
|
|
|
#define CLANG_CODEGEN_CGCALL_H
|
|
|
|
|
2009-12-24 22:08:58 +03:00
|
|
|
#include "llvm/ADT/FoldingSet.h"
|
|
|
|
#include "llvm/Value.h"
|
2008-09-09 01:33:45 +04:00
|
|
|
#include "clang/AST/Type.h"
|
2010-02-26 03:48:12 +03:00
|
|
|
#include "clang/AST/CanonicalType.h"
|
2008-09-09 01:33:45 +04:00
|
|
|
|
2008-09-09 05:06:48 +04:00
|
|
|
#include "CGValue.h"
|
|
|
|
|
2009-02-03 08:31:23 +03:00
|
|
|
// FIXME: Restructure so we don't have to expose so much stuff.
|
|
|
|
#include "ABIInfo.h"
|
|
|
|
|
2008-09-09 01:33:45 +04:00
|
|
|
namespace llvm {
|
2008-09-26 01:02:23 +04:00
|
|
|
struct AttributeWithIndex;
|
2009-02-03 08:31:23 +03:00
|
|
|
class Function;
|
|
|
|
class Type;
|
2008-09-09 01:33:45 +04:00
|
|
|
class Value;
|
|
|
|
|
|
|
|
template<typename T, unsigned> class SmallVector;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
class ASTContext;
|
|
|
|
class Decl;
|
|
|
|
class FunctionDecl;
|
|
|
|
class ObjCMethodDecl;
|
2008-09-10 03:14:03 +04:00
|
|
|
class VarDecl;
|
2008-09-09 01:33:45 +04:00
|
|
|
|
|
|
|
namespace CodeGen {
|
2008-09-26 01:02:23 +04:00
|
|
|
typedef llvm::SmallVector<llvm::AttributeWithIndex, 8> AttributeListType;
|
2008-09-09 01:33:45 +04:00
|
|
|
|
|
|
|
/// CallArgList - Type for representing both the value and type of
|
|
|
|
/// arguments in a call.
|
2008-09-09 05:06:48 +04:00
|
|
|
typedef llvm::SmallVector<std::pair<RValue, QualType>, 16> CallArgList;
|
2008-09-09 01:33:45 +04:00
|
|
|
|
2008-09-10 03:14:03 +04:00
|
|
|
/// FunctionArgList - Type for representing both the decl and type
|
|
|
|
/// of parameters to a function. The decl must be either a
|
|
|
|
/// ParmVarDecl or ImplicitParamDecl.
|
2009-09-09 19:08:12 +04:00
|
|
|
typedef llvm::SmallVector<std::pair<const VarDecl*, QualType>,
|
2008-09-10 03:14:03 +04:00
|
|
|
16> FunctionArgList;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2008-09-09 01:33:45 +04:00
|
|
|
/// CGFunctionInfo - Class to encapsulate the information about a
|
|
|
|
/// function definition.
|
2009-02-03 03:07:12 +03:00
|
|
|
class CGFunctionInfo : public llvm::FoldingSetNode {
|
2009-02-03 08:31:23 +03:00
|
|
|
struct ArgInfo {
|
2010-02-26 03:48:12 +03:00
|
|
|
CanQualType type;
|
2009-02-03 08:31:23 +03:00
|
|
|
ABIArgInfo info;
|
|
|
|
};
|
|
|
|
|
2009-09-12 04:59:20 +04:00
|
|
|
/// The LLVM::CallingConv to use for this function (as specified by the
|
|
|
|
/// user).
|
2009-09-12 02:24:53 +04:00
|
|
|
unsigned CallingConvention;
|
|
|
|
|
2009-09-12 04:59:20 +04:00
|
|
|
/// The LLVM::CallingConv to actually use for this function, which may
|
|
|
|
/// depend on the ABI.
|
|
|
|
unsigned EffectiveCallingConvention;
|
|
|
|
|
2010-02-06 00:31:56 +03:00
|
|
|
/// Whether this function is noreturn.
|
|
|
|
bool NoReturn;
|
|
|
|
|
2009-02-03 08:31:23 +03:00
|
|
|
unsigned NumArgs;
|
|
|
|
ArgInfo *Args;
|
2008-09-09 01:33:45 +04:00
|
|
|
|
2010-03-31 02:15:11 +04:00
|
|
|
/// How many arguments to pass inreg.
|
|
|
|
unsigned RegParm;
|
|
|
|
|
2008-09-09 01:33:45 +04:00
|
|
|
public:
|
2009-02-03 08:31:23 +03:00
|
|
|
typedef const ArgInfo *const_arg_iterator;
|
|
|
|
typedef ArgInfo *arg_iterator;
|
2009-02-03 02:43:58 +03:00
|
|
|
|
2010-06-29 22:13:52 +04:00
|
|
|
CGFunctionInfo(unsigned CallingConvention, bool NoReturn,
|
|
|
|
unsigned RegParm, CanQualType ResTy,
|
|
|
|
const CanQualType *ArgTys, unsigned NumArgTys);
|
2009-02-03 08:31:23 +03:00
|
|
|
~CGFunctionInfo() { delete[] Args; }
|
|
|
|
|
|
|
|
const_arg_iterator arg_begin() const { return Args + 1; }
|
|
|
|
const_arg_iterator arg_end() const { return Args + 1 + NumArgs; }
|
|
|
|
arg_iterator arg_begin() { return Args + 1; }
|
|
|
|
arg_iterator arg_end() { return Args + 1 + NumArgs; }
|
2008-09-09 01:33:45 +04:00
|
|
|
|
2009-02-05 00:17:21 +03:00
|
|
|
unsigned arg_size() const { return NumArgs; }
|
|
|
|
|
2010-02-06 00:31:56 +03:00
|
|
|
bool isNoReturn() const { return NoReturn; }
|
|
|
|
|
2009-09-12 04:59:20 +04:00
|
|
|
/// getCallingConvention - Return the user specified calling
|
|
|
|
/// convention.
|
2009-09-12 02:24:53 +04:00
|
|
|
unsigned getCallingConvention() const { return CallingConvention; }
|
|
|
|
|
2009-09-12 04:59:20 +04:00
|
|
|
/// getEffectiveCallingConvention - Return the actual calling convention to
|
|
|
|
/// use, which may depend on the ABI.
|
|
|
|
unsigned getEffectiveCallingConvention() const {
|
|
|
|
return EffectiveCallingConvention;
|
|
|
|
}
|
|
|
|
void setEffectiveCallingConvention(unsigned Value) {
|
|
|
|
EffectiveCallingConvention = Value;
|
|
|
|
}
|
|
|
|
|
2010-03-31 02:15:11 +04:00
|
|
|
unsigned getRegParm() const { return RegParm; }
|
|
|
|
|
2010-02-26 03:48:12 +03:00
|
|
|
CanQualType getReturnType() const { return Args[0].type; }
|
2009-02-03 00:43:58 +03:00
|
|
|
|
2009-02-03 08:31:23 +03:00
|
|
|
ABIArgInfo &getReturnInfo() { return Args[0].info; }
|
|
|
|
const ABIArgInfo &getReturnInfo() const { return Args[0].info; }
|
2009-02-03 03:07:12 +03:00
|
|
|
|
|
|
|
void Profile(llvm::FoldingSetNodeID &ID) {
|
2009-09-12 02:24:53 +04:00
|
|
|
ID.AddInteger(getCallingConvention());
|
2010-02-06 00:31:56 +03:00
|
|
|
ID.AddBoolean(NoReturn);
|
2010-03-31 02:15:11 +04:00
|
|
|
ID.AddInteger(RegParm);
|
2009-02-05 03:00:23 +03:00
|
|
|
getReturnType().Profile(ID);
|
2009-02-03 08:31:23 +03:00
|
|
|
for (arg_iterator it = arg_begin(), ie = arg_end(); it != ie; ++it)
|
|
|
|
it->type.Profile(ID);
|
2009-02-03 03:07:12 +03:00
|
|
|
}
|
|
|
|
template<class Iterator>
|
2009-09-09 19:08:12 +04:00
|
|
|
static void Profile(llvm::FoldingSetNodeID &ID,
|
2010-03-31 00:24:48 +04:00
|
|
|
const FunctionType::ExtInfo &Info,
|
2010-02-26 03:48:12 +03:00
|
|
|
CanQualType ResTy,
|
2009-02-03 03:07:12 +03:00
|
|
|
Iterator begin,
|
|
|
|
Iterator end) {
|
2010-03-31 00:24:48 +04:00
|
|
|
ID.AddInteger(Info.getCC());
|
|
|
|
ID.AddBoolean(Info.getNoReturn());
|
2010-03-31 02:15:11 +04:00
|
|
|
ID.AddInteger(Info.getRegParm());
|
2009-02-03 03:07:12 +03:00
|
|
|
ResTy.Profile(ID);
|
2010-02-26 03:48:12 +03:00
|
|
|
for (; begin != end; ++begin) {
|
|
|
|
CanQualType T = *begin; // force iterator to be over canonical types
|
|
|
|
T.Profile(ID);
|
|
|
|
}
|
2009-02-03 03:07:12 +03:00
|
|
|
}
|
2008-09-09 01:33:45 +04:00
|
|
|
};
|
2009-12-24 22:08:58 +03:00
|
|
|
|
2009-12-24 23:40:36 +03:00
|
|
|
/// ReturnValueSlot - Contains the address where the return value of a
|
|
|
|
/// function can be stored, and whether the address is volatile or not.
|
2009-12-24 22:08:58 +03:00
|
|
|
class ReturnValueSlot {
|
|
|
|
llvm::PointerIntPair<llvm::Value *, 1, bool> Value;
|
|
|
|
|
|
|
|
public:
|
|
|
|
ReturnValueSlot() {}
|
|
|
|
ReturnValueSlot(llvm::Value *Value, bool IsVolatile)
|
|
|
|
: Value(Value, IsVolatile) {}
|
|
|
|
|
|
|
|
bool isNull() const { return !getValue(); }
|
|
|
|
|
|
|
|
bool isVolatile() const { return Value.getInt(); }
|
|
|
|
llvm::Value *getValue() const { return Value.getPointer(); }
|
|
|
|
};
|
|
|
|
|
2008-09-09 01:33:45 +04:00
|
|
|
} // end namespace CodeGen
|
|
|
|
} // end namespace clang
|
|
|
|
|
|
|
|
#endif
|