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"
|
2013-04-17 20:54:10 +08:00
|
|
|
#include "CGCXXABI.h"
|
2014-09-05 04:04:38 +08:00
|
|
|
#include "CGValue.h"
|
2009-06-06 06:08:42 +08:00
|
|
|
#include "CodeGenFunction.h"
|
2009-07-19 03:43:29 +08:00
|
|
|
#include "clang/AST/RecordLayout.h"
|
2013-10-31 05:53:58 +08:00
|
|
|
#include "clang/CodeGen/CGFunctionInfo.h"
|
2011-04-05 08:23:47 +08:00
|
|
|
#include "clang/Frontend/CodeGenOptions.h"
|
2014-12-05 04:38:18 +08:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2009-08-24 16:52:16 +08:00
|
|
|
#include "llvm/ADT/Triple.h"
|
2013-01-02 19:45:17 +08:00
|
|
|
#include "llvm/IR/DataLayout.h"
|
|
|
|
#include "llvm/IR/Type.h"
|
2009-12-03 17:13:49 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2014-05-02 17:33:20 +08:00
|
|
|
|
|
|
|
#include <algorithm> // std::sort
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-22 18:59:02 +08:00
|
|
|
static bool isAggregateTypeForABI(QualType T) {
|
2013-03-08 05:37:08 +08:00
|
|
|
return !CodeGenFunction::hasScalarEvaluationKind(T) ||
|
2010-08-22 18:59:02 +08:00
|
|
|
T->isMemberFunctionPointerType();
|
|
|
|
}
|
|
|
|
|
2009-06-06 06:08:42 +08:00
|
|
|
ABIInfo::~ABIInfo() {}
|
|
|
|
|
2013-04-17 20:54:10 +08:00
|
|
|
static CGCXXABI::RecordArgABI getRecordArgABI(const RecordType *RT,
|
2013-10-06 09:33:34 +08:00
|
|
|
CGCXXABI &CXXABI) {
|
2013-04-17 20:54:10 +08:00
|
|
|
const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(RT->getDecl());
|
|
|
|
if (!RD)
|
|
|
|
return CGCXXABI::RAA_Default;
|
2013-10-06 09:33:34 +08:00
|
|
|
return CXXABI.getRecordArgABI(RD);
|
2013-04-17 20:54:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static CGCXXABI::RecordArgABI getRecordArgABI(QualType T,
|
2013-10-06 09:33:34 +08:00
|
|
|
CGCXXABI &CXXABI) {
|
2013-04-17 20:54:10 +08:00
|
|
|
const RecordType *RT = T->getAs<RecordType>();
|
|
|
|
if (!RT)
|
|
|
|
return CGCXXABI::RAA_Default;
|
2013-10-06 09:33:34 +08:00
|
|
|
return getRecordArgABI(RT, CXXABI);
|
|
|
|
}
|
|
|
|
|
2014-11-15 09:41:41 +08:00
|
|
|
/// Pass transparent unions as if they were the type of the first element. Sema
|
|
|
|
/// should ensure that all elements of the union have the same "machine type".
|
|
|
|
static QualType useFirstFieldIfTransparentUnion(QualType Ty) {
|
|
|
|
if (const RecordType *UT = Ty->getAsUnionType()) {
|
|
|
|
const RecordDecl *UD = UT->getDecl();
|
|
|
|
if (UD->hasAttr<TransparentUnionAttr>()) {
|
|
|
|
assert(!UD->field_empty() && "sema created an empty transparent union");
|
|
|
|
return UD->field_begin()->getType();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Ty;
|
|
|
|
}
|
|
|
|
|
2013-10-06 09:33:34 +08:00
|
|
|
CGCXXABI &ABIInfo::getCXXABI() const {
|
|
|
|
return CGT.getCXXABI();
|
2013-04-17 20:54:10 +08:00
|
|
|
}
|
|
|
|
|
2010-07-29 10:01:43 +08:00
|
|
|
ASTContext &ABIInfo::getContext() const {
|
|
|
|
return CGT.getContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::LLVMContext &ABIInfo::getVMContext() const {
|
|
|
|
return CGT.getLLVMContext();
|
|
|
|
}
|
|
|
|
|
2012-10-09 00:25:52 +08:00
|
|
|
const llvm::DataLayout &ABIInfo::getDataLayout() const {
|
|
|
|
return CGT.getDataLayout();
|
2010-07-29 10:01:43 +08:00
|
|
|
}
|
|
|
|
|
2013-04-17 06:48:15 +08:00
|
|
|
const TargetInfo &ABIInfo::getTarget() const {
|
|
|
|
return CGT.getTarget();
|
|
|
|
}
|
2010-07-29 10:01:43 +08:00
|
|
|
|
2014-11-01 01:10:41 +08:00
|
|
|
bool ABIInfo::isHomogeneousAggregateBaseType(QualType Ty) const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ABIInfo::isHomogeneousAggregateSmallEnough(const Type *Base,
|
|
|
|
uint64_t Members) const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-06-06 06:08:42 +08:00
|
|
|
void ABIArgInfo::dump() const {
|
2011-07-23 18:55:15 +08:00
|
|
|
raw_ostream &OS = llvm::errs();
|
2009-12-03 17:13:49 +08:00
|
|
|
OS << "(ABIArgInfo Kind=";
|
2009-06-06 06:08:42 +08:00
|
|
|
switch (TheKind) {
|
|
|
|
case Direct:
|
Kill off the 'coerce' ABI passing form. Now 'direct' and 'extend' always
have a "coerce to" type which often matches the default lowering of Clang
type to LLVM IR type, but the coerce case can be handled by making them
not be the same.
This simplifies things and fixes issues where X86-64 abi lowering would
return coerce after making preferred types exactly match up. This caused
us to compile:
typedef float v4f32 __attribute__((__vector_size__(16)));
v4f32 foo(v4f32 X) {
return X+X;
}
into this code at -O0:
define <4 x float> @foo(<4 x float> %X.coerce) nounwind {
entry:
%retval = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=2]
%coerce = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=2]
%X.addr = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=3]
store <4 x float> %X.coerce, <4 x float>* %coerce
%X = load <4 x float>* %coerce ; <<4 x float>> [#uses=1]
store <4 x float> %X, <4 x float>* %X.addr
%tmp = load <4 x float>* %X.addr ; <<4 x float>> [#uses=1]
%tmp1 = load <4 x float>* %X.addr ; <<4 x float>> [#uses=1]
%add = fadd <4 x float> %tmp, %tmp1 ; <<4 x float>> [#uses=1]
store <4 x float> %add, <4 x float>* %retval
%0 = load <4 x float>* %retval ; <<4 x float>> [#uses=1]
ret <4 x float> %0
}
Now we get:
define <4 x float> @foo(<4 x float> %X) nounwind {
entry:
%X.addr = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=3]
store <4 x float> %X, <4 x float>* %X.addr
%tmp = load <4 x float>* %X.addr ; <<4 x float>> [#uses=1]
%tmp1 = load <4 x float>* %X.addr ; <<4 x float>> [#uses=1]
%add = fadd <4 x float> %tmp, %tmp1 ; <<4 x float>> [#uses=1]
ret <4 x float> %add
}
This implements rdar://8248065
llvm-svn: 109733
2010-07-29 14:26:06 +08:00
|
|
|
OS << "Direct Type=";
|
2011-07-18 12:24:23 +08:00
|
|
|
if (llvm::Type *Ty = getCoerceToType())
|
Kill off the 'coerce' ABI passing form. Now 'direct' and 'extend' always
have a "coerce to" type which often matches the default lowering of Clang
type to LLVM IR type, but the coerce case can be handled by making them
not be the same.
This simplifies things and fixes issues where X86-64 abi lowering would
return coerce after making preferred types exactly match up. This caused
us to compile:
typedef float v4f32 __attribute__((__vector_size__(16)));
v4f32 foo(v4f32 X) {
return X+X;
}
into this code at -O0:
define <4 x float> @foo(<4 x float> %X.coerce) nounwind {
entry:
%retval = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=2]
%coerce = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=2]
%X.addr = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=3]
store <4 x float> %X.coerce, <4 x float>* %coerce
%X = load <4 x float>* %coerce ; <<4 x float>> [#uses=1]
store <4 x float> %X, <4 x float>* %X.addr
%tmp = load <4 x float>* %X.addr ; <<4 x float>> [#uses=1]
%tmp1 = load <4 x float>* %X.addr ; <<4 x float>> [#uses=1]
%add = fadd <4 x float> %tmp, %tmp1 ; <<4 x float>> [#uses=1]
store <4 x float> %add, <4 x float>* %retval
%0 = load <4 x float>* %retval ; <<4 x float>> [#uses=1]
ret <4 x float> %0
}
Now we get:
define <4 x float> @foo(<4 x float> %X) nounwind {
entry:
%X.addr = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=3]
store <4 x float> %X, <4 x float>* %X.addr
%tmp = load <4 x float>* %X.addr ; <<4 x float>> [#uses=1]
%tmp1 = load <4 x float>* %X.addr ; <<4 x float>> [#uses=1]
%add = fadd <4 x float> %tmp, %tmp1 ; <<4 x float>> [#uses=1]
ret <4 x float> %add
}
This implements rdar://8248065
llvm-svn: 109733
2010-07-29 14:26:06 +08:00
|
|
|
Ty->print(OS);
|
|
|
|
else
|
|
|
|
OS << "null";
|
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;
|
2014-02-01 08:04:45 +08:00
|
|
|
case InAlloca:
|
|
|
|
OS << "InAlloca Offset=" << getInAllocaFieldIndex();
|
|
|
|
break;
|
2009-06-06 06:08:42 +08:00
|
|
|
case Indirect:
|
2010-04-22 03:10:51 +08:00
|
|
|
OS << "Indirect Align=" << getIndirectAlign()
|
2011-07-16 02:23:44 +08:00
|
|
|
<< " ByVal=" << getIndirectByVal()
|
2010-09-17 04:42:02 +08:00
|
|
|
<< " Realign=" << getIndirectRealign();
|
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; }
|
|
|
|
|
2011-08-30 09:42:09 +08:00
|
|
|
// If someone can figure out a general rule for this, that would be great.
|
|
|
|
// It's probably just doomed to be platform-dependent, though.
|
|
|
|
unsigned TargetCodeGenInfo::getSizeOfUnwindException() const {
|
|
|
|
// Verified for:
|
|
|
|
// x86-64 FreeBSD, Linux, Darwin
|
|
|
|
// x86-32 FreeBSD, Linux, Darwin
|
|
|
|
// PowerPC Linux, Darwin
|
|
|
|
// ARM Darwin (*not* EABI)
|
2013-01-31 20:13:10 +08:00
|
|
|
// AArch64 Linux
|
2011-08-30 09:42:09 +08:00
|
|
|
return 32;
|
|
|
|
}
|
|
|
|
|
2012-02-17 11:33:10 +08:00
|
|
|
bool TargetCodeGenInfo::isNoProtoCallVariadic(const CallArgList &args,
|
|
|
|
const FunctionNoProtoType *fnType) const {
|
2011-09-21 16:08:30 +08:00
|
|
|
// The following conventions are known to require this to be false:
|
|
|
|
// x86_stdcall
|
|
|
|
// MIPS
|
|
|
|
// For everything else, we just prefer false unless we opt out.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-05-08 21:44:39 +08:00
|
|
|
void
|
|
|
|
TargetCodeGenInfo::getDependentLibraryOption(llvm::StringRef Lib,
|
|
|
|
llvm::SmallString<24> &Opt) const {
|
|
|
|
// This assumes the user is passing a library name like "rt" instead of a
|
|
|
|
// filename like "librt.a/so", and that they don't care whether it's static or
|
|
|
|
// dynamic.
|
|
|
|
Opt = "-l";
|
|
|
|
Opt += Lib;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2012-09-27 18:16:10 +08:00
|
|
|
/// isEmptyField - Return true iff a the field is "empty", that is it
|
2009-06-06 06:08:42 +08:00
|
|
|
/// 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();
|
|
|
|
|
2011-11-18 11:47:20 +08:00
|
|
|
// Constant arrays of empty records count as empty, strip them off.
|
|
|
|
// Constant arrays of zero length always count as empty.
|
2009-09-13 16:03:58 +08:00
|
|
|
if (AllowArrays)
|
2011-11-18 11:47:20 +08:00
|
|
|
while (const ConstantArrayType *AT = Context.getAsConstantArrayType(FT)) {
|
|
|
|
if (AT->getSize() == 0)
|
|
|
|
return true;
|
2009-09-13 16:03:58 +08:00
|
|
|
FT = AT->getElementType();
|
2011-11-18 11:47:20 +08:00
|
|
|
}
|
2009-09-13 16:03:58 +08:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-09-27 18:16:10 +08:00
|
|
|
/// isEmptyRecord - Return true iff a structure contains only empty
|
2009-06-06 06:08:42 +08:00
|
|
|
/// 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
|
|
|
|
2011-05-17 10:17:52 +08:00
|
|
|
// If this is a C++ record, check the bases first.
|
2010-05-18 00:46:00 +08:00
|
|
|
if (const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD))
|
2014-03-13 23:41:46 +08:00
|
|
|
for (const auto &I : CXXRD->bases())
|
|
|
|
if (!isEmptyRecord(Context, I.getType(), true))
|
2011-05-17 10:17:52 +08:00
|
|
|
return false;
|
2010-05-18 00:46:00 +08:00
|
|
|
|
2014-03-09 04:12:42 +08:00
|
|
|
for (const auto *I : RD->fields())
|
|
|
|
if (!isEmptyField(Context, I, AllowArrays))
|
2009-06-06 06:08:42 +08:00
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// 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)
|
2014-05-21 13:09:00 +08:00
|
|
|
return nullptr;
|
2009-06-06 06:08:42 +08:00
|
|
|
|
|
|
|
const RecordDecl *RD = RT->getDecl();
|
|
|
|
if (RD->hasFlexibleArrayMember())
|
2014-05-21 13:09:00 +08:00
|
|
|
return nullptr;
|
2009-06-06 06:08:42 +08:00
|
|
|
|
2014-05-21 13:09:00 +08:00
|
|
|
const Type *Found = nullptr;
|
2010-08-26 02:17:27 +08:00
|
|
|
|
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)) {
|
2014-03-13 23:41:46 +08:00
|
|
|
for (const auto &I : CXXRD->bases()) {
|
2010-05-12 05:15:36 +08:00
|
|
|
// Ignore empty records.
|
2014-03-13 23:41:46 +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)
|
2014-05-21 13:09:00 +08:00
|
|
|
return nullptr;
|
2010-05-12 05:15:36 +08:00
|
|
|
|
|
|
|
// If this is non-empty and not a single element struct, the composite
|
|
|
|
// cannot be a single element struct.
|
2014-03-13 23:41:46 +08:00
|
|
|
Found = isSingleElementStruct(I.getType(), Context);
|
2010-05-12 05:15:36 +08:00
|
|
|
if (!Found)
|
2014-05-21 13:09:00 +08:00
|
|
|
return nullptr;
|
2010-05-12 05:15:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for single element.
|
2014-03-09 04:12:42 +08:00
|
|
|
for (const auto *FD : RD->fields()) {
|
2009-06-06 06:08:42 +08:00
|
|
|
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)
|
2014-05-21 13:09:00 +08:00
|
|
|
return nullptr;
|
2009-06-06 06:08:42 +08:00
|
|
|
|
|
|
|
// Treat single element arrays as the element.
|
|
|
|
while (const ConstantArrayType *AT = Context.getAsConstantArrayType(FT)) {
|
|
|
|
if (AT->getSize().getZExtValue() != 1)
|
|
|
|
break;
|
|
|
|
FT = AT->getElementType();
|
|
|
|
}
|
|
|
|
|
2010-08-22 18:59:02 +08:00
|
|
|
if (!isAggregateTypeForABI(FT)) {
|
2009-06-06 06:08:42 +08:00
|
|
|
Found = FT.getTypePtr();
|
|
|
|
} else {
|
|
|
|
Found = isSingleElementStruct(FT, Context);
|
|
|
|
if (!Found)
|
2014-05-21 13:09:00 +08:00
|
|
|
return nullptr;
|
2009-06-06 06:08:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-18 09:25:50 +08:00
|
|
|
// We don't consider a struct a single-element struct if it has
|
|
|
|
// padding beyond the element type.
|
|
|
|
if (Found && Context.getTypeSize(Found) != Context.getTypeSize(T))
|
2014-05-21 13:09:00 +08:00
|
|
|
return nullptr;
|
2011-11-18 09:25:50 +08:00
|
|
|
|
2009-06-06 06:08:42 +08:00
|
|
|
return Found;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool is32Or64BitBasicType(QualType Ty, ASTContext &Context) {
|
2012-11-30 07:21:04 +08:00
|
|
|
// Treat complex types as the element type.
|
|
|
|
if (const ComplexType *CTy = Ty->getAs<ComplexType>())
|
|
|
|
Ty = CTy->getElementType();
|
|
|
|
|
|
|
|
// Check for a type which we know has a simple scalar argument-passing
|
|
|
|
// convention without any padding. (We're specifically looking for 32
|
|
|
|
// and 64-bit integer and integer-equivalents, float, and double.)
|
2010-05-14 11:40:53 +08:00
|
|
|
if (!Ty->getAs<BuiltinType>() && !Ty->hasPointerRepresentation() &&
|
2012-11-30 07:21:04 +08:00
|
|
|
!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;
|
|
|
|
|
2011-11-18 09:32:26 +08:00
|
|
|
uint64_t Size = 0;
|
|
|
|
|
2014-03-09 04:12:42 +08:00
|
|
|
for (const auto *FD : RD->fields()) {
|
2009-06-06 06:08:42 +08:00
|
|
|
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;
|
2011-11-18 09:32:26 +08:00
|
|
|
|
|
|
|
Size += Context.getTypeSize(FD->getType());
|
2009-06-06 06:08:42 +08:00
|
|
|
}
|
|
|
|
|
2011-11-18 09:32:26 +08:00
|
|
|
// Make sure there are not any holes in the struct.
|
|
|
|
if (Size != Context.getTypeSize(Ty))
|
|
|
|
return false;
|
|
|
|
|
2009-06-06 06:08:42 +08:00
|
|
|
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-08-26 02:17:27 +08:00
|
|
|
|
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
|
|
|
|
2014-03-12 14:41:41 +08:00
|
|
|
void computeInfo(CGFunctionInfo &FI) const override {
|
2014-05-14 06:05:45 +08:00
|
|
|
if (!getCXXABI().classifyReturnType(FI))
|
|
|
|
FI.getReturnInfo() = classifyReturnType(FI.getReturnType());
|
2014-03-18 02:10:01 +08:00
|
|
|
for (auto &I : FI.arguments())
|
|
|
|
I.info = classifyArgumentType(I.type);
|
2009-06-06 06:08:42 +08:00
|
|
|
}
|
|
|
|
|
2014-03-12 14:41:41 +08:00
|
|
|
llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
|
|
|
|
CodeGenFunction &CGF) const override;
|
2009-06-06 06:08:42 +08:00
|
|
|
};
|
|
|
|
|
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 {
|
2014-05-21 13:09:00 +08:00
|
|
|
return nullptr;
|
2010-01-10 20:58:08 +08:00
|
|
|
}
|
|
|
|
|
2010-07-29 10:16:43 +08:00
|
|
|
ABIArgInfo DefaultABIInfo::classifyArgumentType(QualType Ty) const {
|
2014-05-14 06:05:45 +08:00
|
|
|
if (isAggregateTypeForABI(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
|
|
|
}
|
|
|
|
|
2011-01-11 07:54:17 +08:00
|
|
|
ABIArgInfo DefaultABIInfo::classifyReturnType(QualType RetTy) const {
|
|
|
|
if (RetTy->isVoidType())
|
|
|
|
return ABIArgInfo::getIgnore();
|
|
|
|
|
|
|
|
if (isAggregateTypeForABI(RetTy))
|
|
|
|
return ABIArgInfo::getIndirect(0);
|
|
|
|
|
|
|
|
// 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());
|
|
|
|
}
|
|
|
|
|
2012-09-07 01:37:28 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// le32/PNaCl bitcode ABI Implementation
|
2013-04-09 05:31:01 +08:00
|
|
|
//
|
|
|
|
// This is a simplified version of the x86_32 ABI. Arguments and return values
|
|
|
|
// are always passed on the stack.
|
2012-09-07 01:37:28 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
class PNaClABIInfo : public ABIInfo {
|
|
|
|
public:
|
|
|
|
PNaClABIInfo(CodeGen::CodeGenTypes &CGT) : ABIInfo(CGT) {}
|
|
|
|
|
|
|
|
ABIArgInfo classifyReturnType(QualType RetTy) const;
|
2013-04-09 05:31:01 +08:00
|
|
|
ABIArgInfo classifyArgumentType(QualType RetTy) const;
|
2012-09-07 01:37:28 +08:00
|
|
|
|
2014-03-12 14:41:41 +08:00
|
|
|
void computeInfo(CGFunctionInfo &FI) const override;
|
|
|
|
llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
|
|
|
|
CodeGenFunction &CGF) const override;
|
2012-09-07 01:37:28 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class PNaClTargetCodeGenInfo : public TargetCodeGenInfo {
|
|
|
|
public:
|
|
|
|
PNaClTargetCodeGenInfo(CodeGen::CodeGenTypes &CGT)
|
|
|
|
: TargetCodeGenInfo(new PNaClABIInfo(CGT)) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
void PNaClABIInfo::computeInfo(CGFunctionInfo &FI) const {
|
2014-05-14 06:05:45 +08:00
|
|
|
if (!getCXXABI().classifyReturnType(FI))
|
2012-09-07 01:37:28 +08:00
|
|
|
FI.getReturnInfo() = classifyReturnType(FI.getReturnType());
|
|
|
|
|
2014-05-14 06:05:45 +08:00
|
|
|
for (auto &I : FI.arguments())
|
|
|
|
I.info = classifyArgumentType(I.type);
|
|
|
|
}
|
2012-09-07 01:37:28 +08:00
|
|
|
|
|
|
|
llvm::Value *PNaClABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
|
|
|
|
CodeGenFunction &CGF) const {
|
2014-05-21 13:09:00 +08:00
|
|
|
return nullptr;
|
2012-09-07 01:37:28 +08:00
|
|
|
}
|
|
|
|
|
2013-04-09 05:31:01 +08:00
|
|
|
/// \brief Classify argument of given type \p Ty.
|
|
|
|
ABIArgInfo PNaClABIInfo::classifyArgumentType(QualType Ty) const {
|
2012-09-07 01:37:28 +08:00
|
|
|
if (isAggregateTypeForABI(Ty)) {
|
2013-10-06 09:33:34 +08:00
|
|
|
if (CGCXXABI::RecordArgABI RAA = getRecordArgABI(Ty, getCXXABI()))
|
2013-04-17 20:54:10 +08:00
|
|
|
return ABIArgInfo::getIndirect(0, RAA == CGCXXABI::RAA_DirectInMemory);
|
2012-09-07 01:37:28 +08:00
|
|
|
return ABIArgInfo::getIndirect(0);
|
2013-04-09 05:31:01 +08:00
|
|
|
} else if (const EnumType *EnumTy = Ty->getAs<EnumType>()) {
|
|
|
|
// Treat an enum type as its underlying type.
|
2012-09-07 01:37:28 +08:00
|
|
|
Ty = EnumTy->getDecl()->getIntegerType();
|
2013-04-09 05:31:01 +08:00
|
|
|
} else if (Ty->isFloatingType()) {
|
|
|
|
// Floating-point types don't go inreg.
|
|
|
|
return ABIArgInfo::getDirect();
|
|
|
|
}
|
2012-09-07 01:37:28 +08:00
|
|
|
|
2013-04-09 05:31:01 +08:00
|
|
|
return (Ty->isPromotableIntegerType() ?
|
2012-09-07 01:37:28 +08:00
|
|
|
ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
|
|
|
|
}
|
|
|
|
|
|
|
|
ABIArgInfo PNaClABIInfo::classifyReturnType(QualType RetTy) const {
|
|
|
|
if (RetTy->isVoidType())
|
|
|
|
return ABIArgInfo::getIgnore();
|
|
|
|
|
2013-04-05 06:49:35 +08:00
|
|
|
// In the PNaCl ABI we always return records/structures on the stack.
|
2012-09-07 01:37:28 +08:00
|
|
|
if (isAggregateTypeForABI(RetTy))
|
|
|
|
return ABIArgInfo::getIndirect(0);
|
|
|
|
|
|
|
|
// 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());
|
|
|
|
}
|
|
|
|
|
2013-03-26 05:00:27 +08:00
|
|
|
/// IsX86_MMXType - Return true if this is an MMX type.
|
|
|
|
bool IsX86_MMXType(llvm::Type *IRType) {
|
|
|
|
// Return true if the type is an MMX type <2 x i32>, <4 x i16>, or <8 x i8>.
|
2010-10-18 11:41:31 +08:00
|
|
|
return IRType->isVectorTy() && IRType->getPrimitiveSizeInBits() == 64 &&
|
|
|
|
cast<llvm::VectorType>(IRType)->getElementType()->isIntegerTy() &&
|
|
|
|
IRType->getScalarSizeInBits() != 64;
|
|
|
|
}
|
|
|
|
|
2011-07-11 17:56:20 +08:00
|
|
|
static llvm::Type* X86AdjustInlineAsmType(CodeGen::CodeGenFunction &CGF,
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef Constraint,
|
2011-07-11 17:56:20 +08:00
|
|
|
llvm::Type* Ty) {
|
2013-06-07 08:04:50 +08:00
|
|
|
if ((Constraint == "y" || Constraint == "&y") && Ty->isVectorTy()) {
|
|
|
|
if (cast<llvm::VectorType>(Ty)->getBitWidth() != 64) {
|
|
|
|
// Invalid MMX constraint
|
2014-05-21 13:09:00 +08:00
|
|
|
return nullptr;
|
2013-06-07 08:04:50 +08:00
|
|
|
}
|
|
|
|
|
2011-02-20 07:03:58 +08:00
|
|
|
return llvm::Type::getX86_MMXTy(CGF.getLLVMContext());
|
2013-06-07 08:04:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// No operation needed
|
2011-02-20 07:03:58 +08:00
|
|
|
return Ty;
|
|
|
|
}
|
|
|
|
|
2014-11-01 06:00:51 +08:00
|
|
|
/// Returns true if this type can be passed in SSE registers with the
|
|
|
|
/// X86_VectorCall calling convention. Shared between x86_32 and x86_64.
|
|
|
|
static bool isX86VectorTypeForVectorCall(ASTContext &Context, QualType Ty) {
|
|
|
|
if (const BuiltinType *BT = Ty->getAs<BuiltinType>()) {
|
|
|
|
if (BT->isFloatingPoint() && BT->getKind() != BuiltinType::Half)
|
|
|
|
return true;
|
|
|
|
} else if (const VectorType *VT = Ty->getAs<VectorType>()) {
|
|
|
|
// vectorcall can pass XMM, YMM, and ZMM vectors. We don't pass SSE1 MMX
|
|
|
|
// registers specially.
|
|
|
|
unsigned VecSize = Context.getTypeSize(VT);
|
|
|
|
if (VecSize == 128 || VecSize == 256 || VecSize == 512)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns true if this aggregate is small enough to be passed in SSE registers
|
|
|
|
/// in the X86_VectorCall calling convention. Shared between x86_32 and x86_64.
|
|
|
|
static bool isX86VectorCallAggregateSmallEnough(uint64_t NumMembers) {
|
|
|
|
return NumMembers <= 4;
|
|
|
|
}
|
|
|
|
|
2010-06-29 04:05:43 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// X86-32 ABI Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
2010-08-26 02:17:27 +08:00
|
|
|
|
2014-01-18 09:12:41 +08:00
|
|
|
/// \brief Similar to llvm::CCState, but for Clang.
|
|
|
|
struct CCState {
|
2014-11-01 06:00:51 +08:00
|
|
|
CCState(unsigned CC) : CC(CC), FreeRegs(0), FreeSSERegs(0) {}
|
2014-01-18 09:12:41 +08:00
|
|
|
|
|
|
|
unsigned CC;
|
|
|
|
unsigned FreeRegs;
|
2014-11-01 06:00:51 +08:00
|
|
|
unsigned FreeSSERegs;
|
2014-01-18 09:12:41 +08:00
|
|
|
};
|
|
|
|
|
2009-06-06 06:08:42 +08:00
|
|
|
/// X86_32ABIInfo - The X86-32 ABI information.
|
|
|
|
class X86_32ABIInfo : public ABIInfo {
|
2012-07-31 10:44:24 +08:00
|
|
|
enum Class {
|
|
|
|
Integer,
|
|
|
|
Float
|
|
|
|
};
|
|
|
|
|
2010-09-17 04:41:56 +08:00
|
|
|
static const unsigned MinABIStackAlignInBytes = 4;
|
|
|
|
|
2009-08-18 07:08:21 +08:00
|
|
|
bool IsDarwinVectorABI;
|
|
|
|
bool IsSmallStructInRegABI;
|
2013-04-17 20:54:10 +08:00
|
|
|
bool IsWin32StructABI;
|
2012-07-31 10:44:24 +08:00
|
|
|
unsigned DefaultNumRegisterParameters;
|
2009-06-06 06:08:42 +08:00
|
|
|
|
|
|
|
static bool isRegisterSize(unsigned Size) {
|
|
|
|
return (Size == 8 || Size == 16 || Size == 32 || Size == 64);
|
|
|
|
}
|
|
|
|
|
2014-11-01 06:00:51 +08:00
|
|
|
bool isHomogeneousAggregateBaseType(QualType Ty) const override {
|
|
|
|
// FIXME: Assumes vectorcall is in use.
|
|
|
|
return isX86VectorTypeForVectorCall(getContext(), Ty);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isHomogeneousAggregateSmallEnough(const Type *Ty,
|
|
|
|
uint64_t NumMembers) const override {
|
|
|
|
// FIXME: Assumes vectorcall is in use.
|
|
|
|
return isX86VectorCallAggregateSmallEnough(NumMembers);
|
|
|
|
}
|
|
|
|
|
2014-05-14 06:05:45 +08:00
|
|
|
bool shouldReturnTypeInRegister(QualType Ty, ASTContext &Context) const;
|
2009-06-06 06:08:42 +08:00
|
|
|
|
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.
|
2014-01-18 09:12:41 +08:00
|
|
|
ABIArgInfo getIndirectResult(QualType Ty, bool ByVal, CCState &State) const;
|
|
|
|
|
|
|
|
ABIArgInfo getIndirectReturnResult(CCState &State) const;
|
2010-04-22 03:10:51 +08:00
|
|
|
|
2010-09-17 04:41:56 +08:00
|
|
|
/// \brief Return the alignment to use for the given type on the stack.
|
2010-09-17 04:42:06 +08:00
|
|
|
unsigned getTypeStackAlignInBytes(QualType Ty, unsigned Align) const;
|
2010-09-17 04:41:56 +08:00
|
|
|
|
2012-07-31 10:44:24 +08:00
|
|
|
Class classify(QualType Ty) const;
|
2014-05-14 06:05:45 +08:00
|
|
|
ABIArgInfo classifyReturnType(QualType RetTy, CCState &State) const;
|
2014-01-18 09:12:41 +08:00
|
|
|
ABIArgInfo classifyArgumentType(QualType RetTy, CCState &State) const;
|
|
|
|
bool shouldUseInReg(QualType Ty, CCState &State, bool &NeedsPadding) const;
|
2009-06-06 06:08:42 +08:00
|
|
|
|
2014-02-01 08:04:45 +08:00
|
|
|
/// \brief Rewrite the function info so that all memory arguments use
|
|
|
|
/// inalloca.
|
|
|
|
void rewriteWithInAlloca(CGFunctionInfo &FI) const;
|
|
|
|
|
|
|
|
void addFieldToArgStruct(SmallVector<llvm::Type *, 6> &FrameFields,
|
|
|
|
unsigned &StackOffset, ABIArgInfo &Info,
|
|
|
|
QualType Type) const;
|
|
|
|
|
2012-07-24 07:30:29 +08:00
|
|
|
public:
|
|
|
|
|
2014-03-12 14:41:41 +08:00
|
|
|
void computeInfo(CGFunctionInfo &FI) const override;
|
|
|
|
llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
|
|
|
|
CodeGenFunction &CGF) const override;
|
2009-06-06 06:08:42 +08:00
|
|
|
|
2013-03-26 05:00:27 +08:00
|
|
|
X86_32ABIInfo(CodeGen::CodeGenTypes &CGT, bool d, bool p, bool w,
|
2012-07-31 10:44:24 +08:00
|
|
|
unsigned r)
|
2011-07-09 07:31:17 +08:00
|
|
|
: ABIInfo(CGT), IsDarwinVectorABI(d), IsSmallStructInRegABI(p),
|
2013-04-17 20:54:10 +08:00
|
|
|
IsWin32StructABI(w), DefaultNumRegisterParameters(r) {}
|
2009-06-06 06:08:42 +08:00
|
|
|
};
|
|
|
|
|
2010-01-10 20:58:08 +08:00
|
|
|
class X86_32TargetCodeGenInfo : public TargetCodeGenInfo {
|
|
|
|
public:
|
2012-01-26 06:46:34 +08:00
|
|
|
X86_32TargetCodeGenInfo(CodeGen::CodeGenTypes &CGT,
|
2013-03-26 05:00:27 +08:00
|
|
|
bool d, bool p, bool w, unsigned r)
|
|
|
|
:TargetCodeGenInfo(new X86_32ABIInfo(CGT, d, p, w, r)) {}
|
2010-02-13 23:54:06 +08:00
|
|
|
|
2013-06-18 10:46:29 +08:00
|
|
|
static bool isStructReturnInRegABI(
|
|
|
|
const llvm::Triple &Triple, const CodeGenOptions &Opts);
|
|
|
|
|
2010-02-13 23:54:06 +08:00
|
|
|
void SetTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
|
2014-03-12 14:41:41 +08:00
|
|
|
CodeGen::CodeGenModule &CGM) const override;
|
2010-03-06 08:35:14 +08:00
|
|
|
|
2014-03-12 14:41:41 +08:00
|
|
|
int getDwarfEHStackPointer(CodeGen::CodeGenModule &CGM) const override {
|
2010-03-06 08:35:14 +08:00
|
|
|
// Darwin uses different dwarf register numbers for EH.
|
2013-04-17 06:48:15 +08:00
|
|
|
if (CGM.getTarget().getTriple().isOSDarwin()) return 5;
|
2010-03-06 08:35:14 +08:00
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
|
2014-03-12 14:41:41 +08:00
|
|
|
llvm::Value *Address) const override;
|
2011-02-20 07:03:58 +08:00
|
|
|
|
2011-07-11 17:56:20 +08:00
|
|
|
llvm::Type* adjustInlineAsmType(CodeGen::CodeGenFunction &CGF,
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef Constraint,
|
2014-03-12 14:41:41 +08:00
|
|
|
llvm::Type* Ty) const override {
|
2011-02-20 07:03:58 +08:00
|
|
|
return X86AdjustInlineAsmType(CGF, Constraint, Ty);
|
|
|
|
}
|
|
|
|
|
2014-09-05 04:04:38 +08:00
|
|
|
void addReturnRegisterOutputs(CodeGenFunction &CGF, LValue ReturnValue,
|
|
|
|
std::string &Constraints,
|
|
|
|
std::vector<llvm::Type *> &ResultRegTypes,
|
|
|
|
std::vector<llvm::Type *> &ResultTruncRegTypes,
|
|
|
|
std::vector<LValue> &ResultRegDests,
|
|
|
|
std::string &AsmString,
|
|
|
|
unsigned NumOutputs) const override;
|
|
|
|
|
2014-03-12 14:41:41 +08:00
|
|
|
llvm::Constant *
|
|
|
|
getUBSanFunctionSignature(CodeGen::CodeGenModule &CGM) const override {
|
2013-10-21 05:29:19 +08:00
|
|
|
unsigned Sig = (0xeb << 0) | // jmp rel8
|
|
|
|
(0x06 << 8) | // .+0x08
|
|
|
|
('F' << 16) |
|
|
|
|
('T' << 24);
|
|
|
|
return llvm::ConstantInt::get(CGM.Int32Ty, Sig);
|
|
|
|
}
|
|
|
|
|
2010-01-10 20:58:08 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
2009-06-06 06:08:42 +08:00
|
|
|
|
2014-09-05 04:04:38 +08:00
|
|
|
/// Rewrite input constraint references after adding some output constraints.
|
|
|
|
/// In the case where there is one output and one input and we add one output,
|
|
|
|
/// we need to replace all operand references greater than or equal to 1:
|
|
|
|
/// mov $0, $1
|
|
|
|
/// mov eax, $1
|
|
|
|
/// The result will be:
|
|
|
|
/// mov $0, $2
|
|
|
|
/// mov eax, $2
|
|
|
|
static void rewriteInputConstraintReferences(unsigned FirstIn,
|
|
|
|
unsigned NumNewOuts,
|
|
|
|
std::string &AsmString) {
|
|
|
|
std::string Buf;
|
|
|
|
llvm::raw_string_ostream OS(Buf);
|
|
|
|
size_t Pos = 0;
|
|
|
|
while (Pos < AsmString.size()) {
|
|
|
|
size_t DollarStart = AsmString.find('$', Pos);
|
|
|
|
if (DollarStart == std::string::npos)
|
|
|
|
DollarStart = AsmString.size();
|
|
|
|
size_t DollarEnd = AsmString.find_first_not_of('$', DollarStart);
|
|
|
|
if (DollarEnd == std::string::npos)
|
|
|
|
DollarEnd = AsmString.size();
|
|
|
|
OS << StringRef(&AsmString[Pos], DollarEnd - Pos);
|
|
|
|
Pos = DollarEnd;
|
|
|
|
size_t NumDollars = DollarEnd - DollarStart;
|
|
|
|
if (NumDollars % 2 != 0 && Pos < AsmString.size()) {
|
|
|
|
// We have an operand reference.
|
|
|
|
size_t DigitStart = Pos;
|
|
|
|
size_t DigitEnd = AsmString.find_first_not_of("0123456789", DigitStart);
|
|
|
|
if (DigitEnd == std::string::npos)
|
|
|
|
DigitEnd = AsmString.size();
|
|
|
|
StringRef OperandStr(&AsmString[DigitStart], DigitEnd - DigitStart);
|
|
|
|
unsigned OperandIndex;
|
|
|
|
if (!OperandStr.getAsInteger(10, OperandIndex)) {
|
|
|
|
if (OperandIndex >= FirstIn)
|
|
|
|
OperandIndex += NumNewOuts;
|
|
|
|
OS << OperandIndex;
|
|
|
|
} else {
|
|
|
|
OS << OperandStr;
|
|
|
|
}
|
|
|
|
Pos = DigitEnd;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
AsmString = std::move(OS.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Add output constraints for EAX:EDX because they are return registers.
|
|
|
|
void X86_32TargetCodeGenInfo::addReturnRegisterOutputs(
|
|
|
|
CodeGenFunction &CGF, LValue ReturnSlot, std::string &Constraints,
|
|
|
|
std::vector<llvm::Type *> &ResultRegTypes,
|
|
|
|
std::vector<llvm::Type *> &ResultTruncRegTypes,
|
|
|
|
std::vector<LValue> &ResultRegDests, std::string &AsmString,
|
|
|
|
unsigned NumOutputs) const {
|
|
|
|
uint64_t RetWidth = CGF.getContext().getTypeSize(ReturnSlot.getType());
|
|
|
|
|
|
|
|
// Use the EAX constraint if the width is 32 or smaller and EAX:EDX if it is
|
|
|
|
// larger.
|
|
|
|
if (!Constraints.empty())
|
|
|
|
Constraints += ',';
|
|
|
|
if (RetWidth <= 32) {
|
|
|
|
Constraints += "={eax}";
|
|
|
|
ResultRegTypes.push_back(CGF.Int32Ty);
|
|
|
|
} else {
|
|
|
|
// Use the 'A' constraint for EAX:EDX.
|
|
|
|
Constraints += "=A";
|
|
|
|
ResultRegTypes.push_back(CGF.Int64Ty);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Truncate EAX or EAX:EDX to an integer of the appropriate size.
|
|
|
|
llvm::Type *CoerceTy = llvm::IntegerType::get(CGF.getLLVMContext(), RetWidth);
|
|
|
|
ResultTruncRegTypes.push_back(CoerceTy);
|
|
|
|
|
|
|
|
// Coerce the integer by bitcasting the return slot pointer.
|
|
|
|
ReturnSlot.setAddress(CGF.Builder.CreateBitCast(ReturnSlot.getAddress(),
|
|
|
|
CoerceTy->getPointerTo()));
|
|
|
|
ResultRegDests.push_back(ReturnSlot);
|
|
|
|
|
|
|
|
rewriteInputConstraintReferences(NumOutputs, 1, AsmString);
|
|
|
|
}
|
|
|
|
|
2009-06-06 06:08:42 +08:00
|
|
|
/// shouldReturnTypeInRegister - Determine if the given type should be
|
|
|
|
/// passed in a register (for the Darwin ABI).
|
2014-05-14 06:05:45 +08:00
|
|
|
bool X86_32ABIInfo::shouldReturnTypeInRegister(QualType Ty,
|
|
|
|
ASTContext &Context) const {
|
2009-06-06 06:08:42 +08:00
|
|
|
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))
|
2014-05-14 06:05:45 +08:00
|
|
|
return shouldReturnTypeInRegister(AT->getElementType(), Context);
|
2009-06-06 06:08:42 +08:00
|
|
|
|
|
|
|
// 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.
|
2014-03-09 04:12:42 +08:00
|
|
|
for (const auto *FD : RT->getDecl()->fields()) {
|
2009-06-06 06:08:42 +08:00
|
|
|
// 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.
|
2014-05-14 06:05:45 +08:00
|
|
|
if (!shouldReturnTypeInRegister(FD->getType(), Context))
|
2009-06-06 06:08:42 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-01-18 09:12:41 +08:00
|
|
|
ABIArgInfo X86_32ABIInfo::getIndirectReturnResult(CCState &State) const {
|
|
|
|
// If the return value is indirect, then the hidden argument is consuming one
|
|
|
|
// integer register.
|
|
|
|
if (State.FreeRegs) {
|
|
|
|
--State.FreeRegs;
|
|
|
|
return ABIArgInfo::getIndirectInReg(/*Align=*/0, /*ByVal=*/false);
|
|
|
|
}
|
|
|
|
return ABIArgInfo::getIndirect(/*Align=*/0, /*ByVal=*/false);
|
|
|
|
}
|
|
|
|
|
2014-05-14 06:05:45 +08:00
|
|
|
ABIArgInfo X86_32ABIInfo::classifyReturnType(QualType RetTy, CCState &State) const {
|
2010-07-29 10:16:43 +08:00
|
|
|
if (RetTy->isVoidType())
|
2009-06-06 06:08:42 +08:00
|
|
|
return ABIArgInfo::getIgnore();
|
2010-08-26 02:17:27 +08:00
|
|
|
|
2014-11-01 06:00:51 +08:00
|
|
|
const Type *Base = nullptr;
|
|
|
|
uint64_t NumElts = 0;
|
|
|
|
if (State.CC == llvm::CallingConv::X86_VectorCall &&
|
|
|
|
isHomogeneousAggregate(RetTy, Base, NumElts)) {
|
|
|
|
// The LLVM struct type for such an aggregate should lower properly.
|
|
|
|
return ABIArgInfo::getDirect();
|
|
|
|
}
|
|
|
|
|
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)
|
Kill off the 'coerce' ABI passing form. Now 'direct' and 'extend' always
have a "coerce to" type which often matches the default lowering of Clang
type to LLVM IR type, but the coerce case can be handled by making them
not be the same.
This simplifies things and fixes issues where X86-64 abi lowering would
return coerce after making preferred types exactly match up. This caused
us to compile:
typedef float v4f32 __attribute__((__vector_size__(16)));
v4f32 foo(v4f32 X) {
return X+X;
}
into this code at -O0:
define <4 x float> @foo(<4 x float> %X.coerce) nounwind {
entry:
%retval = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=2]
%coerce = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=2]
%X.addr = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=3]
store <4 x float> %X.coerce, <4 x float>* %coerce
%X = load <4 x float>* %coerce ; <<4 x float>> [#uses=1]
store <4 x float> %X, <4 x float>* %X.addr
%tmp = load <4 x float>* %X.addr ; <<4 x float>> [#uses=1]
%tmp1 = load <4 x float>* %X.addr ; <<4 x float>> [#uses=1]
%add = fadd <4 x float> %tmp, %tmp1 ; <<4 x float>> [#uses=1]
store <4 x float> %add, <4 x float>* %retval
%0 = load <4 x float>* %retval ; <<4 x float>> [#uses=1]
ret <4 x float> %0
}
Now we get:
define <4 x float> @foo(<4 x float> %X) nounwind {
entry:
%X.addr = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=3]
store <4 x float> %X, <4 x float>* %X.addr
%tmp = load <4 x float>* %X.addr ; <<4 x float>> [#uses=1]
%tmp1 = load <4 x float>* %X.addr ; <<4 x float>> [#uses=1]
%add = fadd <4 x float> %tmp, %tmp1 ; <<4 x float>> [#uses=1]
ret <4 x float> %add
}
This implements rdar://8248065
llvm-svn: 109733
2010-07-29 14:26:06 +08:00
|
|
|
return ABIArgInfo::getDirect(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))
|
Kill off the 'coerce' ABI passing form. Now 'direct' and 'extend' always
have a "coerce to" type which often matches the default lowering of Clang
type to LLVM IR type, but the coerce case can be handled by making them
not be the same.
This simplifies things and fixes issues where X86-64 abi lowering would
return coerce after making preferred types exactly match up. This caused
us to compile:
typedef float v4f32 __attribute__((__vector_size__(16)));
v4f32 foo(v4f32 X) {
return X+X;
}
into this code at -O0:
define <4 x float> @foo(<4 x float> %X.coerce) nounwind {
entry:
%retval = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=2]
%coerce = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=2]
%X.addr = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=3]
store <4 x float> %X.coerce, <4 x float>* %coerce
%X = load <4 x float>* %coerce ; <<4 x float>> [#uses=1]
store <4 x float> %X, <4 x float>* %X.addr
%tmp = load <4 x float>* %X.addr ; <<4 x float>> [#uses=1]
%tmp1 = load <4 x float>* %X.addr ; <<4 x float>> [#uses=1]
%add = fadd <4 x float> %tmp, %tmp1 ; <<4 x float>> [#uses=1]
store <4 x float> %add, <4 x float>* %retval
%0 = load <4 x float>* %retval ; <<4 x float>> [#uses=1]
ret <4 x float> %0
}
Now we get:
define <4 x float> @foo(<4 x float> %X) nounwind {
entry:
%X.addr = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=3]
store <4 x float> %X, <4 x float>* %X.addr
%tmp = load <4 x float>* %X.addr ; <<4 x float>> [#uses=1]
%tmp1 = load <4 x float>* %X.addr ; <<4 x float>> [#uses=1]
%add = fadd <4 x float> %tmp, %tmp1 ; <<4 x float>> [#uses=1]
ret <4 x float> %add
}
This implements rdar://8248065
llvm-svn: 109733
2010-07-29 14:26:06 +08:00
|
|
|
return ABIArgInfo::getDirect(llvm::IntegerType::get(getVMContext(),
|
2010-07-29 10:16:43 +08:00
|
|
|
Size));
|
2009-06-06 06:08:42 +08:00
|
|
|
|
2014-01-18 09:12:41 +08:00
|
|
|
return getIndirectReturnResult(State);
|
2009-06-06 06:08:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return ABIArgInfo::getDirect();
|
2010-07-29 10:16:43 +08:00
|
|
|
}
|
2010-08-26 02:17:27 +08:00
|
|
|
|
2010-08-22 18:59:02 +08:00
|
|
|
if (isAggregateTypeForABI(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 flexible arrays are always indirect.
|
2009-06-06 06:08:42 +08:00
|
|
|
if (RT->getDecl()->hasFlexibleArrayMember())
|
2014-01-18 09:12:41 +08:00
|
|
|
return getIndirectReturnResult(State);
|
2009-10-21 06:07:59 +08:00
|
|
|
}
|
2010-08-26 02:17:27 +08:00
|
|
|
|
2009-08-18 07:08:21 +08:00
|
|
|
// If specified, structs and unions are always indirect.
|
|
|
|
if (!IsSmallStructInRegABI && !RetTy->isAnyComplexType())
|
2014-01-18 09:12:41 +08:00
|
|
|
return getIndirectReturnResult(State);
|
2009-06-06 06:08:42 +08:00
|
|
|
|
|
|
|
// Small structures which are register sized are generally returned
|
|
|
|
// in a register.
|
2014-05-14 06:05:45 +08:00
|
|
|
if (shouldReturnTypeInRegister(RetTy, getContext())) {
|
2010-07-29 10:16:43 +08:00
|
|
|
uint64_t Size = getContext().getTypeSize(RetTy);
|
2011-11-18 09:25:50 +08:00
|
|
|
|
|
|
|
// As a special-case, if the struct is a "single-element" struct, and
|
|
|
|
// the field is of type "float" or "double", return it in a
|
2012-01-26 06:46:34 +08:00
|
|
|
// floating-point register. (MSVC does not apply this special case.)
|
|
|
|
// We apply a similar transformation for pointer types to improve the
|
|
|
|
// quality of the generated IR.
|
2011-11-18 09:25:50 +08:00
|
|
|
if (const Type *SeltTy = isSingleElementStruct(RetTy, getContext()))
|
2013-04-17 20:54:10 +08:00
|
|
|
if ((!IsWin32StructABI && SeltTy->isRealFloatingType())
|
2012-01-26 06:46:34 +08:00
|
|
|
|| SeltTy->hasPointerRepresentation())
|
2011-11-18 09:25:50 +08:00
|
|
|
return ABIArgInfo::getDirect(CGT.ConvertType(QualType(SeltTy, 0)));
|
|
|
|
|
|
|
|
// FIXME: We should be able to narrow this integer in cases with dead
|
|
|
|
// padding.
|
Kill off the 'coerce' ABI passing form. Now 'direct' and 'extend' always
have a "coerce to" type which often matches the default lowering of Clang
type to LLVM IR type, but the coerce case can be handled by making them
not be the same.
This simplifies things and fixes issues where X86-64 abi lowering would
return coerce after making preferred types exactly match up. This caused
us to compile:
typedef float v4f32 __attribute__((__vector_size__(16)));
v4f32 foo(v4f32 X) {
return X+X;
}
into this code at -O0:
define <4 x float> @foo(<4 x float> %X.coerce) nounwind {
entry:
%retval = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=2]
%coerce = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=2]
%X.addr = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=3]
store <4 x float> %X.coerce, <4 x float>* %coerce
%X = load <4 x float>* %coerce ; <<4 x float>> [#uses=1]
store <4 x float> %X, <4 x float>* %X.addr
%tmp = load <4 x float>* %X.addr ; <<4 x float>> [#uses=1]
%tmp1 = load <4 x float>* %X.addr ; <<4 x float>> [#uses=1]
%add = fadd <4 x float> %tmp, %tmp1 ; <<4 x float>> [#uses=1]
store <4 x float> %add, <4 x float>* %retval
%0 = load <4 x float>* %retval ; <<4 x float>> [#uses=1]
ret <4 x float> %0
}
Now we get:
define <4 x float> @foo(<4 x float> %X) nounwind {
entry:
%X.addr = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=3]
store <4 x float> %X, <4 x float>* %X.addr
%tmp = load <4 x float>* %X.addr ; <<4 x float>> [#uses=1]
%tmp1 = load <4 x float>* %X.addr ; <<4 x float>> [#uses=1]
%add = fadd <4 x float> %tmp, %tmp1 ; <<4 x float>> [#uses=1]
ret <4 x float> %add
}
This implements rdar://8248065
llvm-svn: 109733
2010-07-29 14:26:06 +08:00
|
|
|
return ABIArgInfo::getDirect(llvm::IntegerType::get(getVMContext(),Size));
|
2009-06-06 06:08:42 +08:00
|
|
|
}
|
|
|
|
|
2014-01-18 09:12:41 +08:00
|
|
|
return getIndirectReturnResult(State);
|
2009-06-06 06:08:42 +08:00
|
|
|
}
|
2010-08-26 02:17:27 +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
|
|
|
}
|
|
|
|
|
2012-06-06 03:40:46 +08:00
|
|
|
static bool isSSEVectorType(ASTContext &Context, QualType Ty) {
|
|
|
|
return Ty->getAs<VectorType>() && Context.getTypeSize(Ty) == 128;
|
|
|
|
}
|
|
|
|
|
2010-09-17 04:42:00 +08:00
|
|
|
static bool isRecordWithSSEVectorType(ASTContext &Context, QualType Ty) {
|
|
|
|
const RecordType *RT = Ty->getAs<RecordType>();
|
|
|
|
if (!RT)
|
|
|
|
return 0;
|
|
|
|
const RecordDecl *RD = RT->getDecl();
|
|
|
|
|
|
|
|
// If this is a C++ record, check the bases first.
|
|
|
|
if (const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD))
|
2014-03-13 23:41:46 +08:00
|
|
|
for (const auto &I : CXXRD->bases())
|
|
|
|
if (!isRecordWithSSEVectorType(Context, I.getType()))
|
2010-09-17 04:42:00 +08:00
|
|
|
return false;
|
|
|
|
|
2014-03-09 04:12:42 +08:00
|
|
|
for (const auto *i : RD->fields()) {
|
2010-09-17 04:42:00 +08:00
|
|
|
QualType FT = i->getType();
|
|
|
|
|
2012-06-06 03:40:46 +08:00
|
|
|
if (isSSEVectorType(Context, FT))
|
2010-09-17 04:42:00 +08:00
|
|
|
return true;
|
|
|
|
|
|
|
|
if (isRecordWithSSEVectorType(Context, FT))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-09-17 04:42:06 +08:00
|
|
|
unsigned X86_32ABIInfo::getTypeStackAlignInBytes(QualType Ty,
|
|
|
|
unsigned Align) const {
|
|
|
|
// Otherwise, if the alignment is less than or equal to the minimum ABI
|
|
|
|
// alignment, just use the default; the backend will handle this.
|
2010-09-17 04:41:56 +08:00
|
|
|
if (Align <= MinABIStackAlignInBytes)
|
2010-09-17 04:42:06 +08:00
|
|
|
return 0; // Use default alignment.
|
|
|
|
|
|
|
|
// On non-Darwin, the stack type alignment is always 4.
|
|
|
|
if (!IsDarwinVectorABI) {
|
|
|
|
// Set explicit alignment, since we may need to realign the top.
|
2010-09-17 04:41:56 +08:00
|
|
|
return MinABIStackAlignInBytes;
|
2010-09-17 04:42:06 +08:00
|
|
|
}
|
2010-09-17 04:41:56 +08:00
|
|
|
|
2010-09-17 04:42:00 +08:00
|
|
|
// Otherwise, if the type contains an SSE vector type, the alignment is 16.
|
2012-06-06 03:40:46 +08:00
|
|
|
if (Align >= 16 && (isSSEVectorType(getContext(), Ty) ||
|
|
|
|
isRecordWithSSEVectorType(getContext(), Ty)))
|
2010-09-17 04:42:00 +08:00
|
|
|
return 16;
|
|
|
|
|
|
|
|
return MinABIStackAlignInBytes;
|
2010-09-17 04:41:56 +08:00
|
|
|
}
|
|
|
|
|
2012-10-19 13:04:37 +08:00
|
|
|
ABIArgInfo X86_32ABIInfo::getIndirectResult(QualType Ty, bool ByVal,
|
2014-01-18 09:12:41 +08:00
|
|
|
CCState &State) const {
|
2012-10-19 13:04:37 +08:00
|
|
|
if (!ByVal) {
|
2014-01-18 09:12:41 +08:00
|
|
|
if (State.FreeRegs) {
|
|
|
|
--State.FreeRegs; // Non-byval indirects just use one pointer.
|
2012-10-19 13:04:37 +08:00
|
|
|
return ABIArgInfo::getIndirectInReg(0, false);
|
|
|
|
}
|
2010-04-22 03:49:55 +08:00
|
|
|
return ABIArgInfo::getIndirect(0, false);
|
2012-10-19 13:04:37 +08:00
|
|
|
}
|
2010-04-22 03:49:55 +08:00
|
|
|
|
2010-09-17 04:42:06 +08:00
|
|
|
// Compute the byval alignment.
|
|
|
|
unsigned TypeAlign = getContext().getTypeAlign(Ty) / 8;
|
|
|
|
unsigned StackAlign = getTypeStackAlignInBytes(Ty, TypeAlign);
|
|
|
|
if (StackAlign == 0)
|
2014-02-01 08:04:45 +08:00
|
|
|
return ABIArgInfo::getIndirect(4, /*ByVal=*/true);
|
2010-09-17 04:42:06 +08:00
|
|
|
|
|
|
|
// If the stack alignment is less than the type alignment, realign the
|
|
|
|
// argument.
|
2014-02-01 08:04:45 +08:00
|
|
|
bool Realign = TypeAlign > StackAlign;
|
|
|
|
return ABIArgInfo::getIndirect(StackAlign, /*ByVal=*/true, Realign);
|
2010-04-22 03:10:51 +08:00
|
|
|
}
|
|
|
|
|
2012-07-31 10:44:24 +08:00
|
|
|
X86_32ABIInfo::Class X86_32ABIInfo::classify(QualType Ty) const {
|
|
|
|
const Type *T = isSingleElementStruct(Ty, getContext());
|
|
|
|
if (!T)
|
|
|
|
T = Ty.getTypePtr();
|
|
|
|
|
|
|
|
if (const BuiltinType *BT = T->getAs<BuiltinType>()) {
|
|
|
|
BuiltinType::Kind K = BT->getKind();
|
|
|
|
if (K == BuiltinType::Float || K == BuiltinType::Double)
|
|
|
|
return Float;
|
|
|
|
}
|
|
|
|
return Integer;
|
|
|
|
}
|
|
|
|
|
2014-01-18 09:12:41 +08:00
|
|
|
bool X86_32ABIInfo::shouldUseInReg(QualType Ty, CCState &State,
|
|
|
|
bool &NeedsPadding) const {
|
2012-10-24 09:59:00 +08:00
|
|
|
NeedsPadding = false;
|
2012-07-31 10:44:24 +08:00
|
|
|
Class C = classify(Ty);
|
|
|
|
if (C == Float)
|
2012-10-19 13:04:37 +08:00
|
|
|
return false;
|
2012-07-31 10:44:24 +08:00
|
|
|
|
2012-10-24 09:58:58 +08:00
|
|
|
unsigned Size = getContext().getTypeSize(Ty);
|
|
|
|
unsigned SizeInRegs = (Size + 31) / 32;
|
2012-10-23 10:04:01 +08:00
|
|
|
|
|
|
|
if (SizeInRegs == 0)
|
|
|
|
return false;
|
|
|
|
|
2014-01-18 09:12:41 +08:00
|
|
|
if (SizeInRegs > State.FreeRegs) {
|
|
|
|
State.FreeRegs = 0;
|
2012-10-19 13:04:37 +08:00
|
|
|
return false;
|
2012-07-31 10:44:24 +08:00
|
|
|
}
|
|
|
|
|
2014-01-18 09:12:41 +08:00
|
|
|
State.FreeRegs -= SizeInRegs;
|
2012-10-24 09:58:58 +08:00
|
|
|
|
2014-11-01 06:00:51 +08:00
|
|
|
if (State.CC == llvm::CallingConv::X86_FastCall ||
|
|
|
|
State.CC == llvm::CallingConv::X86_VectorCall) {
|
2012-10-24 09:58:58 +08:00
|
|
|
if (Size > 32)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (Ty->isIntegralOrEnumerationType())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (Ty->isPointerType())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (Ty->isReferenceType())
|
|
|
|
return true;
|
|
|
|
|
2014-01-18 09:12:41 +08:00
|
|
|
if (State.FreeRegs)
|
2012-10-24 09:59:00 +08:00
|
|
|
NeedsPadding = true;
|
|
|
|
|
2012-10-24 09:58:58 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-10-19 13:04:37 +08:00
|
|
|
return true;
|
2012-07-31 10:44:24 +08:00
|
|
|
}
|
|
|
|
|
2014-02-01 08:04:45 +08:00
|
|
|
ABIArgInfo X86_32ABIInfo::classifyArgumentType(QualType Ty,
|
|
|
|
CCState &State) const {
|
2009-06-06 06:08:42 +08:00
|
|
|
// FIXME: Set alignment on indirect arguments.
|
2014-02-01 08:04:45 +08:00
|
|
|
|
2014-11-15 09:41:41 +08:00
|
|
|
Ty = useFirstFieldIfTransparentUnion(Ty);
|
|
|
|
|
2014-11-01 06:00:51 +08:00
|
|
|
// Check with the C++ ABI first.
|
|
|
|
const RecordType *RT = Ty->getAs<RecordType>();
|
|
|
|
if (RT) {
|
|
|
|
CGCXXABI::RecordArgABI RAA = getRecordArgABI(RT, getCXXABI());
|
|
|
|
if (RAA == CGCXXABI::RAA_Indirect) {
|
|
|
|
return getIndirectResult(Ty, false, State);
|
|
|
|
} else if (RAA == CGCXXABI::RAA_DirectInMemory) {
|
|
|
|
// The field index doesn't matter, we'll fix it up later.
|
|
|
|
return ABIArgInfo::getInAlloca(/*FieldIndex=*/0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// vectorcall adds the concept of a homogenous vector aggregate, similar
|
|
|
|
// to other targets.
|
|
|
|
const Type *Base = nullptr;
|
|
|
|
uint64_t NumElts = 0;
|
|
|
|
if (State.CC == llvm::CallingConv::X86_VectorCall &&
|
|
|
|
isHomogeneousAggregate(Ty, Base, NumElts)) {
|
|
|
|
if (State.FreeSSERegs >= NumElts) {
|
|
|
|
State.FreeSSERegs -= NumElts;
|
|
|
|
if (Ty->isBuiltinType() || Ty->isVectorType())
|
|
|
|
return ABIArgInfo::getDirect();
|
|
|
|
return ABIArgInfo::getExpand();
|
|
|
|
}
|
|
|
|
return getIndirectResult(Ty, /*ByVal=*/false, State);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isAggregateTypeForABI(Ty)) {
|
|
|
|
if (RT) {
|
2014-02-01 08:04:45 +08:00
|
|
|
// Structs are always byval on win32, regardless of what they contain.
|
2013-04-17 20:54:10 +08:00
|
|
|
if (IsWin32StructABI)
|
2014-01-18 09:12:41 +08:00
|
|
|
return getIndirectResult(Ty, true, State);
|
2010-04-22 03:10:51 +08:00
|
|
|
|
2013-04-17 20:54:10 +08:00
|
|
|
// Structures with flexible arrays are always indirect.
|
2009-06-06 06:08:42 +08:00
|
|
|
if (RT->getDecl()->hasFlexibleArrayMember())
|
2014-01-18 09:12:41 +08:00
|
|
|
return getIndirectResult(Ty, true, State);
|
2010-01-27 11:25:19 +08:00
|
|
|
}
|
2009-06-06 06:08:42 +08:00
|
|
|
|
2011-11-18 08:28:11 +08:00
|
|
|
// Ignore empty structs/unions.
|
2011-11-18 12:01:36 +08:00
|
|
|
if (isEmptyRecord(getContext(), Ty, true))
|
2009-06-06 06:08:42 +08:00
|
|
|
return ABIArgInfo::getIgnore();
|
|
|
|
|
2012-10-24 09:59:00 +08:00
|
|
|
llvm::LLVMContext &LLVMContext = getVMContext();
|
|
|
|
llvm::IntegerType *Int32 = llvm::Type::getInt32Ty(LLVMContext);
|
|
|
|
bool NeedsPadding;
|
2014-01-18 09:12:41 +08:00
|
|
|
if (shouldUseInReg(Ty, State, NeedsPadding)) {
|
2012-10-19 13:04:37 +08:00
|
|
|
unsigned SizeInRegs = (getContext().getTypeSize(Ty) + 31) / 32;
|
2013-07-08 12:47:18 +08:00
|
|
|
SmallVector<llvm::Type*, 3> Elements(SizeInRegs, Int32);
|
2012-10-19 13:04:37 +08:00
|
|
|
llvm::Type *Result = llvm::StructType::get(LLVMContext, Elements);
|
|
|
|
return ABIArgInfo::getDirectInReg(Result);
|
|
|
|
}
|
2014-05-21 13:09:00 +08:00
|
|
|
llvm::IntegerType *PaddingType = NeedsPadding ? Int32 : nullptr;
|
2012-10-19 13:04:37 +08:00
|
|
|
|
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()))
|
2014-01-18 09:12:41 +08:00
|
|
|
return ABIArgInfo::getExpandWithPadding(
|
2014-11-01 06:00:51 +08:00
|
|
|
State.CC == llvm::CallingConv::X86_FastCall ||
|
|
|
|
State.CC == llvm::CallingConv::X86_VectorCall,
|
|
|
|
PaddingType);
|
2009-06-06 06:08:42 +08:00
|
|
|
|
2014-01-18 09:12:41 +08:00
|
|
|
return getIndirectResult(Ty, true, State);
|
2010-08-26 02:17:27 +08:00
|
|
|
}
|
|
|
|
|
2010-08-27 04:05:13 +08:00
|
|
|
if (const VectorType *VT = Ty->getAs<VectorType>()) {
|
2010-08-27 04:08:43 +08:00
|
|
|
// On Darwin, some vectors are passed in memory, we handle this by passing
|
|
|
|
// it as an i8/i16/i32/i64.
|
2010-08-27 04:05:13 +08:00
|
|
|
if (IsDarwinVectorABI) {
|
|
|
|
uint64_t Size = getContext().getTypeSize(Ty);
|
|
|
|
if ((Size == 8 || Size == 16 || Size == 32) ||
|
|
|
|
(Size == 64 && VT->getNumElements() == 1))
|
|
|
|
return ABIArgInfo::getDirect(llvm::IntegerType::get(getVMContext(),
|
|
|
|
Size));
|
|
|
|
}
|
2010-10-18 11:41:31 +08:00
|
|
|
|
2013-03-26 05:00:27 +08:00
|
|
|
if (IsX86_MMXType(CGT.ConvertType(Ty)))
|
|
|
|
return ABIArgInfo::getDirect(llvm::IntegerType::get(getVMContext(), 64));
|
2010-10-19 14:39:39 +08:00
|
|
|
|
2010-08-27 04:05:13 +08:00
|
|
|
return ABIArgInfo::getDirect();
|
|
|
|
}
|
2010-10-19 14:39:39 +08:00
|
|
|
|
|
|
|
|
2010-07-29 10:16:43 +08:00
|
|
|
if (const EnumType *EnumTy = Ty->getAs<EnumType>())
|
|
|
|
Ty = EnumTy->getDecl()->getIntegerType();
|
2010-02-03 04:10:50 +08:00
|
|
|
|
2012-10-24 09:59:00 +08:00
|
|
|
bool NeedsPadding;
|
2014-01-18 09:12:41 +08:00
|
|
|
bool InReg = shouldUseInReg(Ty, State, NeedsPadding);
|
2012-10-19 13:04:37 +08:00
|
|
|
|
|
|
|
if (Ty->isPromotableIntegerType()) {
|
|
|
|
if (InReg)
|
|
|
|
return ABIArgInfo::getExtendInReg();
|
|
|
|
return ABIArgInfo::getExtend();
|
|
|
|
}
|
|
|
|
if (InReg)
|
|
|
|
return ABIArgInfo::getDirectInReg();
|
|
|
|
return ABIArgInfo::getDirect();
|
2009-06-06 06:08:42 +08:00
|
|
|
}
|
|
|
|
|
2012-07-24 08:01:07 +08:00
|
|
|
void X86_32ABIInfo::computeInfo(CGFunctionInfo &FI) const {
|
2014-01-18 09:12:41 +08:00
|
|
|
CCState State(FI.getCallingConvention());
|
|
|
|
if (State.CC == llvm::CallingConv::X86_FastCall)
|
|
|
|
State.FreeRegs = 2;
|
2014-11-01 06:00:51 +08:00
|
|
|
else if (State.CC == llvm::CallingConv::X86_VectorCall) {
|
|
|
|
State.FreeRegs = 2;
|
|
|
|
State.FreeSSERegs = 6;
|
|
|
|
} else if (FI.getHasRegParm())
|
2014-01-18 09:12:41 +08:00
|
|
|
State.FreeRegs = FI.getRegParm();
|
2012-10-24 09:58:58 +08:00
|
|
|
else
|
2014-01-18 09:12:41 +08:00
|
|
|
State.FreeRegs = DefaultNumRegisterParameters;
|
2012-07-31 10:44:24 +08:00
|
|
|
|
2014-07-10 09:58:55 +08:00
|
|
|
if (!getCXXABI().classifyReturnType(FI)) {
|
2014-05-14 06:05:45 +08:00
|
|
|
FI.getReturnInfo() = classifyReturnType(FI.getReturnType(), State);
|
2014-07-10 09:58:55 +08:00
|
|
|
} else if (FI.getReturnInfo().isIndirect()) {
|
|
|
|
// The C++ ABI is not aware of register usage, so we have to check if the
|
|
|
|
// return value was sret and put it in a register ourselves if appropriate.
|
|
|
|
if (State.FreeRegs) {
|
|
|
|
--State.FreeRegs; // The sret parameter consumes a register.
|
|
|
|
FI.getReturnInfo().setInReg(true);
|
|
|
|
}
|
|
|
|
}
|
2012-07-31 10:44:24 +08:00
|
|
|
|
2014-02-01 08:04:45 +08:00
|
|
|
bool UsedInAlloca = false;
|
2014-03-18 02:10:01 +08:00
|
|
|
for (auto &I : FI.arguments()) {
|
|
|
|
I.info = classifyArgumentType(I.type, State);
|
|
|
|
UsedInAlloca |= (I.info.getKind() == ABIArgInfo::InAlloca);
|
2014-02-01 08:04:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// If we needed to use inalloca for any argument, do a second pass and rewrite
|
|
|
|
// all the memory arguments to use inalloca.
|
|
|
|
if (UsedInAlloca)
|
|
|
|
rewriteWithInAlloca(FI);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
X86_32ABIInfo::addFieldToArgStruct(SmallVector<llvm::Type *, 6> &FrameFields,
|
|
|
|
unsigned &StackOffset,
|
|
|
|
ABIArgInfo &Info, QualType Type) const {
|
2014-04-11 03:09:43 +08:00
|
|
|
assert(StackOffset % 4U == 0 && "unaligned inalloca struct");
|
|
|
|
Info = ABIArgInfo::getInAlloca(FrameFields.size());
|
|
|
|
FrameFields.push_back(CGT.ConvertTypeForMem(Type));
|
|
|
|
StackOffset += getContext().getTypeSizeInChars(Type).getQuantity();
|
|
|
|
|
2014-02-01 08:04:45 +08:00
|
|
|
// Insert padding bytes to respect alignment. For x86_32, each argument is 4
|
|
|
|
// byte aligned.
|
2014-04-11 03:09:43 +08:00
|
|
|
if (StackOffset % 4U) {
|
2014-02-01 08:04:45 +08:00
|
|
|
unsigned OldOffset = StackOffset;
|
2014-04-11 03:09:43 +08:00
|
|
|
StackOffset = llvm::RoundUpToAlignment(StackOffset, 4U);
|
2014-02-01 08:04:45 +08:00
|
|
|
unsigned NumBytes = StackOffset - OldOffset;
|
|
|
|
assert(NumBytes);
|
|
|
|
llvm::Type *Ty = llvm::Type::getInt8Ty(getVMContext());
|
|
|
|
Ty = llvm::ArrayType::get(Ty, NumBytes);
|
|
|
|
FrameFields.push_back(Ty);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-26 08:12:26 +08:00
|
|
|
static bool isArgInAlloca(const ABIArgInfo &Info) {
|
|
|
|
// Leave ignored and inreg arguments alone.
|
|
|
|
switch (Info.getKind()) {
|
|
|
|
case ABIArgInfo::InAlloca:
|
|
|
|
return true;
|
|
|
|
case ABIArgInfo::Indirect:
|
|
|
|
assert(Info.getIndirectByVal());
|
|
|
|
return true;
|
|
|
|
case ABIArgInfo::Ignore:
|
|
|
|
return false;
|
|
|
|
case ABIArgInfo::Direct:
|
|
|
|
case ABIArgInfo::Extend:
|
|
|
|
case ABIArgInfo::Expand:
|
|
|
|
if (Info.getInReg())
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
llvm_unreachable("invalid enum");
|
|
|
|
}
|
|
|
|
|
2014-02-01 08:04:45 +08:00
|
|
|
void X86_32ABIInfo::rewriteWithInAlloca(CGFunctionInfo &FI) const {
|
|
|
|
assert(IsWin32StructABI && "inalloca only supported on win32");
|
|
|
|
|
|
|
|
// Build a packed struct type for all of the arguments in memory.
|
|
|
|
SmallVector<llvm::Type *, 6> FrameFields;
|
|
|
|
|
|
|
|
unsigned StackOffset = 0;
|
2014-07-26 08:12:26 +08:00
|
|
|
CGFunctionInfo::arg_iterator I = FI.arg_begin(), E = FI.arg_end();
|
2014-02-01 08:04:45 +08:00
|
|
|
|
2014-07-26 08:12:26 +08:00
|
|
|
// Put 'this' into the struct before 'sret', if necessary.
|
|
|
|
bool IsThisCall =
|
|
|
|
FI.getCallingConvention() == llvm::CallingConv::X86_ThisCall;
|
2014-02-01 08:04:45 +08:00
|
|
|
ABIArgInfo &Ret = FI.getReturnInfo();
|
2014-07-26 08:12:26 +08:00
|
|
|
if (Ret.isIndirect() && Ret.isSRetAfterThis() && !IsThisCall &&
|
|
|
|
isArgInAlloca(I->info)) {
|
|
|
|
addFieldToArgStruct(FrameFields, StackOffset, I->info, I->type);
|
|
|
|
++I;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Put the sret parameter into the inalloca struct if it's in memory.
|
2014-02-01 08:04:45 +08:00
|
|
|
if (Ret.isIndirect() && !Ret.getInReg()) {
|
|
|
|
CanQualType PtrTy = getContext().getPointerType(FI.getReturnType());
|
|
|
|
addFieldToArgStruct(FrameFields, StackOffset, Ret, PtrTy);
|
2014-02-25 08:59:14 +08:00
|
|
|
// On Windows, the hidden sret parameter is always returned in eax.
|
|
|
|
Ret.setInAllocaSRet(IsWin32StructABI);
|
2014-02-01 08:04:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Skip the 'this' parameter in ecx.
|
2014-07-26 08:12:26 +08:00
|
|
|
if (IsThisCall)
|
2014-02-01 08:04:45 +08:00
|
|
|
++I;
|
|
|
|
|
|
|
|
// Put arguments passed in memory into the struct.
|
|
|
|
for (; I != E; ++I) {
|
2014-07-26 08:12:26 +08:00
|
|
|
if (isArgInAlloca(I->info))
|
|
|
|
addFieldToArgStruct(FrameFields, StackOffset, I->info, I->type);
|
2014-02-01 08:04:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
FI.setArgStruct(llvm::StructType::get(getVMContext(), FrameFields,
|
|
|
|
/*isPacked=*/true));
|
2012-07-24 08:01:07 +08:00
|
|
|
}
|
|
|
|
|
2009-06-06 06:08:42 +08:00
|
|
|
llvm::Value *X86_32ABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
|
|
|
|
CodeGenFunction &CGF) const {
|
2012-02-07 08:39:47 +08:00
|
|
|
llvm::Type *BPP = CGF.Int8PtrPtrTy;
|
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");
|
2011-11-18 10:12:09 +08:00
|
|
|
|
|
|
|
// Compute if the address needs to be aligned
|
|
|
|
unsigned Align = CGF.getContext().getTypeAlignInChars(Ty).getQuantity();
|
|
|
|
Align = getTypeStackAlignInBytes(Ty, Align);
|
|
|
|
Align = std::max(Align, 4U);
|
|
|
|
if (Align > 4) {
|
|
|
|
// addr = (addr + align - 1) & -align;
|
|
|
|
llvm::Value *Offset =
|
|
|
|
llvm::ConstantInt::get(CGF.Int32Ty, Align - 1);
|
|
|
|
Addr = CGF.Builder.CreateGEP(Addr, Offset);
|
|
|
|
llvm::Value *AsInt = CGF.Builder.CreatePtrToInt(Addr,
|
|
|
|
CGF.Int32Ty);
|
|
|
|
llvm::Value *Mask = llvm::ConstantInt::get(CGF.Int32Ty, -Align);
|
|
|
|
Addr = CGF.Builder.CreateIntToPtr(CGF.Builder.CreateAnd(AsInt, Mask),
|
|
|
|
Addr->getType(),
|
|
|
|
"ap.cur.aligned");
|
|
|
|
}
|
|
|
|
|
2009-06-06 06:08:42 +08:00
|
|
|
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 =
|
2011-11-18 10:12:09 +08:00
|
|
|
llvm::RoundUpToAlignment(CGF.getContext().getTypeSize(Ty) / 8, Align);
|
2009-06-06 06:08:42 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-07-08 19:10:34 +08:00
|
|
|
bool X86_32TargetCodeGenInfo::isStructReturnInRegABI(
|
|
|
|
const llvm::Triple &Triple, const CodeGenOptions &Opts) {
|
|
|
|
assert(Triple.getArch() == llvm::Triple::x86);
|
|
|
|
|
|
|
|
switch (Opts.getStructReturnConvention()) {
|
|
|
|
case CodeGenOptions::SRCK_Default:
|
|
|
|
break;
|
|
|
|
case CodeGenOptions::SRCK_OnStack: // -fpcc-struct-return
|
|
|
|
return false;
|
|
|
|
case CodeGenOptions::SRCK_InRegs: // -freg-struct-return
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Triple.isOSDarwin())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
switch (Triple.getOS()) {
|
|
|
|
case llvm::Triple::DragonFly:
|
|
|
|
case llvm::Triple::FreeBSD:
|
|
|
|
case llvm::Triple::OpenBSD:
|
|
|
|
case llvm::Triple::Bitrig:
|
|
|
|
case llvm::Triple::Win32:
|
2014-11-25 06:05:42 +08:00
|
|
|
return true;
|
2014-07-08 19:10:34 +08:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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.
|
2012-10-16 04:36:26 +08:00
|
|
|
llvm::AttrBuilder B;
|
2012-10-14 11:28:14 +08:00
|
|
|
B.addStackAlignmentAttr(16);
|
2013-01-23 08:21:06 +08:00
|
|
|
Fn->addAttributes(llvm::AttributeSet::FunctionIndex,
|
|
|
|
llvm::AttributeSet::get(CGM.getLLVMContext(),
|
|
|
|
llvm::AttributeSet::FunctionIndex,
|
|
|
|
B));
|
2010-02-13 23:54:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-06 08:35:14 +08:00
|
|
|
bool X86_32TargetCodeGenInfo::initDwarfEHRegSizeTable(
|
|
|
|
CodeGen::CodeGenFunction &CGF,
|
|
|
|
llvm::Value *Address) const {
|
|
|
|
CodeGen::CGBuilderTy &Builder = CGF.Builder;
|
|
|
|
|
2012-02-07 08:39:47 +08:00
|
|
|
llvm::Value *Four8 = llvm::ConstantInt::get(CGF.Int8Ty, 4);
|
2010-08-26 02:17:27 +08:00
|
|
|
|
2010-03-06 08:35:14 +08:00
|
|
|
// 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
|
|
|
|
2013-04-17 06:48:15 +08:00
|
|
|
if (CGF.CGM.getTarget().getTriple().isOSDarwin()) {
|
2010-03-06 08:35:14 +08:00
|
|
|
// 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.
|
2012-02-07 08:39:47 +08:00
|
|
|
llvm::Value *Sixteen8 = llvm::ConstantInt::get(CGF.Int8Ty, 16);
|
2010-05-27 14:19:26 +08:00
|
|
|
AssignToArrayRange(Builder, Address, Sixteen8, 12, 16);
|
2010-08-26 02:17:27 +08:00
|
|
|
|
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.
|
2012-02-07 08:39:47 +08:00
|
|
|
llvm::Value *Twelve8 = llvm::ConstantInt::get(CGF.Int8Ty, 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
|
|
|
|
2011-07-12 06:41:29 +08:00
|
|
|
/// postMerge - Implement the X86_64 ABI post merging algorithm.
|
|
|
|
///
|
|
|
|
/// Post merger cleanup, reduces a malformed Hi and Lo pair to
|
|
|
|
/// final MEMORY or SSE classes when necessary.
|
|
|
|
///
|
|
|
|
/// \param AggregateSize - The size of the current aggregate in
|
|
|
|
/// the classification process.
|
|
|
|
///
|
|
|
|
/// \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 higher words of the containing object.
|
|
|
|
///
|
|
|
|
void postMerge(unsigned AggregateSize, Class &Lo, Class &Hi) const;
|
|
|
|
|
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.
|
|
|
|
///
|
2013-06-12 08:13:45 +08:00
|
|
|
/// \param isNamedArg - Whether the argument in question is a "named"
|
|
|
|
/// argument, as used in AMD64-ABI 3.5.7.
|
|
|
|
///
|
2009-06-06 06:08:42 +08:00
|
|
|
/// 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.
|
|
|
|
///
|
2012-09-27 18:16:10 +08:00
|
|
|
/// The \arg Lo class will be NoClass iff the argument is ignored.
|
2009-06-06 06:08:42 +08:00
|
|
|
///
|
|
|
|
/// If the \arg Lo class is ComplexX87, then the \arg Hi class will
|
|
|
|
/// also be ComplexX87.
|
2013-06-12 08:13:45 +08:00
|
|
|
void classify(QualType T, uint64_t OffsetBase, Class &Lo, Class &Hi,
|
|
|
|
bool isNamedArg) const;
|
2009-06-06 06:08:42 +08:00
|
|
|
|
2011-07-12 06:41:29 +08:00
|
|
|
llvm::Type *GetByteVectorType(QualType Ty) const;
|
2011-07-10 01:41:47 +08:00
|
|
|
llvm::Type *GetSSETypeAtOffset(llvm::Type *IRType,
|
|
|
|
unsigned IROffset, QualType SourceTy,
|
|
|
|
unsigned SourceOffset) const;
|
|
|
|
llvm::Type *GetINTEGERTypeAtOffset(llvm::Type *IRType,
|
|
|
|
unsigned IROffset, QualType SourceTy,
|
|
|
|
unsigned SourceOffset) const;
|
2010-08-26 02:17:27 +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.
|
IRgen/ABI/x86_64: Avoid passing small structs using byval sometimes.
- We do this when it is easy to determine that the backend will pass them on
the stack properly by itself.
Currently LLVM codegen is really bad in some cases with byval, for example, on
the test case here (which is derived from Sema code, which likes to pass
SourceLocations around)::
struct s47 { unsigned a; };
void f47(int,int,int,int,int,int,struct s47);
void test47(int a, struct s47 b) { f47(a, a, a, a, a, a, b); }
we used to emit code like this::
...
movl %esi, -8(%rbp)
movl -8(%rbp), %ecx
movl %ecx, (%rsp)
...
to handle moving the struct onto the stack, which is just appalling.
Now we generate::
movl %esi, (%rsp)
which seems better, no?
llvm-svn: 152462
2012-03-10 09:03:58 +08:00
|
|
|
///
|
|
|
|
/// \param freeIntRegs - The number of free integer registers remaining
|
|
|
|
/// available.
|
|
|
|
ABIArgInfo getIndirectResult(QualType Ty, unsigned freeIntRegs) 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-10-18 11:41:31 +08:00
|
|
|
ABIArgInfo classifyArgumentType(QualType Ty,
|
IRgen/ABI/x86_64: Avoid passing small structs using byval sometimes.
- We do this when it is easy to determine that the backend will pass them on
the stack properly by itself.
Currently LLVM codegen is really bad in some cases with byval, for example, on
the test case here (which is derived from Sema code, which likes to pass
SourceLocations around)::
struct s47 { unsigned a; };
void f47(int,int,int,int,int,int,struct s47);
void test47(int a, struct s47 b) { f47(a, a, a, a, a, a, b); }
we used to emit code like this::
...
movl %esi, -8(%rbp)
movl -8(%rbp), %ecx
movl %ecx, (%rsp)
...
to handle moving the struct onto the stack, which is just appalling.
Now we generate::
movl %esi, (%rsp)
which seems better, no?
llvm-svn: 152462
2012-03-10 09:03:58 +08:00
|
|
|
unsigned freeIntRegs,
|
2010-10-18 11:41:31 +08:00
|
|
|
unsigned &neededInt,
|
2013-06-12 08:13:45 +08:00
|
|
|
unsigned &neededSSE,
|
|
|
|
bool isNamedArg) const;
|
2009-06-06 06:08:42 +08:00
|
|
|
|
2011-12-02 08:11:43 +08:00
|
|
|
bool IsIllegalVectorType(QualType Ty) const;
|
|
|
|
|
2011-04-21 09:20:55 +08:00
|
|
|
/// The 0.98 ABI revision clarified a lot of ambiguities,
|
|
|
|
/// unfortunately in ways that were not always consistent with
|
|
|
|
/// certain previous compilers. In particular, platforms which
|
|
|
|
/// required strict binary compatibility with older versions of GCC
|
|
|
|
/// may need to exempt themselves.
|
|
|
|
bool honorsRevision0_98() const {
|
2013-04-17 06:48:15 +08:00
|
|
|
return !getTarget().getTriple().isOSDarwin();
|
2011-04-21 09:20:55 +08:00
|
|
|
}
|
|
|
|
|
2011-12-02 08:11:43 +08:00
|
|
|
bool HasAVX;
|
2012-10-11 23:52:22 +08:00
|
|
|
// Some ABIs (e.g. X32 ABI and Native Client OS) use 32 bit pointers on
|
|
|
|
// 64-bit hardware.
|
|
|
|
bool Has64BitPointers;
|
2011-12-02 08:11:43 +08:00
|
|
|
|
2009-06-06 06:08:42 +08:00
|
|
|
public:
|
2011-12-02 08:11:43 +08:00
|
|
|
X86_64ABIInfo(CodeGen::CodeGenTypes &CGT, bool hasavx) :
|
2012-10-11 23:52:22 +08:00
|
|
|
ABIInfo(CGT), HasAVX(hasavx),
|
2012-10-12 02:21:13 +08:00
|
|
|
Has64BitPointers(CGT.getDataLayout().getPointerSize(0) == 8) {
|
2012-10-11 23:52:22 +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
|
|
|
|
2012-02-17 11:33:10 +08:00
|
|
|
bool isPassedUsingAVXType(QualType type) const {
|
|
|
|
unsigned neededInt, neededSSE;
|
IRgen/ABI/x86_64: Avoid passing small structs using byval sometimes.
- We do this when it is easy to determine that the backend will pass them on
the stack properly by itself.
Currently LLVM codegen is really bad in some cases with byval, for example, on
the test case here (which is derived from Sema code, which likes to pass
SourceLocations around)::
struct s47 { unsigned a; };
void f47(int,int,int,int,int,int,struct s47);
void test47(int a, struct s47 b) { f47(a, a, a, a, a, a, b); }
we used to emit code like this::
...
movl %esi, -8(%rbp)
movl -8(%rbp), %ecx
movl %ecx, (%rsp)
...
to handle moving the struct onto the stack, which is just appalling.
Now we generate::
movl %esi, (%rsp)
which seems better, no?
llvm-svn: 152462
2012-03-10 09:03:58 +08:00
|
|
|
// The freeIntRegs argument doesn't matter here.
|
2013-06-12 08:13:45 +08:00
|
|
|
ABIArgInfo info = classifyArgumentType(type, 0, neededInt, neededSSE,
|
|
|
|
/*isNamedArg*/true);
|
2012-02-17 11:33:10 +08:00
|
|
|
if (info.isDirect()) {
|
|
|
|
llvm::Type *ty = info.getCoerceToType();
|
|
|
|
if (llvm::VectorType *vectorTy = dyn_cast_or_null<llvm::VectorType>(ty))
|
|
|
|
return (vectorTy->getBitWidth() > 128);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-03-12 14:41:41 +08:00
|
|
|
void computeInfo(CGFunctionInfo &FI) const override;
|
2009-06-06 06:08:42 +08:00
|
|
|
|
2014-03-12 14:41:41 +08:00
|
|
|
llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
|
|
|
|
CodeGenFunction &CGF) const override;
|
2009-06-06 06:08:42 +08:00
|
|
|
};
|
2010-01-10 20:58:08 +08:00
|
|
|
|
2010-09-01 00:44:54 +08:00
|
|
|
/// WinX86_64ABIInfo - The Windows X86_64 ABI information.
|
2011-01-18 06:56:31 +08:00
|
|
|
class WinX86_64ABIInfo : public ABIInfo {
|
|
|
|
|
2014-11-01 06:00:51 +08:00
|
|
|
ABIArgInfo classify(QualType Ty, unsigned &FreeSSERegs,
|
|
|
|
bool IsReturnType) const;
|
2011-01-18 06:56:31 +08:00
|
|
|
|
2010-09-01 00:44:54 +08:00
|
|
|
public:
|
2011-01-18 06:56:31 +08:00
|
|
|
WinX86_64ABIInfo(CodeGen::CodeGenTypes &CGT) : ABIInfo(CGT) {}
|
|
|
|
|
2014-03-12 14:41:41 +08:00
|
|
|
void computeInfo(CGFunctionInfo &FI) const override;
|
2010-09-01 00:44:54 +08:00
|
|
|
|
2014-03-12 14:41:41 +08:00
|
|
|
llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
|
|
|
|
CodeGenFunction &CGF) const override;
|
2014-11-01 06:00:51 +08:00
|
|
|
|
|
|
|
bool isHomogeneousAggregateBaseType(QualType Ty) const override {
|
|
|
|
// FIXME: Assumes vectorcall is in use.
|
|
|
|
return isX86VectorTypeForVectorCall(getContext(), Ty);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isHomogeneousAggregateSmallEnough(const Type *Ty,
|
|
|
|
uint64_t NumMembers) const override {
|
|
|
|
// FIXME: Assumes vectorcall is in use.
|
|
|
|
return isX86VectorCallAggregateSmallEnough(NumMembers);
|
|
|
|
}
|
2010-09-01 00:44:54 +08:00
|
|
|
};
|
|
|
|
|
2010-01-10 20:58:08 +08:00
|
|
|
class X86_64TargetCodeGenInfo : public TargetCodeGenInfo {
|
2014-09-30 13:29:28 +08:00
|
|
|
bool HasAVX;
|
2010-01-10 20:58:08 +08:00
|
|
|
public:
|
2011-12-02 08:11:43 +08:00
|
|
|
X86_64TargetCodeGenInfo(CodeGen::CodeGenTypes &CGT, bool HasAVX)
|
2014-09-30 13:29:28 +08:00
|
|
|
: TargetCodeGenInfo(new X86_64ABIInfo(CGT, HasAVX)), HasAVX(HasAVX) {}
|
2010-03-06 08:35:14 +08:00
|
|
|
|
2012-02-17 11:33:10 +08:00
|
|
|
const X86_64ABIInfo &getABIInfo() const {
|
|
|
|
return static_cast<const X86_64ABIInfo&>(TargetCodeGenInfo::getABIInfo());
|
|
|
|
}
|
|
|
|
|
2014-03-12 14:41:41 +08:00
|
|
|
int getDwarfEHStackPointer(CodeGen::CodeGenModule &CGM) const override {
|
2010-03-06 08:35:14 +08:00
|
|
|
return 7;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
|
2014-03-12 14:41:41 +08:00
|
|
|
llvm::Value *Address) const override {
|
2012-02-07 08:39:47 +08:00
|
|
|
llvm::Value *Eight8 = llvm::ConstantInt::get(CGF.Int8Ty, 8);
|
2010-08-26 02:17:27 +08:00
|
|
|
|
2010-05-27 14:19:26 +08:00
|
|
|
// 0-15 are the 16 integer registers.
|
|
|
|
// 16 is %rip.
|
2012-02-07 08:39:47 +08:00
|
|
|
AssignToArrayRange(CGF.Builder, Address, Eight8, 0, 16);
|
2010-03-06 08:35:14 +08:00
|
|
|
return false;
|
|
|
|
}
|
2011-02-20 07:03:58 +08:00
|
|
|
|
2011-07-11 17:56:20 +08:00
|
|
|
llvm::Type* adjustInlineAsmType(CodeGen::CodeGenFunction &CGF,
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef Constraint,
|
2014-03-12 14:41:41 +08:00
|
|
|
llvm::Type* Ty) const override {
|
2011-02-20 07:03:58 +08:00
|
|
|
return X86AdjustInlineAsmType(CGF, Constraint, Ty);
|
|
|
|
}
|
|
|
|
|
2012-02-17 11:33:10 +08:00
|
|
|
bool isNoProtoCallVariadic(const CallArgList &args,
|
2014-03-12 14:41:41 +08:00
|
|
|
const FunctionNoProtoType *fnType) const override {
|
2011-09-21 16:08:30 +08:00
|
|
|
// The default CC on x86-64 sets %al to the number of SSA
|
|
|
|
// registers used, and GCC sets this when calling an unprototyped
|
2011-12-01 12:53:19 +08:00
|
|
|
// function, so we override the default behavior. However, don't do
|
2011-12-06 11:08:26 +08:00
|
|
|
// that when AVX types are involved: the ABI explicitly states it is
|
|
|
|
// undefined, and it doesn't work in practice because of how the ABI
|
|
|
|
// defines varargs anyway.
|
2013-08-28 07:08:25 +08:00
|
|
|
if (fnType->getCallConv() == CC_C) {
|
2011-12-01 12:53:19 +08:00
|
|
|
bool HasAVXType = false;
|
2012-02-17 11:33:10 +08:00
|
|
|
for (CallArgList::const_iterator
|
|
|
|
it = args.begin(), ie = args.end(); it != ie; ++it) {
|
|
|
|
if (getABIInfo().isPassedUsingAVXType(it->Ty)) {
|
|
|
|
HasAVXType = true;
|
|
|
|
break;
|
2011-12-01 12:53:19 +08:00
|
|
|
}
|
|
|
|
}
|
2012-02-17 11:33:10 +08:00
|
|
|
|
2011-12-01 12:53:19 +08:00
|
|
|
if (!HasAVXType)
|
|
|
|
return true;
|
|
|
|
}
|
2011-09-21 16:08:30 +08:00
|
|
|
|
2012-02-17 11:33:10 +08:00
|
|
|
return TargetCodeGenInfo::isNoProtoCallVariadic(args, fnType);
|
2011-09-21 16:08:30 +08:00
|
|
|
}
|
|
|
|
|
2014-03-12 14:41:41 +08:00
|
|
|
llvm::Constant *
|
|
|
|
getUBSanFunctionSignature(CodeGen::CodeGenModule &CGM) const override {
|
2013-10-21 05:29:19 +08:00
|
|
|
unsigned Sig = (0xeb << 0) | // jmp rel8
|
|
|
|
(0x0a << 8) | // .+0x0c
|
|
|
|
('F' << 16) |
|
|
|
|
('T' << 24);
|
|
|
|
return llvm::ConstantInt::get(CGM.Int32Ty, Sig);
|
|
|
|
}
|
|
|
|
|
2014-09-30 13:29:28 +08:00
|
|
|
unsigned getOpenMPSimdDefaultAlignment(QualType) const override {
|
|
|
|
return HasAVX ? 32 : 16;
|
|
|
|
}
|
2010-01-10 20:58:08 +08:00
|
|
|
};
|
|
|
|
|
2013-05-24 23:06:56 +08:00
|
|
|
static std::string qualifyWindowsLibrary(llvm::StringRef Lib) {
|
|
|
|
// If the argument does not end in .lib, automatically add the suffix. This
|
|
|
|
// matches the behavior of MSVC.
|
|
|
|
std::string ArgStr = Lib;
|
2013-11-01 03:12:53 +08:00
|
|
|
if (!Lib.endswith_lower(".lib"))
|
2013-05-24 23:06:56 +08:00
|
|
|
ArgStr += ".lib";
|
|
|
|
return ArgStr;
|
|
|
|
}
|
|
|
|
|
2013-05-08 21:44:39 +08:00
|
|
|
class WinX86_32TargetCodeGenInfo : public X86_32TargetCodeGenInfo {
|
|
|
|
public:
|
2013-06-18 10:46:29 +08:00
|
|
|
WinX86_32TargetCodeGenInfo(CodeGen::CodeGenTypes &CGT,
|
|
|
|
bool d, bool p, bool w, unsigned RegParms)
|
|
|
|
: X86_32TargetCodeGenInfo(CGT, d, p, w, RegParms) {}
|
2013-05-08 21:44:39 +08:00
|
|
|
|
|
|
|
void getDependentLibraryOption(llvm::StringRef Lib,
|
2014-03-12 14:41:41 +08:00
|
|
|
llvm::SmallString<24> &Opt) const override {
|
2013-05-08 21:44:39 +08:00
|
|
|
Opt = "/DEFAULTLIB:";
|
2013-05-24 23:06:56 +08:00
|
|
|
Opt += qualifyWindowsLibrary(Lib);
|
2013-05-08 21:44:39 +08:00
|
|
|
}
|
2013-06-04 10:07:14 +08:00
|
|
|
|
|
|
|
void getDetectMismatchOption(llvm::StringRef Name,
|
|
|
|
llvm::StringRef Value,
|
2014-03-12 14:41:41 +08:00
|
|
|
llvm::SmallString<32> &Opt) const override {
|
2013-06-08 06:42:22 +08:00
|
|
|
Opt = "/FAILIFMISMATCH:\"" + Name.str() + "=" + Value.str() + "\"";
|
2013-06-04 10:07:14 +08:00
|
|
|
}
|
2013-05-08 21:44:39 +08:00
|
|
|
};
|
|
|
|
|
2010-09-01 00:44:54 +08:00
|
|
|
class WinX86_64TargetCodeGenInfo : public TargetCodeGenInfo {
|
2014-09-30 13:29:28 +08:00
|
|
|
bool HasAVX;
|
2010-09-01 00:44:54 +08:00
|
|
|
public:
|
2014-09-30 13:29:28 +08:00
|
|
|
WinX86_64TargetCodeGenInfo(CodeGen::CodeGenTypes &CGT, bool HasAVX)
|
|
|
|
: TargetCodeGenInfo(new WinX86_64ABIInfo(CGT)), HasAVX(HasAVX) {}
|
2010-09-01 00:44:54 +08:00
|
|
|
|
2014-03-12 14:41:41 +08:00
|
|
|
int getDwarfEHStackPointer(CodeGen::CodeGenModule &CGM) const override {
|
2010-09-01 00:44:54 +08:00
|
|
|
return 7;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
|
2014-03-12 14:41:41 +08:00
|
|
|
llvm::Value *Address) const override {
|
2012-02-07 08:39:47 +08:00
|
|
|
llvm::Value *Eight8 = llvm::ConstantInt::get(CGF.Int8Ty, 8);
|
2010-10-19 14:39:39 +08:00
|
|
|
|
2010-09-01 00:44:54 +08:00
|
|
|
// 0-15 are the 16 integer registers.
|
|
|
|
// 16 is %rip.
|
2012-02-07 08:39:47 +08:00
|
|
|
AssignToArrayRange(CGF.Builder, Address, Eight8, 0, 16);
|
2010-09-01 00:44:54 +08:00
|
|
|
return false;
|
|
|
|
}
|
2013-05-08 21:44:39 +08:00
|
|
|
|
|
|
|
void getDependentLibraryOption(llvm::StringRef Lib,
|
2014-03-12 14:41:41 +08:00
|
|
|
llvm::SmallString<24> &Opt) const override {
|
2013-05-08 21:44:39 +08:00
|
|
|
Opt = "/DEFAULTLIB:";
|
2013-05-24 23:06:56 +08:00
|
|
|
Opt += qualifyWindowsLibrary(Lib);
|
2013-05-08 21:44:39 +08:00
|
|
|
}
|
2013-06-04 10:07:14 +08:00
|
|
|
|
|
|
|
void getDetectMismatchOption(llvm::StringRef Name,
|
|
|
|
llvm::StringRef Value,
|
2014-03-12 14:41:41 +08:00
|
|
|
llvm::SmallString<32> &Opt) const override {
|
2013-06-08 06:42:22 +08:00
|
|
|
Opt = "/FAILIFMISMATCH:\"" + Name.str() + "=" + Value.str() + "\"";
|
2013-06-04 10:07:14 +08:00
|
|
|
}
|
2014-09-30 13:29:28 +08:00
|
|
|
|
|
|
|
unsigned getOpenMPSimdDefaultAlignment(QualType) const override {
|
|
|
|
return HasAVX ? 32 : 16;
|
|
|
|
}
|
2010-09-01 00:44:54 +08:00
|
|
|
};
|
|
|
|
|
2009-06-06 06:08:42 +08:00
|
|
|
}
|
|
|
|
|
2011-07-12 06:41:29 +08:00
|
|
|
void X86_64ABIInfo::postMerge(unsigned AggregateSize, Class &Lo,
|
|
|
|
Class &Hi) const {
|
|
|
|
// 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 X87UP is not preceded by X87, the whole argument is passed in
|
|
|
|
// memory.
|
|
|
|
//
|
|
|
|
// (c) If the size of the aggregate exceeds two eightbytes and the first
|
|
|
|
// eightbyte isn't SSE or any other eightbyte isn't SSEUP, the whole
|
|
|
|
// argument is passed in memory. NOTE: This is necessary to keep the
|
|
|
|
// ABI working for processors that don't support the __m256 type.
|
|
|
|
//
|
|
|
|
// (d) If SSEUP is not preceded by SSE or SSEUP, it is converted to SSE.
|
|
|
|
//
|
|
|
|
// Some of these are enforced by the merging logic. Others can arise
|
|
|
|
// only with unions; for example:
|
|
|
|
// union { _Complex double; unsigned; }
|
|
|
|
//
|
|
|
|
// Note that clauses (b) and (c) were added in 0.98.
|
|
|
|
//
|
|
|
|
if (Hi == Memory)
|
|
|
|
Lo = Memory;
|
|
|
|
if (Hi == X87Up && Lo != X87 && honorsRevision0_98())
|
|
|
|
Lo = Memory;
|
|
|
|
if (AggregateSize > 128 && (Lo != SSE || Hi != SSEUp))
|
|
|
|
Lo = Memory;
|
|
|
|
if (Hi == SSEUp && Lo != SSE)
|
|
|
|
Hi = SSE;
|
|
|
|
}
|
|
|
|
|
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,
|
2013-06-12 08:13:45 +08:00
|
|
|
Class &Lo, Class &Hi, bool isNamedArg) const {
|
2009-06-06 06:08:42 +08:00
|
|
|
// 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;
|
2012-10-12 00:55:58 +08:00
|
|
|
} else if ((k == BuiltinType::Float || k == BuiltinType::Double) ||
|
|
|
|
(k == BuiltinType::LongDouble &&
|
2013-09-14 09:09:11 +08:00
|
|
|
getTarget().getTriple().isOSNaCl())) {
|
2009-06-06 06:08:42 +08:00
|
|
|
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;
|
|
|
|
}
|
2010-08-26 02:17:27 +08:00
|
|
|
|
2010-06-29 05:43:59 +08:00
|
|
|
if (const EnumType *ET = Ty->getAs<EnumType>()) {
|
2009-06-06 06:08:42 +08:00
|
|
|
// Classify the underlying integer type.
|
2013-06-12 08:13:45 +08:00
|
|
|
classify(ET->getDecl()->getIntegerType(), OffsetBase, Lo, Hi, isNamedArg);
|
2010-06-29 05:43:59 +08:00
|
|
|
return;
|
|
|
|
}
|
2010-08-26 02:17:27 +08:00
|
|
|
|
2010-06-29 05:43:59 +08:00
|
|
|
if (Ty->hasPointerRepresentation()) {
|
2009-06-06 06:08:42 +08:00
|
|
|
Current = Integer;
|
2010-06-29 05:43:59 +08:00
|
|
|
return;
|
|
|
|
}
|
2010-08-26 02:17:27 +08:00
|
|
|
|
2010-06-29 05:43:59 +08:00
|
|
|
if (Ty->isMemberPointerType()) {
|
2014-10-03 00:56:57 +08:00
|
|
|
if (Ty->isMemberFunctionPointerType()) {
|
|
|
|
if (Has64BitPointers) {
|
|
|
|
// If Has64BitPointers, this is an {i64, i64}, so classify both
|
|
|
|
// Lo and Hi now.
|
|
|
|
Lo = Hi = Integer;
|
|
|
|
} else {
|
|
|
|
// Otherwise, with 32-bit pointers, this is an {i32, i32}. If that
|
|
|
|
// straddles an eightbyte boundary, Hi should be classified as well.
|
|
|
|
uint64_t EB_FuncPtr = (OffsetBase) / 64;
|
|
|
|
uint64_t EB_ThisAdj = (OffsetBase + 64 - 1) / 64;
|
|
|
|
if (EB_FuncPtr != EB_ThisAdj) {
|
|
|
|
Lo = Hi = Integer;
|
|
|
|
} else {
|
|
|
|
Current = Integer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2010-05-15 08:00:37 +08:00
|
|
|
Current = Integer;
|
2014-10-03 00:56:57 +08:00
|
|
|
}
|
2010-06-29 05:43:59 +08:00
|
|
|
return;
|
|
|
|
}
|
2010-08-26 02:17:27 +08:00
|
|
|
|
2010-06-29 05:43:59 +08:00
|
|
|
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.
|
2010-08-27 02:03:20 +08:00
|
|
|
if (VT->getElementType()->isSpecificBuiltinType(BuiltinType::LongLong) ||
|
2010-08-27 02:13:50 +08:00
|
|
|
VT->getElementType()->isSpecificBuiltinType(BuiltinType::ULongLong) ||
|
|
|
|
VT->getElementType()->isSpecificBuiltinType(BuiltinType::Long) ||
|
|
|
|
VT->getElementType()->isSpecificBuiltinType(BuiltinType::ULong))
|
2009-06-06 06:08:42 +08:00
|
|
|
Current = Integer;
|
|
|
|
else
|
|
|
|
Current = SSE;
|
|
|
|
|
|
|
|
// If this type crosses an eightbyte boundary, it should be
|
|
|
|
// split.
|
|
|
|
if (OffsetBase && OffsetBase != 64)
|
|
|
|
Hi = Lo;
|
2013-06-12 08:13:45 +08:00
|
|
|
} else if (Size == 128 || (HasAVX && isNamedArg && Size == 256)) {
|
2011-07-12 06:41:29 +08:00
|
|
|
// Arguments of 256-bits are split into four eightbyte chunks. The
|
|
|
|
// least significant one belongs to class SSE and all the others to class
|
|
|
|
// SSEUP. The original Lo and Hi design considers that types can't be
|
|
|
|
// greater than 128-bits, so a 64-bit split in Hi and Lo makes sense.
|
|
|
|
// This design isn't correct for 256-bits, but since there're no cases
|
|
|
|
// where the upper parts would need to be inspected, avoid adding
|
|
|
|
// complexity and just consider Hi to match the 64-256 part.
|
2013-06-12 08:13:45 +08:00
|
|
|
//
|
|
|
|
// Note that per 3.5.7 of AMD64-ABI, 256-bit args are only passed in
|
|
|
|
// registers if they are "named", i.e. not part of the "..." of a
|
|
|
|
// variadic function.
|
2009-06-06 06:08:42 +08:00
|
|
|
Lo = SSE;
|
|
|
|
Hi = SSEUp;
|
|
|
|
}
|
2010-06-29 05:43:59 +08:00
|
|
|
return;
|
|
|
|
}
|
2010-08-26 02:17:27 +08:00
|
|
|
|
2010-06-29 05:43:59 +08:00
|
|
|
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;
|
2012-10-12 00:55:58 +08:00
|
|
|
else if (ET == getContext().DoubleTy ||
|
|
|
|
(ET == getContext().LongDoubleTy &&
|
2013-09-14 09:09:11 +08:00
|
|
|
getTarget().getTriple().isOSNaCl()))
|
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-08-26 02:17:27 +08:00
|
|
|
|
2010-06-29 05:43:59 +08:00
|
|
|
return;
|
|
|
|
}
|
2010-08-26 02:17:27 +08:00
|
|
|
|
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
|
2011-07-12 06:41:29 +08:00
|
|
|
// than four eightbytes, ..., it has class MEMORY.
|
|
|
|
if (Size > 256)
|
2009-06-06 06:08:42 +08:00
|
|
|
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();
|
2011-07-12 09:27:38 +08:00
|
|
|
|
|
|
|
// The only case a 256-bit wide vector could be used is when the array
|
|
|
|
// contains a single 256-bit element. Since Lo and Hi logic isn't extended
|
|
|
|
// to work for sizes wider than 128, early check and fallback to memory.
|
|
|
|
if (Size > 128 && EltSize != 256)
|
|
|
|
return;
|
|
|
|
|
2009-06-06 06:08:42 +08:00
|
|
|
for (uint64_t i=0, Offset=OffsetBase; i<ArraySize; ++i, Offset += EltSize) {
|
|
|
|
Class FieldLo, FieldHi;
|
2013-06-12 08:13:45 +08:00
|
|
|
classify(AT->getElementType(), Offset, FieldLo, FieldHi, isNamedArg);
|
2009-06-06 06:08:42 +08:00
|
|
|
Lo = merge(Lo, FieldLo);
|
|
|
|
Hi = merge(Hi, FieldHi);
|
|
|
|
if (Lo == Memory || Hi == Memory)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-07-12 06:41:29 +08:00
|
|
|
postMerge(Size, Lo, Hi);
|
2009-06-06 06:08:42 +08:00
|
|
|
assert((Hi != SSEUp || Lo == SSE) && "Invalid SSEUp array classification.");
|
2010-06-29 05:43:59 +08:00
|
|
|
return;
|
|
|
|
}
|
2010-08-26 02:17:27 +08:00
|
|
|
|
2010-06-29 05:43:59 +08:00
|
|
|
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
|
2011-07-12 06:41:29 +08:00
|
|
|
// than four eightbytes, ..., it has class MEMORY.
|
|
|
|
if (Size > 256)
|
2009-06-06 06:08:42 +08:00
|
|
|
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.
|
2013-10-06 09:33:34 +08:00
|
|
|
if (getRecordArgABI(RT, getCXXABI()))
|
2009-09-16 23:53:40 +08:00
|
|
|
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)) {
|
2014-03-13 23:41:46 +08:00
|
|
|
for (const auto &I : CXXRD->bases()) {
|
|
|
|
assert(!I.isVirtual() && !I.getType()->isDependentType() &&
|
2009-11-23 07:01:23 +08:00
|
|
|
"Unexpected base class!");
|
|
|
|
const CXXRecordDecl *Base =
|
2014-03-13 23:41:46 +08:00
|
|
|
cast<CXXRecordDecl>(I.getType()->getAs<RecordType>()->getDecl());
|
2009-11-23 07:01:23 +08:00
|
|
|
|
|
|
|
// 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;
|
2012-07-05 02:45:14 +08:00
|
|
|
uint64_t Offset =
|
|
|
|
OffsetBase + getContext().toBits(Layout.getBaseClassOffset(Base));
|
2014-03-13 23:41:46 +08:00
|
|
|
classify(I.getType(), Offset, FieldLo, FieldHi, isNamedArg);
|
2009-11-23 07:01:23 +08:00
|
|
|
Lo = merge(Lo, FieldLo);
|
|
|
|
Hi = merge(Hi, FieldHi);
|
|
|
|
if (Lo == Memory || Hi == Memory)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Classify the fields one at a time, merging the results.
|
2009-06-06 06:08:42 +08:00
|
|
|
unsigned idx = 0;
|
2011-07-13 06:30:58 +08:00
|
|
|
for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end();
|
2009-06-30 10:36:12 +08:00
|
|
|
i != e; ++i, ++idx) {
|
2009-06-06 06:08:42 +08:00
|
|
|
uint64_t Offset = OffsetBase + Layout.getFieldOffset(idx);
|
|
|
|
bool BitField = i->isBitField();
|
|
|
|
|
2011-07-14 05:58:55 +08:00
|
|
|
// AMD64-ABI 3.2.3p2: Rule 1. If the size of an object is larger than
|
|
|
|
// four eightbytes, or it contains unaligned fields, it has class MEMORY.
|
2009-06-06 06:08:42 +08:00
|
|
|
//
|
2011-07-14 05:58:55 +08:00
|
|
|
// The only case a 256-bit wide vector could be used is when the struct
|
|
|
|
// contains a single 256-bit element. Since Lo and Hi logic isn't extended
|
|
|
|
// to work for sizes wider than 128, early check and fallback to memory.
|
|
|
|
//
|
|
|
|
if (Size > 128 && getContext().getTypeSize(i->getType()) != 256) {
|
|
|
|
Lo = Memory;
|
|
|
|
return;
|
|
|
|
}
|
2009-06-06 06:08:42 +08:00
|
|
|
// 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);
|
2011-10-11 02:28:20 +08:00
|
|
|
uint64_t Size = i->getBitWidthValue(getContext());
|
2009-06-06 06:08:42 +08:00
|
|
|
|
|
|
|
uint64_t EB_Lo = Offset / 64;
|
|
|
|
uint64_t EB_Hi = (Offset + Size - 1) / 64;
|
2013-10-06 17:54:18 +08:00
|
|
|
|
2009-06-06 06:08:42 +08:00
|
|
|
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
|
2013-06-12 08:13:45 +08:00
|
|
|
classify(i->getType(), Offset, FieldLo, FieldHi, isNamedArg);
|
2009-06-06 06:08:42 +08:00
|
|
|
Lo = merge(Lo, FieldLo);
|
|
|
|
Hi = merge(Hi, FieldHi);
|
|
|
|
if (Lo == Memory || Hi == Memory)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-07-12 06:41:29 +08:00
|
|
|
postMerge(Size, Lo, Hi);
|
2009-06-06 06:08:42 +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
|
|
|
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.
|
2010-08-22 18:59:02 +08:00
|
|
|
if (!isAggregateTypeForABI(Ty)) {
|
2010-04-22 03:49:55 +08:00
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
2011-12-02 08:11:43 +08:00
|
|
|
bool X86_64ABIInfo::IsIllegalVectorType(QualType Ty) const {
|
|
|
|
if (const VectorType *VecTy = Ty->getAs<VectorType>()) {
|
|
|
|
uint64_t Size = getContext().getTypeSize(VecTy);
|
|
|
|
unsigned LargestVector = HasAVX ? 256 : 128;
|
|
|
|
if (Size <= 64 || Size > LargestVector)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
IRgen/ABI/x86_64: Avoid passing small structs using byval sometimes.
- We do this when it is easy to determine that the backend will pass them on
the stack properly by itself.
Currently LLVM codegen is really bad in some cases with byval, for example, on
the test case here (which is derived from Sema code, which likes to pass
SourceLocations around)::
struct s47 { unsigned a; };
void f47(int,int,int,int,int,int,struct s47);
void test47(int a, struct s47 b) { f47(a, a, a, a, a, a, b); }
we used to emit code like this::
...
movl %esi, -8(%rbp)
movl -8(%rbp), %ecx
movl %ecx, (%rsp)
...
to handle moving the struct onto the stack, which is just appalling.
Now we generate::
movl %esi, (%rsp)
which seems better, no?
llvm-svn: 152462
2012-03-10 09:03:58 +08:00
|
|
|
ABIArgInfo X86_64ABIInfo::getIndirectResult(QualType Ty,
|
|
|
|
unsigned freeIntRegs) 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.
|
IRgen/ABI/x86_64: Avoid passing small structs using byval sometimes.
- We do this when it is easy to determine that the backend will pass them on
the stack properly by itself.
Currently LLVM codegen is really bad in some cases with byval, for example, on
the test case here (which is derived from Sema code, which likes to pass
SourceLocations around)::
struct s47 { unsigned a; };
void f47(int,int,int,int,int,int,struct s47);
void test47(int a, struct s47 b) { f47(a, a, a, a, a, a, b); }
we used to emit code like this::
...
movl %esi, -8(%rbp)
movl -8(%rbp), %ecx
movl %ecx, (%rsp)
...
to handle moving the struct onto the stack, which is just appalling.
Now we generate::
movl %esi, (%rsp)
which seems better, no?
llvm-svn: 152462
2012-03-10 09:03:58 +08:00
|
|
|
//
|
|
|
|
// This assumption is optimistic, as there could be free registers available
|
|
|
|
// when we need to pass this argument in memory, and LLVM could try to pass
|
|
|
|
// the argument in the free register. This does not seem to happen currently,
|
|
|
|
// but this code would be much safer if we could mark the argument with
|
|
|
|
// 'onstack'. See PR12193.
|
2011-12-02 08:11:43 +08:00
|
|
|
if (!isAggregateTypeForABI(Ty) && !IsIllegalVectorType(Ty)) {
|
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();
|
|
|
|
|
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
|
|
|
|
2013-10-06 09:33:34 +08:00
|
|
|
if (CGCXXABI::RecordArgABI RAA = getRecordArgABI(Ty, getCXXABI()))
|
2013-04-17 20:54:10 +08:00
|
|
|
return ABIArgInfo::getIndirect(0, RAA == CGCXXABI::RAA_DirectInMemory);
|
2009-09-16 23:53:40 +08:00
|
|
|
|
2011-05-23 07:21:23 +08:00
|
|
|
// Compute the byval alignment. We specify the alignment of the byval in all
|
|
|
|
// cases so that the mid-level optimizer knows the alignment of the byval.
|
|
|
|
unsigned Align = std::max(getContext().getTypeAlign(Ty) / 8, 8U);
|
IRgen/ABI/x86_64: Avoid passing small structs using byval sometimes.
- We do this when it is easy to determine that the backend will pass them on
the stack properly by itself.
Currently LLVM codegen is really bad in some cases with byval, for example, on
the test case here (which is derived from Sema code, which likes to pass
SourceLocations around)::
struct s47 { unsigned a; };
void f47(int,int,int,int,int,int,struct s47);
void test47(int a, struct s47 b) { f47(a, a, a, a, a, a, b); }
we used to emit code like this::
...
movl %esi, -8(%rbp)
movl -8(%rbp), %ecx
movl %ecx, (%rsp)
...
to handle moving the struct onto the stack, which is just appalling.
Now we generate::
movl %esi, (%rsp)
which seems better, no?
llvm-svn: 152462
2012-03-10 09:03:58 +08:00
|
|
|
|
|
|
|
// Attempt to avoid passing indirect results using byval when possible. This
|
|
|
|
// is important for good codegen.
|
|
|
|
//
|
|
|
|
// We do this by coercing the value into a scalar type which the backend can
|
|
|
|
// handle naturally (i.e., without using byval).
|
|
|
|
//
|
|
|
|
// For simplicity, we currently only do this when we have exhausted all of the
|
|
|
|
// free integer registers. Doing this when there are free integer registers
|
|
|
|
// would require more care, as we would have to ensure that the coerced value
|
|
|
|
// did not claim the unused register. That would require either reording the
|
|
|
|
// arguments to the function (so that any subsequent inreg values came first),
|
|
|
|
// or only doing this optimization when there were no following arguments that
|
|
|
|
// might be inreg.
|
|
|
|
//
|
|
|
|
// We currently expect it to be rare (particularly in well written code) for
|
|
|
|
// arguments to be passed on the stack when there are still free integer
|
|
|
|
// registers available (this would typically imply large structs being passed
|
|
|
|
// by value), so this seems like a fair tradeoff for now.
|
|
|
|
//
|
|
|
|
// We can revisit this if the backend grows support for 'onstack' parameter
|
|
|
|
// attributes. See PR12193.
|
|
|
|
if (freeIntRegs == 0) {
|
|
|
|
uint64_t Size = getContext().getTypeSize(Ty);
|
|
|
|
|
|
|
|
// If this type fits in an eightbyte, coerce it into the matching integral
|
|
|
|
// type, which will end up on the stack (with alignment 8).
|
|
|
|
if (Align == 8 && Size <= 64)
|
|
|
|
return ABIArgInfo::getDirect(llvm::IntegerType::get(getVMContext(),
|
|
|
|
Size));
|
|
|
|
}
|
|
|
|
|
2011-05-23 07:21:23 +08:00
|
|
|
return ABIArgInfo::getIndirect(Align);
|
2009-06-06 06:08:42 +08:00
|
|
|
}
|
|
|
|
|
2011-07-12 06:41:29 +08:00
|
|
|
/// GetByteVectorType - The ABI specifies that a value should be passed in an
|
|
|
|
/// full vector XMM/YMM register. Pick an LLVM IR type that will be passed as a
|
2010-07-29 12:56:46 +08:00
|
|
|
/// vector register.
|
2011-07-12 06:41:29 +08:00
|
|
|
llvm::Type *X86_64ABIInfo::GetByteVectorType(QualType Ty) const {
|
2011-07-10 01:41:47 +08:00
|
|
|
llvm::Type *IRType = CGT.ConvertType(Ty);
|
2010-08-26 02:17:27 +08:00
|
|
|
|
2010-07-29 13:02:29 +08:00
|
|
|
// Wrapper structs that just contain vectors are passed just like vectors,
|
|
|
|
// strip them off if present.
|
2011-07-10 01:41:47 +08:00
|
|
|
llvm::StructType *STy = dyn_cast<llvm::StructType>(IRType);
|
2010-07-29 13:02:29 +08:00
|
|
|
while (STy && STy->getNumElements() == 1) {
|
|
|
|
IRType = STy->getElementType(0);
|
|
|
|
STy = dyn_cast<llvm::StructType>(IRType);
|
|
|
|
}
|
2010-08-26 02:17:27 +08:00
|
|
|
|
2011-07-09 06:57:35 +08:00
|
|
|
// If the preferred type is a 16-byte vector, prefer to pass it.
|
2011-07-10 01:41:47 +08:00
|
|
|
if (llvm::VectorType *VT = dyn_cast<llvm::VectorType>(IRType)){
|
|
|
|
llvm::Type *EltTy = VT->getElementType();
|
2011-07-12 06:41:29 +08:00
|
|
|
unsigned BitWidth = VT->getBitWidth();
|
2011-11-29 07:18:11 +08:00
|
|
|
if ((BitWidth >= 128 && BitWidth <= 256) &&
|
2010-07-29 12:56:46 +08:00
|
|
|
(EltTy->isFloatTy() || EltTy->isDoubleTy() ||
|
|
|
|
EltTy->isIntegerTy(8) || EltTy->isIntegerTy(16) ||
|
|
|
|
EltTy->isIntegerTy(32) || EltTy->isIntegerTy(64) ||
|
|
|
|
EltTy->isIntegerTy(128)))
|
|
|
|
return VT;
|
|
|
|
}
|
2010-08-26 02:17:27 +08:00
|
|
|
|
2010-07-29 12:56:46 +08:00
|
|
|
return llvm::VectorType::get(llvm::Type::getDoubleTy(getVMContext()), 2);
|
|
|
|
}
|
|
|
|
|
implement a todo: pass a eight-byte that consists of a
small integer + padding as that small integer. On code
like:
struct c { double x; int y; };
void bar(struct c C) { }
This means that we compile to:
define void @bar(double %C.coerce0, i32 %C.coerce1) nounwind {
entry:
%C = alloca %struct.c, align 8 ; <%struct.c*> [#uses=2]
%0 = getelementptr %struct.c* %C, i32 0, i32 0 ; <double*> [#uses=1]
store double %C.coerce0, double* %0
%1 = getelementptr %struct.c* %C, i32 0, i32 1 ; <i32*> [#uses=1]
store i32 %C.coerce1, i32* %1
instead of:
define void @bar(double %C.coerce0, i64 %C.coerce1) nounwind {
entry:
%C = alloca %struct.c, align 8 ; <%struct.c*> [#uses=3]
%0 = bitcast %struct.c* %C to %0* ; <%0*> [#uses=2]
%1 = getelementptr %0* %0, i32 0, i32 0 ; <double*> [#uses=1]
store double %C.coerce0, double* %1
%2 = getelementptr %0* %0, i32 0, i32 1 ; <i64*> [#uses=1]
store i64 %C.coerce1, i64* %2
which gives SRoA heartburn.
This implements rdar://5711709, a nice low number :)
llvm-svn: 109737
2010-07-29 15:30:00 +08:00
|
|
|
/// BitsContainNoUserData - Return true if the specified [start,end) bit range
|
|
|
|
/// is known to either be off the end of the specified type or being in
|
|
|
|
/// alignment padding. The user type specified is known to be at most 128 bits
|
|
|
|
/// in size, and have passed through X86_64ABIInfo::classify with a successful
|
|
|
|
/// classification that put one of the two halves in the INTEGER class.
|
|
|
|
///
|
|
|
|
/// It is conservatively correct to return false.
|
|
|
|
static bool BitsContainNoUserData(QualType Ty, unsigned StartBit,
|
|
|
|
unsigned EndBit, ASTContext &Context) {
|
|
|
|
// If the bytes being queried are off the end of the type, there is no user
|
|
|
|
// data hiding here. This handles analysis of builtins, vectors and other
|
|
|
|
// types that don't contain interesting padding.
|
|
|
|
unsigned TySize = (unsigned)Context.getTypeSize(Ty);
|
|
|
|
if (TySize <= StartBit)
|
|
|
|
return true;
|
|
|
|
|
This is a little bit far, but optimize cases like:
struct a {
struct c {
double x;
int y;
} x[1];
};
void foo(struct a A) {
}
into:
define void @foo(double %A.coerce0, i32 %A.coerce1) nounwind {
entry:
%A = alloca %struct.a, align 8 ; <%struct.a*> [#uses=1]
%0 = bitcast %struct.a* %A to %struct.c* ; <%struct.c*> [#uses=2]
%1 = getelementptr %struct.c* %0, i32 0, i32 0 ; <double*> [#uses=1]
store double %A.coerce0, double* %1
%2 = getelementptr %struct.c* %0, i32 0, i32 1 ; <i32*> [#uses=1]
store i32 %A.coerce1, i32* %2
instead of:
define void @foo(double %A.coerce0, i64 %A.coerce1) nounwind {
entry:
%A = alloca %struct.a, align 8 ; <%struct.a*> [#uses=1]
%0 = bitcast %struct.a* %A to %0* ; <%0*> [#uses=2]
%1 = getelementptr %0* %0, i32 0, i32 0 ; <double*> [#uses=1]
store double %A.coerce0, double* %1
%2 = getelementptr %0* %0, i32 0, i32 1 ; <i64*> [#uses=1]
store i64 %A.coerce1, i64* %2
I only do this now because I never want to look at this code again :)
llvm-svn: 109738
2010-07-29 15:43:55 +08:00
|
|
|
if (const ConstantArrayType *AT = Context.getAsConstantArrayType(Ty)) {
|
|
|
|
unsigned EltSize = (unsigned)Context.getTypeSize(AT->getElementType());
|
|
|
|
unsigned NumElts = (unsigned)AT->getSize().getZExtValue();
|
|
|
|
|
|
|
|
// Check each element to see if the element overlaps with the queried range.
|
|
|
|
for (unsigned i = 0; i != NumElts; ++i) {
|
|
|
|
// If the element is after the span we care about, then we're done..
|
|
|
|
unsigned EltOffset = i*EltSize;
|
|
|
|
if (EltOffset >= EndBit) break;
|
2010-08-26 02:17:27 +08:00
|
|
|
|
This is a little bit far, but optimize cases like:
struct a {
struct c {
double x;
int y;
} x[1];
};
void foo(struct a A) {
}
into:
define void @foo(double %A.coerce0, i32 %A.coerce1) nounwind {
entry:
%A = alloca %struct.a, align 8 ; <%struct.a*> [#uses=1]
%0 = bitcast %struct.a* %A to %struct.c* ; <%struct.c*> [#uses=2]
%1 = getelementptr %struct.c* %0, i32 0, i32 0 ; <double*> [#uses=1]
store double %A.coerce0, double* %1
%2 = getelementptr %struct.c* %0, i32 0, i32 1 ; <i32*> [#uses=1]
store i32 %A.coerce1, i32* %2
instead of:
define void @foo(double %A.coerce0, i64 %A.coerce1) nounwind {
entry:
%A = alloca %struct.a, align 8 ; <%struct.a*> [#uses=1]
%0 = bitcast %struct.a* %A to %0* ; <%0*> [#uses=2]
%1 = getelementptr %0* %0, i32 0, i32 0 ; <double*> [#uses=1]
store double %A.coerce0, double* %1
%2 = getelementptr %0* %0, i32 0, i32 1 ; <i64*> [#uses=1]
store i64 %A.coerce1, i64* %2
I only do this now because I never want to look at this code again :)
llvm-svn: 109738
2010-07-29 15:43:55 +08:00
|
|
|
unsigned EltStart = EltOffset < StartBit ? StartBit-EltOffset :0;
|
|
|
|
if (!BitsContainNoUserData(AT->getElementType(), EltStart,
|
|
|
|
EndBit-EltOffset, Context))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// If it overlaps no elements, then it is safe to process as padding.
|
|
|
|
return true;
|
|
|
|
}
|
2010-08-26 02:17:27 +08:00
|
|
|
|
implement a todo: pass a eight-byte that consists of a
small integer + padding as that small integer. On code
like:
struct c { double x; int y; };
void bar(struct c C) { }
This means that we compile to:
define void @bar(double %C.coerce0, i32 %C.coerce1) nounwind {
entry:
%C = alloca %struct.c, align 8 ; <%struct.c*> [#uses=2]
%0 = getelementptr %struct.c* %C, i32 0, i32 0 ; <double*> [#uses=1]
store double %C.coerce0, double* %0
%1 = getelementptr %struct.c* %C, i32 0, i32 1 ; <i32*> [#uses=1]
store i32 %C.coerce1, i32* %1
instead of:
define void @bar(double %C.coerce0, i64 %C.coerce1) nounwind {
entry:
%C = alloca %struct.c, align 8 ; <%struct.c*> [#uses=3]
%0 = bitcast %struct.c* %C to %0* ; <%0*> [#uses=2]
%1 = getelementptr %0* %0, i32 0, i32 0 ; <double*> [#uses=1]
store double %C.coerce0, double* %1
%2 = getelementptr %0* %0, i32 0, i32 1 ; <i64*> [#uses=1]
store i64 %C.coerce1, i64* %2
which gives SRoA heartburn.
This implements rdar://5711709, a nice low number :)
llvm-svn: 109737
2010-07-29 15:30:00 +08:00
|
|
|
if (const RecordType *RT = Ty->getAs<RecordType>()) {
|
|
|
|
const RecordDecl *RD = RT->getDecl();
|
|
|
|
const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD);
|
2010-08-26 02:17:27 +08:00
|
|
|
|
implement a todo: pass a eight-byte that consists of a
small integer + padding as that small integer. On code
like:
struct c { double x; int y; };
void bar(struct c C) { }
This means that we compile to:
define void @bar(double %C.coerce0, i32 %C.coerce1) nounwind {
entry:
%C = alloca %struct.c, align 8 ; <%struct.c*> [#uses=2]
%0 = getelementptr %struct.c* %C, i32 0, i32 0 ; <double*> [#uses=1]
store double %C.coerce0, double* %0
%1 = getelementptr %struct.c* %C, i32 0, i32 1 ; <i32*> [#uses=1]
store i32 %C.coerce1, i32* %1
instead of:
define void @bar(double %C.coerce0, i64 %C.coerce1) nounwind {
entry:
%C = alloca %struct.c, align 8 ; <%struct.c*> [#uses=3]
%0 = bitcast %struct.c* %C to %0* ; <%0*> [#uses=2]
%1 = getelementptr %0* %0, i32 0, i32 0 ; <double*> [#uses=1]
store double %C.coerce0, double* %1
%2 = getelementptr %0* %0, i32 0, i32 1 ; <i64*> [#uses=1]
store i64 %C.coerce1, i64* %2
which gives SRoA heartburn.
This implements rdar://5711709, a nice low number :)
llvm-svn: 109737
2010-07-29 15:30:00 +08:00
|
|
|
// If this is a C++ record, check the bases first.
|
|
|
|
if (const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
|
2014-03-13 23:41:46 +08:00
|
|
|
for (const auto &I : CXXRD->bases()) {
|
|
|
|
assert(!I.isVirtual() && !I.getType()->isDependentType() &&
|
implement a todo: pass a eight-byte that consists of a
small integer + padding as that small integer. On code
like:
struct c { double x; int y; };
void bar(struct c C) { }
This means that we compile to:
define void @bar(double %C.coerce0, i32 %C.coerce1) nounwind {
entry:
%C = alloca %struct.c, align 8 ; <%struct.c*> [#uses=2]
%0 = getelementptr %struct.c* %C, i32 0, i32 0 ; <double*> [#uses=1]
store double %C.coerce0, double* %0
%1 = getelementptr %struct.c* %C, i32 0, i32 1 ; <i32*> [#uses=1]
store i32 %C.coerce1, i32* %1
instead of:
define void @bar(double %C.coerce0, i64 %C.coerce1) nounwind {
entry:
%C = alloca %struct.c, align 8 ; <%struct.c*> [#uses=3]
%0 = bitcast %struct.c* %C to %0* ; <%0*> [#uses=2]
%1 = getelementptr %0* %0, i32 0, i32 0 ; <double*> [#uses=1]
store double %C.coerce0, double* %1
%2 = getelementptr %0* %0, i32 0, i32 1 ; <i64*> [#uses=1]
store i64 %C.coerce1, i64* %2
which gives SRoA heartburn.
This implements rdar://5711709, a nice low number :)
llvm-svn: 109737
2010-07-29 15:30:00 +08:00
|
|
|
"Unexpected base class!");
|
|
|
|
const CXXRecordDecl *Base =
|
2014-03-13 23:41:46 +08:00
|
|
|
cast<CXXRecordDecl>(I.getType()->getAs<RecordType>()->getDecl());
|
2010-08-26 02:17:27 +08:00
|
|
|
|
implement a todo: pass a eight-byte that consists of a
small integer + padding as that small integer. On code
like:
struct c { double x; int y; };
void bar(struct c C) { }
This means that we compile to:
define void @bar(double %C.coerce0, i32 %C.coerce1) nounwind {
entry:
%C = alloca %struct.c, align 8 ; <%struct.c*> [#uses=2]
%0 = getelementptr %struct.c* %C, i32 0, i32 0 ; <double*> [#uses=1]
store double %C.coerce0, double* %0
%1 = getelementptr %struct.c* %C, i32 0, i32 1 ; <i32*> [#uses=1]
store i32 %C.coerce1, i32* %1
instead of:
define void @bar(double %C.coerce0, i64 %C.coerce1) nounwind {
entry:
%C = alloca %struct.c, align 8 ; <%struct.c*> [#uses=3]
%0 = bitcast %struct.c* %C to %0* ; <%0*> [#uses=2]
%1 = getelementptr %0* %0, i32 0, i32 0 ; <double*> [#uses=1]
store double %C.coerce0, double* %1
%2 = getelementptr %0* %0, i32 0, i32 1 ; <i64*> [#uses=1]
store i64 %C.coerce1, i64* %2
which gives SRoA heartburn.
This implements rdar://5711709, a nice low number :)
llvm-svn: 109737
2010-07-29 15:30:00 +08:00
|
|
|
// If the base is after the span we care about, ignore it.
|
2012-07-05 02:45:14 +08:00
|
|
|
unsigned BaseOffset = Context.toBits(Layout.getBaseClassOffset(Base));
|
implement a todo: pass a eight-byte that consists of a
small integer + padding as that small integer. On code
like:
struct c { double x; int y; };
void bar(struct c C) { }
This means that we compile to:
define void @bar(double %C.coerce0, i32 %C.coerce1) nounwind {
entry:
%C = alloca %struct.c, align 8 ; <%struct.c*> [#uses=2]
%0 = getelementptr %struct.c* %C, i32 0, i32 0 ; <double*> [#uses=1]
store double %C.coerce0, double* %0
%1 = getelementptr %struct.c* %C, i32 0, i32 1 ; <i32*> [#uses=1]
store i32 %C.coerce1, i32* %1
instead of:
define void @bar(double %C.coerce0, i64 %C.coerce1) nounwind {
entry:
%C = alloca %struct.c, align 8 ; <%struct.c*> [#uses=3]
%0 = bitcast %struct.c* %C to %0* ; <%0*> [#uses=2]
%1 = getelementptr %0* %0, i32 0, i32 0 ; <double*> [#uses=1]
store double %C.coerce0, double* %1
%2 = getelementptr %0* %0, i32 0, i32 1 ; <i64*> [#uses=1]
store i64 %C.coerce1, i64* %2
which gives SRoA heartburn.
This implements rdar://5711709, a nice low number :)
llvm-svn: 109737
2010-07-29 15:30:00 +08:00
|
|
|
if (BaseOffset >= EndBit) continue;
|
2010-08-26 02:17:27 +08:00
|
|
|
|
implement a todo: pass a eight-byte that consists of a
small integer + padding as that small integer. On code
like:
struct c { double x; int y; };
void bar(struct c C) { }
This means that we compile to:
define void @bar(double %C.coerce0, i32 %C.coerce1) nounwind {
entry:
%C = alloca %struct.c, align 8 ; <%struct.c*> [#uses=2]
%0 = getelementptr %struct.c* %C, i32 0, i32 0 ; <double*> [#uses=1]
store double %C.coerce0, double* %0
%1 = getelementptr %struct.c* %C, i32 0, i32 1 ; <i32*> [#uses=1]
store i32 %C.coerce1, i32* %1
instead of:
define void @bar(double %C.coerce0, i64 %C.coerce1) nounwind {
entry:
%C = alloca %struct.c, align 8 ; <%struct.c*> [#uses=3]
%0 = bitcast %struct.c* %C to %0* ; <%0*> [#uses=2]
%1 = getelementptr %0* %0, i32 0, i32 0 ; <double*> [#uses=1]
store double %C.coerce0, double* %1
%2 = getelementptr %0* %0, i32 0, i32 1 ; <i64*> [#uses=1]
store i64 %C.coerce1, i64* %2
which gives SRoA heartburn.
This implements rdar://5711709, a nice low number :)
llvm-svn: 109737
2010-07-29 15:30:00 +08:00
|
|
|
unsigned BaseStart = BaseOffset < StartBit ? StartBit-BaseOffset :0;
|
2014-03-13 23:41:46 +08:00
|
|
|
if (!BitsContainNoUserData(I.getType(), BaseStart,
|
implement a todo: pass a eight-byte that consists of a
small integer + padding as that small integer. On code
like:
struct c { double x; int y; };
void bar(struct c C) { }
This means that we compile to:
define void @bar(double %C.coerce0, i32 %C.coerce1) nounwind {
entry:
%C = alloca %struct.c, align 8 ; <%struct.c*> [#uses=2]
%0 = getelementptr %struct.c* %C, i32 0, i32 0 ; <double*> [#uses=1]
store double %C.coerce0, double* %0
%1 = getelementptr %struct.c* %C, i32 0, i32 1 ; <i32*> [#uses=1]
store i32 %C.coerce1, i32* %1
instead of:
define void @bar(double %C.coerce0, i64 %C.coerce1) nounwind {
entry:
%C = alloca %struct.c, align 8 ; <%struct.c*> [#uses=3]
%0 = bitcast %struct.c* %C to %0* ; <%0*> [#uses=2]
%1 = getelementptr %0* %0, i32 0, i32 0 ; <double*> [#uses=1]
store double %C.coerce0, double* %1
%2 = getelementptr %0* %0, i32 0, i32 1 ; <i64*> [#uses=1]
store i64 %C.coerce1, i64* %2
which gives SRoA heartburn.
This implements rdar://5711709, a nice low number :)
llvm-svn: 109737
2010-07-29 15:30:00 +08:00
|
|
|
EndBit-BaseOffset, Context))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2010-08-26 02:17:27 +08:00
|
|
|
|
implement a todo: pass a eight-byte that consists of a
small integer + padding as that small integer. On code
like:
struct c { double x; int y; };
void bar(struct c C) { }
This means that we compile to:
define void @bar(double %C.coerce0, i32 %C.coerce1) nounwind {
entry:
%C = alloca %struct.c, align 8 ; <%struct.c*> [#uses=2]
%0 = getelementptr %struct.c* %C, i32 0, i32 0 ; <double*> [#uses=1]
store double %C.coerce0, double* %0
%1 = getelementptr %struct.c* %C, i32 0, i32 1 ; <i32*> [#uses=1]
store i32 %C.coerce1, i32* %1
instead of:
define void @bar(double %C.coerce0, i64 %C.coerce1) nounwind {
entry:
%C = alloca %struct.c, align 8 ; <%struct.c*> [#uses=3]
%0 = bitcast %struct.c* %C to %0* ; <%0*> [#uses=2]
%1 = getelementptr %0* %0, i32 0, i32 0 ; <double*> [#uses=1]
store double %C.coerce0, double* %1
%2 = getelementptr %0* %0, i32 0, i32 1 ; <i64*> [#uses=1]
store i64 %C.coerce1, i64* %2
which gives SRoA heartburn.
This implements rdar://5711709, a nice low number :)
llvm-svn: 109737
2010-07-29 15:30:00 +08:00
|
|
|
// Verify that no field has data that overlaps the region of interest. Yes
|
|
|
|
// this could be sped up a lot by being smarter about queried fields,
|
|
|
|
// however we're only looking at structs up to 16 bytes, so we don't care
|
|
|
|
// much.
|
|
|
|
unsigned idx = 0;
|
|
|
|
for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end();
|
|
|
|
i != e; ++i, ++idx) {
|
|
|
|
unsigned FieldOffset = (unsigned)Layout.getFieldOffset(idx);
|
2010-08-26 02:17:27 +08:00
|
|
|
|
implement a todo: pass a eight-byte that consists of a
small integer + padding as that small integer. On code
like:
struct c { double x; int y; };
void bar(struct c C) { }
This means that we compile to:
define void @bar(double %C.coerce0, i32 %C.coerce1) nounwind {
entry:
%C = alloca %struct.c, align 8 ; <%struct.c*> [#uses=2]
%0 = getelementptr %struct.c* %C, i32 0, i32 0 ; <double*> [#uses=1]
store double %C.coerce0, double* %0
%1 = getelementptr %struct.c* %C, i32 0, i32 1 ; <i32*> [#uses=1]
store i32 %C.coerce1, i32* %1
instead of:
define void @bar(double %C.coerce0, i64 %C.coerce1) nounwind {
entry:
%C = alloca %struct.c, align 8 ; <%struct.c*> [#uses=3]
%0 = bitcast %struct.c* %C to %0* ; <%0*> [#uses=2]
%1 = getelementptr %0* %0, i32 0, i32 0 ; <double*> [#uses=1]
store double %C.coerce0, double* %1
%2 = getelementptr %0* %0, i32 0, i32 1 ; <i64*> [#uses=1]
store i64 %C.coerce1, i64* %2
which gives SRoA heartburn.
This implements rdar://5711709, a nice low number :)
llvm-svn: 109737
2010-07-29 15:30:00 +08:00
|
|
|
// If we found a field after the region we care about, then we're done.
|
|
|
|
if (FieldOffset >= EndBit) break;
|
|
|
|
|
|
|
|
unsigned FieldStart = FieldOffset < StartBit ? StartBit-FieldOffset :0;
|
|
|
|
if (!BitsContainNoUserData(i->getType(), FieldStart, EndBit-FieldOffset,
|
|
|
|
Context))
|
|
|
|
return false;
|
|
|
|
}
|
2010-08-26 02:17:27 +08:00
|
|
|
|
implement a todo: pass a eight-byte that consists of a
small integer + padding as that small integer. On code
like:
struct c { double x; int y; };
void bar(struct c C) { }
This means that we compile to:
define void @bar(double %C.coerce0, i32 %C.coerce1) nounwind {
entry:
%C = alloca %struct.c, align 8 ; <%struct.c*> [#uses=2]
%0 = getelementptr %struct.c* %C, i32 0, i32 0 ; <double*> [#uses=1]
store double %C.coerce0, double* %0
%1 = getelementptr %struct.c* %C, i32 0, i32 1 ; <i32*> [#uses=1]
store i32 %C.coerce1, i32* %1
instead of:
define void @bar(double %C.coerce0, i64 %C.coerce1) nounwind {
entry:
%C = alloca %struct.c, align 8 ; <%struct.c*> [#uses=3]
%0 = bitcast %struct.c* %C to %0* ; <%0*> [#uses=2]
%1 = getelementptr %0* %0, i32 0, i32 0 ; <double*> [#uses=1]
store double %C.coerce0, double* %1
%2 = getelementptr %0* %0, i32 0, i32 1 ; <i64*> [#uses=1]
store i64 %C.coerce1, i64* %2
which gives SRoA heartburn.
This implements rdar://5711709, a nice low number :)
llvm-svn: 109737
2010-07-29 15:30:00 +08:00
|
|
|
// If nothing in this record overlapped the area of interest, then we're
|
|
|
|
// clean.
|
|
|
|
return true;
|
|
|
|
}
|
2010-08-26 02:17:27 +08:00
|
|
|
|
implement a todo: pass a eight-byte that consists of a
small integer + padding as that small integer. On code
like:
struct c { double x; int y; };
void bar(struct c C) { }
This means that we compile to:
define void @bar(double %C.coerce0, i32 %C.coerce1) nounwind {
entry:
%C = alloca %struct.c, align 8 ; <%struct.c*> [#uses=2]
%0 = getelementptr %struct.c* %C, i32 0, i32 0 ; <double*> [#uses=1]
store double %C.coerce0, double* %0
%1 = getelementptr %struct.c* %C, i32 0, i32 1 ; <i32*> [#uses=1]
store i32 %C.coerce1, i32* %1
instead of:
define void @bar(double %C.coerce0, i64 %C.coerce1) nounwind {
entry:
%C = alloca %struct.c, align 8 ; <%struct.c*> [#uses=3]
%0 = bitcast %struct.c* %C to %0* ; <%0*> [#uses=2]
%1 = getelementptr %0* %0, i32 0, i32 0 ; <double*> [#uses=1]
store double %C.coerce0, double* %1
%2 = getelementptr %0* %0, i32 0, i32 1 ; <i64*> [#uses=1]
store i64 %C.coerce1, i64* %2
which gives SRoA heartburn.
This implements rdar://5711709, a nice low number :)
llvm-svn: 109737
2010-07-29 15:30:00 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-07-30 02:39:32 +08:00
|
|
|
/// ContainsFloatAtOffset - Return true if the specified LLVM IR type has a
|
|
|
|
/// float member at the specified offset. For example, {int,{float}} has a
|
|
|
|
/// float at offset 4. It is conservatively correct for this routine to return
|
|
|
|
/// false.
|
2011-07-18 12:24:23 +08:00
|
|
|
static bool ContainsFloatAtOffset(llvm::Type *IRType, unsigned IROffset,
|
2012-10-09 00:25:52 +08:00
|
|
|
const llvm::DataLayout &TD) {
|
2010-07-30 02:39:32 +08:00
|
|
|
// Base case if we find a float.
|
|
|
|
if (IROffset == 0 && IRType->isFloatTy())
|
|
|
|
return true;
|
2010-08-26 02:17:27 +08:00
|
|
|
|
2010-07-30 02:39:32 +08:00
|
|
|
// If this is a struct, recurse into the field at the specified offset.
|
2011-07-18 12:24:23 +08:00
|
|
|
if (llvm::StructType *STy = dyn_cast<llvm::StructType>(IRType)) {
|
2010-07-30 02:39:32 +08:00
|
|
|
const llvm::StructLayout *SL = TD.getStructLayout(STy);
|
|
|
|
unsigned Elt = SL->getElementContainingOffset(IROffset);
|
|
|
|
IROffset -= SL->getElementOffset(Elt);
|
|
|
|
return ContainsFloatAtOffset(STy->getElementType(Elt), IROffset, TD);
|
|
|
|
}
|
2010-08-26 02:17:27 +08:00
|
|
|
|
2010-07-30 02:39:32 +08:00
|
|
|
// If this is an array, recurse into the field at the specified offset.
|
2011-07-18 12:24:23 +08:00
|
|
|
if (llvm::ArrayType *ATy = dyn_cast<llvm::ArrayType>(IRType)) {
|
|
|
|
llvm::Type *EltTy = ATy->getElementType();
|
2010-07-30 02:39:32 +08:00
|
|
|
unsigned EltSize = TD.getTypeAllocSize(EltTy);
|
|
|
|
IROffset -= IROffset/EltSize*EltSize;
|
|
|
|
return ContainsFloatAtOffset(EltTy, IROffset, TD);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
fix rdar://8251384, another case where we could access beyond the
end of a struct. This improves the case when the struct being passed
contains 3 floats, either due to a struct or array of 3 things. Before
we'd generate this IR for the testcase:
define float @bar(double %X.coerce0, double %X.coerce1) nounwind {
entry:
%X = alloca %struct.foof, align 8 ; <%struct.foof*> [#uses=2]
%0 = bitcast %struct.foof* %X to %1* ; <%1*> [#uses=2]
%1 = getelementptr %1* %0, i32 0, i32 0 ; <double*> [#uses=1]
store double %X.coerce0, double* %1
%2 = getelementptr %1* %0, i32 0, i32 1 ; <double*> [#uses=1]
store double %X.coerce1, double* %2
%tmp = getelementptr inbounds %struct.foof* %X, i32 0, i32 2 ; <float*> [#uses=1]
%tmp1 = load float* %tmp ; <float> [#uses=1]
ret float %tmp1
}
which compiled (with optimization) to:
_bar: ## @bar
## BB#0: ## %entry
movd %xmm1, %rax
movd %eax, %xmm0
ret
Now we produce:
define float @bar(double %X.coerce0, float %X.coerce1) nounwind {
entry:
%X = alloca %struct.foof, align 8 ; <%struct.foof*> [#uses=2]
%0 = bitcast %struct.foof* %X to %0* ; <%0*> [#uses=2]
%1 = getelementptr %0* %0, i32 0, i32 0 ; <double*> [#uses=1]
store double %X.coerce0, double* %1
%2 = getelementptr %0* %0, i32 0, i32 1 ; <float*> [#uses=1]
store float %X.coerce1, float* %2
%tmp = getelementptr inbounds %struct.foof* %X, i32 0, i32 2 ; <float*> [#uses=1]
%tmp1 = load float* %tmp ; <float> [#uses=1]
ret float %tmp1
}
and:
_bar: ## @bar
## BB#0: ## %entry
movaps %xmm1, %xmm0
ret
llvm-svn: 109776
2010-07-30 02:13:09 +08:00
|
|
|
|
|
|
|
/// GetSSETypeAtOffset - Return a type that will be passed by the backend in the
|
|
|
|
/// low 8 bytes of an XMM register, corresponding to the SSE class.
|
2011-07-10 01:41:47 +08:00
|
|
|
llvm::Type *X86_64ABIInfo::
|
|
|
|
GetSSETypeAtOffset(llvm::Type *IRType, unsigned IROffset,
|
fix rdar://8251384, another case where we could access beyond the
end of a struct. This improves the case when the struct being passed
contains 3 floats, either due to a struct or array of 3 things. Before
we'd generate this IR for the testcase:
define float @bar(double %X.coerce0, double %X.coerce1) nounwind {
entry:
%X = alloca %struct.foof, align 8 ; <%struct.foof*> [#uses=2]
%0 = bitcast %struct.foof* %X to %1* ; <%1*> [#uses=2]
%1 = getelementptr %1* %0, i32 0, i32 0 ; <double*> [#uses=1]
store double %X.coerce0, double* %1
%2 = getelementptr %1* %0, i32 0, i32 1 ; <double*> [#uses=1]
store double %X.coerce1, double* %2
%tmp = getelementptr inbounds %struct.foof* %X, i32 0, i32 2 ; <float*> [#uses=1]
%tmp1 = load float* %tmp ; <float> [#uses=1]
ret float %tmp1
}
which compiled (with optimization) to:
_bar: ## @bar
## BB#0: ## %entry
movd %xmm1, %rax
movd %eax, %xmm0
ret
Now we produce:
define float @bar(double %X.coerce0, float %X.coerce1) nounwind {
entry:
%X = alloca %struct.foof, align 8 ; <%struct.foof*> [#uses=2]
%0 = bitcast %struct.foof* %X to %0* ; <%0*> [#uses=2]
%1 = getelementptr %0* %0, i32 0, i32 0 ; <double*> [#uses=1]
store double %X.coerce0, double* %1
%2 = getelementptr %0* %0, i32 0, i32 1 ; <float*> [#uses=1]
store float %X.coerce1, float* %2
%tmp = getelementptr inbounds %struct.foof* %X, i32 0, i32 2 ; <float*> [#uses=1]
%tmp1 = load float* %tmp ; <float> [#uses=1]
ret float %tmp1
}
and:
_bar: ## @bar
## BB#0: ## %entry
movaps %xmm1, %xmm0
ret
llvm-svn: 109776
2010-07-30 02:13:09 +08:00
|
|
|
QualType SourceTy, unsigned SourceOffset) const {
|
2010-07-30 02:19:50 +08:00
|
|
|
// The only three choices we have are either double, <2 x float>, or float. We
|
fix rdar://8251384, another case where we could access beyond the
end of a struct. This improves the case when the struct being passed
contains 3 floats, either due to a struct or array of 3 things. Before
we'd generate this IR for the testcase:
define float @bar(double %X.coerce0, double %X.coerce1) nounwind {
entry:
%X = alloca %struct.foof, align 8 ; <%struct.foof*> [#uses=2]
%0 = bitcast %struct.foof* %X to %1* ; <%1*> [#uses=2]
%1 = getelementptr %1* %0, i32 0, i32 0 ; <double*> [#uses=1]
store double %X.coerce0, double* %1
%2 = getelementptr %1* %0, i32 0, i32 1 ; <double*> [#uses=1]
store double %X.coerce1, double* %2
%tmp = getelementptr inbounds %struct.foof* %X, i32 0, i32 2 ; <float*> [#uses=1]
%tmp1 = load float* %tmp ; <float> [#uses=1]
ret float %tmp1
}
which compiled (with optimization) to:
_bar: ## @bar
## BB#0: ## %entry
movd %xmm1, %rax
movd %eax, %xmm0
ret
Now we produce:
define float @bar(double %X.coerce0, float %X.coerce1) nounwind {
entry:
%X = alloca %struct.foof, align 8 ; <%struct.foof*> [#uses=2]
%0 = bitcast %struct.foof* %X to %0* ; <%0*> [#uses=2]
%1 = getelementptr %0* %0, i32 0, i32 0 ; <double*> [#uses=1]
store double %X.coerce0, double* %1
%2 = getelementptr %0* %0, i32 0, i32 1 ; <float*> [#uses=1]
store float %X.coerce1, float* %2
%tmp = getelementptr inbounds %struct.foof* %X, i32 0, i32 2 ; <float*> [#uses=1]
%tmp1 = load float* %tmp ; <float> [#uses=1]
ret float %tmp1
}
and:
_bar: ## @bar
## BB#0: ## %entry
movaps %xmm1, %xmm0
ret
llvm-svn: 109776
2010-07-30 02:13:09 +08:00
|
|
|
// pass as float if the last 4 bytes is just padding. This happens for
|
|
|
|
// structs that contain 3 floats.
|
|
|
|
if (BitsContainNoUserData(SourceTy, SourceOffset*8+32,
|
|
|
|
SourceOffset*8+64, getContext()))
|
|
|
|
return llvm::Type::getFloatTy(getVMContext());
|
2010-08-26 02:17:27 +08:00
|
|
|
|
2010-07-30 02:39:32 +08:00
|
|
|
// We want to pass as <2 x float> if the LLVM IR type contains a float at
|
|
|
|
// offset+0 and offset+4. Walk the LLVM IR type to find out if this is the
|
|
|
|
// case.
|
2012-10-09 00:25:52 +08:00
|
|
|
if (ContainsFloatAtOffset(IRType, IROffset, getDataLayout()) &&
|
|
|
|
ContainsFloatAtOffset(IRType, IROffset+4, getDataLayout()))
|
Finally pass "two floats in a 64-bit unit" as a <2 x float> instead of
as a double in the x86-64 ABI. This allows us to generate much better
code for certain things, e.g.:
_Complex float f32(_Complex float A, _Complex float B) {
return A+B;
}
Used to compile into (look at the integer silliness!):
_f32: ## @f32
## BB#0: ## %entry
movd %xmm1, %rax
movd %eax, %xmm1
movd %xmm0, %rcx
movd %ecx, %xmm0
addss %xmm1, %xmm0
movd %xmm0, %edx
shrq $32, %rax
movd %eax, %xmm0
shrq $32, %rcx
movd %ecx, %xmm1
addss %xmm0, %xmm1
movd %xmm1, %eax
shlq $32, %rax
addq %rdx, %rax
movd %rax, %xmm0
ret
Now we get:
_f32: ## @f32
movdqa %xmm0, %xmm2
addss %xmm1, %xmm2
pshufd $16, %xmm2, %xmm2
pshufd $1, %xmm1, %xmm1
pshufd $1, %xmm0, %xmm0
addss %xmm1, %xmm0
pshufd $16, %xmm0, %xmm1
movdqa %xmm2, %xmm0
unpcklps %xmm1, %xmm0
ret
and compile stuff like:
extern float _Complex ccoshf( float _Complex ) ;
float _Complex ccosf ( float _Complex z ) {
float _Complex iz;
(__real__ iz) = -(__imag__ z);
(__imag__ iz) = (__real__ z);
return ccoshf(iz);
}
into:
_ccosf: ## @ccosf
## BB#0: ## %entry
pshufd $1, %xmm0, %xmm1
xorps LCPI4_0(%rip), %xmm1
unpcklps %xmm0, %xmm1
movaps %xmm1, %xmm0
jmp _ccoshf ## TAILCALL
instead of:
_ccosf: ## @ccosf
## BB#0: ## %entry
movd %xmm0, %rax
movq %rax, %rcx
shlq $32, %rcx
shrq $32, %rax
xorl $-2147483648, %eax ## imm = 0xFFFFFFFF80000000
addq %rcx, %rax
movd %rax, %xmm0
jmp _ccoshf ## TAILCALL
There is still "stuff to be done" here for the struct case,
but this resolves rdar://6379669 - [x86-64 ABI] Pass and return
_Complex float / double efficiently
llvm-svn: 112111
2010-08-26 07:39:14 +08:00
|
|
|
return llvm::VectorType::get(llvm::Type::getFloatTy(getVMContext()), 2);
|
2010-08-26 02:17:27 +08:00
|
|
|
|
fix rdar://8251384, another case where we could access beyond the
end of a struct. This improves the case when the struct being passed
contains 3 floats, either due to a struct or array of 3 things. Before
we'd generate this IR for the testcase:
define float @bar(double %X.coerce0, double %X.coerce1) nounwind {
entry:
%X = alloca %struct.foof, align 8 ; <%struct.foof*> [#uses=2]
%0 = bitcast %struct.foof* %X to %1* ; <%1*> [#uses=2]
%1 = getelementptr %1* %0, i32 0, i32 0 ; <double*> [#uses=1]
store double %X.coerce0, double* %1
%2 = getelementptr %1* %0, i32 0, i32 1 ; <double*> [#uses=1]
store double %X.coerce1, double* %2
%tmp = getelementptr inbounds %struct.foof* %X, i32 0, i32 2 ; <float*> [#uses=1]
%tmp1 = load float* %tmp ; <float> [#uses=1]
ret float %tmp1
}
which compiled (with optimization) to:
_bar: ## @bar
## BB#0: ## %entry
movd %xmm1, %rax
movd %eax, %xmm0
ret
Now we produce:
define float @bar(double %X.coerce0, float %X.coerce1) nounwind {
entry:
%X = alloca %struct.foof, align 8 ; <%struct.foof*> [#uses=2]
%0 = bitcast %struct.foof* %X to %0* ; <%0*> [#uses=2]
%1 = getelementptr %0* %0, i32 0, i32 0 ; <double*> [#uses=1]
store double %X.coerce0, double* %1
%2 = getelementptr %0* %0, i32 0, i32 1 ; <float*> [#uses=1]
store float %X.coerce1, float* %2
%tmp = getelementptr inbounds %struct.foof* %X, i32 0, i32 2 ; <float*> [#uses=1]
%tmp1 = load float* %tmp ; <float> [#uses=1]
ret float %tmp1
}
and:
_bar: ## @bar
## BB#0: ## %entry
movaps %xmm1, %xmm0
ret
llvm-svn: 109776
2010-07-30 02:13:09 +08:00
|
|
|
return llvm::Type::getDoubleTy(getVMContext());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-30 01:40:35 +08:00
|
|
|
/// GetINTEGERTypeAtOffset - 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
|
2010-07-29 07:06:14 +08:00
|
|
|
/// 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.
|
|
|
|
///
|
2014-07-09 22:06:35 +08:00
|
|
|
/// SourceTy is the source-level type for the entire argument. SourceOffset is
|
2010-07-29 07:06:14 +08:00
|
|
|
/// an offset into this that we're processing (which is always either 0 or 8).
|
|
|
|
///
|
2011-07-10 01:41:47 +08:00
|
|
|
llvm::Type *X86_64ABIInfo::
|
|
|
|
GetINTEGERTypeAtOffset(llvm::Type *IRType, unsigned IROffset,
|
2010-07-30 01:40:35 +08:00
|
|
|
QualType SourceTy, unsigned SourceOffset) const {
|
implement a todo: pass a eight-byte that consists of a
small integer + padding as that small integer. On code
like:
struct c { double x; int y; };
void bar(struct c C) { }
This means that we compile to:
define void @bar(double %C.coerce0, i32 %C.coerce1) nounwind {
entry:
%C = alloca %struct.c, align 8 ; <%struct.c*> [#uses=2]
%0 = getelementptr %struct.c* %C, i32 0, i32 0 ; <double*> [#uses=1]
store double %C.coerce0, double* %0
%1 = getelementptr %struct.c* %C, i32 0, i32 1 ; <i32*> [#uses=1]
store i32 %C.coerce1, i32* %1
instead of:
define void @bar(double %C.coerce0, i64 %C.coerce1) nounwind {
entry:
%C = alloca %struct.c, align 8 ; <%struct.c*> [#uses=3]
%0 = bitcast %struct.c* %C to %0* ; <%0*> [#uses=2]
%1 = getelementptr %0* %0, i32 0, i32 0 ; <double*> [#uses=1]
store double %C.coerce0, double* %1
%2 = getelementptr %0* %0, i32 0, i32 1 ; <i64*> [#uses=1]
store i64 %C.coerce1, i64* %2
which gives SRoA heartburn.
This implements rdar://5711709, a nice low number :)
llvm-svn: 109737
2010-07-29 15:30:00 +08:00
|
|
|
// If we're dealing with an un-offset LLVM IR type, then it means that we're
|
|
|
|
// returning an 8-byte unit starting with it. See if we can safely use it.
|
|
|
|
if (IROffset == 0) {
|
|
|
|
// Pointers and int64's always fill the 8-byte unit.
|
2012-10-11 23:52:22 +08:00
|
|
|
if ((isa<llvm::PointerType>(IRType) && Has64BitPointers) ||
|
|
|
|
IRType->isIntegerTy(64))
|
implement a todo: pass a eight-byte that consists of a
small integer + padding as that small integer. On code
like:
struct c { double x; int y; };
void bar(struct c C) { }
This means that we compile to:
define void @bar(double %C.coerce0, i32 %C.coerce1) nounwind {
entry:
%C = alloca %struct.c, align 8 ; <%struct.c*> [#uses=2]
%0 = getelementptr %struct.c* %C, i32 0, i32 0 ; <double*> [#uses=1]
store double %C.coerce0, double* %0
%1 = getelementptr %struct.c* %C, i32 0, i32 1 ; <i32*> [#uses=1]
store i32 %C.coerce1, i32* %1
instead of:
define void @bar(double %C.coerce0, i64 %C.coerce1) nounwind {
entry:
%C = alloca %struct.c, align 8 ; <%struct.c*> [#uses=3]
%0 = bitcast %struct.c* %C to %0* ; <%0*> [#uses=2]
%1 = getelementptr %0* %0, i32 0, i32 0 ; <double*> [#uses=1]
store double %C.coerce0, double* %1
%2 = getelementptr %0* %0, i32 0, i32 1 ; <i64*> [#uses=1]
store i64 %C.coerce1, i64* %2
which gives SRoA heartburn.
This implements rdar://5711709, a nice low number :)
llvm-svn: 109737
2010-07-29 15:30:00 +08:00
|
|
|
return IRType;
|
|
|
|
|
|
|
|
// If we have a 1/2/4-byte integer, we can use it only if the rest of the
|
|
|
|
// goodness in the source type is just tail padding. This is allowed to
|
|
|
|
// kick in for struct {double,int} on the int, but not on
|
|
|
|
// struct{double,int,int} because we wouldn't return the second int. We
|
|
|
|
// have to do this analysis on the source type because we can't depend on
|
|
|
|
// unions being lowered a specific way etc.
|
|
|
|
if (IRType->isIntegerTy(8) || IRType->isIntegerTy(16) ||
|
2012-10-11 23:52:22 +08:00
|
|
|
IRType->isIntegerTy(32) ||
|
|
|
|
(isa<llvm::PointerType>(IRType) && !Has64BitPointers)) {
|
|
|
|
unsigned BitWidth = isa<llvm::PointerType>(IRType) ? 32 :
|
|
|
|
cast<llvm::IntegerType>(IRType)->getBitWidth();
|
2010-08-26 02:17:27 +08:00
|
|
|
|
implement a todo: pass a eight-byte that consists of a
small integer + padding as that small integer. On code
like:
struct c { double x; int y; };
void bar(struct c C) { }
This means that we compile to:
define void @bar(double %C.coerce0, i32 %C.coerce1) nounwind {
entry:
%C = alloca %struct.c, align 8 ; <%struct.c*> [#uses=2]
%0 = getelementptr %struct.c* %C, i32 0, i32 0 ; <double*> [#uses=1]
store double %C.coerce0, double* %0
%1 = getelementptr %struct.c* %C, i32 0, i32 1 ; <i32*> [#uses=1]
store i32 %C.coerce1, i32* %1
instead of:
define void @bar(double %C.coerce0, i64 %C.coerce1) nounwind {
entry:
%C = alloca %struct.c, align 8 ; <%struct.c*> [#uses=3]
%0 = bitcast %struct.c* %C to %0* ; <%0*> [#uses=2]
%1 = getelementptr %0* %0, i32 0, i32 0 ; <double*> [#uses=1]
store double %C.coerce0, double* %1
%2 = getelementptr %0* %0, i32 0, i32 1 ; <i64*> [#uses=1]
store i64 %C.coerce1, i64* %2
which gives SRoA heartburn.
This implements rdar://5711709, a nice low number :)
llvm-svn: 109737
2010-07-29 15:30:00 +08:00
|
|
|
if (BitsContainNoUserData(SourceTy, SourceOffset*8+BitWidth,
|
|
|
|
SourceOffset*8+64, getContext()))
|
|
|
|
return IRType;
|
|
|
|
}
|
|
|
|
}
|
2010-07-29 07:06:14 +08:00
|
|
|
|
2011-07-18 12:24:23 +08:00
|
|
|
if (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.
|
2012-10-09 00:25:52 +08:00
|
|
|
const llvm::StructLayout *SL = getDataLayout().getStructLayout(STy);
|
2010-07-29 07:06:14 +08:00
|
|
|
if (IROffset < SL->getSizeInBytes()) {
|
|
|
|
unsigned FieldIdx = SL->getElementContainingOffset(IROffset);
|
|
|
|
IROffset -= SL->getElementOffset(FieldIdx);
|
2010-08-26 02:17:27 +08:00
|
|
|
|
2010-07-30 01:40:35 +08:00
|
|
|
return GetINTEGERTypeAtOffset(STy->getElementType(FieldIdx), IROffset,
|
|
|
|
SourceTy, SourceOffset);
|
2010-08-26 02:17:27 +08:00
|
|
|
}
|
2010-07-29 07:06:14 +08:00
|
|
|
}
|
2010-08-26 02:17:27 +08:00
|
|
|
|
2011-07-18 12:24:23 +08:00
|
|
|
if (llvm::ArrayType *ATy = dyn_cast<llvm::ArrayType>(IRType)) {
|
2011-07-10 01:41:47 +08:00
|
|
|
llvm::Type *EltTy = ATy->getElementType();
|
2012-10-09 00:25:52 +08:00
|
|
|
unsigned EltSize = getDataLayout().getTypeAllocSize(EltTy);
|
This is a little bit far, but optimize cases like:
struct a {
struct c {
double x;
int y;
} x[1];
};
void foo(struct a A) {
}
into:
define void @foo(double %A.coerce0, i32 %A.coerce1) nounwind {
entry:
%A = alloca %struct.a, align 8 ; <%struct.a*> [#uses=1]
%0 = bitcast %struct.a* %A to %struct.c* ; <%struct.c*> [#uses=2]
%1 = getelementptr %struct.c* %0, i32 0, i32 0 ; <double*> [#uses=1]
store double %A.coerce0, double* %1
%2 = getelementptr %struct.c* %0, i32 0, i32 1 ; <i32*> [#uses=1]
store i32 %A.coerce1, i32* %2
instead of:
define void @foo(double %A.coerce0, i64 %A.coerce1) nounwind {
entry:
%A = alloca %struct.a, align 8 ; <%struct.a*> [#uses=1]
%0 = bitcast %struct.a* %A to %0* ; <%0*> [#uses=2]
%1 = getelementptr %0* %0, i32 0, i32 0 ; <double*> [#uses=1]
store double %A.coerce0, double* %1
%2 = getelementptr %0* %0, i32 0, i32 1 ; <i64*> [#uses=1]
store i64 %A.coerce1, i64* %2
I only do this now because I never want to look at this code again :)
llvm-svn: 109738
2010-07-29 15:43:55 +08:00
|
|
|
unsigned EltOffset = IROffset/EltSize*EltSize;
|
2010-07-30 01:40:35 +08:00
|
|
|
return GetINTEGERTypeAtOffset(EltTy, IROffset-EltOffset, SourceTy,
|
|
|
|
SourceOffset);
|
This is a little bit far, but optimize cases like:
struct a {
struct c {
double x;
int y;
} x[1];
};
void foo(struct a A) {
}
into:
define void @foo(double %A.coerce0, i32 %A.coerce1) nounwind {
entry:
%A = alloca %struct.a, align 8 ; <%struct.a*> [#uses=1]
%0 = bitcast %struct.a* %A to %struct.c* ; <%struct.c*> [#uses=2]
%1 = getelementptr %struct.c* %0, i32 0, i32 0 ; <double*> [#uses=1]
store double %A.coerce0, double* %1
%2 = getelementptr %struct.c* %0, i32 0, i32 1 ; <i32*> [#uses=1]
store i32 %A.coerce1, i32* %2
instead of:
define void @foo(double %A.coerce0, i64 %A.coerce1) nounwind {
entry:
%A = alloca %struct.a, align 8 ; <%struct.a*> [#uses=1]
%0 = bitcast %struct.a* %A to %0* ; <%0*> [#uses=2]
%1 = getelementptr %0* %0, i32 0, i32 0 ; <double*> [#uses=1]
store double %A.coerce0, double* %1
%2 = getelementptr %0* %0, i32 0, i32 1 ; <i64*> [#uses=1]
store i64 %A.coerce1, i64* %2
I only do this now because I never want to look at this code again :)
llvm-svn: 109738
2010-07-29 15:43:55 +08:00
|
|
|
}
|
2010-08-26 02:17:27 +08:00
|
|
|
|
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-30 01:34:39 +08:00
|
|
|
unsigned TySizeInBytes =
|
|
|
|
(unsigned)getContext().getTypeSizeInChars(SourceTy).getQuantity();
|
2010-07-29 07:06:14 +08:00
|
|
|
|
2010-07-30 01:34:39 +08:00
|
|
|
assert(TySizeInBytes != SourceOffset && "Empty field?");
|
2010-08-26 02:17:27 +08:00
|
|
|
|
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.
|
2010-07-30 01:34:39 +08:00
|
|
|
return llvm::IntegerType::get(getVMContext(),
|
|
|
|
std::min(TySizeInBytes-SourceOffset, 8U)*8);
|
2010-07-29 07:06:14 +08:00
|
|
|
}
|
|
|
|
|
2010-09-01 08:50:20 +08:00
|
|
|
|
|
|
|
/// GetX86_64ByValArgumentPair - Given a high and low type that can ideally
|
|
|
|
/// be used as elements of a two register pair to pass or return, return a
|
|
|
|
/// first class aggregate to represent them. For example, if the low part of
|
|
|
|
/// a by-value argument should be passed as i32* and the high part as float,
|
|
|
|
/// return {i32*, float}.
|
2011-07-10 01:41:47 +08:00
|
|
|
static llvm::Type *
|
2011-07-11 17:56:20 +08:00
|
|
|
GetX86_64ByValArgumentPair(llvm::Type *Lo, llvm::Type *Hi,
|
2012-10-09 00:25:52 +08:00
|
|
|
const llvm::DataLayout &TD) {
|
2010-09-01 08:50:20 +08:00
|
|
|
// In order to correctly satisfy the ABI, we need to the high part to start
|
|
|
|
// at offset 8. If the high and low parts we inferred are both 4-byte types
|
|
|
|
// (e.g. i32 and i32) then the resultant struct type ({i32,i32}) won't have
|
|
|
|
// the second element at offset 8. Check for this:
|
|
|
|
unsigned LoSize = (unsigned)TD.getTypeAllocSize(Lo);
|
|
|
|
unsigned HiAlign = TD.getABITypeAlignment(Hi);
|
2014-10-20 14:13:36 +08:00
|
|
|
unsigned HiStart = llvm::RoundUpToAlignment(LoSize, HiAlign);
|
2010-09-01 08:50:20 +08:00
|
|
|
assert(HiStart != 0 && HiStart <= 8 && "Invalid x86-64 argument pair!");
|
2010-10-19 14:39:39 +08:00
|
|
|
|
2010-09-01 08:50:20 +08:00
|
|
|
// To handle this, we have to increase the size of the low part so that the
|
|
|
|
// second element will start at an 8 byte offset. We can't increase the size
|
|
|
|
// of the second element because it might make us access off the end of the
|
|
|
|
// struct.
|
|
|
|
if (HiStart != 8) {
|
|
|
|
// There are only two sorts of types the ABI generation code can produce for
|
|
|
|
// the low part of a pair that aren't 8 bytes in size: float or i8/i16/i32.
|
|
|
|
// Promote these to a larger type.
|
|
|
|
if (Lo->isFloatTy())
|
|
|
|
Lo = llvm::Type::getDoubleTy(Lo->getContext());
|
|
|
|
else {
|
|
|
|
assert(Lo->isIntegerTy() && "Invalid/unknown lo type");
|
|
|
|
Lo = llvm::Type::getInt64Ty(Lo->getContext());
|
|
|
|
}
|
|
|
|
}
|
2010-10-19 14:39:39 +08:00
|
|
|
|
2014-12-02 06:02:27 +08:00
|
|
|
llvm::StructType *Result = llvm::StructType::get(Lo, Hi, nullptr);
|
2010-10-19 14:39:39 +08:00
|
|
|
|
|
|
|
|
2010-09-01 08:50:20 +08:00
|
|
|
// Verify that the second element is at an 8-byte offset.
|
|
|
|
assert(TD.getStructLayout(Result)->getElementOffset(1) == 8 &&
|
|
|
|
"Invalid x86-64 argument pair!");
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
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;
|
2013-06-12 08:13:45 +08:00
|
|
|
classify(RetTy, 0, Lo, Hi, /*isNamedArg*/ true);
|
2009-06-06 06:08:42 +08:00
|
|
|
|
|
|
|
// Check some invariants.
|
|
|
|
assert((Hi != Memory || Lo == Memory) && "Invalid memory classification.");
|
|
|
|
assert((Hi != SSEUp || Lo == SSE) && "Invalid SSEUp classification.");
|
|
|
|
|
2014-05-21 13:09:00 +08:00
|
|
|
llvm::Type *ResType = nullptr;
|
2009-06-06 06:08:42 +08:00
|
|
|
switch (Lo) {
|
|
|
|
case NoClass:
|
2010-07-30 12:02:24 +08:00
|
|
|
if (Hi == NoClass)
|
|
|
|
return ABIArgInfo::getIgnore();
|
|
|
|
// If the low part is just padding, it takes no register, leave ResType
|
|
|
|
// null.
|
|
|
|
assert((Hi == SSE || Hi == Integer || Hi == X87Up) &&
|
|
|
|
"Unknown missing lo part");
|
|
|
|
break;
|
2009-06-06 06:08:42 +08:00
|
|
|
|
|
|
|
case SSEUp:
|
|
|
|
case X87Up:
|
2011-09-23 13:06:16 +08:00
|
|
|
llvm_unreachable("Invalid classification for lo word.");
|
2009-06-06 06:08:42 +08:00
|
|
|
|
|
|
|
// 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:
|
2011-07-10 01:41:47 +08:00
|
|
|
ResType = GetINTEGERTypeAtOffset(CGT.ConvertType(RetTy), 0, RetTy, 0);
|
2010-08-26 02:17:27 +08:00
|
|
|
|
2010-07-30 05:42:50 +08:00
|
|
|
// If we have a sign or zero extended integer, make sure to return Extend
|
|
|
|
// so that the parameter gets the right LLVM IR attributes.
|
|
|
|
if (Hi == NoClass && isa<llvm::IntegerType>(ResType)) {
|
|
|
|
// Treat an enum type as its underlying type.
|
|
|
|
if (const EnumType *EnumTy = RetTy->getAs<EnumType>())
|
|
|
|
RetTy = EnumTy->getDecl()->getIntegerType();
|
2010-08-26 02:17:27 +08:00
|
|
|
|
2010-07-30 05:42:50 +08:00
|
|
|
if (RetTy->isIntegralOrEnumerationType() &&
|
|
|
|
RetTy->isPromotableIntegerType())
|
|
|
|
return ABIArgInfo::getExtend();
|
|
|
|
}
|
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:
|
2011-07-10 01:41:47 +08:00
|
|
|
ResType = GetSSETypeAtOffset(CGT.ConvertType(RetTy), 0, RetTy, 0);
|
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.");
|
2011-06-19 06:49:11 +08:00
|
|
|
ResType = llvm::StructType::get(llvm::Type::getX86_FP80Ty(getVMContext()),
|
2010-07-29 10:01:43 +08:00
|
|
|
llvm::Type::getX86_FP80Ty(getVMContext()),
|
2014-12-02 06:02:27 +08:00
|
|
|
nullptr);
|
2009-06-06 06:08:42 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-05-21 13:09:00 +08:00
|
|
|
llvm::Type *HighPart = nullptr;
|
2009-06-06 06:08:42 +08:00
|
|
|
switch (Hi) {
|
|
|
|
// Memory was handled previously and X87 should
|
|
|
|
// never occur as a hi class.
|
|
|
|
case Memory:
|
|
|
|
case X87:
|
2011-09-23 13:06:16 +08:00
|
|
|
llvm_unreachable("Invalid classification for hi word.");
|
2009-06-06 06:08:42 +08:00
|
|
|
|
|
|
|
case ComplexX87: // Previously handled.
|
2010-07-29 07:12:33 +08:00
|
|
|
case NoClass:
|
|
|
|
break;
|
2009-06-06 06:08:42 +08:00
|
|
|
|
2010-09-01 08:20:33 +08:00
|
|
|
case Integer:
|
2011-07-10 01:41:47 +08:00
|
|
|
HighPart = GetINTEGERTypeAtOffset(CGT.ConvertType(RetTy), 8, RetTy, 8);
|
2010-09-01 08:20:33 +08:00
|
|
|
if (Lo == NoClass) // Return HighPart at offset 8 in memory.
|
|
|
|
return ABIArgInfo::getDirect(HighPart, 8);
|
2009-06-06 06:08:42 +08:00
|
|
|
break;
|
2010-09-01 08:20:33 +08:00
|
|
|
case SSE:
|
2011-07-10 01:41:47 +08:00
|
|
|
HighPart = GetSSETypeAtOffset(CGT.ConvertType(RetTy), 8, RetTy, 8);
|
2010-09-01 08:20:33 +08:00
|
|
|
if (Lo == NoClass) // Return HighPart at offset 8 in memory.
|
|
|
|
return ABIArgInfo::getDirect(HighPart, 8);
|
2009-06-06 06:08:42 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
// AMD64-ABI 3.2.3p4: Rule 5. If the class is SSEUP, the eightbyte
|
2011-07-12 06:41:29 +08:00
|
|
|
// is passed in the next available eightbyte chunk if the last used
|
|
|
|
// vector register.
|
2009-06-06 06:08:42 +08:00
|
|
|
//
|
2011-04-15 13:22:18 +08:00
|
|
|
// SSEUP should always be preceded by SSE, just widen.
|
2009-06-06 06:08:42 +08:00
|
|
|
case SSEUp:
|
|
|
|
assert(Lo == SSE && "Unexpected SSEUp classification.");
|
2011-07-12 06:41:29 +08:00
|
|
|
ResType = GetByteVectorType(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:
|
2011-04-15 13:22:18 +08:00
|
|
|
// If X87Up is preceded by X87, we don't need to do
|
2009-06-06 06:08:42 +08:00
|
|
|
// anything. However, in some cases with unions it may not be
|
2011-04-15 13:22:18 +08:00
|
|
|
// preceded by X87. In such situations we follow gcc and pass the
|
2009-06-06 06:08:42 +08:00
|
|
|
// extra bits in an SSE reg.
|
2010-07-30 01:49:08 +08:00
|
|
|
if (Lo != X87) {
|
2011-07-10 01:41:47 +08:00
|
|
|
HighPart = GetSSETypeAtOffset(CGT.ConvertType(RetTy), 8, RetTy, 8);
|
2010-09-01 08:20:33 +08:00
|
|
|
if (Lo == NoClass) // Return HighPart at offset 8 in memory.
|
|
|
|
return ABIArgInfo::getDirect(HighPart, 8);
|
2010-07-30 01:49:08 +08:00
|
|
|
}
|
2009-06-06 06:08:42 +08:00
|
|
|
break;
|
|
|
|
}
|
2010-10-19 14:39:39 +08:00
|
|
|
|
2010-09-01 08:20:33 +08:00
|
|
|
// If a high part was specified, merge it together with the low part. It is
|
2010-09-01 08:24:35 +08:00
|
|
|
// known to pass in the high eightbyte of the result. We do this by forming a
|
|
|
|
// first class struct aggregate with the high and low part: {low, high}
|
2010-09-01 08:50:20 +08:00
|
|
|
if (HighPart)
|
2012-10-09 00:25:52 +08:00
|
|
|
ResType = GetX86_64ByValArgumentPair(ResType, HighPart, getDataLayout());
|
2009-06-06 06:08:42 +08:00
|
|
|
|
2010-07-30 05:42:50 +08:00
|
|
|
return ABIArgInfo::getDirect(ResType);
|
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
|
|
|
}
|
|
|
|
|
IRgen/ABI/x86_64: Avoid passing small structs using byval sometimes.
- We do this when it is easy to determine that the backend will pass them on
the stack properly by itself.
Currently LLVM codegen is really bad in some cases with byval, for example, on
the test case here (which is derived from Sema code, which likes to pass
SourceLocations around)::
struct s47 { unsigned a; };
void f47(int,int,int,int,int,int,struct s47);
void test47(int a, struct s47 b) { f47(a, a, a, a, a, a, b); }
we used to emit code like this::
...
movl %esi, -8(%rbp)
movl -8(%rbp), %ecx
movl %ecx, (%rsp)
...
to handle moving the struct onto the stack, which is just appalling.
Now we generate::
movl %esi, (%rsp)
which seems better, no?
llvm-svn: 152462
2012-03-10 09:03:58 +08:00
|
|
|
ABIArgInfo X86_64ABIInfo::classifyArgumentType(
|
2013-06-12 08:13:45 +08:00
|
|
|
QualType Ty, unsigned freeIntRegs, unsigned &neededInt, unsigned &neededSSE,
|
|
|
|
bool isNamedArg)
|
IRgen/ABI/x86_64: Avoid passing small structs using byval sometimes.
- We do this when it is easy to determine that the backend will pass them on
the stack properly by itself.
Currently LLVM codegen is really bad in some cases with byval, for example, on
the test case here (which is derived from Sema code, which likes to pass
SourceLocations around)::
struct s47 { unsigned a; };
void f47(int,int,int,int,int,int,struct s47);
void test47(int a, struct s47 b) { f47(a, a, a, a, a, a, b); }
we used to emit code like this::
...
movl %esi, -8(%rbp)
movl -8(%rbp), %ecx
movl %ecx, (%rsp)
...
to handle moving the struct onto the stack, which is just appalling.
Now we generate::
movl %esi, (%rsp)
which seems better, no?
llvm-svn: 152462
2012-03-10 09:03:58 +08:00
|
|
|
const
|
|
|
|
{
|
2014-11-15 09:41:41 +08:00
|
|
|
Ty = useFirstFieldIfTransparentUnion(Ty);
|
|
|
|
|
2009-06-06 06:08:42 +08:00
|
|
|
X86_64ABIInfo::Class Lo, Hi;
|
2013-06-12 08:13:45 +08:00
|
|
|
classify(Ty, 0, Lo, Hi, isNamedArg);
|
2010-08-26 02:17:27 +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((Hi != SSEUp || Lo == SSE) && "Invalid SSEUp classification.");
|
|
|
|
|
|
|
|
neededInt = 0;
|
|
|
|
neededSSE = 0;
|
2014-05-21 13:09:00 +08:00
|
|
|
llvm::Type *ResType = nullptr;
|
2009-06-06 06:08:42 +08:00
|
|
|
switch (Lo) {
|
|
|
|
case NoClass:
|
2010-07-30 12:02:24 +08:00
|
|
|
if (Hi == NoClass)
|
|
|
|
return ABIArgInfo::getIgnore();
|
|
|
|
// If the low part is just padding, it takes no register, leave ResType
|
|
|
|
// null.
|
|
|
|
assert((Hi == SSE || Hi == Integer || Hi == X87Up) &&
|
|
|
|
"Unknown missing lo part");
|
|
|
|
break;
|
2010-08-26 02:17:27 +08:00
|
|
|
|
2009-06-06 06:08:42 +08:00
|
|
|
// 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:
|
2013-10-06 09:33:34 +08:00
|
|
|
if (getRecordArgABI(Ty, getCXXABI()) == CGCXXABI::RAA_Indirect)
|
2011-06-29 15:04:55 +08:00
|
|
|
++neededInt;
|
IRgen/ABI/x86_64: Avoid passing small structs using byval sometimes.
- We do this when it is easy to determine that the backend will pass them on
the stack properly by itself.
Currently LLVM codegen is really bad in some cases with byval, for example, on
the test case here (which is derived from Sema code, which likes to pass
SourceLocations around)::
struct s47 { unsigned a; };
void f47(int,int,int,int,int,int,struct s47);
void test47(int a, struct s47 b) { f47(a, a, a, a, a, a, b); }
we used to emit code like this::
...
movl %esi, -8(%rbp)
movl -8(%rbp), %ecx
movl %ecx, (%rsp)
...
to handle moving the struct onto the stack, which is just appalling.
Now we generate::
movl %esi, (%rsp)
which seems better, no?
llvm-svn: 152462
2012-03-10 09:03:58 +08:00
|
|
|
return getIndirectResult(Ty, freeIntRegs);
|
2009-06-06 06:08:42 +08:00
|
|
|
|
|
|
|
case SSEUp:
|
|
|
|
case X87Up:
|
2011-09-23 13:06:16 +08:00
|
|
|
llvm_unreachable("Invalid classification for lo word.");
|
2009-06-06 06:08:42 +08:00
|
|
|
|
|
|
|
// 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-08-26 02:17:27 +08:00
|
|
|
|
2010-07-29 06:44:07 +08:00
|
|
|
// Pick an 8-byte type based on the preferred type.
|
2011-07-10 01:41:47 +08:00
|
|
|
ResType = GetINTEGERTypeAtOffset(CGT.ConvertType(Ty), 0, Ty, 0);
|
2010-07-30 05:42:50 +08:00
|
|
|
|
|
|
|
// If we have a sign or zero extended integer, make sure to return Extend
|
|
|
|
// so that the parameter gets the right LLVM IR attributes.
|
|
|
|
if (Hi == NoClass && isa<llvm::IntegerType>(ResType)) {
|
|
|
|
// Treat an enum type as its underlying type.
|
|
|
|
if (const EnumType *EnumTy = Ty->getAs<EnumType>())
|
|
|
|
Ty = EnumTy->getDecl()->getIntegerType();
|
2010-08-26 02:17:27 +08:00
|
|
|
|
2010-07-30 05:42:50 +08:00
|
|
|
if (Ty->isIntegralOrEnumerationType() &&
|
|
|
|
Ty->isPromotableIntegerType())
|
|
|
|
return ABIArgInfo::getExtend();
|
|
|
|
}
|
2010-08-26 02:17:27 +08:00
|
|
|
|
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.
|
2010-10-18 11:41:31 +08:00
|
|
|
case SSE: {
|
2011-07-10 01:41:47 +08:00
|
|
|
llvm::Type *IRType = CGT.ConvertType(Ty);
|
2011-07-02 08:57:27 +08:00
|
|
|
ResType = GetSSETypeAtOffset(IRType, 0, Ty, 0);
|
2010-10-19 07:51:38 +08:00
|
|
|
++neededSSE;
|
2009-06-06 06:08:42 +08:00
|
|
|
break;
|
|
|
|
}
|
2010-10-18 11:41:31 +08:00
|
|
|
}
|
2009-06-06 06:08:42 +08:00
|
|
|
|
2014-05-21 13:09:00 +08:00
|
|
|
llvm::Type *HighPart = nullptr;
|
2009-06-06 06:08:42 +08:00
|
|
|
switch (Hi) {
|
|
|
|
// Memory was handled previously, ComplexX87 and X87 should
|
2011-04-15 13:22:18 +08:00
|
|
|
// never occur as hi classes, and X87Up must be preceded by X87,
|
2009-06-06 06:08:42 +08:00
|
|
|
// which is passed in memory.
|
|
|
|
case Memory:
|
|
|
|
case X87:
|
|
|
|
case ComplexX87:
|
2011-09-23 13:06:16 +08:00
|
|
|
llvm_unreachable("Invalid classification for hi word.");
|
2009-06-06 06:08:42 +08:00
|
|
|
|
|
|
|
case NoClass: break;
|
2010-08-26 02:17:27 +08:00
|
|
|
|
2010-09-01 08:24:35 +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.
|
2011-07-10 01:41:47 +08:00
|
|
|
HighPart = GetINTEGERTypeAtOffset(CGT.ConvertType(Ty), 8, Ty, 8);
|
2010-07-30 12:02:24 +08:00
|
|
|
|
2010-09-01 08:24:35 +08:00
|
|
|
if (Lo == NoClass) // Pass HighPart at offset 8 in memory.
|
|
|
|
return ABIArgInfo::getDirect(HighPart, 8);
|
2009-06-06 06:08:42 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
// X87Up generally doesn't occur here (long double is passed in
|
|
|
|
// memory), except in situations involving unions.
|
|
|
|
case X87Up:
|
2010-09-01 08:24:35 +08:00
|
|
|
case SSE:
|
2011-07-10 01:41:47 +08:00
|
|
|
HighPart = GetSSETypeAtOffset(CGT.ConvertType(Ty), 8, Ty, 8);
|
2010-08-26 02:17:27 +08:00
|
|
|
|
2010-09-01 08:24:35 +08:00
|
|
|
if (Lo == NoClass) // Pass HighPart at offset 8 in memory.
|
|
|
|
return ABIArgInfo::getDirect(HighPart, 8);
|
2010-07-30 12:02:24 +08:00
|
|
|
|
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-08-26 02:17:27 +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");
|
2011-07-12 06:41:29 +08:00
|
|
|
ResType = GetByteVectorType(Ty);
|
2009-06-06 06:08:42 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-09-01 08:24:35 +08:00
|
|
|
// If a high part was specified, merge it together with the low part. It is
|
|
|
|
// known to pass in the high eightbyte of the result. We do this by forming a
|
|
|
|
// first class struct aggregate with the high and low part: {low, high}
|
|
|
|
if (HighPart)
|
2012-10-09 00:25:52 +08:00
|
|
|
ResType = GetX86_64ByValArgumentPair(ResType, HighPart, getDataLayout());
|
2010-10-19 14:39:39 +08:00
|
|
|
|
2010-07-30 05:42:50 +08:00
|
|
|
return ABIArgInfo::getDirect(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-08-26 02:17:27 +08:00
|
|
|
|
2014-05-14 06:05:45 +08:00
|
|
|
if (!getCXXABI().classifyReturnType(FI))
|
|
|
|
FI.getReturnInfo() = classifyReturnType(FI.getReturnType());
|
2009-06-06 06:08:42 +08:00
|
|
|
|
|
|
|
// Keep track of the number of assigned registers.
|
2010-10-19 07:51:38 +08:00
|
|
|
unsigned freeIntRegs = 6, freeSSERegs = 8;
|
2009-06-06 06:08:42 +08:00
|
|
|
|
|
|
|
// If the return value is indirect, then the hidden argument is consuming one
|
|
|
|
// integer register.
|
|
|
|
if (FI.getReturnInfo().isIndirect())
|
|
|
|
--freeIntRegs;
|
|
|
|
|
2014-09-30 05:21:48 +08:00
|
|
|
unsigned NumRequiredArgs = FI.getNumRequiredArgs();
|
2009-06-06 06:08:42 +08:00
|
|
|
// AMD64-ABI 3.2.3p3: Once arguments are classified, the registers
|
|
|
|
// get assigned (in left-to-right order) for passing as follows...
|
2014-09-30 05:21:48 +08:00
|
|
|
unsigned ArgNo = 0;
|
2009-06-06 06:08:42 +08:00
|
|
|
for (CGFunctionInfo::arg_iterator it = FI.arg_begin(), ie = FI.arg_end();
|
2014-09-30 05:21:48 +08:00
|
|
|
it != ie; ++it, ++ArgNo) {
|
|
|
|
bool IsNamedArg = ArgNo < NumRequiredArgs;
|
2013-06-12 08:13:45 +08:00
|
|
|
|
2010-10-19 07:51:38 +08:00
|
|
|
unsigned neededInt, neededSSE;
|
IRgen/ABI/x86_64: Avoid passing small structs using byval sometimes.
- We do this when it is easy to determine that the backend will pass them on
the stack properly by itself.
Currently LLVM codegen is really bad in some cases with byval, for example, on
the test case here (which is derived from Sema code, which likes to pass
SourceLocations around)::
struct s47 { unsigned a; };
void f47(int,int,int,int,int,int,struct s47);
void test47(int a, struct s47 b) { f47(a, a, a, a, a, a, b); }
we used to emit code like this::
...
movl %esi, -8(%rbp)
movl -8(%rbp), %ecx
movl %ecx, (%rsp)
...
to handle moving the struct onto the stack, which is just appalling.
Now we generate::
movl %esi, (%rsp)
which seems better, no?
llvm-svn: 152462
2012-03-10 09:03:58 +08:00
|
|
|
it->info = classifyArgumentType(it->type, freeIntRegs, neededInt,
|
2014-09-30 05:21:48 +08:00
|
|
|
neededSSE, IsNamedArg);
|
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.
|
2010-10-19 07:51:38 +08:00
|
|
|
if (freeIntRegs >= neededInt && freeSSERegs >= neededSSE) {
|
2009-06-06 06:08:42 +08:00
|
|
|
freeIntRegs -= neededInt;
|
|
|
|
freeSSERegs -= neededSSE;
|
|
|
|
} else {
|
IRgen/ABI/x86_64: Avoid passing small structs using byval sometimes.
- We do this when it is easy to determine that the backend will pass them on
the stack properly by itself.
Currently LLVM codegen is really bad in some cases with byval, for example, on
the test case here (which is derived from Sema code, which likes to pass
SourceLocations around)::
struct s47 { unsigned a; };
void f47(int,int,int,int,int,int,struct s47);
void test47(int a, struct s47 b) { f47(a, a, a, a, a, a, b); }
we used to emit code like this::
...
movl %esi, -8(%rbp)
movl -8(%rbp), %ecx
movl %ecx, (%rsp)
...
to handle moving the struct onto the stack, which is just appalling.
Now we generate::
movl %esi, (%rsp)
which seems better, no?
llvm-svn: 152462
2012-03-10 09:03:58 +08:00
|
|
|
it->info = getIndirectResult(it->type, freeIntRegs);
|
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.
|
2011-11-18 10:44:19 +08:00
|
|
|
// It isn't stated explicitly in the standard, but in practice we use
|
|
|
|
// alignment greater than 16 where necessary.
|
2009-06-06 06:08:42 +08:00
|
|
|
uint64_t Align = CGF.getContext().getTypeAlign(Ty) / 8;
|
|
|
|
if (Align > 8) {
|
2011-11-18 10:44:19 +08:00
|
|
|
// overflow_arg_area = (overflow_arg_area + align - 1) & -align;
|
2009-08-14 05:57:51 +08:00
|
|
|
llvm::Value *Offset =
|
2011-11-18 10:44:19 +08:00
|
|
|
llvm::ConstantInt::get(CGF.Int64Ty, Align - 1);
|
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);
|
2011-11-18 10:44:19 +08:00
|
|
|
llvm::Value *Mask = llvm::ConstantInt::get(CGF.Int64Ty, -(uint64_t)Align);
|
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.
|
2011-07-18 12:24:23 +08:00
|
|
|
llvm::Type *LTy = CGF.ConvertTypeForMem(Ty);
|
2009-06-06 06:08:42 +08:00
|
|
|
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 {
|
|
|
|
// 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;
|
|
|
|
// };
|
2010-10-19 07:51:38 +08:00
|
|
|
unsigned neededInt, neededSSE;
|
2010-08-26 02:17:27 +08:00
|
|
|
|
2010-03-12 02:19:55 +08:00
|
|
|
Ty = CGF.getContext().getCanonicalType(Ty);
|
2013-06-12 08:13:45 +08:00
|
|
|
ABIArgInfo AI = classifyArgumentType(Ty, 0, neededInt, neededSSE,
|
|
|
|
/*isNamedArg*/false);
|
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).
|
|
|
|
|
2014-05-21 13:09:00 +08:00
|
|
|
llvm::Value *InRegs = nullptr;
|
|
|
|
llvm::Value *gp_offset_p = nullptr, *gp_offset = nullptr;
|
|
|
|
llvm::Value *fp_offset_p = nullptr, *fp_offset = nullptr;
|
2009-06-06 06:08:42 +08:00
|
|
|
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?
|
2011-07-18 12:24:23 +08:00
|
|
|
llvm::Type *LTy = CGF.ConvertTypeForMem(Ty);
|
2009-06-06 06:08:42 +08:00
|
|
|
llvm::Value *RegAddr =
|
|
|
|
CGF.Builder.CreateLoad(CGF.Builder.CreateStructGEP(VAListAddr, 3),
|
|
|
|
"reg_save_area");
|
|
|
|
if (neededInt && neededSSE) {
|
|
|
|
// FIXME: Cleanup.
|
Kill off the 'coerce' ABI passing form. Now 'direct' and 'extend' always
have a "coerce to" type which often matches the default lowering of Clang
type to LLVM IR type, but the coerce case can be handled by making them
not be the same.
This simplifies things and fixes issues where X86-64 abi lowering would
return coerce after making preferred types exactly match up. This caused
us to compile:
typedef float v4f32 __attribute__((__vector_size__(16)));
v4f32 foo(v4f32 X) {
return X+X;
}
into this code at -O0:
define <4 x float> @foo(<4 x float> %X.coerce) nounwind {
entry:
%retval = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=2]
%coerce = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=2]
%X.addr = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=3]
store <4 x float> %X.coerce, <4 x float>* %coerce
%X = load <4 x float>* %coerce ; <<4 x float>> [#uses=1]
store <4 x float> %X, <4 x float>* %X.addr
%tmp = load <4 x float>* %X.addr ; <<4 x float>> [#uses=1]
%tmp1 = load <4 x float>* %X.addr ; <<4 x float>> [#uses=1]
%add = fadd <4 x float> %tmp, %tmp1 ; <<4 x float>> [#uses=1]
store <4 x float> %add, <4 x float>* %retval
%0 = load <4 x float>* %retval ; <<4 x float>> [#uses=1]
ret <4 x float> %0
}
Now we get:
define <4 x float> @foo(<4 x float> %X) nounwind {
entry:
%X.addr = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=3]
store <4 x float> %X, <4 x float>* %X.addr
%tmp = load <4 x float>* %X.addr ; <<4 x float>> [#uses=1]
%tmp1 = load <4 x float>* %X.addr ; <<4 x float>> [#uses=1]
%add = fadd <4 x float> %tmp, %tmp1 ; <<4 x float>> [#uses=1]
ret <4 x float> %add
}
This implements rdar://8248065
llvm-svn: 109733
2010-07-29 14:26:06 +08:00
|
|
|
assert(AI.isDirect() && "Unexpected ABI info for mixed regs");
|
2011-07-18 12:24:23 +08:00
|
|
|
llvm::StructType *ST = cast<llvm::StructType>(AI.getCoerceToType());
|
2013-06-08 07:20:55 +08:00
|
|
|
llvm::Value *Tmp = CGF.CreateMemTemp(Ty);
|
|
|
|
Tmp = CGF.Builder.CreateBitCast(Tmp, ST->getPointerTo());
|
2009-06-06 06:08:42 +08:00
|
|
|
assert(ST->getNumElements() == 2 && "Unexpected ABI info for mixed regs");
|
2011-07-18 12:24:23 +08:00
|
|
|
llvm::Type *TyLo = ST->getElementType(0);
|
|
|
|
llvm::Type *TyHi = ST->getElementType(1);
|
2010-08-26 14:28:35 +08:00
|
|
|
assert((TyLo->isFPOrFPVectorTy() ^ TyHi->isFPOrFPVectorTy()) &&
|
2009-06-06 06:08:42 +08:00
|
|
|
"Unexpected ABI info for mixed regs");
|
2011-07-18 12:24:23 +08:00
|
|
|
llvm::Type *PTyLo = llvm::PointerType::getUnqual(TyLo);
|
|
|
|
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);
|
2014-06-25 04:01:50 +08:00
|
|
|
llvm::Value *RegLoAddr = TyLo->isFPOrFPVectorTy() ? FPAddr : GPAddr;
|
|
|
|
llvm::Value *RegHiAddr = TyLo->isFPOrFPVectorTy() ? 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));
|
2013-06-08 07:20:55 +08:00
|
|
|
|
|
|
|
// Copy to a temporary if necessary to ensure the appropriate alignment.
|
|
|
|
std::pair<CharUnits, CharUnits> SizeAlign =
|
|
|
|
CGF.getContext().getTypeInfoInChars(Ty);
|
|
|
|
uint64_t TySize = SizeAlign.first.getQuantity();
|
|
|
|
unsigned TyAlign = SizeAlign.second.getQuantity();
|
|
|
|
if (TyAlign > 8) {
|
|
|
|
llvm::Value *Tmp = CGF.CreateMemTemp(Ty);
|
|
|
|
CGF.Builder.CreateMemCpy(Tmp, RegAddr, TySize, 8, false);
|
|
|
|
RegAddr = Tmp;
|
|
|
|
}
|
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);
|
2012-02-07 08:39:47 +08:00
|
|
|
llvm::Type *DoubleTy = CGF.DoubleTy;
|
2011-07-18 12:24:23 +08:00
|
|
|
llvm::Type *DblPtrTy =
|
2010-06-29 04:05:43 +08:00
|
|
|
llvm::PointerType::getUnqual(DoubleTy);
|
2014-12-02 06:02:27 +08:00
|
|
|
llvm::StructType *ST = llvm::StructType::get(DoubleTy, DoubleTy, nullptr);
|
2013-06-08 07:20:55 +08:00
|
|
|
llvm::Value *V, *Tmp = CGF.CreateMemTemp(Ty);
|
|
|
|
Tmp = CGF.Builder.CreateBitCast(Tmp, ST->getPointerTo());
|
2010-06-29 04:05:43 +08:00
|
|
|
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);
|
2011-03-30 19:28:58 +08:00
|
|
|
llvm::PHINode *ResAddr = CGF.Builder.CreatePHI(RegAddr->getType(), 2,
|
2009-06-06 06:08:42 +08:00
|
|
|
"vaarg.addr");
|
|
|
|
ResAddr->addIncoming(RegAddr, InRegBlock);
|
|
|
|
ResAddr->addIncoming(MemAddr, InMemBlock);
|
|
|
|
return ResAddr;
|
|
|
|
}
|
|
|
|
|
2014-11-01 06:00:51 +08:00
|
|
|
ABIArgInfo WinX86_64ABIInfo::classify(QualType Ty, unsigned &FreeSSERegs,
|
|
|
|
bool IsReturnType) const {
|
2011-01-18 06:56:31 +08:00
|
|
|
|
|
|
|
if (Ty->isVoidType())
|
|
|
|
return ABIArgInfo::getIgnore();
|
|
|
|
|
|
|
|
if (const EnumType *EnumTy = Ty->getAs<EnumType>())
|
|
|
|
Ty = EnumTy->getDecl()->getIntegerType();
|
|
|
|
|
2014-11-01 06:00:51 +08:00
|
|
|
TypeInfo Info = getContext().getTypeInfo(Ty);
|
|
|
|
uint64_t Width = Info.Width;
|
|
|
|
unsigned Align = getContext().toCharUnitsFromBits(Info.Align).getQuantity();
|
2011-01-18 06:56:31 +08:00
|
|
|
|
2014-05-02 08:51:20 +08:00
|
|
|
const RecordType *RT = Ty->getAs<RecordType>();
|
|
|
|
if (RT) {
|
2014-05-14 06:05:45 +08:00
|
|
|
if (!IsReturnType) {
|
2013-10-06 09:33:34 +08:00
|
|
|
if (CGCXXABI::RecordArgABI RAA = getRecordArgABI(RT, getCXXABI()))
|
2013-04-17 20:54:10 +08:00
|
|
|
return ABIArgInfo::getIndirect(0, RAA == CGCXXABI::RAA_DirectInMemory);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (RT->getDecl()->hasFlexibleArrayMember())
|
2011-01-18 06:56:31 +08:00
|
|
|
return ABIArgInfo::getIndirect(0, /*ByVal=*/false);
|
|
|
|
|
2011-02-22 11:56:57 +08:00
|
|
|
// FIXME: mingw-w64-gcc emits 128-bit struct as i128
|
2014-11-01 06:00:51 +08:00
|
|
|
if (Width == 128 && getTarget().getTriple().isWindowsGNUEnvironment())
|
2011-02-22 11:56:57 +08:00
|
|
|
return ABIArgInfo::getDirect(llvm::IntegerType::get(getVMContext(),
|
2014-11-01 06:00:51 +08:00
|
|
|
Width));
|
|
|
|
}
|
|
|
|
|
|
|
|
// vectorcall adds the concept of a homogenous vector aggregate, similar to
|
|
|
|
// other targets.
|
|
|
|
const Type *Base = nullptr;
|
|
|
|
uint64_t NumElts = 0;
|
|
|
|
if (FreeSSERegs && isHomogeneousAggregate(Ty, Base, NumElts)) {
|
|
|
|
if (FreeSSERegs >= NumElts) {
|
|
|
|
FreeSSERegs -= NumElts;
|
|
|
|
if (IsReturnType || Ty->isBuiltinType() || Ty->isVectorType())
|
|
|
|
return ABIArgInfo::getDirect();
|
|
|
|
return ABIArgInfo::getExpand();
|
|
|
|
}
|
|
|
|
return ABIArgInfo::getIndirect(Align, /*ByVal=*/false);
|
2014-05-02 08:51:20 +08:00
|
|
|
}
|
|
|
|
|
2014-11-01 06:00:51 +08:00
|
|
|
|
2014-05-02 09:17:12 +08:00
|
|
|
if (Ty->isMemberPointerType()) {
|
2014-05-02 09:14:59 +08:00
|
|
|
// If the member pointer is represented by an LLVM int or ptr, pass it
|
|
|
|
// directly.
|
|
|
|
llvm::Type *LLTy = CGT.ConvertType(Ty);
|
|
|
|
if (LLTy->isPointerTy() || LLTy->isIntegerTy())
|
|
|
|
return ABIArgInfo::getDirect();
|
2014-05-02 08:51:20 +08:00
|
|
|
}
|
2011-02-22 11:56:57 +08:00
|
|
|
|
2014-05-02 08:51:20 +08:00
|
|
|
if (RT || Ty->isMemberPointerType()) {
|
2011-02-22 11:56:57 +08:00
|
|
|
// MS x64 ABI requirement: "Any argument that doesn't fit in 8 bytes, or is
|
|
|
|
// not 1, 2, 4, or 8 bytes, must be passed by reference."
|
2014-11-01 06:00:51 +08:00
|
|
|
if (Width > 64 || !llvm::isPowerOf2_64(Width))
|
2014-05-02 08:51:20 +08:00
|
|
|
return ABIArgInfo::getIndirect(0, /*ByVal=*/false);
|
2011-01-18 06:56:31 +08:00
|
|
|
|
2014-05-02 08:51:20 +08:00
|
|
|
// Otherwise, coerce it to a small integer.
|
2014-11-01 06:00:51 +08:00
|
|
|
return ABIArgInfo::getDirect(llvm::IntegerType::get(getVMContext(), Width));
|
2011-01-18 06:56:31 +08:00
|
|
|
}
|
|
|
|
|
2014-08-27 08:36:55 +08:00
|
|
|
// Bool type is always extended to the ABI, other builtin types are not
|
|
|
|
// extended.
|
|
|
|
const BuiltinType *BT = Ty->getAs<BuiltinType>();
|
|
|
|
if (BT && BT->getKind() == BuiltinType::Bool)
|
2014-08-27 06:11:53 +08:00
|
|
|
return ABIArgInfo::getExtend();
|
|
|
|
|
2011-01-18 06:56:31 +08:00
|
|
|
return ABIArgInfo::getDirect();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WinX86_64ABIInfo::computeInfo(CGFunctionInfo &FI) const {
|
2014-11-01 06:00:51 +08:00
|
|
|
bool IsVectorCall =
|
|
|
|
FI.getCallingConvention() == llvm::CallingConv::X86_VectorCall;
|
|
|
|
|
|
|
|
// We can use up to 4 SSE return registers with vectorcall.
|
|
|
|
unsigned FreeSSERegs = IsVectorCall ? 4 : 0;
|
2014-05-14 06:05:45 +08:00
|
|
|
if (!getCXXABI().classifyReturnType(FI))
|
2014-11-01 06:00:51 +08:00
|
|
|
FI.getReturnInfo() = classify(FI.getReturnType(), FreeSSERegs, true);
|
2014-05-10 06:46:15 +08:00
|
|
|
|
2014-11-01 06:00:51 +08:00
|
|
|
// We can use up to 6 SSE register parameters with vectorcall.
|
|
|
|
FreeSSERegs = IsVectorCall ? 6 : 0;
|
2014-03-18 02:10:01 +08:00
|
|
|
for (auto &I : FI.arguments())
|
2014-11-01 06:00:51 +08:00
|
|
|
I.info = classify(I.type, FreeSSERegs, false);
|
2011-01-18 06:56:31 +08:00
|
|
|
}
|
|
|
|
|
2010-09-01 00:44:54 +08:00
|
|
|
llvm::Value *WinX86_64ABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
|
|
|
|
CodeGenFunction &CGF) const {
|
2012-02-07 08:39:47 +08:00
|
|
|
llvm::Type *BPP = CGF.Int8PtrPtrTy;
|
2010-09-01 00:44:54 +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 =
|
|
|
|
llvm::PointerType::getUnqual(CGF.ConvertType(Ty));
|
|
|
|
llvm::Value *AddrTyped = Builder.CreateBitCast(Addr, PTy);
|
|
|
|
|
|
|
|
uint64_t Offset =
|
|
|
|
llvm::RoundUpToAlignment(CGF.getContext().getTypeSize(Ty) / 8, 8);
|
|
|
|
llvm::Value *NextAddr =
|
|
|
|
Builder.CreateGEP(Addr, llvm::ConstantInt::get(CGF.Int32Ty, Offset),
|
|
|
|
"ap.next");
|
|
|
|
Builder.CreateStore(NextAddr, VAListAddrAsBPP);
|
2010-06-29 04:05:43 +08:00
|
|
|
|
2010-09-01 00:44:54 +08:00
|
|
|
return AddrTyped;
|
|
|
|
}
|
2010-06-29 04:05:43 +08:00
|
|
|
|
2012-10-20 21:02:06 +08:00
|
|
|
namespace {
|
|
|
|
|
2012-10-17 06:30:41 +08:00
|
|
|
class NaClX86_64ABIInfo : public ABIInfo {
|
|
|
|
public:
|
|
|
|
NaClX86_64ABIInfo(CodeGen::CodeGenTypes &CGT, bool HasAVX)
|
|
|
|
: ABIInfo(CGT), PInfo(CGT), NInfo(CGT, HasAVX) {}
|
2014-03-12 14:41:41 +08:00
|
|
|
void computeInfo(CGFunctionInfo &FI) const override;
|
|
|
|
llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
|
|
|
|
CodeGenFunction &CGF) const override;
|
2012-10-17 06:30:41 +08:00
|
|
|
private:
|
|
|
|
PNaClABIInfo PInfo; // Used for generating calls with pnaclcall callingconv.
|
|
|
|
X86_64ABIInfo NInfo; // Used for everything else.
|
|
|
|
};
|
|
|
|
|
|
|
|
class NaClX86_64TargetCodeGenInfo : public TargetCodeGenInfo {
|
2014-09-30 13:29:28 +08:00
|
|
|
bool HasAVX;
|
2012-10-17 06:30:41 +08:00
|
|
|
public:
|
2014-09-30 13:29:28 +08:00
|
|
|
NaClX86_64TargetCodeGenInfo(CodeGen::CodeGenTypes &CGT, bool HasAVX)
|
|
|
|
: TargetCodeGenInfo(new NaClX86_64ABIInfo(CGT, HasAVX)), HasAVX(HasAVX) {
|
|
|
|
}
|
|
|
|
unsigned getOpenMPSimdDefaultAlignment(QualType) const override {
|
|
|
|
return HasAVX ? 32 : 16;
|
|
|
|
}
|
2012-10-17 06:30:41 +08:00
|
|
|
};
|
|
|
|
|
2012-10-20 21:02:06 +08:00
|
|
|
}
|
|
|
|
|
2012-10-17 06:30:41 +08:00
|
|
|
void NaClX86_64ABIInfo::computeInfo(CGFunctionInfo &FI) const {
|
|
|
|
if (FI.getASTCallingConvention() == CC_PnaclCall)
|
|
|
|
PInfo.computeInfo(FI);
|
|
|
|
else
|
|
|
|
NInfo.computeInfo(FI);
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::Value *NaClX86_64ABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
|
|
|
|
CodeGenFunction &CGF) const {
|
|
|
|
// Always use the native convention; calling pnacl-style varargs functions
|
|
|
|
// is unuspported.
|
|
|
|
return NInfo.EmitVAArg(VAListAddr, Ty, CGF);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-11 08:10:12 +08:00
|
|
|
// PowerPC-32
|
|
|
|
namespace {
|
2014-11-04 02:32:54 +08:00
|
|
|
/// PPC32_SVR4_ABIInfo - The 32-bit PowerPC ELF (SVR4) ABI information.
|
|
|
|
class PPC32_SVR4_ABIInfo : public DefaultABIInfo {
|
|
|
|
public:
|
|
|
|
PPC32_SVR4_ABIInfo(CodeGen::CodeGenTypes &CGT) : DefaultABIInfo(CGT) {}
|
|
|
|
|
|
|
|
llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
|
|
|
|
CodeGenFunction &CGF) const override;
|
|
|
|
};
|
|
|
|
|
|
|
|
class PPC32TargetCodeGenInfo : public TargetCodeGenInfo {
|
2010-03-11 08:10:12 +08:00
|
|
|
public:
|
2014-11-04 02:32:54 +08:00
|
|
|
PPC32TargetCodeGenInfo(CodeGenTypes &CGT) : TargetCodeGenInfo(new PPC32_SVR4_ABIInfo(CGT)) {}
|
2010-08-26 02:17:27 +08:00
|
|
|
|
2014-03-12 14:41:41 +08:00
|
|
|
int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const override {
|
2010-03-11 08:10:12 +08:00
|
|
|
// This is recovered from gcc output.
|
|
|
|
return 1; // r1 is the dedicated stack pointer
|
|
|
|
}
|
|
|
|
|
|
|
|
bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
|
2014-03-12 14:41:41 +08:00
|
|
|
llvm::Value *Address) const override;
|
2014-10-04 01:45:20 +08:00
|
|
|
|
|
|
|
unsigned getOpenMPSimdDefaultAlignment(QualType) const override {
|
|
|
|
return 16; // Natural alignment for Altivec vectors.
|
|
|
|
}
|
2010-03-11 08:10:12 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-11-04 02:32:54 +08:00
|
|
|
llvm::Value *PPC32_SVR4_ABIInfo::EmitVAArg(llvm::Value *VAListAddr,
|
|
|
|
QualType Ty,
|
|
|
|
CodeGenFunction &CGF) const {
|
|
|
|
if (const ComplexType *CTy = Ty->getAs<ComplexType>()) {
|
|
|
|
// TODO: Implement this. For now ignore.
|
|
|
|
(void)CTy;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isI64 = Ty->isIntegerType() && getContext().getTypeSize(Ty) == 64;
|
|
|
|
bool isInt = Ty->isIntegerType() || Ty->isPointerType() || Ty->isAggregateType();
|
|
|
|
llvm::Type *CharPtr = CGF.Int8PtrTy;
|
|
|
|
llvm::Type *CharPtrPtr = CGF.Int8PtrPtrTy;
|
|
|
|
|
|
|
|
CGBuilderTy &Builder = CGF.Builder;
|
|
|
|
llvm::Value *GPRPtr = Builder.CreateBitCast(VAListAddr, CharPtr, "gprptr");
|
|
|
|
llvm::Value *GPRPtrAsInt = Builder.CreatePtrToInt(GPRPtr, CGF.Int32Ty);
|
|
|
|
llvm::Value *FPRPtrAsInt = Builder.CreateAdd(GPRPtrAsInt, Builder.getInt32(1));
|
|
|
|
llvm::Value *FPRPtr = Builder.CreateIntToPtr(FPRPtrAsInt, CharPtr);
|
|
|
|
llvm::Value *OverflowAreaPtrAsInt = Builder.CreateAdd(FPRPtrAsInt, Builder.getInt32(3));
|
|
|
|
llvm::Value *OverflowAreaPtr = Builder.CreateIntToPtr(OverflowAreaPtrAsInt, CharPtrPtr);
|
|
|
|
llvm::Value *RegsaveAreaPtrAsInt = Builder.CreateAdd(OverflowAreaPtrAsInt, Builder.getInt32(4));
|
|
|
|
llvm::Value *RegsaveAreaPtr = Builder.CreateIntToPtr(RegsaveAreaPtrAsInt, CharPtrPtr);
|
|
|
|
llvm::Value *GPR = Builder.CreateLoad(GPRPtr, false, "gpr");
|
|
|
|
// Align GPR when TY is i64.
|
|
|
|
if (isI64) {
|
|
|
|
llvm::Value *GPRAnd = Builder.CreateAnd(GPR, Builder.getInt8(1));
|
|
|
|
llvm::Value *CC64 = Builder.CreateICmpEQ(GPRAnd, Builder.getInt8(1));
|
|
|
|
llvm::Value *GPRPlusOne = Builder.CreateAdd(GPR, Builder.getInt8(1));
|
|
|
|
GPR = Builder.CreateSelect(CC64, GPRPlusOne, GPR);
|
|
|
|
}
|
|
|
|
llvm::Value *FPR = Builder.CreateLoad(FPRPtr, false, "fpr");
|
|
|
|
llvm::Value *OverflowArea = Builder.CreateLoad(OverflowAreaPtr, false, "overflow_area");
|
|
|
|
llvm::Value *OverflowAreaAsInt = Builder.CreatePtrToInt(OverflowArea, CGF.Int32Ty);
|
|
|
|
llvm::Value *RegsaveArea = Builder.CreateLoad(RegsaveAreaPtr, false, "regsave_area");
|
|
|
|
llvm::Value *RegsaveAreaAsInt = Builder.CreatePtrToInt(RegsaveArea, CGF.Int32Ty);
|
|
|
|
|
|
|
|
llvm::Value *CC = Builder.CreateICmpULT(isInt ? GPR : FPR,
|
|
|
|
Builder.getInt8(8), "cond");
|
|
|
|
|
|
|
|
llvm::Value *RegConstant = Builder.CreateMul(isInt ? GPR : FPR,
|
|
|
|
Builder.getInt8(isInt ? 4 : 8));
|
|
|
|
|
|
|
|
llvm::Value *OurReg = Builder.CreateAdd(RegsaveAreaAsInt, Builder.CreateSExt(RegConstant, CGF.Int32Ty));
|
|
|
|
|
|
|
|
if (Ty->isFloatingType())
|
|
|
|
OurReg = Builder.CreateAdd(OurReg, Builder.getInt32(32));
|
|
|
|
|
|
|
|
llvm::BasicBlock *UsingRegs = CGF.createBasicBlock("using_regs");
|
|
|
|
llvm::BasicBlock *UsingOverflow = CGF.createBasicBlock("using_overflow");
|
|
|
|
llvm::BasicBlock *Cont = CGF.createBasicBlock("cont");
|
|
|
|
|
|
|
|
Builder.CreateCondBr(CC, UsingRegs, UsingOverflow);
|
|
|
|
|
|
|
|
CGF.EmitBlock(UsingRegs);
|
|
|
|
|
|
|
|
llvm::Type *PTy = llvm::PointerType::getUnqual(CGF.ConvertType(Ty));
|
|
|
|
llvm::Value *Result1 = Builder.CreateIntToPtr(OurReg, PTy);
|
|
|
|
// Increase the GPR/FPR indexes.
|
|
|
|
if (isInt) {
|
|
|
|
GPR = Builder.CreateAdd(GPR, Builder.getInt8(isI64 ? 2 : 1));
|
|
|
|
Builder.CreateStore(GPR, GPRPtr);
|
|
|
|
} else {
|
|
|
|
FPR = Builder.CreateAdd(FPR, Builder.getInt8(1));
|
|
|
|
Builder.CreateStore(FPR, FPRPtr);
|
|
|
|
}
|
|
|
|
CGF.EmitBranch(Cont);
|
|
|
|
|
|
|
|
CGF.EmitBlock(UsingOverflow);
|
|
|
|
|
|
|
|
// Increase the overflow area.
|
|
|
|
llvm::Value *Result2 = Builder.CreateIntToPtr(OverflowAreaAsInt, PTy);
|
|
|
|
OverflowAreaAsInt = Builder.CreateAdd(OverflowAreaAsInt, Builder.getInt32(isInt ? 4 : 8));
|
|
|
|
Builder.CreateStore(Builder.CreateIntToPtr(OverflowAreaAsInt, CharPtr), OverflowAreaPtr);
|
|
|
|
CGF.EmitBranch(Cont);
|
|
|
|
|
|
|
|
CGF.EmitBlock(Cont);
|
|
|
|
|
|
|
|
llvm::PHINode *Result = CGF.Builder.CreatePHI(PTy, 2, "vaarg.addr");
|
|
|
|
Result->addIncoming(Result1, UsingRegs);
|
|
|
|
Result->addIncoming(Result2, UsingOverflow);
|
|
|
|
|
|
|
|
if (Ty->isAggregateType()) {
|
|
|
|
llvm::Value *AGGPtr = Builder.CreateBitCast(Result, CharPtrPtr, "aggrptr") ;
|
|
|
|
return Builder.CreateLoad(AGGPtr, false, "aggr");
|
|
|
|
}
|
|
|
|
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2010-03-11 08:10:12 +08:00
|
|
|
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;
|
|
|
|
|
2012-02-07 08:39:47 +08:00
|
|
|
llvm::IntegerType *i8 = CGF.Int8Ty;
|
2010-03-11 08:10:12 +08:00
|
|
|
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
|
|
|
|
2010-08-26 02:17:27 +08:00
|
|
|
return false;
|
2010-03-11 08:10:12 +08:00
|
|
|
}
|
|
|
|
|
2012-05-10 02:22:46 +08:00
|
|
|
// PowerPC-64
|
|
|
|
|
|
|
|
namespace {
|
2012-10-04 03:18:57 +08:00
|
|
|
/// PPC64_SVR4_ABIInfo - The 64-bit PowerPC ELF (SVR4) ABI information.
|
|
|
|
class PPC64_SVR4_ABIInfo : public DefaultABIInfo {
|
[PowerPC] Support the ELFv2 ABI
This patch implements clang support for the PowerPC ELFv2 ABI.
Together with a series of companion patches in LLVM, this makes
clang/LLVM fully usable on powerpc64le-linux.
Most of the ELFv2 ABI changes are fully implemented on the LLVM side.
On the clang side, we only need to implement some changes in how
aggregate types are passed by value. Specifically, we need to:
- pass (and return) "homogeneous" floating-point or vector aggregates in
FPRs and VRs (this is similar to the ARM homogeneous aggregate ABI)
- return aggregates of up to 16 bytes in one or two GPRs
The second piece is trivial to implement in any case. To implement
the first piece, this patch makes use of infrastructure recently
enabled in the LLVM PowerPC back-end to support passing array types
directly, where the array element type encodes properties needed to
handle homogeneous aggregates correctly.
Specifically, the array element type encodes:
- whether the parameter should be passed in FPRs, VRs, or just
GPRs/stack slots (for float / vector / integer element types,
respectively)
- what the alignment requirements of the parameter are when passed in
GPRs/stack slots (8 for float / 16 for vector / the element type
size for integer element types) -- this corresponds to the
"byval align" field
With this support in place, the clang part simply needs to *detect*
whether an aggregate type implements a float / vector homogeneous
aggregate as defined by the ELFv2 ABI, and if so, pass/return it
as array type using the appropriate float / vector element type.
llvm-svn: 213494
2014-07-21 08:48:09 +08:00
|
|
|
public:
|
|
|
|
enum ABIKind {
|
|
|
|
ELFv1 = 0,
|
|
|
|
ELFv2
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
static const unsigned GPRBits = 64;
|
|
|
|
ABIKind Kind;
|
2012-10-04 03:18:57 +08:00
|
|
|
|
|
|
|
public:
|
[PowerPC] Support the ELFv2 ABI
This patch implements clang support for the PowerPC ELFv2 ABI.
Together with a series of companion patches in LLVM, this makes
clang/LLVM fully usable on powerpc64le-linux.
Most of the ELFv2 ABI changes are fully implemented on the LLVM side.
On the clang side, we only need to implement some changes in how
aggregate types are passed by value. Specifically, we need to:
- pass (and return) "homogeneous" floating-point or vector aggregates in
FPRs and VRs (this is similar to the ARM homogeneous aggregate ABI)
- return aggregates of up to 16 bytes in one or two GPRs
The second piece is trivial to implement in any case. To implement
the first piece, this patch makes use of infrastructure recently
enabled in the LLVM PowerPC back-end to support passing array types
directly, where the array element type encodes properties needed to
handle homogeneous aggregates correctly.
Specifically, the array element type encodes:
- whether the parameter should be passed in FPRs, VRs, or just
GPRs/stack slots (for float / vector / integer element types,
respectively)
- what the alignment requirements of the parameter are when passed in
GPRs/stack slots (8 for float / 16 for vector / the element type
size for integer element types) -- this corresponds to the
"byval align" field
With this support in place, the clang part simply needs to *detect*
whether an aggregate type implements a float / vector homogeneous
aggregate as defined by the ELFv2 ABI, and if so, pass/return it
as array type using the appropriate float / vector element type.
llvm-svn: 213494
2014-07-21 08:48:09 +08:00
|
|
|
PPC64_SVR4_ABIInfo(CodeGen::CodeGenTypes &CGT, ABIKind Kind)
|
|
|
|
: DefaultABIInfo(CGT), Kind(Kind) {}
|
2012-10-04 03:18:57 +08:00
|
|
|
|
2012-11-06 03:13:42 +08:00
|
|
|
bool isPromotableTypeForABI(QualType Ty) const;
|
2014-07-11 01:20:07 +08:00
|
|
|
bool isAlignedParamType(QualType Ty) const;
|
2012-11-06 03:13:42 +08:00
|
|
|
|
|
|
|
ABIArgInfo classifyReturnType(QualType RetTy) const;
|
|
|
|
ABIArgInfo classifyArgumentType(QualType Ty) const;
|
|
|
|
|
2014-11-01 01:10:41 +08:00
|
|
|
bool isHomogeneousAggregateBaseType(QualType Ty) const override;
|
|
|
|
bool isHomogeneousAggregateSmallEnough(const Type *Ty,
|
|
|
|
uint64_t Members) const override;
|
|
|
|
|
2012-10-13 03:26:17 +08:00
|
|
|
// TODO: We can add more logic to computeInfo to improve performance.
|
|
|
|
// Example: For aggregate arguments that fit in a register, we could
|
|
|
|
// use getDirectInReg (as is done below for structs containing a single
|
|
|
|
// floating-point value) to avoid pushing them to memory on function
|
|
|
|
// entry. This would require changing the logic in PPCISelLowering
|
|
|
|
// when lowering the parameters in the caller and args in the callee.
|
2014-03-12 14:41:41 +08:00
|
|
|
void computeInfo(CGFunctionInfo &FI) const override {
|
2014-05-14 06:05:45 +08:00
|
|
|
if (!getCXXABI().classifyReturnType(FI))
|
|
|
|
FI.getReturnInfo() = classifyReturnType(FI.getReturnType());
|
2014-03-18 02:10:01 +08:00
|
|
|
for (auto &I : FI.arguments()) {
|
2012-10-13 03:26:17 +08:00
|
|
|
// We rely on the default argument classification for the most part.
|
|
|
|
// One exception: An aggregate containing a single floating-point
|
2013-07-24 06:15:57 +08:00
|
|
|
// or vector item must be passed in a register if one is available.
|
2014-03-18 02:10:01 +08:00
|
|
|
const Type *T = isSingleElementStruct(I.type, getContext());
|
2012-10-13 03:26:17 +08:00
|
|
|
if (T) {
|
|
|
|
const BuiltinType *BT = T->getAs<BuiltinType>();
|
2014-07-11 00:39:01 +08:00
|
|
|
if ((T->isVectorType() && getContext().getTypeSize(T) == 128) ||
|
|
|
|
(BT && BT->isFloatingPoint())) {
|
2012-10-13 03:26:17 +08:00
|
|
|
QualType QT(T, 0);
|
2014-03-18 02:10:01 +08:00
|
|
|
I.info = ABIArgInfo::getDirectInReg(CGT.ConvertType(QT));
|
2012-10-13 03:26:17 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2014-03-18 02:10:01 +08:00
|
|
|
I.info = classifyArgumentType(I.type);
|
2012-10-13 03:26:17 +08:00
|
|
|
}
|
|
|
|
}
|
2012-10-04 03:18:57 +08:00
|
|
|
|
2014-03-12 14:41:41 +08:00
|
|
|
llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
|
|
|
|
CodeGenFunction &CGF) const override;
|
2012-10-04 03:18:57 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class PPC64_SVR4_TargetCodeGenInfo : public TargetCodeGenInfo {
|
|
|
|
public:
|
[PowerPC] Support the ELFv2 ABI
This patch implements clang support for the PowerPC ELFv2 ABI.
Together with a series of companion patches in LLVM, this makes
clang/LLVM fully usable on powerpc64le-linux.
Most of the ELFv2 ABI changes are fully implemented on the LLVM side.
On the clang side, we only need to implement some changes in how
aggregate types are passed by value. Specifically, we need to:
- pass (and return) "homogeneous" floating-point or vector aggregates in
FPRs and VRs (this is similar to the ARM homogeneous aggregate ABI)
- return aggregates of up to 16 bytes in one or two GPRs
The second piece is trivial to implement in any case. To implement
the first piece, this patch makes use of infrastructure recently
enabled in the LLVM PowerPC back-end to support passing array types
directly, where the array element type encodes properties needed to
handle homogeneous aggregates correctly.
Specifically, the array element type encodes:
- whether the parameter should be passed in FPRs, VRs, or just
GPRs/stack slots (for float / vector / integer element types,
respectively)
- what the alignment requirements of the parameter are when passed in
GPRs/stack slots (8 for float / 16 for vector / the element type
size for integer element types) -- this corresponds to the
"byval align" field
With this support in place, the clang part simply needs to *detect*
whether an aggregate type implements a float / vector homogeneous
aggregate as defined by the ELFv2 ABI, and if so, pass/return it
as array type using the appropriate float / vector element type.
llvm-svn: 213494
2014-07-21 08:48:09 +08:00
|
|
|
PPC64_SVR4_TargetCodeGenInfo(CodeGenTypes &CGT,
|
|
|
|
PPC64_SVR4_ABIInfo::ABIKind Kind)
|
|
|
|
: TargetCodeGenInfo(new PPC64_SVR4_ABIInfo(CGT, Kind)) {}
|
2012-10-04 03:18:57 +08:00
|
|
|
|
2014-03-12 14:41:41 +08:00
|
|
|
int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const override {
|
2012-10-04 03:18:57 +08:00
|
|
|
// This is recovered from gcc output.
|
|
|
|
return 1; // r1 is the dedicated stack pointer
|
|
|
|
}
|
|
|
|
|
|
|
|
bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
|
2014-03-12 14:41:41 +08:00
|
|
|
llvm::Value *Address) const override;
|
2014-10-04 01:45:20 +08:00
|
|
|
|
|
|
|
unsigned getOpenMPSimdDefaultAlignment(QualType) const override {
|
|
|
|
return 16; // Natural alignment for Altivec and VSX vectors.
|
|
|
|
}
|
2012-10-04 03:18:57 +08:00
|
|
|
};
|
|
|
|
|
2012-05-10 02:22:46 +08:00
|
|
|
class PPC64TargetCodeGenInfo : public DefaultTargetCodeGenInfo {
|
|
|
|
public:
|
|
|
|
PPC64TargetCodeGenInfo(CodeGenTypes &CGT) : DefaultTargetCodeGenInfo(CGT) {}
|
|
|
|
|
2014-03-12 14:41:41 +08:00
|
|
|
int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const override {
|
2012-05-10 02:22:46 +08:00
|
|
|
// This is recovered from gcc output.
|
|
|
|
return 1; // r1 is the dedicated stack pointer
|
|
|
|
}
|
|
|
|
|
|
|
|
bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
|
2014-03-12 14:41:41 +08:00
|
|
|
llvm::Value *Address) const override;
|
2014-10-04 01:45:20 +08:00
|
|
|
|
|
|
|
unsigned getOpenMPSimdDefaultAlignment(QualType) const override {
|
|
|
|
return 16; // Natural alignment for Altivec vectors.
|
|
|
|
}
|
2012-05-10 02:22:46 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-11-06 03:13:42 +08:00
|
|
|
// Return true if the ABI requires Ty to be passed sign- or zero-
|
|
|
|
// extended to 64 bits.
|
|
|
|
bool
|
|
|
|
PPC64_SVR4_ABIInfo::isPromotableTypeForABI(QualType Ty) const {
|
|
|
|
// Treat an enum type as its underlying type.
|
|
|
|
if (const EnumType *EnumTy = Ty->getAs<EnumType>())
|
|
|
|
Ty = EnumTy->getDecl()->getIntegerType();
|
|
|
|
|
|
|
|
// Promotable integer types are required to be promoted by the ABI.
|
|
|
|
if (Ty->isPromotableIntegerType())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// In addition to the usual promotable integer types, we also need to
|
|
|
|
// extend all 32-bit types, since the ABI requires promotion to 64 bits.
|
|
|
|
if (const BuiltinType *BT = Ty->getAs<BuiltinType>())
|
|
|
|
switch (BT->getKind()) {
|
|
|
|
case BuiltinType::Int:
|
|
|
|
case BuiltinType::UInt:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-11 01:20:07 +08:00
|
|
|
/// isAlignedParamType - Determine whether a type requires 16-byte
|
|
|
|
/// alignment in the parameter area.
|
|
|
|
bool
|
|
|
|
PPC64_SVR4_ABIInfo::isAlignedParamType(QualType Ty) const {
|
|
|
|
// Complex types are passed just like their elements.
|
|
|
|
if (const ComplexType *CTy = Ty->getAs<ComplexType>())
|
|
|
|
Ty = CTy->getElementType();
|
|
|
|
|
|
|
|
// Only vector types of size 16 bytes need alignment (larger types are
|
|
|
|
// passed via reference, smaller types are not aligned).
|
|
|
|
if (Ty->isVectorType())
|
|
|
|
return getContext().getTypeSize(Ty) == 128;
|
|
|
|
|
|
|
|
// For single-element float/vector structs, we consider the whole type
|
|
|
|
// to have the same alignment requirements as its single element.
|
|
|
|
const Type *AlignAsType = nullptr;
|
|
|
|
const Type *EltType = isSingleElementStruct(Ty, getContext());
|
|
|
|
if (EltType) {
|
|
|
|
const BuiltinType *BT = EltType->getAs<BuiltinType>();
|
|
|
|
if ((EltType->isVectorType() &&
|
|
|
|
getContext().getTypeSize(EltType) == 128) ||
|
|
|
|
(BT && BT->isFloatingPoint()))
|
|
|
|
AlignAsType = EltType;
|
|
|
|
}
|
|
|
|
|
[PowerPC] Support the ELFv2 ABI
This patch implements clang support for the PowerPC ELFv2 ABI.
Together with a series of companion patches in LLVM, this makes
clang/LLVM fully usable on powerpc64le-linux.
Most of the ELFv2 ABI changes are fully implemented on the LLVM side.
On the clang side, we only need to implement some changes in how
aggregate types are passed by value. Specifically, we need to:
- pass (and return) "homogeneous" floating-point or vector aggregates in
FPRs and VRs (this is similar to the ARM homogeneous aggregate ABI)
- return aggregates of up to 16 bytes in one or two GPRs
The second piece is trivial to implement in any case. To implement
the first piece, this patch makes use of infrastructure recently
enabled in the LLVM PowerPC back-end to support passing array types
directly, where the array element type encodes properties needed to
handle homogeneous aggregates correctly.
Specifically, the array element type encodes:
- whether the parameter should be passed in FPRs, VRs, or just
GPRs/stack slots (for float / vector / integer element types,
respectively)
- what the alignment requirements of the parameter are when passed in
GPRs/stack slots (8 for float / 16 for vector / the element type
size for integer element types) -- this corresponds to the
"byval align" field
With this support in place, the clang part simply needs to *detect*
whether an aggregate type implements a float / vector homogeneous
aggregate as defined by the ELFv2 ABI, and if so, pass/return it
as array type using the appropriate float / vector element type.
llvm-svn: 213494
2014-07-21 08:48:09 +08:00
|
|
|
// Likewise for ELFv2 homogeneous aggregates.
|
|
|
|
const Type *Base = nullptr;
|
|
|
|
uint64_t Members = 0;
|
|
|
|
if (!AlignAsType && Kind == ELFv2 &&
|
|
|
|
isAggregateTypeForABI(Ty) && isHomogeneousAggregate(Ty, Base, Members))
|
|
|
|
AlignAsType = Base;
|
|
|
|
|
2014-07-11 01:20:07 +08:00
|
|
|
// With special case aggregates, only vector base types need alignment.
|
|
|
|
if (AlignAsType)
|
|
|
|
return AlignAsType->isVectorType();
|
|
|
|
|
|
|
|
// Otherwise, we only need alignment for any aggregate type that
|
|
|
|
// has an alignment requirement of >= 16 bytes.
|
|
|
|
if (isAggregateTypeForABI(Ty) && getContext().getTypeAlign(Ty) >= 128)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
[PowerPC] Support the ELFv2 ABI
This patch implements clang support for the PowerPC ELFv2 ABI.
Together with a series of companion patches in LLVM, this makes
clang/LLVM fully usable on powerpc64le-linux.
Most of the ELFv2 ABI changes are fully implemented on the LLVM side.
On the clang side, we only need to implement some changes in how
aggregate types are passed by value. Specifically, we need to:
- pass (and return) "homogeneous" floating-point or vector aggregates in
FPRs and VRs (this is similar to the ARM homogeneous aggregate ABI)
- return aggregates of up to 16 bytes in one or two GPRs
The second piece is trivial to implement in any case. To implement
the first piece, this patch makes use of infrastructure recently
enabled in the LLVM PowerPC back-end to support passing array types
directly, where the array element type encodes properties needed to
handle homogeneous aggregates correctly.
Specifically, the array element type encodes:
- whether the parameter should be passed in FPRs, VRs, or just
GPRs/stack slots (for float / vector / integer element types,
respectively)
- what the alignment requirements of the parameter are when passed in
GPRs/stack slots (8 for float / 16 for vector / the element type
size for integer element types) -- this corresponds to the
"byval align" field
With this support in place, the clang part simply needs to *detect*
whether an aggregate type implements a float / vector homogeneous
aggregate as defined by the ELFv2 ABI, and if so, pass/return it
as array type using the appropriate float / vector element type.
llvm-svn: 213494
2014-07-21 08:48:09 +08:00
|
|
|
/// isHomogeneousAggregate - Return true if a type is an ELFv2 homogeneous
|
|
|
|
/// aggregate. Base is set to the base element type, and Members is set
|
|
|
|
/// to the number of base elements.
|
2014-11-01 01:10:41 +08:00
|
|
|
bool ABIInfo::isHomogeneousAggregate(QualType Ty, const Type *&Base,
|
|
|
|
uint64_t &Members) const {
|
[PowerPC] Support the ELFv2 ABI
This patch implements clang support for the PowerPC ELFv2 ABI.
Together with a series of companion patches in LLVM, this makes
clang/LLVM fully usable on powerpc64le-linux.
Most of the ELFv2 ABI changes are fully implemented on the LLVM side.
On the clang side, we only need to implement some changes in how
aggregate types are passed by value. Specifically, we need to:
- pass (and return) "homogeneous" floating-point or vector aggregates in
FPRs and VRs (this is similar to the ARM homogeneous aggregate ABI)
- return aggregates of up to 16 bytes in one or two GPRs
The second piece is trivial to implement in any case. To implement
the first piece, this patch makes use of infrastructure recently
enabled in the LLVM PowerPC back-end to support passing array types
directly, where the array element type encodes properties needed to
handle homogeneous aggregates correctly.
Specifically, the array element type encodes:
- whether the parameter should be passed in FPRs, VRs, or just
GPRs/stack slots (for float / vector / integer element types,
respectively)
- what the alignment requirements of the parameter are when passed in
GPRs/stack slots (8 for float / 16 for vector / the element type
size for integer element types) -- this corresponds to the
"byval align" field
With this support in place, the clang part simply needs to *detect*
whether an aggregate type implements a float / vector homogeneous
aggregate as defined by the ELFv2 ABI, and if so, pass/return it
as array type using the appropriate float / vector element type.
llvm-svn: 213494
2014-07-21 08:48:09 +08:00
|
|
|
if (const ConstantArrayType *AT = getContext().getAsConstantArrayType(Ty)) {
|
|
|
|
uint64_t NElements = AT->getSize().getZExtValue();
|
|
|
|
if (NElements == 0)
|
|
|
|
return false;
|
|
|
|
if (!isHomogeneousAggregate(AT->getElementType(), Base, Members))
|
|
|
|
return false;
|
|
|
|
Members *= NElements;
|
|
|
|
} else if (const RecordType *RT = Ty->getAs<RecordType>()) {
|
|
|
|
const RecordDecl *RD = RT->getDecl();
|
|
|
|
if (RD->hasFlexibleArrayMember())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
Members = 0;
|
2014-10-29 21:23:20 +08:00
|
|
|
|
|
|
|
// If this is a C++ record, check the bases first.
|
|
|
|
if (const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
|
|
|
|
for (const auto &I : CXXRD->bases()) {
|
|
|
|
// Ignore empty records.
|
|
|
|
if (isEmptyRecord(getContext(), I.getType(), true))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
uint64_t FldMembers;
|
|
|
|
if (!isHomogeneousAggregate(I.getType(), Base, FldMembers))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
Members += FldMembers;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
[PowerPC] Support the ELFv2 ABI
This patch implements clang support for the PowerPC ELFv2 ABI.
Together with a series of companion patches in LLVM, this makes
clang/LLVM fully usable on powerpc64le-linux.
Most of the ELFv2 ABI changes are fully implemented on the LLVM side.
On the clang side, we only need to implement some changes in how
aggregate types are passed by value. Specifically, we need to:
- pass (and return) "homogeneous" floating-point or vector aggregates in
FPRs and VRs (this is similar to the ARM homogeneous aggregate ABI)
- return aggregates of up to 16 bytes in one or two GPRs
The second piece is trivial to implement in any case. To implement
the first piece, this patch makes use of infrastructure recently
enabled in the LLVM PowerPC back-end to support passing array types
directly, where the array element type encodes properties needed to
handle homogeneous aggregates correctly.
Specifically, the array element type encodes:
- whether the parameter should be passed in FPRs, VRs, or just
GPRs/stack slots (for float / vector / integer element types,
respectively)
- what the alignment requirements of the parameter are when passed in
GPRs/stack slots (8 for float / 16 for vector / the element type
size for integer element types) -- this corresponds to the
"byval align" field
With this support in place, the clang part simply needs to *detect*
whether an aggregate type implements a float / vector homogeneous
aggregate as defined by the ELFv2 ABI, and if so, pass/return it
as array type using the appropriate float / vector element type.
llvm-svn: 213494
2014-07-21 08:48:09 +08:00
|
|
|
for (const auto *FD : RD->fields()) {
|
|
|
|
// Ignore (non-zero arrays of) empty records.
|
|
|
|
QualType FT = FD->getType();
|
|
|
|
while (const ConstantArrayType *AT =
|
|
|
|
getContext().getAsConstantArrayType(FT)) {
|
|
|
|
if (AT->getSize().getZExtValue() == 0)
|
|
|
|
return false;
|
|
|
|
FT = AT->getElementType();
|
|
|
|
}
|
|
|
|
if (isEmptyRecord(getContext(), FT, true))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// For compatibility with GCC, ignore empty bitfields in C++ mode.
|
|
|
|
if (getContext().getLangOpts().CPlusPlus &&
|
|
|
|
FD->isBitField() && FD->getBitWidthValue(getContext()) == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
uint64_t FldMembers;
|
|
|
|
if (!isHomogeneousAggregate(FD->getType(), Base, FldMembers))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
Members = (RD->isUnion() ?
|
|
|
|
std::max(Members, FldMembers) : Members + FldMembers);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Base)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Ensure there is no padding.
|
|
|
|
if (getContext().getTypeSize(Base) * Members !=
|
|
|
|
getContext().getTypeSize(Ty))
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
Members = 1;
|
|
|
|
if (const ComplexType *CT = Ty->getAs<ComplexType>()) {
|
|
|
|
Members = 2;
|
|
|
|
Ty = CT->getElementType();
|
|
|
|
}
|
|
|
|
|
2014-11-01 01:10:41 +08:00
|
|
|
// Most ABIs only support float, double, and some vector type widths.
|
|
|
|
if (!isHomogeneousAggregateBaseType(Ty))
|
[PowerPC] Support the ELFv2 ABI
This patch implements clang support for the PowerPC ELFv2 ABI.
Together with a series of companion patches in LLVM, this makes
clang/LLVM fully usable on powerpc64le-linux.
Most of the ELFv2 ABI changes are fully implemented on the LLVM side.
On the clang side, we only need to implement some changes in how
aggregate types are passed by value. Specifically, we need to:
- pass (and return) "homogeneous" floating-point or vector aggregates in
FPRs and VRs (this is similar to the ARM homogeneous aggregate ABI)
- return aggregates of up to 16 bytes in one or two GPRs
The second piece is trivial to implement in any case. To implement
the first piece, this patch makes use of infrastructure recently
enabled in the LLVM PowerPC back-end to support passing array types
directly, where the array element type encodes properties needed to
handle homogeneous aggregates correctly.
Specifically, the array element type encodes:
- whether the parameter should be passed in FPRs, VRs, or just
GPRs/stack slots (for float / vector / integer element types,
respectively)
- what the alignment requirements of the parameter are when passed in
GPRs/stack slots (8 for float / 16 for vector / the element type
size for integer element types) -- this corresponds to the
"byval align" field
With this support in place, the clang part simply needs to *detect*
whether an aggregate type implements a float / vector homogeneous
aggregate as defined by the ELFv2 ABI, and if so, pass/return it
as array type using the appropriate float / vector element type.
llvm-svn: 213494
2014-07-21 08:48:09 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// The base type must be the same for all members. Types that
|
|
|
|
// agree in both total size and mode (float vs. vector) are
|
|
|
|
// treated as being equivalent here.
|
|
|
|
const Type *TyPtr = Ty.getTypePtr();
|
|
|
|
if (!Base)
|
|
|
|
Base = TyPtr;
|
|
|
|
|
|
|
|
if (Base->isVectorType() != TyPtr->isVectorType() ||
|
|
|
|
getContext().getTypeSize(Base) != getContext().getTypeSize(TyPtr))
|
|
|
|
return false;
|
|
|
|
}
|
2014-11-01 01:10:41 +08:00
|
|
|
return Members > 0 && isHomogeneousAggregateSmallEnough(Base, Members);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PPC64_SVR4_ABIInfo::isHomogeneousAggregateBaseType(QualType Ty) const {
|
|
|
|
// Homogeneous aggregates for ELFv2 must have base types of float,
|
|
|
|
// double, long double, or 128-bit vectors.
|
|
|
|
if (const BuiltinType *BT = Ty->getAs<BuiltinType>()) {
|
|
|
|
if (BT->getKind() == BuiltinType::Float ||
|
|
|
|
BT->getKind() == BuiltinType::Double ||
|
|
|
|
BT->getKind() == BuiltinType::LongDouble)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (const VectorType *VT = Ty->getAs<VectorType>()) {
|
|
|
|
if (getContext().getTypeSize(VT) == 128)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
[PowerPC] Support the ELFv2 ABI
This patch implements clang support for the PowerPC ELFv2 ABI.
Together with a series of companion patches in LLVM, this makes
clang/LLVM fully usable on powerpc64le-linux.
Most of the ELFv2 ABI changes are fully implemented on the LLVM side.
On the clang side, we only need to implement some changes in how
aggregate types are passed by value. Specifically, we need to:
- pass (and return) "homogeneous" floating-point or vector aggregates in
FPRs and VRs (this is similar to the ARM homogeneous aggregate ABI)
- return aggregates of up to 16 bytes in one or two GPRs
The second piece is trivial to implement in any case. To implement
the first piece, this patch makes use of infrastructure recently
enabled in the LLVM PowerPC back-end to support passing array types
directly, where the array element type encodes properties needed to
handle homogeneous aggregates correctly.
Specifically, the array element type encodes:
- whether the parameter should be passed in FPRs, VRs, or just
GPRs/stack slots (for float / vector / integer element types,
respectively)
- what the alignment requirements of the parameter are when passed in
GPRs/stack slots (8 for float / 16 for vector / the element type
size for integer element types) -- this corresponds to the
"byval align" field
With this support in place, the clang part simply needs to *detect*
whether an aggregate type implements a float / vector homogeneous
aggregate as defined by the ELFv2 ABI, and if so, pass/return it
as array type using the appropriate float / vector element type.
llvm-svn: 213494
2014-07-21 08:48:09 +08:00
|
|
|
|
2014-11-01 01:10:41 +08:00
|
|
|
bool PPC64_SVR4_ABIInfo::isHomogeneousAggregateSmallEnough(
|
|
|
|
const Type *Base, uint64_t Members) const {
|
[PowerPC] Support the ELFv2 ABI
This patch implements clang support for the PowerPC ELFv2 ABI.
Together with a series of companion patches in LLVM, this makes
clang/LLVM fully usable on powerpc64le-linux.
Most of the ELFv2 ABI changes are fully implemented on the LLVM side.
On the clang side, we only need to implement some changes in how
aggregate types are passed by value. Specifically, we need to:
- pass (and return) "homogeneous" floating-point or vector aggregates in
FPRs and VRs (this is similar to the ARM homogeneous aggregate ABI)
- return aggregates of up to 16 bytes in one or two GPRs
The second piece is trivial to implement in any case. To implement
the first piece, this patch makes use of infrastructure recently
enabled in the LLVM PowerPC back-end to support passing array types
directly, where the array element type encodes properties needed to
handle homogeneous aggregates correctly.
Specifically, the array element type encodes:
- whether the parameter should be passed in FPRs, VRs, or just
GPRs/stack slots (for float / vector / integer element types,
respectively)
- what the alignment requirements of the parameter are when passed in
GPRs/stack slots (8 for float / 16 for vector / the element type
size for integer element types) -- this corresponds to the
"byval align" field
With this support in place, the clang part simply needs to *detect*
whether an aggregate type implements a float / vector homogeneous
aggregate as defined by the ELFv2 ABI, and if so, pass/return it
as array type using the appropriate float / vector element type.
llvm-svn: 213494
2014-07-21 08:48:09 +08:00
|
|
|
// Vector types require one register, floating point types require one
|
|
|
|
// or two registers depending on their size.
|
2014-11-01 01:10:41 +08:00
|
|
|
uint32_t NumRegs =
|
|
|
|
Base->isVectorType() ? 1 : (getContext().getTypeSize(Base) + 63) / 64;
|
[PowerPC] Support the ELFv2 ABI
This patch implements clang support for the PowerPC ELFv2 ABI.
Together with a series of companion patches in LLVM, this makes
clang/LLVM fully usable on powerpc64le-linux.
Most of the ELFv2 ABI changes are fully implemented on the LLVM side.
On the clang side, we only need to implement some changes in how
aggregate types are passed by value. Specifically, we need to:
- pass (and return) "homogeneous" floating-point or vector aggregates in
FPRs and VRs (this is similar to the ARM homogeneous aggregate ABI)
- return aggregates of up to 16 bytes in one or two GPRs
The second piece is trivial to implement in any case. To implement
the first piece, this patch makes use of infrastructure recently
enabled in the LLVM PowerPC back-end to support passing array types
directly, where the array element type encodes properties needed to
handle homogeneous aggregates correctly.
Specifically, the array element type encodes:
- whether the parameter should be passed in FPRs, VRs, or just
GPRs/stack slots (for float / vector / integer element types,
respectively)
- what the alignment requirements of the parameter are when passed in
GPRs/stack slots (8 for float / 16 for vector / the element type
size for integer element types) -- this corresponds to the
"byval align" field
With this support in place, the clang part simply needs to *detect*
whether an aggregate type implements a float / vector homogeneous
aggregate as defined by the ELFv2 ABI, and if so, pass/return it
as array type using the appropriate float / vector element type.
llvm-svn: 213494
2014-07-21 08:48:09 +08:00
|
|
|
|
|
|
|
// Homogeneous Aggregates may occupy at most 8 registers.
|
2014-11-01 01:10:41 +08:00
|
|
|
return Members * NumRegs <= 8;
|
[PowerPC] Support the ELFv2 ABI
This patch implements clang support for the PowerPC ELFv2 ABI.
Together with a series of companion patches in LLVM, this makes
clang/LLVM fully usable on powerpc64le-linux.
Most of the ELFv2 ABI changes are fully implemented on the LLVM side.
On the clang side, we only need to implement some changes in how
aggregate types are passed by value. Specifically, we need to:
- pass (and return) "homogeneous" floating-point or vector aggregates in
FPRs and VRs (this is similar to the ARM homogeneous aggregate ABI)
- return aggregates of up to 16 bytes in one or two GPRs
The second piece is trivial to implement in any case. To implement
the first piece, this patch makes use of infrastructure recently
enabled in the LLVM PowerPC back-end to support passing array types
directly, where the array element type encodes properties needed to
handle homogeneous aggregates correctly.
Specifically, the array element type encodes:
- whether the parameter should be passed in FPRs, VRs, or just
GPRs/stack slots (for float / vector / integer element types,
respectively)
- what the alignment requirements of the parameter are when passed in
GPRs/stack slots (8 for float / 16 for vector / the element type
size for integer element types) -- this corresponds to the
"byval align" field
With this support in place, the clang part simply needs to *detect*
whether an aggregate type implements a float / vector homogeneous
aggregate as defined by the ELFv2 ABI, and if so, pass/return it
as array type using the appropriate float / vector element type.
llvm-svn: 213494
2014-07-21 08:48:09 +08:00
|
|
|
}
|
|
|
|
|
2012-11-06 03:13:42 +08:00
|
|
|
ABIArgInfo
|
|
|
|
PPC64_SVR4_ABIInfo::classifyArgumentType(QualType Ty) const {
|
2014-11-15 09:41:41 +08:00
|
|
|
Ty = useFirstFieldIfTransparentUnion(Ty);
|
|
|
|
|
2012-11-27 10:46:43 +08:00
|
|
|
if (Ty->isAnyComplexType())
|
|
|
|
return ABIArgInfo::getDirect();
|
|
|
|
|
2014-07-11 00:39:01 +08:00
|
|
|
// Non-Altivec vector types are passed in GPRs (smaller than 16 bytes)
|
|
|
|
// or via reference (larger than 16 bytes).
|
|
|
|
if (Ty->isVectorType()) {
|
|
|
|
uint64_t Size = getContext().getTypeSize(Ty);
|
|
|
|
if (Size > 128)
|
|
|
|
return ABIArgInfo::getIndirect(0, /*ByVal=*/false);
|
|
|
|
else if (Size < 128) {
|
|
|
|
llvm::Type *CoerceTy = llvm::IntegerType::get(getVMContext(), Size);
|
|
|
|
return ABIArgInfo::getDirect(CoerceTy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-06 03:13:42 +08:00
|
|
|
if (isAggregateTypeForABI(Ty)) {
|
2013-10-06 09:33:34 +08:00
|
|
|
if (CGCXXABI::RecordArgABI RAA = getRecordArgABI(Ty, getCXXABI()))
|
2013-04-17 20:54:10 +08:00
|
|
|
return ABIArgInfo::getIndirect(0, RAA == CGCXXABI::RAA_DirectInMemory);
|
2012-11-06 03:13:42 +08:00
|
|
|
|
2014-07-11 01:20:07 +08:00
|
|
|
uint64_t ABIAlign = isAlignedParamType(Ty)? 16 : 8;
|
|
|
|
uint64_t TyAlign = getContext().getTypeAlign(Ty) / 8;
|
[PowerPC] Support the ELFv2 ABI
This patch implements clang support for the PowerPC ELFv2 ABI.
Together with a series of companion patches in LLVM, this makes
clang/LLVM fully usable on powerpc64le-linux.
Most of the ELFv2 ABI changes are fully implemented on the LLVM side.
On the clang side, we only need to implement some changes in how
aggregate types are passed by value. Specifically, we need to:
- pass (and return) "homogeneous" floating-point or vector aggregates in
FPRs and VRs (this is similar to the ARM homogeneous aggregate ABI)
- return aggregates of up to 16 bytes in one or two GPRs
The second piece is trivial to implement in any case. To implement
the first piece, this patch makes use of infrastructure recently
enabled in the LLVM PowerPC back-end to support passing array types
directly, where the array element type encodes properties needed to
handle homogeneous aggregates correctly.
Specifically, the array element type encodes:
- whether the parameter should be passed in FPRs, VRs, or just
GPRs/stack slots (for float / vector / integer element types,
respectively)
- what the alignment requirements of the parameter are when passed in
GPRs/stack slots (8 for float / 16 for vector / the element type
size for integer element types) -- this corresponds to the
"byval align" field
With this support in place, the clang part simply needs to *detect*
whether an aggregate type implements a float / vector homogeneous
aggregate as defined by the ELFv2 ABI, and if so, pass/return it
as array type using the appropriate float / vector element type.
llvm-svn: 213494
2014-07-21 08:48:09 +08:00
|
|
|
|
|
|
|
// ELFv2 homogeneous aggregates are passed as array types.
|
|
|
|
const Type *Base = nullptr;
|
|
|
|
uint64_t Members = 0;
|
|
|
|
if (Kind == ELFv2 &&
|
|
|
|
isHomogeneousAggregate(Ty, Base, Members)) {
|
|
|
|
llvm::Type *BaseTy = CGT.ConvertType(QualType(Base, 0));
|
|
|
|
llvm::Type *CoerceTy = llvm::ArrayType::get(BaseTy, Members);
|
|
|
|
return ABIArgInfo::getDirect(CoerceTy);
|
2014-07-21 08:56:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// If an aggregate may end up fully in registers, we do not
|
|
|
|
// use the ByVal method, but pass the aggregate as array.
|
|
|
|
// This is usually beneficial since we avoid forcing the
|
|
|
|
// back-end to store the argument to memory.
|
|
|
|
uint64_t Bits = getContext().getTypeSize(Ty);
|
|
|
|
if (Bits > 0 && Bits <= 8 * GPRBits) {
|
|
|
|
llvm::Type *CoerceTy;
|
|
|
|
|
|
|
|
// Types up to 8 bytes are passed as integer type (which will be
|
|
|
|
// properly aligned in the argument save area doubleword).
|
|
|
|
if (Bits <= GPRBits)
|
|
|
|
CoerceTy = llvm::IntegerType::get(getVMContext(),
|
|
|
|
llvm::RoundUpToAlignment(Bits, 8));
|
|
|
|
// Larger types are passed as arrays, with the base type selected
|
|
|
|
// according to the required alignment in the save area.
|
|
|
|
else {
|
|
|
|
uint64_t RegBits = ABIAlign * 8;
|
|
|
|
uint64_t NumRegs = llvm::RoundUpToAlignment(Bits, RegBits) / RegBits;
|
|
|
|
llvm::Type *RegTy = llvm::IntegerType::get(getVMContext(), RegBits);
|
|
|
|
CoerceTy = llvm::ArrayType::get(RegTy, NumRegs);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ABIArgInfo::getDirect(CoerceTy);
|
[PowerPC] Support the ELFv2 ABI
This patch implements clang support for the PowerPC ELFv2 ABI.
Together with a series of companion patches in LLVM, this makes
clang/LLVM fully usable on powerpc64le-linux.
Most of the ELFv2 ABI changes are fully implemented on the LLVM side.
On the clang side, we only need to implement some changes in how
aggregate types are passed by value. Specifically, we need to:
- pass (and return) "homogeneous" floating-point or vector aggregates in
FPRs and VRs (this is similar to the ARM homogeneous aggregate ABI)
- return aggregates of up to 16 bytes in one or two GPRs
The second piece is trivial to implement in any case. To implement
the first piece, this patch makes use of infrastructure recently
enabled in the LLVM PowerPC back-end to support passing array types
directly, where the array element type encodes properties needed to
handle homogeneous aggregates correctly.
Specifically, the array element type encodes:
- whether the parameter should be passed in FPRs, VRs, or just
GPRs/stack slots (for float / vector / integer element types,
respectively)
- what the alignment requirements of the parameter are when passed in
GPRs/stack slots (8 for float / 16 for vector / the element type
size for integer element types) -- this corresponds to the
"byval align" field
With this support in place, the clang part simply needs to *detect*
whether an aggregate type implements a float / vector homogeneous
aggregate as defined by the ELFv2 ABI, and if so, pass/return it
as array type using the appropriate float / vector element type.
llvm-svn: 213494
2014-07-21 08:48:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// All other aggregates are passed ByVal.
|
2014-07-11 01:20:07 +08:00
|
|
|
return ABIArgInfo::getIndirect(ABIAlign, /*ByVal=*/true,
|
|
|
|
/*Realign=*/TyAlign > ABIAlign);
|
2012-11-06 03:13:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return (isPromotableTypeForABI(Ty) ?
|
|
|
|
ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
|
|
|
|
}
|
|
|
|
|
|
|
|
ABIArgInfo
|
|
|
|
PPC64_SVR4_ABIInfo::classifyReturnType(QualType RetTy) const {
|
|
|
|
if (RetTy->isVoidType())
|
|
|
|
return ABIArgInfo::getIgnore();
|
|
|
|
|
2012-12-17 12:20:17 +08:00
|
|
|
if (RetTy->isAnyComplexType())
|
|
|
|
return ABIArgInfo::getDirect();
|
|
|
|
|
2014-07-11 00:39:01 +08:00
|
|
|
// Non-Altivec vector types are returned in GPRs (smaller than 16 bytes)
|
|
|
|
// or via reference (larger than 16 bytes).
|
|
|
|
if (RetTy->isVectorType()) {
|
|
|
|
uint64_t Size = getContext().getTypeSize(RetTy);
|
|
|
|
if (Size > 128)
|
|
|
|
return ABIArgInfo::getIndirect(0);
|
|
|
|
else if (Size < 128) {
|
|
|
|
llvm::Type *CoerceTy = llvm::IntegerType::get(getVMContext(), Size);
|
|
|
|
return ABIArgInfo::getDirect(CoerceTy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
[PowerPC] Support the ELFv2 ABI
This patch implements clang support for the PowerPC ELFv2 ABI.
Together with a series of companion patches in LLVM, this makes
clang/LLVM fully usable on powerpc64le-linux.
Most of the ELFv2 ABI changes are fully implemented on the LLVM side.
On the clang side, we only need to implement some changes in how
aggregate types are passed by value. Specifically, we need to:
- pass (and return) "homogeneous" floating-point or vector aggregates in
FPRs and VRs (this is similar to the ARM homogeneous aggregate ABI)
- return aggregates of up to 16 bytes in one or two GPRs
The second piece is trivial to implement in any case. To implement
the first piece, this patch makes use of infrastructure recently
enabled in the LLVM PowerPC back-end to support passing array types
directly, where the array element type encodes properties needed to
handle homogeneous aggregates correctly.
Specifically, the array element type encodes:
- whether the parameter should be passed in FPRs, VRs, or just
GPRs/stack slots (for float / vector / integer element types,
respectively)
- what the alignment requirements of the parameter are when passed in
GPRs/stack slots (8 for float / 16 for vector / the element type
size for integer element types) -- this corresponds to the
"byval align" field
With this support in place, the clang part simply needs to *detect*
whether an aggregate type implements a float / vector homogeneous
aggregate as defined by the ELFv2 ABI, and if so, pass/return it
as array type using the appropriate float / vector element type.
llvm-svn: 213494
2014-07-21 08:48:09 +08:00
|
|
|
if (isAggregateTypeForABI(RetTy)) {
|
|
|
|
// ELFv2 homogeneous aggregates are returned as array types.
|
|
|
|
const Type *Base = nullptr;
|
|
|
|
uint64_t Members = 0;
|
|
|
|
if (Kind == ELFv2 &&
|
|
|
|
isHomogeneousAggregate(RetTy, Base, Members)) {
|
|
|
|
llvm::Type *BaseTy = CGT.ConvertType(QualType(Base, 0));
|
|
|
|
llvm::Type *CoerceTy = llvm::ArrayType::get(BaseTy, Members);
|
|
|
|
return ABIArgInfo::getDirect(CoerceTy);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ELFv2 small aggregates are returned in up to two registers.
|
|
|
|
uint64_t Bits = getContext().getTypeSize(RetTy);
|
|
|
|
if (Kind == ELFv2 && Bits <= 2 * GPRBits) {
|
|
|
|
if (Bits == 0)
|
|
|
|
return ABIArgInfo::getIgnore();
|
|
|
|
|
|
|
|
llvm::Type *CoerceTy;
|
|
|
|
if (Bits > GPRBits) {
|
|
|
|
CoerceTy = llvm::IntegerType::get(getVMContext(), GPRBits);
|
2014-12-02 06:02:27 +08:00
|
|
|
CoerceTy = llvm::StructType::get(CoerceTy, CoerceTy, nullptr);
|
[PowerPC] Support the ELFv2 ABI
This patch implements clang support for the PowerPC ELFv2 ABI.
Together with a series of companion patches in LLVM, this makes
clang/LLVM fully usable on powerpc64le-linux.
Most of the ELFv2 ABI changes are fully implemented on the LLVM side.
On the clang side, we only need to implement some changes in how
aggregate types are passed by value. Specifically, we need to:
- pass (and return) "homogeneous" floating-point or vector aggregates in
FPRs and VRs (this is similar to the ARM homogeneous aggregate ABI)
- return aggregates of up to 16 bytes in one or two GPRs
The second piece is trivial to implement in any case. To implement
the first piece, this patch makes use of infrastructure recently
enabled in the LLVM PowerPC back-end to support passing array types
directly, where the array element type encodes properties needed to
handle homogeneous aggregates correctly.
Specifically, the array element type encodes:
- whether the parameter should be passed in FPRs, VRs, or just
GPRs/stack slots (for float / vector / integer element types,
respectively)
- what the alignment requirements of the parameter are when passed in
GPRs/stack slots (8 for float / 16 for vector / the element type
size for integer element types) -- this corresponds to the
"byval align" field
With this support in place, the clang part simply needs to *detect*
whether an aggregate type implements a float / vector homogeneous
aggregate as defined by the ELFv2 ABI, and if so, pass/return it
as array type using the appropriate float / vector element type.
llvm-svn: 213494
2014-07-21 08:48:09 +08:00
|
|
|
} else
|
|
|
|
CoerceTy = llvm::IntegerType::get(getVMContext(),
|
|
|
|
llvm::RoundUpToAlignment(Bits, 8));
|
|
|
|
return ABIArgInfo::getDirect(CoerceTy);
|
|
|
|
}
|
|
|
|
|
|
|
|
// All other aggregates are returned indirectly.
|
2012-11-06 03:13:42 +08:00
|
|
|
return ABIArgInfo::getIndirect(0);
|
[PowerPC] Support the ELFv2 ABI
This patch implements clang support for the PowerPC ELFv2 ABI.
Together with a series of companion patches in LLVM, this makes
clang/LLVM fully usable on powerpc64le-linux.
Most of the ELFv2 ABI changes are fully implemented on the LLVM side.
On the clang side, we only need to implement some changes in how
aggregate types are passed by value. Specifically, we need to:
- pass (and return) "homogeneous" floating-point or vector aggregates in
FPRs and VRs (this is similar to the ARM homogeneous aggregate ABI)
- return aggregates of up to 16 bytes in one or two GPRs
The second piece is trivial to implement in any case. To implement
the first piece, this patch makes use of infrastructure recently
enabled in the LLVM PowerPC back-end to support passing array types
directly, where the array element type encodes properties needed to
handle homogeneous aggregates correctly.
Specifically, the array element type encodes:
- whether the parameter should be passed in FPRs, VRs, or just
GPRs/stack slots (for float / vector / integer element types,
respectively)
- what the alignment requirements of the parameter are when passed in
GPRs/stack slots (8 for float / 16 for vector / the element type
size for integer element types) -- this corresponds to the
"byval align" field
With this support in place, the clang part simply needs to *detect*
whether an aggregate type implements a float / vector homogeneous
aggregate as defined by the ELFv2 ABI, and if so, pass/return it
as array type using the appropriate float / vector element type.
llvm-svn: 213494
2014-07-21 08:48:09 +08:00
|
|
|
}
|
2012-11-06 03:13:42 +08:00
|
|
|
|
|
|
|
return (isPromotableTypeForABI(RetTy) ?
|
|
|
|
ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
|
|
|
|
}
|
|
|
|
|
2012-10-04 03:18:57 +08:00
|
|
|
// Based on ARMABIInfo::EmitVAArg, adjusted for 64-bit machine.
|
|
|
|
llvm::Value *PPC64_SVR4_ABIInfo::EmitVAArg(llvm::Value *VAListAddr,
|
|
|
|
QualType Ty,
|
|
|
|
CodeGenFunction &CGF) const {
|
|
|
|
llvm::Type *BP = CGF.Int8PtrTy;
|
|
|
|
llvm::Type *BPP = CGF.Int8PtrPtrTy;
|
|
|
|
|
|
|
|
CGBuilderTy &Builder = CGF.Builder;
|
|
|
|
llvm::Value *VAListAddrAsBPP = Builder.CreateBitCast(VAListAddr, BPP, "ap");
|
|
|
|
llvm::Value *Addr = Builder.CreateLoad(VAListAddrAsBPP, "ap.cur");
|
|
|
|
|
2014-07-11 01:20:07 +08:00
|
|
|
// Handle types that require 16-byte alignment in the parameter save area.
|
|
|
|
if (isAlignedParamType(Ty)) {
|
|
|
|
llvm::Value *AddrAsInt = Builder.CreatePtrToInt(Addr, CGF.Int64Ty);
|
|
|
|
AddrAsInt = Builder.CreateAdd(AddrAsInt, Builder.getInt64(15));
|
|
|
|
AddrAsInt = Builder.CreateAnd(AddrAsInt, Builder.getInt64(-16));
|
|
|
|
Addr = Builder.CreateIntToPtr(AddrAsInt, BP, "ap.align");
|
|
|
|
}
|
|
|
|
|
2013-01-15 01:45:36 +08:00
|
|
|
// Update the va_list pointer. The pointer should be bumped by the
|
|
|
|
// size of the object. We can trust getTypeSize() except for a complex
|
|
|
|
// type whose base type is smaller than a doubleword. For these, the
|
|
|
|
// size of the object is 16 bytes; see below for further explanation.
|
2012-10-04 03:18:57 +08:00
|
|
|
unsigned SizeInBytes = CGF.getContext().getTypeSize(Ty) / 8;
|
2013-01-15 01:45:36 +08:00
|
|
|
QualType BaseTy;
|
|
|
|
unsigned CplxBaseSize = 0;
|
|
|
|
|
|
|
|
if (const ComplexType *CTy = Ty->getAs<ComplexType>()) {
|
|
|
|
BaseTy = CTy->getElementType();
|
|
|
|
CplxBaseSize = CGF.getContext().getTypeSize(BaseTy) / 8;
|
|
|
|
if (CplxBaseSize < 8)
|
|
|
|
SizeInBytes = 16;
|
|
|
|
}
|
|
|
|
|
2012-10-04 03:18:57 +08:00
|
|
|
unsigned Offset = llvm::RoundUpToAlignment(SizeInBytes, 8);
|
|
|
|
llvm::Value *NextAddr =
|
|
|
|
Builder.CreateGEP(Addr, llvm::ConstantInt::get(CGF.Int64Ty, Offset),
|
|
|
|
"ap.next");
|
|
|
|
Builder.CreateStore(NextAddr, VAListAddrAsBPP);
|
|
|
|
|
2013-01-15 01:45:36 +08:00
|
|
|
// If we have a complex type and the base type is smaller than 8 bytes,
|
|
|
|
// the ABI calls for the real and imaginary parts to be right-adjusted
|
|
|
|
// in separate doublewords. However, Clang expects us to produce a
|
|
|
|
// pointer to a structure with the two parts packed tightly. So generate
|
|
|
|
// loads of the real and imaginary parts relative to the va_list pointer,
|
|
|
|
// and store them to a temporary structure.
|
|
|
|
if (CplxBaseSize && CplxBaseSize < 8) {
|
|
|
|
llvm::Value *RealAddr = Builder.CreatePtrToInt(Addr, CGF.Int64Ty);
|
|
|
|
llvm::Value *ImagAddr = RealAddr;
|
2014-06-21 00:37:40 +08:00
|
|
|
if (CGF.CGM.getDataLayout().isBigEndian()) {
|
|
|
|
RealAddr = Builder.CreateAdd(RealAddr, Builder.getInt64(8 - CplxBaseSize));
|
|
|
|
ImagAddr = Builder.CreateAdd(ImagAddr, Builder.getInt64(16 - CplxBaseSize));
|
|
|
|
} else {
|
|
|
|
ImagAddr = Builder.CreateAdd(ImagAddr, Builder.getInt64(8));
|
|
|
|
}
|
2013-01-15 01:45:36 +08:00
|
|
|
llvm::Type *PBaseTy = llvm::PointerType::getUnqual(CGF.ConvertType(BaseTy));
|
|
|
|
RealAddr = Builder.CreateIntToPtr(RealAddr, PBaseTy);
|
|
|
|
ImagAddr = Builder.CreateIntToPtr(ImagAddr, PBaseTy);
|
|
|
|
llvm::Value *Real = Builder.CreateLoad(RealAddr, false, ".vareal");
|
|
|
|
llvm::Value *Imag = Builder.CreateLoad(ImagAddr, false, ".vaimag");
|
|
|
|
llvm::Value *Ptr = CGF.CreateTempAlloca(CGT.ConvertTypeForMem(Ty),
|
|
|
|
"vacplx");
|
|
|
|
llvm::Value *RealPtr = Builder.CreateStructGEP(Ptr, 0, ".real");
|
|
|
|
llvm::Value *ImagPtr = Builder.CreateStructGEP(Ptr, 1, ".imag");
|
|
|
|
Builder.CreateStore(Real, RealPtr, false);
|
|
|
|
Builder.CreateStore(Imag, ImagPtr, false);
|
|
|
|
return Ptr;
|
|
|
|
}
|
|
|
|
|
2012-10-04 03:18:57 +08:00
|
|
|
// If the argument is smaller than 8 bytes, it is right-adjusted in
|
|
|
|
// its doubleword slot. Adjust the pointer to pick it up from the
|
|
|
|
// correct offset.
|
2014-06-21 00:37:40 +08:00
|
|
|
if (SizeInBytes < 8 && CGF.CGM.getDataLayout().isBigEndian()) {
|
2012-10-04 03:18:57 +08:00
|
|
|
llvm::Value *AddrAsInt = Builder.CreatePtrToInt(Addr, CGF.Int64Ty);
|
|
|
|
AddrAsInt = Builder.CreateAdd(AddrAsInt, Builder.getInt64(8 - SizeInBytes));
|
|
|
|
Addr = Builder.CreateIntToPtr(AddrAsInt, BP);
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::Type *PTy = llvm::PointerType::getUnqual(CGF.ConvertType(Ty));
|
|
|
|
return Builder.CreateBitCast(Addr, PTy);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
PPC64_initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
|
|
|
|
llvm::Value *Address) {
|
2012-05-10 02:22:46 +08:00
|
|
|
// 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::IntegerType *i8 = CGF.Int8Ty;
|
|
|
|
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 8-byte general-purpose registers
|
|
|
|
AssignToArrayRange(Builder, Address, Eight8, 0, 31);
|
|
|
|
|
|
|
|
// 32-63: fp0-31, the 8-byte floating-point registers
|
|
|
|
AssignToArrayRange(Builder, Address, Eight8, 32, 63);
|
|
|
|
|
|
|
|
// 64-76 are various 4-byte special-purpose registers:
|
|
|
|
// 64: mq
|
|
|
|
// 65: lr
|
|
|
|
// 66: ctr
|
|
|
|
// 67: ap
|
|
|
|
// 68-75 cr0-7
|
|
|
|
// 76: xer
|
|
|
|
AssignToArrayRange(Builder, Address, Four8, 64, 76);
|
|
|
|
|
|
|
|
// 77-108: v0-31, the 16-byte vector registers
|
|
|
|
AssignToArrayRange(Builder, Address, Sixteen8, 77, 108);
|
|
|
|
|
|
|
|
// 109: vrsave
|
|
|
|
// 110: vscr
|
|
|
|
// 111: spe_acc
|
|
|
|
// 112: spefscr
|
|
|
|
// 113: sfp
|
|
|
|
AssignToArrayRange(Builder, Address, Four8, 109, 113);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2010-03-11 08:10:12 +08:00
|
|
|
|
2012-10-04 03:18:57 +08:00
|
|
|
bool
|
|
|
|
PPC64_SVR4_TargetCodeGenInfo::initDwarfEHRegSizeTable(
|
|
|
|
CodeGen::CodeGenFunction &CGF,
|
|
|
|
llvm::Value *Address) const {
|
|
|
|
|
|
|
|
return PPC64_initDwarfEHRegSizeTable(CGF, Address);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
PPC64TargetCodeGenInfo::initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
|
|
|
|
llvm::Value *Address) const {
|
|
|
|
|
|
|
|
return PPC64_initDwarfEHRegSizeTable(CGF, Address);
|
|
|
|
}
|
|
|
|
|
2014-03-29 23:09:45 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2014-05-24 20:52:07 +08:00
|
|
|
// AArch64 ABI Implementation
|
2014-03-29 23:09:45 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2014-05-24 20:52:07 +08:00
|
|
|
class AArch64ABIInfo : public ABIInfo {
|
2014-03-29 23:09:45 +08:00
|
|
|
public:
|
|
|
|
enum ABIKind {
|
|
|
|
AAPCS = 0,
|
|
|
|
DarwinPCS
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
ABIKind Kind;
|
|
|
|
|
|
|
|
public:
|
2014-05-24 20:52:07 +08:00
|
|
|
AArch64ABIInfo(CodeGenTypes &CGT, ABIKind Kind) : ABIInfo(CGT), Kind(Kind) {}
|
2014-03-29 23:09:45 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
ABIKind getABIKind() const { return Kind; }
|
|
|
|
bool isDarwinPCS() const { return Kind == DarwinPCS; }
|
|
|
|
|
|
|
|
ABIArgInfo classifyReturnType(QualType RetTy) const;
|
2014-11-28 05:02:49 +08:00
|
|
|
ABIArgInfo classifyArgumentType(QualType RetTy) const;
|
2014-11-01 01:10:41 +08:00
|
|
|
bool isHomogeneousAggregateBaseType(QualType Ty) const override;
|
|
|
|
bool isHomogeneousAggregateSmallEnough(const Type *Ty,
|
|
|
|
uint64_t Members) const override;
|
|
|
|
|
2014-03-29 23:09:45 +08:00
|
|
|
bool isIllegalVectorType(QualType Ty) const;
|
|
|
|
|
2014-11-15 03:09:44 +08:00
|
|
|
void computeInfo(CGFunctionInfo &FI) const override {
|
2014-05-14 06:05:45 +08:00
|
|
|
if (!getCXXABI().classifyReturnType(FI))
|
|
|
|
FI.getReturnInfo() = classifyReturnType(FI.getReturnType());
|
2014-04-17 18:20:38 +08:00
|
|
|
|
2014-11-28 05:02:49 +08:00
|
|
|
for (auto &it : FI.arguments())
|
|
|
|
it.info = classifyArgumentType(it.type);
|
2014-03-29 23:09:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
llvm::Value *EmitDarwinVAArg(llvm::Value *VAListAddr, QualType Ty,
|
|
|
|
CodeGenFunction &CGF) const;
|
|
|
|
|
|
|
|
llvm::Value *EmitAAPCSVAArg(llvm::Value *VAListAddr, QualType Ty,
|
|
|
|
CodeGenFunction &CGF) const;
|
|
|
|
|
|
|
|
virtual llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
|
2014-11-01 09:32:27 +08:00
|
|
|
CodeGenFunction &CGF) const override {
|
2014-03-29 23:09:45 +08:00
|
|
|
return isDarwinPCS() ? EmitDarwinVAArg(VAListAddr, Ty, CGF)
|
|
|
|
: EmitAAPCSVAArg(VAListAddr, Ty, CGF);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-05-24 20:52:07 +08:00
|
|
|
class AArch64TargetCodeGenInfo : public TargetCodeGenInfo {
|
2014-03-29 23:09:45 +08:00
|
|
|
public:
|
2014-05-24 20:52:07 +08:00
|
|
|
AArch64TargetCodeGenInfo(CodeGenTypes &CGT, AArch64ABIInfo::ABIKind Kind)
|
|
|
|
: TargetCodeGenInfo(new AArch64ABIInfo(CGT, Kind)) {}
|
2014-03-29 23:09:45 +08:00
|
|
|
|
|
|
|
StringRef getARCRetainAutoreleasedReturnValueMarker() const {
|
|
|
|
return "mov\tfp, fp\t\t; marker for objc_retainAutoreleaseReturnValue";
|
|
|
|
}
|
|
|
|
|
|
|
|
int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const { return 31; }
|
|
|
|
|
|
|
|
virtual bool doesReturnSlotInterfereWithArgs() const { return false; }
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2014-11-28 05:02:49 +08:00
|
|
|
ABIArgInfo AArch64ABIInfo::classifyArgumentType(QualType Ty) const {
|
2014-11-15 09:41:41 +08:00
|
|
|
Ty = useFirstFieldIfTransparentUnion(Ty);
|
|
|
|
|
2014-03-29 23:09:45 +08:00
|
|
|
// Handle illegal vector types here.
|
|
|
|
if (isIllegalVectorType(Ty)) {
|
|
|
|
uint64_t Size = getContext().getTypeSize(Ty);
|
|
|
|
if (Size <= 32) {
|
|
|
|
llvm::Type *ResType = llvm::Type::getInt32Ty(getVMContext());
|
|
|
|
return ABIArgInfo::getDirect(ResType);
|
|
|
|
}
|
|
|
|
if (Size == 64) {
|
|
|
|
llvm::Type *ResType =
|
|
|
|
llvm::VectorType::get(llvm::Type::getInt32Ty(getVMContext()), 2);
|
|
|
|
return ABIArgInfo::getDirect(ResType);
|
|
|
|
}
|
|
|
|
if (Size == 128) {
|
|
|
|
llvm::Type *ResType =
|
|
|
|
llvm::VectorType::get(llvm::Type::getInt32Ty(getVMContext()), 4);
|
|
|
|
return ABIArgInfo::getDirect(ResType);
|
|
|
|
}
|
|
|
|
return ABIArgInfo::getIndirect(0, /*ByVal=*/false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isAggregateTypeForABI(Ty)) {
|
|
|
|
// Treat an enum type as its underlying type.
|
|
|
|
if (const EnumType *EnumTy = Ty->getAs<EnumType>())
|
|
|
|
Ty = EnumTy->getDecl()->getIntegerType();
|
|
|
|
|
|
|
|
return (Ty->isPromotableIntegerType() && isDarwinPCS()
|
|
|
|
? ABIArgInfo::getExtend()
|
|
|
|
: ABIArgInfo::getDirect());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Structures with either a non-trivial destructor or a non-trivial
|
|
|
|
// copy constructor are always indirect.
|
2014-05-14 06:05:45 +08:00
|
|
|
if (CGCXXABI::RecordArgABI RAA = getRecordArgABI(Ty, getCXXABI())) {
|
|
|
|
return ABIArgInfo::getIndirect(0, /*ByVal=*/RAA ==
|
2014-11-28 05:02:49 +08:00
|
|
|
CGCXXABI::RAA_DirectInMemory);
|
2014-03-29 23:09:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Empty records are always ignored on Darwin, but actually passed in C++ mode
|
|
|
|
// elsewhere for GNU compatibility.
|
|
|
|
if (isEmptyRecord(getContext(), Ty, true)) {
|
|
|
|
if (!getContext().getLangOpts().CPlusPlus || isDarwinPCS())
|
|
|
|
return ABIArgInfo::getIgnore();
|
|
|
|
|
|
|
|
return ABIArgInfo::getDirect(llvm::Type::getInt8Ty(getVMContext()));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Homogeneous Floating-point Aggregates (HFAs) need to be expanded.
|
2014-05-21 13:09:00 +08:00
|
|
|
const Type *Base = nullptr;
|
2014-03-29 23:09:45 +08:00
|
|
|
uint64_t Members = 0;
|
2014-11-01 01:10:41 +08:00
|
|
|
if (isHomogeneousAggregate(Ty, Base, Members)) {
|
2014-11-28 05:02:49 +08:00
|
|
|
return ABIArgInfo::getDirect(
|
|
|
|
llvm::ArrayType::get(CGT.ConvertType(QualType(Base, 0)), Members));
|
2014-03-29 23:09:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Aggregates <= 16 bytes are passed directly in registers or on the stack.
|
|
|
|
uint64_t Size = getContext().getTypeSize(Ty);
|
|
|
|
if (Size <= 128) {
|
2014-04-15 22:55:11 +08:00
|
|
|
unsigned Alignment = getContext().getTypeAlign(Ty);
|
2014-03-29 23:09:45 +08:00
|
|
|
Size = 64 * ((Size + 63) / 64); // round up to multiple of 8 bytes
|
2014-11-28 05:02:49 +08:00
|
|
|
|
2014-03-29 23:09:45 +08:00
|
|
|
// We use a pair of i64 for 16-byte aggregate with 8-byte alignment.
|
|
|
|
// For aggregates with 16-byte alignment, we use i128.
|
2014-04-15 22:55:11 +08:00
|
|
|
if (Alignment < 128 && Size == 128) {
|
2014-03-29 23:09:45 +08:00
|
|
|
llvm::Type *BaseTy = llvm::Type::getInt64Ty(getVMContext());
|
|
|
|
return ABIArgInfo::getDirect(llvm::ArrayType::get(BaseTy, Size / 64));
|
|
|
|
}
|
|
|
|
return ABIArgInfo::getDirect(llvm::IntegerType::get(getVMContext(), Size));
|
|
|
|
}
|
|
|
|
|
|
|
|
return ABIArgInfo::getIndirect(0, /*ByVal=*/false);
|
|
|
|
}
|
|
|
|
|
2014-05-24 20:52:07 +08:00
|
|
|
ABIArgInfo AArch64ABIInfo::classifyReturnType(QualType RetTy) const {
|
2014-03-29 23:09:45 +08:00
|
|
|
if (RetTy->isVoidType())
|
|
|
|
return ABIArgInfo::getIgnore();
|
|
|
|
|
|
|
|
// Large vector types should be returned via memory.
|
|
|
|
if (RetTy->isVectorType() && getContext().getTypeSize(RetTy) > 128)
|
|
|
|
return ABIArgInfo::getIndirect(0);
|
|
|
|
|
|
|
|
if (!isAggregateTypeForABI(RetTy)) {
|
|
|
|
// Treat an enum type as its underlying type.
|
|
|
|
if (const EnumType *EnumTy = RetTy->getAs<EnumType>())
|
|
|
|
RetTy = EnumTy->getDecl()->getIntegerType();
|
|
|
|
|
2014-04-18 21:46:08 +08:00
|
|
|
return (RetTy->isPromotableIntegerType() && isDarwinPCS()
|
|
|
|
? ABIArgInfo::getExtend()
|
|
|
|
: ABIArgInfo::getDirect());
|
2014-03-29 23:09:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isEmptyRecord(getContext(), RetTy, true))
|
|
|
|
return ABIArgInfo::getIgnore();
|
|
|
|
|
2014-05-21 13:09:00 +08:00
|
|
|
const Type *Base = nullptr;
|
2014-11-01 01:10:41 +08:00
|
|
|
uint64_t Members = 0;
|
|
|
|
if (isHomogeneousAggregate(RetTy, Base, Members))
|
2014-03-29 23:09:45 +08:00
|
|
|
// Homogeneous Floating-point Aggregates (HFAs) are returned directly.
|
|
|
|
return ABIArgInfo::getDirect();
|
|
|
|
|
|
|
|
// Aggregates <= 16 bytes are returned directly in registers or on the stack.
|
|
|
|
uint64_t Size = getContext().getTypeSize(RetTy);
|
|
|
|
if (Size <= 128) {
|
|
|
|
Size = 64 * ((Size + 63) / 64); // round up to multiple of 8 bytes
|
|
|
|
return ABIArgInfo::getDirect(llvm::IntegerType::get(getVMContext(), Size));
|
|
|
|
}
|
|
|
|
|
|
|
|
return ABIArgInfo::getIndirect(0);
|
|
|
|
}
|
|
|
|
|
2014-05-24 20:52:07 +08:00
|
|
|
/// isIllegalVectorType - check whether the vector type is legal for AArch64.
|
|
|
|
bool AArch64ABIInfo::isIllegalVectorType(QualType Ty) const {
|
2014-03-29 23:09:45 +08:00
|
|
|
if (const VectorType *VT = Ty->getAs<VectorType>()) {
|
|
|
|
// Check whether VT is legal.
|
|
|
|
unsigned NumElements = VT->getNumElements();
|
|
|
|
uint64_t Size = getContext().getTypeSize(VT);
|
|
|
|
// NumElements should be power of 2 between 1 and 16.
|
|
|
|
if ((NumElements & (NumElements - 1)) != 0 || NumElements > 16)
|
|
|
|
return true;
|
|
|
|
return Size != 64 && (Size != 128 || NumElements == 1);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-11-01 01:10:41 +08:00
|
|
|
bool AArch64ABIInfo::isHomogeneousAggregateBaseType(QualType Ty) const {
|
|
|
|
// Homogeneous aggregates for AAPCS64 must have base types of a floating
|
|
|
|
// point type or a short-vector type. This is the same as the 32-bit ABI,
|
|
|
|
// but with the difference that any floating-point type is allowed,
|
|
|
|
// including __fp16.
|
|
|
|
if (const BuiltinType *BT = Ty->getAs<BuiltinType>()) {
|
|
|
|
if (BT->isFloatingPoint())
|
|
|
|
return true;
|
|
|
|
} else if (const VectorType *VT = Ty->getAs<VectorType>()) {
|
|
|
|
unsigned VecSize = getContext().getTypeSize(VT);
|
|
|
|
if (VecSize == 64 || VecSize == 128)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AArch64ABIInfo::isHomogeneousAggregateSmallEnough(const Type *Base,
|
|
|
|
uint64_t Members) const {
|
|
|
|
return Members <= 4;
|
|
|
|
}
|
|
|
|
|
2014-11-28 05:02:49 +08:00
|
|
|
llvm::Value *AArch64ABIInfo::EmitAAPCSVAArg(llvm::Value *VAListAddr,
|
|
|
|
QualType Ty,
|
|
|
|
CodeGenFunction &CGF) const {
|
|
|
|
ABIArgInfo AI = classifyArgumentType(Ty);
|
2014-11-01 01:10:41 +08:00
|
|
|
bool IsIndirect = AI.isIndirect();
|
|
|
|
|
2014-11-28 05:02:49 +08:00
|
|
|
llvm::Type *BaseTy = CGF.ConvertType(Ty);
|
|
|
|
if (IsIndirect)
|
|
|
|
BaseTy = llvm::PointerType::getUnqual(BaseTy);
|
|
|
|
else if (AI.getCoerceToType())
|
|
|
|
BaseTy = AI.getCoerceToType();
|
|
|
|
|
|
|
|
unsigned NumRegs = 1;
|
|
|
|
if (llvm::ArrayType *ArrTy = dyn_cast<llvm::ArrayType>(BaseTy)) {
|
|
|
|
BaseTy = ArrTy->getElementType();
|
|
|
|
NumRegs = ArrTy->getNumElements();
|
|
|
|
}
|
|
|
|
bool IsFPR = BaseTy->isFloatingPointTy() || BaseTy->isVectorTy();
|
|
|
|
|
2014-03-29 23:09:45 +08:00
|
|
|
// The AArch64 va_list type and handling is specified in the Procedure Call
|
|
|
|
// Standard, section B.4:
|
|
|
|
//
|
|
|
|
// struct {
|
|
|
|
// void *__stack;
|
|
|
|
// void *__gr_top;
|
|
|
|
// void *__vr_top;
|
|
|
|
// int __gr_offs;
|
|
|
|
// int __vr_offs;
|
|
|
|
// };
|
|
|
|
|
|
|
|
llvm::BasicBlock *MaybeRegBlock = CGF.createBasicBlock("vaarg.maybe_reg");
|
|
|
|
llvm::BasicBlock *InRegBlock = CGF.createBasicBlock("vaarg.in_reg");
|
|
|
|
llvm::BasicBlock *OnStackBlock = CGF.createBasicBlock("vaarg.on_stack");
|
|
|
|
llvm::BasicBlock *ContBlock = CGF.createBasicBlock("vaarg.end");
|
|
|
|
auto &Ctx = CGF.getContext();
|
|
|
|
|
2014-05-21 13:09:00 +08:00
|
|
|
llvm::Value *reg_offs_p = nullptr, *reg_offs = nullptr;
|
2014-03-29 23:09:45 +08:00
|
|
|
int reg_top_index;
|
2014-11-28 05:02:49 +08:00
|
|
|
int RegSize = IsIndirect ? 8 : getContext().getTypeSize(Ty) / 8;
|
|
|
|
if (!IsFPR) {
|
2014-03-29 23:09:45 +08:00
|
|
|
// 3 is the field number of __gr_offs
|
|
|
|
reg_offs_p = CGF.Builder.CreateStructGEP(VAListAddr, 3, "gr_offs_p");
|
|
|
|
reg_offs = CGF.Builder.CreateLoad(reg_offs_p, "gr_offs");
|
|
|
|
reg_top_index = 1; // field number for __gr_top
|
2014-11-28 05:02:49 +08:00
|
|
|
RegSize = llvm::RoundUpToAlignment(RegSize, 8);
|
2014-03-29 23:09:45 +08:00
|
|
|
} else {
|
|
|
|
// 4 is the field number of __vr_offs.
|
|
|
|
reg_offs_p = CGF.Builder.CreateStructGEP(VAListAddr, 4, "vr_offs_p");
|
|
|
|
reg_offs = CGF.Builder.CreateLoad(reg_offs_p, "vr_offs");
|
|
|
|
reg_top_index = 2; // field number for __vr_top
|
2014-11-28 05:02:49 +08:00
|
|
|
RegSize = 16 * NumRegs;
|
2014-03-29 23:09:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//=======================================
|
|
|
|
// Find out where argument was passed
|
|
|
|
//=======================================
|
|
|
|
|
|
|
|
// If reg_offs >= 0 we're already using the stack for this type of
|
|
|
|
// argument. We don't want to keep updating reg_offs (in case it overflows,
|
|
|
|
// though anyone passing 2GB of arguments, each at most 16 bytes, deserves
|
|
|
|
// whatever they get).
|
2014-05-21 13:09:00 +08:00
|
|
|
llvm::Value *UsingStack = nullptr;
|
2014-03-29 23:09:45 +08:00
|
|
|
UsingStack = CGF.Builder.CreateICmpSGE(
|
|
|
|
reg_offs, llvm::ConstantInt::get(CGF.Int32Ty, 0));
|
|
|
|
|
|
|
|
CGF.Builder.CreateCondBr(UsingStack, OnStackBlock, MaybeRegBlock);
|
|
|
|
|
|
|
|
// Otherwise, at least some kind of argument could go in these registers, the
|
2014-04-21 09:23:36 +08:00
|
|
|
// question is whether this particular type is too big.
|
2014-03-29 23:09:45 +08:00
|
|
|
CGF.EmitBlock(MaybeRegBlock);
|
|
|
|
|
|
|
|
// Integer arguments may need to correct register alignment (for example a
|
|
|
|
// "struct { __int128 a; };" gets passed in x_2N, x_{2N+1}). In this case we
|
|
|
|
// align __gr_offs to calculate the potential address.
|
2014-11-28 05:02:49 +08:00
|
|
|
if (!IsFPR && !IsIndirect && Ctx.getTypeAlign(Ty) > 64) {
|
2014-03-29 23:09:45 +08:00
|
|
|
int Align = Ctx.getTypeAlign(Ty) / 8;
|
|
|
|
|
|
|
|
reg_offs = CGF.Builder.CreateAdd(
|
|
|
|
reg_offs, llvm::ConstantInt::get(CGF.Int32Ty, Align - 1),
|
|
|
|
"align_regoffs");
|
|
|
|
reg_offs = CGF.Builder.CreateAnd(
|
|
|
|
reg_offs, llvm::ConstantInt::get(CGF.Int32Ty, -Align),
|
|
|
|
"aligned_regoffs");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the gr_offs/vr_offs pointer for next call to va_arg on this va_list.
|
2014-05-21 13:09:00 +08:00
|
|
|
llvm::Value *NewOffset = nullptr;
|
2014-03-29 23:09:45 +08:00
|
|
|
NewOffset = CGF.Builder.CreateAdd(
|
|
|
|
reg_offs, llvm::ConstantInt::get(CGF.Int32Ty, RegSize), "new_reg_offs");
|
|
|
|
CGF.Builder.CreateStore(NewOffset, reg_offs_p);
|
|
|
|
|
|
|
|
// Now we're in a position to decide whether this argument really was in
|
|
|
|
// registers or not.
|
2014-05-21 13:09:00 +08:00
|
|
|
llvm::Value *InRegs = nullptr;
|
2014-03-29 23:09:45 +08:00
|
|
|
InRegs = CGF.Builder.CreateICmpSLE(
|
|
|
|
NewOffset, llvm::ConstantInt::get(CGF.Int32Ty, 0), "inreg");
|
|
|
|
|
|
|
|
CGF.Builder.CreateCondBr(InRegs, InRegBlock, OnStackBlock);
|
|
|
|
|
|
|
|
//=======================================
|
|
|
|
// Argument was in registers
|
|
|
|
//=======================================
|
|
|
|
|
|
|
|
// Now we emit the code for if the argument was originally passed in
|
|
|
|
// registers. First start the appropriate block:
|
|
|
|
CGF.EmitBlock(InRegBlock);
|
|
|
|
|
2014-05-21 13:09:00 +08:00
|
|
|
llvm::Value *reg_top_p = nullptr, *reg_top = nullptr;
|
2014-03-29 23:09:45 +08:00
|
|
|
reg_top_p =
|
|
|
|
CGF.Builder.CreateStructGEP(VAListAddr, reg_top_index, "reg_top_p");
|
|
|
|
reg_top = CGF.Builder.CreateLoad(reg_top_p, "reg_top");
|
|
|
|
llvm::Value *BaseAddr = CGF.Builder.CreateGEP(reg_top, reg_offs);
|
2014-05-21 13:09:00 +08:00
|
|
|
llvm::Value *RegAddr = nullptr;
|
2014-03-29 23:09:45 +08:00
|
|
|
llvm::Type *MemTy = llvm::PointerType::getUnqual(CGF.ConvertTypeForMem(Ty));
|
|
|
|
|
|
|
|
if (IsIndirect) {
|
|
|
|
// If it's been passed indirectly (actually a struct), whatever we find from
|
|
|
|
// stored registers or on the stack will actually be a struct **.
|
|
|
|
MemTy = llvm::PointerType::getUnqual(MemTy);
|
|
|
|
}
|
|
|
|
|
2014-05-21 13:09:00 +08:00
|
|
|
const Type *Base = nullptr;
|
2014-11-01 01:10:41 +08:00
|
|
|
uint64_t NumMembers = 0;
|
|
|
|
bool IsHFA = isHomogeneousAggregate(Ty, Base, NumMembers);
|
2014-05-07 22:45:55 +08:00
|
|
|
if (IsHFA && NumMembers > 1) {
|
2014-03-29 23:09:45 +08:00
|
|
|
// Homogeneous aggregates passed in registers will have their elements split
|
|
|
|
// and stored 16-bytes apart regardless of size (they're notionally in qN,
|
|
|
|
// qN+1, ...). We reload and store into a temporary local variable
|
|
|
|
// contiguously.
|
|
|
|
assert(!IsIndirect && "Homogeneous aggregates should be passed directly");
|
|
|
|
llvm::Type *BaseTy = CGF.ConvertType(QualType(Base, 0));
|
|
|
|
llvm::Type *HFATy = llvm::ArrayType::get(BaseTy, NumMembers);
|
|
|
|
llvm::Value *Tmp = CGF.CreateTempAlloca(HFATy);
|
|
|
|
int Offset = 0;
|
|
|
|
|
|
|
|
if (CGF.CGM.getDataLayout().isBigEndian() && Ctx.getTypeSize(Base) < 128)
|
|
|
|
Offset = 16 - Ctx.getTypeSize(Base) / 8;
|
|
|
|
for (unsigned i = 0; i < NumMembers; ++i) {
|
|
|
|
llvm::Value *BaseOffset =
|
|
|
|
llvm::ConstantInt::get(CGF.Int32Ty, 16 * i + Offset);
|
|
|
|
llvm::Value *LoadAddr = CGF.Builder.CreateGEP(BaseAddr, BaseOffset);
|
|
|
|
LoadAddr = CGF.Builder.CreateBitCast(
|
|
|
|
LoadAddr, llvm::PointerType::getUnqual(BaseTy));
|
|
|
|
llvm::Value *StoreAddr = CGF.Builder.CreateStructGEP(Tmp, i);
|
|
|
|
|
|
|
|
llvm::Value *Elem = CGF.Builder.CreateLoad(LoadAddr);
|
|
|
|
CGF.Builder.CreateStore(Elem, StoreAddr);
|
|
|
|
}
|
|
|
|
|
|
|
|
RegAddr = CGF.Builder.CreateBitCast(Tmp, MemTy);
|
|
|
|
} else {
|
|
|
|
// Otherwise the object is contiguous in memory
|
|
|
|
unsigned BeAlign = reg_top_index == 2 ? 16 : 8;
|
2014-05-07 22:45:55 +08:00
|
|
|
if (CGF.CGM.getDataLayout().isBigEndian() &&
|
|
|
|
(IsHFA || !isAggregateTypeForABI(Ty)) &&
|
2014-03-29 23:09:45 +08:00
|
|
|
Ctx.getTypeSize(Ty) < (BeAlign * 8)) {
|
|
|
|
int Offset = BeAlign - Ctx.getTypeSize(Ty) / 8;
|
|
|
|
BaseAddr = CGF.Builder.CreatePtrToInt(BaseAddr, CGF.Int64Ty);
|
|
|
|
|
|
|
|
BaseAddr = CGF.Builder.CreateAdd(
|
|
|
|
BaseAddr, llvm::ConstantInt::get(CGF.Int64Ty, Offset), "align_be");
|
|
|
|
|
|
|
|
BaseAddr = CGF.Builder.CreateIntToPtr(BaseAddr, CGF.Int8PtrTy);
|
|
|
|
}
|
|
|
|
|
|
|
|
RegAddr = CGF.Builder.CreateBitCast(BaseAddr, MemTy);
|
|
|
|
}
|
|
|
|
|
|
|
|
CGF.EmitBranch(ContBlock);
|
|
|
|
|
|
|
|
//=======================================
|
|
|
|
// Argument was on the stack
|
|
|
|
//=======================================
|
|
|
|
CGF.EmitBlock(OnStackBlock);
|
|
|
|
|
2014-05-21 13:09:00 +08:00
|
|
|
llvm::Value *stack_p = nullptr, *OnStackAddr = nullptr;
|
2014-03-29 23:09:45 +08:00
|
|
|
stack_p = CGF.Builder.CreateStructGEP(VAListAddr, 0, "stack_p");
|
|
|
|
OnStackAddr = CGF.Builder.CreateLoad(stack_p, "stack");
|
|
|
|
|
|
|
|
// Again, stack arguments may need realigmnent. In this case both integer and
|
|
|
|
// floating-point ones might be affected.
|
|
|
|
if (!IsIndirect && Ctx.getTypeAlign(Ty) > 64) {
|
|
|
|
int Align = Ctx.getTypeAlign(Ty) / 8;
|
|
|
|
|
|
|
|
OnStackAddr = CGF.Builder.CreatePtrToInt(OnStackAddr, CGF.Int64Ty);
|
|
|
|
|
|
|
|
OnStackAddr = CGF.Builder.CreateAdd(
|
|
|
|
OnStackAddr, llvm::ConstantInt::get(CGF.Int64Ty, Align - 1),
|
|
|
|
"align_stack");
|
|
|
|
OnStackAddr = CGF.Builder.CreateAnd(
|
|
|
|
OnStackAddr, llvm::ConstantInt::get(CGF.Int64Ty, -Align),
|
|
|
|
"align_stack");
|
|
|
|
|
|
|
|
OnStackAddr = CGF.Builder.CreateIntToPtr(OnStackAddr, CGF.Int8PtrTy);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t StackSize;
|
|
|
|
if (IsIndirect)
|
|
|
|
StackSize = 8;
|
|
|
|
else
|
|
|
|
StackSize = Ctx.getTypeSize(Ty) / 8;
|
|
|
|
|
|
|
|
// All stack slots are 8 bytes
|
|
|
|
StackSize = llvm::RoundUpToAlignment(StackSize, 8);
|
|
|
|
|
|
|
|
llvm::Value *StackSizeC = llvm::ConstantInt::get(CGF.Int32Ty, StackSize);
|
|
|
|
llvm::Value *NewStack =
|
|
|
|
CGF.Builder.CreateGEP(OnStackAddr, StackSizeC, "new_stack");
|
|
|
|
|
|
|
|
// Write the new value of __stack for the next call to va_arg
|
|
|
|
CGF.Builder.CreateStore(NewStack, stack_p);
|
|
|
|
|
|
|
|
if (CGF.CGM.getDataLayout().isBigEndian() && !isAggregateTypeForABI(Ty) &&
|
|
|
|
Ctx.getTypeSize(Ty) < 64) {
|
|
|
|
int Offset = 8 - Ctx.getTypeSize(Ty) / 8;
|
|
|
|
OnStackAddr = CGF.Builder.CreatePtrToInt(OnStackAddr, CGF.Int64Ty);
|
|
|
|
|
|
|
|
OnStackAddr = CGF.Builder.CreateAdd(
|
|
|
|
OnStackAddr, llvm::ConstantInt::get(CGF.Int64Ty, Offset), "align_be");
|
|
|
|
|
|
|
|
OnStackAddr = CGF.Builder.CreateIntToPtr(OnStackAddr, CGF.Int8PtrTy);
|
|
|
|
}
|
|
|
|
|
|
|
|
OnStackAddr = CGF.Builder.CreateBitCast(OnStackAddr, MemTy);
|
|
|
|
|
|
|
|
CGF.EmitBranch(ContBlock);
|
|
|
|
|
|
|
|
//=======================================
|
|
|
|
// Tidy up
|
|
|
|
//=======================================
|
|
|
|
CGF.EmitBlock(ContBlock);
|
|
|
|
|
|
|
|
llvm::PHINode *ResAddr = CGF.Builder.CreatePHI(MemTy, 2, "vaarg.addr");
|
|
|
|
ResAddr->addIncoming(RegAddr, InRegBlock);
|
|
|
|
ResAddr->addIncoming(OnStackAddr, OnStackBlock);
|
|
|
|
|
|
|
|
if (IsIndirect)
|
|
|
|
return CGF.Builder.CreateLoad(ResAddr, "vaarg.addr");
|
|
|
|
|
|
|
|
return ResAddr;
|
|
|
|
}
|
|
|
|
|
2014-05-24 20:52:07 +08:00
|
|
|
llvm::Value *AArch64ABIInfo::EmitDarwinVAArg(llvm::Value *VAListAddr, QualType Ty,
|
2014-03-29 23:09:45 +08:00
|
|
|
CodeGenFunction &CGF) const {
|
|
|
|
// We do not support va_arg for aggregates or illegal vector types.
|
|
|
|
// Lower VAArg here for these cases and use the LLVM va_arg instruction for
|
|
|
|
// other cases.
|
|
|
|
if (!isAggregateTypeForABI(Ty) && !isIllegalVectorType(Ty))
|
2014-05-21 13:09:00 +08:00
|
|
|
return nullptr;
|
2014-03-29 23:09:45 +08:00
|
|
|
|
|
|
|
uint64_t Size = CGF.getContext().getTypeSize(Ty) / 8;
|
|
|
|
uint64_t Align = CGF.getContext().getTypeAlign(Ty) / 8;
|
|
|
|
|
2014-05-21 13:09:00 +08:00
|
|
|
const Type *Base = nullptr;
|
2014-11-01 01:10:41 +08:00
|
|
|
uint64_t Members = 0;
|
|
|
|
bool isHA = isHomogeneousAggregate(Ty, Base, Members);
|
2014-03-29 23:09:45 +08:00
|
|
|
|
|
|
|
bool isIndirect = false;
|
|
|
|
// Arguments bigger than 16 bytes which aren't homogeneous aggregates should
|
|
|
|
// be passed indirectly.
|
|
|
|
if (Size > 16 && !isHA) {
|
|
|
|
isIndirect = true;
|
|
|
|
Size = 8;
|
|
|
|
Align = 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::Type *BP = llvm::Type::getInt8PtrTy(CGF.getLLVMContext());
|
|
|
|
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");
|
|
|
|
|
|
|
|
if (isEmptyRecord(getContext(), Ty, true)) {
|
|
|
|
// These are ignored for parameter passing purposes.
|
|
|
|
llvm::Type *PTy = llvm::PointerType::getUnqual(CGF.ConvertType(Ty));
|
|
|
|
return Builder.CreateBitCast(Addr, PTy);
|
|
|
|
}
|
|
|
|
|
|
|
|
const uint64_t MinABIAlign = 8;
|
|
|
|
if (Align > MinABIAlign) {
|
|
|
|
llvm::Value *Offset = llvm::ConstantInt::get(CGF.Int32Ty, Align - 1);
|
|
|
|
Addr = Builder.CreateGEP(Addr, Offset);
|
|
|
|
llvm::Value *AsInt = Builder.CreatePtrToInt(Addr, CGF.Int64Ty);
|
|
|
|
llvm::Value *Mask = llvm::ConstantInt::get(CGF.Int64Ty, ~(Align - 1));
|
|
|
|
llvm::Value *Aligned = Builder.CreateAnd(AsInt, Mask);
|
|
|
|
Addr = Builder.CreateIntToPtr(Aligned, BP, "ap.align");
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t Offset = llvm::RoundUpToAlignment(Size, MinABIAlign);
|
|
|
|
llvm::Value *NextAddr = Builder.CreateGEP(
|
|
|
|
Addr, llvm::ConstantInt::get(CGF.Int32Ty, Offset), "ap.next");
|
|
|
|
Builder.CreateStore(NextAddr, VAListAddrAsBPP);
|
|
|
|
|
|
|
|
if (isIndirect)
|
|
|
|
Addr = Builder.CreateLoad(Builder.CreateBitCast(Addr, BPP));
|
|
|
|
llvm::Type *PTy = llvm::PointerType::getUnqual(CGF.ConvertType(Ty));
|
|
|
|
llvm::Value *AddrTyped = Builder.CreateBitCast(Addr, PTy);
|
|
|
|
|
|
|
|
return AddrTyped;
|
|
|
|
}
|
|
|
|
|
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;
|
2014-02-11 17:25:50 +08:00
|
|
|
mutable int VFPRegs[16];
|
|
|
|
const unsigned NumVFPs;
|
|
|
|
const unsigned NumGPRs;
|
|
|
|
mutable unsigned AllocatedGPRs;
|
|
|
|
mutable unsigned AllocatedVFPs;
|
2009-09-12 09:00:39 +08:00
|
|
|
|
|
|
|
public:
|
2014-02-11 17:25:50 +08:00
|
|
|
ARMABIInfo(CodeGenTypes &CGT, ABIKind _Kind) : ABIInfo(CGT), Kind(_Kind),
|
|
|
|
NumVFPs(16), NumGPRs(4) {
|
2014-12-03 00:04:58 +08:00
|
|
|
setCCs();
|
2014-02-11 17:25:50 +08:00
|
|
|
resetAllocatedRegs();
|
2013-03-01 03:01:20 +08:00
|
|
|
}
|
2009-09-12 09:00:39 +08:00
|
|
|
|
2011-08-30 09:42:09 +08:00
|
|
|
bool isEABI() const {
|
2013-12-13 05:29:27 +08:00
|
|
|
switch (getTarget().getTriple().getEnvironment()) {
|
|
|
|
case llvm::Triple::Android:
|
|
|
|
case llvm::Triple::EABI:
|
2013-12-17 03:16:04 +08:00
|
|
|
case llvm::Triple::EABIHF:
|
2013-12-13 05:29:27 +08:00
|
|
|
case llvm::Triple::GNUEABI:
|
2013-12-17 02:30:28 +08:00
|
|
|
case llvm::Triple::GNUEABIHF:
|
2013-12-13 05:29:27 +08:00
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2011-08-30 09:42:09 +08:00
|
|
|
}
|
|
|
|
|
2013-12-17 03:16:04 +08:00
|
|
|
bool isEABIHF() const {
|
|
|
|
switch (getTarget().getTriple().getEnvironment()) {
|
|
|
|
case llvm::Triple::EABIHF:
|
|
|
|
case llvm::Triple::GNUEABIHF:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-12 09:00:39 +08:00
|
|
|
ABIKind getABIKind() const { return Kind; }
|
|
|
|
|
2013-10-01 22:34:25 +08:00
|
|
|
private:
|
2014-01-28 18:56:36 +08:00
|
|
|
ABIArgInfo classifyReturnType(QualType RetTy, bool isVariadic) const;
|
2014-05-10 00:21:39 +08:00
|
|
|
ABIArgInfo classifyArgumentType(QualType RetTy, bool isVariadic,
|
2014-02-11 17:25:50 +08:00
|
|
|
bool &IsCPRC) const;
|
2012-10-17 03:18:39 +08:00
|
|
|
bool isIllegalVectorType(QualType Ty) const;
|
2009-06-06 06:08:42 +08:00
|
|
|
|
2014-11-01 01:10:41 +08:00
|
|
|
bool isHomogeneousAggregateBaseType(QualType Ty) const override;
|
|
|
|
bool isHomogeneousAggregateSmallEnough(const Type *Ty,
|
|
|
|
uint64_t Members) const override;
|
|
|
|
|
2014-03-12 14:41:41 +08:00
|
|
|
void computeInfo(CGFunctionInfo &FI) const override;
|
2009-06-06 06:08:42 +08:00
|
|
|
|
2014-03-12 14:41:41 +08:00
|
|
|
llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
|
|
|
|
CodeGenFunction &CGF) const override;
|
2013-03-01 03:01:20 +08:00
|
|
|
|
|
|
|
llvm::CallingConv::ID getLLVMDefaultCC() const;
|
|
|
|
llvm::CallingConv::ID getABIDefaultCC() const;
|
2014-12-03 00:04:58 +08:00
|
|
|
void setCCs();
|
2014-02-11 17:25:50 +08:00
|
|
|
|
|
|
|
void markAllocatedGPRs(unsigned Alignment, unsigned NumRequired) const;
|
|
|
|
void markAllocatedVFPs(unsigned Alignment, unsigned NumRequired) const;
|
|
|
|
void resetAllocatedRegs(void) const;
|
2009-06-06 06:08:42 +08:00
|
|
|
};
|
|
|
|
|
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
|
|
|
|
2011-08-30 09:42:09 +08:00
|
|
|
const ARMABIInfo &getABIInfo() const {
|
|
|
|
return static_cast<const ARMABIInfo&>(TargetCodeGenInfo::getABIInfo());
|
|
|
|
}
|
|
|
|
|
2014-03-12 14:41:41 +08:00
|
|
|
int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const override {
|
2010-03-06 08:35:14 +08:00
|
|
|
return 13;
|
|
|
|
}
|
2011-05-19 03:36:54 +08:00
|
|
|
|
2014-03-12 14:41:41 +08:00
|
|
|
StringRef getARCRetainAutoreleasedReturnValueMarker() const override {
|
2011-06-16 07:02:42 +08:00
|
|
|
return "mov\tr7, r7\t\t@ marker for objc_retainAutoreleaseReturnValue";
|
|
|
|
}
|
|
|
|
|
2011-05-19 03:36:54 +08:00
|
|
|
bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
|
2014-03-12 14:41:41 +08:00
|
|
|
llvm::Value *Address) const override {
|
2012-02-07 08:39:47 +08:00
|
|
|
llvm::Value *Four8 = llvm::ConstantInt::get(CGF.Int8Ty, 4);
|
2011-05-19 03:36:54 +08:00
|
|
|
|
|
|
|
// 0-15 are the 16 integer registers.
|
2012-02-07 08:39:47 +08:00
|
|
|
AssignToArrayRange(CGF.Builder, Address, Four8, 0, 15);
|
2011-05-19 03:36:54 +08:00
|
|
|
return false;
|
|
|
|
}
|
2011-08-30 09:42:09 +08:00
|
|
|
|
2014-03-12 14:41:41 +08:00
|
|
|
unsigned getSizeOfUnwindException() const override {
|
2011-08-30 09:42:09 +08:00
|
|
|
if (getABIInfo().isEABI()) return 88;
|
|
|
|
return TargetCodeGenInfo::getSizeOfUnwindException();
|
|
|
|
}
|
2013-10-01 22:34:25 +08:00
|
|
|
|
|
|
|
void SetTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
|
2014-03-12 14:41:41 +08:00
|
|
|
CodeGen::CodeGenModule &CGM) const override {
|
2013-10-01 22:34:25 +08:00
|
|
|
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D);
|
|
|
|
if (!FD)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const ARMInterruptAttr *Attr = FD->getAttr<ARMInterruptAttr>();
|
|
|
|
if (!Attr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const char *Kind;
|
|
|
|
switch (Attr->getInterrupt()) {
|
|
|
|
case ARMInterruptAttr::Generic: Kind = ""; break;
|
|
|
|
case ARMInterruptAttr::IRQ: Kind = "IRQ"; break;
|
|
|
|
case ARMInterruptAttr::FIQ: Kind = "FIQ"; break;
|
|
|
|
case ARMInterruptAttr::SWI: Kind = "SWI"; break;
|
|
|
|
case ARMInterruptAttr::ABORT: Kind = "ABORT"; break;
|
|
|
|
case ARMInterruptAttr::UNDEF: Kind = "UNDEF"; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::Function *Fn = cast<llvm::Function>(GV);
|
|
|
|
|
|
|
|
Fn->addFnAttr("interrupt", Kind);
|
|
|
|
|
|
|
|
if (cast<ARMABIInfo>(getABIInfo()).getABIKind() == ARMABIInfo::APCS)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// AAPCS guarantees that sp will be 8-byte aligned on any public interface,
|
|
|
|
// however this is not necessarily true on taking any interrupt. Instruct
|
|
|
|
// the backend to perform a realignment as part of the function prologue.
|
|
|
|
llvm::AttrBuilder B;
|
|
|
|
B.addStackAlignmentAttr(8);
|
|
|
|
Fn->addAttributes(llvm::AttributeSet::FunctionIndex,
|
|
|
|
llvm::AttributeSet::get(CGM.getLLVMContext(),
|
|
|
|
llvm::AttributeSet::FunctionIndex,
|
|
|
|
B));
|
|
|
|
}
|
|
|
|
|
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 {
|
2012-10-31 07:21:41 +08:00
|
|
|
// To correctly handle Homogeneous Aggregate, we need to keep track of the
|
2012-11-01 03:02:26 +08:00
|
|
|
// VFP registers allocated so far.
|
2012-10-31 07:21:41 +08:00
|
|
|
// C.1.vfp If the argument is a VFP CPRC and there are sufficient consecutive
|
|
|
|
// VFP registers of the appropriate type unallocated then the argument is
|
|
|
|
// allocated to the lowest-numbered sequence of such registers.
|
|
|
|
// C.2.vfp If the argument is a VFP CPRC then any VFP registers that are
|
|
|
|
// unallocated are marked as unavailable.
|
2014-02-11 17:25:50 +08:00
|
|
|
resetAllocatedRegs();
|
|
|
|
|
2014-05-14 06:05:45 +08:00
|
|
|
if (getCXXABI().classifyReturnType(FI)) {
|
|
|
|
if (FI.getReturnInfo().isIndirect())
|
|
|
|
markAllocatedGPRs(1, 1);
|
|
|
|
} else {
|
|
|
|
FI.getReturnInfo() = classifyReturnType(FI.getReturnType(), FI.isVariadic());
|
|
|
|
}
|
2014-03-18 02:10:01 +08:00
|
|
|
for (auto &I : FI.arguments()) {
|
2014-02-11 17:25:50 +08:00
|
|
|
unsigned PreAllocationVFPs = AllocatedVFPs;
|
|
|
|
unsigned PreAllocationGPRs = AllocatedGPRs;
|
|
|
|
bool IsCPRC = false;
|
2012-10-31 07:21:41 +08:00
|
|
|
// 6.1.2.3 There is one VFP co-processor register class using registers
|
|
|
|
// s0-s15 (d0-d7) for passing arguments.
|
2014-05-10 00:21:39 +08:00
|
|
|
I.info = classifyArgumentType(I.type, FI.isVariadic(), IsCPRC);
|
2014-02-11 17:25:50 +08:00
|
|
|
|
|
|
|
// If we have allocated some arguments onto the stack (due to running
|
|
|
|
// out of VFP registers), we cannot split an argument between GPRs and
|
|
|
|
// the stack. If this situation occurs, we add padding to prevent the
|
2014-05-19 21:10:05 +08:00
|
|
|
// GPRs from being used. In this situation, the current argument could
|
2014-02-11 17:25:50 +08:00
|
|
|
// only be allocated by rule C.8, so rule C.6 would mark these GPRs as
|
|
|
|
// unusable anyway.
|
2014-07-18 17:09:31 +08:00
|
|
|
// We do not have to do this if the argument is being passed ByVal, as the
|
|
|
|
// backend can handle that situation correctly.
|
2014-02-11 17:25:50 +08:00
|
|
|
const bool StackUsed = PreAllocationGPRs > NumGPRs || PreAllocationVFPs > NumVFPs;
|
2014-07-18 17:09:31 +08:00
|
|
|
const bool IsByVal = I.info.isIndirect() && I.info.getIndirectByVal();
|
|
|
|
if (!IsCPRC && PreAllocationGPRs < NumGPRs && AllocatedGPRs > NumGPRs &&
|
|
|
|
StackUsed && !IsByVal) {
|
2012-10-31 07:21:41 +08:00
|
|
|
llvm::Type *PaddingTy = llvm::ArrayType::get(
|
2014-02-11 17:25:50 +08:00
|
|
|
llvm::Type::getInt32Ty(getVMContext()), NumGPRs - PreAllocationGPRs);
|
2014-05-19 21:10:05 +08:00
|
|
|
if (I.info.canHaveCoerceToType()) {
|
2014-11-08 06:30:50 +08:00
|
|
|
I.info = ABIArgInfo::getDirect(I.info.getCoerceToType() /* type */,
|
|
|
|
0 /* offset */, PaddingTy, true);
|
2014-05-19 21:10:05 +08:00
|
|
|
} else {
|
|
|
|
I.info = ABIArgInfo::getDirect(nullptr /* type */, 0 /* offset */,
|
2014-11-08 06:30:50 +08:00
|
|
|
PaddingTy, true);
|
2014-05-19 21:10:05 +08:00
|
|
|
}
|
2012-10-31 07:21:41 +08:00
|
|
|
}
|
|
|
|
}
|
2009-09-12 09:00:39 +08:00
|
|
|
|
2011-04-15 04:06:49 +08:00
|
|
|
// Always honor user-specified calling convention.
|
|
|
|
if (FI.getCallingConvention() != llvm::CallingConv::C)
|
|
|
|
return;
|
|
|
|
|
2013-03-01 03:01:20 +08:00
|
|
|
llvm::CallingConv::ID cc = getRuntimeCC();
|
|
|
|
if (cc != llvm::CallingConv::C)
|
|
|
|
FI.setEffectiveCallingConvention(cc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Return the default calling convention that LLVM will use.
|
|
|
|
llvm::CallingConv::ID ARMABIInfo::getLLVMDefaultCC() const {
|
|
|
|
// The default calling convention that LLVM will infer.
|
2013-12-17 03:16:04 +08:00
|
|
|
if (isEABIHF())
|
2013-03-01 03:01:20 +08:00
|
|
|
return llvm::CallingConv::ARM_AAPCS_VFP;
|
2012-10-25 21:33:01 +08:00
|
|
|
else if (isEABI())
|
2013-03-01 03:01:20 +08:00
|
|
|
return llvm::CallingConv::ARM_AAPCS;
|
2010-06-17 03:01:17 +08:00
|
|
|
else
|
2013-03-01 03:01:20 +08:00
|
|
|
return llvm::CallingConv::ARM_APCS;
|
|
|
|
}
|
2010-06-17 00:13:39 +08:00
|
|
|
|
2013-03-01 03:01:20 +08:00
|
|
|
/// Return the calling convention that our ABI would like us to use
|
|
|
|
/// as the C calling convention.
|
|
|
|
llvm::CallingConv::ID ARMABIInfo::getABIDefaultCC() const {
|
2009-09-12 09:00:39 +08:00
|
|
|
switch (getABIKind()) {
|
2013-03-01 03:01:20 +08:00
|
|
|
case APCS: return llvm::CallingConv::ARM_APCS;
|
|
|
|
case AAPCS: return llvm::CallingConv::ARM_AAPCS;
|
|
|
|
case AAPCS_VFP: return llvm::CallingConv::ARM_AAPCS_VFP;
|
2009-09-12 09:00:39 +08:00
|
|
|
}
|
2013-03-01 03:01:20 +08:00
|
|
|
llvm_unreachable("bad ABI kind");
|
|
|
|
}
|
|
|
|
|
2014-12-03 00:04:58 +08:00
|
|
|
void ARMABIInfo::setCCs() {
|
2013-03-01 03:01:20 +08:00
|
|
|
assert(getRuntimeCC() == llvm::CallingConv::C);
|
|
|
|
|
|
|
|
// Don't muddy up the IR with a ton of explicit annotations if
|
|
|
|
// they'd just match what LLVM will infer from the triple.
|
|
|
|
llvm::CallingConv::ID abiCC = getABIDefaultCC();
|
|
|
|
if (abiCC != getLLVMDefaultCC())
|
|
|
|
RuntimeCC = abiCC;
|
2014-12-03 00:04:58 +08:00
|
|
|
|
|
|
|
BuiltinCC = (getABIKind() == APCS ?
|
|
|
|
llvm::CallingConv::ARM_APCS : llvm::CallingConv::ARM_AAPCS);
|
2009-06-06 06:08:42 +08:00
|
|
|
}
|
|
|
|
|
2012-11-01 03:02:26 +08:00
|
|
|
/// markAllocatedVFPs - update VFPRegs according to the alignment and
|
|
|
|
/// number of VFP registers (unit is S register) requested.
|
2014-02-11 17:25:50 +08:00
|
|
|
void ARMABIInfo::markAllocatedVFPs(unsigned Alignment,
|
|
|
|
unsigned NumRequired) const {
|
2012-11-01 03:02:26 +08:00
|
|
|
// Early Exit.
|
2014-02-11 17:25:50 +08:00
|
|
|
if (AllocatedVFPs >= 16) {
|
|
|
|
// We use AllocatedVFP > 16 to signal that some CPRCs were allocated on
|
|
|
|
// the stack.
|
|
|
|
AllocatedVFPs = 17;
|
2012-11-01 03:02:26 +08:00
|
|
|
return;
|
2014-02-11 17:25:50 +08:00
|
|
|
}
|
2012-11-01 03:02:26 +08:00
|
|
|
// C.1.vfp If the argument is a VFP CPRC and there are sufficient consecutive
|
|
|
|
// VFP registers of the appropriate type unallocated then the argument is
|
|
|
|
// allocated to the lowest-numbered sequence of such registers.
|
|
|
|
for (unsigned I = 0; I < 16; I += Alignment) {
|
|
|
|
bool FoundSlot = true;
|
|
|
|
for (unsigned J = I, JEnd = I + NumRequired; J < JEnd; J++)
|
|
|
|
if (J >= 16 || VFPRegs[J]) {
|
|
|
|
FoundSlot = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (FoundSlot) {
|
|
|
|
for (unsigned J = I, JEnd = I + NumRequired; J < JEnd; J++)
|
|
|
|
VFPRegs[J] = 1;
|
2014-02-11 17:25:50 +08:00
|
|
|
AllocatedVFPs += NumRequired;
|
2012-11-01 03:02:26 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// C.2.vfp If the argument is a VFP CPRC then any VFP registers that are
|
|
|
|
// unallocated are marked as unavailable.
|
|
|
|
for (unsigned I = 0; I < 16; I++)
|
|
|
|
VFPRegs[I] = 1;
|
2014-02-11 17:25:50 +08:00
|
|
|
AllocatedVFPs = 17; // We do not have enough VFP registers.
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Update AllocatedGPRs to record the number of general purpose registers
|
|
|
|
/// which have been allocated. It is valid for AllocatedGPRs to go above 4,
|
|
|
|
/// this represents arguments being stored on the stack.
|
|
|
|
void ARMABIInfo::markAllocatedGPRs(unsigned Alignment,
|
2014-06-27 21:59:27 +08:00
|
|
|
unsigned NumRequired) const {
|
2014-02-11 17:25:50 +08:00
|
|
|
assert((Alignment == 1 || Alignment == 2) && "Alignment must be 4 or 8 bytes");
|
|
|
|
|
|
|
|
if (Alignment == 2 && AllocatedGPRs & 0x1)
|
|
|
|
AllocatedGPRs += 1;
|
|
|
|
|
|
|
|
AllocatedGPRs += NumRequired;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARMABIInfo::resetAllocatedRegs(void) const {
|
|
|
|
AllocatedGPRs = 0;
|
|
|
|
AllocatedVFPs = 0;
|
|
|
|
for (unsigned i = 0; i < NumVFPs; ++i)
|
|
|
|
VFPRegs[i] = 0;
|
2012-11-01 03:02:26 +08:00
|
|
|
}
|
|
|
|
|
2014-05-10 00:21:39 +08:00
|
|
|
ABIArgInfo ARMABIInfo::classifyArgumentType(QualType Ty, bool isVariadic,
|
2014-02-11 17:25:50 +08:00
|
|
|
bool &IsCPRC) const {
|
2012-10-31 07:21:41 +08:00
|
|
|
// We update number of allocated VFPs according to
|
|
|
|
// 6.1.2.1 The following argument types are VFP CPRCs:
|
|
|
|
// A single-precision floating-point type (including promoted
|
|
|
|
// half-precision types); A double-precision floating-point type;
|
|
|
|
// A 64-bit or 128-bit containerized vector type; Homogeneous Aggregate
|
|
|
|
// with a Base Type of a single- or double-precision floating-point type,
|
|
|
|
// 64-bit containerized vectors or 128-bit containerized vectors with one
|
|
|
|
// to four Elements.
|
2014-11-08 06:30:50 +08:00
|
|
|
bool IsEffectivelyAAPCS_VFP = getABIKind() == AAPCS_VFP && !isVariadic;
|
2014-08-27 18:43:15 +08:00
|
|
|
|
2014-11-15 09:41:41 +08:00
|
|
|
Ty = useFirstFieldIfTransparentUnion(Ty);
|
|
|
|
|
2012-10-17 03:18:39 +08:00
|
|
|
// Handle illegal vector types here.
|
|
|
|
if (isIllegalVectorType(Ty)) {
|
|
|
|
uint64_t Size = getContext().getTypeSize(Ty);
|
|
|
|
if (Size <= 32) {
|
|
|
|
llvm::Type *ResType =
|
|
|
|
llvm::Type::getInt32Ty(getVMContext());
|
2014-02-11 17:25:50 +08:00
|
|
|
markAllocatedGPRs(1, 1);
|
2014-11-08 06:30:50 +08:00
|
|
|
return ABIArgInfo::getDirect(ResType);
|
2012-10-17 03:18:39 +08:00
|
|
|
}
|
|
|
|
if (Size == 64) {
|
|
|
|
llvm::Type *ResType = llvm::VectorType::get(
|
|
|
|
llvm::Type::getInt32Ty(getVMContext()), 2);
|
2014-02-11 17:25:50 +08:00
|
|
|
if (getABIKind() == ARMABIInfo::AAPCS || isVariadic){
|
|
|
|
markAllocatedGPRs(2, 2);
|
|
|
|
} else {
|
|
|
|
markAllocatedVFPs(2, 2);
|
|
|
|
IsCPRC = true;
|
|
|
|
}
|
2014-11-08 06:30:50 +08:00
|
|
|
return ABIArgInfo::getDirect(ResType);
|
2012-10-17 03:18:39 +08:00
|
|
|
}
|
|
|
|
if (Size == 128) {
|
|
|
|
llvm::Type *ResType = llvm::VectorType::get(
|
|
|
|
llvm::Type::getInt32Ty(getVMContext()), 4);
|
2014-02-11 17:25:50 +08:00
|
|
|
if (getABIKind() == ARMABIInfo::AAPCS || isVariadic) {
|
|
|
|
markAllocatedGPRs(2, 4);
|
|
|
|
} else {
|
|
|
|
markAllocatedVFPs(4, 4);
|
|
|
|
IsCPRC = true;
|
|
|
|
}
|
2014-11-08 06:30:50 +08:00
|
|
|
return ABIArgInfo::getDirect(ResType);
|
2012-10-17 03:18:39 +08:00
|
|
|
}
|
2014-02-11 17:25:50 +08:00
|
|
|
markAllocatedGPRs(1, 1);
|
2012-10-17 03:18:39 +08:00
|
|
|
return ABIArgInfo::getIndirect(0, /*ByVal=*/false);
|
|
|
|
}
|
2012-11-01 03:02:26 +08:00
|
|
|
// Update VFPRegs for legal vector types.
|
2014-02-11 17:25:50 +08:00
|
|
|
if (getABIKind() == ARMABIInfo::AAPCS_VFP && !isVariadic) {
|
|
|
|
if (const VectorType *VT = Ty->getAs<VectorType>()) {
|
|
|
|
uint64_t Size = getContext().getTypeSize(VT);
|
|
|
|
// Size of a legal vector should be power of 2 and above 64.
|
|
|
|
markAllocatedVFPs(Size >= 128 ? 4 : 2, Size / 32);
|
|
|
|
IsCPRC = true;
|
|
|
|
}
|
2012-10-31 07:21:41 +08:00
|
|
|
}
|
2012-11-01 03:02:26 +08:00
|
|
|
// Update VFPRegs for floating point types.
|
2014-02-11 17:25:50 +08:00
|
|
|
if (getABIKind() == ARMABIInfo::AAPCS_VFP && !isVariadic) {
|
|
|
|
if (const BuiltinType *BT = Ty->getAs<BuiltinType>()) {
|
|
|
|
if (BT->getKind() == BuiltinType::Half ||
|
|
|
|
BT->getKind() == BuiltinType::Float) {
|
|
|
|
markAllocatedVFPs(1, 1);
|
|
|
|
IsCPRC = true;
|
|
|
|
}
|
|
|
|
if (BT->getKind() == BuiltinType::Double ||
|
|
|
|
BT->getKind() == BuiltinType::LongDouble) {
|
|
|
|
markAllocatedVFPs(2, 2);
|
|
|
|
IsCPRC = true;
|
|
|
|
}
|
|
|
|
}
|
2012-10-31 07:21:41 +08:00
|
|
|
}
|
2012-10-17 03:18:39 +08:00
|
|
|
|
2010-08-22 18:59:02 +08:00
|
|
|
if (!isAggregateTypeForABI(Ty)) {
|
2010-02-03 04:10:50 +08:00
|
|
|
// Treat an enum type as its underlying type.
|
2014-02-11 17:25:50 +08:00
|
|
|
if (const EnumType *EnumTy = Ty->getAs<EnumType>()) {
|
2010-02-03 04:10:50 +08:00
|
|
|
Ty = EnumTy->getDecl()->getIntegerType();
|
2014-02-11 17:25:50 +08:00
|
|
|
}
|
2010-02-03 04:10:50 +08:00
|
|
|
|
2014-02-11 17:25:50 +08:00
|
|
|
unsigned Size = getContext().getTypeSize(Ty);
|
|
|
|
if (!IsCPRC)
|
|
|
|
markAllocatedGPRs(Size > 32 ? 2 : 1, (Size + 31) / 32);
|
2014-11-08 06:30:50 +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
|
|
|
|
2014-02-11 17:25:50 +08:00
|
|
|
if (CGCXXABI::RecordArgABI RAA = getRecordArgABI(Ty, getCXXABI())) {
|
|
|
|
markAllocatedGPRs(1, 1);
|
2013-06-22 06:49:34 +08:00
|
|
|
return ABIArgInfo::getIndirect(0, RAA == CGCXXABI::RAA_DirectInMemory);
|
2014-02-11 17:25:50 +08:00
|
|
|
}
|
2013-06-22 06:49:34 +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();
|
|
|
|
|
2014-11-08 06:30:50 +08:00
|
|
|
if (IsEffectivelyAAPCS_VFP) {
|
2012-10-31 07:21:41 +08:00
|
|
|
// Homogeneous Aggregates need to be expanded when we can fit the aggregate
|
|
|
|
// into VFP registers.
|
2014-05-21 13:09:00 +08:00
|
|
|
const Type *Base = nullptr;
|
2012-10-31 07:21:41 +08:00
|
|
|
uint64_t Members = 0;
|
2014-11-01 01:10:41 +08:00
|
|
|
if (isHomogeneousAggregate(Ty, Base, Members)) {
|
2012-04-13 19:22:00 +08:00
|
|
|
assert(Base && "Base class should be set for homogeneous aggregate");
|
2012-10-31 07:21:41 +08:00
|
|
|
// Base can be a floating-point or a vector.
|
|
|
|
if (Base->isVectorType()) {
|
|
|
|
// ElementSize is in number of floats.
|
|
|
|
unsigned ElementSize = getContext().getTypeSize(Base) == 64 ? 2 : 4;
|
2014-02-11 17:25:50 +08:00
|
|
|
markAllocatedVFPs(ElementSize,
|
2012-11-07 03:05:29 +08:00
|
|
|
Members * ElementSize);
|
2012-10-31 07:21:41 +08:00
|
|
|
} else if (Base->isSpecificBuiltinType(BuiltinType::Float))
|
2014-02-11 17:25:50 +08:00
|
|
|
markAllocatedVFPs(1, Members);
|
2012-10-31 07:21:41 +08:00
|
|
|
else {
|
|
|
|
assert(Base->isSpecificBuiltinType(BuiltinType::Double) ||
|
|
|
|
Base->isSpecificBuiltinType(BuiltinType::LongDouble));
|
2014-02-11 17:25:50 +08:00
|
|
|
markAllocatedVFPs(2, Members * 2);
|
2012-10-31 07:21:41 +08:00
|
|
|
}
|
2014-02-11 17:25:50 +08:00
|
|
|
IsCPRC = true;
|
2014-11-08 06:30:50 +08:00
|
|
|
return ABIArgInfo::getDirect(nullptr, 0, nullptr, false);
|
2012-04-13 19:22:00 +08:00
|
|
|
}
|
2011-08-03 13:58:22 +08:00
|
|
|
}
|
|
|
|
|
2012-08-14 05:23:55 +08:00
|
|
|
// Support byval for ARM.
|
2012-11-07 03:05:29 +08:00
|
|
|
// The ABI alignment for APCS is 4-byte and for AAPCS at least 4-byte and at
|
|
|
|
// most 8-byte. We realign the indirect argument if type alignment is bigger
|
|
|
|
// than ABI alignment.
|
2012-11-06 06:42:46 +08:00
|
|
|
uint64_t ABIAlign = 4;
|
|
|
|
uint64_t TyAlign = getContext().getTypeAlign(Ty) / 8;
|
|
|
|
if (getABIKind() == ARMABIInfo::AAPCS_VFP ||
|
|
|
|
getABIKind() == ARMABIInfo::AAPCS)
|
|
|
|
ABIAlign = std::min(std::max(TyAlign, (uint64_t)4), (uint64_t)8);
|
2012-11-06 12:58:01 +08:00
|
|
|
if (getContext().getTypeSizeInChars(Ty) > CharUnits::fromQuantity(64)) {
|
2014-06-27 21:59:27 +08:00
|
|
|
// Update Allocated GPRs. Since this is only used when the size of the
|
|
|
|
// argument is greater than 64 bytes, this will always use up any available
|
|
|
|
// registers (of which there are 4). We also don't care about getting the
|
|
|
|
// alignment right, because general-purpose registers cannot be back-filled.
|
|
|
|
markAllocatedGPRs(1, 4);
|
2014-03-12 22:02:50 +08:00
|
|
|
return ABIArgInfo::getIndirect(TyAlign, /*ByVal=*/true,
|
2012-11-07 03:05:29 +08:00
|
|
|
/*Realign=*/TyAlign > ABIAlign);
|
2012-08-09 08:31:40 +08:00
|
|
|
}
|
|
|
|
|
2010-09-23 09:54:28 +08:00
|
|
|
// Otherwise, pass by coercing to a structure of the appropriate size.
|
2011-07-18 12:24:23 +08:00
|
|
|
llvm::Type* ElemTy;
|
2009-06-06 06:08:42 +08:00
|
|
|
unsigned SizeRegs;
|
2012-08-09 08:31:40 +08:00
|
|
|
// FIXME: Try to match the types of the arguments more accurately where
|
|
|
|
// we can.
|
|
|
|
if (getContext().getTypeAlign(Ty) <= 32) {
|
2011-08-02 07:39:04 +08:00
|
|
|
ElemTy = llvm::Type::getInt32Ty(getVMContext());
|
|
|
|
SizeRegs = (getContext().getTypeSize(Ty) + 31) / 32;
|
2014-02-11 17:25:50 +08:00
|
|
|
markAllocatedGPRs(1, SizeRegs);
|
2012-06-26 06:04:00 +08:00
|
|
|
} else {
|
|
|
|
ElemTy = llvm::Type::getInt64Ty(getVMContext());
|
|
|
|
SizeRegs = (getContext().getTypeSize(Ty) + 63) / 64;
|
2014-02-11 17:25:50 +08:00
|
|
|
markAllocatedGPRs(2, SizeRegs * 2);
|
2009-06-06 06:08:42 +08:00
|
|
|
}
|
2011-04-29 02:16:06 +08:00
|
|
|
|
2014-11-08 06:30:50 +08:00
|
|
|
return ABIArgInfo::getDirect(llvm::ArrayType::get(ElemTy, SizeRegs));
|
2009-06-06 06:08:42 +08:00
|
|
|
}
|
|
|
|
|
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) {
|
2012-06-07 04:45:41 +08:00
|
|
|
const FieldDecl *FD = *i;
|
2009-09-13 16:03:58 +08:00
|
|
|
|
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-08-26 02:17:27 +08:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-02-11 17:25:50 +08:00
|
|
|
ABIArgInfo ARMABIInfo::classifyReturnType(QualType RetTy,
|
|
|
|
bool isVariadic) const {
|
2014-11-08 06:30:50 +08:00
|
|
|
bool IsEffectivelyAAPCS_VFP = getABIKind() == AAPCS_VFP && !isVariadic;
|
2014-08-27 18:43:15 +08:00
|
|
|
|
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-09-23 09:54:32 +08:00
|
|
|
// Large vector types should be returned via memory.
|
2014-02-11 17:25:50 +08:00
|
|
|
if (RetTy->isVectorType() && getContext().getTypeSize(RetTy) > 128) {
|
|
|
|
markAllocatedGPRs(1, 1);
|
2010-09-23 09:54:32 +08:00
|
|
|
return ABIArgInfo::getIndirect(0);
|
2014-02-11 17:25:50 +08:00
|
|
|
}
|
2010-09-23 09:54:32 +08:00
|
|
|
|
2010-08-22 18:59:02 +08:00
|
|
|
if (!isAggregateTypeForABI(RetTy)) {
|
2010-02-03 04:10:50 +08:00
|
|
|
// Treat an enum type as its underlying type.
|
|
|
|
if (const EnumType *EnumTy = RetTy->getAs<EnumType>())
|
|
|
|
RetTy = EnumTy->getDecl()->getIntegerType();
|
|
|
|
|
2014-11-08 06:30:50 +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
|
|
|
|
|
|
|
// 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())
|
2014-08-27 18:43:15 +08:00
|
|
|
return ABIArgInfo::getDirect(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)
|
Kill off the 'coerce' ABI passing form. Now 'direct' and 'extend' always
have a "coerce to" type which often matches the default lowering of Clang
type to LLVM IR type, but the coerce case can be handled by making them
not be the same.
This simplifies things and fixes issues where X86-64 abi lowering would
return coerce after making preferred types exactly match up. This caused
us to compile:
typedef float v4f32 __attribute__((__vector_size__(16)));
v4f32 foo(v4f32 X) {
return X+X;
}
into this code at -O0:
define <4 x float> @foo(<4 x float> %X.coerce) nounwind {
entry:
%retval = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=2]
%coerce = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=2]
%X.addr = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=3]
store <4 x float> %X.coerce, <4 x float>* %coerce
%X = load <4 x float>* %coerce ; <<4 x float>> [#uses=1]
store <4 x float> %X, <4 x float>* %X.addr
%tmp = load <4 x float>* %X.addr ; <<4 x float>> [#uses=1]
%tmp1 = load <4 x float>* %X.addr ; <<4 x float>> [#uses=1]
%add = fadd <4 x float> %tmp, %tmp1 ; <<4 x float>> [#uses=1]
store <4 x float> %add, <4 x float>* %retval
%0 = load <4 x float>* %retval ; <<4 x float>> [#uses=1]
ret <4 x float> %0
}
Now we get:
define <4 x float> @foo(<4 x float> %X) nounwind {
entry:
%X.addr = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=3]
store <4 x float> %X, <4 x float>* %X.addr
%tmp = load <4 x float>* %X.addr ; <<4 x float>> [#uses=1]
%tmp1 = load <4 x float>* %X.addr ; <<4 x float>> [#uses=1]
%add = fadd <4 x float> %tmp, %tmp1 ; <<4 x float>> [#uses=1]
ret <4 x float> %add
}
This implements rdar://8248065
llvm-svn: 109733
2010-07-29 14:26:06 +08:00
|
|
|
return ABIArgInfo::getDirect(llvm::Type::getInt8Ty(getVMContext()));
|
2009-09-13 16:03:58 +08:00
|
|
|
if (Size <= 16)
|
Kill off the 'coerce' ABI passing form. Now 'direct' and 'extend' always
have a "coerce to" type which often matches the default lowering of Clang
type to LLVM IR type, but the coerce case can be handled by making them
not be the same.
This simplifies things and fixes issues where X86-64 abi lowering would
return coerce after making preferred types exactly match up. This caused
us to compile:
typedef float v4f32 __attribute__((__vector_size__(16)));
v4f32 foo(v4f32 X) {
return X+X;
}
into this code at -O0:
define <4 x float> @foo(<4 x float> %X.coerce) nounwind {
entry:
%retval = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=2]
%coerce = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=2]
%X.addr = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=3]
store <4 x float> %X.coerce, <4 x float>* %coerce
%X = load <4 x float>* %coerce ; <<4 x float>> [#uses=1]
store <4 x float> %X, <4 x float>* %X.addr
%tmp = load <4 x float>* %X.addr ; <<4 x float>> [#uses=1]
%tmp1 = load <4 x float>* %X.addr ; <<4 x float>> [#uses=1]
%add = fadd <4 x float> %tmp, %tmp1 ; <<4 x float>> [#uses=1]
store <4 x float> %add, <4 x float>* %retval
%0 = load <4 x float>* %retval ; <<4 x float>> [#uses=1]
ret <4 x float> %0
}
Now we get:
define <4 x float> @foo(<4 x float> %X) nounwind {
entry:
%X.addr = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=3]
store <4 x float> %X, <4 x float>* %X.addr
%tmp = load <4 x float>* %X.addr ; <<4 x float>> [#uses=1]
%tmp1 = load <4 x float>* %X.addr ; <<4 x float>> [#uses=1]
%add = fadd <4 x float> %tmp, %tmp1 ; <<4 x float>> [#uses=1]
ret <4 x float> %add
}
This implements rdar://8248065
llvm-svn: 109733
2010-07-29 14:26:06 +08:00
|
|
|
return ABIArgInfo::getDirect(llvm::Type::getInt16Ty(getVMContext()));
|
|
|
|
return ABIArgInfo::getDirect(llvm::Type::getInt32Ty(getVMContext()));
|
2009-09-13 16:03:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise return in memory.
|
2014-02-11 17:25:50 +08:00
|
|
|
markAllocatedGPRs(1, 1);
|
2009-09-13 16:03:58 +08:00
|
|
|
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();
|
|
|
|
|
2011-11-02 12:51:36 +08:00
|
|
|
// Check for homogeneous aggregates with AAPCS-VFP.
|
2014-11-08 06:30:50 +08:00
|
|
|
if (IsEffectivelyAAPCS_VFP) {
|
2014-05-21 13:09:00 +08:00
|
|
|
const Type *Base = nullptr;
|
2014-11-01 01:10:41 +08:00
|
|
|
uint64_t Members;
|
|
|
|
if (isHomogeneousAggregate(RetTy, Base, Members)) {
|
2012-04-13 19:22:00 +08:00
|
|
|
assert(Base && "Base class should be set for homogeneous aggregate");
|
2011-11-02 12:51:36 +08:00
|
|
|
// Homogeneous Aggregates are returned directly.
|
2014-11-08 06:30:50 +08:00
|
|
|
return ABIArgInfo::getDirect(nullptr, 0, nullptr, false);
|
2012-04-13 19:22:00 +08:00
|
|
|
}
|
2011-11-02 12:51:36 +08:00
|
|
|
}
|
|
|
|
|
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) {
|
2014-07-03 17:28:12 +08:00
|
|
|
if (getDataLayout().isBigEndian())
|
|
|
|
// Return in 32 bit integer integer type (as if loaded by LDR, AAPCS 5.4)
|
2014-11-08 06:30:50 +08:00
|
|
|
return ABIArgInfo::getDirect(llvm::Type::getInt32Ty(getVMContext()));
|
2014-07-03 17:28:12 +08:00
|
|
|
|
2009-09-14 08:56:55 +08:00
|
|
|
// Return in the smallest viable integer type.
|
|
|
|
if (Size <= 8)
|
2014-11-08 06:30:50 +08:00
|
|
|
return ABIArgInfo::getDirect(llvm::Type::getInt8Ty(getVMContext()));
|
2009-09-14 08:56:55 +08:00
|
|
|
if (Size <= 16)
|
2014-11-08 06:30:50 +08:00
|
|
|
return ABIArgInfo::getDirect(llvm::Type::getInt16Ty(getVMContext()));
|
|
|
|
return ABIArgInfo::getDirect(llvm::Type::getInt32Ty(getVMContext()));
|
2009-09-14 08:56:55 +08:00
|
|
|
}
|
|
|
|
|
2014-02-11 17:25:50 +08:00
|
|
|
markAllocatedGPRs(1, 1);
|
2009-09-13 16:03:58 +08:00
|
|
|
return ABIArgInfo::getIndirect(0);
|
2009-06-06 06:08:42 +08:00
|
|
|
}
|
|
|
|
|
2012-10-17 03:18:39 +08:00
|
|
|
/// isIllegalVector - check whether Ty is an illegal vector type.
|
|
|
|
bool ARMABIInfo::isIllegalVectorType(QualType Ty) const {
|
|
|
|
if (const VectorType *VT = Ty->getAs<VectorType>()) {
|
|
|
|
// Check whether VT is legal.
|
|
|
|
unsigned NumElements = VT->getNumElements();
|
|
|
|
uint64_t Size = getContext().getTypeSize(VT);
|
|
|
|
// NumElements should be power of 2.
|
|
|
|
if ((NumElements & (NumElements - 1)) != 0)
|
|
|
|
return true;
|
|
|
|
// Size should be greater than 32 bits.
|
|
|
|
return Size <= 32;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-11-01 01:10:41 +08:00
|
|
|
bool ARMABIInfo::isHomogeneousAggregateBaseType(QualType Ty) const {
|
|
|
|
// Homogeneous aggregates for AAPCS-VFP must have base types of float,
|
|
|
|
// double, or 64-bit or 128-bit vectors.
|
|
|
|
if (const BuiltinType *BT = Ty->getAs<BuiltinType>()) {
|
|
|
|
if (BT->getKind() == BuiltinType::Float ||
|
|
|
|
BT->getKind() == BuiltinType::Double ||
|
|
|
|
BT->getKind() == BuiltinType::LongDouble)
|
|
|
|
return true;
|
|
|
|
} else if (const VectorType *VT = Ty->getAs<VectorType>()) {
|
|
|
|
unsigned VecSize = getContext().getTypeSize(VT);
|
|
|
|
if (VecSize == 64 || VecSize == 128)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ARMABIInfo::isHomogeneousAggregateSmallEnough(const Type *Base,
|
|
|
|
uint64_t Members) const {
|
|
|
|
return Members <= 4;
|
|
|
|
}
|
|
|
|
|
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 {
|
2012-02-07 08:39:47 +08:00
|
|
|
llvm::Type *BP = CGF.Int8PtrTy;
|
|
|
|
llvm::Type *BPP = CGF.Int8PtrPtrTy;
|
2009-06-06 06:08:42 +08:00
|
|
|
|
|
|
|
CGBuilderTy &Builder = CGF.Builder;
|
2012-02-07 08:39:47 +08:00
|
|
|
llvm::Value *VAListAddrAsBPP = Builder.CreateBitCast(VAListAddr, BPP, "ap");
|
2009-06-06 06:08:42 +08:00
|
|
|
llvm::Value *Addr = Builder.CreateLoad(VAListAddrAsBPP, "ap.cur");
|
2012-10-17 03:01:37 +08:00
|
|
|
|
2013-06-22 07:05:33 +08:00
|
|
|
if (isEmptyRecord(getContext(), Ty, true)) {
|
|
|
|
// These are ignored for parameter passing purposes.
|
|
|
|
llvm::Type *PTy = llvm::PointerType::getUnqual(CGF.ConvertType(Ty));
|
|
|
|
return Builder.CreateBitCast(Addr, PTy);
|
|
|
|
}
|
|
|
|
|
2012-10-17 03:01:37 +08:00
|
|
|
uint64_t Size = CGF.getContext().getTypeSize(Ty) / 8;
|
2011-08-03 06:33:37 +08:00
|
|
|
uint64_t TyAlign = CGF.getContext().getTypeAlign(Ty) / 8;
|
2012-10-17 03:18:39 +08:00
|
|
|
bool IsIndirect = false;
|
2012-10-17 03:01:37 +08:00
|
|
|
|
|
|
|
// The ABI alignment for 64-bit or 128-bit vectors is 8 for AAPCS and 4 for
|
|
|
|
// APCS. For AAPCS, the ABI alignment is at least 4-byte and at most 8-byte.
|
2012-10-17 03:51:48 +08:00
|
|
|
if (getABIKind() == ARMABIInfo::AAPCS_VFP ||
|
|
|
|
getABIKind() == ARMABIInfo::AAPCS)
|
|
|
|
TyAlign = std::min(std::max(TyAlign, (uint64_t)4), (uint64_t)8);
|
|
|
|
else
|
|
|
|
TyAlign = 4;
|
2012-10-17 03:18:39 +08:00
|
|
|
// Use indirect if size of the illegal vector is bigger than 16 bytes.
|
|
|
|
if (isIllegalVectorType(Ty) && Size > 16) {
|
|
|
|
IsIndirect = true;
|
|
|
|
Size = 4;
|
|
|
|
TyAlign = 4;
|
|
|
|
}
|
2012-10-17 03:01:37 +08:00
|
|
|
|
|
|
|
// Handle address alignment for ABI alignment > 4 bytes.
|
2011-08-03 06:33:37 +08:00
|
|
|
if (TyAlign > 4) {
|
|
|
|
assert((TyAlign & (TyAlign - 1)) == 0 &&
|
|
|
|
"Alignment is not power of 2!");
|
|
|
|
llvm::Value *AddrAsInt = Builder.CreatePtrToInt(Addr, CGF.Int32Ty);
|
|
|
|
AddrAsInt = Builder.CreateAdd(AddrAsInt, Builder.getInt32(TyAlign - 1));
|
|
|
|
AddrAsInt = Builder.CreateAnd(AddrAsInt, Builder.getInt32(~(TyAlign - 1)));
|
2012-10-17 03:01:37 +08:00
|
|
|
Addr = Builder.CreateIntToPtr(AddrAsInt, BP, "ap.align");
|
2011-08-03 06:33:37 +08:00
|
|
|
}
|
2009-06-06 06:08:42 +08:00
|
|
|
|
|
|
|
uint64_t Offset =
|
2012-10-17 03:01:37 +08:00
|
|
|
llvm::RoundUpToAlignment(Size, 4);
|
2009-06-06 06:08:42 +08:00
|
|
|
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);
|
|
|
|
|
2012-10-17 03:18:39 +08:00
|
|
|
if (IsIndirect)
|
|
|
|
Addr = Builder.CreateLoad(Builder.CreateBitCast(Addr, BPP));
|
2012-10-17 03:51:48 +08:00
|
|
|
else if (TyAlign < CGF.getContext().getTypeAlign(Ty) / 8) {
|
2012-10-17 03:01:37 +08:00
|
|
|
// We can't directly cast ap.cur to pointer to a vector type, since ap.cur
|
|
|
|
// may not be correctly aligned for the vector type. We create an aligned
|
|
|
|
// temporary space and copy the content over from ap.cur to the temporary
|
|
|
|
// space. This is necessary if the natural alignment of the type is greater
|
|
|
|
// than the ABI alignment.
|
|
|
|
llvm::Type *I8PtrTy = Builder.getInt8PtrTy();
|
|
|
|
CharUnits CharSize = getContext().getTypeSizeInChars(Ty);
|
|
|
|
llvm::Value *AlignedTemp = CGF.CreateTempAlloca(CGF.ConvertType(Ty),
|
|
|
|
"var.align");
|
|
|
|
llvm::Value *Dst = Builder.CreateBitCast(AlignedTemp, I8PtrTy);
|
|
|
|
llvm::Value *Src = Builder.CreateBitCast(Addr, I8PtrTy);
|
|
|
|
Builder.CreateMemCpy(Dst, Src,
|
|
|
|
llvm::ConstantInt::get(CGF.IntPtrTy, CharSize.getQuantity()),
|
|
|
|
TyAlign, false);
|
|
|
|
Addr = AlignedTemp; //The content is in aligned location.
|
|
|
|
}
|
|
|
|
llvm::Type *PTy =
|
|
|
|
llvm::PointerType::getUnqual(CGF.ConvertType(Ty));
|
|
|
|
llvm::Value *AddrTyped = Builder.CreateBitCast(Addr, PTy);
|
|
|
|
|
2009-06-06 06:08:42 +08:00
|
|
|
return AddrTyped;
|
|
|
|
}
|
|
|
|
|
2012-10-20 21:02:06 +08:00
|
|
|
namespace {
|
|
|
|
|
2012-10-17 06:30:41 +08:00
|
|
|
class NaClARMABIInfo : public ABIInfo {
|
|
|
|
public:
|
|
|
|
NaClARMABIInfo(CodeGen::CodeGenTypes &CGT, ARMABIInfo::ABIKind Kind)
|
|
|
|
: ABIInfo(CGT), PInfo(CGT), NInfo(CGT, Kind) {}
|
2014-03-12 14:41:41 +08:00
|
|
|
void computeInfo(CGFunctionInfo &FI) const override;
|
|
|
|
llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
|
|
|
|
CodeGenFunction &CGF) const override;
|
2012-10-17 06:30:41 +08:00
|
|
|
private:
|
|
|
|
PNaClABIInfo PInfo; // Used for generating calls with pnaclcall callingconv.
|
|
|
|
ARMABIInfo NInfo; // Used for everything else.
|
|
|
|
};
|
|
|
|
|
|
|
|
class NaClARMTargetCodeGenInfo : public TargetCodeGenInfo {
|
|
|
|
public:
|
|
|
|
NaClARMTargetCodeGenInfo(CodeGen::CodeGenTypes &CGT, ARMABIInfo::ABIKind Kind)
|
|
|
|
: TargetCodeGenInfo(new NaClARMABIInfo(CGT, Kind)) {}
|
|
|
|
};
|
|
|
|
|
2012-10-20 21:02:06 +08:00
|
|
|
}
|
|
|
|
|
2012-10-17 06:30:41 +08:00
|
|
|
void NaClARMABIInfo::computeInfo(CGFunctionInfo &FI) const {
|
|
|
|
if (FI.getASTCallingConvention() == CC_PnaclCall)
|
|
|
|
PInfo.computeInfo(FI);
|
|
|
|
else
|
|
|
|
static_cast<const ABIInfo&>(NInfo).computeInfo(FI);
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::Value *NaClARMABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
|
|
|
|
CodeGenFunction &CGF) const {
|
|
|
|
// Always use the native convention; calling pnacl-style varargs functions
|
|
|
|
// is unsupported.
|
|
|
|
return static_cast<const ABIInfo&>(NInfo).EmitVAArg(VAListAddr, Ty, CGF);
|
|
|
|
}
|
|
|
|
|
2011-04-22 19:10:38 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2012-05-25 01:43:12 +08:00
|
|
|
// NVPTX ABI Implementation
|
2011-04-22 19:10:38 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2012-05-25 01:43:12 +08:00
|
|
|
class NVPTXABIInfo : public ABIInfo {
|
2011-04-22 19:10:38 +08:00
|
|
|
public:
|
2013-03-30 22:38:24 +08:00
|
|
|
NVPTXABIInfo(CodeGenTypes &CGT) : ABIInfo(CGT) {}
|
2011-04-22 19:10:38 +08:00
|
|
|
|
|
|
|
ABIArgInfo classifyReturnType(QualType RetTy) const;
|
|
|
|
ABIArgInfo classifyArgumentType(QualType Ty) const;
|
|
|
|
|
2014-03-12 14:41:41 +08:00
|
|
|
void computeInfo(CGFunctionInfo &FI) const override;
|
|
|
|
llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
|
|
|
|
CodeGenFunction &CFG) const override;
|
2011-04-22 19:10:38 +08:00
|
|
|
};
|
|
|
|
|
2012-05-25 01:43:12 +08:00
|
|
|
class NVPTXTargetCodeGenInfo : public TargetCodeGenInfo {
|
2011-04-22 19:10:38 +08:00
|
|
|
public:
|
2012-05-25 01:43:12 +08:00
|
|
|
NVPTXTargetCodeGenInfo(CodeGenTypes &CGT)
|
|
|
|
: TargetCodeGenInfo(new NVPTXABIInfo(CGT)) {}
|
2014-03-12 14:41:41 +08:00
|
|
|
|
|
|
|
void SetTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
|
|
|
|
CodeGen::CodeGenModule &M) const override;
|
2013-03-30 22:38:24 +08:00
|
|
|
private:
|
2014-04-16 00:57:05 +08:00
|
|
|
// Adds a NamedMDNode with F, Name, and Operand as operands, and adds the
|
|
|
|
// resulting MDNode to the nvvm.annotations MDNode.
|
|
|
|
static void addNVVMMetadata(llvm::Function *F, StringRef Name, int Operand);
|
2011-04-22 19:10:38 +08:00
|
|
|
};
|
|
|
|
|
2012-05-25 01:43:12 +08:00
|
|
|
ABIArgInfo NVPTXABIInfo::classifyReturnType(QualType RetTy) const {
|
2011-04-22 19:10:38 +08:00
|
|
|
if (RetTy->isVoidType())
|
|
|
|
return ABIArgInfo::getIgnore();
|
2013-11-21 04:35:34 +08:00
|
|
|
|
|
|
|
// note: this is different from default ABI
|
|
|
|
if (!RetTy->isScalarType())
|
|
|
|
return ABIArgInfo::getDirect();
|
|
|
|
|
|
|
|
// 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());
|
2011-04-22 19:10:38 +08:00
|
|
|
}
|
|
|
|
|
2012-05-25 01:43:12 +08:00
|
|
|
ABIArgInfo NVPTXABIInfo::classifyArgumentType(QualType Ty) const {
|
2013-11-21 04:35:34 +08:00
|
|
|
// Treat an enum type as its underlying type.
|
|
|
|
if (const EnumType *EnumTy = Ty->getAs<EnumType>())
|
|
|
|
Ty = EnumTy->getDecl()->getIntegerType();
|
2011-04-22 19:10:38 +08:00
|
|
|
|
2014-10-29 21:43:21 +08:00
|
|
|
// Return aggregates type as indirect by value
|
|
|
|
if (isAggregateTypeForABI(Ty))
|
|
|
|
return ABIArgInfo::getIndirect(0, /* byval */ true);
|
|
|
|
|
2013-11-21 04:35:34 +08:00
|
|
|
return (Ty->isPromotableIntegerType() ?
|
|
|
|
ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
|
2011-04-22 19:10:38 +08:00
|
|
|
}
|
|
|
|
|
2012-05-25 01:43:12 +08:00
|
|
|
void NVPTXABIInfo::computeInfo(CGFunctionInfo &FI) const {
|
2014-05-14 06:05:45 +08:00
|
|
|
if (!getCXXABI().classifyReturnType(FI))
|
|
|
|
FI.getReturnInfo() = classifyReturnType(FI.getReturnType());
|
2014-03-18 02:10:01 +08:00
|
|
|
for (auto &I : FI.arguments())
|
|
|
|
I.info = classifyArgumentType(I.type);
|
2011-04-22 19:10:38 +08:00
|
|
|
|
|
|
|
// Always honor user-specified calling convention.
|
|
|
|
if (FI.getCallingConvention() != llvm::CallingConv::C)
|
|
|
|
return;
|
|
|
|
|
2013-03-01 03:01:20 +08:00
|
|
|
FI.setEffectiveCallingConvention(getRuntimeCC());
|
|
|
|
}
|
|
|
|
|
2012-05-25 01:43:12 +08:00
|
|
|
llvm::Value *NVPTXABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
|
|
|
|
CodeGenFunction &CFG) const {
|
|
|
|
llvm_unreachable("NVPTX does not support varargs");
|
2011-04-22 19:10:38 +08:00
|
|
|
}
|
|
|
|
|
2012-05-25 01:43:12 +08:00
|
|
|
void NVPTXTargetCodeGenInfo::
|
|
|
|
SetTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
|
|
|
|
CodeGen::CodeGenModule &M) const{
|
2011-10-06 01:58:44 +08:00
|
|
|
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D);
|
|
|
|
if (!FD) return;
|
|
|
|
|
|
|
|
llvm::Function *F = cast<llvm::Function>(GV);
|
|
|
|
|
|
|
|
// Perform special handling in OpenCL mode
|
2012-03-11 15:00:24 +08:00
|
|
|
if (M.getLangOpts().OpenCL) {
|
2013-03-30 22:38:24 +08:00
|
|
|
// Use OpenCL function attributes to check for kernel functions
|
2011-10-06 01:58:44 +08:00
|
|
|
// By default, all functions are device functions
|
|
|
|
if (FD->hasAttr<OpenCLKernelAttr>()) {
|
2013-03-30 22:38:24 +08:00
|
|
|
// OpenCL __kernel functions get kernel metadata
|
2014-04-16 00:57:05 +08:00
|
|
|
// Create !{<func-ref>, metadata !"kernel", i32 1} node
|
|
|
|
addNVVMMetadata(F, "kernel", 1);
|
2011-10-06 01:58:44 +08:00
|
|
|
// And kernel functions are not subject to inlining
|
2012-12-21 03:27:06 +08:00
|
|
|
F->addFnAttr(llvm::Attribute::NoInline);
|
2011-10-06 01:58:44 +08:00
|
|
|
}
|
2011-10-07 00:49:54 +08:00
|
|
|
}
|
2011-10-06 01:58:44 +08:00
|
|
|
|
2011-10-07 00:49:54 +08:00
|
|
|
// Perform special handling in CUDA mode.
|
2012-03-11 15:00:24 +08:00
|
|
|
if (M.getLangOpts().CUDA) {
|
2013-03-30 22:38:24 +08:00
|
|
|
// CUDA __global__ functions get a kernel metadata entry. Since
|
2011-10-07 00:49:54 +08:00
|
|
|
// __global__ functions cannot be called from the device, we do not
|
|
|
|
// need to set the noinline attribute.
|
2014-04-16 00:57:05 +08:00
|
|
|
if (FD->hasAttr<CUDAGlobalAttr>()) {
|
|
|
|
// Create !{<func-ref>, metadata !"kernel", i32 1} node
|
|
|
|
addNVVMMetadata(F, "kernel", 1);
|
|
|
|
}
|
|
|
|
if (FD->hasAttr<CUDALaunchBoundsAttr>()) {
|
|
|
|
// Create !{<func-ref>, metadata !"maxntidx", i32 <val>} node
|
|
|
|
addNVVMMetadata(F, "maxntidx",
|
|
|
|
FD->getAttr<CUDALaunchBoundsAttr>()->getMaxThreads());
|
|
|
|
// min blocks is a default argument for CUDALaunchBoundsAttr, so getting a
|
|
|
|
// zero value from getMinBlocks either means it was not specified in
|
|
|
|
// __launch_bounds__ or the user specified a 0 value. In both cases, we
|
|
|
|
// don't have to add a PTX directive.
|
|
|
|
int MinCTASM = FD->getAttr<CUDALaunchBoundsAttr>()->getMinBlocks();
|
|
|
|
if (MinCTASM > 0) {
|
|
|
|
// Create !{<func-ref>, metadata !"minctasm", i32 <val>} node
|
|
|
|
addNVVMMetadata(F, "minctasm", MinCTASM);
|
|
|
|
}
|
|
|
|
}
|
2011-10-06 01:58:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-16 00:57:05 +08:00
|
|
|
void NVPTXTargetCodeGenInfo::addNVVMMetadata(llvm::Function *F, StringRef Name,
|
|
|
|
int Operand) {
|
2013-03-30 22:38:24 +08:00
|
|
|
llvm::Module *M = F->getParent();
|
|
|
|
llvm::LLVMContext &Ctx = M->getContext();
|
|
|
|
|
|
|
|
// Get "nvvm.annotations" metadata node
|
|
|
|
llvm::NamedMDNode *MD = M->getOrInsertNamedMetadata("nvvm.annotations");
|
|
|
|
|
2014-12-10 02:39:32 +08:00
|
|
|
llvm::Metadata *MDVals[] = {
|
|
|
|
llvm::ConstantAsMetadata::get(F), llvm::MDString::get(Ctx, Name),
|
|
|
|
llvm::ConstantAsMetadata::get(
|
|
|
|
llvm::ConstantInt::get(llvm::Type::getInt32Ty(Ctx), Operand))};
|
2013-03-30 22:38:24 +08:00
|
|
|
// Append metadata to nvvm.annotations
|
|
|
|
MD->addOperand(llvm::MDNode::get(Ctx, MDVals));
|
|
|
|
}
|
2011-04-22 19:10:38 +08:00
|
|
|
}
|
|
|
|
|
2013-05-07 00:26:41 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// SystemZ ABI Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class SystemZABIInfo : public ABIInfo {
|
|
|
|
public:
|
|
|
|
SystemZABIInfo(CodeGenTypes &CGT) : ABIInfo(CGT) {}
|
|
|
|
|
|
|
|
bool isPromotableIntegerType(QualType Ty) const;
|
|
|
|
bool isCompoundType(QualType Ty) const;
|
|
|
|
bool isFPArgumentType(QualType Ty) const;
|
|
|
|
|
|
|
|
ABIArgInfo classifyReturnType(QualType RetTy) const;
|
|
|
|
ABIArgInfo classifyArgumentType(QualType ArgTy) const;
|
|
|
|
|
2014-03-12 14:41:41 +08:00
|
|
|
void computeInfo(CGFunctionInfo &FI) const override {
|
2014-05-14 06:05:45 +08:00
|
|
|
if (!getCXXABI().classifyReturnType(FI))
|
|
|
|
FI.getReturnInfo() = classifyReturnType(FI.getReturnType());
|
2014-03-18 02:10:01 +08:00
|
|
|
for (auto &I : FI.arguments())
|
|
|
|
I.info = classifyArgumentType(I.type);
|
2013-05-07 00:26:41 +08:00
|
|
|
}
|
|
|
|
|
2014-03-12 14:41:41 +08:00
|
|
|
llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
|
|
|
|
CodeGenFunction &CGF) const override;
|
2013-05-07 00:26:41 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class SystemZTargetCodeGenInfo : public TargetCodeGenInfo {
|
|
|
|
public:
|
|
|
|
SystemZTargetCodeGenInfo(CodeGenTypes &CGT)
|
|
|
|
: TargetCodeGenInfo(new SystemZABIInfo(CGT)) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SystemZABIInfo::isPromotableIntegerType(QualType Ty) const {
|
|
|
|
// Treat an enum type as its underlying type.
|
|
|
|
if (const EnumType *EnumTy = Ty->getAs<EnumType>())
|
|
|
|
Ty = EnumTy->getDecl()->getIntegerType();
|
|
|
|
|
|
|
|
// Promotable integer types are required to be promoted by the ABI.
|
|
|
|
if (Ty->isPromotableIntegerType())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// 32-bit values must also be promoted.
|
|
|
|
if (const BuiltinType *BT = Ty->getAs<BuiltinType>())
|
|
|
|
switch (BT->getKind()) {
|
|
|
|
case BuiltinType::Int:
|
|
|
|
case BuiltinType::UInt:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SystemZABIInfo::isCompoundType(QualType Ty) const {
|
|
|
|
return Ty->isAnyComplexType() || isAggregateTypeForABI(Ty);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SystemZABIInfo::isFPArgumentType(QualType Ty) const {
|
|
|
|
if (const BuiltinType *BT = Ty->getAs<BuiltinType>())
|
|
|
|
switch (BT->getKind()) {
|
|
|
|
case BuiltinType::Float:
|
|
|
|
case BuiltinType::Double:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (const RecordType *RT = Ty->getAsStructureType()) {
|
|
|
|
const RecordDecl *RD = RT->getDecl();
|
|
|
|
bool Found = false;
|
|
|
|
|
|
|
|
// If this is a C++ record, check the bases first.
|
|
|
|
if (const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD))
|
2014-03-13 23:41:46 +08:00
|
|
|
for (const auto &I : CXXRD->bases()) {
|
|
|
|
QualType Base = I.getType();
|
2013-05-07 00:26:41 +08:00
|
|
|
|
|
|
|
// Empty bases don't affect things either way.
|
|
|
|
if (isEmptyRecord(getContext(), Base, true))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (Found)
|
|
|
|
return false;
|
|
|
|
Found = isFPArgumentType(Base);
|
|
|
|
if (!Found)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check the fields.
|
2014-03-09 04:12:42 +08:00
|
|
|
for (const auto *FD : RD->fields()) {
|
2013-05-07 00:26:41 +08:00
|
|
|
// Empty bitfields don't affect things either way.
|
|
|
|
// Unlike isSingleElementStruct(), empty structure and array fields
|
|
|
|
// do count. So do anonymous bitfields that aren't zero-sized.
|
|
|
|
if (FD->isBitField() && FD->getBitWidthValue(getContext()) == 0)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Unlike isSingleElementStruct(), arrays do not count.
|
|
|
|
// Nested isFPArgumentType structures still do though.
|
|
|
|
if (Found)
|
|
|
|
return false;
|
|
|
|
Found = isFPArgumentType(FD->getType());
|
|
|
|
if (!Found)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unlike isSingleElementStruct(), trailing padding is allowed.
|
|
|
|
// An 8-byte aligned struct s { float f; } is passed as a double.
|
|
|
|
return Found;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::Value *SystemZABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
|
|
|
|
CodeGenFunction &CGF) const {
|
|
|
|
// Assume that va_list type is correct; should be pointer to LLVM type:
|
|
|
|
// struct {
|
|
|
|
// i64 __gpr;
|
|
|
|
// i64 __fpr;
|
|
|
|
// i8 *__overflow_arg_area;
|
|
|
|
// i8 *__reg_save_area;
|
|
|
|
// };
|
|
|
|
|
|
|
|
// Every argument occupies 8 bytes and is passed by preference in either
|
|
|
|
// GPRs or FPRs.
|
|
|
|
Ty = CGF.getContext().getCanonicalType(Ty);
|
|
|
|
ABIArgInfo AI = classifyArgumentType(Ty);
|
|
|
|
bool InFPRs = isFPArgumentType(Ty);
|
|
|
|
|
|
|
|
llvm::Type *APTy = llvm::PointerType::getUnqual(CGF.ConvertTypeForMem(Ty));
|
|
|
|
bool IsIndirect = AI.isIndirect();
|
|
|
|
unsigned UnpaddedBitSize;
|
|
|
|
if (IsIndirect) {
|
|
|
|
APTy = llvm::PointerType::getUnqual(APTy);
|
|
|
|
UnpaddedBitSize = 64;
|
|
|
|
} else
|
|
|
|
UnpaddedBitSize = getContext().getTypeSize(Ty);
|
|
|
|
unsigned PaddedBitSize = 64;
|
|
|
|
assert((UnpaddedBitSize <= PaddedBitSize) && "Invalid argument size.");
|
|
|
|
|
|
|
|
unsigned PaddedSize = PaddedBitSize / 8;
|
|
|
|
unsigned Padding = (PaddedBitSize - UnpaddedBitSize) / 8;
|
|
|
|
|
|
|
|
unsigned MaxRegs, RegCountField, RegSaveIndex, RegPadding;
|
|
|
|
if (InFPRs) {
|
|
|
|
MaxRegs = 4; // Maximum of 4 FPR arguments
|
|
|
|
RegCountField = 1; // __fpr
|
|
|
|
RegSaveIndex = 16; // save offset for f0
|
|
|
|
RegPadding = 0; // floats are passed in the high bits of an FPR
|
|
|
|
} else {
|
|
|
|
MaxRegs = 5; // Maximum of 5 GPR arguments
|
|
|
|
RegCountField = 0; // __gpr
|
|
|
|
RegSaveIndex = 2; // save offset for r2
|
|
|
|
RegPadding = Padding; // values are passed in the low bits of a GPR
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::Value *RegCountPtr =
|
|
|
|
CGF.Builder.CreateStructGEP(VAListAddr, RegCountField, "reg_count_ptr");
|
|
|
|
llvm::Value *RegCount = CGF.Builder.CreateLoad(RegCountPtr, "reg_count");
|
|
|
|
llvm::Type *IndexTy = RegCount->getType();
|
|
|
|
llvm::Value *MaxRegsV = llvm::ConstantInt::get(IndexTy, MaxRegs);
|
|
|
|
llvm::Value *InRegs = CGF.Builder.CreateICmpULT(RegCount, MaxRegsV,
|
2014-02-11 17:25:50 +08:00
|
|
|
"fits_in_regs");
|
2013-05-07 00:26:41 +08:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
// Work out the address of an argument register.
|
|
|
|
llvm::Value *PaddedSizeV = llvm::ConstantInt::get(IndexTy, PaddedSize);
|
|
|
|
llvm::Value *ScaledRegCount =
|
|
|
|
CGF.Builder.CreateMul(RegCount, PaddedSizeV, "scaled_reg_count");
|
|
|
|
llvm::Value *RegBase =
|
|
|
|
llvm::ConstantInt::get(IndexTy, RegSaveIndex * PaddedSize + RegPadding);
|
|
|
|
llvm::Value *RegOffset =
|
|
|
|
CGF.Builder.CreateAdd(ScaledRegCount, RegBase, "reg_offset");
|
|
|
|
llvm::Value *RegSaveAreaPtr =
|
|
|
|
CGF.Builder.CreateStructGEP(VAListAddr, 3, "reg_save_area_ptr");
|
|
|
|
llvm::Value *RegSaveArea =
|
|
|
|
CGF.Builder.CreateLoad(RegSaveAreaPtr, "reg_save_area");
|
|
|
|
llvm::Value *RawRegAddr =
|
|
|
|
CGF.Builder.CreateGEP(RegSaveArea, RegOffset, "raw_reg_addr");
|
|
|
|
llvm::Value *RegAddr =
|
|
|
|
CGF.Builder.CreateBitCast(RawRegAddr, APTy, "reg_addr");
|
|
|
|
|
|
|
|
// Update the register count
|
|
|
|
llvm::Value *One = llvm::ConstantInt::get(IndexTy, 1);
|
|
|
|
llvm::Value *NewRegCount =
|
|
|
|
CGF.Builder.CreateAdd(RegCount, One, "reg_count");
|
|
|
|
CGF.Builder.CreateStore(NewRegCount, RegCountPtr);
|
|
|
|
CGF.EmitBranch(ContBlock);
|
|
|
|
|
|
|
|
// Emit code to load the value if it was passed in memory.
|
|
|
|
CGF.EmitBlock(InMemBlock);
|
|
|
|
|
|
|
|
// Work out the address of a stack argument.
|
|
|
|
llvm::Value *OverflowArgAreaPtr =
|
|
|
|
CGF.Builder.CreateStructGEP(VAListAddr, 2, "overflow_arg_area_ptr");
|
|
|
|
llvm::Value *OverflowArgArea =
|
|
|
|
CGF.Builder.CreateLoad(OverflowArgAreaPtr, "overflow_arg_area");
|
|
|
|
llvm::Value *PaddingV = llvm::ConstantInt::get(IndexTy, Padding);
|
|
|
|
llvm::Value *RawMemAddr =
|
|
|
|
CGF.Builder.CreateGEP(OverflowArgArea, PaddingV, "raw_mem_addr");
|
|
|
|
llvm::Value *MemAddr =
|
|
|
|
CGF.Builder.CreateBitCast(RawMemAddr, APTy, "mem_addr");
|
|
|
|
|
|
|
|
// Update overflow_arg_area_ptr pointer
|
|
|
|
llvm::Value *NewOverflowArgArea =
|
|
|
|
CGF.Builder.CreateGEP(OverflowArgArea, PaddedSizeV, "overflow_arg_area");
|
|
|
|
CGF.Builder.CreateStore(NewOverflowArgArea, OverflowArgAreaPtr);
|
|
|
|
CGF.EmitBranch(ContBlock);
|
|
|
|
|
|
|
|
// Return the appropriate result.
|
|
|
|
CGF.EmitBlock(ContBlock);
|
|
|
|
llvm::PHINode *ResAddr = CGF.Builder.CreatePHI(APTy, 2, "va_arg.addr");
|
|
|
|
ResAddr->addIncoming(RegAddr, InRegBlock);
|
|
|
|
ResAddr->addIncoming(MemAddr, InMemBlock);
|
|
|
|
|
|
|
|
if (IsIndirect)
|
|
|
|
return CGF.Builder.CreateLoad(ResAddr, "indirect_arg");
|
|
|
|
|
|
|
|
return ResAddr;
|
|
|
|
}
|
|
|
|
|
|
|
|
ABIArgInfo SystemZABIInfo::classifyReturnType(QualType RetTy) const {
|
|
|
|
if (RetTy->isVoidType())
|
|
|
|
return ABIArgInfo::getIgnore();
|
|
|
|
if (isCompoundType(RetTy) || getContext().getTypeSize(RetTy) > 64)
|
|
|
|
return ABIArgInfo::getIndirect(0);
|
|
|
|
return (isPromotableIntegerType(RetTy) ?
|
|
|
|
ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
|
|
|
|
}
|
|
|
|
|
|
|
|
ABIArgInfo SystemZABIInfo::classifyArgumentType(QualType Ty) const {
|
|
|
|
// Handle the generic C++ ABI.
|
2013-10-06 09:33:34 +08:00
|
|
|
if (CGCXXABI::RecordArgABI RAA = getRecordArgABI(Ty, getCXXABI()))
|
2013-05-07 00:26:41 +08:00
|
|
|
return ABIArgInfo::getIndirect(0, RAA == CGCXXABI::RAA_DirectInMemory);
|
|
|
|
|
|
|
|
// Integers and enums are extended to full register width.
|
|
|
|
if (isPromotableIntegerType(Ty))
|
|
|
|
return ABIArgInfo::getExtend();
|
|
|
|
|
|
|
|
// Values that are not 1, 2, 4 or 8 bytes in size are passed indirectly.
|
|
|
|
uint64_t Size = getContext().getTypeSize(Ty);
|
|
|
|
if (Size != 8 && Size != 16 && Size != 32 && Size != 64)
|
2013-12-04 17:59:57 +08:00
|
|
|
return ABIArgInfo::getIndirect(0, /*ByVal=*/false);
|
2013-05-07 00:26:41 +08:00
|
|
|
|
|
|
|
// Handle small structures.
|
|
|
|
if (const RecordType *RT = Ty->getAs<RecordType>()) {
|
|
|
|
// Structures with flexible arrays have variable length, so really
|
|
|
|
// fail the size test above.
|
|
|
|
const RecordDecl *RD = RT->getDecl();
|
|
|
|
if (RD->hasFlexibleArrayMember())
|
2013-12-04 17:59:57 +08:00
|
|
|
return ABIArgInfo::getIndirect(0, /*ByVal=*/false);
|
2013-05-07 00:26:41 +08:00
|
|
|
|
|
|
|
// The structure is passed as an unextended integer, a float, or a double.
|
|
|
|
llvm::Type *PassTy;
|
|
|
|
if (isFPArgumentType(Ty)) {
|
|
|
|
assert(Size == 32 || Size == 64);
|
|
|
|
if (Size == 32)
|
|
|
|
PassTy = llvm::Type::getFloatTy(getVMContext());
|
|
|
|
else
|
|
|
|
PassTy = llvm::Type::getDoubleTy(getVMContext());
|
|
|
|
} else
|
|
|
|
PassTy = llvm::IntegerType::get(getVMContext(), Size);
|
|
|
|
return ABIArgInfo::getDirect(PassTy);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Non-structure compounds are passed indirectly.
|
|
|
|
if (isCompoundType(Ty))
|
2013-12-04 17:59:57 +08:00
|
|
|
return ABIArgInfo::getIndirect(0, /*ByVal=*/false);
|
2013-05-07 00:26:41 +08:00
|
|
|
|
2014-05-21 13:09:00 +08:00
|
|
|
return ABIArgInfo::getDirect(nullptr);
|
2013-05-07 00:26:41 +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,
|
2014-03-12 14:41:41 +08:00
|
|
|
CodeGen::CodeGenModule &M) const override;
|
2010-01-10 20:58:08 +08:00
|
|
|
};
|
|
|
|
|
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.
|
2012-12-21 03:27:06 +08:00
|
|
|
F->addFnAttr(llvm::Attribute::NoInline);
|
2010-01-10 20:58:08 +08:00
|
|
|
|
|
|
|
// Step 3: Emit ISR vector alias.
|
2012-11-27 02:59:10 +08:00
|
|
|
unsigned Num = attr->getNumber() / 2;
|
2014-05-18 05:30:14 +08:00
|
|
|
llvm::GlobalAlias::create(llvm::Function::ExternalLinkage,
|
|
|
|
"__isr_" + Twine(Num), F);
|
2010-01-10 20:58:08 +08:00
|
|
|
}
|
|
|
|
}
|
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 {
|
2011-06-02 08:09:17 +08:00
|
|
|
class MipsABIInfo : public ABIInfo {
|
2011-11-03 07:14:57 +08:00
|
|
|
bool IsO32;
|
2012-07-04 03:24:06 +08:00
|
|
|
unsigned MinABIStackAlignInBytes, StackAlignInBytes;
|
|
|
|
void CoerceToIntArgs(uint64_t TySize,
|
2013-07-06 03:34:19 +08:00
|
|
|
SmallVectorImpl<llvm::Type *> &ArgList) const;
|
2012-05-12 05:56:58 +08:00
|
|
|
llvm::Type* HandleAggregates(QualType Ty, uint64_t TySize) const;
|
2012-01-04 11:34:42 +08:00
|
|
|
llvm::Type* returnAggregateInRegs(QualType RetTy, uint64_t Size) const;
|
2012-01-10 03:31:25 +08:00
|
|
|
llvm::Type* getPaddingType(uint64_t Align, uint64_t Offset) const;
|
2011-06-02 08:09:17 +08:00
|
|
|
public:
|
2013-11-12 06:10:46 +08:00
|
|
|
MipsABIInfo(CodeGenTypes &CGT, bool _IsO32) :
|
2012-07-04 03:24:06 +08:00
|
|
|
ABIInfo(CGT), IsO32(_IsO32), MinABIStackAlignInBytes(IsO32 ? 4 : 8),
|
2013-11-12 06:10:46 +08:00
|
|
|
StackAlignInBytes(IsO32 ? 8 : 16) {}
|
2011-06-02 08:09:17 +08:00
|
|
|
|
|
|
|
ABIArgInfo classifyReturnType(QualType RetTy) const;
|
2012-01-07 08:25:33 +08:00
|
|
|
ABIArgInfo classifyArgumentType(QualType RetTy, uint64_t &Offset) const;
|
2014-03-12 14:41:41 +08:00
|
|
|
void computeInfo(CGFunctionInfo &FI) const override;
|
|
|
|
llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
|
|
|
|
CodeGenFunction &CGF) const override;
|
2011-06-02 08:09:17 +08:00
|
|
|
};
|
|
|
|
|
2010-05-27 14:19:26 +08:00
|
|
|
class MIPSTargetCodeGenInfo : public TargetCodeGenInfo {
|
2011-09-21 02:23:28 +08:00
|
|
|
unsigned SizeOfUnwindException;
|
2010-05-27 14:19:26 +08:00
|
|
|
public:
|
2013-11-12 06:10:46 +08:00
|
|
|
MIPSTargetCodeGenInfo(CodeGenTypes &CGT, bool IsO32)
|
|
|
|
: TargetCodeGenInfo(new MipsABIInfo(CGT, IsO32)),
|
2011-11-03 07:14:57 +08:00
|
|
|
SizeOfUnwindException(IsO32 ? 24 : 32) {}
|
2010-05-27 14:19:26 +08:00
|
|
|
|
2014-03-12 14:41:41 +08:00
|
|
|
int getDwarfEHStackPointer(CodeGen::CodeGenModule &CGM) const override {
|
2010-05-27 14:19:26 +08:00
|
|
|
return 29;
|
|
|
|
}
|
|
|
|
|
2013-01-17 01:10:28 +08:00
|
|
|
void SetTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
|
2014-03-12 14:41:41 +08:00
|
|
|
CodeGen::CodeGenModule &CGM) const override {
|
2013-03-14 04:40:30 +08:00
|
|
|
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D);
|
|
|
|
if (!FD) return;
|
2013-03-19 22:32:23 +08:00
|
|
|
llvm::Function *Fn = cast<llvm::Function>(GV);
|
2013-03-14 04:40:30 +08:00
|
|
|
if (FD->hasAttr<Mips16Attr>()) {
|
|
|
|
Fn->addFnAttr("mips16");
|
|
|
|
}
|
|
|
|
else if (FD->hasAttr<NoMips16Attr>()) {
|
|
|
|
Fn->addFnAttr("nomips16");
|
|
|
|
}
|
2013-01-17 01:10:28 +08:00
|
|
|
}
|
2013-03-14 04:40:30 +08:00
|
|
|
|
2010-05-27 14:19:26 +08:00
|
|
|
bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
|
2014-03-12 14:41:41 +08:00
|
|
|
llvm::Value *Address) const override;
|
2011-08-30 09:42:09 +08:00
|
|
|
|
2014-03-12 14:41:41 +08:00
|
|
|
unsigned getSizeOfUnwindException() const override {
|
2011-09-21 02:23:28 +08:00
|
|
|
return SizeOfUnwindException;
|
2011-08-30 09:42:09 +08:00
|
|
|
}
|
2010-05-27 14:19:26 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2012-07-04 03:24:06 +08:00
|
|
|
void MipsABIInfo::CoerceToIntArgs(uint64_t TySize,
|
2013-07-06 03:34:19 +08:00
|
|
|
SmallVectorImpl<llvm::Type *> &ArgList) const {
|
2012-07-04 03:24:06 +08:00
|
|
|
llvm::IntegerType *IntTy =
|
|
|
|
llvm::IntegerType::get(getVMContext(), MinABIStackAlignInBytes * 8);
|
2012-05-12 05:56:58 +08:00
|
|
|
|
|
|
|
// Add (TySize / MinABIStackAlignInBytes) args of IntTy.
|
|
|
|
for (unsigned N = TySize / (MinABIStackAlignInBytes * 8); N; --N)
|
|
|
|
ArgList.push_back(IntTy);
|
|
|
|
|
|
|
|
// If necessary, add one more integer type to ArgList.
|
|
|
|
unsigned R = TySize % (MinABIStackAlignInBytes * 8);
|
|
|
|
|
|
|
|
if (R)
|
|
|
|
ArgList.push_back(llvm::IntegerType::get(getVMContext(), R));
|
|
|
|
}
|
|
|
|
|
2011-11-03 07:54:49 +08:00
|
|
|
// In N32/64, an aligned double precision floating point field is passed in
|
|
|
|
// a register.
|
2012-05-12 05:56:58 +08:00
|
|
|
llvm::Type* MipsABIInfo::HandleAggregates(QualType Ty, uint64_t TySize) const {
|
2012-07-04 03:24:06 +08:00
|
|
|
SmallVector<llvm::Type*, 8> ArgList, IntArgList;
|
|
|
|
|
|
|
|
if (IsO32) {
|
|
|
|
CoerceToIntArgs(TySize, ArgList);
|
|
|
|
return llvm::StructType::get(getVMContext(), ArgList);
|
|
|
|
}
|
2011-11-03 07:54:49 +08:00
|
|
|
|
2012-01-12 08:52:17 +08:00
|
|
|
if (Ty->isComplexType())
|
|
|
|
return CGT.ConvertType(Ty);
|
2012-01-11 07:12:19 +08:00
|
|
|
|
2012-02-10 03:54:16 +08:00
|
|
|
const RecordType *RT = Ty->getAs<RecordType>();
|
2011-11-03 07:54:49 +08:00
|
|
|
|
2012-07-04 03:24:06 +08:00
|
|
|
// Unions/vectors are passed in integer registers.
|
|
|
|
if (!RT || !RT->isStructureOrClassType()) {
|
|
|
|
CoerceToIntArgs(TySize, ArgList);
|
|
|
|
return llvm::StructType::get(getVMContext(), ArgList);
|
|
|
|
}
|
2011-11-03 07:54:49 +08:00
|
|
|
|
|
|
|
const RecordDecl *RD = RT->getDecl();
|
|
|
|
const ASTRecordLayout &Layout = getContext().getASTRecordLayout(RD);
|
2012-05-12 05:56:58 +08:00
|
|
|
assert(!(TySize % 8) && "Size of structure must be multiple of 8.");
|
2011-11-03 07:54:49 +08:00
|
|
|
|
|
|
|
uint64_t LastOffset = 0;
|
|
|
|
unsigned idx = 0;
|
|
|
|
llvm::IntegerType *I64 = llvm::IntegerType::get(getVMContext(), 64);
|
|
|
|
|
2012-02-10 03:54:16 +08:00
|
|
|
// Iterate over fields in the struct/class and check if there are any aligned
|
|
|
|
// double fields.
|
2011-11-03 07:54:49 +08:00
|
|
|
for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end();
|
|
|
|
i != e; ++i, ++idx) {
|
2012-04-30 10:36:29 +08:00
|
|
|
const QualType Ty = i->getType();
|
2011-11-03 07:54:49 +08:00
|
|
|
const BuiltinType *BT = Ty->getAs<BuiltinType>();
|
|
|
|
|
|
|
|
if (!BT || BT->getKind() != BuiltinType::Double)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
uint64_t Offset = Layout.getFieldOffset(idx);
|
|
|
|
if (Offset % 64) // Ignore doubles that are not aligned.
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Add ((Offset - LastOffset) / 64) args of type i64.
|
|
|
|
for (unsigned j = (Offset - LastOffset) / 64; j > 0; --j)
|
|
|
|
ArgList.push_back(I64);
|
|
|
|
|
|
|
|
// Add double type.
|
|
|
|
ArgList.push_back(llvm::Type::getDoubleTy(getVMContext()));
|
|
|
|
LastOffset = Offset + 64;
|
|
|
|
}
|
|
|
|
|
2012-07-04 03:24:06 +08:00
|
|
|
CoerceToIntArgs(TySize - LastOffset, IntArgList);
|
|
|
|
ArgList.append(IntArgList.begin(), IntArgList.end());
|
2011-11-03 07:54:49 +08:00
|
|
|
|
|
|
|
return llvm::StructType::get(getVMContext(), ArgList);
|
|
|
|
}
|
|
|
|
|
2013-10-30 02:41:15 +08:00
|
|
|
llvm::Type *MipsABIInfo::getPaddingType(uint64_t OrigOffset,
|
|
|
|
uint64_t Offset) const {
|
|
|
|
if (OrigOffset + MinABIStackAlignInBytes > Offset)
|
2014-05-21 13:09:00 +08:00
|
|
|
return nullptr;
|
2012-01-10 03:31:25 +08:00
|
|
|
|
2013-10-30 02:41:15 +08:00
|
|
|
return llvm::IntegerType::get(getVMContext(), (Offset - OrigOffset) * 8);
|
2012-01-10 03:31:25 +08:00
|
|
|
}
|
2012-01-11 06:44:52 +08:00
|
|
|
|
2012-01-07 08:25:33 +08:00
|
|
|
ABIArgInfo
|
|
|
|
MipsABIInfo::classifyArgumentType(QualType Ty, uint64_t &Offset) const {
|
2012-01-10 03:31:25 +08:00
|
|
|
uint64_t OrigOffset = Offset;
|
2012-05-12 05:56:58 +08:00
|
|
|
uint64_t TySize = getContext().getTypeSize(Ty);
|
2012-01-10 03:31:25 +08:00
|
|
|
uint64_t Align = getContext().getTypeAlign(Ty) / 8;
|
2012-05-12 05:56:58 +08:00
|
|
|
|
2012-07-04 03:24:06 +08:00
|
|
|
Align = std::min(std::max(Align, (uint64_t)MinABIStackAlignInBytes),
|
|
|
|
(uint64_t)StackAlignInBytes);
|
2013-10-30 02:41:15 +08:00
|
|
|
unsigned CurrOffset = llvm::RoundUpToAlignment(Offset, Align);
|
|
|
|
Offset = CurrOffset + llvm::RoundUpToAlignment(TySize, Align * 8) / 8;
|
2012-01-10 03:31:25 +08:00
|
|
|
|
2012-07-04 03:24:06 +08:00
|
|
|
if (isAggregateTypeForABI(Ty) || Ty->isVectorType()) {
|
2011-06-02 08:09:17 +08:00
|
|
|
// Ignore empty aggregates.
|
2012-01-07 08:25:33 +08:00
|
|
|
if (TySize == 0)
|
2011-06-02 08:09:17 +08:00
|
|
|
return ABIArgInfo::getIgnore();
|
|
|
|
|
2013-10-06 09:33:34 +08:00
|
|
|
if (CGCXXABI::RecordArgABI RAA = getRecordArgABI(Ty, getCXXABI())) {
|
2012-05-12 05:56:58 +08:00
|
|
|
Offset = OrigOffset + MinABIStackAlignInBytes;
|
2013-04-17 20:54:10 +08:00
|
|
|
return ABIArgInfo::getIndirect(0, RAA == CGCXXABI::RAA_DirectInMemory);
|
2012-01-07 08:25:33 +08:00
|
|
|
}
|
2011-08-02 02:09:58 +08:00
|
|
|
|
2012-05-12 05:56:58 +08:00
|
|
|
// If we have reached here, aggregates are passed directly by coercing to
|
|
|
|
// another structure type. Padding is inserted if the offset of the
|
|
|
|
// aggregate is unaligned.
|
2014-10-24 23:30:16 +08:00
|
|
|
ABIArgInfo ArgInfo =
|
|
|
|
ABIArgInfo::getDirect(HandleAggregates(Ty, TySize), 0,
|
|
|
|
getPaddingType(OrigOffset, CurrOffset));
|
|
|
|
ArgInfo.setInReg(true);
|
|
|
|
return ArgInfo;
|
2011-06-02 08:09:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Treat an enum type as its underlying type.
|
|
|
|
if (const EnumType *EnumTy = Ty->getAs<EnumType>())
|
|
|
|
Ty = EnumTy->getDecl()->getIntegerType();
|
|
|
|
|
2014-10-24 22:42:42 +08:00
|
|
|
// All integral types are promoted to the GPR width.
|
|
|
|
if (Ty->isIntegralOrEnumerationType())
|
2012-01-10 03:31:25 +08:00
|
|
|
return ABIArgInfo::getExtend();
|
|
|
|
|
2013-10-30 02:41:15 +08:00
|
|
|
return ABIArgInfo::getDirect(
|
2014-05-21 13:09:00 +08:00
|
|
|
nullptr, 0, IsO32 ? nullptr : getPaddingType(OrigOffset, CurrOffset));
|
2011-06-02 08:09:17 +08:00
|
|
|
}
|
|
|
|
|
2012-01-04 11:34:42 +08:00
|
|
|
llvm::Type*
|
|
|
|
MipsABIInfo::returnAggregateInRegs(QualType RetTy, uint64_t Size) const {
|
2012-02-10 02:49:26 +08:00
|
|
|
const RecordType *RT = RetTy->getAs<RecordType>();
|
2012-07-04 03:24:06 +08:00
|
|
|
SmallVector<llvm::Type*, 8> RTList;
|
2012-01-04 11:34:42 +08:00
|
|
|
|
2012-02-10 02:49:26 +08:00
|
|
|
if (RT && RT->isStructureOrClassType()) {
|
2012-01-04 11:34:42 +08:00
|
|
|
const RecordDecl *RD = RT->getDecl();
|
2012-02-10 02:49:26 +08:00
|
|
|
const ASTRecordLayout &Layout = getContext().getASTRecordLayout(RD);
|
|
|
|
unsigned FieldCnt = Layout.getFieldCount();
|
|
|
|
|
|
|
|
// N32/64 returns struct/classes in floating point registers if the
|
|
|
|
// following conditions are met:
|
|
|
|
// 1. The size of the struct/class is no larger than 128-bit.
|
|
|
|
// 2. The struct/class has one or two fields all of which are floating
|
|
|
|
// point types.
|
|
|
|
// 3. The offset of the first field is zero (this follows what gcc does).
|
|
|
|
//
|
|
|
|
// Any other composite results are returned in integer registers.
|
|
|
|
//
|
|
|
|
if (FieldCnt && (FieldCnt <= 2) && !Layout.getFieldOffset(0)) {
|
|
|
|
RecordDecl::field_iterator b = RD->field_begin(), e = RD->field_end();
|
|
|
|
for (; b != e; ++b) {
|
2012-04-30 10:36:29 +08:00
|
|
|
const BuiltinType *BT = b->getType()->getAs<BuiltinType>();
|
2012-01-04 11:34:42 +08:00
|
|
|
|
2012-02-10 02:49:26 +08:00
|
|
|
if (!BT || !BT->isFloatingPoint())
|
|
|
|
break;
|
2012-01-04 11:34:42 +08:00
|
|
|
|
2012-04-30 10:36:29 +08:00
|
|
|
RTList.push_back(CGT.ConvertType(b->getType()));
|
2012-02-10 02:49:26 +08:00
|
|
|
}
|
2012-01-04 11:34:42 +08:00
|
|
|
|
2012-02-10 02:49:26 +08:00
|
|
|
if (b == e)
|
|
|
|
return llvm::StructType::get(getVMContext(), RTList,
|
|
|
|
RD->hasAttr<PackedAttr>());
|
2012-01-04 11:34:42 +08:00
|
|
|
|
2012-02-10 02:49:26 +08:00
|
|
|
RTList.clear();
|
|
|
|
}
|
2012-01-04 11:34:42 +08:00
|
|
|
}
|
|
|
|
|
2012-07-04 03:24:06 +08:00
|
|
|
CoerceToIntArgs(Size, RTList);
|
2012-01-04 11:34:42 +08:00
|
|
|
return llvm::StructType::get(getVMContext(), RTList);
|
|
|
|
}
|
|
|
|
|
2011-06-02 08:09:17 +08:00
|
|
|
ABIArgInfo MipsABIInfo::classifyReturnType(QualType RetTy) const {
|
2012-01-24 07:18:57 +08:00
|
|
|
uint64_t Size = getContext().getTypeSize(RetTy);
|
|
|
|
|
2014-09-04 21:28:14 +08:00
|
|
|
if (RetTy->isVoidType())
|
|
|
|
return ABIArgInfo::getIgnore();
|
|
|
|
|
|
|
|
// O32 doesn't treat zero-sized structs differently from other structs.
|
|
|
|
// However, N32/N64 ignores zero sized return values.
|
|
|
|
if (!IsO32 && Size == 0)
|
2011-06-02 08:09:17 +08:00
|
|
|
return ABIArgInfo::getIgnore();
|
|
|
|
|
2012-05-12 05:01:17 +08:00
|
|
|
if (isAggregateTypeForABI(RetTy) || RetTy->isVectorType()) {
|
2012-01-04 11:34:42 +08:00
|
|
|
if (Size <= 128) {
|
|
|
|
if (RetTy->isAnyComplexType())
|
|
|
|
return ABIArgInfo::getDirect();
|
|
|
|
|
2014-09-04 23:05:39 +08:00
|
|
|
// O32 returns integer vectors in registers and N32/N64 returns all small
|
2014-09-04 23:07:43 +08:00
|
|
|
// aggregates in registers.
|
2014-09-04 23:05:39 +08:00
|
|
|
if (!IsO32 ||
|
|
|
|
(RetTy->isVectorType() && !RetTy->hasFloatingRepresentation())) {
|
|
|
|
ABIArgInfo ArgInfo =
|
|
|
|
ABIArgInfo::getDirect(returnAggregateInRegs(RetTy, Size));
|
|
|
|
ArgInfo.setInReg(true);
|
|
|
|
return ArgInfo;
|
|
|
|
}
|
2012-01-04 11:34:42 +08:00
|
|
|
}
|
2011-06-02 08:09:17 +08:00
|
|
|
|
|
|
|
return ABIArgInfo::getIndirect(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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());
|
|
|
|
}
|
|
|
|
|
|
|
|
void MipsABIInfo::computeInfo(CGFunctionInfo &FI) const {
|
2012-01-12 09:10:09 +08:00
|
|
|
ABIArgInfo &RetInfo = FI.getReturnInfo();
|
2014-05-14 06:05:45 +08:00
|
|
|
if (!getCXXABI().classifyReturnType(FI))
|
|
|
|
RetInfo = classifyReturnType(FI.getReturnType());
|
2012-01-12 09:10:09 +08:00
|
|
|
|
|
|
|
// Check if a pointer to an aggregate is passed as a hidden argument.
|
2012-05-12 05:56:58 +08:00
|
|
|
uint64_t Offset = RetInfo.isIndirect() ? MinABIStackAlignInBytes : 0;
|
2012-01-12 09:10:09 +08:00
|
|
|
|
2014-03-18 02:10:01 +08:00
|
|
|
for (auto &I : FI.arguments())
|
|
|
|
I.info = classifyArgumentType(I.type, Offset);
|
2011-06-02 08:09:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
llvm::Value* MipsABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
|
|
|
|
CodeGenFunction &CGF) const {
|
2014-08-01 21:26:28 +08:00
|
|
|
llvm::Type *BP = CGF.Int8PtrTy;
|
|
|
|
llvm::Type *BPP = CGF.Int8PtrPtrTy;
|
2014-11-19 18:01:35 +08:00
|
|
|
|
|
|
|
// Integer arguments are promoted 32-bit on O32 and 64-bit on N32/N64.
|
|
|
|
unsigned SlotSizeInBits = IsO32 ? 32 : 64;
|
|
|
|
if (Ty->isIntegerType() &&
|
|
|
|
CGF.getContext().getIntWidth(Ty) < SlotSizeInBits) {
|
|
|
|
Ty = CGF.getContext().getIntTypeForBitwidth(SlotSizeInBits,
|
|
|
|
Ty->isSignedIntegerType());
|
|
|
|
}
|
2014-08-01 21:26:28 +08:00
|
|
|
|
|
|
|
CGBuilderTy &Builder = CGF.Builder;
|
|
|
|
llvm::Value *VAListAddrAsBPP = Builder.CreateBitCast(VAListAddr, BPP, "ap");
|
|
|
|
llvm::Value *Addr = Builder.CreateLoad(VAListAddrAsBPP, "ap.cur");
|
2014-09-22 21:27:06 +08:00
|
|
|
int64_t TypeAlign =
|
|
|
|
std::min(getContext().getTypeAlign(Ty) / 8, StackAlignInBytes);
|
2014-08-01 21:26:28 +08:00
|
|
|
llvm::Type *PTy = llvm::PointerType::getUnqual(CGF.ConvertType(Ty));
|
|
|
|
llvm::Value *AddrTyped;
|
|
|
|
unsigned PtrWidth = getTarget().getPointerWidth(0);
|
|
|
|
llvm::IntegerType *IntTy = (PtrWidth == 32) ? CGF.Int32Ty : CGF.Int64Ty;
|
|
|
|
|
|
|
|
if (TypeAlign > MinABIStackAlignInBytes) {
|
|
|
|
llvm::Value *AddrAsInt = CGF.Builder.CreatePtrToInt(Addr, IntTy);
|
|
|
|
llvm::Value *Inc = llvm::ConstantInt::get(IntTy, TypeAlign - 1);
|
|
|
|
llvm::Value *Mask = llvm::ConstantInt::get(IntTy, -TypeAlign);
|
|
|
|
llvm::Value *Add = CGF.Builder.CreateAdd(AddrAsInt, Inc);
|
|
|
|
llvm::Value *And = CGF.Builder.CreateAnd(Add, Mask);
|
|
|
|
AddrTyped = CGF.Builder.CreateIntToPtr(And, PTy);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
AddrTyped = Builder.CreateBitCast(Addr, PTy);
|
|
|
|
|
|
|
|
llvm::Value *AlignedAddr = Builder.CreateBitCast(AddrTyped, BP);
|
|
|
|
TypeAlign = std::max((unsigned)TypeAlign, MinABIStackAlignInBytes);
|
2014-11-19 18:01:35 +08:00
|
|
|
unsigned ArgSizeInBits = CGF.getContext().getTypeSize(Ty);
|
|
|
|
uint64_t Offset = llvm::RoundUpToAlignment(ArgSizeInBits / 8, TypeAlign);
|
2014-08-01 21:26:28 +08:00
|
|
|
llvm::Value *NextAddr =
|
|
|
|
Builder.CreateGEP(AlignedAddr, llvm::ConstantInt::get(IntTy, Offset),
|
|
|
|
"ap.next");
|
|
|
|
Builder.CreateStore(NextAddr, VAListAddrAsBPP);
|
|
|
|
|
|
|
|
return AddrTyped;
|
2011-06-02 08:09:17 +08:00
|
|
|
}
|
|
|
|
|
2010-05-27 14:19:26 +08:00
|
|
|
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.
|
|
|
|
|
|
|
|
// Everything on MIPS is 4 bytes. Double-precision FP registers
|
|
|
|
// are aliased to pairs of single-precision FP registers.
|
2012-02-07 08:39:47 +08:00
|
|
|
llvm::Value *Four8 = llvm::ConstantInt::get(CGF.Int8Ty, 4);
|
2010-05-27 14:19:26 +08:00
|
|
|
|
|
|
|
// 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.
|
2012-02-07 08:39:47 +08:00
|
|
|
AssignToArrayRange(CGF.Builder, Address, Four8, 0, 65);
|
2010-05-27 14:19:26 +08:00
|
|
|
|
|
|
|
// 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.
|
2012-02-07 08:39:47 +08:00
|
|
|
AssignToArrayRange(CGF.Builder, Address, Four8, 80, 181);
|
2010-05-27 14:19:26 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-10-14 00:24:41 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// TCE ABI Implementation (see http://tce.cs.tut.fi). Uses mostly the defaults.
|
|
|
|
// Currently subclassed only to implement custom OpenCL C function attribute
|
|
|
|
// handling.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class TCETargetCodeGenInfo : public DefaultTargetCodeGenInfo {
|
|
|
|
public:
|
|
|
|
TCETargetCodeGenInfo(CodeGenTypes &CGT)
|
|
|
|
: DefaultTargetCodeGenInfo(CGT) {}
|
|
|
|
|
2014-03-12 14:41:41 +08:00
|
|
|
void SetTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
|
|
|
|
CodeGen::CodeGenModule &M) const override;
|
2011-10-14 00:24:41 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
void TCETargetCodeGenInfo::SetTargetAttributes(const Decl *D,
|
|
|
|
llvm::GlobalValue *GV,
|
|
|
|
CodeGen::CodeGenModule &M) const {
|
|
|
|
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D);
|
|
|
|
if (!FD) return;
|
|
|
|
|
|
|
|
llvm::Function *F = cast<llvm::Function>(GV);
|
|
|
|
|
2012-03-11 15:00:24 +08:00
|
|
|
if (M.getLangOpts().OpenCL) {
|
2011-10-14 00:24:41 +08:00
|
|
|
if (FD->hasAttr<OpenCLKernelAttr>()) {
|
|
|
|
// OpenCL C Kernel functions are not subject to inlining
|
2012-12-21 03:27:06 +08:00
|
|
|
F->addFnAttr(llvm::Attribute::NoInline);
|
2013-12-19 21:16:35 +08:00
|
|
|
const ReqdWorkGroupSizeAttr *Attr = FD->getAttr<ReqdWorkGroupSizeAttr>();
|
|
|
|
if (Attr) {
|
2011-10-14 00:24:41 +08:00
|
|
|
// Convert the reqd_work_group_size() attributes to metadata.
|
|
|
|
llvm::LLVMContext &Context = F->getContext();
|
|
|
|
llvm::NamedMDNode *OpenCLMetadata =
|
|
|
|
M.getModule().getOrInsertNamedMetadata("opencl.kernel_wg_size_info");
|
|
|
|
|
2014-12-10 02:39:32 +08:00
|
|
|
SmallVector<llvm::Metadata *, 5> Operands;
|
|
|
|
Operands.push_back(llvm::ConstantAsMetadata::get(F));
|
2011-10-14 00:24:41 +08:00
|
|
|
|
2014-12-10 02:39:32 +08:00
|
|
|
Operands.push_back(
|
|
|
|
llvm::ConstantAsMetadata::get(llvm::Constant::getIntegerValue(
|
|
|
|
M.Int32Ty, llvm::APInt(32, Attr->getXDim()))));
|
|
|
|
Operands.push_back(
|
|
|
|
llvm::ConstantAsMetadata::get(llvm::Constant::getIntegerValue(
|
|
|
|
M.Int32Ty, llvm::APInt(32, Attr->getYDim()))));
|
|
|
|
Operands.push_back(
|
|
|
|
llvm::ConstantAsMetadata::get(llvm::Constant::getIntegerValue(
|
|
|
|
M.Int32Ty, llvm::APInt(32, Attr->getZDim()))));
|
2011-10-14 00:24:41 +08:00
|
|
|
|
|
|
|
// Add a boolean constant operand for "required" (true) or "hint" (false)
|
|
|
|
// for implementing the work_group_size_hint attr later. Currently
|
|
|
|
// always true as the hint is not yet implemented.
|
2014-12-10 02:39:32 +08:00
|
|
|
Operands.push_back(
|
|
|
|
llvm::ConstantAsMetadata::get(llvm::ConstantInt::getTrue(Context)));
|
2011-10-14 00:24:41 +08:00
|
|
|
OpenCLMetadata->addOperand(llvm::MDNode::get(Context, Operands));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2010-05-27 14:19:26 +08:00
|
|
|
|
2011-12-13 05:14:55 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Hexagon ABI Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class HexagonABIInfo : public ABIInfo {
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
HexagonABIInfo(CodeGenTypes &CGT) : ABIInfo(CGT) {}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
ABIArgInfo classifyReturnType(QualType RetTy) const;
|
|
|
|
ABIArgInfo classifyArgumentType(QualType RetTy) const;
|
|
|
|
|
2014-03-12 14:41:41 +08:00
|
|
|
void computeInfo(CGFunctionInfo &FI) const override;
|
2011-12-13 05:14:55 +08:00
|
|
|
|
2014-03-12 14:41:41 +08:00
|
|
|
llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
|
|
|
|
CodeGenFunction &CGF) const override;
|
2011-12-13 05:14:55 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class HexagonTargetCodeGenInfo : public TargetCodeGenInfo {
|
|
|
|
public:
|
|
|
|
HexagonTargetCodeGenInfo(CodeGenTypes &CGT)
|
|
|
|
:TargetCodeGenInfo(new HexagonABIInfo(CGT)) {}
|
|
|
|
|
2014-03-12 14:41:41 +08:00
|
|
|
int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const override {
|
2011-12-13 05:14:55 +08:00
|
|
|
return 29;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void HexagonABIInfo::computeInfo(CGFunctionInfo &FI) const {
|
2014-05-14 06:05:45 +08:00
|
|
|
if (!getCXXABI().classifyReturnType(FI))
|
|
|
|
FI.getReturnInfo() = classifyReturnType(FI.getReturnType());
|
2014-03-18 02:10:01 +08:00
|
|
|
for (auto &I : FI.arguments())
|
|
|
|
I.info = classifyArgumentType(I.type);
|
2011-12-13 05:14:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ABIArgInfo HexagonABIInfo::classifyArgumentType(QualType Ty) const {
|
|
|
|
if (!isAggregateTypeForABI(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());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ignore empty records.
|
|
|
|
if (isEmptyRecord(getContext(), Ty, true))
|
|
|
|
return ABIArgInfo::getIgnore();
|
|
|
|
|
2013-10-06 09:33:34 +08:00
|
|
|
if (CGCXXABI::RecordArgABI RAA = getRecordArgABI(Ty, getCXXABI()))
|
2013-04-17 20:54:10 +08:00
|
|
|
return ABIArgInfo::getIndirect(0, RAA == CGCXXABI::RAA_DirectInMemory);
|
2011-12-13 05:14:55 +08:00
|
|
|
|
|
|
|
uint64_t Size = getContext().getTypeSize(Ty);
|
|
|
|
if (Size > 64)
|
|
|
|
return ABIArgInfo::getIndirect(0, /*ByVal=*/true);
|
|
|
|
// Pass in the smallest viable integer type.
|
|
|
|
else if (Size > 32)
|
|
|
|
return ABIArgInfo::getDirect(llvm::Type::getInt64Ty(getVMContext()));
|
|
|
|
else if (Size > 16)
|
|
|
|
return ABIArgInfo::getDirect(llvm::Type::getInt32Ty(getVMContext()));
|
|
|
|
else if (Size > 8)
|
|
|
|
return ABIArgInfo::getDirect(llvm::Type::getInt16Ty(getVMContext()));
|
|
|
|
else
|
|
|
|
return ABIArgInfo::getDirect(llvm::Type::getInt8Ty(getVMContext()));
|
|
|
|
}
|
|
|
|
|
|
|
|
ABIArgInfo HexagonABIInfo::classifyReturnType(QualType RetTy) const {
|
|
|
|
if (RetTy->isVoidType())
|
|
|
|
return ABIArgInfo::getIgnore();
|
|
|
|
|
|
|
|
// Large vector types should be returned via memory.
|
|
|
|
if (RetTy->isVectorType() && getContext().getTypeSize(RetTy) > 64)
|
|
|
|
return ABIArgInfo::getIndirect(0);
|
|
|
|
|
|
|
|
if (!isAggregateTypeForABI(RetTy)) {
|
|
|
|
// 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());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isEmptyRecord(getContext(), RetTy, true))
|
|
|
|
return ABIArgInfo::getIgnore();
|
|
|
|
|
|
|
|
// Aggregates <= 8 bytes are returned in r0; other aggregates
|
|
|
|
// are returned indirectly.
|
|
|
|
uint64_t Size = getContext().getTypeSize(RetTy);
|
|
|
|
if (Size <= 64) {
|
|
|
|
// Return in the smallest viable integer type.
|
|
|
|
if (Size <= 8)
|
|
|
|
return ABIArgInfo::getDirect(llvm::Type::getInt8Ty(getVMContext()));
|
|
|
|
if (Size <= 16)
|
|
|
|
return ABIArgInfo::getDirect(llvm::Type::getInt16Ty(getVMContext()));
|
|
|
|
if (Size <= 32)
|
|
|
|
return ABIArgInfo::getDirect(llvm::Type::getInt32Ty(getVMContext()));
|
|
|
|
return ABIArgInfo::getDirect(llvm::Type::getInt64Ty(getVMContext()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return ABIArgInfo::getIndirect(0, /*ByVal=*/true);
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::Value *HexagonABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
|
2012-02-07 08:39:47 +08:00
|
|
|
CodeGenFunction &CGF) const {
|
2011-12-13 05:14:55 +08:00
|
|
|
// FIXME: Need to handle alignment
|
2012-02-07 08:39:47 +08:00
|
|
|
llvm::Type *BPP = CGF.Int8PtrPtrTy;
|
2011-12-13 05:14:55 +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 =
|
|
|
|
llvm::PointerType::getUnqual(CGF.ConvertType(Ty));
|
|
|
|
llvm::Value *AddrTyped = Builder.CreateBitCast(Addr, PTy);
|
|
|
|
|
|
|
|
uint64_t Offset =
|
|
|
|
llvm::RoundUpToAlignment(CGF.getContext().getTypeSize(Ty) / 8, 4);
|
|
|
|
llvm::Value *NextAddr =
|
|
|
|
Builder.CreateGEP(Addr, llvm::ConstantInt::get(CGF.Int32Ty, Offset),
|
|
|
|
"ap.next");
|
|
|
|
Builder.CreateStore(NextAddr, VAListAddrAsBPP);
|
|
|
|
|
|
|
|
return AddrTyped;
|
|
|
|
}
|
|
|
|
|
2014-12-05 04:38:18 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// AMDGPU ABI Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class AMDGPUTargetCodeGenInfo : public TargetCodeGenInfo {
|
|
|
|
public:
|
|
|
|
AMDGPUTargetCodeGenInfo(CodeGenTypes &CGT)
|
|
|
|
: TargetCodeGenInfo(new DefaultABIInfo(CGT)) {}
|
|
|
|
void SetTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
|
|
|
|
CodeGen::CodeGenModule &M) const override;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void AMDGPUTargetCodeGenInfo::SetTargetAttributes(
|
|
|
|
const Decl *D,
|
|
|
|
llvm::GlobalValue *GV,
|
|
|
|
CodeGen::CodeGenModule &M) const {
|
|
|
|
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D);
|
|
|
|
if (!FD)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (const auto Attr = FD->getAttr<AMDGPUNumVGPRAttr>()) {
|
|
|
|
llvm::Function *F = cast<llvm::Function>(GV);
|
|
|
|
uint32_t NumVGPR = Attr->getNumVGPR();
|
|
|
|
if (NumVGPR != 0)
|
|
|
|
F->addFnAttr("amdgpu_num_vgpr", llvm::utostr(NumVGPR));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (const auto Attr = FD->getAttr<AMDGPUNumSGPRAttr>()) {
|
|
|
|
llvm::Function *F = cast<llvm::Function>(GV);
|
|
|
|
unsigned NumSGPR = Attr->getNumSGPR();
|
|
|
|
if (NumSGPR != 0)
|
|
|
|
F->addFnAttr("amdgpu_num_sgpr", llvm::utostr(NumSGPR));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-13 05:14:55 +08:00
|
|
|
|
2013-05-28 05:48:25 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// SPARC v9 ABI Implementation.
|
|
|
|
// Based on the SPARC Compliance Definition version 2.4.1.
|
|
|
|
//
|
|
|
|
// Function arguments a mapped to a nominal "parameter array" and promoted to
|
|
|
|
// registers depending on their type. Each argument occupies 8 or 16 bytes in
|
|
|
|
// the array, structs larger than 16 bytes are passed indirectly.
|
|
|
|
//
|
|
|
|
// One case requires special care:
|
|
|
|
//
|
|
|
|
// struct mixed {
|
|
|
|
// int i;
|
|
|
|
// float f;
|
|
|
|
// };
|
|
|
|
//
|
|
|
|
// When a struct mixed is passed by value, it only occupies 8 bytes in the
|
|
|
|
// parameter array, but the int is passed in an integer register, and the float
|
|
|
|
// is passed in a floating point register. This is represented as two arguments
|
|
|
|
// with the LLVM IR inreg attribute:
|
|
|
|
//
|
|
|
|
// declare void f(i32 inreg %i, float inreg %f)
|
|
|
|
//
|
|
|
|
// The code generator will only allocate 4 bytes from the parameter array for
|
|
|
|
// the inreg arguments. All other arguments are allocated a multiple of 8
|
|
|
|
// bytes.
|
|
|
|
//
|
|
|
|
namespace {
|
|
|
|
class SparcV9ABIInfo : public ABIInfo {
|
|
|
|
public:
|
|
|
|
SparcV9ABIInfo(CodeGenTypes &CGT) : ABIInfo(CGT) {}
|
|
|
|
|
|
|
|
private:
|
|
|
|
ABIArgInfo classifyType(QualType RetTy, unsigned SizeLimit) const;
|
2014-03-12 14:41:41 +08:00
|
|
|
void computeInfo(CGFunctionInfo &FI) const override;
|
|
|
|
llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
|
|
|
|
CodeGenFunction &CGF) const override;
|
2013-05-28 12:57:37 +08:00
|
|
|
|
|
|
|
// Coercion type builder for structs passed in registers. The coercion type
|
|
|
|
// serves two purposes:
|
|
|
|
//
|
|
|
|
// 1. Pad structs to a multiple of 64 bits, so they are passed 'left-aligned'
|
|
|
|
// in registers.
|
|
|
|
// 2. Expose aligned floating point elements as first-level elements, so the
|
|
|
|
// code generator knows to pass them in floating point registers.
|
|
|
|
//
|
|
|
|
// We also compute the InReg flag which indicates that the struct contains
|
|
|
|
// aligned 32-bit floats.
|
|
|
|
//
|
|
|
|
struct CoerceBuilder {
|
|
|
|
llvm::LLVMContext &Context;
|
|
|
|
const llvm::DataLayout &DL;
|
|
|
|
SmallVector<llvm::Type*, 8> Elems;
|
|
|
|
uint64_t Size;
|
|
|
|
bool InReg;
|
|
|
|
|
|
|
|
CoerceBuilder(llvm::LLVMContext &c, const llvm::DataLayout &dl)
|
|
|
|
: Context(c), DL(dl), Size(0), InReg(false) {}
|
|
|
|
|
|
|
|
// Pad Elems with integers until Size is ToSize.
|
|
|
|
void pad(uint64_t ToSize) {
|
|
|
|
assert(ToSize >= Size && "Cannot remove elements");
|
|
|
|
if (ToSize == Size)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Finish the current 64-bit word.
|
|
|
|
uint64_t Aligned = llvm::RoundUpToAlignment(Size, 64);
|
|
|
|
if (Aligned > Size && Aligned <= ToSize) {
|
|
|
|
Elems.push_back(llvm::IntegerType::get(Context, Aligned - Size));
|
|
|
|
Size = Aligned;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add whole 64-bit words.
|
|
|
|
while (Size + 64 <= ToSize) {
|
|
|
|
Elems.push_back(llvm::Type::getInt64Ty(Context));
|
|
|
|
Size += 64;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Final in-word padding.
|
|
|
|
if (Size < ToSize) {
|
|
|
|
Elems.push_back(llvm::IntegerType::get(Context, ToSize - Size));
|
|
|
|
Size = ToSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add a floating point element at Offset.
|
|
|
|
void addFloat(uint64_t Offset, llvm::Type *Ty, unsigned Bits) {
|
|
|
|
// Unaligned floats are treated as integers.
|
|
|
|
if (Offset % Bits)
|
|
|
|
return;
|
|
|
|
// The InReg flag is only required if there are any floats < 64 bits.
|
|
|
|
if (Bits < 64)
|
|
|
|
InReg = true;
|
|
|
|
pad(Offset);
|
|
|
|
Elems.push_back(Ty);
|
|
|
|
Size = Offset + Bits;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add a struct type to the coercion type, starting at Offset (in bits).
|
|
|
|
void addStruct(uint64_t Offset, llvm::StructType *StrTy) {
|
|
|
|
const llvm::StructLayout *Layout = DL.getStructLayout(StrTy);
|
|
|
|
for (unsigned i = 0, e = StrTy->getNumElements(); i != e; ++i) {
|
|
|
|
llvm::Type *ElemTy = StrTy->getElementType(i);
|
|
|
|
uint64_t ElemOffset = Offset + Layout->getElementOffsetInBits(i);
|
|
|
|
switch (ElemTy->getTypeID()) {
|
|
|
|
case llvm::Type::StructTyID:
|
|
|
|
addStruct(ElemOffset, cast<llvm::StructType>(ElemTy));
|
|
|
|
break;
|
|
|
|
case llvm::Type::FloatTyID:
|
|
|
|
addFloat(ElemOffset, ElemTy, 32);
|
|
|
|
break;
|
|
|
|
case llvm::Type::DoubleTyID:
|
|
|
|
addFloat(ElemOffset, ElemTy, 64);
|
|
|
|
break;
|
|
|
|
case llvm::Type::FP128TyID:
|
|
|
|
addFloat(ElemOffset, ElemTy, 128);
|
|
|
|
break;
|
|
|
|
case llvm::Type::PointerTyID:
|
|
|
|
if (ElemOffset % 64 == 0) {
|
|
|
|
pad(ElemOffset);
|
|
|
|
Elems.push_back(ElemTy);
|
|
|
|
Size += 64;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if Ty is a usable substitute for the coercion type.
|
|
|
|
bool isUsableType(llvm::StructType *Ty) const {
|
|
|
|
if (Ty->getNumElements() != Elems.size())
|
|
|
|
return false;
|
|
|
|
for (unsigned i = 0, e = Elems.size(); i != e; ++i)
|
|
|
|
if (Elems[i] != Ty->getElementType(i))
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the coercion type as a literal struct type.
|
|
|
|
llvm::Type *getType() const {
|
|
|
|
if (Elems.size() == 1)
|
|
|
|
return Elems.front();
|
|
|
|
else
|
|
|
|
return llvm::StructType::get(Context, Elems);
|
|
|
|
}
|
|
|
|
};
|
2013-05-28 05:48:25 +08:00
|
|
|
};
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
|
|
|
ABIArgInfo
|
|
|
|
SparcV9ABIInfo::classifyType(QualType Ty, unsigned SizeLimit) const {
|
|
|
|
if (Ty->isVoidType())
|
|
|
|
return ABIArgInfo::getIgnore();
|
|
|
|
|
|
|
|
uint64_t Size = getContext().getTypeSize(Ty);
|
|
|
|
|
|
|
|
// Anything too big to fit in registers is passed with an explicit indirect
|
|
|
|
// pointer / sret pointer.
|
|
|
|
if (Size > SizeLimit)
|
|
|
|
return ABIArgInfo::getIndirect(0, /*ByVal=*/false);
|
|
|
|
|
|
|
|
// Treat an enum type as its underlying type.
|
|
|
|
if (const EnumType *EnumTy = Ty->getAs<EnumType>())
|
|
|
|
Ty = EnumTy->getDecl()->getIntegerType();
|
|
|
|
|
|
|
|
// Integer types smaller than a register are extended.
|
|
|
|
if (Size < 64 && Ty->isIntegerType())
|
|
|
|
return ABIArgInfo::getExtend();
|
|
|
|
|
|
|
|
// Other non-aggregates go in registers.
|
|
|
|
if (!isAggregateTypeForABI(Ty))
|
|
|
|
return ABIArgInfo::getDirect();
|
|
|
|
|
2014-01-12 14:54:56 +08:00
|
|
|
// If a C++ object has either a non-trivial copy constructor or a non-trivial
|
|
|
|
// destructor, it is passed with an explicit indirect pointer / sret pointer.
|
|
|
|
if (CGCXXABI::RecordArgABI RAA = getRecordArgABI(Ty, getCXXABI()))
|
|
|
|
return ABIArgInfo::getIndirect(0, RAA == CGCXXABI::RAA_DirectInMemory);
|
|
|
|
|
2013-05-28 05:48:25 +08:00
|
|
|
// This is a small aggregate type that should be passed in registers.
|
2013-05-28 12:57:37 +08:00
|
|
|
// Build a coercion type from the LLVM struct type.
|
|
|
|
llvm::StructType *StrTy = dyn_cast<llvm::StructType>(CGT.ConvertType(Ty));
|
|
|
|
if (!StrTy)
|
|
|
|
return ABIArgInfo::getDirect();
|
|
|
|
|
|
|
|
CoerceBuilder CB(getVMContext(), getDataLayout());
|
|
|
|
CB.addStruct(0, StrTy);
|
|
|
|
CB.pad(llvm::RoundUpToAlignment(CB.DL.getTypeSizeInBits(StrTy), 64));
|
|
|
|
|
|
|
|
// Try to use the original type for coercion.
|
|
|
|
llvm::Type *CoerceTy = CB.isUsableType(StrTy) ? StrTy : CB.getType();
|
|
|
|
|
|
|
|
if (CB.InReg)
|
|
|
|
return ABIArgInfo::getDirectInReg(CoerceTy);
|
|
|
|
else
|
|
|
|
return ABIArgInfo::getDirect(CoerceTy);
|
2013-05-28 05:48:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
llvm::Value *SparcV9ABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
|
|
|
|
CodeGenFunction &CGF) const {
|
2013-06-05 11:00:18 +08:00
|
|
|
ABIArgInfo AI = classifyType(Ty, 16 * 8);
|
|
|
|
llvm::Type *ArgTy = CGT.ConvertType(Ty);
|
|
|
|
if (AI.canHaveCoerceToType() && !AI.getCoerceToType())
|
|
|
|
AI.setCoerceToType(ArgTy);
|
|
|
|
|
|
|
|
llvm::Type *BPP = CGF.Int8PtrPtrTy;
|
|
|
|
CGBuilderTy &Builder = CGF.Builder;
|
|
|
|
llvm::Value *VAListAddrAsBPP = Builder.CreateBitCast(VAListAddr, BPP, "ap");
|
|
|
|
llvm::Value *Addr = Builder.CreateLoad(VAListAddrAsBPP, "ap.cur");
|
|
|
|
llvm::Type *ArgPtrTy = llvm::PointerType::getUnqual(ArgTy);
|
|
|
|
llvm::Value *ArgAddr;
|
|
|
|
unsigned Stride;
|
|
|
|
|
|
|
|
switch (AI.getKind()) {
|
|
|
|
case ABIArgInfo::Expand:
|
2014-02-01 08:04:45 +08:00
|
|
|
case ABIArgInfo::InAlloca:
|
2013-06-05 11:00:18 +08:00
|
|
|
llvm_unreachable("Unsupported ABI kind for va_arg");
|
|
|
|
|
|
|
|
case ABIArgInfo::Extend:
|
|
|
|
Stride = 8;
|
|
|
|
ArgAddr = Builder
|
|
|
|
.CreateConstGEP1_32(Addr, 8 - getDataLayout().getTypeAllocSize(ArgTy),
|
|
|
|
"extend");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ABIArgInfo::Direct:
|
|
|
|
Stride = getDataLayout().getTypeAllocSize(AI.getCoerceToType());
|
|
|
|
ArgAddr = Addr;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ABIArgInfo::Indirect:
|
|
|
|
Stride = 8;
|
|
|
|
ArgAddr = Builder.CreateBitCast(Addr,
|
|
|
|
llvm::PointerType::getUnqual(ArgPtrTy),
|
|
|
|
"indirect");
|
|
|
|
ArgAddr = Builder.CreateLoad(ArgAddr, "indirect.arg");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ABIArgInfo::Ignore:
|
|
|
|
return llvm::UndefValue::get(ArgPtrTy);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update VAList.
|
|
|
|
Addr = Builder.CreateConstGEP1_32(Addr, Stride, "ap.next");
|
|
|
|
Builder.CreateStore(Addr, VAListAddrAsBPP);
|
|
|
|
|
|
|
|
return Builder.CreatePointerCast(ArgAddr, ArgPtrTy, "arg.addr");
|
2013-05-28 05:48:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SparcV9ABIInfo::computeInfo(CGFunctionInfo &FI) const {
|
|
|
|
FI.getReturnInfo() = classifyType(FI.getReturnType(), 32 * 8);
|
2014-03-18 02:10:01 +08:00
|
|
|
for (auto &I : FI.arguments())
|
|
|
|
I.info = classifyType(I.type, 16 * 8);
|
2013-05-28 05:48:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
class SparcV9TargetCodeGenInfo : public TargetCodeGenInfo {
|
|
|
|
public:
|
|
|
|
SparcV9TargetCodeGenInfo(CodeGenTypes &CGT)
|
|
|
|
: TargetCodeGenInfo(new SparcV9ABIInfo(CGT)) {}
|
2014-02-25 02:46:27 +08:00
|
|
|
|
2014-03-12 14:41:41 +08:00
|
|
|
int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const override {
|
2014-02-25 02:46:27 +08:00
|
|
|
return 14;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
|
2014-03-12 14:41:41 +08:00
|
|
|
llvm::Value *Address) const override;
|
2013-05-28 05:48:25 +08:00
|
|
|
};
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
2014-02-25 02:46:27 +08:00
|
|
|
bool
|
|
|
|
SparcV9TargetCodeGenInfo::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::IntegerType *i8 = CGF.Int8Ty;
|
|
|
|
llvm::Value *Four8 = llvm::ConstantInt::get(i8, 4);
|
|
|
|
llvm::Value *Eight8 = llvm::ConstantInt::get(i8, 8);
|
|
|
|
|
|
|
|
// 0-31: the 8-byte general-purpose registers
|
|
|
|
AssignToArrayRange(Builder, Address, Eight8, 0, 31);
|
|
|
|
|
|
|
|
// 32-63: f0-31, the 4-byte floating-point registers
|
|
|
|
AssignToArrayRange(Builder, Address, Four8, 32, 63);
|
|
|
|
|
|
|
|
// Y = 64
|
|
|
|
// PSR = 65
|
|
|
|
// WIM = 66
|
|
|
|
// TBR = 67
|
|
|
|
// PC = 68
|
|
|
|
// NPC = 69
|
|
|
|
// FSR = 70
|
|
|
|
// CSR = 71
|
|
|
|
AssignToArrayRange(Builder, Address, Eight8, 64, 71);
|
|
|
|
|
|
|
|
// 72-87: d0-15, the 8-byte floating-point registers
|
|
|
|
AssignToArrayRange(Builder, Address, Eight8, 72, 87);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-05-28 05:48:25 +08:00
|
|
|
|
2013-08-13 17:43:10 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2014-03-03 21:45:29 +08:00
|
|
|
// XCore ABI Implementation
|
2013-08-13 17:43:10 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2014-05-02 17:33:20 +08:00
|
|
|
|
2013-08-13 17:43:10 +08:00
|
|
|
namespace {
|
2014-05-02 17:33:20 +08:00
|
|
|
|
|
|
|
/// A SmallStringEnc instance is used to build up the TypeString by passing
|
|
|
|
/// it by reference between functions that append to it.
|
|
|
|
typedef llvm::SmallString<128> SmallStringEnc;
|
|
|
|
|
|
|
|
/// TypeStringCache caches the meta encodings of Types.
|
|
|
|
///
|
|
|
|
/// The reason for caching TypeStrings is two fold:
|
|
|
|
/// 1. To cache a type's encoding for later uses;
|
|
|
|
/// 2. As a means to break recursive member type inclusion.
|
|
|
|
///
|
|
|
|
/// A cache Entry can have a Status of:
|
|
|
|
/// NonRecursive: The type encoding is not recursive;
|
|
|
|
/// Recursive: The type encoding is recursive;
|
|
|
|
/// Incomplete: An incomplete TypeString;
|
|
|
|
/// IncompleteUsed: An incomplete TypeString that has been used in a
|
|
|
|
/// Recursive type encoding.
|
|
|
|
///
|
|
|
|
/// A NonRecursive entry will have all of its sub-members expanded as fully
|
|
|
|
/// as possible. Whilst it may contain types which are recursive, the type
|
|
|
|
/// itself is not recursive and thus its encoding may be safely used whenever
|
|
|
|
/// the type is encountered.
|
|
|
|
///
|
|
|
|
/// A Recursive entry will have all of its sub-members expanded as fully as
|
|
|
|
/// possible. The type itself is recursive and it may contain other types which
|
|
|
|
/// are recursive. The Recursive encoding must not be used during the expansion
|
|
|
|
/// of a recursive type's recursive branch. For simplicity the code uses
|
|
|
|
/// IncompleteCount to reject all usage of Recursive encodings for member types.
|
|
|
|
///
|
|
|
|
/// An Incomplete entry is always a RecordType and only encodes its
|
|
|
|
/// identifier e.g. "s(S){}". Incomplete 'StubEnc' entries are ephemeral and
|
|
|
|
/// are placed into the cache during type expansion as a means to identify and
|
|
|
|
/// handle recursive inclusion of types as sub-members. If there is recursion
|
|
|
|
/// the entry becomes IncompleteUsed.
|
|
|
|
///
|
|
|
|
/// During the expansion of a RecordType's members:
|
|
|
|
///
|
|
|
|
/// If the cache contains a NonRecursive encoding for the member type, the
|
|
|
|
/// cached encoding is used;
|
|
|
|
///
|
|
|
|
/// If the cache contains a Recursive encoding for the member type, the
|
|
|
|
/// cached encoding is 'Swapped' out, as it may be incorrect, and...
|
|
|
|
///
|
|
|
|
/// If the member is a RecordType, an Incomplete encoding is placed into the
|
|
|
|
/// cache to break potential recursive inclusion of itself as a sub-member;
|
|
|
|
///
|
|
|
|
/// Once a member RecordType has been expanded, its temporary incomplete
|
|
|
|
/// entry is removed from the cache. If a Recursive encoding was swapped out
|
|
|
|
/// it is swapped back in;
|
|
|
|
///
|
|
|
|
/// If an incomplete entry is used to expand a sub-member, the incomplete
|
|
|
|
/// entry is marked as IncompleteUsed. The cache keeps count of how many
|
|
|
|
/// IncompleteUsed entries it currently contains in IncompleteUsedCount;
|
|
|
|
///
|
|
|
|
/// If a member's encoding is found to be a NonRecursive or Recursive viz:
|
|
|
|
/// IncompleteUsedCount==0, the member's encoding is added to the cache.
|
|
|
|
/// Else the member is part of a recursive type and thus the recursion has
|
|
|
|
/// been exited too soon for the encoding to be correct for the member.
|
|
|
|
///
|
|
|
|
class TypeStringCache {
|
|
|
|
enum Status {NonRecursive, Recursive, Incomplete, IncompleteUsed};
|
|
|
|
struct Entry {
|
|
|
|
std::string Str; // The encoded TypeString for the type.
|
|
|
|
enum Status State; // Information about the encoding in 'Str'.
|
|
|
|
std::string Swapped; // A temporary place holder for a Recursive encoding
|
|
|
|
// during the expansion of RecordType's members.
|
|
|
|
};
|
|
|
|
std::map<const IdentifierInfo *, struct Entry> Map;
|
|
|
|
unsigned IncompleteCount; // Number of Incomplete entries in the Map.
|
|
|
|
unsigned IncompleteUsedCount; // Number of IncompleteUsed entries in the Map.
|
|
|
|
public:
|
2014-05-06 17:38:54 +08:00
|
|
|
TypeStringCache() : IncompleteCount(0), IncompleteUsedCount(0) {};
|
2014-05-02 17:33:20 +08:00
|
|
|
void addIncomplete(const IdentifierInfo *ID, std::string StubEnc);
|
|
|
|
bool removeIncomplete(const IdentifierInfo *ID);
|
|
|
|
void addIfComplete(const IdentifierInfo *ID, StringRef Str,
|
|
|
|
bool IsRecursive);
|
|
|
|
StringRef lookupStr(const IdentifierInfo *ID);
|
|
|
|
};
|
|
|
|
|
2014-05-20 15:19:33 +08:00
|
|
|
/// TypeString encodings for enum & union fields must be order.
|
2014-05-02 17:33:20 +08:00
|
|
|
/// FieldEncoding is a helper for this ordering process.
|
|
|
|
class FieldEncoding {
|
|
|
|
bool HasName;
|
|
|
|
std::string Enc;
|
|
|
|
public:
|
|
|
|
FieldEncoding(bool b, SmallStringEnc &e) : HasName(b), Enc(e.c_str()) {};
|
|
|
|
StringRef str() {return Enc.c_str();};
|
|
|
|
bool operator<(const FieldEncoding &rhs) const {
|
|
|
|
if (HasName != rhs.HasName) return HasName;
|
|
|
|
return Enc < rhs.Enc;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-08-19 17:46:39 +08:00
|
|
|
class XCoreABIInfo : public DefaultABIInfo {
|
|
|
|
public:
|
|
|
|
XCoreABIInfo(CodeGen::CodeGenTypes &CGT) : DefaultABIInfo(CGT) {}
|
2014-03-12 14:41:41 +08:00
|
|
|
llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
|
|
|
|
CodeGenFunction &CGF) const override;
|
2013-08-19 17:46:39 +08:00
|
|
|
};
|
|
|
|
|
2014-03-03 21:45:29 +08:00
|
|
|
class XCoreTargetCodeGenInfo : public TargetCodeGenInfo {
|
2014-05-02 17:33:20 +08:00
|
|
|
mutable TypeStringCache TSC;
|
2013-08-13 17:43:10 +08:00
|
|
|
public:
|
2014-03-03 21:45:29 +08:00
|
|
|
XCoreTargetCodeGenInfo(CodeGenTypes &CGT)
|
2013-08-19 17:46:39 +08:00
|
|
|
:TargetCodeGenInfo(new XCoreABIInfo(CGT)) {}
|
2014-05-08 23:01:48 +08:00
|
|
|
void emitTargetMD(const Decl *D, llvm::GlobalValue *GV,
|
|
|
|
CodeGen::CodeGenModule &M) const override;
|
2013-08-13 17:43:10 +08:00
|
|
|
};
|
2014-05-02 17:33:20 +08:00
|
|
|
|
2013-10-11 18:29:34 +08:00
|
|
|
} // End anonymous namespace.
|
2013-08-13 17:43:10 +08:00
|
|
|
|
2013-08-19 17:46:39 +08:00
|
|
|
llvm::Value *XCoreABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
|
|
|
|
CodeGenFunction &CGF) const {
|
|
|
|
CGBuilderTy &Builder = CGF.Builder;
|
|
|
|
|
2013-10-11 18:29:34 +08:00
|
|
|
// Get the VAList.
|
2013-08-19 17:46:39 +08:00
|
|
|
llvm::Value *VAListAddrAsBPP = Builder.CreateBitCast(VAListAddr,
|
|
|
|
CGF.Int8PtrPtrTy);
|
|
|
|
llvm::Value *AP = Builder.CreateLoad(VAListAddrAsBPP);
|
|
|
|
|
2013-10-11 18:29:34 +08:00
|
|
|
// Handle the argument.
|
|
|
|
ABIArgInfo AI = classifyArgumentType(Ty);
|
|
|
|
llvm::Type *ArgTy = CGT.ConvertType(Ty);
|
|
|
|
if (AI.canHaveCoerceToType() && !AI.getCoerceToType())
|
|
|
|
AI.setCoerceToType(ArgTy);
|
2013-08-19 17:46:39 +08:00
|
|
|
llvm::Type *ArgPtrTy = llvm::PointerType::getUnqual(ArgTy);
|
2013-10-11 18:29:34 +08:00
|
|
|
llvm::Value *Val;
|
2013-10-14 15:02:04 +08:00
|
|
|
uint64_t ArgSize = 0;
|
2013-08-19 17:46:39 +08:00
|
|
|
switch (AI.getKind()) {
|
|
|
|
case ABIArgInfo::Expand:
|
2014-02-01 08:04:45 +08:00
|
|
|
case ABIArgInfo::InAlloca:
|
2013-08-19 17:46:39 +08:00
|
|
|
llvm_unreachable("Unsupported ABI kind for va_arg");
|
|
|
|
case ABIArgInfo::Ignore:
|
2013-10-11 18:29:34 +08:00
|
|
|
Val = llvm::UndefValue::get(ArgPtrTy);
|
|
|
|
ArgSize = 0;
|
|
|
|
break;
|
2013-08-19 17:46:39 +08:00
|
|
|
case ABIArgInfo::Extend:
|
|
|
|
case ABIArgInfo::Direct:
|
2013-10-11 18:29:34 +08:00
|
|
|
Val = Builder.CreatePointerCast(AP, ArgPtrTy);
|
|
|
|
ArgSize = getDataLayout().getTypeAllocSize(AI.getCoerceToType());
|
|
|
|
if (ArgSize < 4)
|
|
|
|
ArgSize = 4;
|
|
|
|
break;
|
2013-08-19 17:46:39 +08:00
|
|
|
case ABIArgInfo::Indirect:
|
|
|
|
llvm::Value *ArgAddr;
|
|
|
|
ArgAddr = Builder.CreateBitCast(AP, llvm::PointerType::getUnqual(ArgPtrTy));
|
|
|
|
ArgAddr = Builder.CreateLoad(ArgAddr);
|
2013-10-11 18:29:34 +08:00
|
|
|
Val = Builder.CreatePointerCast(ArgAddr, ArgPtrTy);
|
|
|
|
ArgSize = 4;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Increment the VAList.
|
|
|
|
if (ArgSize) {
|
|
|
|
llvm::Value *APN = Builder.CreateConstGEP1_32(AP, ArgSize);
|
|
|
|
Builder.CreateStore(APN, VAListAddrAsBPP);
|
2013-08-19 17:46:39 +08:00
|
|
|
}
|
2013-10-11 18:29:34 +08:00
|
|
|
return Val;
|
2013-08-19 17:46:39 +08:00
|
|
|
}
|
2013-08-13 17:43:10 +08:00
|
|
|
|
2014-05-02 17:33:20 +08:00
|
|
|
/// During the expansion of a RecordType, an incomplete TypeString is placed
|
|
|
|
/// into the cache as a means to identify and break recursion.
|
|
|
|
/// If there is a Recursive encoding in the cache, it is swapped out and will
|
|
|
|
/// be reinserted by removeIncomplete().
|
|
|
|
/// All other types of encoding should have been used rather than arriving here.
|
|
|
|
void TypeStringCache::addIncomplete(const IdentifierInfo *ID,
|
|
|
|
std::string StubEnc) {
|
|
|
|
if (!ID)
|
|
|
|
return;
|
|
|
|
Entry &E = Map[ID];
|
|
|
|
assert( (E.Str.empty() || E.State == Recursive) &&
|
|
|
|
"Incorrectly use of addIncomplete");
|
|
|
|
assert(!StubEnc.empty() && "Passing an empty string to addIncomplete()");
|
|
|
|
E.Swapped.swap(E.Str); // swap out the Recursive
|
|
|
|
E.Str.swap(StubEnc);
|
|
|
|
E.State = Incomplete;
|
|
|
|
++IncompleteCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Once the RecordType has been expanded, the temporary incomplete TypeString
|
|
|
|
/// must be removed from the cache.
|
|
|
|
/// If a Recursive was swapped out by addIncomplete(), it will be replaced.
|
|
|
|
/// Returns true if the RecordType was defined recursively.
|
|
|
|
bool TypeStringCache::removeIncomplete(const IdentifierInfo *ID) {
|
|
|
|
if (!ID)
|
|
|
|
return false;
|
|
|
|
auto I = Map.find(ID);
|
|
|
|
assert(I != Map.end() && "Entry not present");
|
|
|
|
Entry &E = I->second;
|
|
|
|
assert( (E.State == Incomplete ||
|
|
|
|
E.State == IncompleteUsed) &&
|
|
|
|
"Entry must be an incomplete type");
|
|
|
|
bool IsRecursive = false;
|
|
|
|
if (E.State == IncompleteUsed) {
|
|
|
|
// We made use of our Incomplete encoding, thus we are recursive.
|
|
|
|
IsRecursive = true;
|
|
|
|
--IncompleteUsedCount;
|
|
|
|
}
|
|
|
|
if (E.Swapped.empty())
|
|
|
|
Map.erase(I);
|
|
|
|
else {
|
|
|
|
// Swap the Recursive back.
|
|
|
|
E.Swapped.swap(E.Str);
|
|
|
|
E.Swapped.clear();
|
|
|
|
E.State = Recursive;
|
|
|
|
}
|
|
|
|
--IncompleteCount;
|
|
|
|
return IsRecursive;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Add the encoded TypeString to the cache only if it is NonRecursive or
|
|
|
|
/// Recursive (viz: all sub-members were expanded as fully as possible).
|
|
|
|
void TypeStringCache::addIfComplete(const IdentifierInfo *ID, StringRef Str,
|
|
|
|
bool IsRecursive) {
|
|
|
|
if (!ID || IncompleteUsedCount)
|
|
|
|
return; // No key or it is is an incomplete sub-type so don't add.
|
|
|
|
Entry &E = Map[ID];
|
|
|
|
if (IsRecursive && !E.Str.empty()) {
|
|
|
|
assert(E.State==Recursive && E.Str.size() == Str.size() &&
|
|
|
|
"This is not the same Recursive entry");
|
|
|
|
// The parent container was not recursive after all, so we could have used
|
|
|
|
// this Recursive sub-member entry after all, but we assumed the worse when
|
|
|
|
// we started viz: IncompleteCount!=0.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
assert(E.Str.empty() && "Entry already present");
|
|
|
|
E.Str = Str.str();
|
|
|
|
E.State = IsRecursive? Recursive : NonRecursive;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Return a cached TypeString encoding for the ID. If there isn't one, or we
|
|
|
|
/// are recursively expanding a type (IncompleteCount != 0) and the cached
|
|
|
|
/// encoding is Recursive, return an empty StringRef.
|
|
|
|
StringRef TypeStringCache::lookupStr(const IdentifierInfo *ID) {
|
|
|
|
if (!ID)
|
|
|
|
return StringRef(); // We have no key.
|
|
|
|
auto I = Map.find(ID);
|
|
|
|
if (I == Map.end())
|
|
|
|
return StringRef(); // We have no encoding.
|
|
|
|
Entry &E = I->second;
|
|
|
|
if (E.State == Recursive && IncompleteCount)
|
|
|
|
return StringRef(); // We don't use Recursive encodings for member types.
|
|
|
|
|
|
|
|
if (E.State == Incomplete) {
|
|
|
|
// The incomplete type is being used to break out of recursion.
|
|
|
|
E.State = IncompleteUsed;
|
|
|
|
++IncompleteUsedCount;
|
|
|
|
}
|
|
|
|
return E.Str.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// The XCore ABI includes a type information section that communicates symbol
|
|
|
|
/// type information to the linker. The linker uses this information to verify
|
|
|
|
/// safety/correctness of things such as array bound and pointers et al.
|
|
|
|
/// The ABI only requires C (and XC) language modules to emit TypeStrings.
|
|
|
|
/// This type information (TypeString) is emitted into meta data for all global
|
|
|
|
/// symbols: definitions, declarations, functions & variables.
|
|
|
|
///
|
|
|
|
/// The TypeString carries type, qualifier, name, size & value details.
|
|
|
|
/// Please see 'Tools Development Guide' section 2.16.2 for format details:
|
|
|
|
/// <https://www.xmos.com/download/public/Tools-Development-Guide%28X9114A%29.pdf>
|
|
|
|
/// The output is tested by test/CodeGen/xcore-stringtype.c.
|
|
|
|
///
|
|
|
|
static bool getTypeString(SmallStringEnc &Enc, const Decl *D,
|
|
|
|
CodeGen::CodeGenModule &CGM, TypeStringCache &TSC);
|
|
|
|
|
|
|
|
/// XCore uses emitTargetMD to emit TypeString metadata for global symbols.
|
|
|
|
void XCoreTargetCodeGenInfo::emitTargetMD(const Decl *D, llvm::GlobalValue *GV,
|
|
|
|
CodeGen::CodeGenModule &CGM) const {
|
|
|
|
SmallStringEnc Enc;
|
|
|
|
if (getTypeString(Enc, D, CGM, TSC)) {
|
|
|
|
llvm::LLVMContext &Ctx = CGM.getModule().getContext();
|
2014-12-10 02:39:32 +08:00
|
|
|
llvm::SmallVector<llvm::Metadata *, 2> MDVals;
|
|
|
|
MDVals.push_back(llvm::ConstantAsMetadata::get(GV));
|
2014-05-02 17:33:20 +08:00
|
|
|
MDVals.push_back(llvm::MDString::get(Ctx, Enc.str()));
|
|
|
|
llvm::NamedMDNode *MD =
|
|
|
|
CGM.getModule().getOrInsertNamedMetadata("xcore.typestrings");
|
|
|
|
MD->addOperand(llvm::MDNode::get(Ctx, MDVals));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool appendType(SmallStringEnc &Enc, QualType QType,
|
|
|
|
const CodeGen::CodeGenModule &CGM,
|
|
|
|
TypeStringCache &TSC);
|
|
|
|
|
|
|
|
/// Helper function for appendRecordType().
|
|
|
|
/// Builds a SmallVector containing the encoded field types in declaration order.
|
|
|
|
static bool extractFieldType(SmallVectorImpl<FieldEncoding> &FE,
|
|
|
|
const RecordDecl *RD,
|
|
|
|
const CodeGen::CodeGenModule &CGM,
|
|
|
|
TypeStringCache &TSC) {
|
2014-08-22 00:06:57 +08:00
|
|
|
for (const auto *Field : RD->fields()) {
|
2014-05-02 17:33:20 +08:00
|
|
|
SmallStringEnc Enc;
|
|
|
|
Enc += "m(";
|
2014-08-22 00:06:57 +08:00
|
|
|
Enc += Field->getName();
|
2014-05-02 17:33:20 +08:00
|
|
|
Enc += "){";
|
2014-08-22 00:06:57 +08:00
|
|
|
if (Field->isBitField()) {
|
2014-05-02 17:33:20 +08:00
|
|
|
Enc += "b(";
|
|
|
|
llvm::raw_svector_ostream OS(Enc);
|
|
|
|
OS.resync();
|
2014-08-22 00:06:57 +08:00
|
|
|
OS << Field->getBitWidthValue(CGM.getContext());
|
2014-05-02 17:33:20 +08:00
|
|
|
OS.flush();
|
|
|
|
Enc += ':';
|
|
|
|
}
|
2014-08-22 00:06:57 +08:00
|
|
|
if (!appendType(Enc, Field->getType(), CGM, TSC))
|
2014-05-02 17:33:20 +08:00
|
|
|
return false;
|
2014-08-22 00:06:57 +08:00
|
|
|
if (Field->isBitField())
|
2014-05-02 17:33:20 +08:00
|
|
|
Enc += ')';
|
|
|
|
Enc += '}';
|
2014-08-22 00:06:57 +08:00
|
|
|
FE.push_back(FieldEncoding(!Field->getName().empty(), Enc));
|
2014-05-02 17:33:20 +08:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Appends structure and union types to Enc and adds encoding to cache.
|
|
|
|
/// Recursively calls appendType (via extractFieldType) for each field.
|
|
|
|
/// Union types have their fields ordered according to the ABI.
|
|
|
|
static bool appendRecordType(SmallStringEnc &Enc, const RecordType *RT,
|
|
|
|
const CodeGen::CodeGenModule &CGM,
|
|
|
|
TypeStringCache &TSC, const IdentifierInfo *ID) {
|
|
|
|
// Append the cached TypeString if we have one.
|
|
|
|
StringRef TypeString = TSC.lookupStr(ID);
|
|
|
|
if (!TypeString.empty()) {
|
|
|
|
Enc += TypeString;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start to emit an incomplete TypeString.
|
|
|
|
size_t Start = Enc.size();
|
|
|
|
Enc += (RT->isUnionType()? 'u' : 's');
|
|
|
|
Enc += '(';
|
|
|
|
if (ID)
|
|
|
|
Enc += ID->getName();
|
|
|
|
Enc += "){";
|
|
|
|
|
|
|
|
// We collect all encoded fields and order as necessary.
|
|
|
|
bool IsRecursive = false;
|
|
|
|
const RecordDecl *RD = RT->getDecl()->getDefinition();
|
|
|
|
if (RD && !RD->field_empty()) {
|
|
|
|
// An incomplete TypeString stub is placed in the cache for this RecordType
|
|
|
|
// so that recursive calls to this RecordType will use it whilst building a
|
|
|
|
// complete TypeString for this RecordType.
|
2014-05-20 15:19:33 +08:00
|
|
|
SmallVector<FieldEncoding, 16> FE;
|
2014-05-02 17:33:20 +08:00
|
|
|
std::string StubEnc(Enc.substr(Start).str());
|
|
|
|
StubEnc += '}'; // StubEnc now holds a valid incomplete TypeString.
|
|
|
|
TSC.addIncomplete(ID, std::move(StubEnc));
|
|
|
|
if (!extractFieldType(FE, RD, CGM, TSC)) {
|
|
|
|
(void) TSC.removeIncomplete(ID);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
IsRecursive = TSC.removeIncomplete(ID);
|
|
|
|
// The ABI requires unions to be sorted but not structures.
|
|
|
|
// See FieldEncoding::operator< for sort algorithm.
|
|
|
|
if (RT->isUnionType())
|
|
|
|
std::sort(FE.begin(), FE.end());
|
2014-05-20 15:19:33 +08:00
|
|
|
// We can now complete the TypeString.
|
|
|
|
unsigned E = FE.size();
|
2014-05-02 17:33:20 +08:00
|
|
|
for (unsigned I = 0; I != E; ++I) {
|
|
|
|
if (I)
|
|
|
|
Enc += ',';
|
|
|
|
Enc += FE[I].str();
|
|
|
|
}
|
2014-05-20 15:19:33 +08:00
|
|
|
}
|
2014-05-02 17:33:20 +08:00
|
|
|
Enc += '}';
|
|
|
|
TSC.addIfComplete(ID, Enc.substr(Start), IsRecursive);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Appends enum types to Enc and adds the encoding to the cache.
|
|
|
|
static bool appendEnumType(SmallStringEnc &Enc, const EnumType *ET,
|
|
|
|
TypeStringCache &TSC,
|
|
|
|
const IdentifierInfo *ID) {
|
|
|
|
// Append the cached TypeString if we have one.
|
|
|
|
StringRef TypeString = TSC.lookupStr(ID);
|
|
|
|
if (!TypeString.empty()) {
|
|
|
|
Enc += TypeString;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t Start = Enc.size();
|
|
|
|
Enc += "e(";
|
|
|
|
if (ID)
|
|
|
|
Enc += ID->getName();
|
|
|
|
Enc += "){";
|
2014-05-20 15:19:33 +08:00
|
|
|
|
|
|
|
// We collect all encoded enumerations and order them alphanumerically.
|
2014-05-02 17:33:20 +08:00
|
|
|
if (const EnumDecl *ED = ET->getDecl()->getDefinition()) {
|
2014-05-20 15:19:33 +08:00
|
|
|
SmallVector<FieldEncoding, 16> FE;
|
|
|
|
for (auto I = ED->enumerator_begin(), E = ED->enumerator_end(); I != E;
|
|
|
|
++I) {
|
|
|
|
SmallStringEnc EnumEnc;
|
|
|
|
EnumEnc += "m(";
|
|
|
|
EnumEnc += I->getName();
|
|
|
|
EnumEnc += "){";
|
|
|
|
I->getInitVal().toString(EnumEnc);
|
|
|
|
EnumEnc += '}';
|
|
|
|
FE.push_back(FieldEncoding(!I->getName().empty(), EnumEnc));
|
|
|
|
}
|
|
|
|
std::sort(FE.begin(), FE.end());
|
|
|
|
unsigned E = FE.size();
|
|
|
|
for (unsigned I = 0; I != E; ++I) {
|
|
|
|
if (I)
|
2014-05-02 17:33:20 +08:00
|
|
|
Enc += ',';
|
2014-05-20 15:19:33 +08:00
|
|
|
Enc += FE[I].str();
|
2014-05-02 17:33:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Enc += '}';
|
|
|
|
TSC.addIfComplete(ID, Enc.substr(Start), false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Appends type's qualifier to Enc.
|
|
|
|
/// This is done prior to appending the type's encoding.
|
|
|
|
static void appendQualifier(SmallStringEnc &Enc, QualType QT) {
|
|
|
|
// Qualifiers are emitted in alphabetical order.
|
|
|
|
static const char *Table[] = {"","c:","r:","cr:","v:","cv:","rv:","crv:"};
|
|
|
|
int Lookup = 0;
|
|
|
|
if (QT.isConstQualified())
|
|
|
|
Lookup += 1<<0;
|
|
|
|
if (QT.isRestrictQualified())
|
|
|
|
Lookup += 1<<1;
|
|
|
|
if (QT.isVolatileQualified())
|
|
|
|
Lookup += 1<<2;
|
|
|
|
Enc += Table[Lookup];
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Appends built-in types to Enc.
|
|
|
|
static bool appendBuiltinType(SmallStringEnc &Enc, const BuiltinType *BT) {
|
|
|
|
const char *EncType;
|
|
|
|
switch (BT->getKind()) {
|
|
|
|
case BuiltinType::Void:
|
|
|
|
EncType = "0";
|
|
|
|
break;
|
|
|
|
case BuiltinType::Bool:
|
|
|
|
EncType = "b";
|
|
|
|
break;
|
|
|
|
case BuiltinType::Char_U:
|
|
|
|
EncType = "uc";
|
|
|
|
break;
|
|
|
|
case BuiltinType::UChar:
|
|
|
|
EncType = "uc";
|
|
|
|
break;
|
|
|
|
case BuiltinType::SChar:
|
|
|
|
EncType = "sc";
|
|
|
|
break;
|
|
|
|
case BuiltinType::UShort:
|
|
|
|
EncType = "us";
|
|
|
|
break;
|
|
|
|
case BuiltinType::Short:
|
|
|
|
EncType = "ss";
|
|
|
|
break;
|
|
|
|
case BuiltinType::UInt:
|
|
|
|
EncType = "ui";
|
|
|
|
break;
|
|
|
|
case BuiltinType::Int:
|
|
|
|
EncType = "si";
|
|
|
|
break;
|
|
|
|
case BuiltinType::ULong:
|
|
|
|
EncType = "ul";
|
|
|
|
break;
|
|
|
|
case BuiltinType::Long:
|
|
|
|
EncType = "sl";
|
|
|
|
break;
|
|
|
|
case BuiltinType::ULongLong:
|
|
|
|
EncType = "ull";
|
|
|
|
break;
|
|
|
|
case BuiltinType::LongLong:
|
|
|
|
EncType = "sll";
|
|
|
|
break;
|
|
|
|
case BuiltinType::Float:
|
|
|
|
EncType = "ft";
|
|
|
|
break;
|
|
|
|
case BuiltinType::Double:
|
|
|
|
EncType = "d";
|
|
|
|
break;
|
|
|
|
case BuiltinType::LongDouble:
|
|
|
|
EncType = "ld";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Enc += EncType;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Appends a pointer encoding to Enc before calling appendType for the pointee.
|
|
|
|
static bool appendPointerType(SmallStringEnc &Enc, const PointerType *PT,
|
|
|
|
const CodeGen::CodeGenModule &CGM,
|
|
|
|
TypeStringCache &TSC) {
|
|
|
|
Enc += "p(";
|
|
|
|
if (!appendType(Enc, PT->getPointeeType(), CGM, TSC))
|
|
|
|
return false;
|
|
|
|
Enc += ')';
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Appends array encoding to Enc before calling appendType for the element.
|
2014-06-05 17:06:21 +08:00
|
|
|
static bool appendArrayType(SmallStringEnc &Enc, QualType QT,
|
|
|
|
const ArrayType *AT,
|
2014-05-02 17:33:20 +08:00
|
|
|
const CodeGen::CodeGenModule &CGM,
|
|
|
|
TypeStringCache &TSC, StringRef NoSizeEnc) {
|
|
|
|
if (AT->getSizeModifier() != ArrayType::Normal)
|
|
|
|
return false;
|
|
|
|
Enc += "a(";
|
|
|
|
if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(AT))
|
|
|
|
CAT->getSize().toStringUnsigned(Enc);
|
|
|
|
else
|
|
|
|
Enc += NoSizeEnc; // Global arrays use "*", otherwise it is "".
|
|
|
|
Enc += ':';
|
2014-06-05 17:06:21 +08:00
|
|
|
// The Qualifiers should be attached to the type rather than the array.
|
|
|
|
appendQualifier(Enc, QT);
|
2014-05-02 17:33:20 +08:00
|
|
|
if (!appendType(Enc, AT->getElementType(), CGM, TSC))
|
|
|
|
return false;
|
|
|
|
Enc += ')';
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Appends a function encoding to Enc, calling appendType for the return type
|
|
|
|
/// and the arguments.
|
|
|
|
static bool appendFunctionType(SmallStringEnc &Enc, const FunctionType *FT,
|
|
|
|
const CodeGen::CodeGenModule &CGM,
|
|
|
|
TypeStringCache &TSC) {
|
|
|
|
Enc += "f{";
|
|
|
|
if (!appendType(Enc, FT->getReturnType(), CGM, TSC))
|
|
|
|
return false;
|
|
|
|
Enc += "}(";
|
|
|
|
if (const FunctionProtoType *FPT = FT->getAs<FunctionProtoType>()) {
|
|
|
|
// N.B. we are only interested in the adjusted param types.
|
|
|
|
auto I = FPT->param_type_begin();
|
|
|
|
auto E = FPT->param_type_end();
|
|
|
|
if (I != E) {
|
|
|
|
do {
|
|
|
|
if (!appendType(Enc, *I, CGM, TSC))
|
|
|
|
return false;
|
|
|
|
++I;
|
|
|
|
if (I != E)
|
|
|
|
Enc += ',';
|
|
|
|
} while (I != E);
|
|
|
|
if (FPT->isVariadic())
|
|
|
|
Enc += ",va";
|
|
|
|
} else {
|
|
|
|
if (FPT->isVariadic())
|
|
|
|
Enc += "va";
|
|
|
|
else
|
|
|
|
Enc += '0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Enc += ')';
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Handles the type's qualifier before dispatching a call to handle specific
|
|
|
|
/// type encodings.
|
|
|
|
static bool appendType(SmallStringEnc &Enc, QualType QType,
|
|
|
|
const CodeGen::CodeGenModule &CGM,
|
|
|
|
TypeStringCache &TSC) {
|
|
|
|
|
|
|
|
QualType QT = QType.getCanonicalType();
|
|
|
|
|
2014-06-05 17:06:21 +08:00
|
|
|
if (const ArrayType *AT = QT->getAsArrayTypeUnsafe())
|
|
|
|
// The Qualifiers should be attached to the type rather than the array.
|
|
|
|
// Thus we don't call appendQualifier() here.
|
|
|
|
return appendArrayType(Enc, QT, AT, CGM, TSC, "");
|
|
|
|
|
2014-05-02 17:33:20 +08:00
|
|
|
appendQualifier(Enc, QT);
|
|
|
|
|
|
|
|
if (const BuiltinType *BT = QT->getAs<BuiltinType>())
|
|
|
|
return appendBuiltinType(Enc, BT);
|
|
|
|
|
|
|
|
if (const PointerType *PT = QT->getAs<PointerType>())
|
|
|
|
return appendPointerType(Enc, PT, CGM, TSC);
|
|
|
|
|
|
|
|
if (const EnumType *ET = QT->getAs<EnumType>())
|
|
|
|
return appendEnumType(Enc, ET, TSC, QT.getBaseTypeIdentifier());
|
|
|
|
|
|
|
|
if (const RecordType *RT = QT->getAsStructureType())
|
|
|
|
return appendRecordType(Enc, RT, CGM, TSC, QT.getBaseTypeIdentifier());
|
|
|
|
|
|
|
|
if (const RecordType *RT = QT->getAsUnionType())
|
|
|
|
return appendRecordType(Enc, RT, CGM, TSC, QT.getBaseTypeIdentifier());
|
|
|
|
|
|
|
|
if (const FunctionType *FT = QT->getAs<FunctionType>())
|
|
|
|
return appendFunctionType(Enc, FT, CGM, TSC);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool getTypeString(SmallStringEnc &Enc, const Decl *D,
|
|
|
|
CodeGen::CodeGenModule &CGM, TypeStringCache &TSC) {
|
|
|
|
if (!D)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
|
|
|
|
if (FD->getLanguageLinkage() != CLanguageLinkage)
|
|
|
|
return false;
|
|
|
|
return appendType(Enc, FD->getType(), CGM, TSC);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
|
|
|
|
if (VD->getLanguageLinkage() != CLanguageLinkage)
|
|
|
|
return false;
|
|
|
|
QualType QT = VD->getType().getCanonicalType();
|
|
|
|
if (const ArrayType *AT = QT->getAsArrayTypeUnsafe()) {
|
|
|
|
// Global ArrayTypes are given a size of '*' if the size is unknown.
|
2014-06-05 17:06:21 +08:00
|
|
|
// The Qualifiers should be attached to the type rather than the array.
|
|
|
|
// Thus we don't call appendQualifier() here.
|
|
|
|
return appendArrayType(Enc, QT, AT, CGM, TSC, "*");
|
2014-05-02 17:33:20 +08:00
|
|
|
}
|
|
|
|
return appendType(Enc, QT, CGM, TSC);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-13 17:43:10 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Driver code
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-09-19 09:54:22 +08:00
|
|
|
const llvm::Triple &CodeGenModule::getTriple() const {
|
|
|
|
return getTarget().getTriple();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CodeGenModule::supportsCOMDAT() const {
|
|
|
|
return !getTriple().isOSBinFormatMachO();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2013-04-17 06:48:15 +08:00
|
|
|
const llvm::Triple &Triple = getTarget().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
|
|
|
|
2012-09-07 01:37:28 +08:00
|
|
|
case llvm::Triple::le32:
|
|
|
|
return *(TheTargetCodeGenInfo = new PNaClTargetCodeGenInfo(Types));
|
2010-05-27 14:19:26 +08:00
|
|
|
case llvm::Triple::mips:
|
|
|
|
case llvm::Triple::mipsel:
|
2013-11-12 06:10:46 +08:00
|
|
|
return *(TheTargetCodeGenInfo = new MIPSTargetCodeGenInfo(Types, true));
|
|
|
|
|
2011-09-21 02:30:57 +08:00
|
|
|
case llvm::Triple::mips64:
|
|
|
|
case llvm::Triple::mips64el:
|
2013-11-12 06:10:46 +08:00
|
|
|
return *(TheTargetCodeGenInfo = new MIPSTargetCodeGenInfo(Types, false));
|
|
|
|
|
2014-05-24 20:51:25 +08:00
|
|
|
case llvm::Triple::aarch64:
|
2014-07-23 20:32:58 +08:00
|
|
|
case llvm::Triple::aarch64_be: {
|
2014-05-24 20:52:07 +08:00
|
|
|
AArch64ABIInfo::ABIKind Kind = AArch64ABIInfo::AAPCS;
|
2014-06-08 07:30:42 +08:00
|
|
|
if (getTarget().getABI() == "darwinpcs")
|
2014-05-24 20:52:07 +08:00
|
|
|
Kind = AArch64ABIInfo::DarwinPCS;
|
2014-03-29 23:09:45 +08:00
|
|
|
|
2014-05-24 20:52:07 +08:00
|
|
|
return *(TheTargetCodeGenInfo = new AArch64TargetCodeGenInfo(Types, Kind));
|
2014-03-29 23:09:45 +08:00
|
|
|
}
|
|
|
|
|
2009-09-12 08:59:49 +08:00
|
|
|
case llvm::Triple::arm:
|
2014-03-28 22:40:46 +08:00
|
|
|
case llvm::Triple::armeb:
|
2009-09-12 08:59:49 +08:00
|
|
|
case llvm::Triple::thumb:
|
2014-03-28 22:40:46 +08:00
|
|
|
case llvm::Triple::thumbeb:
|
2011-04-05 08:23:47 +08:00
|
|
|
{
|
|
|
|
ARMABIInfo::ABIKind Kind = ARMABIInfo::AAPCS;
|
2014-06-08 07:30:42 +08:00
|
|
|
if (getTarget().getABI() == "apcs-gnu")
|
2011-04-05 08:23:47 +08:00
|
|
|
Kind = ARMABIInfo::APCS;
|
2012-10-25 21:33:01 +08:00
|
|
|
else if (CodeGenOpts.FloatABI == "hard" ||
|
2013-04-17 06:48:15 +08:00
|
|
|
(CodeGenOpts.FloatABI != "soft" &&
|
|
|
|
Triple.getEnvironment() == llvm::Triple::GNUEABIHF))
|
2011-04-05 08:23:47 +08:00
|
|
|
Kind = ARMABIInfo::AAPCS_VFP;
|
|
|
|
|
2012-10-17 06:30:41 +08:00
|
|
|
switch (Triple.getOS()) {
|
2012-12-05 02:38:10 +08:00
|
|
|
case llvm::Triple::NaCl:
|
2012-10-17 06:30:41 +08:00
|
|
|
return *(TheTargetCodeGenInfo =
|
|
|
|
new NaClARMTargetCodeGenInfo(Types, Kind));
|
|
|
|
default:
|
|
|
|
return *(TheTargetCodeGenInfo =
|
|
|
|
new ARMTargetCodeGenInfo(Types, Kind));
|
|
|
|
}
|
2011-04-05 08:23:47 +08:00
|
|
|
}
|
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));
|
2012-05-10 02:22:46 +08:00
|
|
|
case llvm::Triple::ppc64:
|
[PowerPC] Support the ELFv2 ABI
This patch implements clang support for the PowerPC ELFv2 ABI.
Together with a series of companion patches in LLVM, this makes
clang/LLVM fully usable on powerpc64le-linux.
Most of the ELFv2 ABI changes are fully implemented on the LLVM side.
On the clang side, we only need to implement some changes in how
aggregate types are passed by value. Specifically, we need to:
- pass (and return) "homogeneous" floating-point or vector aggregates in
FPRs and VRs (this is similar to the ARM homogeneous aggregate ABI)
- return aggregates of up to 16 bytes in one or two GPRs
The second piece is trivial to implement in any case. To implement
the first piece, this patch makes use of infrastructure recently
enabled in the LLVM PowerPC back-end to support passing array types
directly, where the array element type encodes properties needed to
handle homogeneous aggregates correctly.
Specifically, the array element type encodes:
- whether the parameter should be passed in FPRs, VRs, or just
GPRs/stack slots (for float / vector / integer element types,
respectively)
- what the alignment requirements of the parameter are when passed in
GPRs/stack slots (8 for float / 16 for vector / the element type
size for integer element types) -- this corresponds to the
"byval align" field
With this support in place, the clang part simply needs to *detect*
whether an aggregate type implements a float / vector homogeneous
aggregate as defined by the ELFv2 ABI, and if so, pass/return it
as array type using the appropriate float / vector element type.
llvm-svn: 213494
2014-07-21 08:48:09 +08:00
|
|
|
if (Triple.isOSBinFormatELF()) {
|
|
|
|
PPC64_SVR4_ABIInfo::ABIKind Kind = PPC64_SVR4_ABIInfo::ELFv1;
|
2014-07-28 21:17:52 +08:00
|
|
|
if (getTarget().getABI() == "elfv2")
|
|
|
|
Kind = PPC64_SVR4_ABIInfo::ELFv2;
|
|
|
|
|
[PowerPC] Support the ELFv2 ABI
This patch implements clang support for the PowerPC ELFv2 ABI.
Together with a series of companion patches in LLVM, this makes
clang/LLVM fully usable on powerpc64le-linux.
Most of the ELFv2 ABI changes are fully implemented on the LLVM side.
On the clang side, we only need to implement some changes in how
aggregate types are passed by value. Specifically, we need to:
- pass (and return) "homogeneous" floating-point or vector aggregates in
FPRs and VRs (this is similar to the ARM homogeneous aggregate ABI)
- return aggregates of up to 16 bytes in one or two GPRs
The second piece is trivial to implement in any case. To implement
the first piece, this patch makes use of infrastructure recently
enabled in the LLVM PowerPC back-end to support passing array types
directly, where the array element type encodes properties needed to
handle homogeneous aggregates correctly.
Specifically, the array element type encodes:
- whether the parameter should be passed in FPRs, VRs, or just
GPRs/stack slots (for float / vector / integer element types,
respectively)
- what the alignment requirements of the parameter are when passed in
GPRs/stack slots (8 for float / 16 for vector / the element type
size for integer element types) -- this corresponds to the
"byval align" field
With this support in place, the clang part simply needs to *detect*
whether an aggregate type implements a float / vector homogeneous
aggregate as defined by the ELFv2 ABI, and if so, pass/return it
as array type using the appropriate float / vector element type.
llvm-svn: 213494
2014-07-21 08:48:09 +08:00
|
|
|
return *(TheTargetCodeGenInfo =
|
|
|
|
new PPC64_SVR4_TargetCodeGenInfo(Types, Kind));
|
|
|
|
} else
|
2012-10-04 03:18:57 +08:00
|
|
|
return *(TheTargetCodeGenInfo = new PPC64TargetCodeGenInfo(Types));
|
[PowerPC] Support the ELFv2 ABI
This patch implements clang support for the PowerPC ELFv2 ABI.
Together with a series of companion patches in LLVM, this makes
clang/LLVM fully usable on powerpc64le-linux.
Most of the ELFv2 ABI changes are fully implemented on the LLVM side.
On the clang side, we only need to implement some changes in how
aggregate types are passed by value. Specifically, we need to:
- pass (and return) "homogeneous" floating-point or vector aggregates in
FPRs and VRs (this is similar to the ARM homogeneous aggregate ABI)
- return aggregates of up to 16 bytes in one or two GPRs
The second piece is trivial to implement in any case. To implement
the first piece, this patch makes use of infrastructure recently
enabled in the LLVM PowerPC back-end to support passing array types
directly, where the array element type encodes properties needed to
handle homogeneous aggregates correctly.
Specifically, the array element type encodes:
- whether the parameter should be passed in FPRs, VRs, or just
GPRs/stack slots (for float / vector / integer element types,
respectively)
- what the alignment requirements of the parameter are when passed in
GPRs/stack slots (8 for float / 16 for vector / the element type
size for integer element types) -- this corresponds to the
"byval align" field
With this support in place, the clang part simply needs to *detect*
whether an aggregate type implements a float / vector homogeneous
aggregate as defined by the ELFv2 ABI, and if so, pass/return it
as array type using the appropriate float / vector element type.
llvm-svn: 213494
2014-07-21 08:48:09 +08:00
|
|
|
case llvm::Triple::ppc64le: {
|
2013-07-26 09:36:11 +08:00
|
|
|
assert(Triple.isOSBinFormatELF() && "PPC64 LE non-ELF not supported!");
|
[PowerPC] Support the ELFv2 ABI
This patch implements clang support for the PowerPC ELFv2 ABI.
Together with a series of companion patches in LLVM, this makes
clang/LLVM fully usable on powerpc64le-linux.
Most of the ELFv2 ABI changes are fully implemented on the LLVM side.
On the clang side, we only need to implement some changes in how
aggregate types are passed by value. Specifically, we need to:
- pass (and return) "homogeneous" floating-point or vector aggregates in
FPRs and VRs (this is similar to the ARM homogeneous aggregate ABI)
- return aggregates of up to 16 bytes in one or two GPRs
The second piece is trivial to implement in any case. To implement
the first piece, this patch makes use of infrastructure recently
enabled in the LLVM PowerPC back-end to support passing array types
directly, where the array element type encodes properties needed to
handle homogeneous aggregates correctly.
Specifically, the array element type encodes:
- whether the parameter should be passed in FPRs, VRs, or just
GPRs/stack slots (for float / vector / integer element types,
respectively)
- what the alignment requirements of the parameter are when passed in
GPRs/stack slots (8 for float / 16 for vector / the element type
size for integer element types) -- this corresponds to the
"byval align" field
With this support in place, the clang part simply needs to *detect*
whether an aggregate type implements a float / vector homogeneous
aggregate as defined by the ELFv2 ABI, and if so, pass/return it
as array type using the appropriate float / vector element type.
llvm-svn: 213494
2014-07-21 08:48:09 +08:00
|
|
|
PPC64_SVR4_ABIInfo::ABIKind Kind = PPC64_SVR4_ABIInfo::ELFv2;
|
2014-07-28 21:17:52 +08:00
|
|
|
if (getTarget().getABI() == "elfv1")
|
|
|
|
Kind = PPC64_SVR4_ABIInfo::ELFv1;
|
|
|
|
|
[PowerPC] Support the ELFv2 ABI
This patch implements clang support for the PowerPC ELFv2 ABI.
Together with a series of companion patches in LLVM, this makes
clang/LLVM fully usable on powerpc64le-linux.
Most of the ELFv2 ABI changes are fully implemented on the LLVM side.
On the clang side, we only need to implement some changes in how
aggregate types are passed by value. Specifically, we need to:
- pass (and return) "homogeneous" floating-point or vector aggregates in
FPRs and VRs (this is similar to the ARM homogeneous aggregate ABI)
- return aggregates of up to 16 bytes in one or two GPRs
The second piece is trivial to implement in any case. To implement
the first piece, this patch makes use of infrastructure recently
enabled in the LLVM PowerPC back-end to support passing array types
directly, where the array element type encodes properties needed to
handle homogeneous aggregates correctly.
Specifically, the array element type encodes:
- whether the parameter should be passed in FPRs, VRs, or just
GPRs/stack slots (for float / vector / integer element types,
respectively)
- what the alignment requirements of the parameter are when passed in
GPRs/stack slots (8 for float / 16 for vector / the element type
size for integer element types) -- this corresponds to the
"byval align" field
With this support in place, the clang part simply needs to *detect*
whether an aggregate type implements a float / vector homogeneous
aggregate as defined by the ELFv2 ABI, and if so, pass/return it
as array type using the appropriate float / vector element type.
llvm-svn: 213494
2014-07-21 08:48:09 +08:00
|
|
|
return *(TheTargetCodeGenInfo =
|
|
|
|
new PPC64_SVR4_TargetCodeGenInfo(Types, Kind));
|
|
|
|
}
|
2010-03-11 08:10:12 +08:00
|
|
|
|
2012-05-21 07:28:41 +08:00
|
|
|
case llvm::Triple::nvptx:
|
|
|
|
case llvm::Triple::nvptx64:
|
2012-05-25 01:43:12 +08:00
|
|
|
return *(TheTargetCodeGenInfo = new NVPTXTargetCodeGenInfo(Types));
|
2011-04-22 19:10:38 +08:00
|
|
|
|
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
|
|
|
|
2013-05-07 00:26:41 +08:00
|
|
|
case llvm::Triple::systemz:
|
|
|
|
return *(TheTargetCodeGenInfo = new SystemZTargetCodeGenInfo(Types));
|
|
|
|
|
2011-10-14 00:24:41 +08:00
|
|
|
case llvm::Triple::tce:
|
|
|
|
return *(TheTargetCodeGenInfo = new TCETargetCodeGenInfo(Types));
|
|
|
|
|
2011-07-09 07:31:17 +08:00
|
|
|
case llvm::Triple::x86: {
|
2013-06-18 10:46:29 +08:00
|
|
|
bool IsDarwinVectorABI = Triple.isOSDarwin();
|
|
|
|
bool IsSmallStructInRegABI =
|
|
|
|
X86_32TargetCodeGenInfo::isStructReturnInRegABI(Triple, CodeGenOpts);
|
2014-11-23 10:16:24 +08:00
|
|
|
bool IsWin32FloatStructABI = Triple.isOSWindows() && !Triple.isOSCygMing();
|
2011-04-20 05:43:27 +08:00
|
|
|
|
2013-06-18 10:46:29 +08:00
|
|
|
if (Triple.getOS() == llvm::Triple::Win32) {
|
2012-01-26 06:46:34 +08:00
|
|
|
return *(TheTargetCodeGenInfo =
|
2013-05-08 21:44:39 +08:00
|
|
|
new WinX86_32TargetCodeGenInfo(Types,
|
2013-06-18 10:46:29 +08:00
|
|
|
IsDarwinVectorABI, IsSmallStructInRegABI,
|
|
|
|
IsWin32FloatStructABI,
|
2013-05-08 21:44:39 +08:00
|
|
|
CodeGenOpts.NumRegisterParameters));
|
2013-06-18 10:46:29 +08:00
|
|
|
} else {
|
2010-01-10 20:58:08 +08:00
|
|
|
return *(TheTargetCodeGenInfo =
|
2013-06-18 10:46:29 +08:00
|
|
|
new X86_32TargetCodeGenInfo(Types,
|
|
|
|
IsDarwinVectorABI, IsSmallStructInRegABI,
|
|
|
|
IsWin32FloatStructABI,
|
2012-07-31 10:44:24 +08:00
|
|
|
CodeGenOpts.NumRegisterParameters));
|
2009-06-06 06:08:42 +08:00
|
|
|
}
|
2011-07-09 07:31:17 +08:00
|
|
|
}
|
2009-08-24 16:52:16 +08:00
|
|
|
|
2011-12-02 08:11:43 +08:00
|
|
|
case llvm::Triple::x86_64: {
|
2014-06-08 07:30:42 +08:00
|
|
|
bool HasAVX = getTarget().getABI() == "avx";
|
2011-12-02 08:11:43 +08:00
|
|
|
|
2010-09-01 00:44:54 +08:00
|
|
|
switch (Triple.getOS()) {
|
|
|
|
case llvm::Triple::Win32:
|
2014-09-30 13:29:28 +08:00
|
|
|
return *(TheTargetCodeGenInfo =
|
|
|
|
new WinX86_64TargetCodeGenInfo(Types, HasAVX));
|
2012-12-05 02:38:10 +08:00
|
|
|
case llvm::Triple::NaCl:
|
2014-09-30 13:29:28 +08:00
|
|
|
return *(TheTargetCodeGenInfo =
|
|
|
|
new NaClX86_64TargetCodeGenInfo(Types, HasAVX));
|
2010-09-01 00:44:54 +08:00
|
|
|
default:
|
2014-09-30 13:29:28 +08:00
|
|
|
return *(TheTargetCodeGenInfo =
|
|
|
|
new X86_64TargetCodeGenInfo(Types, HasAVX));
|
2010-09-01 00:44:54 +08:00
|
|
|
}
|
2009-06-06 06:08:42 +08:00
|
|
|
}
|
2011-12-13 05:14:55 +08:00
|
|
|
case llvm::Triple::hexagon:
|
|
|
|
return *(TheTargetCodeGenInfo = new HexagonTargetCodeGenInfo(Types));
|
2014-12-05 04:38:18 +08:00
|
|
|
case llvm::Triple::r600:
|
|
|
|
return *(TheTargetCodeGenInfo = new AMDGPUTargetCodeGenInfo(Types));
|
2013-05-28 05:48:25 +08:00
|
|
|
case llvm::Triple::sparcv9:
|
|
|
|
return *(TheTargetCodeGenInfo = new SparcV9TargetCodeGenInfo(Types));
|
2013-08-13 17:43:10 +08:00
|
|
|
case llvm::Triple::xcore:
|
2014-03-03 21:45:29 +08:00
|
|
|
return *(TheTargetCodeGenInfo = new XCoreTargetCodeGenInfo(Types));
|
2011-12-02 08:11:43 +08:00
|
|
|
}
|
2009-06-06 06:08:42 +08:00
|
|
|
}
|