diff --git a/gen/abi-x86-64.cpp b/gen/abi-x86-64.cpp index 4ca1c66b..0cca16d4 100644 --- a/gen/abi-x86-64.cpp +++ b/gen/abi-x86-64.cpp @@ -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 diff --git a/gen/abi-x86.cpp b/gen/abi-x86.cpp index dbc68b27..ddc87236 100644 --- a/gen/abi-x86.cpp +++ b/gen/abi-x86.cpp @@ -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 diff --git a/gen/functions.cpp b/gen/functions.cpp index ed797e10..c3165fc4 100644 --- a/gen/functions.cpp +++ b/gen/functions.cpp @@ -37,6 +37,7 @@ #include "gen/abi.h" #include "gen/nested.h" #include "gen/pragma.h" +#include #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); } } diff --git a/gen/tocall.cpp b/gen/tocall.cpp index e5853f30..b918ff4d 100644 --- a/gen/tocall.cpp +++ b/gen/tocall.cpp @@ -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)); } diff --git a/ir/irfuncty.cpp b/ir/irfuncty.cpp index c5380ff2..05ed7d97 100644 --- a/ir/irfuncty.cpp +++ b/ir/irfuncty.cpp @@ -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); } diff --git a/ir/irfuncty.h b/ir/irfuncty.h index 01c630d9..0beac0cc 100644 --- a/ir/irfuncty.h +++ b/ir/irfuncty.h @@ -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