2010-01-10 20:58:08 +08:00
|
|
|
//===---- TargetInfo.cpp - Encapsulate target details -----------*- C++ -*-===//
|
2009-06-06 06:08:42 +08:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-01-10 20:58:08 +08:00
|
|
|
#include "TargetInfo.h"
|
2009-06-06 06:08:42 +08:00
|
|
|
#include "ABIInfo.h"
|
|
|
|
#include "CodeGenFunction.h"
|
2009-07-19 03:43:29 +08:00
|
|
|
#include "clang/AST/RecordLayout.h"
|
2009-06-06 06:08:42 +08:00
|
|
|
#include "llvm/Type.h"
|
Change X86_64ABIInfo to have ASTContext and TargetData ivars to
avoid passing ASTContext down through all the methods it has.
When classifying an argument, or argument piece, as INTEGER, check
to see if we have a pointer at exactly the same offset in the
preferred type. If so, use that pointer type instead of i64. This
allows us to compile A function taking a stringref into something
like this:
define i8* @foo(i64 %D.coerce0, i8* %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=4]
%0 = getelementptr %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
store i64 %D.coerce0, i64* %0
%1 = getelementptr %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
store i8* %D.coerce1, i8** %1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
instead of this:
define i8* @foo(i64 %D.coerce0, i64 %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=3]
%0 = insertvalue %0 undef, i64 %D.coerce0, 0 ; <%0> [#uses=1]
%1 = insertvalue %0 %0, i64 %D.coerce1, 1 ; <%0> [#uses=1]
%2 = bitcast %struct.DeclGroup* %D to %0* ; <%0*> [#uses=1]
store %0 %1, %0* %2, align 1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
This implements rdar://7375902 - [codegen quality] clang x86-64 ABI lowering code punishing StringRef
llvm-svn: 107123
2010-06-29 14:01:59 +08:00
|
|
|
#include "llvm/Target/TargetData.h"
|
2010-01-10 20:58:08 +08:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2009-08-24 16:52:16 +08:00
|
|
|
#include "llvm/ADT/Triple.h"
|
2009-12-03 17:13:49 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2009-06-06 06:08:42 +08:00
|
|
|
using namespace clang;
|
|
|
|
using namespace CodeGen;
|
|
|
|
|
2010-05-27 14:19:26 +08:00
|
|
|
static void AssignToArrayRange(CodeGen::CGBuilderTy &Builder,
|
|
|
|
llvm::Value *Array,
|
|
|
|
llvm::Value *Value,
|
|
|
|
unsigned FirstIndex,
|
|
|
|
unsigned LastIndex) {
|
|
|
|
// Alternatively, we could emit this as a loop in the source.
|
|
|
|
for (unsigned I = FirstIndex; I <= LastIndex; ++I) {
|
|
|
|
llvm::Value *Cell = Builder.CreateConstInBoundsGEP1_32(Array, I);
|
|
|
|
Builder.CreateStore(Value, Cell);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-06 06:08:42 +08:00
|
|
|
ABIInfo::~ABIInfo() {}
|
|
|
|
|
2010-07-29 10:01:43 +08:00
|
|
|
ASTContext &ABIInfo::getContext() const {
|
|
|
|
return CGT.getContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::LLVMContext &ABIInfo::getVMContext() const {
|
|
|
|
return CGT.getLLVMContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
const llvm::TargetData &ABIInfo::getTargetData() const {
|
|
|
|
return CGT.getTargetData();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-06 06:08:42 +08:00
|
|
|
void ABIArgInfo::dump() const {
|
2009-12-03 17:13:49 +08:00
|
|
|
llvm::raw_ostream &OS = llvm::errs();
|
|
|
|
OS << "(ABIArgInfo Kind=";
|
2009-06-06 06:08:42 +08:00
|
|
|
switch (TheKind) {
|
|
|
|
case Direct:
|
2009-12-03 17:13:49 +08:00
|
|
|
OS << "Direct";
|
2009-06-06 06:08:42 +08:00
|
|
|
break;
|
2009-06-06 17:36:29 +08:00
|
|
|
case Extend:
|
2009-12-03 17:13:49 +08:00
|
|
|
OS << "Extend";
|
2009-06-06 17:36:29 +08:00
|
|
|
break;
|
2009-06-06 06:08:42 +08:00
|
|
|
case Ignore:
|
2009-12-03 17:13:49 +08:00
|
|
|
OS << "Ignore";
|
2009-06-06 06:08:42 +08:00
|
|
|
break;
|
|
|
|
case Coerce:
|
2009-12-03 17:13:49 +08:00
|
|
|
OS << "Coerce Type=";
|
|
|
|
getCoerceToType()->print(OS);
|
2009-06-06 06:08:42 +08:00
|
|
|
break;
|
|
|
|
case Indirect:
|
2010-04-22 03:10:51 +08:00
|
|
|
OS << "Indirect Align=" << getIndirectAlign()
|
|
|
|
<< " Byal=" << getIndirectByVal();
|
2009-06-06 06:08:42 +08:00
|
|
|
break;
|
|
|
|
case Expand:
|
2009-12-03 17:13:49 +08:00
|
|
|
OS << "Expand";
|
2009-06-06 06:08:42 +08:00
|
|
|
break;
|
|
|
|
}
|
2009-12-03 17:13:49 +08:00
|
|
|
OS << ")\n";
|
2009-06-06 06:08:42 +08:00
|
|
|
}
|
|
|
|
|
2010-01-10 20:58:08 +08:00
|
|
|
TargetCodeGenInfo::~TargetCodeGenInfo() { delete Info; }
|
|
|
|
|
2009-09-13 16:03:58 +08:00
|
|
|
static bool isEmptyRecord(ASTContext &Context, QualType T, bool AllowArrays);
|
2009-06-06 06:08:42 +08:00
|
|
|
|
|
|
|
/// isEmptyField - Return true iff a the field is "empty", that is it
|
|
|
|
/// is an unnamed bit-field or an (array of) empty record(s).
|
2009-09-13 16:03:58 +08:00
|
|
|
static bool isEmptyField(ASTContext &Context, const FieldDecl *FD,
|
|
|
|
bool AllowArrays) {
|
2009-06-06 06:08:42 +08:00
|
|
|
if (FD->isUnnamedBitfield())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
QualType FT = FD->getType();
|
|
|
|
|
2009-09-13 16:03:58 +08:00
|
|
|
// Constant arrays of empty records count as empty, strip them off.
|
|
|
|
if (AllowArrays)
|
|
|
|
while (const ConstantArrayType *AT = Context.getAsConstantArrayType(FT))
|
|
|
|
FT = AT->getElementType();
|
|
|
|
|
2010-05-18 00:46:00 +08:00
|
|
|
const RecordType *RT = FT->getAs<RecordType>();
|
|
|
|
if (!RT)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// C++ record fields are never empty, at least in the Itanium ABI.
|
|
|
|
//
|
|
|
|
// FIXME: We should use a predicate for whether this behavior is true in the
|
|
|
|
// current ABI.
|
|
|
|
if (isa<CXXRecordDecl>(RT->getDecl()))
|
|
|
|
return false;
|
|
|
|
|
2009-09-13 16:03:58 +08:00
|
|
|
return isEmptyRecord(Context, FT, AllowArrays);
|
2009-06-06 06:08:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// isEmptyRecord - Return true iff a structure contains only empty
|
|
|
|
/// fields. Note that a structure with a flexible array member is not
|
|
|
|
/// considered empty.
|
2009-09-13 16:03:58 +08:00
|
|
|
static bool isEmptyRecord(ASTContext &Context, QualType T, bool AllowArrays) {
|
2009-07-30 05:53:49 +08:00
|
|
|
const RecordType *RT = T->getAs<RecordType>();
|
2009-06-06 06:08:42 +08:00
|
|
|
if (!RT)
|
|
|
|
return 0;
|
|
|
|
const RecordDecl *RD = RT->getDecl();
|
|
|
|
if (RD->hasFlexibleArrayMember())
|
|
|
|
return false;
|
2010-05-18 00:46:00 +08:00
|
|
|
|
|
|
|
// If this is a C++ record, check the bases first.
|
|
|
|
if (const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD))
|
|
|
|
for (CXXRecordDecl::base_class_const_iterator i = CXXRD->bases_begin(),
|
|
|
|
e = CXXRD->bases_end(); i != e; ++i)
|
|
|
|
if (!isEmptyRecord(Context, i->getType(), true))
|
|
|
|
return false;
|
|
|
|
|
2009-06-30 10:36:12 +08:00
|
|
|
for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end();
|
|
|
|
i != e; ++i)
|
2009-09-13 16:03:58 +08:00
|
|
|
if (!isEmptyField(Context, *i, AllowArrays))
|
2009-06-06 06:08:42 +08:00
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-09-16 23:53:40 +08:00
|
|
|
/// hasNonTrivialDestructorOrCopyConstructor - Determine if a type has either
|
|
|
|
/// a non-trivial destructor or a non-trivial copy constructor.
|
|
|
|
static bool hasNonTrivialDestructorOrCopyConstructor(const RecordType *RT) {
|
|
|
|
const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(RT->getDecl());
|
|
|
|
if (!RD)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return !RD->hasTrivialDestructor() || !RD->hasTrivialCopyConstructor();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// isRecordWithNonTrivialDestructorOrCopyConstructor - Determine if a type is
|
|
|
|
/// a record type with either a non-trivial destructor or a non-trivial copy
|
|
|
|
/// constructor.
|
|
|
|
static bool isRecordWithNonTrivialDestructorOrCopyConstructor(QualType T) {
|
|
|
|
const RecordType *RT = T->getAs<RecordType>();
|
|
|
|
if (!RT)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return hasNonTrivialDestructorOrCopyConstructor(RT);
|
|
|
|
}
|
|
|
|
|
2009-06-06 06:08:42 +08:00
|
|
|
/// isSingleElementStruct - Determine if a structure is a "single
|
|
|
|
/// element struct", i.e. it has exactly one non-empty field or
|
|
|
|
/// exactly one field which is itself a single element
|
|
|
|
/// struct. Structures with flexible array members are never
|
|
|
|
/// considered single element structs.
|
|
|
|
///
|
|
|
|
/// \return The field declaration for the single non-empty field, if
|
|
|
|
/// it exists.
|
|
|
|
static const Type *isSingleElementStruct(QualType T, ASTContext &Context) {
|
|
|
|
const RecordType *RT = T->getAsStructureType();
|
|
|
|
if (!RT)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
const RecordDecl *RD = RT->getDecl();
|
|
|
|
if (RD->hasFlexibleArrayMember())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
const Type *Found = 0;
|
2010-05-12 05:15:36 +08:00
|
|
|
|
|
|
|
// If this is a C++ record, check the bases first.
|
|
|
|
if (const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
|
|
|
|
for (CXXRecordDecl::base_class_const_iterator i = CXXRD->bases_begin(),
|
|
|
|
e = CXXRD->bases_end(); i != e; ++i) {
|
|
|
|
// Ignore empty records.
|
2010-05-18 00:46:00 +08:00
|
|
|
if (isEmptyRecord(Context, i->getType(), true))
|
2010-05-12 05:15:36 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// If we already found an element then this isn't a single-element struct.
|
|
|
|
if (Found)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// If this is non-empty and not a single element struct, the composite
|
|
|
|
// cannot be a single element struct.
|
|
|
|
Found = isSingleElementStruct(i->getType(), Context);
|
|
|
|
if (!Found)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for single element.
|
2009-06-30 10:36:12 +08:00
|
|
|
for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end();
|
|
|
|
i != e; ++i) {
|
2009-06-06 06:08:42 +08:00
|
|
|
const FieldDecl *FD = *i;
|
|
|
|
QualType FT = FD->getType();
|
|
|
|
|
|
|
|
// Ignore empty fields.
|
2009-09-13 16:03:58 +08:00
|
|
|
if (isEmptyField(Context, FD, true))
|
2009-06-06 06:08:42 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// If we already found an element then this isn't a single-element
|
|
|
|
// struct.
|
|
|
|
if (Found)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// Treat single element arrays as the element.
|
|
|
|
while (const ConstantArrayType *AT = Context.getAsConstantArrayType(FT)) {
|
|
|
|
if (AT->getSize().getZExtValue() != 1)
|
|
|
|
break;
|
|
|
|
FT = AT->getElementType();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!CodeGenFunction::hasAggregateLLVMType(FT)) {
|
|
|
|
Found = FT.getTypePtr();
|
|
|
|
} else {
|
|
|
|
Found = isSingleElementStruct(FT, Context);
|
|
|
|
if (!Found)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Found;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool is32Or64BitBasicType(QualType Ty, ASTContext &Context) {
|
2010-05-14 11:40:53 +08:00
|
|
|
if (!Ty->getAs<BuiltinType>() && !Ty->hasPointerRepresentation() &&
|
2009-09-24 13:12:36 +08:00
|
|
|
!Ty->isAnyComplexType() && !Ty->isEnumeralType() &&
|
|
|
|
!Ty->isBlockPointerType())
|
2009-06-06 06:08:42 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
uint64_t Size = Context.getTypeSize(Ty);
|
|
|
|
return Size == 32 || Size == 64;
|
|
|
|
}
|
|
|
|
|
2009-11-09 09:33:53 +08:00
|
|
|
/// canExpandIndirectArgument - Test whether an argument type which is to be
|
|
|
|
/// passed indirectly (on the stack) would have the equivalent layout if it was
|
|
|
|
/// expanded into separate arguments. If so, we prefer to do the latter to avoid
|
|
|
|
/// inhibiting optimizations.
|
|
|
|
///
|
|
|
|
// FIXME: This predicate is missing many cases, currently it just follows
|
|
|
|
// llvm-gcc (checks that all fields are 32-bit or 64-bit primitive types). We
|
|
|
|
// should probably make this smarter, or better yet make the LLVM backend
|
|
|
|
// capable of handling it.
|
|
|
|
static bool canExpandIndirectArgument(QualType Ty, ASTContext &Context) {
|
|
|
|
// We can only expand structure types.
|
|
|
|
const RecordType *RT = Ty->getAs<RecordType>();
|
|
|
|
if (!RT)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// We can only expand (C) structures.
|
|
|
|
//
|
|
|
|
// FIXME: This needs to be generalized to handle classes as well.
|
|
|
|
const RecordDecl *RD = RT->getDecl();
|
|
|
|
if (!RD->isStruct() || isa<CXXRecordDecl>(RD))
|
|
|
|
return false;
|
|
|
|
|
2009-06-30 10:36:12 +08:00
|
|
|
for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end();
|
|
|
|
i != e; ++i) {
|
2009-06-06 06:08:42 +08:00
|
|
|
const FieldDecl *FD = *i;
|
|
|
|
|
|
|
|
if (!is32Or64BitBasicType(FD->getType(), Context))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// FIXME: Reject bit-fields wholesale; there are two problems, we don't know
|
|
|
|
// how to expand them yet, and the predicate for telling if a bitfield still
|
|
|
|
// counts as "basic" is more complicated than what we were doing previously.
|
|
|
|
if (FD->isBitField())
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
/// DefaultABIInfo - The default implementation for ABI specific
|
|
|
|
/// details. This implementation provides information which results in
|
|
|
|
/// self-consistent and sensible LLVM IR generation, but does not
|
|
|
|
/// conform to any particular ABI.
|
|
|
|
class DefaultABIInfo : public ABIInfo {
|
2010-07-29 10:01:43 +08:00
|
|
|
public:
|
|
|
|
DefaultABIInfo(CodeGen::CodeGenTypes &CGT) : ABIInfo(CGT) {}
|
|
|
|
|
2010-07-29 10:16:43 +08:00
|
|
|
ABIArgInfo classifyReturnType(QualType RetTy) const;
|
|
|
|
ABIArgInfo classifyArgumentType(QualType RetTy) const;
|
2009-06-06 06:08:42 +08:00
|
|
|
|
2010-07-29 10:31:05 +08:00
|
|
|
virtual void computeInfo(CGFunctionInfo &FI) const {
|
2010-07-29 10:16:43 +08:00
|
|
|
FI.getReturnInfo() = classifyReturnType(FI.getReturnType());
|
2009-06-06 06:08:42 +08:00
|
|
|
for (CGFunctionInfo::arg_iterator it = FI.arg_begin(), ie = FI.arg_end();
|
|
|
|
it != ie; ++it)
|
2010-07-29 10:16:43 +08:00
|
|
|
it->info = classifyArgumentType(it->type);
|
2009-06-06 06:08:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
|
|
|
|
CodeGenFunction &CGF) const;
|
|
|
|
};
|
|
|
|
|
2010-01-10 20:58:08 +08:00
|
|
|
class DefaultTargetCodeGenInfo : public TargetCodeGenInfo {
|
|
|
|
public:
|
2010-07-29 10:01:43 +08:00
|
|
|
DefaultTargetCodeGenInfo(CodeGen::CodeGenTypes &CGT)
|
|
|
|
: TargetCodeGenInfo(new DefaultABIInfo(CGT)) {}
|
2010-01-10 20:58:08 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
llvm::Value *DefaultABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
|
|
|
|
CodeGenFunction &CGF) const {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-07-29 10:16:43 +08:00
|
|
|
ABIArgInfo DefaultABIInfo::classifyArgumentType(QualType Ty) const {
|
2010-03-12 02:19:55 +08:00
|
|
|
if (CodeGenFunction::hasAggregateLLVMType(Ty))
|
2010-01-10 20:58:08 +08:00
|
|
|
return ABIArgInfo::getIndirect(0);
|
2010-04-22 03:10:51 +08:00
|
|
|
|
2010-03-12 02:19:55 +08:00
|
|
|
// Treat an enum type as its underlying type.
|
|
|
|
if (const EnumType *EnumTy = Ty->getAs<EnumType>())
|
|
|
|
Ty = EnumTy->getDecl()->getIntegerType();
|
2010-02-03 04:10:50 +08:00
|
|
|
|
2010-03-12 02:19:55 +08:00
|
|
|
return (Ty->isPromotableIntegerType() ?
|
|
|
|
ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
|
2010-01-10 20:58:08 +08:00
|
|
|
}
|
|
|
|
|
2010-06-29 04:05:43 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// X86-32 ABI Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-06-06 06:08:42 +08:00
|
|
|
/// X86_32ABIInfo - The X86-32 ABI information.
|
|
|
|
class X86_32ABIInfo : public ABIInfo {
|
2009-08-18 07:08:21 +08:00
|
|
|
bool IsDarwinVectorABI;
|
|
|
|
bool IsSmallStructInRegABI;
|
2009-06-06 06:08:42 +08:00
|
|
|
|
|
|
|
static bool isRegisterSize(unsigned Size) {
|
|
|
|
return (Size == 8 || Size == 16 || Size == 32 || Size == 64);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool shouldReturnTypeInRegister(QualType Ty, ASTContext &Context);
|
|
|
|
|
2010-04-22 03:10:51 +08:00
|
|
|
/// getIndirectResult - Give a source type \arg Ty, return a suitable result
|
|
|
|
/// such that the argument will be passed in memory.
|
2010-07-29 10:16:43 +08:00
|
|
|
ABIArgInfo getIndirectResult(QualType Ty, bool ByVal = true) const;
|
2010-04-22 03:10:51 +08:00
|
|
|
|
2009-06-06 06:08:42 +08:00
|
|
|
public:
|
|
|
|
|
2010-07-29 10:16:43 +08:00
|
|
|
ABIArgInfo classifyReturnType(QualType RetTy) const;
|
|
|
|
ABIArgInfo classifyArgumentType(QualType RetTy) const;
|
2009-06-06 06:08:42 +08:00
|
|
|
|
2010-07-29 10:31:05 +08:00
|
|
|
virtual void computeInfo(CGFunctionInfo &FI) const {
|
2010-07-29 10:16:43 +08:00
|
|
|
FI.getReturnInfo() = classifyReturnType(FI.getReturnType());
|
2009-06-06 06:08:42 +08:00
|
|
|
for (CGFunctionInfo::arg_iterator it = FI.arg_begin(), ie = FI.arg_end();
|
|
|
|
it != ie; ++it)
|
2010-07-29 10:16:43 +08:00
|
|
|
it->info = classifyArgumentType(it->type);
|
2009-06-06 06:08:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
|
|
|
|
CodeGenFunction &CGF) const;
|
|
|
|
|
2010-07-29 10:01:43 +08:00
|
|
|
X86_32ABIInfo(CodeGen::CodeGenTypes &CGT, bool d, bool p)
|
|
|
|
: ABIInfo(CGT), IsDarwinVectorABI(d), IsSmallStructInRegABI(p) {}
|
2009-06-06 06:08:42 +08:00
|
|
|
};
|
|
|
|
|
2010-01-10 20:58:08 +08:00
|
|
|
class X86_32TargetCodeGenInfo : public TargetCodeGenInfo {
|
|
|
|
public:
|
2010-07-29 10:01:43 +08:00
|
|
|
X86_32TargetCodeGenInfo(CodeGen::CodeGenTypes &CGT, bool d, bool p)
|
|
|
|
:TargetCodeGenInfo(new X86_32ABIInfo(CGT, d, p)) {}
|
2010-02-13 23:54:06 +08:00
|
|
|
|
|
|
|
void SetTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
|
|
|
|
CodeGen::CodeGenModule &CGM) const;
|
2010-03-06 08:35:14 +08:00
|
|
|
|
|
|
|
int getDwarfEHStackPointer(CodeGen::CodeGenModule &CGM) const {
|
|
|
|
// Darwin uses different dwarf register numbers for EH.
|
|
|
|
if (CGM.isTargetDarwin()) return 5;
|
|
|
|
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
|
|
|
|
llvm::Value *Address) const;
|
2010-01-10 20:58:08 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
2009-06-06 06:08:42 +08:00
|
|
|
|
|
|
|
/// shouldReturnTypeInRegister - Determine if the given type should be
|
|
|
|
/// passed in a register (for the Darwin ABI).
|
|
|
|
bool X86_32ABIInfo::shouldReturnTypeInRegister(QualType Ty,
|
|
|
|
ASTContext &Context) {
|
|
|
|
uint64_t Size = Context.getTypeSize(Ty);
|
|
|
|
|
|
|
|
// Type must be register sized.
|
|
|
|
if (!isRegisterSize(Size))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (Ty->isVectorType()) {
|
|
|
|
// 64- and 128- bit vectors inside structures are not returned in
|
|
|
|
// registers.
|
|
|
|
if (Size == 64 || Size == 128)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-05-15 08:00:30 +08:00
|
|
|
// If this is a builtin, pointer, enum, complex type, member pointer, or
|
|
|
|
// member function pointer it is ok.
|
2010-05-14 11:40:53 +08:00
|
|
|
if (Ty->getAs<BuiltinType>() || Ty->hasPointerRepresentation() ||
|
2009-09-24 13:12:36 +08:00
|
|
|
Ty->isAnyComplexType() || Ty->isEnumeralType() ||
|
2010-05-15 08:00:30 +08:00
|
|
|
Ty->isBlockPointerType() || Ty->isMemberPointerType())
|
2009-06-06 06:08:42 +08:00
|
|
|
return true;
|
|
|
|
|
|
|
|
// Arrays are treated like records.
|
|
|
|
if (const ConstantArrayType *AT = Context.getAsConstantArrayType(Ty))
|
|
|
|
return shouldReturnTypeInRegister(AT->getElementType(), Context);
|
|
|
|
|
|
|
|
// Otherwise, it must be a record type.
|
2009-07-30 05:53:49 +08:00
|
|
|
const RecordType *RT = Ty->getAs<RecordType>();
|
2009-06-06 06:08:42 +08:00
|
|
|
if (!RT) return false;
|
|
|
|
|
2010-01-27 11:25:19 +08:00
|
|
|
// FIXME: Traverse bases here too.
|
|
|
|
|
2009-06-06 06:08:42 +08:00
|
|
|
// Structure types are passed in register if all fields would be
|
|
|
|
// passed in a register.
|
2009-06-30 10:36:12 +08:00
|
|
|
for (RecordDecl::field_iterator i = RT->getDecl()->field_begin(),
|
|
|
|
e = RT->getDecl()->field_end(); i != e; ++i) {
|
2009-06-06 06:08:42 +08:00
|
|
|
const FieldDecl *FD = *i;
|
|
|
|
|
|
|
|
// Empty fields are ignored.
|
2009-09-13 16:03:58 +08:00
|
|
|
if (isEmptyField(Context, FD, true))
|
2009-06-06 06:08:42 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// Check fields recursively.
|
|
|
|
if (!shouldReturnTypeInRegister(FD->getType(), Context))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-07-29 10:16:43 +08:00
|
|
|
ABIArgInfo X86_32ABIInfo::classifyReturnType(QualType RetTy) const {
|
|
|
|
if (RetTy->isVoidType())
|
2009-06-06 06:08:42 +08:00
|
|
|
return ABIArgInfo::getIgnore();
|
2010-07-29 10:16:43 +08:00
|
|
|
|
|
|
|
if (const VectorType *VT = RetTy->getAs<VectorType>()) {
|
2009-06-06 06:08:42 +08:00
|
|
|
// On Darwin, some vectors are returned in registers.
|
2009-08-18 07:08:21 +08:00
|
|
|
if (IsDarwinVectorABI) {
|
2010-07-29 10:16:43 +08:00
|
|
|
uint64_t Size = getContext().getTypeSize(RetTy);
|
2009-06-06 06:08:42 +08:00
|
|
|
|
|
|
|
// 128-bit vectors are a special case; they are returned in
|
|
|
|
// registers and we need to make sure to pick a type the LLVM
|
|
|
|
// backend will like.
|
|
|
|
if (Size == 128)
|
2009-08-14 05:57:51 +08:00
|
|
|
return ABIArgInfo::getCoerce(llvm::VectorType::get(
|
2010-07-29 10:16:43 +08:00
|
|
|
llvm::Type::getInt64Ty(getVMContext()), 2));
|
2009-06-06 06:08:42 +08:00
|
|
|
|
|
|
|
// Always return in register if it fits in a general purpose
|
|
|
|
// register, or if it is 64 bits and has a single element.
|
|
|
|
if ((Size == 8 || Size == 16 || Size == 32) ||
|
|
|
|
(Size == 64 && VT->getNumElements() == 1))
|
2010-07-29 10:16:43 +08:00
|
|
|
return ABIArgInfo::getCoerce(llvm::IntegerType::get(getVMContext(),
|
|
|
|
Size));
|
2009-06-06 06:08:42 +08:00
|
|
|
|
|
|
|
return ABIArgInfo::getIndirect(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ABIArgInfo::getDirect();
|
2010-07-29 10:16:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (CodeGenFunction::hasAggregateLLVMType(RetTy)) {
|
2010-01-27 11:25:19 +08:00
|
|
|
if (const RecordType *RT = RetTy->getAs<RecordType>()) {
|
2009-10-21 06:07:59 +08:00
|
|
|
// Structures with either a non-trivial destructor or a non-trivial
|
|
|
|
// copy constructor are always indirect.
|
|
|
|
if (hasNonTrivialDestructorOrCopyConstructor(RT))
|
|
|
|
return ABIArgInfo::getIndirect(0, /*ByVal=*/false);
|
|
|
|
|
|
|
|
// Structures with flexible arrays are always indirect.
|
2009-06-06 06:08:42 +08:00
|
|
|
if (RT->getDecl()->hasFlexibleArrayMember())
|
|
|
|
return ABIArgInfo::getIndirect(0);
|
2009-10-21 06:07:59 +08:00
|
|
|
}
|
|
|
|
|
2009-08-18 07:08:21 +08:00
|
|
|
// If specified, structs and unions are always indirect.
|
|
|
|
if (!IsSmallStructInRegABI && !RetTy->isAnyComplexType())
|
2009-06-06 06:08:42 +08:00
|
|
|
return ABIArgInfo::getIndirect(0);
|
|
|
|
|
|
|
|
// Classify "single element" structs as their element type.
|
2010-07-29 10:16:43 +08:00
|
|
|
if (const Type *SeltTy = isSingleElementStruct(RetTy, getContext())) {
|
2009-09-22 07:43:11 +08:00
|
|
|
if (const BuiltinType *BT = SeltTy->getAs<BuiltinType>()) {
|
2009-06-06 06:08:42 +08:00
|
|
|
if (BT->isIntegerType()) {
|
|
|
|
// We need to use the size of the structure, padding
|
|
|
|
// bit-fields can adjust that to be larger than the single
|
|
|
|
// element type.
|
2010-07-29 10:16:43 +08:00
|
|
|
uint64_t Size = getContext().getTypeSize(RetTy);
|
2009-07-15 07:10:40 +08:00
|
|
|
return ABIArgInfo::getCoerce(
|
2010-07-29 10:16:43 +08:00
|
|
|
llvm::IntegerType::get(getVMContext(), (unsigned)Size));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (BT->getKind() == BuiltinType::Float) {
|
|
|
|
assert(getContext().getTypeSize(RetTy) ==
|
|
|
|
getContext().getTypeSize(SeltTy) &&
|
2009-06-06 06:08:42 +08:00
|
|
|
"Unexpect single element structure size!");
|
2010-07-29 10:16:43 +08:00
|
|
|
return ABIArgInfo::getCoerce(llvm::Type::getFloatTy(getVMContext()));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (BT->getKind() == BuiltinType::Double) {
|
|
|
|
assert(getContext().getTypeSize(RetTy) ==
|
|
|
|
getContext().getTypeSize(SeltTy) &&
|
2009-06-06 06:08:42 +08:00
|
|
|
"Unexpect single element structure size!");
|
2010-07-29 10:16:43 +08:00
|
|
|
return ABIArgInfo::getCoerce(llvm::Type::getDoubleTy(getVMContext()));
|
2009-06-06 06:08:42 +08:00
|
|
|
}
|
|
|
|
} else if (SeltTy->isPointerType()) {
|
|
|
|
// FIXME: It would be really nice if this could come out as the proper
|
|
|
|
// pointer type.
|
2010-07-29 10:16:43 +08:00
|
|
|
const llvm::Type *PtrTy = llvm::Type::getInt8PtrTy(getVMContext());
|
2009-06-06 06:08:42 +08:00
|
|
|
return ABIArgInfo::getCoerce(PtrTy);
|
|
|
|
} else if (SeltTy->isVectorType()) {
|
|
|
|
// 64- and 128-bit vectors are never returned in a
|
|
|
|
// register when inside a structure.
|
2010-07-29 10:16:43 +08:00
|
|
|
uint64_t Size = getContext().getTypeSize(RetTy);
|
2009-06-06 06:08:42 +08:00
|
|
|
if (Size == 64 || Size == 128)
|
|
|
|
return ABIArgInfo::getIndirect(0);
|
|
|
|
|
2010-07-29 10:16:43 +08:00
|
|
|
return classifyReturnType(QualType(SeltTy, 0));
|
2009-06-06 06:08:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Small structures which are register sized are generally returned
|
|
|
|
// in a register.
|
2010-07-29 10:16:43 +08:00
|
|
|
if (X86_32ABIInfo::shouldReturnTypeInRegister(RetTy, getContext())) {
|
|
|
|
uint64_t Size = getContext().getTypeSize(RetTy);
|
|
|
|
return ABIArgInfo::getCoerce(llvm::IntegerType::get(getVMContext(),Size));
|
2009-06-06 06:08:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return ABIArgInfo::getIndirect(0);
|
|
|
|
}
|
2010-07-29 10:16:43 +08:00
|
|
|
|
|
|
|
// Treat an enum type as its underlying type.
|
|
|
|
if (const EnumType *EnumTy = RetTy->getAs<EnumType>())
|
|
|
|
RetTy = EnumTy->getDecl()->getIntegerType();
|
|
|
|
|
|
|
|
return (RetTy->isPromotableIntegerType() ?
|
|
|
|
ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
|
2009-06-06 06:08:42 +08:00
|
|
|
}
|
|
|
|
|
2010-07-29 10:16:43 +08:00
|
|
|
ABIArgInfo X86_32ABIInfo::getIndirectResult(QualType Ty, bool ByVal) const {
|
2010-04-22 03:49:55 +08:00
|
|
|
if (!ByVal)
|
|
|
|
return ABIArgInfo::getIndirect(0, false);
|
|
|
|
|
|
|
|
// Compute the byval alignment. We trust the back-end to honor the
|
|
|
|
// minimum ABI alignment for byval, to make cleaner IR.
|
|
|
|
const unsigned MinABIAlign = 4;
|
2010-07-29 10:16:43 +08:00
|
|
|
unsigned Align = getContext().getTypeAlign(Ty) / 8;
|
2010-04-22 03:49:55 +08:00
|
|
|
if (Align > MinABIAlign)
|
|
|
|
return ABIArgInfo::getIndirect(Align);
|
|
|
|
return ABIArgInfo::getIndirect(0);
|
2010-04-22 03:10:51 +08:00
|
|
|
}
|
|
|
|
|
2010-07-29 10:16:43 +08:00
|
|
|
ABIArgInfo X86_32ABIInfo::classifyArgumentType(QualType Ty) const {
|
2009-06-06 06:08:42 +08:00
|
|
|
// FIXME: Set alignment on indirect arguments.
|
|
|
|
if (CodeGenFunction::hasAggregateLLVMType(Ty)) {
|
|
|
|
// Structures with flexible arrays are always indirect.
|
2010-01-27 11:25:19 +08:00
|
|
|
if (const RecordType *RT = Ty->getAs<RecordType>()) {
|
|
|
|
// Structures with either a non-trivial destructor or a non-trivial
|
|
|
|
// copy constructor are always indirect.
|
|
|
|
if (hasNonTrivialDestructorOrCopyConstructor(RT))
|
2010-07-29 10:16:43 +08:00
|
|
|
return getIndirectResult(Ty, /*ByVal=*/false);
|
2010-04-22 03:10:51 +08:00
|
|
|
|
2009-06-06 06:08:42 +08:00
|
|
|
if (RT->getDecl()->hasFlexibleArrayMember())
|
2010-07-29 10:16:43 +08:00
|
|
|
return getIndirectResult(Ty);
|
2010-01-27 11:25:19 +08:00
|
|
|
}
|
2009-06-06 06:08:42 +08:00
|
|
|
|
|
|
|
// Ignore empty structs.
|
2010-07-29 10:16:43 +08:00
|
|
|
if (Ty->isStructureType() && getContext().getTypeSize(Ty) == 0)
|
2009-06-06 06:08:42 +08:00
|
|
|
return ABIArgInfo::getIgnore();
|
|
|
|
|
2009-11-09 09:33:53 +08:00
|
|
|
// Expand small (<= 128-bit) record types when we know that the stack layout
|
|
|
|
// of those arguments will match the struct. This is important because the
|
|
|
|
// LLVM backend isn't smart enough to remove byval, which inhibits many
|
|
|
|
// optimizations.
|
2010-07-29 10:16:43 +08:00
|
|
|
if (getContext().getTypeSize(Ty) <= 4*32 &&
|
|
|
|
canExpandIndirectArgument(Ty, getContext()))
|
2009-11-09 09:33:53 +08:00
|
|
|
return ABIArgInfo::getExpand();
|
2009-06-06 06:08:42 +08:00
|
|
|
|
2010-07-29 10:16:43 +08:00
|
|
|
return getIndirectResult(Ty);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (const EnumType *EnumTy = Ty->getAs<EnumType>())
|
|
|
|
Ty = EnumTy->getDecl()->getIntegerType();
|
2010-02-03 04:10:50 +08:00
|
|
|
|
2010-07-29 10:16:43 +08:00
|
|
|
return (Ty->isPromotableIntegerType() ?
|
|
|
|
ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
|
2009-06-06 06:08:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
llvm::Value *X86_32ABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
|
|
|
|
CodeGenFunction &CGF) const {
|
2009-10-13 18:07:13 +08:00
|
|
|
const llvm::Type *BP = llvm::Type::getInt8PtrTy(CGF.getLLVMContext());
|
2009-07-30 06:16:19 +08:00
|
|
|
const llvm::Type *BPP = llvm::PointerType::getUnqual(BP);
|
2009-06-06 06:08:42 +08:00
|
|
|
|
|
|
|
CGBuilderTy &Builder = CGF.Builder;
|
|
|
|
llvm::Value *VAListAddrAsBPP = Builder.CreateBitCast(VAListAddr, BPP,
|
|
|
|
"ap");
|
|
|
|
llvm::Value *Addr = Builder.CreateLoad(VAListAddrAsBPP, "ap.cur");
|
|
|
|
llvm::Type *PTy =
|
2009-07-30 06:16:19 +08:00
|
|
|
llvm::PointerType::getUnqual(CGF.ConvertType(Ty));
|
2009-06-06 06:08:42 +08:00
|
|
|
llvm::Value *AddrTyped = Builder.CreateBitCast(Addr, PTy);
|
|
|
|
|
|
|
|
uint64_t Offset =
|
|
|
|
llvm::RoundUpToAlignment(CGF.getContext().getTypeSize(Ty) / 8, 4);
|
|
|
|
llvm::Value *NextAddr =
|
2010-06-27 15:15:29 +08:00
|
|
|
Builder.CreateGEP(Addr, llvm::ConstantInt::get(CGF.Int32Ty, Offset),
|
2009-06-06 06:08:42 +08:00
|
|
|
"ap.next");
|
|
|
|
Builder.CreateStore(NextAddr, VAListAddrAsBPP);
|
|
|
|
|
|
|
|
return AddrTyped;
|
|
|
|
}
|
|
|
|
|
2010-02-13 23:54:06 +08:00
|
|
|
void X86_32TargetCodeGenInfo::SetTargetAttributes(const Decl *D,
|
|
|
|
llvm::GlobalValue *GV,
|
|
|
|
CodeGen::CodeGenModule &CGM) const {
|
|
|
|
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
|
|
|
|
if (FD->hasAttr<X86ForceAlignArgPointerAttr>()) {
|
|
|
|
// Get the LLVM function.
|
|
|
|
llvm::Function *Fn = cast<llvm::Function>(GV);
|
|
|
|
|
|
|
|
// Now add the 'alignstack' attribute with a value of 16.
|
|
|
|
Fn->addFnAttr(llvm::Attribute::constructStackAlignmentFromInt(16));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-06 08:35:14 +08:00
|
|
|
bool X86_32TargetCodeGenInfo::initDwarfEHRegSizeTable(
|
|
|
|
CodeGen::CodeGenFunction &CGF,
|
|
|
|
llvm::Value *Address) const {
|
|
|
|
CodeGen::CGBuilderTy &Builder = CGF.Builder;
|
|
|
|
llvm::LLVMContext &Context = CGF.getLLVMContext();
|
|
|
|
|
|
|
|
const llvm::IntegerType *i8 = llvm::Type::getInt8Ty(Context);
|
|
|
|
llvm::Value *Four8 = llvm::ConstantInt::get(i8, 4);
|
|
|
|
|
|
|
|
// 0-7 are the eight integer registers; the order is different
|
|
|
|
// on Darwin (for EH), but the range is the same.
|
|
|
|
// 8 is %eip.
|
2010-05-27 14:19:26 +08:00
|
|
|
AssignToArrayRange(Builder, Address, Four8, 0, 8);
|
2010-03-06 08:35:14 +08:00
|
|
|
|
|
|
|
if (CGF.CGM.isTargetDarwin()) {
|
|
|
|
// 12-16 are st(0..4). Not sure why we stop at 4.
|
|
|
|
// These have size 16, which is sizeof(long double) on
|
|
|
|
// platforms with 8-byte alignment for that type.
|
|
|
|
llvm::Value *Sixteen8 = llvm::ConstantInt::get(i8, 16);
|
2010-05-27 14:19:26 +08:00
|
|
|
AssignToArrayRange(Builder, Address, Sixteen8, 12, 16);
|
2010-03-06 08:35:14 +08:00
|
|
|
|
|
|
|
} else {
|
|
|
|
// 9 is %eflags, which doesn't get a size on Darwin for some
|
|
|
|
// reason.
|
|
|
|
Builder.CreateStore(Four8, Builder.CreateConstInBoundsGEP1_32(Address, 9));
|
|
|
|
|
|
|
|
// 11-16 are st(0..5). Not sure why we stop at 5.
|
|
|
|
// These have size 12, which is sizeof(long double) on
|
|
|
|
// platforms with 4-byte alignment for that type.
|
|
|
|
llvm::Value *Twelve8 = llvm::ConstantInt::get(i8, 12);
|
2010-05-27 14:19:26 +08:00
|
|
|
AssignToArrayRange(Builder, Address, Twelve8, 11, 16);
|
|
|
|
}
|
2010-03-06 08:35:14 +08:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-06-29 04:05:43 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// X86-64 ABI Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
2009-06-06 06:08:42 +08:00
|
|
|
namespace {
|
|
|
|
/// X86_64ABIInfo - The X86_64 ABI information.
|
|
|
|
class X86_64ABIInfo : public ABIInfo {
|
|
|
|
enum Class {
|
|
|
|
Integer = 0,
|
|
|
|
SSE,
|
|
|
|
SSEUp,
|
|
|
|
X87,
|
|
|
|
X87Up,
|
|
|
|
ComplexX87,
|
|
|
|
NoClass,
|
|
|
|
Memory
|
|
|
|
};
|
|
|
|
|
|
|
|
/// merge - Implement the X86_64 ABI merging algorithm.
|
|
|
|
///
|
|
|
|
/// Merge an accumulating classification \arg Accum with a field
|
|
|
|
/// classification \arg Field.
|
|
|
|
///
|
|
|
|
/// \param Accum - The accumulating classification. This should
|
|
|
|
/// always be either NoClass or the result of a previous merge
|
|
|
|
/// call. In addition, this should never be Memory (the caller
|
|
|
|
/// should just return Memory for the aggregate).
|
2010-06-29 05:43:59 +08:00
|
|
|
static Class merge(Class Accum, Class Field);
|
2009-06-06 06:08:42 +08:00
|
|
|
|
|
|
|
/// classify - Determine the x86_64 register classes in which the
|
|
|
|
/// given type T should be passed.
|
|
|
|
///
|
|
|
|
/// \param Lo - The classification for the parts of the type
|
|
|
|
/// residing in the low word of the containing object.
|
|
|
|
///
|
|
|
|
/// \param Hi - The classification for the parts of the type
|
|
|
|
/// residing in the high word of the containing object.
|
|
|
|
///
|
|
|
|
/// \param OffsetBase - The bit offset of this type in the
|
|
|
|
/// containing object. Some parameters are classified different
|
|
|
|
/// depending on whether they straddle an eightbyte boundary.
|
|
|
|
///
|
|
|
|
/// If a word is unused its result will be NoClass; if a type should
|
|
|
|
/// be passed in Memory then at least the classification of \arg Lo
|
|
|
|
/// will be Memory.
|
|
|
|
///
|
|
|
|
/// The \arg Lo class will be NoClass iff the argument is ignored.
|
|
|
|
///
|
|
|
|
/// If the \arg Lo class is ComplexX87, then the \arg Hi class will
|
|
|
|
/// also be ComplexX87.
|
Change X86_64ABIInfo to have ASTContext and TargetData ivars to
avoid passing ASTContext down through all the methods it has.
When classifying an argument, or argument piece, as INTEGER, check
to see if we have a pointer at exactly the same offset in the
preferred type. If so, use that pointer type instead of i64. This
allows us to compile A function taking a stringref into something
like this:
define i8* @foo(i64 %D.coerce0, i8* %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=4]
%0 = getelementptr %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
store i64 %D.coerce0, i64* %0
%1 = getelementptr %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
store i8* %D.coerce1, i8** %1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
instead of this:
define i8* @foo(i64 %D.coerce0, i64 %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=3]
%0 = insertvalue %0 undef, i64 %D.coerce0, 0 ; <%0> [#uses=1]
%1 = insertvalue %0 %0, i64 %D.coerce1, 1 ; <%0> [#uses=1]
%2 = bitcast %struct.DeclGroup* %D to %0* ; <%0*> [#uses=1]
store %0 %1, %0* %2, align 1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
This implements rdar://7375902 - [codegen quality] clang x86-64 ABI lowering code punishing StringRef
llvm-svn: 107123
2010-06-29 14:01:59 +08:00
|
|
|
void classify(QualType T, uint64_t OffsetBase, Class &Lo, Class &Hi) const;
|
2009-06-06 06:08:42 +08:00
|
|
|
|
2010-07-29 12:56:46 +08:00
|
|
|
const llvm::Type *Get16ByteVectorType(QualType Ty) const;
|
|
|
|
|
2010-07-29 12:41:05 +08:00
|
|
|
const llvm::Type *Get8ByteTypeAtOffset(const llvm::Type *IRType,
|
|
|
|
unsigned IROffset, QualType SourceTy,
|
2010-07-29 10:20:19 +08:00
|
|
|
unsigned SourceOffset) const;
|
|
|
|
|
2009-06-06 06:08:42 +08:00
|
|
|
/// getCoerceResult - Given a source type \arg Ty and an LLVM type
|
|
|
|
/// to coerce to, chose the best way to pass Ty in the same place
|
|
|
|
/// that \arg CoerceTo would be passed, but while keeping the
|
|
|
|
/// emitted code as simple as possible.
|
|
|
|
///
|
|
|
|
/// FIXME: Note, this should be cleaned up to just take an enumeration of all
|
|
|
|
/// the ways we might want to pass things, instead of constructing an LLVM
|
|
|
|
/// type. This makes this code more explicit, and it makes it clearer that we
|
|
|
|
/// are also doing this for correctness in the case of passing scalar types.
|
|
|
|
ABIArgInfo getCoerceResult(QualType Ty,
|
Change X86_64ABIInfo to have ASTContext and TargetData ivars to
avoid passing ASTContext down through all the methods it has.
When classifying an argument, or argument piece, as INTEGER, check
to see if we have a pointer at exactly the same offset in the
preferred type. If so, use that pointer type instead of i64. This
allows us to compile A function taking a stringref into something
like this:
define i8* @foo(i64 %D.coerce0, i8* %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=4]
%0 = getelementptr %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
store i64 %D.coerce0, i64* %0
%1 = getelementptr %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
store i8* %D.coerce1, i8** %1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
instead of this:
define i8* @foo(i64 %D.coerce0, i64 %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=3]
%0 = insertvalue %0 undef, i64 %D.coerce0, 0 ; <%0> [#uses=1]
%1 = insertvalue %0 %0, i64 %D.coerce1, 1 ; <%0> [#uses=1]
%2 = bitcast %struct.DeclGroup* %D to %0* ; <%0*> [#uses=1]
store %0 %1, %0* %2, align 1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
This implements rdar://7375902 - [codegen quality] clang x86-64 ABI lowering code punishing StringRef
llvm-svn: 107123
2010-06-29 14:01:59 +08:00
|
|
|
const llvm::Type *CoerceTo) const;
|
2009-06-06 06:08:42 +08:00
|
|
|
|
2010-04-22 03:49:55 +08:00
|
|
|
/// getIndirectResult - Give a source type \arg Ty, return a suitable result
|
|
|
|
/// such that the argument will be returned in memory.
|
Change X86_64ABIInfo to have ASTContext and TargetData ivars to
avoid passing ASTContext down through all the methods it has.
When classifying an argument, or argument piece, as INTEGER, check
to see if we have a pointer at exactly the same offset in the
preferred type. If so, use that pointer type instead of i64. This
allows us to compile A function taking a stringref into something
like this:
define i8* @foo(i64 %D.coerce0, i8* %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=4]
%0 = getelementptr %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
store i64 %D.coerce0, i64* %0
%1 = getelementptr %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
store i8* %D.coerce1, i8** %1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
instead of this:
define i8* @foo(i64 %D.coerce0, i64 %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=3]
%0 = insertvalue %0 undef, i64 %D.coerce0, 0 ; <%0> [#uses=1]
%1 = insertvalue %0 %0, i64 %D.coerce1, 1 ; <%0> [#uses=1]
%2 = bitcast %struct.DeclGroup* %D to %0* ; <%0*> [#uses=1]
store %0 %1, %0* %2, align 1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
This implements rdar://7375902 - [codegen quality] clang x86-64 ABI lowering code punishing StringRef
llvm-svn: 107123
2010-06-29 14:01:59 +08:00
|
|
|
ABIArgInfo getIndirectReturnResult(QualType Ty) const;
|
2010-04-22 03:49:55 +08:00
|
|
|
|
2009-06-06 06:08:42 +08:00
|
|
|
/// getIndirectResult - Give a source type \arg Ty, return a suitable result
|
|
|
|
/// such that the argument will be passed in memory.
|
Change X86_64ABIInfo to have ASTContext and TargetData ivars to
avoid passing ASTContext down through all the methods it has.
When classifying an argument, or argument piece, as INTEGER, check
to see if we have a pointer at exactly the same offset in the
preferred type. If so, use that pointer type instead of i64. This
allows us to compile A function taking a stringref into something
like this:
define i8* @foo(i64 %D.coerce0, i8* %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=4]
%0 = getelementptr %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
store i64 %D.coerce0, i64* %0
%1 = getelementptr %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
store i8* %D.coerce1, i8** %1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
instead of this:
define i8* @foo(i64 %D.coerce0, i64 %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=3]
%0 = insertvalue %0 undef, i64 %D.coerce0, 0 ; <%0> [#uses=1]
%1 = insertvalue %0 %0, i64 %D.coerce1, 1 ; <%0> [#uses=1]
%2 = bitcast %struct.DeclGroup* %D to %0* ; <%0*> [#uses=1]
store %0 %1, %0* %2, align 1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
This implements rdar://7375902 - [codegen quality] clang x86-64 ABI lowering code punishing StringRef
llvm-svn: 107123
2010-06-29 14:01:59 +08:00
|
|
|
ABIArgInfo getIndirectResult(QualType Ty) const;
|
2009-06-06 06:08:42 +08:00
|
|
|
|
2010-07-29 10:16:43 +08:00
|
|
|
ABIArgInfo classifyReturnType(QualType RetTy) const;
|
2009-06-06 06:08:42 +08:00
|
|
|
|
2010-07-29 12:41:05 +08:00
|
|
|
ABIArgInfo classifyArgumentType(QualType Ty, unsigned &neededInt,
|
|
|
|
unsigned &neededSSE) const;
|
2009-06-06 06:08:42 +08:00
|
|
|
|
|
|
|
public:
|
2010-07-29 10:01:43 +08:00
|
|
|
X86_64ABIInfo(CodeGen::CodeGenTypes &CGT) : ABIInfo(CGT) {}
|
Change X86_64ABIInfo to have ASTContext and TargetData ivars to
avoid passing ASTContext down through all the methods it has.
When classifying an argument, or argument piece, as INTEGER, check
to see if we have a pointer at exactly the same offset in the
preferred type. If so, use that pointer type instead of i64. This
allows us to compile A function taking a stringref into something
like this:
define i8* @foo(i64 %D.coerce0, i8* %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=4]
%0 = getelementptr %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
store i64 %D.coerce0, i64* %0
%1 = getelementptr %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
store i8* %D.coerce1, i8** %1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
instead of this:
define i8* @foo(i64 %D.coerce0, i64 %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=3]
%0 = insertvalue %0 undef, i64 %D.coerce0, 0 ; <%0> [#uses=1]
%1 = insertvalue %0 %0, i64 %D.coerce1, 1 ; <%0> [#uses=1]
%2 = bitcast %struct.DeclGroup* %D to %0* ; <%0*> [#uses=1]
store %0 %1, %0* %2, align 1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
This implements rdar://7375902 - [codegen quality] clang x86-64 ABI lowering code punishing StringRef
llvm-svn: 107123
2010-06-29 14:01:59 +08:00
|
|
|
|
2010-07-29 10:31:05 +08:00
|
|
|
virtual void computeInfo(CGFunctionInfo &FI) const;
|
2009-06-06 06:08:42 +08:00
|
|
|
|
|
|
|
virtual llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
|
|
|
|
CodeGenFunction &CGF) const;
|
|
|
|
};
|
2010-01-10 20:58:08 +08:00
|
|
|
|
|
|
|
class X86_64TargetCodeGenInfo : public TargetCodeGenInfo {
|
|
|
|
public:
|
2010-07-29 10:01:43 +08:00
|
|
|
X86_64TargetCodeGenInfo(CodeGen::CodeGenTypes &CGT)
|
|
|
|
: TargetCodeGenInfo(new X86_64ABIInfo(CGT)) {}
|
2010-03-06 08:35:14 +08:00
|
|
|
|
|
|
|
int getDwarfEHStackPointer(CodeGen::CodeGenModule &CGM) const {
|
|
|
|
return 7;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
|
|
|
|
llvm::Value *Address) const {
|
|
|
|
CodeGen::CGBuilderTy &Builder = CGF.Builder;
|
|
|
|
llvm::LLVMContext &Context = CGF.getLLVMContext();
|
|
|
|
|
|
|
|
const llvm::IntegerType *i8 = llvm::Type::getInt8Ty(Context);
|
|
|
|
llvm::Value *Eight8 = llvm::ConstantInt::get(i8, 8);
|
|
|
|
|
2010-05-27 14:19:26 +08:00
|
|
|
// 0-15 are the 16 integer registers.
|
|
|
|
// 16 is %rip.
|
|
|
|
AssignToArrayRange(Builder, Address, Eight8, 0, 16);
|
2010-03-06 08:35:14 +08:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2010-01-10 20:58:08 +08:00
|
|
|
};
|
|
|
|
|
2009-06-06 06:08:42 +08:00
|
|
|
}
|
|
|
|
|
2010-06-29 05:43:59 +08:00
|
|
|
X86_64ABIInfo::Class X86_64ABIInfo::merge(Class Accum, Class Field) {
|
2009-06-06 06:08:42 +08:00
|
|
|
// AMD64-ABI 3.2.3p2: Rule 4. Each field of an object is
|
|
|
|
// classified recursively so that always two fields are
|
|
|
|
// considered. The resulting class is calculated according to
|
|
|
|
// the classes of the fields in the eightbyte:
|
|
|
|
//
|
|
|
|
// (a) If both classes are equal, this is the resulting class.
|
|
|
|
//
|
|
|
|
// (b) If one of the classes is NO_CLASS, the resulting class is
|
|
|
|
// the other class.
|
|
|
|
//
|
|
|
|
// (c) If one of the classes is MEMORY, the result is the MEMORY
|
|
|
|
// class.
|
|
|
|
//
|
|
|
|
// (d) If one of the classes is INTEGER, the result is the
|
|
|
|
// INTEGER.
|
|
|
|
//
|
|
|
|
// (e) If one of the classes is X87, X87UP, COMPLEX_X87 class,
|
|
|
|
// MEMORY is used as class.
|
|
|
|
//
|
|
|
|
// (f) Otherwise class SSE is used.
|
|
|
|
|
|
|
|
// Accum should never be memory (we should have returned) or
|
|
|
|
// ComplexX87 (because this cannot be passed in a structure).
|
|
|
|
assert((Accum != Memory && Accum != ComplexX87) &&
|
|
|
|
"Invalid accumulated classification during merge.");
|
|
|
|
if (Accum == Field || Field == NoClass)
|
|
|
|
return Accum;
|
2010-06-29 05:43:59 +08:00
|
|
|
if (Field == Memory)
|
2009-06-06 06:08:42 +08:00
|
|
|
return Memory;
|
2010-06-29 05:43:59 +08:00
|
|
|
if (Accum == NoClass)
|
2009-06-06 06:08:42 +08:00
|
|
|
return Field;
|
2010-06-29 05:43:59 +08:00
|
|
|
if (Accum == Integer || Field == Integer)
|
2009-06-06 06:08:42 +08:00
|
|
|
return Integer;
|
2010-06-29 05:43:59 +08:00
|
|
|
if (Field == X87 || Field == X87Up || Field == ComplexX87 ||
|
|
|
|
Accum == X87 || Accum == X87Up)
|
2009-06-06 06:08:42 +08:00
|
|
|
return Memory;
|
2010-06-29 05:43:59 +08:00
|
|
|
return SSE;
|
2009-06-06 06:08:42 +08:00
|
|
|
}
|
|
|
|
|
2010-07-01 03:14:05 +08:00
|
|
|
void X86_64ABIInfo::classify(QualType Ty, uint64_t OffsetBase,
|
2009-06-06 06:08:42 +08:00
|
|
|
Class &Lo, Class &Hi) const {
|
|
|
|
// FIXME: This code can be simplified by introducing a simple value class for
|
|
|
|
// Class pairs with appropriate constructor methods for the various
|
|
|
|
// situations.
|
|
|
|
|
|
|
|
// FIXME: Some of the split computations are wrong; unaligned vectors
|
|
|
|
// shouldn't be passed in registers for example, so there is no chance they
|
|
|
|
// can straddle an eightbyte. Verify & simplify.
|
|
|
|
|
|
|
|
Lo = Hi = NoClass;
|
|
|
|
|
|
|
|
Class &Current = OffsetBase < 64 ? Lo : Hi;
|
|
|
|
Current = Memory;
|
|
|
|
|
2009-09-22 07:43:11 +08:00
|
|
|
if (const BuiltinType *BT = Ty->getAs<BuiltinType>()) {
|
2009-06-06 06:08:42 +08:00
|
|
|
BuiltinType::Kind k = BT->getKind();
|
|
|
|
|
|
|
|
if (k == BuiltinType::Void) {
|
|
|
|
Current = NoClass;
|
|
|
|
} else if (k == BuiltinType::Int128 || k == BuiltinType::UInt128) {
|
|
|
|
Lo = Integer;
|
|
|
|
Hi = Integer;
|
|
|
|
} else if (k >= BuiltinType::Bool && k <= BuiltinType::LongLong) {
|
|
|
|
Current = Integer;
|
|
|
|
} else if (k == BuiltinType::Float || k == BuiltinType::Double) {
|
|
|
|
Current = SSE;
|
|
|
|
} else if (k == BuiltinType::LongDouble) {
|
|
|
|
Lo = X87;
|
|
|
|
Hi = X87Up;
|
|
|
|
}
|
|
|
|
// FIXME: _Decimal32 and _Decimal64 are SSE.
|
|
|
|
// FIXME: _float128 and _Decimal128 are (SSE, SSEUp).
|
2010-06-29 05:43:59 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (const EnumType *ET = Ty->getAs<EnumType>()) {
|
2009-06-06 06:08:42 +08:00
|
|
|
// Classify the underlying integer type.
|
Change X86_64ABIInfo to have ASTContext and TargetData ivars to
avoid passing ASTContext down through all the methods it has.
When classifying an argument, or argument piece, as INTEGER, check
to see if we have a pointer at exactly the same offset in the
preferred type. If so, use that pointer type instead of i64. This
allows us to compile A function taking a stringref into something
like this:
define i8* @foo(i64 %D.coerce0, i8* %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=4]
%0 = getelementptr %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
store i64 %D.coerce0, i64* %0
%1 = getelementptr %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
store i8* %D.coerce1, i8** %1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
instead of this:
define i8* @foo(i64 %D.coerce0, i64 %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=3]
%0 = insertvalue %0 undef, i64 %D.coerce0, 0 ; <%0> [#uses=1]
%1 = insertvalue %0 %0, i64 %D.coerce1, 1 ; <%0> [#uses=1]
%2 = bitcast %struct.DeclGroup* %D to %0* ; <%0*> [#uses=1]
store %0 %1, %0* %2, align 1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
This implements rdar://7375902 - [codegen quality] clang x86-64 ABI lowering code punishing StringRef
llvm-svn: 107123
2010-06-29 14:01:59 +08:00
|
|
|
classify(ET->getDecl()->getIntegerType(), OffsetBase, Lo, Hi);
|
2010-06-29 05:43:59 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Ty->hasPointerRepresentation()) {
|
2009-06-06 06:08:42 +08:00
|
|
|
Current = Integer;
|
2010-06-29 05:43:59 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Ty->isMemberPointerType()) {
|
2010-05-15 08:00:37 +08:00
|
|
|
if (Ty->isMemberFunctionPointerType())
|
|
|
|
Lo = Hi = Integer;
|
|
|
|
else
|
|
|
|
Current = Integer;
|
2010-06-29 05:43:59 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (const VectorType *VT = Ty->getAs<VectorType>()) {
|
2010-07-29 10:01:43 +08:00
|
|
|
uint64_t Size = getContext().getTypeSize(VT);
|
2009-06-06 06:08:42 +08:00
|
|
|
if (Size == 32) {
|
|
|
|
// gcc passes all <4 x char>, <2 x short>, <1 x int>, <1 x
|
|
|
|
// float> as integer.
|
|
|
|
Current = Integer;
|
|
|
|
|
|
|
|
// If this type crosses an eightbyte boundary, it should be
|
|
|
|
// split.
|
|
|
|
uint64_t EB_Real = (OffsetBase) / 64;
|
|
|
|
uint64_t EB_Imag = (OffsetBase + Size - 1) / 64;
|
|
|
|
if (EB_Real != EB_Imag)
|
|
|
|
Hi = Lo;
|
|
|
|
} else if (Size == 64) {
|
|
|
|
// gcc passes <1 x double> in memory. :(
|
|
|
|
if (VT->getElementType()->isSpecificBuiltinType(BuiltinType::Double))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// gcc passes <1 x long long> as INTEGER.
|
|
|
|
if (VT->getElementType()->isSpecificBuiltinType(BuiltinType::LongLong))
|
|
|
|
Current = Integer;
|
|
|
|
else
|
|
|
|
Current = SSE;
|
|
|
|
|
|
|
|
// If this type crosses an eightbyte boundary, it should be
|
|
|
|
// split.
|
|
|
|
if (OffsetBase && OffsetBase != 64)
|
|
|
|
Hi = Lo;
|
|
|
|
} else if (Size == 128) {
|
|
|
|
Lo = SSE;
|
|
|
|
Hi = SSEUp;
|
|
|
|
}
|
2010-06-29 05:43:59 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (const ComplexType *CT = Ty->getAs<ComplexType>()) {
|
2010-07-29 10:01:43 +08:00
|
|
|
QualType ET = getContext().getCanonicalType(CT->getElementType());
|
2009-06-06 06:08:42 +08:00
|
|
|
|
2010-07-29 10:01:43 +08:00
|
|
|
uint64_t Size = getContext().getTypeSize(Ty);
|
2010-06-16 08:17:44 +08:00
|
|
|
if (ET->isIntegralOrEnumerationType()) {
|
2009-06-06 06:08:42 +08:00
|
|
|
if (Size <= 64)
|
|
|
|
Current = Integer;
|
|
|
|
else if (Size <= 128)
|
|
|
|
Lo = Hi = Integer;
|
2010-07-29 10:01:43 +08:00
|
|
|
} else if (ET == getContext().FloatTy)
|
2009-06-06 06:08:42 +08:00
|
|
|
Current = SSE;
|
2010-07-29 10:01:43 +08:00
|
|
|
else if (ET == getContext().DoubleTy)
|
2009-06-06 06:08:42 +08:00
|
|
|
Lo = Hi = SSE;
|
2010-07-29 10:01:43 +08:00
|
|
|
else if (ET == getContext().LongDoubleTy)
|
2009-06-06 06:08:42 +08:00
|
|
|
Current = ComplexX87;
|
|
|
|
|
|
|
|
// If this complex type crosses an eightbyte boundary then it
|
|
|
|
// should be split.
|
|
|
|
uint64_t EB_Real = (OffsetBase) / 64;
|
2010-07-29 10:01:43 +08:00
|
|
|
uint64_t EB_Imag = (OffsetBase + getContext().getTypeSize(ET)) / 64;
|
2009-06-06 06:08:42 +08:00
|
|
|
if (Hi == NoClass && EB_Real != EB_Imag)
|
|
|
|
Hi = Lo;
|
2010-06-29 05:43:59 +08:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-07-29 10:01:43 +08:00
|
|
|
if (const ConstantArrayType *AT = getContext().getAsConstantArrayType(Ty)) {
|
2009-06-06 06:08:42 +08:00
|
|
|
// Arrays are treated like structures.
|
|
|
|
|
2010-07-29 10:01:43 +08:00
|
|
|
uint64_t Size = getContext().getTypeSize(Ty);
|
2009-06-06 06:08:42 +08:00
|
|
|
|
|
|
|
// AMD64-ABI 3.2.3p2: Rule 1. If the size of an object is larger
|
|
|
|
// than two eightbytes, ..., it has class MEMORY.
|
|
|
|
if (Size > 128)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// AMD64-ABI 3.2.3p2: Rule 1. If ..., or it contains unaligned
|
|
|
|
// fields, it has class MEMORY.
|
|
|
|
//
|
|
|
|
// Only need to check alignment of array base.
|
2010-07-29 10:01:43 +08:00
|
|
|
if (OffsetBase % getContext().getTypeAlign(AT->getElementType()))
|
2009-06-06 06:08:42 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Otherwise implement simplified merge. We could be smarter about
|
|
|
|
// this, but it isn't worth it and would be harder to verify.
|
|
|
|
Current = NoClass;
|
2010-07-29 10:01:43 +08:00
|
|
|
uint64_t EltSize = getContext().getTypeSize(AT->getElementType());
|
2009-06-06 06:08:42 +08:00
|
|
|
uint64_t ArraySize = AT->getSize().getZExtValue();
|
|
|
|
for (uint64_t i=0, Offset=OffsetBase; i<ArraySize; ++i, Offset += EltSize) {
|
|
|
|
Class FieldLo, FieldHi;
|
Change X86_64ABIInfo to have ASTContext and TargetData ivars to
avoid passing ASTContext down through all the methods it has.
When classifying an argument, or argument piece, as INTEGER, check
to see if we have a pointer at exactly the same offset in the
preferred type. If so, use that pointer type instead of i64. This
allows us to compile A function taking a stringref into something
like this:
define i8* @foo(i64 %D.coerce0, i8* %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=4]
%0 = getelementptr %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
store i64 %D.coerce0, i64* %0
%1 = getelementptr %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
store i8* %D.coerce1, i8** %1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
instead of this:
define i8* @foo(i64 %D.coerce0, i64 %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=3]
%0 = insertvalue %0 undef, i64 %D.coerce0, 0 ; <%0> [#uses=1]
%1 = insertvalue %0 %0, i64 %D.coerce1, 1 ; <%0> [#uses=1]
%2 = bitcast %struct.DeclGroup* %D to %0* ; <%0*> [#uses=1]
store %0 %1, %0* %2, align 1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
This implements rdar://7375902 - [codegen quality] clang x86-64 ABI lowering code punishing StringRef
llvm-svn: 107123
2010-06-29 14:01:59 +08:00
|
|
|
classify(AT->getElementType(), Offset, FieldLo, FieldHi);
|
2009-06-06 06:08:42 +08:00
|
|
|
Lo = merge(Lo, FieldLo);
|
|
|
|
Hi = merge(Hi, FieldHi);
|
|
|
|
if (Lo == Memory || Hi == Memory)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do post merger cleanup (see below). Only case we worry about is Memory.
|
|
|
|
if (Hi == Memory)
|
|
|
|
Lo = Memory;
|
|
|
|
assert((Hi != SSEUp || Lo == SSE) && "Invalid SSEUp array classification.");
|
2010-06-29 05:43:59 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (const RecordType *RT = Ty->getAs<RecordType>()) {
|
2010-07-29 10:01:43 +08:00
|
|
|
uint64_t Size = getContext().getTypeSize(Ty);
|
2009-06-06 06:08:42 +08:00
|
|
|
|
|
|
|
// AMD64-ABI 3.2.3p2: Rule 1. If the size of an object is larger
|
|
|
|
// than two eightbytes, ..., it has class MEMORY.
|
|
|
|
if (Size > 128)
|
|
|
|
return;
|
|
|
|
|
2009-09-16 23:53:40 +08:00
|
|
|
// AMD64-ABI 3.2.3p2: Rule 2. If a C++ object has either a non-trivial
|
|
|
|
// copy constructor or a non-trivial destructor, it is passed by invisible
|
|
|
|
// reference.
|
|
|
|
if (hasNonTrivialDestructorOrCopyConstructor(RT))
|
|
|
|
return;
|
2009-11-23 07:01:23 +08:00
|
|
|
|
2009-06-06 06:08:42 +08:00
|
|
|
const RecordDecl *RD = RT->getDecl();
|
|
|
|
|
|
|
|
// Assume variable sized types are passed in memory.
|
|
|
|
if (RD->hasFlexibleArrayMember())
|
|
|
|
return;
|
|
|
|
|
2010-07-29 10:01:43 +08:00
|
|
|
const ASTRecordLayout &Layout = getContext().getASTRecordLayout(RD);
|
2009-06-06 06:08:42 +08:00
|
|
|
|
|
|
|
// Reset Lo class, this will be recomputed.
|
|
|
|
Current = NoClass;
|
2009-11-23 07:01:23 +08:00
|
|
|
|
|
|
|
// If this is a C++ record, classify the bases first.
|
|
|
|
if (const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
|
|
|
|
for (CXXRecordDecl::base_class_const_iterator i = CXXRD->bases_begin(),
|
|
|
|
e = CXXRD->bases_end(); i != e; ++i) {
|
|
|
|
assert(!i->isVirtual() && !i->getType()->isDependentType() &&
|
|
|
|
"Unexpected base class!");
|
|
|
|
const CXXRecordDecl *Base =
|
|
|
|
cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
|
|
|
|
|
|
|
|
// Classify this field.
|
|
|
|
//
|
|
|
|
// AMD64-ABI 3.2.3p2: Rule 3. If the size of the aggregate exceeds a
|
|
|
|
// single eightbyte, each is classified separately. Each eightbyte gets
|
|
|
|
// initialized to class NO_CLASS.
|
|
|
|
Class FieldLo, FieldHi;
|
|
|
|
uint64_t Offset = OffsetBase + Layout.getBaseClassOffset(Base);
|
Change X86_64ABIInfo to have ASTContext and TargetData ivars to
avoid passing ASTContext down through all the methods it has.
When classifying an argument, or argument piece, as INTEGER, check
to see if we have a pointer at exactly the same offset in the
preferred type. If so, use that pointer type instead of i64. This
allows us to compile A function taking a stringref into something
like this:
define i8* @foo(i64 %D.coerce0, i8* %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=4]
%0 = getelementptr %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
store i64 %D.coerce0, i64* %0
%1 = getelementptr %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
store i8* %D.coerce1, i8** %1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
instead of this:
define i8* @foo(i64 %D.coerce0, i64 %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=3]
%0 = insertvalue %0 undef, i64 %D.coerce0, 0 ; <%0> [#uses=1]
%1 = insertvalue %0 %0, i64 %D.coerce1, 1 ; <%0> [#uses=1]
%2 = bitcast %struct.DeclGroup* %D to %0* ; <%0*> [#uses=1]
store %0 %1, %0* %2, align 1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
This implements rdar://7375902 - [codegen quality] clang x86-64 ABI lowering code punishing StringRef
llvm-svn: 107123
2010-06-29 14:01:59 +08:00
|
|
|
classify(i->getType(), Offset, FieldLo, FieldHi);
|
2009-11-23 07:01:23 +08:00
|
|
|
Lo = merge(Lo, FieldLo);
|
|
|
|
Hi = merge(Hi, FieldHi);
|
|
|
|
if (Lo == Memory || Hi == Memory)
|
|
|
|
break;
|
|
|
|
}
|
2009-12-22 09:19:25 +08:00
|
|
|
|
|
|
|
// If this record has no fields but isn't empty, classify as INTEGER.
|
|
|
|
if (RD->field_empty() && Size)
|
|
|
|
Current = Integer;
|
2009-11-23 07:01:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Classify the fields one at a time, merging the results.
|
2009-06-06 06:08:42 +08:00
|
|
|
unsigned idx = 0;
|
2009-06-30 10:36:12 +08:00
|
|
|
for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end();
|
|
|
|
i != e; ++i, ++idx) {
|
2009-06-06 06:08:42 +08:00
|
|
|
uint64_t Offset = OffsetBase + Layout.getFieldOffset(idx);
|
|
|
|
bool BitField = i->isBitField();
|
|
|
|
|
|
|
|
// AMD64-ABI 3.2.3p2: Rule 1. If ..., or it contains unaligned
|
|
|
|
// fields, it has class MEMORY.
|
|
|
|
//
|
|
|
|
// Note, skip this test for bit-fields, see below.
|
2010-07-29 10:01:43 +08:00
|
|
|
if (!BitField && Offset % getContext().getTypeAlign(i->getType())) {
|
2009-06-06 06:08:42 +08:00
|
|
|
Lo = Memory;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Classify this field.
|
|
|
|
//
|
|
|
|
// AMD64-ABI 3.2.3p2: Rule 3. If the size of the aggregate
|
|
|
|
// exceeds a single eightbyte, each is classified
|
|
|
|
// separately. Each eightbyte gets initialized to class
|
|
|
|
// NO_CLASS.
|
|
|
|
Class FieldLo, FieldHi;
|
|
|
|
|
|
|
|
// Bit-fields require special handling, they do not force the
|
|
|
|
// structure to be passed in memory even if unaligned, and
|
|
|
|
// therefore they can straddle an eightbyte.
|
|
|
|
if (BitField) {
|
|
|
|
// Ignore padding bit-fields.
|
|
|
|
if (i->isUnnamedBitfield())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
uint64_t Offset = OffsetBase + Layout.getFieldOffset(idx);
|
2010-07-29 10:01:43 +08:00
|
|
|
uint64_t Size =
|
|
|
|
i->getBitWidth()->EvaluateAsInt(getContext()).getZExtValue();
|
2009-06-06 06:08:42 +08:00
|
|
|
|
|
|
|
uint64_t EB_Lo = Offset / 64;
|
|
|
|
uint64_t EB_Hi = (Offset + Size - 1) / 64;
|
|
|
|
FieldLo = FieldHi = NoClass;
|
|
|
|
if (EB_Lo) {
|
|
|
|
assert(EB_Hi == EB_Lo && "Invalid classification, type > 16 bytes.");
|
|
|
|
FieldLo = NoClass;
|
|
|
|
FieldHi = Integer;
|
|
|
|
} else {
|
|
|
|
FieldLo = Integer;
|
|
|
|
FieldHi = EB_Hi ? Integer : NoClass;
|
|
|
|
}
|
|
|
|
} else
|
Change X86_64ABIInfo to have ASTContext and TargetData ivars to
avoid passing ASTContext down through all the methods it has.
When classifying an argument, or argument piece, as INTEGER, check
to see if we have a pointer at exactly the same offset in the
preferred type. If so, use that pointer type instead of i64. This
allows us to compile A function taking a stringref into something
like this:
define i8* @foo(i64 %D.coerce0, i8* %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=4]
%0 = getelementptr %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
store i64 %D.coerce0, i64* %0
%1 = getelementptr %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
store i8* %D.coerce1, i8** %1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
instead of this:
define i8* @foo(i64 %D.coerce0, i64 %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=3]
%0 = insertvalue %0 undef, i64 %D.coerce0, 0 ; <%0> [#uses=1]
%1 = insertvalue %0 %0, i64 %D.coerce1, 1 ; <%0> [#uses=1]
%2 = bitcast %struct.DeclGroup* %D to %0* ; <%0*> [#uses=1]
store %0 %1, %0* %2, align 1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
This implements rdar://7375902 - [codegen quality] clang x86-64 ABI lowering code punishing StringRef
llvm-svn: 107123
2010-06-29 14:01:59 +08:00
|
|
|
classify(i->getType(), Offset, FieldLo, FieldHi);
|
2009-06-06 06:08:42 +08:00
|
|
|
Lo = merge(Lo, FieldLo);
|
|
|
|
Hi = merge(Hi, FieldHi);
|
|
|
|
if (Lo == Memory || Hi == Memory)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// AMD64-ABI 3.2.3p2: Rule 5. Then a post merger cleanup is done:
|
|
|
|
//
|
|
|
|
// (a) If one of the classes is MEMORY, the whole argument is
|
|
|
|
// passed in memory.
|
|
|
|
//
|
|
|
|
// (b) If SSEUP is not preceeded by SSE, it is converted to SSE.
|
|
|
|
|
|
|
|
// The first of these conditions is guaranteed by how we implement
|
|
|
|
// the merge (just bail).
|
|
|
|
//
|
|
|
|
// The second condition occurs in the case of unions; for example
|
|
|
|
// union { _Complex double; unsigned; }.
|
|
|
|
if (Hi == Memory)
|
|
|
|
Lo = Memory;
|
|
|
|
if (Hi == SSEUp && Lo != SSE)
|
|
|
|
Hi = SSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ABIArgInfo X86_64ABIInfo::getCoerceResult(QualType Ty,
|
Change X86_64ABIInfo to have ASTContext and TargetData ivars to
avoid passing ASTContext down through all the methods it has.
When classifying an argument, or argument piece, as INTEGER, check
to see if we have a pointer at exactly the same offset in the
preferred type. If so, use that pointer type instead of i64. This
allows us to compile A function taking a stringref into something
like this:
define i8* @foo(i64 %D.coerce0, i8* %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=4]
%0 = getelementptr %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
store i64 %D.coerce0, i64* %0
%1 = getelementptr %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
store i8* %D.coerce1, i8** %1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
instead of this:
define i8* @foo(i64 %D.coerce0, i64 %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=3]
%0 = insertvalue %0 undef, i64 %D.coerce0, 0 ; <%0> [#uses=1]
%1 = insertvalue %0 %0, i64 %D.coerce1, 1 ; <%0> [#uses=1]
%2 = bitcast %struct.DeclGroup* %D to %0* ; <%0*> [#uses=1]
store %0 %1, %0* %2, align 1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
This implements rdar://7375902 - [codegen quality] clang x86-64 ABI lowering code punishing StringRef
llvm-svn: 107123
2010-06-29 14:01:59 +08:00
|
|
|
const llvm::Type *CoerceTo) const {
|
2010-07-29 06:15:08 +08:00
|
|
|
// If this is a pointer passed as a pointer, just pass it directly.
|
|
|
|
if ((isa<llvm::PointerType>(CoerceTo) || CoerceTo->isIntegerTy(64)) &&
|
|
|
|
Ty->hasPointerRepresentation())
|
|
|
|
return ABIArgInfo::getExtend();
|
|
|
|
|
|
|
|
if (isa<llvm::IntegerType>(CoerceTo)) {
|
2009-06-06 06:08:42 +08:00
|
|
|
// Integer and pointer types will end up in a general purpose
|
|
|
|
// register.
|
2010-02-03 04:10:50 +08:00
|
|
|
|
|
|
|
// Treat an enum type as its underlying type.
|
|
|
|
if (const EnumType *EnumTy = Ty->getAs<EnumType>())
|
|
|
|
Ty = EnumTy->getDecl()->getIntegerType();
|
|
|
|
|
2010-07-29 06:15:08 +08:00
|
|
|
if (Ty->isIntegralOrEnumerationType())
|
2009-06-06 17:36:29 +08:00
|
|
|
return (Ty->isPromotableIntegerType() ?
|
|
|
|
ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
|
2010-07-29 07:12:33 +08:00
|
|
|
|
2010-06-27 05:52:32 +08:00
|
|
|
} else if (CoerceTo->isDoubleTy()) {
|
2010-02-24 15:14:12 +08:00
|
|
|
assert(Ty.isCanonical() && "should always have a canonical type here");
|
|
|
|
assert(!Ty.hasQualifiers() && "should never have a qualified type here");
|
2009-06-06 06:08:42 +08:00
|
|
|
|
|
|
|
// Float and double end up in a single SSE reg.
|
2010-07-29 10:01:43 +08:00
|
|
|
if (Ty == getContext().FloatTy || Ty == getContext().DoubleTy)
|
2009-06-06 06:08:42 +08:00
|
|
|
return ABIArgInfo::getDirect();
|
|
|
|
|
X86-64:
pass/return structs of float/int as float/i32 instead of double/i64
to make the code generated for ABI cleaner. Passing in the low part
of a double is the same as passing in a float.
For example, we now compile:
struct DeclGroup { float NumDecls; };
float foo(DeclGroup D);
void bar(DeclGroup *D) {
foo(*D);
}
into:
%struct.DeclGroup = type { float }
define void @_Z3barP9DeclGroup(%struct.DeclGroup* %D) nounwind {
entry:
%D.addr = alloca %struct.DeclGroup*, align 8 ; <%struct.DeclGroup**> [#uses=2]
%agg.tmp = alloca %struct.DeclGroup, align 4 ; <%struct.DeclGroup*> [#uses=2]
store %struct.DeclGroup* %D, %struct.DeclGroup** %D.addr
%tmp = load %struct.DeclGroup** %D.addr ; <%struct.DeclGroup*> [#uses=1]
%tmp1 = bitcast %struct.DeclGroup* %agg.tmp to i8* ; <i8*> [#uses=1]
%tmp2 = bitcast %struct.DeclGroup* %tmp to i8* ; <i8*> [#uses=1]
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %tmp1, i8* %tmp2, i64 4, i32 4, i1 false)
%coerce.dive = getelementptr %struct.DeclGroup* %agg.tmp, i32 0, i32 0 ; <float*> [#uses=1]
%0 = load float* %coerce.dive, align 1 ; <float> [#uses=1]
%call = call float @_Z3foo9DeclGroup(float %0) ; <float> [#uses=0]
ret void
}
instead of:
%struct.DeclGroup = type { float }
define void @_Z3barP9DeclGroup(%struct.DeclGroup* %D) nounwind {
entry:
%D.addr = alloca %struct.DeclGroup*, align 8 ; <%struct.DeclGroup**> [#uses=2]
%agg.tmp = alloca %struct.DeclGroup, align 4 ; <%struct.DeclGroup*> [#uses=2]
%tmp3 = alloca double ; <double*> [#uses=2]
store %struct.DeclGroup* %D, %struct.DeclGroup** %D.addr
%tmp = load %struct.DeclGroup** %D.addr ; <%struct.DeclGroup*> [#uses=1]
%tmp1 = bitcast %struct.DeclGroup* %agg.tmp to i8* ; <i8*> [#uses=1]
%tmp2 = bitcast %struct.DeclGroup* %tmp to i8* ; <i8*> [#uses=1]
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %tmp1, i8* %tmp2, i64 4, i32 4, i1 false)
%coerce.dive = getelementptr %struct.DeclGroup* %agg.tmp, i32 0, i32 0 ; <float*> [#uses=1]
%0 = bitcast double* %tmp3 to float* ; <float*> [#uses=1]
%1 = load float* %coerce.dive ; <float> [#uses=1]
store float %1, float* %0, align 1
%2 = load double* %tmp3 ; <double> [#uses=1]
%call = call float @_Z3foo9DeclGroup(double %2) ; <float> [#uses=0]
ret void
}
which is this machine code (at -O0):
__Z3barP9DeclGroup:
subq $24, %rsp
movq %rdi, 16(%rsp)
movq 16(%rsp), %rdi
leaq 8(%rsp), %rax
movl (%rdi), %ecx
movl %ecx, (%rax)
movss 8(%rsp), %xmm0
callq __Z3foo9DeclGroup
addq $24, %rsp
ret
vs this:
__Z3barP9DeclGroup:
subq $24, %rsp
movq %rdi, 16(%rsp)
movq 16(%rsp), %rdi
leaq 8(%rsp), %rax
movl (%rdi), %ecx
movl %ecx, (%rax)
movss 8(%rsp), %xmm0
movss %xmm0, (%rsp)
movsd (%rsp), %xmm0
callq __Z3foo9DeclGroup
addq $24, %rsp
ret
At -O3, it is the difference between this now:
__Z3barP9DeclGroup:
movss (%rdi), %xmm0
jmp __Z3foo9DeclGroup # TAILCALL
vs this before:
__Z3barP9DeclGroup:
movl (%rdi), %eax
movd %rax, %xmm0
jmp __Z3foo9DeclGroup # TAILCALL
llvm-svn: 107048
2010-06-29 03:56:59 +08:00
|
|
|
// If this is a 32-bit structure that is passed as a double, then it will be
|
|
|
|
// passed in the low 32-bits of the XMM register, which is the same as how a
|
|
|
|
// float is passed. Coerce to a float instead of a double.
|
2010-07-29 10:01:43 +08:00
|
|
|
if (getContext().getTypeSizeInChars(Ty).getQuantity() == 4)
|
X86-64:
pass/return structs of float/int as float/i32 instead of double/i64
to make the code generated for ABI cleaner. Passing in the low part
of a double is the same as passing in a float.
For example, we now compile:
struct DeclGroup { float NumDecls; };
float foo(DeclGroup D);
void bar(DeclGroup *D) {
foo(*D);
}
into:
%struct.DeclGroup = type { float }
define void @_Z3barP9DeclGroup(%struct.DeclGroup* %D) nounwind {
entry:
%D.addr = alloca %struct.DeclGroup*, align 8 ; <%struct.DeclGroup**> [#uses=2]
%agg.tmp = alloca %struct.DeclGroup, align 4 ; <%struct.DeclGroup*> [#uses=2]
store %struct.DeclGroup* %D, %struct.DeclGroup** %D.addr
%tmp = load %struct.DeclGroup** %D.addr ; <%struct.DeclGroup*> [#uses=1]
%tmp1 = bitcast %struct.DeclGroup* %agg.tmp to i8* ; <i8*> [#uses=1]
%tmp2 = bitcast %struct.DeclGroup* %tmp to i8* ; <i8*> [#uses=1]
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %tmp1, i8* %tmp2, i64 4, i32 4, i1 false)
%coerce.dive = getelementptr %struct.DeclGroup* %agg.tmp, i32 0, i32 0 ; <float*> [#uses=1]
%0 = load float* %coerce.dive, align 1 ; <float> [#uses=1]
%call = call float @_Z3foo9DeclGroup(float %0) ; <float> [#uses=0]
ret void
}
instead of:
%struct.DeclGroup = type { float }
define void @_Z3barP9DeclGroup(%struct.DeclGroup* %D) nounwind {
entry:
%D.addr = alloca %struct.DeclGroup*, align 8 ; <%struct.DeclGroup**> [#uses=2]
%agg.tmp = alloca %struct.DeclGroup, align 4 ; <%struct.DeclGroup*> [#uses=2]
%tmp3 = alloca double ; <double*> [#uses=2]
store %struct.DeclGroup* %D, %struct.DeclGroup** %D.addr
%tmp = load %struct.DeclGroup** %D.addr ; <%struct.DeclGroup*> [#uses=1]
%tmp1 = bitcast %struct.DeclGroup* %agg.tmp to i8* ; <i8*> [#uses=1]
%tmp2 = bitcast %struct.DeclGroup* %tmp to i8* ; <i8*> [#uses=1]
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %tmp1, i8* %tmp2, i64 4, i32 4, i1 false)
%coerce.dive = getelementptr %struct.DeclGroup* %agg.tmp, i32 0, i32 0 ; <float*> [#uses=1]
%0 = bitcast double* %tmp3 to float* ; <float*> [#uses=1]
%1 = load float* %coerce.dive ; <float> [#uses=1]
store float %1, float* %0, align 1
%2 = load double* %tmp3 ; <double> [#uses=1]
%call = call float @_Z3foo9DeclGroup(double %2) ; <float> [#uses=0]
ret void
}
which is this machine code (at -O0):
__Z3barP9DeclGroup:
subq $24, %rsp
movq %rdi, 16(%rsp)
movq 16(%rsp), %rdi
leaq 8(%rsp), %rax
movl (%rdi), %ecx
movl %ecx, (%rax)
movss 8(%rsp), %xmm0
callq __Z3foo9DeclGroup
addq $24, %rsp
ret
vs this:
__Z3barP9DeclGroup:
subq $24, %rsp
movq %rdi, 16(%rsp)
movq 16(%rsp), %rdi
leaq 8(%rsp), %rax
movl (%rdi), %ecx
movl %ecx, (%rax)
movss 8(%rsp), %xmm0
movss %xmm0, (%rsp)
movsd (%rsp), %xmm0
callq __Z3foo9DeclGroup
addq $24, %rsp
ret
At -O3, it is the difference between this now:
__Z3barP9DeclGroup:
movss (%rdi), %xmm0
jmp __Z3foo9DeclGroup # TAILCALL
vs this before:
__Z3barP9DeclGroup:
movl (%rdi), %eax
movd %rax, %xmm0
jmp __Z3foo9DeclGroup # TAILCALL
llvm-svn: 107048
2010-06-29 03:56:59 +08:00
|
|
|
CoerceTo = llvm::Type::getFloatTy(CoerceTo->getContext());
|
2009-06-06 06:08:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return ABIArgInfo::getCoerce(CoerceTo);
|
|
|
|
}
|
|
|
|
|
Change X86_64ABIInfo to have ASTContext and TargetData ivars to
avoid passing ASTContext down through all the methods it has.
When classifying an argument, or argument piece, as INTEGER, check
to see if we have a pointer at exactly the same offset in the
preferred type. If so, use that pointer type instead of i64. This
allows us to compile A function taking a stringref into something
like this:
define i8* @foo(i64 %D.coerce0, i8* %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=4]
%0 = getelementptr %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
store i64 %D.coerce0, i64* %0
%1 = getelementptr %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
store i8* %D.coerce1, i8** %1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
instead of this:
define i8* @foo(i64 %D.coerce0, i64 %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=3]
%0 = insertvalue %0 undef, i64 %D.coerce0, 0 ; <%0> [#uses=1]
%1 = insertvalue %0 %0, i64 %D.coerce1, 1 ; <%0> [#uses=1]
%2 = bitcast %struct.DeclGroup* %D to %0* ; <%0*> [#uses=1]
store %0 %1, %0* %2, align 1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
This implements rdar://7375902 - [codegen quality] clang x86-64 ABI lowering code punishing StringRef
llvm-svn: 107123
2010-06-29 14:01:59 +08:00
|
|
|
ABIArgInfo X86_64ABIInfo::getIndirectReturnResult(QualType Ty) const {
|
2010-04-22 03:49:55 +08:00
|
|
|
// If this is a scalar LLVM value then assume LLVM will pass it in the right
|
|
|
|
// place naturally.
|
|
|
|
if (!CodeGenFunction::hasAggregateLLVMType(Ty)) {
|
|
|
|
// Treat an enum type as its underlying type.
|
|
|
|
if (const EnumType *EnumTy = Ty->getAs<EnumType>())
|
|
|
|
Ty = EnumTy->getDecl()->getIntegerType();
|
|
|
|
|
|
|
|
return (Ty->isPromotableIntegerType() ?
|
|
|
|
ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
|
|
|
|
}
|
|
|
|
|
|
|
|
return ABIArgInfo::getIndirect(0);
|
|
|
|
}
|
|
|
|
|
Change X86_64ABIInfo to have ASTContext and TargetData ivars to
avoid passing ASTContext down through all the methods it has.
When classifying an argument, or argument piece, as INTEGER, check
to see if we have a pointer at exactly the same offset in the
preferred type. If so, use that pointer type instead of i64. This
allows us to compile A function taking a stringref into something
like this:
define i8* @foo(i64 %D.coerce0, i8* %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=4]
%0 = getelementptr %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
store i64 %D.coerce0, i64* %0
%1 = getelementptr %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
store i8* %D.coerce1, i8** %1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
instead of this:
define i8* @foo(i64 %D.coerce0, i64 %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=3]
%0 = insertvalue %0 undef, i64 %D.coerce0, 0 ; <%0> [#uses=1]
%1 = insertvalue %0 %0, i64 %D.coerce1, 1 ; <%0> [#uses=1]
%2 = bitcast %struct.DeclGroup* %D to %0* ; <%0*> [#uses=1]
store %0 %1, %0* %2, align 1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
This implements rdar://7375902 - [codegen quality] clang x86-64 ABI lowering code punishing StringRef
llvm-svn: 107123
2010-06-29 14:01:59 +08:00
|
|
|
ABIArgInfo X86_64ABIInfo::getIndirectResult(QualType Ty) const {
|
2009-06-06 06:08:42 +08:00
|
|
|
// If this is a scalar LLVM value then assume LLVM will pass it in the right
|
|
|
|
// place naturally.
|
2010-02-03 04:10:50 +08:00
|
|
|
if (!CodeGenFunction::hasAggregateLLVMType(Ty)) {
|
|
|
|
// Treat an enum type as its underlying type.
|
|
|
|
if (const EnumType *EnumTy = Ty->getAs<EnumType>())
|
|
|
|
Ty = EnumTy->getDecl()->getIntegerType();
|
|
|
|
|
2009-06-06 17:36:29 +08:00
|
|
|
return (Ty->isPromotableIntegerType() ?
|
|
|
|
ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
|
2010-02-03 04:10:50 +08:00
|
|
|
}
|
2009-06-06 06:08:42 +08:00
|
|
|
|
2010-04-22 03:49:55 +08:00
|
|
|
if (isRecordWithNonTrivialDestructorOrCopyConstructor(Ty))
|
|
|
|
return ABIArgInfo::getIndirect(0, /*ByVal=*/false);
|
2009-09-16 23:53:40 +08:00
|
|
|
|
2010-04-22 03:49:55 +08:00
|
|
|
// Compute the byval alignment. We trust the back-end to honor the
|
|
|
|
// minimum ABI alignment for byval, to make cleaner IR.
|
|
|
|
const unsigned MinABIAlign = 8;
|
2010-07-29 10:01:43 +08:00
|
|
|
unsigned Align = getContext().getTypeAlign(Ty) / 8;
|
2010-04-22 03:49:55 +08:00
|
|
|
if (Align > MinABIAlign)
|
|
|
|
return ABIArgInfo::getIndirect(Align);
|
|
|
|
return ABIArgInfo::getIndirect(0);
|
2009-06-06 06:08:42 +08:00
|
|
|
}
|
|
|
|
|
2010-07-29 12:56:46 +08:00
|
|
|
/// Get16ByteVectorType - The ABI specifies that a value should be passed in an
|
|
|
|
/// full vector XMM register. Pick an LLVM IR type that will be passed as a
|
|
|
|
/// vector register.
|
|
|
|
const llvm::Type *X86_64ABIInfo::Get16ByteVectorType(QualType Ty) const {
|
|
|
|
// If the preferred type is a 16-byte vector, prefer to pass it.
|
|
|
|
if (const llvm::VectorType *VT =
|
|
|
|
dyn_cast<llvm::VectorType>(CGT.ConvertTypeRecursive(Ty))){
|
|
|
|
const llvm::Type *EltTy = VT->getElementType();
|
|
|
|
if (VT->getBitWidth() == 128 &&
|
|
|
|
(EltTy->isFloatTy() || EltTy->isDoubleTy() ||
|
|
|
|
EltTy->isIntegerTy(8) || EltTy->isIntegerTy(16) ||
|
|
|
|
EltTy->isIntegerTy(32) || EltTy->isIntegerTy(64) ||
|
|
|
|
EltTy->isIntegerTy(128)))
|
|
|
|
return VT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return llvm::VectorType::get(llvm::Type::getDoubleTy(getVMContext()), 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-29 07:06:14 +08:00
|
|
|
/// Get8ByteTypeAtOffset - The ABI specifies that a value should be passed in an
|
|
|
|
/// 8-byte GPR. This means that we either have a scalar or we are talking about
|
|
|
|
/// the high or low part of an up-to-16-byte struct. This routine picks the
|
|
|
|
/// best LLVM IR type to represent this, which may be i64 or may be anything
|
|
|
|
/// else that the backend will pass in a GPR that works better (e.g. i8, %foo*,
|
|
|
|
/// etc).
|
|
|
|
///
|
|
|
|
/// PrefType is an LLVM IR type that corresponds to (part of) the IR type for
|
|
|
|
/// the source type. IROffset is an offset in bytes into the LLVM IR type that
|
|
|
|
/// the 8-byte value references. PrefType may be null.
|
|
|
|
///
|
|
|
|
/// SourceTy is the source level type for the entire argument. SourceOffset is
|
|
|
|
/// an offset into this that we're processing (which is always either 0 or 8).
|
|
|
|
///
|
2010-07-29 10:20:19 +08:00
|
|
|
const llvm::Type *X86_64ABIInfo::
|
2010-07-29 12:41:05 +08:00
|
|
|
Get8ByteTypeAtOffset(const llvm::Type *IRType, unsigned IROffset,
|
2010-07-29 10:20:19 +08:00
|
|
|
QualType SourceTy, unsigned SourceOffset) const {
|
2010-07-29 07:06:14 +08:00
|
|
|
// Pointers are always 8-bytes at offset 0.
|
2010-07-29 12:51:12 +08:00
|
|
|
if (IROffset == 0 && isa<llvm::PointerType>(IRType))
|
2010-07-29 12:41:05 +08:00
|
|
|
return IRType;
|
2010-07-29 07:06:14 +08:00
|
|
|
|
|
|
|
// TODO: 1/2/4/8 byte integers are also interesting, but we have to know that
|
|
|
|
// the "hole" is not used in the containing struct (just undef padding).
|
|
|
|
|
2010-07-29 12:51:12 +08:00
|
|
|
if (const llvm::StructType *STy = dyn_cast<llvm::StructType>(IRType)) {
|
2010-07-29 07:06:14 +08:00
|
|
|
// If this is a struct, recurse into the field at the specified offset.
|
2010-07-29 10:20:19 +08:00
|
|
|
const llvm::StructLayout *SL = getTargetData().getStructLayout(STy);
|
2010-07-29 07:06:14 +08:00
|
|
|
if (IROffset < SL->getSizeInBytes()) {
|
|
|
|
unsigned FieldIdx = SL->getElementContainingOffset(IROffset);
|
|
|
|
IROffset -= SL->getElementOffset(FieldIdx);
|
|
|
|
|
|
|
|
return Get8ByteTypeAtOffset(STy->getElementType(FieldIdx), IROffset,
|
2010-07-29 10:20:19 +08:00
|
|
|
SourceTy, SourceOffset);
|
2010-07-29 07:06:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Okay, we don't have any better idea of what to pass, so we pass this in an
|
|
|
|
// integer register that isn't too big to fit the rest of the struct.
|
2010-07-29 10:20:19 +08:00
|
|
|
uint64_t TySizeInBytes =
|
|
|
|
getContext().getTypeSizeInChars(SourceTy).getQuantity();
|
2010-07-29 07:06:14 +08:00
|
|
|
|
|
|
|
// It is always safe to classify this as an integer type up to i64 that
|
|
|
|
// isn't larger than the structure.
|
|
|
|
switch (unsigned(TySizeInBytes-SourceOffset)) {
|
2010-07-29 10:20:19 +08:00
|
|
|
case 1: return llvm::Type::getInt8Ty(getVMContext());
|
|
|
|
case 2: return llvm::Type::getInt16Ty(getVMContext());
|
2010-07-29 07:06:14 +08:00
|
|
|
case 3:
|
2010-07-29 10:20:19 +08:00
|
|
|
case 4: return llvm::Type::getInt32Ty(getVMContext());
|
|
|
|
default: return llvm::Type::getInt64Ty(getVMContext());
|
2010-07-29 07:06:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-29 05:43:59 +08:00
|
|
|
ABIArgInfo X86_64ABIInfo::
|
2010-07-29 10:16:43 +08:00
|
|
|
classifyReturnType(QualType RetTy) const {
|
2009-06-06 06:08:42 +08:00
|
|
|
// AMD64-ABI 3.2.3p4: Rule 1. Classify the return type with the
|
|
|
|
// classification algorithm.
|
|
|
|
X86_64ABIInfo::Class Lo, Hi;
|
Change X86_64ABIInfo to have ASTContext and TargetData ivars to
avoid passing ASTContext down through all the methods it has.
When classifying an argument, or argument piece, as INTEGER, check
to see if we have a pointer at exactly the same offset in the
preferred type. If so, use that pointer type instead of i64. This
allows us to compile A function taking a stringref into something
like this:
define i8* @foo(i64 %D.coerce0, i8* %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=4]
%0 = getelementptr %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
store i64 %D.coerce0, i64* %0
%1 = getelementptr %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
store i8* %D.coerce1, i8** %1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
instead of this:
define i8* @foo(i64 %D.coerce0, i64 %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=3]
%0 = insertvalue %0 undef, i64 %D.coerce0, 0 ; <%0> [#uses=1]
%1 = insertvalue %0 %0, i64 %D.coerce1, 1 ; <%0> [#uses=1]
%2 = bitcast %struct.DeclGroup* %D to %0* ; <%0*> [#uses=1]
store %0 %1, %0* %2, align 1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
This implements rdar://7375902 - [codegen quality] clang x86-64 ABI lowering code punishing StringRef
llvm-svn: 107123
2010-06-29 14:01:59 +08:00
|
|
|
classify(RetTy, 0, Lo, Hi);
|
2009-06-06 06:08:42 +08:00
|
|
|
|
|
|
|
// Check some invariants.
|
|
|
|
assert((Hi != Memory || Lo == Memory) && "Invalid memory classification.");
|
|
|
|
assert((Lo != NoClass || Hi == NoClass) && "Invalid null classification.");
|
|
|
|
assert((Hi != SSEUp || Lo == SSE) && "Invalid SSEUp classification.");
|
|
|
|
|
|
|
|
const llvm::Type *ResType = 0;
|
|
|
|
switch (Lo) {
|
|
|
|
case NoClass:
|
|
|
|
return ABIArgInfo::getIgnore();
|
|
|
|
|
|
|
|
case SSEUp:
|
|
|
|
case X87Up:
|
|
|
|
assert(0 && "Invalid classification for lo word.");
|
|
|
|
|
|
|
|
// AMD64-ABI 3.2.3p4: Rule 2. Types of class memory are returned via
|
|
|
|
// hidden argument.
|
|
|
|
case Memory:
|
Change X86_64ABIInfo to have ASTContext and TargetData ivars to
avoid passing ASTContext down through all the methods it has.
When classifying an argument, or argument piece, as INTEGER, check
to see if we have a pointer at exactly the same offset in the
preferred type. If so, use that pointer type instead of i64. This
allows us to compile A function taking a stringref into something
like this:
define i8* @foo(i64 %D.coerce0, i8* %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=4]
%0 = getelementptr %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
store i64 %D.coerce0, i64* %0
%1 = getelementptr %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
store i8* %D.coerce1, i8** %1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
instead of this:
define i8* @foo(i64 %D.coerce0, i64 %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=3]
%0 = insertvalue %0 undef, i64 %D.coerce0, 0 ; <%0> [#uses=1]
%1 = insertvalue %0 %0, i64 %D.coerce1, 1 ; <%0> [#uses=1]
%2 = bitcast %struct.DeclGroup* %D to %0* ; <%0*> [#uses=1]
store %0 %1, %0* %2, align 1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
This implements rdar://7375902 - [codegen quality] clang x86-64 ABI lowering code punishing StringRef
llvm-svn: 107123
2010-06-29 14:01:59 +08:00
|
|
|
return getIndirectReturnResult(RetTy);
|
2009-06-06 06:08:42 +08:00
|
|
|
|
|
|
|
// AMD64-ABI 3.2.3p4: Rule 3. If the class is INTEGER, the next
|
|
|
|
// available register of the sequence %rax, %rdx is used.
|
|
|
|
case Integer:
|
2010-07-29 12:51:12 +08:00
|
|
|
ResType = Get8ByteTypeAtOffset(CGT.ConvertTypeRecursive(RetTy), 0, RetTy,0);
|
2010-07-29 07:06:14 +08:00
|
|
|
break;
|
2009-06-06 06:08:42 +08:00
|
|
|
|
|
|
|
// AMD64-ABI 3.2.3p4: Rule 4. If the class is SSE, the next
|
|
|
|
// available SSE register of the sequence %xmm0, %xmm1 is used.
|
|
|
|
case SSE:
|
2010-07-29 10:01:43 +08:00
|
|
|
ResType = llvm::Type::getDoubleTy(getVMContext());
|
2010-07-29 07:12:33 +08:00
|
|
|
break;
|
2009-06-06 06:08:42 +08:00
|
|
|
|
|
|
|
// AMD64-ABI 3.2.3p4: Rule 6. If the class is X87, the value is
|
|
|
|
// returned on the X87 stack in %st0 as 80-bit x87 number.
|
|
|
|
case X87:
|
2010-07-29 10:01:43 +08:00
|
|
|
ResType = llvm::Type::getX86_FP80Ty(getVMContext());
|
2010-07-29 07:12:33 +08:00
|
|
|
break;
|
2009-06-06 06:08:42 +08:00
|
|
|
|
|
|
|
// AMD64-ABI 3.2.3p4: Rule 8. If the class is COMPLEX_X87, the real
|
|
|
|
// part of the value is returned in %st0 and the imaginary part in
|
|
|
|
// %st1.
|
|
|
|
case ComplexX87:
|
|
|
|
assert(Hi == ComplexX87 && "Unexpected ComplexX87 classification.");
|
2010-07-29 10:16:43 +08:00
|
|
|
ResType = llvm::StructType::get(getVMContext(),
|
2010-07-29 10:01:43 +08:00
|
|
|
llvm::Type::getX86_FP80Ty(getVMContext()),
|
|
|
|
llvm::Type::getX86_FP80Ty(getVMContext()),
|
2009-06-06 06:08:42 +08:00
|
|
|
NULL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (Hi) {
|
|
|
|
// Memory was handled previously and X87 should
|
|
|
|
// never occur as a hi class.
|
|
|
|
case Memory:
|
|
|
|
case X87:
|
|
|
|
assert(0 && "Invalid classification for hi word.");
|
|
|
|
|
|
|
|
case ComplexX87: // Previously handled.
|
2010-07-29 07:12:33 +08:00
|
|
|
case NoClass:
|
|
|
|
break;
|
2009-06-06 06:08:42 +08:00
|
|
|
|
2010-07-29 07:06:14 +08:00
|
|
|
case Integer: {
|
2010-07-29 12:51:12 +08:00
|
|
|
const llvm::Type *HiType =
|
|
|
|
Get8ByteTypeAtOffset(CGT.ConvertTypeRecursive(RetTy), 8, RetTy, 8);
|
2010-07-29 10:16:43 +08:00
|
|
|
ResType = llvm::StructType::get(getVMContext(), ResType, HiType, NULL);
|
2009-06-06 06:08:42 +08:00
|
|
|
break;
|
2010-07-29 07:06:14 +08:00
|
|
|
}
|
2009-06-06 06:08:42 +08:00
|
|
|
case SSE:
|
2010-07-29 10:16:43 +08:00
|
|
|
ResType = llvm::StructType::get(getVMContext(), ResType,
|
|
|
|
llvm::Type::getDoubleTy(getVMContext()),
|
|
|
|
NULL);
|
2009-06-06 06:08:42 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
// AMD64-ABI 3.2.3p4: Rule 5. If the class is SSEUP, the eightbyte
|
|
|
|
// is passed in the upper half of the last used SSE register.
|
|
|
|
//
|
|
|
|
// SSEUP should always be preceeded by SSE, just widen.
|
|
|
|
case SSEUp:
|
|
|
|
assert(Lo == SSE && "Unexpected SSEUp classification.");
|
2010-07-29 12:56:46 +08:00
|
|
|
ResType = Get16ByteVectorType(RetTy);
|
2009-06-06 06:08:42 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
// AMD64-ABI 3.2.3p4: Rule 7. If the class is X87UP, the value is
|
|
|
|
// returned together with the previous X87 value in %st0.
|
|
|
|
case X87Up:
|
|
|
|
// If X87Up is preceeded by X87, we don't need to do
|
|
|
|
// anything. However, in some cases with unions it may not be
|
|
|
|
// preceeded by X87. In such situations we follow gcc and pass the
|
|
|
|
// extra bits in an SSE reg.
|
|
|
|
if (Lo != X87)
|
2010-07-29 10:16:43 +08:00
|
|
|
ResType = llvm::StructType::get(getVMContext(), ResType,
|
|
|
|
llvm::Type::getDoubleTy(getVMContext()),
|
|
|
|
NULL);
|
2009-06-06 06:08:42 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
Change X86_64ABIInfo to have ASTContext and TargetData ivars to
avoid passing ASTContext down through all the methods it has.
When classifying an argument, or argument piece, as INTEGER, check
to see if we have a pointer at exactly the same offset in the
preferred type. If so, use that pointer type instead of i64. This
allows us to compile A function taking a stringref into something
like this:
define i8* @foo(i64 %D.coerce0, i8* %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=4]
%0 = getelementptr %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
store i64 %D.coerce0, i64* %0
%1 = getelementptr %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
store i8* %D.coerce1, i8** %1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
instead of this:
define i8* @foo(i64 %D.coerce0, i64 %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=3]
%0 = insertvalue %0 undef, i64 %D.coerce0, 0 ; <%0> [#uses=1]
%1 = insertvalue %0 %0, i64 %D.coerce1, 1 ; <%0> [#uses=1]
%2 = bitcast %struct.DeclGroup* %D to %0* ; <%0*> [#uses=1]
store %0 %1, %0* %2, align 1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
This implements rdar://7375902 - [codegen quality] clang x86-64 ABI lowering code punishing StringRef
llvm-svn: 107123
2010-06-29 14:01:59 +08:00
|
|
|
return getCoerceResult(RetTy, ResType);
|
|
|
|
}
|
|
|
|
|
2010-07-29 10:16:43 +08:00
|
|
|
ABIArgInfo X86_64ABIInfo::classifyArgumentType(QualType Ty, unsigned &neededInt,
|
2010-07-29 12:41:05 +08:00
|
|
|
unsigned &neededSSE) const {
|
2009-06-06 06:08:42 +08:00
|
|
|
X86_64ABIInfo::Class Lo, Hi;
|
Change X86_64ABIInfo to have ASTContext and TargetData ivars to
avoid passing ASTContext down through all the methods it has.
When classifying an argument, or argument piece, as INTEGER, check
to see if we have a pointer at exactly the same offset in the
preferred type. If so, use that pointer type instead of i64. This
allows us to compile A function taking a stringref into something
like this:
define i8* @foo(i64 %D.coerce0, i8* %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=4]
%0 = getelementptr %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
store i64 %D.coerce0, i64* %0
%1 = getelementptr %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
store i8* %D.coerce1, i8** %1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
instead of this:
define i8* @foo(i64 %D.coerce0, i64 %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=3]
%0 = insertvalue %0 undef, i64 %D.coerce0, 0 ; <%0> [#uses=1]
%1 = insertvalue %0 %0, i64 %D.coerce1, 1 ; <%0> [#uses=1]
%2 = bitcast %struct.DeclGroup* %D to %0* ; <%0*> [#uses=1]
store %0 %1, %0* %2, align 1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
This implements rdar://7375902 - [codegen quality] clang x86-64 ABI lowering code punishing StringRef
llvm-svn: 107123
2010-06-29 14:01:59 +08:00
|
|
|
classify(Ty, 0, Lo, Hi);
|
2010-07-29 12:41:05 +08:00
|
|
|
|
2009-06-06 06:08:42 +08:00
|
|
|
// Check some invariants.
|
|
|
|
// FIXME: Enforce these by construction.
|
|
|
|
assert((Hi != Memory || Lo == Memory) && "Invalid memory classification.");
|
|
|
|
assert((Lo != NoClass || Hi == NoClass) && "Invalid null classification.");
|
|
|
|
assert((Hi != SSEUp || Lo == SSE) && "Invalid SSEUp classification.");
|
|
|
|
|
|
|
|
neededInt = 0;
|
|
|
|
neededSSE = 0;
|
|
|
|
const llvm::Type *ResType = 0;
|
|
|
|
switch (Lo) {
|
|
|
|
case NoClass:
|
|
|
|
return ABIArgInfo::getIgnore();
|
|
|
|
|
|
|
|
// AMD64-ABI 3.2.3p3: Rule 1. If the class is MEMORY, pass the argument
|
|
|
|
// on the stack.
|
|
|
|
case Memory:
|
|
|
|
|
|
|
|
// AMD64-ABI 3.2.3p3: Rule 5. If the class is X87, X87UP or
|
|
|
|
// COMPLEX_X87, it is passed in memory.
|
|
|
|
case X87:
|
|
|
|
case ComplexX87:
|
Change X86_64ABIInfo to have ASTContext and TargetData ivars to
avoid passing ASTContext down through all the methods it has.
When classifying an argument, or argument piece, as INTEGER, check
to see if we have a pointer at exactly the same offset in the
preferred type. If so, use that pointer type instead of i64. This
allows us to compile A function taking a stringref into something
like this:
define i8* @foo(i64 %D.coerce0, i8* %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=4]
%0 = getelementptr %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
store i64 %D.coerce0, i64* %0
%1 = getelementptr %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
store i8* %D.coerce1, i8** %1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
instead of this:
define i8* @foo(i64 %D.coerce0, i64 %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=3]
%0 = insertvalue %0 undef, i64 %D.coerce0, 0 ; <%0> [#uses=1]
%1 = insertvalue %0 %0, i64 %D.coerce1, 1 ; <%0> [#uses=1]
%2 = bitcast %struct.DeclGroup* %D to %0* ; <%0*> [#uses=1]
store %0 %1, %0* %2, align 1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
This implements rdar://7375902 - [codegen quality] clang x86-64 ABI lowering code punishing StringRef
llvm-svn: 107123
2010-06-29 14:01:59 +08:00
|
|
|
return getIndirectResult(Ty);
|
2009-06-06 06:08:42 +08:00
|
|
|
|
|
|
|
case SSEUp:
|
|
|
|
case X87Up:
|
|
|
|
assert(0 && "Invalid classification for lo word.");
|
|
|
|
|
|
|
|
// AMD64-ABI 3.2.3p3: Rule 2. If the class is INTEGER, the next
|
|
|
|
// available register of the sequence %rdi, %rsi, %rdx, %rcx, %r8
|
|
|
|
// and %r9 is used.
|
|
|
|
case Integer:
|
Change X86_64ABIInfo to have ASTContext and TargetData ivars to
avoid passing ASTContext down through all the methods it has.
When classifying an argument, or argument piece, as INTEGER, check
to see if we have a pointer at exactly the same offset in the
preferred type. If so, use that pointer type instead of i64. This
allows us to compile A function taking a stringref into something
like this:
define i8* @foo(i64 %D.coerce0, i8* %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=4]
%0 = getelementptr %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
store i64 %D.coerce0, i64* %0
%1 = getelementptr %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
store i8* %D.coerce1, i8** %1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
instead of this:
define i8* @foo(i64 %D.coerce0, i64 %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=3]
%0 = insertvalue %0 undef, i64 %D.coerce0, 0 ; <%0> [#uses=1]
%1 = insertvalue %0 %0, i64 %D.coerce1, 1 ; <%0> [#uses=1]
%2 = bitcast %struct.DeclGroup* %D to %0* ; <%0*> [#uses=1]
store %0 %1, %0* %2, align 1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
This implements rdar://7375902 - [codegen quality] clang x86-64 ABI lowering code punishing StringRef
llvm-svn: 107123
2010-06-29 14:01:59 +08:00
|
|
|
++neededInt;
|
2010-07-29 12:41:05 +08:00
|
|
|
|
2010-07-29 06:44:07 +08:00
|
|
|
// Pick an 8-byte type based on the preferred type.
|
2010-07-29 12:51:12 +08:00
|
|
|
ResType = Get8ByteTypeAtOffset(CGT.ConvertTypeRecursive(Ty), 0, Ty, 0);
|
2009-06-06 06:08:42 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
// AMD64-ABI 3.2.3p3: Rule 3. If the class is SSE, the next
|
|
|
|
// available SSE register is used, the registers are taken in the
|
|
|
|
// order from %xmm0 to %xmm7.
|
|
|
|
case SSE:
|
|
|
|
++neededSSE;
|
2010-07-29 10:16:43 +08:00
|
|
|
ResType = llvm::Type::getDoubleTy(getVMContext());
|
2009-06-06 06:08:42 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (Hi) {
|
|
|
|
// Memory was handled previously, ComplexX87 and X87 should
|
|
|
|
// never occur as hi classes, and X87Up must be preceed by X87,
|
|
|
|
// which is passed in memory.
|
|
|
|
case Memory:
|
|
|
|
case X87:
|
|
|
|
case ComplexX87:
|
|
|
|
assert(0 && "Invalid classification for hi word.");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NoClass: break;
|
Change X86_64ABIInfo to have ASTContext and TargetData ivars to
avoid passing ASTContext down through all the methods it has.
When classifying an argument, or argument piece, as INTEGER, check
to see if we have a pointer at exactly the same offset in the
preferred type. If so, use that pointer type instead of i64. This
allows us to compile A function taking a stringref into something
like this:
define i8* @foo(i64 %D.coerce0, i8* %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=4]
%0 = getelementptr %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
store i64 %D.coerce0, i64* %0
%1 = getelementptr %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
store i8* %D.coerce1, i8** %1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
instead of this:
define i8* @foo(i64 %D.coerce0, i64 %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=3]
%0 = insertvalue %0 undef, i64 %D.coerce0, 0 ; <%0> [#uses=1]
%1 = insertvalue %0 %0, i64 %D.coerce1, 1 ; <%0> [#uses=1]
%2 = bitcast %struct.DeclGroup* %D to %0* ; <%0*> [#uses=1]
store %0 %1, %0* %2, align 1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
This implements rdar://7375902 - [codegen quality] clang x86-64 ABI lowering code punishing StringRef
llvm-svn: 107123
2010-06-29 14:01:59 +08:00
|
|
|
|
|
|
|
case Integer: {
|
2009-06-06 06:08:42 +08:00
|
|
|
++neededInt;
|
2010-07-29 06:44:07 +08:00
|
|
|
// Pick an 8-byte type based on the preferred type.
|
2010-07-29 12:51:12 +08:00
|
|
|
const llvm::Type *HiType =
|
|
|
|
Get8ByteTypeAtOffset(CGT.ConvertTypeRecursive(Ty), 8, Ty, 8);
|
2010-07-29 10:16:43 +08:00
|
|
|
ResType = llvm::StructType::get(getVMContext(), ResType, HiType, NULL);
|
2009-06-06 06:08:42 +08:00
|
|
|
break;
|
Change X86_64ABIInfo to have ASTContext and TargetData ivars to
avoid passing ASTContext down through all the methods it has.
When classifying an argument, or argument piece, as INTEGER, check
to see if we have a pointer at exactly the same offset in the
preferred type. If so, use that pointer type instead of i64. This
allows us to compile A function taking a stringref into something
like this:
define i8* @foo(i64 %D.coerce0, i8* %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=4]
%0 = getelementptr %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
store i64 %D.coerce0, i64* %0
%1 = getelementptr %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
store i8* %D.coerce1, i8** %1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
instead of this:
define i8* @foo(i64 %D.coerce0, i64 %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=3]
%0 = insertvalue %0 undef, i64 %D.coerce0, 0 ; <%0> [#uses=1]
%1 = insertvalue %0 %0, i64 %D.coerce1, 1 ; <%0> [#uses=1]
%2 = bitcast %struct.DeclGroup* %D to %0* ; <%0*> [#uses=1]
store %0 %1, %0* %2, align 1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
This implements rdar://7375902 - [codegen quality] clang x86-64 ABI lowering code punishing StringRef
llvm-svn: 107123
2010-06-29 14:01:59 +08:00
|
|
|
}
|
2009-06-06 06:08:42 +08:00
|
|
|
|
|
|
|
// X87Up generally doesn't occur here (long double is passed in
|
|
|
|
// memory), except in situations involving unions.
|
|
|
|
case X87Up:
|
|
|
|
case SSE:
|
2010-07-29 10:16:43 +08:00
|
|
|
ResType = llvm::StructType::get(getVMContext(), ResType,
|
|
|
|
llvm::Type::getDoubleTy(getVMContext()),
|
|
|
|
NULL);
|
2009-06-06 06:08:42 +08:00
|
|
|
++neededSSE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
// AMD64-ABI 3.2.3p3: Rule 4. If the class is SSEUP, the
|
|
|
|
// eightbyte is passed in the upper half of the last used SSE
|
2010-07-29 07:47:21 +08:00
|
|
|
// register. This only happens when 128-bit vectors are passed.
|
2009-06-06 06:08:42 +08:00
|
|
|
case SSEUp:
|
2010-07-29 07:47:21 +08:00
|
|
|
assert(Lo == SSE && "Unexpected SSEUp classification");
|
2010-07-29 12:56:46 +08:00
|
|
|
ResType = Get16ByteVectorType(Ty);
|
2009-06-06 06:08:42 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
Change X86_64ABIInfo to have ASTContext and TargetData ivars to
avoid passing ASTContext down through all the methods it has.
When classifying an argument, or argument piece, as INTEGER, check
to see if we have a pointer at exactly the same offset in the
preferred type. If so, use that pointer type instead of i64. This
allows us to compile A function taking a stringref into something
like this:
define i8* @foo(i64 %D.coerce0, i8* %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=4]
%0 = getelementptr %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
store i64 %D.coerce0, i64* %0
%1 = getelementptr %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
store i8* %D.coerce1, i8** %1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
instead of this:
define i8* @foo(i64 %D.coerce0, i64 %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=3]
%0 = insertvalue %0 undef, i64 %D.coerce0, 0 ; <%0> [#uses=1]
%1 = insertvalue %0 %0, i64 %D.coerce1, 1 ; <%0> [#uses=1]
%2 = bitcast %struct.DeclGroup* %D to %0* ; <%0*> [#uses=1]
store %0 %1, %0* %2, align 1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
This implements rdar://7375902 - [codegen quality] clang x86-64 ABI lowering code punishing StringRef
llvm-svn: 107123
2010-06-29 14:01:59 +08:00
|
|
|
return getCoerceResult(Ty, ResType);
|
2009-06-06 06:08:42 +08:00
|
|
|
}
|
|
|
|
|
2010-07-29 10:31:05 +08:00
|
|
|
void X86_64ABIInfo::computeInfo(CGFunctionInfo &FI) const {
|
2010-07-29 12:41:05 +08:00
|
|
|
|
2010-07-29 10:16:43 +08:00
|
|
|
FI.getReturnInfo() = classifyReturnType(FI.getReturnType());
|
2009-06-06 06:08:42 +08:00
|
|
|
|
|
|
|
// Keep track of the number of assigned registers.
|
|
|
|
unsigned freeIntRegs = 6, freeSSERegs = 8;
|
|
|
|
|
|
|
|
// If the return value is indirect, then the hidden argument is consuming one
|
|
|
|
// integer register.
|
|
|
|
if (FI.getReturnInfo().isIndirect())
|
|
|
|
--freeIntRegs;
|
|
|
|
|
|
|
|
// AMD64-ABI 3.2.3p3: Once arguments are classified, the registers
|
|
|
|
// get assigned (in left-to-right order) for passing as follows...
|
|
|
|
for (CGFunctionInfo::arg_iterator it = FI.arg_begin(), ie = FI.arg_end();
|
|
|
|
it != ie; ++it) {
|
|
|
|
unsigned neededInt, neededSSE;
|
2010-07-29 12:41:05 +08:00
|
|
|
it->info = classifyArgumentType(it->type, neededInt, neededSSE);
|
2009-06-06 06:08:42 +08:00
|
|
|
|
|
|
|
// AMD64-ABI 3.2.3p3: If there are no registers available for any
|
|
|
|
// eightbyte of an argument, the whole argument is passed on the
|
|
|
|
// stack. If registers have already been assigned for some
|
|
|
|
// eightbytes of such an argument, the assignments get reverted.
|
|
|
|
if (freeIntRegs >= neededInt && freeSSERegs >= neededSSE) {
|
|
|
|
freeIntRegs -= neededInt;
|
|
|
|
freeSSERegs -= neededSSE;
|
|
|
|
} else {
|
Change X86_64ABIInfo to have ASTContext and TargetData ivars to
avoid passing ASTContext down through all the methods it has.
When classifying an argument, or argument piece, as INTEGER, check
to see if we have a pointer at exactly the same offset in the
preferred type. If so, use that pointer type instead of i64. This
allows us to compile A function taking a stringref into something
like this:
define i8* @foo(i64 %D.coerce0, i8* %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=4]
%0 = getelementptr %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
store i64 %D.coerce0, i64* %0
%1 = getelementptr %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
store i8* %D.coerce1, i8** %1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
instead of this:
define i8* @foo(i64 %D.coerce0, i64 %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=3]
%0 = insertvalue %0 undef, i64 %D.coerce0, 0 ; <%0> [#uses=1]
%1 = insertvalue %0 %0, i64 %D.coerce1, 1 ; <%0> [#uses=1]
%2 = bitcast %struct.DeclGroup* %D to %0* ; <%0*> [#uses=1]
store %0 %1, %0* %2, align 1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
This implements rdar://7375902 - [codegen quality] clang x86-64 ABI lowering code punishing StringRef
llvm-svn: 107123
2010-06-29 14:01:59 +08:00
|
|
|
it->info = getIndirectResult(it->type);
|
2009-06-06 06:08:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static llvm::Value *EmitVAArgFromMemory(llvm::Value *VAListAddr,
|
|
|
|
QualType Ty,
|
|
|
|
CodeGenFunction &CGF) {
|
|
|
|
llvm::Value *overflow_arg_area_p =
|
|
|
|
CGF.Builder.CreateStructGEP(VAListAddr, 2, "overflow_arg_area_p");
|
|
|
|
llvm::Value *overflow_arg_area =
|
|
|
|
CGF.Builder.CreateLoad(overflow_arg_area_p, "overflow_arg_area");
|
|
|
|
|
|
|
|
// AMD64-ABI 3.5.7p5: Step 7. Align l->overflow_arg_area upwards to a 16
|
|
|
|
// byte boundary if alignment needed by type exceeds 8 byte boundary.
|
|
|
|
uint64_t Align = CGF.getContext().getTypeAlign(Ty) / 8;
|
|
|
|
if (Align > 8) {
|
|
|
|
// Note that we follow the ABI & gcc here, even though the type
|
|
|
|
// could in theory have an alignment greater than 16. This case
|
|
|
|
// shouldn't ever matter in practice.
|
|
|
|
|
|
|
|
// overflow_arg_area = (overflow_arg_area + 15) & ~15;
|
2009-08-14 05:57:51 +08:00
|
|
|
llvm::Value *Offset =
|
2010-06-27 15:15:29 +08:00
|
|
|
llvm::ConstantInt::get(CGF.Int32Ty, 15);
|
2009-06-06 06:08:42 +08:00
|
|
|
overflow_arg_area = CGF.Builder.CreateGEP(overflow_arg_area, Offset);
|
|
|
|
llvm::Value *AsInt = CGF.Builder.CreatePtrToInt(overflow_arg_area,
|
2010-06-27 15:15:29 +08:00
|
|
|
CGF.Int64Ty);
|
|
|
|
llvm::Value *Mask = llvm::ConstantInt::get(CGF.Int64Ty, ~15LL);
|
2009-06-06 06:08:42 +08:00
|
|
|
overflow_arg_area =
|
|
|
|
CGF.Builder.CreateIntToPtr(CGF.Builder.CreateAnd(AsInt, Mask),
|
|
|
|
overflow_arg_area->getType(),
|
|
|
|
"overflow_arg_area.align");
|
|
|
|
}
|
|
|
|
|
|
|
|
// AMD64-ABI 3.5.7p5: Step 8. Fetch type from l->overflow_arg_area.
|
|
|
|
const llvm::Type *LTy = CGF.ConvertTypeForMem(Ty);
|
|
|
|
llvm::Value *Res =
|
|
|
|
CGF.Builder.CreateBitCast(overflow_arg_area,
|
2009-07-30 06:16:19 +08:00
|
|
|
llvm::PointerType::getUnqual(LTy));
|
2009-06-06 06:08:42 +08:00
|
|
|
|
|
|
|
// AMD64-ABI 3.5.7p5: Step 9. Set l->overflow_arg_area to:
|
|
|
|
// l->overflow_arg_area + sizeof(type).
|
|
|
|
// AMD64-ABI 3.5.7p5: Step 10. Align l->overflow_arg_area upwards to
|
|
|
|
// an 8 byte boundary.
|
|
|
|
|
|
|
|
uint64_t SizeInBytes = (CGF.getContext().getTypeSize(Ty) + 7) / 8;
|
2009-08-14 05:57:51 +08:00
|
|
|
llvm::Value *Offset =
|
2010-06-27 15:15:29 +08:00
|
|
|
llvm::ConstantInt::get(CGF.Int32Ty, (SizeInBytes + 7) & ~7);
|
2009-06-06 06:08:42 +08:00
|
|
|
overflow_arg_area = CGF.Builder.CreateGEP(overflow_arg_area, Offset,
|
|
|
|
"overflow_arg_area.next");
|
|
|
|
CGF.Builder.CreateStore(overflow_arg_area, overflow_arg_area_p);
|
|
|
|
|
|
|
|
// AMD64-ABI 3.5.7p5: Step 11. Return the fetched type.
|
|
|
|
return Res;
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::Value *X86_64ABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
|
|
|
|
CodeGenFunction &CGF) const {
|
2009-07-15 07:10:40 +08:00
|
|
|
llvm::LLVMContext &VMContext = CGF.getLLVMContext();
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-06-06 06:08:42 +08:00
|
|
|
// Assume that va_list type is correct; should be pointer to LLVM type:
|
|
|
|
// struct {
|
|
|
|
// i32 gp_offset;
|
|
|
|
// i32 fp_offset;
|
|
|
|
// i8* overflow_arg_area;
|
|
|
|
// i8* reg_save_area;
|
|
|
|
// };
|
|
|
|
unsigned neededInt, neededSSE;
|
2010-03-12 02:19:55 +08:00
|
|
|
|
|
|
|
Ty = CGF.getContext().getCanonicalType(Ty);
|
2010-07-29 12:41:05 +08:00
|
|
|
ABIArgInfo AI = classifyArgumentType(Ty, neededInt, neededSSE);
|
2009-06-06 06:08:42 +08:00
|
|
|
|
|
|
|
// AMD64-ABI 3.5.7p5: Step 1. Determine whether type may be passed
|
|
|
|
// in the registers. If not go to step 7.
|
|
|
|
if (!neededInt && !neededSSE)
|
|
|
|
return EmitVAArgFromMemory(VAListAddr, Ty, CGF);
|
|
|
|
|
|
|
|
// AMD64-ABI 3.5.7p5: Step 2. Compute num_gp to hold the number of
|
|
|
|
// general purpose registers needed to pass type and num_fp to hold
|
|
|
|
// the number of floating point registers needed.
|
|
|
|
|
|
|
|
// AMD64-ABI 3.5.7p5: Step 3. Verify whether arguments fit into
|
|
|
|
// registers. In the case: l->gp_offset > 48 - num_gp * 8 or
|
|
|
|
// l->fp_offset > 304 - num_fp * 16 go to step 7.
|
|
|
|
//
|
|
|
|
// NOTE: 304 is a typo, there are (6 * 8 + 8 * 16) = 176 bytes of
|
|
|
|
// register save space).
|
|
|
|
|
|
|
|
llvm::Value *InRegs = 0;
|
|
|
|
llvm::Value *gp_offset_p = 0, *gp_offset = 0;
|
|
|
|
llvm::Value *fp_offset_p = 0, *fp_offset = 0;
|
|
|
|
if (neededInt) {
|
|
|
|
gp_offset_p = CGF.Builder.CreateStructGEP(VAListAddr, 0, "gp_offset_p");
|
|
|
|
gp_offset = CGF.Builder.CreateLoad(gp_offset_p, "gp_offset");
|
2010-06-29 05:43:59 +08:00
|
|
|
InRegs = llvm::ConstantInt::get(CGF.Int32Ty, 48 - neededInt * 8);
|
|
|
|
InRegs = CGF.Builder.CreateICmpULE(gp_offset, InRegs, "fits_in_gp");
|
2009-06-06 06:08:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (neededSSE) {
|
|
|
|
fp_offset_p = CGF.Builder.CreateStructGEP(VAListAddr, 1, "fp_offset_p");
|
|
|
|
fp_offset = CGF.Builder.CreateLoad(fp_offset_p, "fp_offset");
|
|
|
|
llvm::Value *FitsInFP =
|
2010-06-29 05:43:59 +08:00
|
|
|
llvm::ConstantInt::get(CGF.Int32Ty, 176 - neededSSE * 16);
|
|
|
|
FitsInFP = CGF.Builder.CreateICmpULE(fp_offset, FitsInFP, "fits_in_fp");
|
2009-06-06 06:08:42 +08:00
|
|
|
InRegs = InRegs ? CGF.Builder.CreateAnd(InRegs, FitsInFP) : FitsInFP;
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::BasicBlock *InRegBlock = CGF.createBasicBlock("vaarg.in_reg");
|
|
|
|
llvm::BasicBlock *InMemBlock = CGF.createBasicBlock("vaarg.in_mem");
|
|
|
|
llvm::BasicBlock *ContBlock = CGF.createBasicBlock("vaarg.end");
|
|
|
|
CGF.Builder.CreateCondBr(InRegs, InRegBlock, InMemBlock);
|
|
|
|
|
|
|
|
// Emit code to load the value if it was passed in registers.
|
|
|
|
|
|
|
|
CGF.EmitBlock(InRegBlock);
|
|
|
|
|
|
|
|
// AMD64-ABI 3.5.7p5: Step 4. Fetch type from l->reg_save_area with
|
|
|
|
// an offset of l->gp_offset and/or l->fp_offset. This may require
|
|
|
|
// copying to a temporary location in case the parameter is passed
|
|
|
|
// in different register classes or requires an alignment greater
|
|
|
|
// than 8 for general purpose registers and 16 for XMM registers.
|
|
|
|
//
|
|
|
|
// FIXME: This really results in shameful code when we end up needing to
|
|
|
|
// collect arguments from different places; often what should result in a
|
|
|
|
// simple assembling of a structure from scattered addresses has many more
|
|
|
|
// loads than necessary. Can we clean this up?
|
|
|
|
const llvm::Type *LTy = CGF.ConvertTypeForMem(Ty);
|
|
|
|
llvm::Value *RegAddr =
|
|
|
|
CGF.Builder.CreateLoad(CGF.Builder.CreateStructGEP(VAListAddr, 3),
|
|
|
|
"reg_save_area");
|
|
|
|
if (neededInt && neededSSE) {
|
|
|
|
// FIXME: Cleanup.
|
|
|
|
assert(AI.isCoerce() && "Unexpected ABI info for mixed regs");
|
|
|
|
const llvm::StructType *ST = cast<llvm::StructType>(AI.getCoerceToType());
|
|
|
|
llvm::Value *Tmp = CGF.CreateTempAlloca(ST);
|
|
|
|
assert(ST->getNumElements() == 2 && "Unexpected ABI info for mixed regs");
|
|
|
|
const llvm::Type *TyLo = ST->getElementType(0);
|
|
|
|
const llvm::Type *TyHi = ST->getElementType(1);
|
2010-02-16 00:14:01 +08:00
|
|
|
assert((TyLo->isFloatingPointTy() ^ TyHi->isFloatingPointTy()) &&
|
2009-06-06 06:08:42 +08:00
|
|
|
"Unexpected ABI info for mixed regs");
|
2009-07-30 06:16:19 +08:00
|
|
|
const llvm::Type *PTyLo = llvm::PointerType::getUnqual(TyLo);
|
|
|
|
const llvm::Type *PTyHi = llvm::PointerType::getUnqual(TyHi);
|
2009-06-06 06:08:42 +08:00
|
|
|
llvm::Value *GPAddr = CGF.Builder.CreateGEP(RegAddr, gp_offset);
|
|
|
|
llvm::Value *FPAddr = CGF.Builder.CreateGEP(RegAddr, fp_offset);
|
2010-02-16 00:14:01 +08:00
|
|
|
llvm::Value *RegLoAddr = TyLo->isFloatingPointTy() ? FPAddr : GPAddr;
|
|
|
|
llvm::Value *RegHiAddr = TyLo->isFloatingPointTy() ? GPAddr : FPAddr;
|
2009-06-06 06:08:42 +08:00
|
|
|
llvm::Value *V =
|
|
|
|
CGF.Builder.CreateLoad(CGF.Builder.CreateBitCast(RegLoAddr, PTyLo));
|
|
|
|
CGF.Builder.CreateStore(V, CGF.Builder.CreateStructGEP(Tmp, 0));
|
|
|
|
V = CGF.Builder.CreateLoad(CGF.Builder.CreateBitCast(RegHiAddr, PTyHi));
|
|
|
|
CGF.Builder.CreateStore(V, CGF.Builder.CreateStructGEP(Tmp, 1));
|
|
|
|
|
2009-07-15 07:10:40 +08:00
|
|
|
RegAddr = CGF.Builder.CreateBitCast(Tmp,
|
2009-07-30 06:16:19 +08:00
|
|
|
llvm::PointerType::getUnqual(LTy));
|
2009-06-06 06:08:42 +08:00
|
|
|
} else if (neededInt) {
|
|
|
|
RegAddr = CGF.Builder.CreateGEP(RegAddr, gp_offset);
|
|
|
|
RegAddr = CGF.Builder.CreateBitCast(RegAddr,
|
2009-07-30 06:16:19 +08:00
|
|
|
llvm::PointerType::getUnqual(LTy));
|
2010-06-29 04:05:43 +08:00
|
|
|
} else if (neededSSE == 1) {
|
|
|
|
RegAddr = CGF.Builder.CreateGEP(RegAddr, fp_offset);
|
|
|
|
RegAddr = CGF.Builder.CreateBitCast(RegAddr,
|
|
|
|
llvm::PointerType::getUnqual(LTy));
|
2009-06-06 06:08:42 +08:00
|
|
|
} else {
|
2010-06-29 04:05:43 +08:00
|
|
|
assert(neededSSE == 2 && "Invalid number of needed registers!");
|
|
|
|
// SSE registers are spaced 16 bytes apart in the register save
|
|
|
|
// area, we need to collect the two eightbytes together.
|
|
|
|
llvm::Value *RegAddrLo = CGF.Builder.CreateGEP(RegAddr, fp_offset);
|
2010-06-29 05:43:59 +08:00
|
|
|
llvm::Value *RegAddrHi = CGF.Builder.CreateConstGEP1_32(RegAddrLo, 16);
|
2010-06-29 04:05:43 +08:00
|
|
|
const llvm::Type *DoubleTy = llvm::Type::getDoubleTy(VMContext);
|
|
|
|
const llvm::Type *DblPtrTy =
|
|
|
|
llvm::PointerType::getUnqual(DoubleTy);
|
|
|
|
const llvm::StructType *ST = llvm::StructType::get(VMContext, DoubleTy,
|
|
|
|
DoubleTy, NULL);
|
|
|
|
llvm::Value *V, *Tmp = CGF.CreateTempAlloca(ST);
|
|
|
|
V = CGF.Builder.CreateLoad(CGF.Builder.CreateBitCast(RegAddrLo,
|
|
|
|
DblPtrTy));
|
|
|
|
CGF.Builder.CreateStore(V, CGF.Builder.CreateStructGEP(Tmp, 0));
|
|
|
|
V = CGF.Builder.CreateLoad(CGF.Builder.CreateBitCast(RegAddrHi,
|
|
|
|
DblPtrTy));
|
|
|
|
CGF.Builder.CreateStore(V, CGF.Builder.CreateStructGEP(Tmp, 1));
|
|
|
|
RegAddr = CGF.Builder.CreateBitCast(Tmp,
|
|
|
|
llvm::PointerType::getUnqual(LTy));
|
2009-06-06 06:08:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// AMD64-ABI 3.5.7p5: Step 5. Set:
|
|
|
|
// l->gp_offset = l->gp_offset + num_gp * 8
|
|
|
|
// l->fp_offset = l->fp_offset + num_fp * 16.
|
|
|
|
if (neededInt) {
|
2010-06-27 15:15:29 +08:00
|
|
|
llvm::Value *Offset = llvm::ConstantInt::get(CGF.Int32Ty, neededInt * 8);
|
2009-06-06 06:08:42 +08:00
|
|
|
CGF.Builder.CreateStore(CGF.Builder.CreateAdd(gp_offset, Offset),
|
|
|
|
gp_offset_p);
|
|
|
|
}
|
|
|
|
if (neededSSE) {
|
2010-06-27 15:15:29 +08:00
|
|
|
llvm::Value *Offset = llvm::ConstantInt::get(CGF.Int32Ty, neededSSE * 16);
|
2009-06-06 06:08:42 +08:00
|
|
|
CGF.Builder.CreateStore(CGF.Builder.CreateAdd(fp_offset, Offset),
|
|
|
|
fp_offset_p);
|
|
|
|
}
|
|
|
|
CGF.EmitBranch(ContBlock);
|
|
|
|
|
|
|
|
// Emit code to load the value if it was passed in memory.
|
|
|
|
|
|
|
|
CGF.EmitBlock(InMemBlock);
|
|
|
|
llvm::Value *MemAddr = EmitVAArgFromMemory(VAListAddr, Ty, CGF);
|
|
|
|
|
|
|
|
// Return the appropriate result.
|
|
|
|
|
|
|
|
CGF.EmitBlock(ContBlock);
|
|
|
|
llvm::PHINode *ResAddr = CGF.Builder.CreatePHI(RegAddr->getType(),
|
|
|
|
"vaarg.addr");
|
|
|
|
ResAddr->reserveOperandSpace(2);
|
|
|
|
ResAddr->addIncoming(RegAddr, InRegBlock);
|
|
|
|
ResAddr->addIncoming(MemAddr, InMemBlock);
|
|
|
|
return ResAddr;
|
|
|
|
}
|
|
|
|
|
2010-06-29 04:05:43 +08:00
|
|
|
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
2009-09-12 08:59:49 +08:00
|
|
|
// PIC16 ABI Implementation
|
2010-06-29 04:05:43 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2009-09-12 08:59:49 +08:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2009-06-06 06:08:42 +08:00
|
|
|
class PIC16ABIInfo : public ABIInfo {
|
2010-07-29 10:01:43 +08:00
|
|
|
public:
|
|
|
|
PIC16ABIInfo(CodeGenTypes &CGT) : ABIInfo(CGT) {}
|
|
|
|
|
2010-07-29 10:16:43 +08:00
|
|
|
ABIArgInfo classifyReturnType(QualType RetTy) const;
|
2009-06-06 06:08:42 +08:00
|
|
|
|
2010-07-29 10:16:43 +08:00
|
|
|
ABIArgInfo classifyArgumentType(QualType RetTy) const;
|
2009-06-06 06:08:42 +08:00
|
|
|
|
2010-07-29 10:31:05 +08:00
|
|
|
virtual void computeInfo(CGFunctionInfo &FI) const {
|
2010-07-29 10:16:43 +08:00
|
|
|
FI.getReturnInfo() = classifyReturnType(FI.getReturnType());
|
2009-06-06 06:08:42 +08:00
|
|
|
for (CGFunctionInfo::arg_iterator it = FI.arg_begin(), ie = FI.arg_end();
|
|
|
|
it != ie; ++it)
|
2010-07-29 10:16:43 +08:00
|
|
|
it->info = classifyArgumentType(it->type);
|
2009-06-06 06:08:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
|
|
|
|
CodeGenFunction &CGF) const;
|
|
|
|
};
|
|
|
|
|
2010-01-10 20:58:08 +08:00
|
|
|
class PIC16TargetCodeGenInfo : public TargetCodeGenInfo {
|
|
|
|
public:
|
2010-07-29 10:01:43 +08:00
|
|
|
PIC16TargetCodeGenInfo(CodeGenTypes &CGT)
|
|
|
|
: TargetCodeGenInfo(new PIC16ABIInfo(CGT)) {}
|
2010-01-10 20:58:08 +08:00
|
|
|
};
|
|
|
|
|
2009-09-12 08:59:49 +08:00
|
|
|
}
|
|
|
|
|
2010-07-29 10:16:43 +08:00
|
|
|
ABIArgInfo PIC16ABIInfo::classifyReturnType(QualType RetTy) const {
|
2009-06-06 06:08:42 +08:00
|
|
|
if (RetTy->isVoidType()) {
|
|
|
|
return ABIArgInfo::getIgnore();
|
|
|
|
} else {
|
|
|
|
return ABIArgInfo::getDirect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-29 10:16:43 +08:00
|
|
|
ABIArgInfo PIC16ABIInfo::classifyArgumentType(QualType Ty) const {
|
2009-06-06 06:08:42 +08:00
|
|
|
return ABIArgInfo::getDirect();
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::Value *PIC16ABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
|
2010-06-27 15:15:29 +08:00
|
|
|
CodeGenFunction &CGF) const {
|
2010-04-07 01:29:22 +08:00
|
|
|
const llvm::Type *BP = llvm::Type::getInt8PtrTy(CGF.getLLVMContext());
|
2010-02-17 10:25:52 +08:00
|
|
|
const llvm::Type *BPP = llvm::PointerType::getUnqual(BP);
|
|
|
|
|
|
|
|
CGBuilderTy &Builder = CGF.Builder;
|
|
|
|
llvm::Value *VAListAddrAsBPP = Builder.CreateBitCast(VAListAddr, BPP,
|
|
|
|
"ap");
|
|
|
|
llvm::Value *Addr = Builder.CreateLoad(VAListAddrAsBPP, "ap.cur");
|
|
|
|
llvm::Type *PTy =
|
|
|
|
llvm::PointerType::getUnqual(CGF.ConvertType(Ty));
|
|
|
|
llvm::Value *AddrTyped = Builder.CreateBitCast(Addr, PTy);
|
|
|
|
|
|
|
|
uint64_t Offset = CGF.getContext().getTypeSize(Ty) / 8;
|
|
|
|
|
|
|
|
llvm::Value *NextAddr =
|
|
|
|
Builder.CreateGEP(Addr, llvm::ConstantInt::get(
|
|
|
|
llvm::Type::getInt32Ty(CGF.getLLVMContext()), Offset),
|
|
|
|
"ap.next");
|
|
|
|
Builder.CreateStore(NextAddr, VAListAddrAsBPP);
|
|
|
|
|
|
|
|
return AddrTyped;
|
2009-06-06 06:08:42 +08:00
|
|
|
}
|
|
|
|
|
2010-02-17 10:25:52 +08:00
|
|
|
|
2010-03-11 08:10:12 +08:00
|
|
|
// PowerPC-32
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
class PPC32TargetCodeGenInfo : public DefaultTargetCodeGenInfo {
|
|
|
|
public:
|
2010-07-29 10:01:43 +08:00
|
|
|
PPC32TargetCodeGenInfo(CodeGenTypes &CGT) : DefaultTargetCodeGenInfo(CGT) {}
|
|
|
|
|
2010-03-11 08:10:12 +08:00
|
|
|
int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const {
|
|
|
|
// This is recovered from gcc output.
|
|
|
|
return 1; // r1 is the dedicated stack pointer
|
|
|
|
}
|
|
|
|
|
|
|
|
bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
|
|
|
|
llvm::Value *Address) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
PPC32TargetCodeGenInfo::initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
|
|
|
|
llvm::Value *Address) const {
|
|
|
|
// This is calculated from the LLVM and GCC tables and verified
|
|
|
|
// against gcc output. AFAIK all ABIs use the same encoding.
|
|
|
|
|
|
|
|
CodeGen::CGBuilderTy &Builder = CGF.Builder;
|
|
|
|
llvm::LLVMContext &Context = CGF.getLLVMContext();
|
|
|
|
|
|
|
|
const llvm::IntegerType *i8 = llvm::Type::getInt8Ty(Context);
|
|
|
|
llvm::Value *Four8 = llvm::ConstantInt::get(i8, 4);
|
|
|
|
llvm::Value *Eight8 = llvm::ConstantInt::get(i8, 8);
|
|
|
|
llvm::Value *Sixteen8 = llvm::ConstantInt::get(i8, 16);
|
|
|
|
|
|
|
|
// 0-31: r0-31, the 4-byte general-purpose registers
|
2010-05-27 14:19:26 +08:00
|
|
|
AssignToArrayRange(Builder, Address, Four8, 0, 31);
|
2010-03-11 08:10:12 +08:00
|
|
|
|
|
|
|
// 32-63: fp0-31, the 8-byte floating-point registers
|
2010-05-27 14:19:26 +08:00
|
|
|
AssignToArrayRange(Builder, Address, Eight8, 32, 63);
|
2010-03-11 08:10:12 +08:00
|
|
|
|
|
|
|
// 64-76 are various 4-byte special-purpose registers:
|
|
|
|
// 64: mq
|
|
|
|
// 65: lr
|
|
|
|
// 66: ctr
|
|
|
|
// 67: ap
|
|
|
|
// 68-75 cr0-7
|
|
|
|
// 76: xer
|
2010-05-27 14:19:26 +08:00
|
|
|
AssignToArrayRange(Builder, Address, Four8, 64, 76);
|
2010-03-11 08:10:12 +08:00
|
|
|
|
|
|
|
// 77-108: v0-31, the 16-byte vector registers
|
2010-05-27 14:19:26 +08:00
|
|
|
AssignToArrayRange(Builder, Address, Sixteen8, 77, 108);
|
2010-03-11 08:10:12 +08:00
|
|
|
|
|
|
|
// 109: vrsave
|
|
|
|
// 110: vscr
|
|
|
|
// 111: spe_acc
|
|
|
|
// 112: spefscr
|
|
|
|
// 113: sfp
|
2010-05-27 14:19:26 +08:00
|
|
|
AssignToArrayRange(Builder, Address, Four8, 109, 113);
|
2010-03-11 08:10:12 +08:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-29 04:05:43 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2009-09-12 08:59:49 +08:00
|
|
|
// ARM ABI Implementation
|
2010-06-29 04:05:43 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2009-09-12 08:59:49 +08:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2009-06-06 06:08:42 +08:00
|
|
|
class ARMABIInfo : public ABIInfo {
|
2009-09-12 09:00:39 +08:00
|
|
|
public:
|
|
|
|
enum ABIKind {
|
|
|
|
APCS = 0,
|
|
|
|
AAPCS = 1,
|
|
|
|
AAPCS_VFP
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
ABIKind Kind;
|
|
|
|
|
|
|
|
public:
|
2010-07-29 10:01:43 +08:00
|
|
|
ARMABIInfo(CodeGenTypes &CGT, ABIKind _Kind) : ABIInfo(CGT), Kind(_Kind) {}
|
2009-09-12 09:00:39 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
ABIKind getABIKind() const { return Kind; }
|
|
|
|
|
2010-07-29 10:16:43 +08:00
|
|
|
ABIArgInfo classifyReturnType(QualType RetTy) const;
|
|
|
|
ABIArgInfo classifyArgumentType(QualType RetTy) const;
|
2009-06-06 06:08:42 +08:00
|
|
|
|
2010-07-29 10:31:05 +08:00
|
|
|
virtual void computeInfo(CGFunctionInfo &FI) const;
|
2009-06-06 06:08:42 +08:00
|
|
|
|
|
|
|
virtual llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
|
|
|
|
CodeGenFunction &CGF) const;
|
|
|
|
};
|
|
|
|
|
2010-01-10 20:58:08 +08:00
|
|
|
class ARMTargetCodeGenInfo : public TargetCodeGenInfo {
|
|
|
|
public:
|
2010-07-29 10:01:43 +08:00
|
|
|
ARMTargetCodeGenInfo(CodeGenTypes &CGT, ARMABIInfo::ABIKind K)
|
|
|
|
:TargetCodeGenInfo(new ARMABIInfo(CGT, K)) {}
|
2010-03-06 08:35:14 +08:00
|
|
|
|
|
|
|
int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const {
|
|
|
|
return 13;
|
|
|
|
}
|
2010-01-10 20:58:08 +08:00
|
|
|
};
|
|
|
|
|
2009-09-12 08:59:49 +08:00
|
|
|
}
|
|
|
|
|
2010-07-29 10:31:05 +08:00
|
|
|
void ARMABIInfo::computeInfo(CGFunctionInfo &FI) const {
|
2010-07-29 10:16:43 +08:00
|
|
|
FI.getReturnInfo() = classifyReturnType(FI.getReturnType());
|
2009-06-06 06:08:42 +08:00
|
|
|
for (CGFunctionInfo::arg_iterator it = FI.arg_begin(), ie = FI.arg_end();
|
2010-07-29 10:16:43 +08:00
|
|
|
it != ie; ++it)
|
|
|
|
it->info = classifyArgumentType(it->type);
|
2009-09-12 09:00:39 +08:00
|
|
|
|
2010-07-29 10:16:43 +08:00
|
|
|
const llvm::Triple &Triple(getContext().Target.getTriple());
|
2010-06-17 00:13:39 +08:00
|
|
|
llvm::CallingConv::ID DefaultCC;
|
2010-06-17 03:01:17 +08:00
|
|
|
if (Triple.getEnvironmentName() == "gnueabi" ||
|
|
|
|
Triple.getEnvironmentName() == "eabi")
|
2010-06-17 00:13:39 +08:00
|
|
|
DefaultCC = llvm::CallingConv::ARM_AAPCS;
|
2010-06-17 03:01:17 +08:00
|
|
|
else
|
|
|
|
DefaultCC = llvm::CallingConv::ARM_APCS;
|
2010-06-17 00:13:39 +08:00
|
|
|
|
2009-09-12 09:00:39 +08:00
|
|
|
switch (getABIKind()) {
|
|
|
|
case APCS:
|
2010-06-17 00:13:39 +08:00
|
|
|
if (DefaultCC != llvm::CallingConv::ARM_APCS)
|
|
|
|
FI.setEffectiveCallingConvention(llvm::CallingConv::ARM_APCS);
|
2009-09-12 09:00:39 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case AAPCS:
|
2010-06-17 00:13:39 +08:00
|
|
|
if (DefaultCC != llvm::CallingConv::ARM_AAPCS)
|
|
|
|
FI.setEffectiveCallingConvention(llvm::CallingConv::ARM_AAPCS);
|
2009-09-12 09:00:39 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case AAPCS_VFP:
|
|
|
|
FI.setEffectiveCallingConvention(llvm::CallingConv::ARM_AAPCS_VFP);
|
|
|
|
break;
|
|
|
|
}
|
2009-06-06 06:08:42 +08:00
|
|
|
}
|
|
|
|
|
2010-07-29 10:16:43 +08:00
|
|
|
ABIArgInfo ARMABIInfo::classifyArgumentType(QualType Ty) const {
|
2010-02-03 04:10:50 +08:00
|
|
|
if (!CodeGenFunction::hasAggregateLLVMType(Ty)) {
|
|
|
|
// Treat an enum type as its underlying type.
|
|
|
|
if (const EnumType *EnumTy = Ty->getAs<EnumType>())
|
|
|
|
Ty = EnumTy->getDecl()->getIntegerType();
|
|
|
|
|
2009-06-06 17:36:29 +08:00
|
|
|
return (Ty->isPromotableIntegerType() ?
|
|
|
|
ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
|
2010-02-03 04:10:50 +08:00
|
|
|
}
|
2009-09-13 16:03:58 +08:00
|
|
|
|
2009-09-15 05:54:03 +08:00
|
|
|
// Ignore empty records.
|
2010-07-29 10:16:43 +08:00
|
|
|
if (isEmptyRecord(getContext(), Ty, true))
|
2009-09-15 05:54:03 +08:00
|
|
|
return ABIArgInfo::getIgnore();
|
|
|
|
|
2010-06-08 10:42:08 +08:00
|
|
|
// Structures with either a non-trivial destructor or a non-trivial
|
|
|
|
// copy constructor are always indirect.
|
|
|
|
if (isRecordWithNonTrivialDestructorOrCopyConstructor(Ty))
|
|
|
|
return ABIArgInfo::getIndirect(0, /*ByVal=*/false);
|
|
|
|
|
2009-06-06 06:08:42 +08:00
|
|
|
// FIXME: This is kind of nasty... but there isn't much choice because the ARM
|
|
|
|
// backend doesn't support byval.
|
|
|
|
// FIXME: This doesn't handle alignment > 64 bits.
|
|
|
|
const llvm::Type* ElemTy;
|
|
|
|
unsigned SizeRegs;
|
2010-07-29 10:16:43 +08:00
|
|
|
if (getContext().getTypeAlign(Ty) > 32) {
|
|
|
|
ElemTy = llvm::Type::getInt64Ty(getVMContext());
|
|
|
|
SizeRegs = (getContext().getTypeSize(Ty) + 63) / 64;
|
2009-06-06 06:08:42 +08:00
|
|
|
} else {
|
2010-07-29 10:16:43 +08:00
|
|
|
ElemTy = llvm::Type::getInt32Ty(getVMContext());
|
|
|
|
SizeRegs = (getContext().getTypeSize(Ty) + 31) / 32;
|
2009-06-06 06:08:42 +08:00
|
|
|
}
|
|
|
|
std::vector<const llvm::Type*> LLVMFields;
|
2009-07-30 06:16:19 +08:00
|
|
|
LLVMFields.push_back(llvm::ArrayType::get(ElemTy, SizeRegs));
|
2010-07-29 10:16:43 +08:00
|
|
|
const llvm::Type* STy = llvm::StructType::get(getVMContext(), LLVMFields,
|
|
|
|
true);
|
2009-06-06 06:08:42 +08:00
|
|
|
return ABIArgInfo::getCoerce(STy);
|
|
|
|
}
|
|
|
|
|
2010-07-29 10:16:43 +08:00
|
|
|
static bool isIntegerLikeType(QualType Ty, ASTContext &Context,
|
2009-09-13 16:03:58 +08:00
|
|
|
llvm::LLVMContext &VMContext) {
|
|
|
|
// APCS, C Language Calling Conventions, Non-Simple Return Values: A structure
|
|
|
|
// is called integer-like if its size is less than or equal to one word, and
|
|
|
|
// the offset of each of its addressable sub-fields is zero.
|
|
|
|
|
|
|
|
uint64_t Size = Context.getTypeSize(Ty);
|
|
|
|
|
|
|
|
// Check that the type fits in a word.
|
|
|
|
if (Size > 32)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// FIXME: Handle vector types!
|
|
|
|
if (Ty->isVectorType())
|
|
|
|
return false;
|
|
|
|
|
2009-09-14 10:20:34 +08:00
|
|
|
// Float types are never treated as "integer like".
|
|
|
|
if (Ty->isRealFloatingType())
|
|
|
|
return false;
|
|
|
|
|
2009-09-13 16:03:58 +08:00
|
|
|
// If this is a builtin or pointer type then it is ok.
|
2009-09-22 07:43:11 +08:00
|
|
|
if (Ty->getAs<BuiltinType>() || Ty->isPointerType())
|
2009-09-13 16:03:58 +08:00
|
|
|
return true;
|
|
|
|
|
2010-02-02 07:31:26 +08:00
|
|
|
// Small complex integer types are "integer like".
|
|
|
|
if (const ComplexType *CT = Ty->getAs<ComplexType>())
|
|
|
|
return isIntegerLikeType(CT->getElementType(), Context, VMContext);
|
2009-09-13 16:03:58 +08:00
|
|
|
|
|
|
|
// Single element and zero sized arrays should be allowed, by the definition
|
|
|
|
// above, but they are not.
|
|
|
|
|
|
|
|
// Otherwise, it must be a record type.
|
|
|
|
const RecordType *RT = Ty->getAs<RecordType>();
|
|
|
|
if (!RT) return false;
|
|
|
|
|
|
|
|
// Ignore records with flexible arrays.
|
|
|
|
const RecordDecl *RD = RT->getDecl();
|
|
|
|
if (RD->hasFlexibleArrayMember())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Check that all sub-fields are at offset 0, and are themselves "integer
|
|
|
|
// like".
|
|
|
|
const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD);
|
|
|
|
|
|
|
|
bool HadField = false;
|
|
|
|
unsigned idx = 0;
|
|
|
|
for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end();
|
|
|
|
i != e; ++i, ++idx) {
|
|
|
|
const FieldDecl *FD = *i;
|
|
|
|
|
2010-01-29 11:22:29 +08:00
|
|
|
// Bit-fields are not addressable, we only need to verify they are "integer
|
|
|
|
// like". We still have to disallow a subsequent non-bitfield, for example:
|
|
|
|
// struct { int : 0; int x }
|
|
|
|
// is non-integer like according to gcc.
|
|
|
|
if (FD->isBitField()) {
|
|
|
|
if (!RD->isUnion())
|
|
|
|
HadField = true;
|
|
|
|
|
|
|
|
if (!isIntegerLikeType(FD->getType(), Context, VMContext))
|
|
|
|
return false;
|
2009-09-13 16:03:58 +08:00
|
|
|
|
2010-01-29 11:22:29 +08:00
|
|
|
continue;
|
2009-09-13 16:03:58 +08:00
|
|
|
}
|
|
|
|
|
2010-01-29 11:22:29 +08:00
|
|
|
// Check if this field is at offset 0.
|
|
|
|
if (Layout.getFieldOffset(idx) != 0)
|
|
|
|
return false;
|
|
|
|
|
2009-09-13 16:03:58 +08:00
|
|
|
if (!isIntegerLikeType(FD->getType(), Context, VMContext))
|
|
|
|
return false;
|
|
|
|
|
2010-01-29 11:22:29 +08:00
|
|
|
// Only allow at most one field in a structure. This doesn't match the
|
|
|
|
// wording above, but follows gcc in situations with a field following an
|
|
|
|
// empty structure.
|
2009-09-13 16:03:58 +08:00
|
|
|
if (!RD->isUnion()) {
|
|
|
|
if (HadField)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
HadField = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-07-29 10:16:43 +08:00
|
|
|
ABIArgInfo ARMABIInfo::classifyReturnType(QualType RetTy) const {
|
2009-09-13 16:03:58 +08:00
|
|
|
if (RetTy->isVoidType())
|
2009-06-06 06:08:42 +08:00
|
|
|
return ABIArgInfo::getIgnore();
|
2009-09-13 16:03:58 +08:00
|
|
|
|
2010-02-03 04:10:50 +08:00
|
|
|
if (!CodeGenFunction::hasAggregateLLVMType(RetTy)) {
|
|
|
|
// Treat an enum type as its underlying type.
|
|
|
|
if (const EnumType *EnumTy = RetTy->getAs<EnumType>())
|
|
|
|
RetTy = EnumTy->getDecl()->getIntegerType();
|
|
|
|
|
2009-06-06 17:36:29 +08:00
|
|
|
return (RetTy->isPromotableIntegerType() ?
|
|
|
|
ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
|
2010-02-03 04:10:50 +08:00
|
|
|
}
|
2009-09-13 16:03:58 +08:00
|
|
|
|
2010-06-08 10:42:08 +08:00
|
|
|
// Structures with either a non-trivial destructor or a non-trivial
|
|
|
|
// copy constructor are always indirect.
|
|
|
|
if (isRecordWithNonTrivialDestructorOrCopyConstructor(RetTy))
|
|
|
|
return ABIArgInfo::getIndirect(0, /*ByVal=*/false);
|
|
|
|
|
2009-09-13 16:03:58 +08:00
|
|
|
// Are we following APCS?
|
|
|
|
if (getABIKind() == APCS) {
|
2010-07-29 10:16:43 +08:00
|
|
|
if (isEmptyRecord(getContext(), RetTy, false))
|
2009-09-13 16:03:58 +08:00
|
|
|
return ABIArgInfo::getIgnore();
|
|
|
|
|
2010-02-02 07:31:19 +08:00
|
|
|
// Complex types are all returned as packed integers.
|
|
|
|
//
|
|
|
|
// FIXME: Consider using 2 x vector types if the back end handles them
|
|
|
|
// correctly.
|
|
|
|
if (RetTy->isAnyComplexType())
|
2010-07-29 10:16:43 +08:00
|
|
|
return ABIArgInfo::getCoerce(llvm::IntegerType::get(getVMContext(),
|
|
|
|
getContext().getTypeSize(RetTy)));
|
2010-02-02 07:31:19 +08:00
|
|
|
|
2009-09-13 16:03:58 +08:00
|
|
|
// Integer like structures are returned in r0.
|
2010-07-29 10:16:43 +08:00
|
|
|
if (isIntegerLikeType(RetTy, getContext(), getVMContext())) {
|
2009-09-13 16:03:58 +08:00
|
|
|
// Return in the smallest viable integer type.
|
2010-07-29 10:16:43 +08:00
|
|
|
uint64_t Size = getContext().getTypeSize(RetTy);
|
2009-09-13 16:03:58 +08:00
|
|
|
if (Size <= 8)
|
2010-07-29 10:16:43 +08:00
|
|
|
return ABIArgInfo::getCoerce(llvm::Type::getInt8Ty(getVMContext()));
|
2009-09-13 16:03:58 +08:00
|
|
|
if (Size <= 16)
|
2010-07-29 10:16:43 +08:00
|
|
|
return ABIArgInfo::getCoerce(llvm::Type::getInt16Ty(getVMContext()));
|
|
|
|
return ABIArgInfo::getCoerce(llvm::Type::getInt32Ty(getVMContext()));
|
2009-09-13 16:03:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise return in memory.
|
|
|
|
return ABIArgInfo::getIndirect(0);
|
2009-06-06 06:08:42 +08:00
|
|
|
}
|
2009-09-13 16:03:58 +08:00
|
|
|
|
|
|
|
// Otherwise this is an AAPCS variant.
|
|
|
|
|
2010-07-29 10:16:43 +08:00
|
|
|
if (isEmptyRecord(getContext(), RetTy, true))
|
2009-09-14 08:56:55 +08:00
|
|
|
return ABIArgInfo::getIgnore();
|
|
|
|
|
2009-09-13 16:03:58 +08:00
|
|
|
// Aggregates <= 4 bytes are returned in r0; other aggregates
|
|
|
|
// are returned indirectly.
|
2010-07-29 10:16:43 +08:00
|
|
|
uint64_t Size = getContext().getTypeSize(RetTy);
|
2009-09-14 08:56:55 +08:00
|
|
|
if (Size <= 32) {
|
|
|
|
// Return in the smallest viable integer type.
|
|
|
|
if (Size <= 8)
|
2010-07-29 10:16:43 +08:00
|
|
|
return ABIArgInfo::getCoerce(llvm::Type::getInt8Ty(getVMContext()));
|
2009-09-14 08:56:55 +08:00
|
|
|
if (Size <= 16)
|
2010-07-29 10:16:43 +08:00
|
|
|
return ABIArgInfo::getCoerce(llvm::Type::getInt16Ty(getVMContext()));
|
|
|
|
return ABIArgInfo::getCoerce(llvm::Type::getInt32Ty(getVMContext()));
|
2009-09-14 08:56:55 +08:00
|
|
|
}
|
|
|
|
|
2009-09-13 16:03:58 +08:00
|
|
|
return ABIArgInfo::getIndirect(0);
|
2009-06-06 06:08:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
llvm::Value *ARMABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
|
2010-06-27 15:15:29 +08:00
|
|
|
CodeGenFunction &CGF) const {
|
2009-06-06 06:08:42 +08:00
|
|
|
// FIXME: Need to handle alignment
|
2009-10-13 18:07:13 +08:00
|
|
|
const llvm::Type *BP = llvm::Type::getInt8PtrTy(CGF.getLLVMContext());
|
2009-07-30 06:16:19 +08:00
|
|
|
const llvm::Type *BPP = llvm::PointerType::getUnqual(BP);
|
2009-06-06 06:08:42 +08:00
|
|
|
|
|
|
|
CGBuilderTy &Builder = CGF.Builder;
|
|
|
|
llvm::Value *VAListAddrAsBPP = Builder.CreateBitCast(VAListAddr, BPP,
|
|
|
|
"ap");
|
|
|
|
llvm::Value *Addr = Builder.CreateLoad(VAListAddrAsBPP, "ap.cur");
|
|
|
|
llvm::Type *PTy =
|
2009-07-30 06:16:19 +08:00
|
|
|
llvm::PointerType::getUnqual(CGF.ConvertType(Ty));
|
2009-06-06 06:08:42 +08:00
|
|
|
llvm::Value *AddrTyped = Builder.CreateBitCast(Addr, PTy);
|
|
|
|
|
|
|
|
uint64_t Offset =
|
|
|
|
llvm::RoundUpToAlignment(CGF.getContext().getTypeSize(Ty) / 8, 4);
|
|
|
|
llvm::Value *NextAddr =
|
2010-06-27 15:15:29 +08:00
|
|
|
Builder.CreateGEP(Addr, llvm::ConstantInt::get(CGF.Int32Ty, Offset),
|
2009-06-06 06:08:42 +08:00
|
|
|
"ap.next");
|
|
|
|
Builder.CreateStore(NextAddr, VAListAddrAsBPP);
|
|
|
|
|
|
|
|
return AddrTyped;
|
|
|
|
}
|
|
|
|
|
2010-07-29 10:16:43 +08:00
|
|
|
ABIArgInfo DefaultABIInfo::classifyReturnType(QualType RetTy) const {
|
|
|
|
if (RetTy->isVoidType())
|
2009-06-06 06:08:42 +08:00
|
|
|
return ABIArgInfo::getIgnore();
|
2010-07-29 10:16:43 +08:00
|
|
|
|
|
|
|
if (CodeGenFunction::hasAggregateLLVMType(RetTy))
|
2009-06-06 06:08:42 +08:00
|
|
|
return ABIArgInfo::getIndirect(0);
|
2010-02-03 04:10:50 +08:00
|
|
|
|
2010-07-29 10:16:43 +08:00
|
|
|
// Treat an enum type as its underlying type.
|
|
|
|
if (const EnumType *EnumTy = RetTy->getAs<EnumType>())
|
|
|
|
RetTy = EnumTy->getDecl()->getIntegerType();
|
|
|
|
|
|
|
|
return (RetTy->isPromotableIntegerType() ?
|
|
|
|
ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
|
2009-06-06 06:08:42 +08:00
|
|
|
}
|
|
|
|
|
2010-06-29 04:05:43 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2009-09-12 08:59:49 +08:00
|
|
|
// SystemZ ABI Implementation
|
2010-06-29 04:05:43 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2009-09-12 08:59:49 +08:00
|
|
|
|
2009-07-17 04:09:57 +08:00
|
|
|
namespace {
|
2009-09-12 08:59:49 +08:00
|
|
|
|
2009-07-17 04:09:57 +08:00
|
|
|
class SystemZABIInfo : public ABIInfo {
|
2010-07-29 10:01:43 +08:00
|
|
|
public:
|
|
|
|
SystemZABIInfo(CodeGenTypes &CGT) : ABIInfo(CGT) {}
|
|
|
|
|
2009-07-17 04:09:57 +08:00
|
|
|
bool isPromotableIntegerType(QualType Ty) const;
|
|
|
|
|
2010-07-29 10:16:43 +08:00
|
|
|
ABIArgInfo classifyReturnType(QualType RetTy) const;
|
|
|
|
ABIArgInfo classifyArgumentType(QualType RetTy) const;
|
2009-07-17 04:09:57 +08:00
|
|
|
|
2010-07-29 10:31:05 +08:00
|
|
|
virtual void computeInfo(CGFunctionInfo &FI) const {
|
2010-07-29 10:16:43 +08:00
|
|
|
FI.getReturnInfo() = classifyReturnType(FI.getReturnType());
|
2009-07-17 04:09:57 +08:00
|
|
|
for (CGFunctionInfo::arg_iterator it = FI.arg_begin(), ie = FI.arg_end();
|
|
|
|
it != ie; ++it)
|
2010-07-29 10:16:43 +08:00
|
|
|
it->info = classifyArgumentType(it->type);
|
2009-07-17 04:09:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
|
|
|
|
CodeGenFunction &CGF) const;
|
|
|
|
};
|
2009-09-12 08:59:49 +08:00
|
|
|
|
2010-01-10 20:58:08 +08:00
|
|
|
class SystemZTargetCodeGenInfo : public TargetCodeGenInfo {
|
|
|
|
public:
|
2010-07-29 10:01:43 +08:00
|
|
|
SystemZTargetCodeGenInfo(CodeGenTypes &CGT)
|
|
|
|
: TargetCodeGenInfo(new SystemZABIInfo(CGT)) {}
|
2010-01-10 20:58:08 +08:00
|
|
|
};
|
|
|
|
|
2009-07-17 04:09:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SystemZABIInfo::isPromotableIntegerType(QualType Ty) const {
|
|
|
|
// SystemZ ABI requires all 8, 16 and 32 bit quantities to be extended.
|
2009-09-22 07:43:11 +08:00
|
|
|
if (const BuiltinType *BT = Ty->getAs<BuiltinType>())
|
2009-07-17 04:09:57 +08:00
|
|
|
switch (BT->getKind()) {
|
|
|
|
case BuiltinType::Bool:
|
|
|
|
case BuiltinType::Char_S:
|
|
|
|
case BuiltinType::Char_U:
|
|
|
|
case BuiltinType::SChar:
|
|
|
|
case BuiltinType::UChar:
|
|
|
|
case BuiltinType::Short:
|
|
|
|
case BuiltinType::UShort:
|
|
|
|
case BuiltinType::Int:
|
|
|
|
case BuiltinType::UInt:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::Value *SystemZABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
|
|
|
|
CodeGenFunction &CGF) const {
|
|
|
|
// FIXME: Implement
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-29 10:16:43 +08:00
|
|
|
ABIArgInfo SystemZABIInfo::classifyReturnType(QualType RetTy) const {
|
|
|
|
if (RetTy->isVoidType())
|
2009-07-17 04:09:57 +08:00
|
|
|
return ABIArgInfo::getIgnore();
|
2010-07-29 10:16:43 +08:00
|
|
|
if (CodeGenFunction::hasAggregateLLVMType(RetTy))
|
2009-07-17 04:09:57 +08:00
|
|
|
return ABIArgInfo::getIndirect(0);
|
2010-07-29 10:16:43 +08:00
|
|
|
|
|
|
|
return (isPromotableIntegerType(RetTy) ?
|
|
|
|
ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
|
2009-07-17 04:09:57 +08:00
|
|
|
}
|
|
|
|
|
2010-07-29 10:16:43 +08:00
|
|
|
ABIArgInfo SystemZABIInfo::classifyArgumentType(QualType Ty) const {
|
|
|
|
if (CodeGenFunction::hasAggregateLLVMType(Ty))
|
2009-07-17 04:09:57 +08:00
|
|
|
return ABIArgInfo::getIndirect(0);
|
2010-07-29 10:16:43 +08:00
|
|
|
|
|
|
|
return (isPromotableIntegerType(Ty) ?
|
|
|
|
ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
|
2009-07-17 04:09:57 +08:00
|
|
|
}
|
|
|
|
|
2010-06-29 04:05:43 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2010-01-10 20:58:08 +08:00
|
|
|
// MSP430 ABI Implementation
|
2010-06-29 04:05:43 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2010-01-10 20:58:08 +08:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class MSP430TargetCodeGenInfo : public TargetCodeGenInfo {
|
|
|
|
public:
|
2010-07-29 10:01:43 +08:00
|
|
|
MSP430TargetCodeGenInfo(CodeGenTypes &CGT)
|
|
|
|
: TargetCodeGenInfo(new DefaultABIInfo(CGT)) {}
|
2010-01-10 20:58:08 +08:00
|
|
|
void SetTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
|
|
|
|
CodeGen::CodeGenModule &M) const;
|
|
|
|
};
|
|
|
|
|
2009-06-06 06:08:42 +08:00
|
|
|
}
|
|
|
|
|
2010-01-10 20:58:08 +08:00
|
|
|
void MSP430TargetCodeGenInfo::SetTargetAttributes(const Decl *D,
|
|
|
|
llvm::GlobalValue *GV,
|
|
|
|
CodeGen::CodeGenModule &M) const {
|
|
|
|
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
|
|
|
|
if (const MSP430InterruptAttr *attr = FD->getAttr<MSP430InterruptAttr>()) {
|
|
|
|
// Handle 'interrupt' attribute:
|
|
|
|
llvm::Function *F = cast<llvm::Function>(GV);
|
|
|
|
|
|
|
|
// Step 1: Set ISR calling convention.
|
|
|
|
F->setCallingConv(llvm::CallingConv::MSP430_INTR);
|
|
|
|
|
|
|
|
// Step 2: Add attributes goodness.
|
|
|
|
F->addFnAttr(llvm::Attribute::NoInline);
|
|
|
|
|
|
|
|
// Step 3: Emit ISR vector alias.
|
|
|
|
unsigned Num = attr->getNumber() + 0xffe0;
|
|
|
|
new llvm::GlobalAlias(GV->getType(), llvm::Function::ExternalLinkage,
|
|
|
|
"vector_" +
|
|
|
|
llvm::LowercaseString(llvm::utohexstr(Num)),
|
|
|
|
GV, &M.getModule());
|
|
|
|
}
|
|
|
|
}
|
2009-06-06 06:08:42 +08:00
|
|
|
}
|
|
|
|
|
2010-06-29 04:05:43 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2010-05-27 14:19:26 +08:00
|
|
|
// MIPS ABI Implementation. This works for both little-endian and
|
|
|
|
// big-endian variants.
|
2010-06-29 04:05:43 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-05-27 14:19:26 +08:00
|
|
|
namespace {
|
|
|
|
class MIPSTargetCodeGenInfo : public TargetCodeGenInfo {
|
|
|
|
public:
|
2010-07-29 10:01:43 +08:00
|
|
|
MIPSTargetCodeGenInfo(CodeGenTypes &CGT)
|
|
|
|
: TargetCodeGenInfo(new DefaultABIInfo(CGT)) {}
|
2010-05-27 14:19:26 +08:00
|
|
|
|
|
|
|
int getDwarfEHStackPointer(CodeGen::CodeGenModule &CGM) const {
|
|
|
|
return 29;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
|
|
|
|
llvm::Value *Address) const;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
MIPSTargetCodeGenInfo::initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
|
|
|
|
llvm::Value *Address) const {
|
|
|
|
// This information comes from gcc's implementation, which seems to
|
|
|
|
// as canonical as it gets.
|
|
|
|
|
|
|
|
CodeGen::CGBuilderTy &Builder = CGF.Builder;
|
|
|
|
llvm::LLVMContext &Context = CGF.getLLVMContext();
|
|
|
|
|
|
|
|
// Everything on MIPS is 4 bytes. Double-precision FP registers
|
|
|
|
// are aliased to pairs of single-precision FP registers.
|
|
|
|
const llvm::IntegerType *i8 = llvm::Type::getInt8Ty(Context);
|
|
|
|
llvm::Value *Four8 = llvm::ConstantInt::get(i8, 4);
|
|
|
|
|
|
|
|
// 0-31 are the general purpose registers, $0 - $31.
|
|
|
|
// 32-63 are the floating-point registers, $f0 - $f31.
|
|
|
|
// 64 and 65 are the multiply/divide registers, $hi and $lo.
|
|
|
|
// 66 is the (notional, I think) register for signal-handler return.
|
|
|
|
AssignToArrayRange(Builder, Address, Four8, 0, 65);
|
|
|
|
|
|
|
|
// 67-74 are the floating-point status registers, $fcc0 - $fcc7.
|
|
|
|
// They are one bit wide and ignored here.
|
|
|
|
|
|
|
|
// 80-111 are the coprocessor 0 registers, $c0r0 - $c0r31.
|
|
|
|
// (coprocessor 1 is the FP unit)
|
|
|
|
// 112-143 are the coprocessor 2 registers, $c2r0 - $c2r31.
|
|
|
|
// 144-175 are the coprocessor 3 registers, $c3r0 - $c3r31.
|
|
|
|
// 176-181 are the DSP accumulator registers.
|
|
|
|
AssignToArrayRange(Builder, Address, Four8, 80, 181);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-29 10:01:43 +08:00
|
|
|
const TargetCodeGenInfo &CodeGenModule::getTargetCodeGenInfo() {
|
2010-01-10 20:58:08 +08:00
|
|
|
if (TheTargetCodeGenInfo)
|
|
|
|
return *TheTargetCodeGenInfo;
|
2009-06-06 06:08:42 +08:00
|
|
|
|
2010-01-10 20:58:08 +08:00
|
|
|
// For now we just cache the TargetCodeGenInfo in CodeGenModule and don't
|
|
|
|
// free it.
|
2009-08-24 16:52:16 +08:00
|
|
|
|
Change X86_64ABIInfo to have ASTContext and TargetData ivars to
avoid passing ASTContext down through all the methods it has.
When classifying an argument, or argument piece, as INTEGER, check
to see if we have a pointer at exactly the same offset in the
preferred type. If so, use that pointer type instead of i64. This
allows us to compile A function taking a stringref into something
like this:
define i8* @foo(i64 %D.coerce0, i8* %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=4]
%0 = getelementptr %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
store i64 %D.coerce0, i64* %0
%1 = getelementptr %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
store i8* %D.coerce1, i8** %1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
instead of this:
define i8* @foo(i64 %D.coerce0, i64 %D.coerce1) nounwind ssp {
entry:
%D = alloca %struct.DeclGroup, align 8 ; <%struct.DeclGroup*> [#uses=3]
%0 = insertvalue %0 undef, i64 %D.coerce0, 0 ; <%0> [#uses=1]
%1 = insertvalue %0 %0, i64 %D.coerce1, 1 ; <%0> [#uses=1]
%2 = bitcast %struct.DeclGroup* %D to %0* ; <%0*> [#uses=1]
store %0 %1, %0* %2, align 1
%tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
%tmp1 = load i64* %tmp ; <i64> [#uses=1]
%tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
%tmp3 = load i8** %tmp2 ; <i8*> [#uses=1]
%add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
ret i8* %add.ptr
}
This implements rdar://7375902 - [codegen quality] clang x86-64 ABI lowering code punishing StringRef
llvm-svn: 107123
2010-06-29 14:01:59 +08:00
|
|
|
const llvm::Triple &Triple = getContext().Target.getTriple();
|
2009-08-24 17:10:05 +08:00
|
|
|
switch (Triple.getArch()) {
|
2009-08-24 16:52:16 +08:00
|
|
|
default:
|
2010-07-29 10:01:43 +08:00
|
|
|
return *(TheTargetCodeGenInfo = new DefaultTargetCodeGenInfo(Types));
|
2009-08-24 16:52:16 +08:00
|
|
|
|
2010-05-27 14:19:26 +08:00
|
|
|
case llvm::Triple::mips:
|
|
|
|
case llvm::Triple::mipsel:
|
2010-07-29 10:01:43 +08:00
|
|
|
return *(TheTargetCodeGenInfo = new MIPSTargetCodeGenInfo(Types));
|
2010-05-27 14:19:26 +08:00
|
|
|
|
2009-09-12 08:59:49 +08:00
|
|
|
case llvm::Triple::arm:
|
|
|
|
case llvm::Triple::thumb:
|
2009-09-12 09:00:39 +08:00
|
|
|
// FIXME: We want to know the float calling convention as well.
|
2009-09-14 08:35:03 +08:00
|
|
|
if (strcmp(getContext().Target.getABI(), "apcs-gnu") == 0)
|
2010-01-10 20:58:08 +08:00
|
|
|
return *(TheTargetCodeGenInfo =
|
2010-07-29 10:01:43 +08:00
|
|
|
new ARMTargetCodeGenInfo(Types, ARMABIInfo::APCS));
|
2009-09-12 09:00:39 +08:00
|
|
|
|
2010-01-10 20:58:08 +08:00
|
|
|
return *(TheTargetCodeGenInfo =
|
2010-07-29 10:01:43 +08:00
|
|
|
new ARMTargetCodeGenInfo(Types, ARMABIInfo::AAPCS));
|
2009-09-12 08:59:49 +08:00
|
|
|
|
|
|
|
case llvm::Triple::pic16:
|
2010-07-29 10:01:43 +08:00
|
|
|
return *(TheTargetCodeGenInfo = new PIC16TargetCodeGenInfo(Types));
|
2009-09-12 08:59:49 +08:00
|
|
|
|
2010-03-11 08:10:12 +08:00
|
|
|
case llvm::Triple::ppc:
|
2010-07-29 10:01:43 +08:00
|
|
|
return *(TheTargetCodeGenInfo = new PPC32TargetCodeGenInfo(Types));
|
2010-03-11 08:10:12 +08:00
|
|
|
|
2009-09-12 08:59:49 +08:00
|
|
|
case llvm::Triple::systemz:
|
2010-07-29 10:01:43 +08:00
|
|
|
return *(TheTargetCodeGenInfo = new SystemZTargetCodeGenInfo(Types));
|
2010-01-10 20:58:08 +08:00
|
|
|
|
|
|
|
case llvm::Triple::msp430:
|
2010-07-29 10:01:43 +08:00
|
|
|
return *(TheTargetCodeGenInfo = new MSP430TargetCodeGenInfo(Types));
|
2009-09-12 08:59:49 +08:00
|
|
|
|
2009-08-24 17:10:05 +08:00
|
|
|
case llvm::Triple::x86:
|
|
|
|
switch (Triple.getOS()) {
|
2009-10-21 01:22:50 +08:00
|
|
|
case llvm::Triple::Darwin:
|
2010-01-10 20:58:08 +08:00
|
|
|
return *(TheTargetCodeGenInfo =
|
2010-07-29 10:01:43 +08:00
|
|
|
new X86_32TargetCodeGenInfo(Types, true, true));
|
2009-08-24 16:52:16 +08:00
|
|
|
case llvm::Triple::Cygwin:
|
|
|
|
case llvm::Triple::MinGW32:
|
|
|
|
case llvm::Triple::MinGW64:
|
2009-10-21 19:58:24 +08:00
|
|
|
case llvm::Triple::AuroraUX:
|
|
|
|
case llvm::Triple::DragonFly:
|
2009-09-03 09:48:05 +08:00
|
|
|
case llvm::Triple::FreeBSD:
|
2009-08-24 16:52:16 +08:00
|
|
|
case llvm::Triple::OpenBSD:
|
2010-01-10 20:58:08 +08:00
|
|
|
return *(TheTargetCodeGenInfo =
|
2010-07-29 10:01:43 +08:00
|
|
|
new X86_32TargetCodeGenInfo(Types, false, true));
|
2009-08-24 16:52:16 +08:00
|
|
|
|
|
|
|
default:
|
2010-01-10 20:58:08 +08:00
|
|
|
return *(TheTargetCodeGenInfo =
|
2010-07-29 10:01:43 +08:00
|
|
|
new X86_32TargetCodeGenInfo(Types, false, false));
|
2009-06-06 06:08:42 +08:00
|
|
|
}
|
2009-08-24 16:52:16 +08:00
|
|
|
|
|
|
|
case llvm::Triple::x86_64:
|
2010-07-29 10:01:43 +08:00
|
|
|
return *(TheTargetCodeGenInfo = new X86_64TargetCodeGenInfo(Types));
|
2009-06-06 06:08:42 +08:00
|
|
|
}
|
|
|
|
}
|