Merge branch 'master' into merge-2.061-2

This commit is contained in:
kai
2013-02-03 15:50:39 +01:00
8 changed files with 82 additions and 47 deletions

View File

@@ -10,6 +10,9 @@
#ifndef ROOT_MEM_H
#define ROOT_MEM_H
#if defined(IN_LLVM) && (LDC_LLVM_VER >= 303)
#include "llvm/Config/config.h"
#endif
#include <stddef.h> // for size_t
typedef void (*FINALIZERPROC)(void* pObj, void* pClientData);

View File

@@ -534,7 +534,8 @@ void X86_64TargetABI::rewriteFunctionType(TypeFunction* tf) {
{
Logger::println("Putting 'this' in register");
#if LDC_LLVM_VER >= 303
fty.arg_this->attrs = llvm::Attribute::get(gIR->context(), llvm::AttrBuilder().addAttribute(llvm::Attribute::InReg));
fty.arg_this->attrs.clear();
fty.arg_this->attrs.addAttribute(llvm::Attribute::InReg);
#elif LDC_LLVM_VER == 302
fty.arg_this->attrs = llvm::Attributes::get(gIR->context(), llvm::AttrBuilder().addAttribute(llvm::Attributes::InReg));
#else
@@ -546,7 +547,8 @@ void X86_64TargetABI::rewriteFunctionType(TypeFunction* tf) {
{
Logger::println("Putting context ptr in register");
#if LDC_LLVM_VER >= 303
fty.arg_nest->attrs = llvm::Attribute::get(gIR->context(), llvm::AttrBuilder().addAttribute(llvm::Attribute::InReg));
fty.arg_nest->attrs.clear();
fty.arg_nest->attrs.addAttribute(llvm::Attribute::InReg);
#elif LDC_LLVM_VER == 302
fty.arg_nest->attrs = llvm::Attributes::get(gIR->context(), llvm::AttrBuilder().addAttribute(llvm::Attributes::InReg));
#else
@@ -560,8 +562,7 @@ void X86_64TargetABI::rewriteFunctionType(TypeFunction* tf) {
// sret and inreg are incompatible, but the ABI requires the
// sret parameter to be in RDI in this situation...
#if LDC_LLVM_VER >= 303
sret->attrs = llvm::Attribute::get(gIR->context(), llvm::AttrBuilder(sret->attrs).addAttribute(llvm::Attribute::InReg)
.removeAttribute(llvm::Attribute::StructRet));
sret->attrs.addAttribute(llvm::Attribute::InReg).removeAttribute(llvm::Attribute::StructRet);
#elif LDC_LLVM_VER == 302
sret->attrs = llvm::Attributes::get(gIR->context(), llvm::AttrBuilder(sret->attrs).addAttribute(llvm::Attributes::InReg)
.removeAttribute(llvm::Attributes::StructRet));
@@ -586,7 +587,7 @@ void X86_64TargetABI::rewriteFunctionType(TypeFunction* tf) {
if (xmmcount > 0) {
Logger::println("Putting float parameter in register");
#if LDC_LLVM_VER >= 303
arg.attrs = llvm::Attribute::get(gIR->context(), llvm::AttrBuilder(arg.attrs).addAttribute(llvm::Attribute::InReg));
arg.attrs.addAttribute(llvm::Attribute::InReg);
#elif LDC_LLVM_VER == 302
arg.attrs = llvm::Attributes::get(gIR->context(), llvm::AttrBuilder(arg.attrs).addAttribute(llvm::Attributes::InReg));
#else
@@ -603,7 +604,7 @@ void X86_64TargetABI::rewriteFunctionType(TypeFunction* tf) {
{
Logger::println("Putting byref parameter in register");
#if LDC_LLVM_VER >= 303
arg.attrs = llvm::Attribute::get(gIR->context(), llvm::AttrBuilder(arg.attrs).addAttribute(llvm::Attribute::InReg));
arg.attrs.addAttribute(llvm::Attribute::InReg);
#elif LDC_LLVM_VER == 302
arg.attrs = llvm::Attributes::get(gIR->context(), llvm::AttrBuilder(arg.attrs).addAttribute(llvm::Attributes::InReg));
#else
@@ -615,7 +616,7 @@ void X86_64TargetABI::rewriteFunctionType(TypeFunction* tf) {
{
Logger::println("Putting pointer parameter in register");
#if LDC_LLVM_VER >= 303
arg.attrs = llvm::Attribute::get(gIR->context(), llvm::AttrBuilder(arg.attrs).addAttribute(llvm::Attribute::InReg));
arg.attrs.addAttribute(llvm::Attribute::InReg);
#elif LDC_LLVM_VER == 302
arg.attrs = llvm::Attributes::get(gIR->context(), llvm::AttrBuilder(arg.attrs).addAttribute(llvm::Attributes::InReg));
#else
@@ -627,7 +628,7 @@ void X86_64TargetABI::rewriteFunctionType(TypeFunction* tf) {
{
Logger::println("Putting integral parameter in register");
#if LDC_LLVM_VER >= 303
arg.attrs = llvm::Attribute::get(gIR->context(), llvm::AttrBuilder(arg.attrs).addAttribute(llvm::Attribute::InReg));
arg.attrs.addAttribute(llvm::Attribute::InReg);
#elif LDC_LLVM_VER == 302
arg.attrs = llvm::Attributes::get(gIR->context(), llvm::AttrBuilder(arg.attrs).addAttribute(llvm::Attributes::InReg));
#else
@@ -643,7 +644,8 @@ void X86_64TargetABI::rewriteFunctionType(TypeFunction* tf) {
arg.ltype = compositeToInt.type(arg.type, arg.ltype);
arg.byref = false;
#if LDC_LLVM_VER >= 303
arg.attrs = llvm::Attribute::get(gIR->context(), llvm::AttrBuilder().addAttribute(llvm::Attribute::InReg));
arg.attrs.clear();
arg.attrs.addAttribute(llvm::Attribute::InReg);
#elif LDC_LLVM_VER == 302
arg.attrs = llvm::Attributes::get(gIR->context(), llvm::AttrBuilder().addAttribute(llvm::Attributes::InReg));
#else

View File

@@ -125,7 +125,8 @@ struct X86TargetABI : TargetABI
{
Logger::println("Putting 'this' in register");
#if LDC_LLVM_VER >= 303
fty.arg_this->attrs = llvm::Attribute::get(gIR->context(), llvm::AttrBuilder().addAttribute(llvm::Attribute::InReg));
fty.arg_this->attrs.clear();
fty.arg_this->attrs.addAttribute(llvm::Attribute::InReg);
#elif LDC_LLVM_VER == 302
fty.arg_this->attrs = llvm::Attributes::get(gIR->context(), llvm::AttrBuilder().addAttribute(llvm::Attributes::InReg));
#else
@@ -136,7 +137,8 @@ struct X86TargetABI : TargetABI
{
Logger::println("Putting context ptr in register");
#if LDC_LLVM_VER >= 303
fty.arg_nest->attrs = llvm::Attribute::get(gIR->context(), llvm::AttrBuilder().addAttribute(llvm::Attribute::InReg));
fty.arg_nest->attrs.clear();
fty.arg_nest->attrs.addAttribute(llvm::Attribute::InReg);
#elif LDC_LLVM_VER == 302
fty.arg_nest->attrs = llvm::Attributes::get(gIR->context(), llvm::AttrBuilder().addAttribute(llvm::Attributes::InReg));
#else
@@ -149,8 +151,7 @@ struct X86TargetABI : TargetABI
// sret and inreg are incompatible, but the ABI requires the
// sret parameter to be in EAX in this situation...
#if LDC_LLVM_VER >= 303
sret->attrs = llvm::Attribute::get(gIR->context(), llvm::AttrBuilder(sret->attrs).addAttribute(llvm::Attribute::InReg)
.removeAttribute(llvm::Attribute::StructRet));
sret->attrs.addAttribute(llvm::Attribute::InReg).removeAttribute(llvm::Attribute::StructRet);
#elif LDC_LLVM_VER == 302
sret->attrs = llvm::Attributes::get(gIR->context(), llvm::AttrBuilder(sret->attrs).addAttribute(llvm::Attributes::InReg)
.removeAttribute(llvm::Attributes::StructRet));
@@ -175,7 +176,7 @@ struct X86TargetABI : TargetABI
{
Logger::println("Putting last (byref) parameter in register");
#if LDC_LLVM_VER >= 303
last->attrs = llvm::Attribute::get(gIR->context(), llvm::AttrBuilder(last->attrs).addAttribute(llvm::Attribute::InReg));
last->attrs.addAttribute(llvm::Attribute::InReg);
#elif LDC_LLVM_VER == 302
last->attrs = llvm::Attributes::get(gIR->context(), llvm::AttrBuilder(last->attrs).addAttribute(llvm::Attributes::InReg));
#else
@@ -192,7 +193,7 @@ struct X86TargetABI : TargetABI
last->byref = false;
// erase previous attributes
#if LDC_LLVM_VER >= 303
last->attrs = llvm::Attribute();
last->attrs.clear();
#elif LDC_LLVM_VER == 302
last->attrs = llvm::Attributes();
#else
@@ -200,7 +201,7 @@ struct X86TargetABI : TargetABI
#endif
}
#if LDC_LLVM_VER >= 303
last->attrs = llvm::Attribute::get(gIR->context(), llvm::AttrBuilder(last->attrs).addAttribute(llvm::Attribute::InReg));
last->attrs.addAttribute(llvm::Attribute::InReg);
#elif LDC_LLVM_VER == 302
last->attrs = llvm::Attributes::get(gIR->context(), llvm::AttrBuilder(last->attrs).addAttribute(llvm::Attributes::InReg));
#else

View File

@@ -37,6 +37,7 @@
#include "gen/abi.h"
#include "gen/nested.h"
#include "gen/pragma.h"
#include <iostream>
#if LDC_LLVM_VER < 302
using namespace llvm::Attribute;
@@ -83,7 +84,7 @@ llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nesttype,
{
#if LDC_LLVM_VER >= 302
#if LDC_LLVM_VER >= 303
fty.arg_sret = new IrFuncTyArg(rt, true, llvm::Attribute::get(gIR->context(),
fty.arg_sret = new IrFuncTyArg(rt, true,
llvm::AttrBuilder().addAttribute(llvm::Attribute::StructRet)
.addAttribute(llvm::Attribute::NoAlias)
#else
@@ -100,7 +101,10 @@ llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nesttype,
// _silent_ miscompilations (especially in the GVN pass).
.addAttribute(llvm::Attributes::NoCapture)
#endif
));
#if LDC_LLVM_VER == 302
)
#endif
);
#else
fty.arg_sret = new IrFuncTyArg(rt, true, StructRet | NoAlias
#if !STRUCTTHISREF
@@ -119,14 +123,18 @@ llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nesttype,
if (f->isref)
t = t->pointerTo();
#endif
#if LDC_LLVM_VER >= 302
attrBuilder.addAttribute(DtoShouldExtend(t));
#if LDC_LLVM_VER >= 303
if (llvm::Attribute::AttrKind a = DtoShouldExtend(t))
attrBuilder.addAttribute(a);
#elif LDC_LLVM_VER == 302
if (llvm::Attributes::AttrVal a = DtoShouldExtend(t))
attrBuilder.addAttribute(a);
#else
a = DtoShouldExtend(t);
#endif
}
#if LDC_LLVM_VER >= 303
llvm::Attribute a = llvm::Attribute::get(gIR->context(), attrBuilder);
llvm::AttrBuilder a = attrBuilder;
#elif LDC_LLVM_VER == 302
llvm::Attributes a = llvm::Attributes::get(gIR->context(), attrBuilder);
#endif
@@ -167,8 +175,8 @@ llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nesttype,
// _argptr
#if LDC_LLVM_VER >= 303
fty.arg_argptr = new IrFuncTyArg(Type::tvoid->pointerTo(), false,
llvm::Attribute::get(gIR->context(), llvm::AttrBuilder().addAttribute(llvm::Attribute::NoAlias)
.addAttribute(llvm::Attribute::NoCapture)));
llvm::AttrBuilder().addAttribute(llvm::Attribute::NoAlias)
.addAttribute(llvm::Attribute::NoCapture));
#elif LDC_LLVM_VER == 302
fty.arg_argptr = new IrFuncTyArg(Type::tvoid->pointerTo(), false,
llvm::Attributes::get(gIR->context(), llvm::AttrBuilder().addAttribute(llvm::Attributes::NoAlias)
@@ -239,14 +247,18 @@ llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nesttype,
// sext/zext
else if (!byref)
{
#if LDC_LLVM_VER >= 302
attrBuilder.addAttribute(DtoShouldExtend(argtype));
#if LDC_LLVM_VER >= 303
if (llvm::Attribute::AttrKind a = DtoShouldExtend(argtype))
attrBuilder.addAttribute(a);
#elif LDC_LLVM_VER == 302
if (llvm::Attributes::AttrVal a = DtoShouldExtend(argtype))
attrBuilder.addAttribute(a);
#else
a |= DtoShouldExtend(argtype);
#endif
}
#if LDC_LLVM_VER >= 303
llvm::Attribute a = llvm::Attribute::get(gIR->context(), attrBuilder);
llvm::AttrBuilder a = attrBuilder;
#elif LDC_LLVM_VER == 302
llvm::Attributes a = llvm::Attributes::get(gIR->context(), attrBuilder);
#endif
@@ -562,9 +574,8 @@ static void set_param_attrs(TypeFunction* f, llvm::Function* func, FuncDeclarati
// handle implicit args
#define ADD_PA(X) \
if (f->fty.X) { \
if (HAS_ATTRIBUTES(f->fty.X->attrs)) { \
llvm::AttrBuilder builder(f->fty.X->attrs); \
llvm::AttributeSet a = llvm::AttributeSet::get(gIR->context(), idx, builder); \
if (f->fty.X->attrs.hasAttributes()) { \
llvm::AttributeSet a = llvm::AttributeSet::get(gIR->context(), idx, f->fty.X->attrs); \
attrs = attrs.addAttributes(gIR->context(), idx, a); \
} \
idx++; \
@@ -586,12 +597,11 @@ static void set_param_attrs(TypeFunction* f, llvm::Function* func, FuncDeclarati
Parameter* fnarg = Parameter::getNth(f->parameters, k);
assert(fnarg);
llvm::Attribute a = f->fty.args[k]->attrs;
if (HAS_ATTRIBUTES(a))
llvm::AttrBuilder a = f->fty.args[k]->attrs;
if (a.hasAttributes())
{
unsigned i = idx + (f->fty.reverseParams ? n-k-1 : k);
llvm::AttrBuilder builder(a);
llvm::AttributeSet as = llvm::AttributeSet::get(gIR->context(), i, builder);
llvm::AttributeSet as = llvm::AttributeSet::get(gIR->context(), i, a);
attrs = attrs.addAttributes(gIR->context(), i, as);
}
}

View File

@@ -39,6 +39,10 @@ Triple llvm::Triple__get32BitArchVariant(const std::string& triple) {
switch (T.getArch()) {
case Triple::UnknownArch:
case Triple::msp430:
#if LDC_LLVM_VER == 300
case Triple::alpha:
case Triple::systemz:
#endif
T.setArch(Triple::UnknownArch);
break;
@@ -55,14 +59,20 @@ Triple llvm::Triple__get32BitArchVariant(const std::string& triple) {
case Triple::thumb:
case Triple::x86:
case Triple::xcore:
#if LDC_LLVM_VER == 300
case Triple::bfin:
#endif
// Already 32-bit.
break;
case Triple::mips64: T.setArch(Triple::mips); break;
case Triple::mips64el: T.setArch(Triple::mipsel); break;
case Triple::ppc64: T.setArch(Triple::ppc); break;
case Triple::ppc64: T.setArch(Triple::ppc); break;
case Triple::sparcv9: T.setArch(Triple::sparc); break;
case Triple::x86_64: T.setArch(Triple::x86); break;
#if LDC_LLVM_VER == 300
case Triple::ptx64: T.setArch(Triple::ptx32); break;
#endif
}
return T;
}
@@ -80,9 +90,16 @@ Triple llvm::Triple__get64BitArchVariant(const std::string& triple) {
case Triple::tce:
case Triple::thumb:
case Triple::xcore:
#if LDC_LLVM_VER == 300
case Triple::bfin:
#endif
T.setArch(Triple::UnknownArch);
break;
#if LDC_LLVM_VER == 300
case Triple::alpha:
case Triple::systemz:
#endif
case Triple::mips64:
case Triple::mips64el:
case Triple::ppc64:
@@ -96,6 +113,9 @@ Triple llvm::Triple__get64BitArchVariant(const std::string& triple) {
case Triple::ppc: T.setArch(Triple::ppc64); break;
case Triple::sparc: T.setArch(Triple::sparcv9); break;
case Triple::x86: T.setArch(Triple::x86_64); break;
#if LDC_LLVM_VER == 300
case Triple::ptx32: T.setArch(Triple::ptx64); break;
#endif
}
return T;
}

View File

@@ -203,9 +203,9 @@ static LLValue *fixArgument(DValue *argval, TypeFunction* tf, LLType *callableAr
#if LDC_LLVM_VER >= 303
static inline void addToAttributes(llvm::AttributeSet &Attrs,
unsigned Idx, llvm::Attribute Attr)
unsigned Idx, llvm::AttrBuilder B)
{
llvm::AttrBuilder Builder(Attr);
llvm::AttrBuilder Builder(B);
Attrs = Attrs.addAttributes(gIR->context(), Idx,
llvm::AttributeSet::get(gIR->context(), Idx, Builder));
}

View File

@@ -18,21 +18,20 @@
#include "gen/tollvm.h"
#if LDC_LLVM_VER >= 303
IrFuncTyArg::IrFuncTyArg(Type* t, bool bref, llvm::Attribute a) : type(t)
IrFuncTyArg::IrFuncTyArg(Type* t, bool bref, llvm::AttrBuilder a)
#else
IrFuncTyArg::IrFuncTyArg(Type* t, bool bref, llvm::Attributes a) : type(t)
IrFuncTyArg::IrFuncTyArg(Type* t, bool bref, llvm::Attributes a)
#endif
: type(t),
ltype(t != Type::tvoid && bref ? DtoType(t->pointerTo()) : DtoType(t)),
attrs(a), byref(bref), rewrite(0)
{
ltype = t != Type::tvoid && bref ? DtoType(t->pointerTo()) : DtoType(t);
attrs = a;
byref = bref;
rewrite = NULL;
}
#if LDC_LLVM_VER >= 303
bool IrFuncTyArg::isInReg() const { return attrs.hasAttribute(llvm::Attribute::InReg); }
bool IrFuncTyArg::isSRet() const { return attrs.hasAttribute(llvm::Attribute::StructRet); }
bool IrFuncTyArg::isByVal() const { return attrs.hasAttribute(llvm::Attribute::ByVal); }
bool IrFuncTyArg::isInReg() const { return attrs.contains(llvm::Attribute::InReg); }
bool IrFuncTyArg::isSRet() const { return attrs.contains(llvm::Attribute::StructRet); }
bool IrFuncTyArg::isByVal() const { return attrs.contains(llvm::Attribute::ByVal); }
#elif LDC_LLVM_VER == 302
bool IrFuncTyArg::isInReg() const { return attrs.hasAttribute(llvm::Attributes::InReg); }
bool IrFuncTyArg::isSRet() const { return attrs.hasAttribute(llvm::Attributes::StructRet); }

View File

@@ -49,7 +49,7 @@ struct IrFuncTyArg : IrBase
/** These are the final LLVM attributes used for the function.
* Must be valid for the LLVM Type and byref setting */
#if LDC_LLVM_VER >= 303
llvm::Attribute attrs;
llvm::AttrBuilder attrs;
#else
llvm::Attributes attrs;
#endif
@@ -76,7 +76,7 @@ struct IrFuncTyArg : IrBase
* LLVM Type will be of DtoType(type->pointerTo()), instead
* of just DtoType(type) */
#if LDC_LLVM_VER >= 303
IrFuncTyArg(Type* t, bool byref, llvm::Attribute a = llvm::Attribute());
IrFuncTyArg(Type* t, bool byref, llvm::AttrBuilder b = llvm::AttrBuilder());
#elif LDC_LLVM_VER == 302
IrFuncTyArg(Type* t, bool byref, llvm::Attributes a = llvm::Attributes());
#else