diff --git a/gen/abi-x86-64.cpp b/gen/abi-x86-64.cpp index f3e54d86..4ca1c66b 100644 --- a/gen/abi-x86-64.cpp +++ b/gen/abi-x86-64.cpp @@ -533,7 +533,9 @@ void X86_64TargetABI::rewriteFunctionType(TypeFunction* tf) { if (fty.arg_this) { Logger::println("Putting 'this' in register"); -#if LDC_LLVM_VER >= 302 +#if LDC_LLVM_VER >= 303 + fty.arg_this->attrs = llvm::Attribute::get(gIR->context(), llvm::AttrBuilder().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 fty.arg_this->attrs = llvm::Attribute::InReg; @@ -543,7 +545,9 @@ void X86_64TargetABI::rewriteFunctionType(TypeFunction* tf) { else if (fty.arg_nest) { Logger::println("Putting context ptr in register"); -#if LDC_LLVM_VER >= 302 +#if LDC_LLVM_VER >= 303 + fty.arg_nest->attrs = llvm::Attribute::get(gIR->context(), llvm::AttrBuilder().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 fty.arg_nest->attrs = llvm::Attribute::InReg; @@ -555,7 +559,10 @@ void X86_64TargetABI::rewriteFunctionType(TypeFunction* tf) { Logger::println("Putting sret ptr in register"); // sret and inreg are incompatible, but the ABI requires the // sret parameter to be in RDI in this situation... -#if LDC_LLVM_VER >= 302 +#if LDC_LLVM_VER >= 303 + sret->attrs = llvm::Attribute::get(gIR->context(), llvm::AttrBuilder(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)); #else @@ -578,7 +585,9 @@ void X86_64TargetABI::rewriteFunctionType(TypeFunction* tf) { { if (xmmcount > 0) { Logger::println("Putting float parameter in register"); -#if LDC_LLVM_VER >= 302 +#if LDC_LLVM_VER >= 303 + arg.attrs = llvm::Attribute::get(gIR->context(), llvm::AttrBuilder(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 arg.attrs |= llvm::Attribute::InReg; @@ -593,7 +602,9 @@ void X86_64TargetABI::rewriteFunctionType(TypeFunction* tf) { else if (arg.byref && !arg.isByVal()) { Logger::println("Putting byref parameter in register"); -#if LDC_LLVM_VER >= 302 +#if LDC_LLVM_VER >= 303 + arg.attrs = llvm::Attribute::get(gIR->context(), llvm::AttrBuilder(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 arg.attrs |= llvm::Attribute::InReg; @@ -603,7 +614,9 @@ void X86_64TargetABI::rewriteFunctionType(TypeFunction* tf) { else if (ty->ty == Tpointer) { Logger::println("Putting pointer parameter in register"); -#if LDC_LLVM_VER >= 302 +#if LDC_LLVM_VER >= 303 + arg.attrs = llvm::Attribute::get(gIR->context(), llvm::AttrBuilder(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 arg.attrs |= llvm::Attribute::InReg; @@ -613,7 +626,9 @@ void X86_64TargetABI::rewriteFunctionType(TypeFunction* tf) { else if (ty->isintegral() && sz <= 8) { Logger::println("Putting integral parameter in register"); -#if LDC_LLVM_VER >= 302 +#if LDC_LLVM_VER >= 303 + arg.attrs = llvm::Attribute::get(gIR->context(), llvm::AttrBuilder(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 arg.attrs |= llvm::Attribute::InReg; @@ -627,7 +642,9 @@ void X86_64TargetABI::rewriteFunctionType(TypeFunction* tf) { arg.rewrite = &compositeToInt; arg.ltype = compositeToInt.type(arg.type, arg.ltype); arg.byref = false; -#if LDC_LLVM_VER >= 302 +#if LDC_LLVM_VER >= 303 + arg.attrs = llvm::Attribute::get(gIR->context(), llvm::AttrBuilder().addAttribute(llvm::Attribute::InReg)); +#elif LDC_LLVM_VER == 302 arg.attrs = llvm::Attributes::get(gIR->context(), llvm::AttrBuilder().addAttribute(llvm::Attributes::InReg)); #else arg.attrs = llvm::Attribute::InReg; diff --git a/gen/abi-x86.cpp b/gen/abi-x86.cpp index a5b768e0..dbc68b27 100644 --- a/gen/abi-x86.cpp +++ b/gen/abi-x86.cpp @@ -124,7 +124,9 @@ struct X86TargetABI : TargetABI if (fty.arg_this) { Logger::println("Putting 'this' in register"); -#if LDC_LLVM_VER >= 302 +#if LDC_LLVM_VER >= 303 + fty.arg_this->attrs = llvm::Attribute::get(gIR->context(), llvm::AttrBuilder().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 fty.arg_this->attrs = llvm::Attribute::InReg; @@ -133,7 +135,9 @@ struct X86TargetABI : TargetABI else if (fty.arg_nest) { Logger::println("Putting context ptr in register"); -#if LDC_LLVM_VER >= 302 +#if LDC_LLVM_VER >= 303 + fty.arg_nest->attrs = llvm::Attribute::get(gIR->context(), llvm::AttrBuilder().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 fty.arg_nest->attrs = llvm::Attribute::InReg; @@ -144,7 +148,10 @@ struct X86TargetABI : TargetABI Logger::println("Putting sret ptr in register"); // sret and inreg are incompatible, but the ABI requires the // sret parameter to be in EAX in this situation... -#if LDC_LLVM_VER >= 302 +#if LDC_LLVM_VER >= 303 + sret->attrs = llvm::Attribute::get(gIR->context(), llvm::AttrBuilder(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)); #else @@ -167,7 +174,9 @@ struct X86TargetABI : TargetABI if (last->byref && !last->isByVal()) { Logger::println("Putting last (byref) parameter in register"); -#if LDC_LLVM_VER >= 302 +#if LDC_LLVM_VER >= 303 + last->attrs = llvm::Attribute::get(gIR->context(), llvm::AttrBuilder(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 last->attrs |= llvm::Attribute::InReg; @@ -182,13 +191,17 @@ struct X86TargetABI : TargetABI last->ltype = compositeToInt.type(last->type, last->ltype); last->byref = false; // erase previous attributes -#if LDC_LLVM_VER >= 302 +#if LDC_LLVM_VER >= 303 + last->attrs = llvm::Attribute(); +#elif LDC_LLVM_VER == 302 last->attrs = llvm::Attributes(); #else last->attrs = llvm::Attribute::None; #endif } -#if LDC_LLVM_VER >= 302 +#if LDC_LLVM_VER >= 303 + last->attrs = llvm::Attribute::get(gIR->context(), llvm::AttrBuilder(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 last->attrs |= llvm::Attribute::InReg; diff --git a/gen/functions.cpp b/gen/functions.cpp index 2091559f..a0f505dc 100644 --- a/gen/functions.cpp +++ b/gen/functions.cpp @@ -68,7 +68,9 @@ llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nesttype, else { Type* rt = f->next; -#if LDC_LLVM_VER >= 302 +#if LDC_LLVM_VER >= 303 + llvm::Attribute a; +#elif LDC_LLVM_VER == 302 llvm::Attributes a; #else llvm::Attributes a = None; @@ -78,9 +80,15 @@ llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nesttype, if (abi->returnInArg(f)) { #if LDC_LLVM_VER >= 302 +#if LDC_LLVM_VER >= 303 + fty.arg_sret = new IrFuncTyArg(rt, true, llvm::Attribute::get(gIR->context(), + llvm::AttrBuilder().addAttribute(llvm::Attribute::StructRet) + .addAttribute(llvm::Attribute::NoAlias) +#else fty.arg_sret = new IrFuncTyArg(rt, true, llvm::Attributes::get(gIR->context(), llvm::AttrBuilder().addAttribute(llvm::Attributes::StructRet) .addAttribute(llvm::Attributes::NoAlias) +#endif #if !STRUCTTHISREF // In D2 where 'this' in structs is a reference, nocapture // might not actually be applicable, even if it probably still @@ -146,7 +154,11 @@ llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nesttype, fty.arg_arguments = new IrFuncTyArg(Type::typeinfo->type->arrayOf(), false); lidx++; // _argptr -#if LDC_LLVM_VER >= 302 +#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))); +#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) .addAttribute(llvm::Attributes::NoCapture))); @@ -186,7 +198,9 @@ llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nesttype, #endif Type* argtype = arg->type; -#if LDC_LLVM_VER >= 302 +#if LDC_LLVM_VER >= 303 + llvm::Attribute a; +#elif LDC_LLVM_VER == 302 llvm::Attributes a; #else llvm::Attributes a = None; @@ -203,7 +217,9 @@ llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nesttype, // byval else if (abi->passByVal(byref ? argtype->pointerTo() : argtype)) { -#if LDC_LLVM_VER >= 302 +#if LDC_LLVM_VER >= 303 + if (!byref) a = llvm::Attribute::get(gIR->context(), llvm::AttrBuilder(a).addAttribute(llvm::Attribute::ByVal)); +#elif LDC_LLVM_VER == 302 if (!byref) a = llvm::Attributes::get(gIR->context(), llvm::AttrBuilder(a).addAttribute(llvm::Attributes::ByVal)); #else if (!byref) a |= llvm::Attribute::ByVal; @@ -214,7 +230,9 @@ llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nesttype, // sext/zext else if (!byref) { -#if LDC_LLVM_VER >= 302 +#if LDC_LLVM_VER >= 303 + a = llvm::Attribute::get(gIR->context(), llvm::AttrBuilder(a).addAttributes(DtoShouldExtend(argtype))); +#elif LDC_LLVM_VER == 302 a = llvm::Attributes::get(gIR->context(), llvm::AttrBuilder(a).addAttributes(DtoShouldExtend(argtype))); #else a |= DtoShouldExtend(argtype); @@ -333,7 +351,9 @@ LLFunction* DtoInlineIRFunction(FuncDeclaration* fdecl) LLFunction* fun = gIR->module->getFunction(mangled_name); fun->setLinkage(llvm::GlobalValue::LinkOnceODRLinkage); -#if LDC_LLVM_VER >= 302 +#if LDC_LLVM_VER >= 303 + fun->addFnAttr(llvm::Attribute::AlwaysInline); +#elif LDC_LLVM_VER == 302 fun->addFnAttr(llvm::Attributes::AlwaysInline); #else fun->addFnAttr(AlwaysInline); @@ -544,7 +564,9 @@ static void set_param_attrs(TypeFunction* f, llvm::Function* func, FuncDeclarati // set attrs on the rest of the arguments size_t n = Parameter::dim(f->parameters); -#if LDC_LLVM_VER >= 302 +#if LDC_LLVM_VER >= 303 + LLSmallVector attrptr(n, llvm::Attribute()); +#elif LDC_LLVM_VER == 302 LLSmallVector attrptr(n, llvm::Attributes()); #else LLSmallVector attrptr(n, None); @@ -587,7 +609,11 @@ static void set_param_attrs(TypeFunction* f, llvm::Function* func, FuncDeclarati bool found = false; for (size_t j = 0; j < newSize; ++j) { if (attrs[j].Index == curr.Index) { -#if LDC_LLVM_VER >= 302 +#if LDC_LLVM_VER >= 303 + attrs[j].Attrs = llvm::Attribute::get( + gIR->context(), + llvm::AttrBuilder(attrs[j].Attrs).addAttributes(curr.Attrs)); +#elif LDC_LLVM_VER == 302 attrs[j].Attrs = llvm::Attributes::get( gIR->context(), llvm::AttrBuilder(attrs[j].Attrs).addAttributes(curr.Attrs)); @@ -688,7 +714,9 @@ void DtoDeclareFunction(FuncDeclaration* fdecl) if (!fdecl->isIntrinsic()) { set_param_attrs(f, func, fdecl); if (global.params.disableRedZone) { -#if LDC_LLVM_VER >= 302 +#if LDC_LLVM_VER >= 303 + func->addFnAttr(llvm::Attribute::NoRedZone); +#elif LDC_LLVM_VER == 302 func->addFnAttr(llvm::Attributes::NoRedZone); #else func->addFnAttr(NoRedZone); diff --git a/gen/passes/GarbageCollect2Stack.cpp b/gen/passes/GarbageCollect2Stack.cpp index 9bccf089..2c70de25 100644 --- a/gen/passes/GarbageCollect2Stack.cpp +++ b/gen/passes/GarbageCollect2Stack.cpp @@ -27,7 +27,11 @@ #include "llvm/Intrinsics.h" #include "llvm/Support/CallSite.h" #include "llvm/Support/CommandLine.h" +#if LDC_LLVM_VER >= 303 +#include "llvm/IRBuilder.h" +#else #include "llvm/Support/IRBuilder.h" +#endif #include "llvm/Analysis/CallGraph.h" #include "llvm/Analysis/Dominators.h" #include "llvm/Analysis/ValueTracking.h" @@ -716,7 +720,9 @@ bool isSafeToStackAllocate(Instruction* Alloc, Value* V, DominatorTree& DT, for (CallSite::arg_iterator A = B; A != E; ++A) if (A->get() == V) { if (!CS.paramHasAttr(A - B + 1, -#if LDC_LLVM_VER >= 302 +#if LDC_LLVM_VER >= 303 + Attribute::NoCapture +#elif LDC_LLVM_VER == 302 Attributes::NoCapture #else Attribute::NoCapture diff --git a/gen/runtime.cpp b/gen/runtime.cpp index 61e22d59..2ce14705 100644 --- a/gen/runtime.cpp +++ b/gen/runtime.cpp @@ -197,15 +197,44 @@ static void LLVM_D_BuildRuntimeModule() ///////////////////////////////////////////////////////////////////////////////////// // Construct some attribute lists used below (possibly multiple times) -#if LDC_LLVM_VER >= 302 #if LDC_LLVM_VER >= 303 llvm::AttributeSet -#else - llvm::AttrListPtr -#endif NoAttrs, Attr_NoAlias - = NoAttrs.addAttr(gIR->context(), 0, llvm::Attributes::get(gIR->context(), llvm::AttrBuilder().addAttribute(llvm::Attributes::NoAlias))), + = NoAttrs.addAttr(gIR->context(), 0, llvm::Attribute::get(gIR->context(), llvm::AttrBuilder().addAttribute(llvm::Attribute::NoAlias))), + Attr_NoUnwind + = NoAttrs.addAttr(gIR->context(), ~0U, llvm::Attribute::get(gIR->context(), llvm::AttrBuilder().addAttribute(llvm::Attribute::NoUnwind))), + Attr_ReadOnly + = NoAttrs.addAttr(gIR->context(), ~0U, llvm::Attribute::get(gIR->context(), llvm::AttrBuilder().addAttribute(llvm::Attribute::ReadOnly))), + Attr_ReadOnly_NoUnwind + = Attr_ReadOnly.addAttr(gIR->context(), ~0U, llvm::Attribute::get(gIR->context(), llvm::AttrBuilder().addAttribute(llvm::Attribute::NoUnwind))), + Attr_ReadOnly_1_NoCapture + = Attr_ReadOnly.addAttr(gIR->context(), 1, llvm::Attribute::get(gIR->context(), llvm::AttrBuilder().addAttribute(llvm::Attribute::NoCapture))), + Attr_ReadOnly_1_3_NoCapture + = Attr_ReadOnly_1_NoCapture.addAttr(gIR->context(), 3, llvm::Attribute::get(gIR->context(), llvm::AttrBuilder().addAttribute(llvm::Attribute::NoCapture))), + Attr_ReadOnly_NoUnwind_1_NoCapture + = Attr_ReadOnly_1_NoCapture.addAttr(gIR->context(), ~0U, llvm::Attribute::get(gIR->context(), llvm::AttrBuilder().addAttribute(llvm::Attribute::NoUnwind))), + Attr_ReadNone + = NoAttrs.addAttr(gIR->context(), ~0U, llvm::Attribute::get(gIR->context(), llvm::AttrBuilder().addAttribute(llvm::Attribute::ReadNone))), + Attr_1_NoCapture + = NoAttrs.addAttr(gIR->context(), 1, llvm::Attribute::get(gIR->context(), llvm::AttrBuilder().addAttribute(llvm::Attribute::NoCapture))), + Attr_NoAlias_1_NoCapture + = Attr_1_NoCapture.addAttr(gIR->context(), 0, llvm::Attribute::get(gIR->context(), llvm::AttrBuilder().addAttribute(llvm::Attribute::NoAlias))), +#if DMDV1 + Attr_NoAlias_3_NoCapture + = Attr_NoAlias.addAttr(gIR->context(), 3, llvm::Attribute::get(gIR->context(), llvm::AttrBuilder().addAttribute(llvm::Attribute::NoCapture))), +#endif + Attr_1_2_NoCapture + = Attr_1_NoCapture.addAttr(gIR->context(), 2, llvm::Attribute::get(gIR->context(), llvm::AttrBuilder().addAttribute(llvm::Attribute::NoCapture))), + Attr_1_3_NoCapture + = Attr_1_NoCapture.addAttr(gIR->context(), 3, llvm::Attribute::get(gIR->context(), llvm::AttrBuilder().addAttribute(llvm::Attribute::NoCapture))), + Attr_1_4_NoCapture + = Attr_1_NoCapture.addAttr(gIR->context(), 4, llvm::Attribute::get(gIR->context(), llvm::AttrBuilder().addAttribute(llvm::Attribute::NoCapture))); +#elif LDC_LLVM_VER == 302 + llvm::AttrListPtr + NoAttrs, + Attr_NoAlias + = NoAttrs.addAttr(gIR->context(), 0, llvm::Attributes::get(gIR->context(), llvm::AttrBuilder().addAttribute(llvm::Attributes::NoAlias))), Attr_NoUnwind = NoAttrs.addAttr(gIR->context(), ~0U, llvm::Attributes::get(gIR->context(), llvm::AttrBuilder().addAttribute(llvm::Attributes::NoUnwind))), Attr_ReadOnly diff --git a/gen/tocall.cpp b/gen/tocall.cpp index 0b266256..ebe2a22e 100644 --- a/gen/tocall.cpp +++ b/gen/tocall.cpp @@ -404,7 +404,10 @@ DValue* DtoCallFunction(Loc& loc, Type* resulttype, DValue* fnval, Expressions* // add attrs for hidden ptr Attr.Index = 1; Attr.Attrs = tf->fty.arg_sret->attrs; -#if LDC_LLVM_VER >= 302 +#if LDC_LLVM_VER >= 303 + assert((Attr.Attrs.hasAttribute(llvm::Attribute::StructRet) || Attr.Attrs.hasAttribute(llvm::Attribute::InReg)) + && "Sret arg not sret or inreg?"); +#elif LDC_LLVM_VER == 302 assert((Attr.Attrs.hasAttribute(llvm::Attributes::StructRet) || Attr.Attrs.hasAttribute(llvm::Attributes::InReg)) && "Sret arg not sret or inreg?"); #else @@ -525,7 +528,9 @@ DValue* DtoCallFunction(Loc& loc, Type* resulttype, DValue* fnval, Expressions* } size_t n = Parameter::dim(tf->parameters); -#if LDC_LLVM_VER >= 302 +#if LDC_LLVM_VER >= 303 + LLSmallVector attrptr(n, llvm::Attribute()); +#elif LDC_LLVM_VER == 302 LLSmallVector attrptr(n, llvm::Attributes()); #else LLSmallVector attrptr(n, llvm::Attribute::None); diff --git a/gen/tollvm.cpp b/gen/tollvm.cpp index cc4b040b..d21d88f6 100644 --- a/gen/tollvm.cpp +++ b/gen/tollvm.cpp @@ -42,7 +42,11 @@ bool DtoIsPassedByRef(Type* type) return (t == Tstruct || t == Tsarray); } +#if LDC_LLVM_VER >= 303 +llvm::Attribute DtoShouldExtend(Type* type) +#else llvm::Attributes DtoShouldExtend(Type* type) +#endif { type = type->toBasetype(); if (type->isintegral()) @@ -51,7 +55,9 @@ llvm::Attributes DtoShouldExtend(Type* type) { case Tint8: case Tint16: -#if LDC_LLVM_VER >= 302 +#if LDC_LLVM_VER >= 303 + return llvm::Attribute::get(gIR->context(), llvm::AttrBuilder().addAttribute(llvm::Attribute::SExt)); +#elif LDC_LLVM_VER == 302 return llvm::Attributes::get(gIR->context(), llvm::AttrBuilder().addAttribute(llvm::Attributes::SExt)); #else return llvm::Attribute::SExt; @@ -59,14 +65,18 @@ llvm::Attributes DtoShouldExtend(Type* type) case Tuns8: case Tuns16: -#if LDC_LLVM_VER >= 302 +#if LDC_LLVM_VER >= 303 + return llvm::Attribute::get(gIR->context(), llvm::AttrBuilder().addAttribute(llvm::Attribute::ZExt)); +#elif LDC_LLVM_VER == 302 return llvm::Attributes::get(gIR->context(), llvm::AttrBuilder().addAttribute(llvm::Attributes::ZExt)); #else return llvm::Attribute::ZExt; #endif } } -#if LDC_LLVM_VER >= 302 +#if LDC_LLVM_VER >= 303 + return llvm::Attribute(); +#elif LDC_LLVM_VER == 302 return llvm::Attributes(); #else return llvm::Attribute::None; diff --git a/gen/tollvm.h b/gen/tollvm.h index 5e0530a9..0cd00dab 100644 --- a/gen/tollvm.h +++ b/gen/tollvm.h @@ -34,7 +34,11 @@ LLType* DtoTypeNotVoid(Type* t); bool DtoIsPassedByRef(Type* type); // should argument be zero or sign extended +#if LDC_LLVM_VER >= 303 +llvm::Attribute DtoShouldExtend(Type* type); +#else llvm::Attributes DtoShouldExtend(Type* type); +#endif // tuple helper // takes a arguments list and makes a struct type out of them diff --git a/ir/irfunction.cpp b/ir/irfunction.cpp index c075a530..93f37654 100644 --- a/ir/irfunction.cpp +++ b/ir/irfunction.cpp @@ -72,7 +72,10 @@ IrFunction::IrFunction(FuncDeclaration* fd) void IrFunction::setNeverInline() { -#if LDC_LLVM_VER >= 302 +#if LDC_LLVM_VER >= 303 + assert(!func->getFnAttributes().hasAttribute(llvm::Attribute::AlwaysInline) && "function can't be never- and always-inline at the same time"); + func->addFnAttr(llvm::Attribute::NoInline); +#elif LDC_LLVM_VER == 302 assert(!func->getFnAttributes().hasAttribute(llvm::Attributes::AlwaysInline) && "function can't be never- and always-inline at the same time"); func->addFnAttr(llvm::Attributes::NoInline); #else @@ -83,7 +86,10 @@ void IrFunction::setNeverInline() void IrFunction::setAlwaysInline() { -#if LDC_LLVM_VER >= 302 +#if LDC_LLVM_VER >= 303 + assert(!func->getFnAttributes().hasAttribute(llvm::Attribute::NoInline) && "function can't be never- and always-inline at the same time"); + func->addFnAttr(llvm::Attribute::AlwaysInline); +#elif LDC_LLVM_VER == 302 assert(!func->getFnAttributes().hasAttribute(llvm::Attributes::NoInline) && "function can't be never- and always-inline at the same time"); func->addFnAttr(llvm::Attributes::AlwaysInline); #else diff --git a/ir/irfuncty.cpp b/ir/irfuncty.cpp index c1d6c8c6..c5380ff2 100644 --- a/ir/irfuncty.cpp +++ b/ir/irfuncty.cpp @@ -17,7 +17,11 @@ #include "gen/llvm.h" #include "gen/tollvm.h" +#if LDC_LLVM_VER >= 303 +IrFuncTyArg::IrFuncTyArg(Type* t, bool bref, llvm::Attribute a) : type(t) +#else IrFuncTyArg::IrFuncTyArg(Type* t, bool bref, llvm::Attributes a) : type(t) +#endif { ltype = t != Type::tvoid && bref ? DtoType(t->pointerTo()) : DtoType(t); attrs = a; @@ -25,7 +29,11 @@ IrFuncTyArg::IrFuncTyArg(Type* t, bool bref, llvm::Attributes a) : type(t) rewrite = NULL; } -#if LDC_LLVM_VER >= 302 +#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); } +#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); } bool IrFuncTyArg::isByVal() const { return attrs.hasAttribute(llvm::Attributes::ByVal); } diff --git a/ir/irfuncty.h b/ir/irfuncty.h index e56b21c9..4052085e 100644 --- a/ir/irfuncty.h +++ b/ir/irfuncty.h @@ -44,7 +44,11 @@ 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; +#else llvm::Attributes attrs; +#endif /** 'true' if the final LLVM argument is a LLVM reference type. * Must be true when the D Type is a value type, but the final @@ -67,7 +71,9 @@ struct IrFuncTyArg : IrBase * @param byref Initial value for the 'byref' field. If true the initial * LLVM Type will be of DtoType(type->pointerTo()), instead * of just DtoType(type) */ -#if LDC_LLVM_VER >= 302 +#if LDC_LLVM_VER >= 303 + IrFuncTyArg(Type* t, bool byref, llvm::Attribute a = llvm::Attribute()); +#elif LDC_LLVM_VER == 302 IrFuncTyArg(Type* t, bool byref, llvm::Attributes a = llvm::Attributes()); #else IrFuncTyArg(Type* t, bool byref, llvm::Attributes a = llvm::Attribute::None);