//===----- 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.
//
//===----------------------------------------------------------------------===//
#include "CGCall.h"
#include "CodeGenFunction.h"
#include "CodeGenModule.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclObjC.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Attributes.h"
#include "llvm/Support/CommandLine.h"
using namespace clang;
using namespace CodeGen;
static llvm::cl::opt<bool>
UseX86_64ABI("use-x86_64-abi",
llvm::cl::desc("Enable use of experimental x86_64 ABI."),
llvm::cl::init(false));
/***/
// FIXME: Use iterator and sidestep silly type array creation.
CGFunctionInfo::CGFunctionInfo(const FunctionTypeNoProto *FTNP)
: IsVariadic(true)
{
ArgTypes.push_back(FTNP->getResultType());
}
CGFunctionInfo::CGFunctionInfo(const FunctionTypeProto *FTP)
: IsVariadic(FTP->isVariadic())
{
ArgTypes.push_back(FTP->getResultType());
for (unsigned i = 0, e = FTP->getNumArgs(); i != e; ++i)
ArgTypes.push_back(FTP->getArgType(i));
}
// FIXME: Is there really any reason to have this still?
CGFunctionInfo::CGFunctionInfo(const FunctionDecl *FD)
{
const FunctionType *FTy = FD->getType()->getAsFunctionType();
const FunctionTypeProto *FTP = dyn_cast<FunctionTypeProto>(FTy);
ArgTypes.push_back(FTy->getResultType());
if (FTP) {
IsVariadic = FTP->isVariadic();
for (unsigned i = 0, e = FTP->getNumArgs(); i != e; ++i)
ArgTypes.push_back(FTP->getArgType(i));
} else {
IsVariadic = true;
}
}
CGFunctionInfo::CGFunctionInfo(const ObjCMethodDecl *MD,
const ASTContext &Context)
: IsVariadic(MD->isVariadic())
{
ArgTypes.push_back(MD->getResultType());
ArgTypes.push_back(MD->getSelfDecl()->getType());
ArgTypes.push_back(Context.getObjCSelType());
for (ObjCMethodDecl::param_const_iterator i = MD->param_begin(),
e = MD->param_end(); i != e; ++i)
ArgTypes.push_back((*i)->getType());
}
ArgTypeIterator CGFunctionInfo::argtypes_begin() const {
return ArgTypes.begin();
}
ArgTypeIterator CGFunctionInfo::argtypes_end() const {
return ArgTypes.end();
}
/***/
CGCallInfo::CGCallInfo(QualType _ResultType, const CallArgList &_Args) {
ArgTypes.push_back(_ResultType);
for (CallArgList::const_iterator i = _Args.begin(), e = _Args.end(); i!=e; ++i)
ArgTypes.push_back(i->second);
}
ArgTypeIterator CGCallInfo::argtypes_begin() const {
return ArgTypes.begin();
}
ArgTypeIterator CGCallInfo::argtypes_end() const {
return ArgTypes.end();
}
/***/
/// ABIArgInfo - Helper class to encapsulate information about how a
/// specific C type should be passed to or returned from a function.
class ABIArgInfo {
public:
enum Kind {
Default,
StructRet, /// Only valid for return values. The return value
/// should be passed through a pointer to a caller
/// allocated location passed as an implicit first
/// argument to the function.
Ignore, /// Ignore the argument (treat as void). Useful for
/// void and empty structs.
Coerce, /// Only valid for aggregate return types, the argument
/// should be accessed by coercion to a provided type.
ByVal, /// Only valid for aggregate argument types. The
/// structure should be passed "byval" with the
/// specified alignment (0 indicates default
/// alignment).
Expand, /// Only valid for aggregate argument types. The
/// structure should be expanded into consecutive
/// arguments for its constituent fields. Currently
/// expand is only allowed on structures whose fields
/// are all scalar types or are themselves expandable
/// types.
KindFirst=Default, KindLast=Expand
};
private