diff --git a/driver/cl_options.cpp b/driver/cl_options.cpp index 6416e89e..0a10e807 100644 --- a/driver/cl_options.cpp +++ b/driver/cl_options.cpp @@ -2,7 +2,11 @@ #include "gen/cl_helpers.h" #include "llvm/Target/TargetMachine.h" +#if LDC_LLVM_VER >= 302 +#include "llvm/DataLayout.h" +#else #include "llvm/Target/TargetData.h" +#endif #include "gen/logger.h" diff --git a/driver/main.cpp b/driver/main.cpp index a277a424..15ddb5e0 100644 --- a/driver/main.cpp +++ b/driver/main.cpp @@ -238,7 +238,11 @@ int main(int argc, char** argv) // Handle fixed-up arguments! cl::SetVersionPrinter(&printVersion); +#if LDC_LLVM_VER >= 302 + cl::ParseCommandLineOptions(final_args.size(), const_cast(&final_args[0]), "LLVM-based D Compiler\n"); +#else cl::ParseCommandLineOptions(final_args.size(), const_cast(&final_args[0]), "LLVM-based D Compiler\n", true); +#endif // Print config file path if -v was passed if (global.params.verbose) { @@ -569,11 +573,15 @@ int main(int argc, char** argv) gTargetMachine = target; - gTargetData = target->getTargetData(); +#if LDC_LLVM_VER >= 302 + gDataLayout = target->getDataLayout(); +#else + gDataLayout = target->getTargetData(); +#endif - global.params.isLE = gTargetData->isLittleEndian(); + global.params.isLE = gDataLayout->isLittleEndian(); // Starting with LLVM 3.1 we could also use global.params.targetTriple.isArch64Bit(); - global.params.is64bit = gTargetData->getPointerSizeInBits() == 64; + global.params.is64bit = gDataLayout->getPointerSizeInBits() == 64; global.params.cpu = static_cast(global.params.targetTriple.getArch()); global.params.os = static_cast(global.params.targetTriple.getOS()); diff --git a/driver/toobj.cpp b/driver/toobj.cpp index 3cb0097b..a7047651 100644 --- a/driver/toobj.cpp +++ b/driver/toobj.cpp @@ -121,10 +121,17 @@ void emit_file(llvm::TargetMachine &Target, llvm::Module& m, llvm::raw_fd_ostrea // Build up all of the passes that we want to do to the module. FunctionPassManager Passes(&m); +#if LDC_LLVM_VER >= 302 + if (const DataLayout *DL = Target.getDataLayout()) + Passes.add(new DataLayout(*DL)); + else + Passes.add(new DataLayout(&m)); +#else if (const TargetData *TD = Target.getTargetData()) Passes.add(new TargetData(*TD)); else Passes.add(new TargetData(&m)); +#endif llvm::formatted_raw_ostream fout(out); if (Target.addPassesToEmitFile(Passes, fout, fileType, codeGenOptLevel())) diff --git a/gen/abi-x86-64.cpp b/gen/abi-x86-64.cpp index 86e83efa..74201404 100644 --- a/gen/abi-x86-64.cpp +++ b/gen/abi-x86-64.cpp @@ -526,13 +526,21 @@ void X86_64TargetABI::rewriteFunctionType(TypeFunction* tf) { if (fty.arg_this) { Logger::println("Putting 'this' in register"); +#if LDC_LLVM_VER >= 302 + fty.arg_this->attrs = llvm::Attributes::get(llvm::Attributes::Builder().addAttribute(llvm::Attributes::InReg)); +#else fty.arg_this->attrs = llvm::Attribute::InReg; +#endif --regcount; } else if (fty.arg_nest) { Logger::println("Putting context ptr in register"); +#if LDC_LLVM_VER >= 302 + fty.arg_nest->attrs = llvm::Attributes::get(llvm::Attributes::Builder().addAttribute(llvm::Attributes::InReg)); +#else fty.arg_nest->attrs = llvm::Attribute::InReg; +#endif --regcount; } else if (IrFuncTyArg* sret = fty.arg_sret) @@ -540,8 +548,13 @@ 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 + sret->attrs = llvm::Attributes::get(llvm::Attributes::Builder(sret->attrs).addAttribute(llvm::Attributes::InReg) + .removeAttribute(llvm::Attributes::StructRet)); +#else sret->attrs = (sret->attrs | llvm::Attribute::InReg) & ~llvm::Attribute::StructRet; +#endif --regcount; } @@ -558,7 +571,11 @@ void X86_64TargetABI::rewriteFunctionType(TypeFunction* tf) { { if (xmmcount > 0) { Logger::println("Putting float parameter in register"); +#if LDC_LLVM_VER >= 302 + arg.attrs = llvm::Attributes::get(llvm::Attributes::Builder(arg.attrs).addAttribute(llvm::Attributes::InReg)); +#else arg.attrs |= llvm::Attribute::InReg; +#endif --xmmcount; } } @@ -569,19 +586,31 @@ void X86_64TargetABI::rewriteFunctionType(TypeFunction* tf) { else if (arg.byref && !arg.isByVal()) { Logger::println("Putting byref parameter in register"); +#if LDC_LLVM_VER >= 302 + arg.attrs = llvm::Attributes::get(llvm::Attributes::Builder(arg.attrs).addAttribute(llvm::Attributes::InReg)); +#else arg.attrs |= llvm::Attribute::InReg; +#endif --regcount; } else if (ty->ty == Tpointer) { Logger::println("Putting pointer parameter in register"); +#if LDC_LLVM_VER >= 302 + arg.attrs = llvm::Attributes::get(llvm::Attributes::Builder(arg.attrs).addAttribute(llvm::Attributes::InReg)); +#else arg.attrs |= llvm::Attribute::InReg; +#endif --regcount; } else if (ty->isintegral() && sz <= 8) { Logger::println("Putting integral parameter in register"); +#if LDC_LLVM_VER >= 302 + arg.attrs = llvm::Attributes::get(llvm::Attributes::Builder(arg.attrs).addAttribute(llvm::Attributes::InReg)); +#else arg.attrs |= llvm::Attribute::InReg; +#endif --regcount; } else if ((ty->ty == Tstruct || ty->ty == Tsarray) && @@ -591,7 +620,11 @@ 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 + arg.attrs = llvm::Attributes::get(llvm::Attributes::Builder().addAttribute(llvm::Attributes::InReg)); +#else arg.attrs = llvm::Attribute::InReg; +#endif --regcount; } } diff --git a/gen/abi-x86.cpp b/gen/abi-x86.cpp index edbfd1c3..368b7875 100644 --- a/gen/abi-x86.cpp +++ b/gen/abi-x86.cpp @@ -115,20 +115,33 @@ struct X86TargetABI : TargetABI if (fty.arg_this) { Logger::println("Putting 'this' in register"); +#if LDC_LLVM_VER >= 302 + fty.arg_this->attrs = llvm::Attributes::get(llvm::Attributes::Builder().addAttribute(llvm::Attributes::InReg)); +#else fty.arg_this->attrs = llvm::Attribute::InReg; +#endif } else if (fty.arg_nest) { Logger::println("Putting context ptr in register"); +#if LDC_LLVM_VER >= 302 + fty.arg_nest->attrs = llvm::Attributes::get(llvm::Attributes::Builder().addAttribute(llvm::Attributes::InReg)); +#else fty.arg_nest->attrs = llvm::Attribute::InReg; +#endif } else if (IrFuncTyArg* sret = fty.arg_sret) { 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 + sret->attrs = llvm::Attributes::get(llvm::Attributes::Builder(sret->attrs).addAttribute(llvm::Attributes::InReg) + .removeAttribute(llvm::Attributes::StructRet)); +#else sret->attrs = (sret->attrs | llvm::Attribute::InReg) & ~llvm::Attribute::StructRet; +#endif } // otherwise try to mark the last param inreg else if (!fty.args.empty()) @@ -145,7 +158,11 @@ struct X86TargetABI : TargetABI if (last->byref && !last->isByVal()) { Logger::println("Putting last (byref) parameter in register"); +#if LDC_LLVM_VER >= 302 + last->attrs = llvm::Attributes::get(llvm::Attributes::Builder(last->attrs).addAttribute(llvm::Attributes::InReg)); +#else last->attrs |= llvm::Attribute::InReg; +#endif } else if (!lastTy->isfloating() && (sz == 1 || sz == 2 || sz == 4)) // right? { @@ -156,9 +173,17 @@ struct X86TargetABI : TargetABI last->ltype = compositeToInt.type(last->type, last->ltype); last->byref = false; // erase previous attributes +#if LDC_LLVM_VER >= 302 + last->attrs = llvm::Attributes(); +#else last->attrs = llvm::Attribute::None; +#endif } +#if LDC_LLVM_VER >= 302 + last->attrs = llvm::Attributes::get(llvm::Attributes::Builder(last->attrs).addAttribute(llvm::Attributes::InReg)); +#else last->attrs |= llvm::Attribute::InReg; +#endif } } diff --git a/gen/classes.cpp b/gen/classes.cpp index 4db73d7f..2e268bea 100644 --- a/gen/classes.cpp +++ b/gen/classes.cpp @@ -558,7 +558,7 @@ static LLConstant* build_offti_entry(ClassDeclaration* cd, VarDeclaration* vd) // assert(vd->ir.irField); // grab the offset from llvm and the formal class type - size_t offset = gTargetData->getStructLayout(isaStruct(cd->type->ir.type->get()))->getElementOffset(vd->ir.irField->index); + size_t offset = gDataLayout->getStructLayout(isaStruct(cd->type->ir.type->get()))->getElementOffset(vd->ir.irField->index); // offset nested struct/union fields offset += vd->ir.irField->unionOffset; diff --git a/gen/functions.cpp b/gen/functions.cpp index 8b5754ce..79334f2c 100644 --- a/gen/functions.cpp +++ b/gen/functions.cpp @@ -25,7 +25,9 @@ #include "gen/nested.h" #include "gen/pragma.h" +#if LDC_LLVM_VER < 302 using namespace llvm::Attribute; +#endif llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nesttype, bool ismain) { @@ -57,12 +59,22 @@ llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nesttype, else { Type* rt = f->next; +#if LDC_LLVM_VER >= 302 + llvm::Attributes a; +#else llvm::Attributes a = None; +#endif // sret return if (abi->returnInArg(f)) { +#if LDC_LLVM_VER >= 302 + fty.arg_sret = new IrFuncTyArg(rt, true, llvm::Attributes::get(llvm::Attributes::Builder().addAttribute(llvm::Attributes::StructRet) + .addAttribute(llvm::Attributes::NoAlias) + .addAttribute(llvm::Attributes::NoCapture))); +#else fty.arg_sret = new IrFuncTyArg(rt, true, StructRet | NoAlias | NoCapture); +#endif rt = Type::tvoid; lidx++; } @@ -112,7 +124,13 @@ 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 + fty.arg_argptr = new IrFuncTyArg(Type::tvoid->pointerTo(), false, + llvm::Attributes::get(llvm::Attributes::Builder().addAttribute(llvm::Attributes::NoAlias) + .addAttribute(llvm::Attributes::NoCapture))); +#else fty.arg_argptr = new IrFuncTyArg(Type::tvoid->pointerTo(), false, NoAlias | NoCapture); +#endif lidx++; } } @@ -146,7 +164,11 @@ llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nesttype, #endif Type* argtype = arg->type; +#if LDC_LLVM_VER >= 302 + llvm::Attributes a; +#else llvm::Attributes a = None; +#endif // handle lazy args if (arg->storageClass & STClazy) @@ -159,7 +181,11 @@ llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nesttype, // byval else if (abi->passByVal(byref ? argtype->pointerTo() : argtype)) { +#if LDC_LLVM_VER >= 302 + if (!byref) a = llvm::Attributes::get(llvm::Attributes::Builder(a).addAttribute(llvm::Attributes::ByVal)); +#else if (!byref) a |= llvm::Attribute::ByVal; +#endif // set byref, because byval requires a pointed LLVM type byref = true; } @@ -409,7 +435,11 @@ 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 + LLSmallVector attrptr(n, llvm::Attributes()); +#else LLSmallVector attrptr(n, None); +#endif for (size_t k = 0; k < n; ++k) { @@ -513,7 +543,11 @@ void DtoDeclareFunction(FuncDeclaration* fdecl) if (!fdecl->isIntrinsic()) { set_param_attrs(f, func, fdecl); if (global.params.disableRedZone) { +#if LDC_LLVM_VER >= 302 + func->addFnAttr(llvm::Attributes::NoRedZone); +#else func->addFnAttr(NoRedZone); +#endif } } diff --git a/gen/irstate.cpp b/gen/irstate.cpp index 73837b1f..ffd22751 100644 --- a/gen/irstate.cpp +++ b/gen/irstate.cpp @@ -17,7 +17,11 @@ IRState* gIR = 0; llvm::TargetMachine* gTargetMachine = 0; -const llvm::TargetData* gTargetData = 0; +#if LDC_LLVM_VER >= 302 +const llvm::DataLayout* gDataLayout = 0; +#else +const llvm::TargetData* gDataLayout = 0; +#endif TargetABI* gABI = 0; ////////////////////////////////////////////////////////////////////////////////////////// diff --git a/gen/irstate.h b/gen/irstate.h index e4aa387c..2a19aaac 100644 --- a/gen/irstate.h +++ b/gen/irstate.h @@ -31,7 +31,11 @@ struct TargetABI; extern IRState* gIR; extern llvm::TargetMachine* gTargetMachine; -extern const llvm::TargetData* gTargetData; +#if LDC_LLVM_VER >= 302 +extern const llvm::DataLayout* gDataLayout; +#else +extern const llvm::TargetData* gDataLayout; +#endif extern TargetABI* gABI; struct TypeFunction; diff --git a/gen/llvm.h b/gen/llvm.h index da9b652a..da582fe1 100644 --- a/gen/llvm.h +++ b/gen/llvm.h @@ -12,12 +12,12 @@ #include "llvm/Value.h" #include "llvm/Attributes.h" -#include "llvm/Target/TargetData.h" - #if LDC_LLVM_VER >= 302 +#include "llvm/DataLayout.h" #include "llvm/DebugInfo.h" #include "llvm/IRBuilder.h" #else +#include "llvm/Target/TargetData.h" #include "llvm/Analysis/DebugInfo.h" #include "llvm/Support/IRBuilder.h" #endif diff --git a/gen/llvmhelpers.cpp b/gen/llvmhelpers.cpp index a06dae59..114e2fd8 100644 --- a/gen/llvmhelpers.cpp +++ b/gen/llvmhelpers.cpp @@ -1114,7 +1114,7 @@ void DtoVarDeclaration(VarDeclaration* vd) LLType* lltype = DtoType(type); llvm::Value* allocainst; - if(gTargetData->getTypeSizeInBits(lltype) == 0) + if(gDataLayout->getTypeSizeInBits(lltype) == 0) allocainst = llvm::ConstantPointerNull::get(getPtrToType(lltype)); else allocainst = DtoAlloca(type, vd->toChars()); @@ -1595,7 +1595,7 @@ void DtoOverloadedIntrinsicName(TemplateInstance* ti, TemplateDeclaration* td, s } char tmp[21]; // probably excessive, but covers a uint64_t - sprintf(tmp, "%lu", static_cast(gTargetData->getTypeSizeInBits(DtoType(T)))); + sprintf(tmp, "%lu", static_cast(gDataLayout->getTypeSizeInBits(DtoType(T)))); // replace # in name with bitsize name = td->intrinsicName; @@ -1770,7 +1770,7 @@ size_t realignOffset(size_t offset, Type* type) } // then we check against the llvm alignment - size_t alignsize2 = gTargetData->getABITypeAlignment(T); + size_t alignsize2 = gDataLayout->getABITypeAlignment(T); // if it differs we need to insert manual padding as well if (alignsize != alignsize2) diff --git a/gen/module.cpp b/gen/module.cpp index e8b9c189..da6e1a50 100644 --- a/gen/module.cpp +++ b/gen/module.cpp @@ -2,7 +2,11 @@ #include "llvm/Analysis/Verifier.h" #include "llvm/Module.h" #include "llvm/LinkAllPasses.h" +#if LDC_LLVM_VER >= 302 +#include "llvm/DataLayout.h" +#else #include "llvm/Target/TargetData.h" +#endif #include "mars.h" #include "module.h" @@ -245,7 +249,7 @@ llvm::Module* Module::genLLVMModule(llvm::LLVMContext& context, Ir* sir) ir.module->setTargetTriple(global.params.targetTriple.str()); // set final data layout - ir.module->setDataLayout(gTargetData->getStringRepresentation()); + ir.module->setDataLayout(gDataLayout->getStringRepresentation()); if (Logger::enabled()) Logger::cout() << "Final data layout: " << ir.module->getDataLayout() << '\n'; diff --git a/gen/optimizer.cpp b/gen/optimizer.cpp index 331a92af..c5ae4a54 100644 --- a/gen/optimizer.cpp +++ b/gen/optimizer.cpp @@ -8,7 +8,11 @@ #include "llvm/LinkAllPasses.h" #include "llvm/Analysis/LoopPass.h" #include "llvm/Analysis/Verifier.h" +#if LDC_LLVM_VER >= 302 +#include "llvm/DataLayout.h" +#else #include "llvm/Target/TargetData.h" +#endif #include "llvm/Support/CommandLine.h" #include "llvm/Support/PassNameParser.h" #include "llvm/Transforms/IPO.h" @@ -274,7 +278,11 @@ bool ldc_optimize_module(llvm::Module* m) if (verifyEach) pm.add(createVerifierPass()); +#if LDC_LLVM_VER >= 302 + addPass(pm, new DataLayout(m)); +#else addPass(pm, new TargetData(m)); +#endif bool optimize = optimizeLevel != 0 || doInline(); diff --git a/gen/passes/SimplifyDRuntimeCalls.cpp b/gen/passes/SimplifyDRuntimeCalls.cpp index c2441ba5..98d7978a 100644 --- a/gen/passes/SimplifyDRuntimeCalls.cpp +++ b/gen/passes/SimplifyDRuntimeCalls.cpp @@ -28,7 +28,11 @@ #endif #include "llvm/Analysis/AliasAnalysis.h" #include "llvm/Analysis/ValueTracking.h" +#if LDC_LLVM_VER >= 302 +#include "llvm/DataLayout.h" +#else #include "llvm/Target/TargetData.h" +#endif #include "llvm/ADT/StringMap.h" #include "llvm/ADT/Statistic.h" #include "llvm/Support/Compiler.h" @@ -52,7 +56,11 @@ namespace { protected: Function *Caller; bool* Changed; +#if LDC_LLVM_VER >= 302 + const DataLayout *TD; +#else const TargetData *TD; +#endif AliasAnalysis *AA; LLVMContext *Context; @@ -74,8 +82,13 @@ namespace { /// delete CI. virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B)=0; +#if LDC_LLVM_VER >= 302 + Value *OptimizeCall(CallInst *CI, bool& Changed, const DataLayout &TD, + AliasAnalysis& AA, IRBuilder<> &B) { +#else Value *OptimizeCall(CallInst *CI, bool& Changed, const TargetData &TD, AliasAnalysis& AA, IRBuilder<> &B) { +#endif Caller = CI->getParent()->getParent(); this->Changed = &Changed; this->TD = &TD; @@ -101,7 +114,7 @@ Value *LibCallOptimization::EmitMemCpy(Value *Dst, Value *Src, Value *Len, Type *VoidPtrTy = PointerType::getUnqual(B.getInt8Ty()); Type *Tys[3] ={VoidPtrTy, VoidPtrTy, intTy}; Value *MemCpy = Intrinsic::getDeclaration(M, Intrinsic::memcpy, llvm::makeArrayRef(Tys, 3)); - + return B.CreateCall5(MemCpy, CastToCStr(Dst, B), CastToCStr(Src, B), Len, ConstantInt::get(B.getInt32Ty(), Align), B.getFalse()); } @@ -296,10 +309,18 @@ namespace { void InitOptimizations(); bool runOnFunction(Function &F); +#if LDC_LLVM_VER >= 302 + bool runOnce(Function &F, const DataLayout& DL, AliasAnalysis& AA); +#else bool runOnce(Function &F, const TargetData& TD, AliasAnalysis& AA); +#endif virtual void getAnalysisUsage(AnalysisUsage &AU) const { +#if LDC_LLVM_VER >= 302 + AU.addRequired(); +#else AU.addRequired(); +#endif AU.addRequired(); } }; @@ -349,7 +370,11 @@ bool SimplifyDRuntimeCalls::runOnFunction(Function &F) { if (Optimizations.empty()) InitOptimizations(); +#if LDC_LLVM_VER >= 302 + const DataLayout &TD = getAnalysis(); +#else const TargetData &TD = getAnalysis(); +#endif AliasAnalysis &AA = getAnalysis(); // Iterate to catch opportunities opened up by other optimizations, @@ -367,7 +392,11 @@ bool SimplifyDRuntimeCalls::runOnFunction(Function &F) { return EverChanged; } +#if LDC_LLVM_VER >= 302 +bool SimplifyDRuntimeCalls::runOnce(Function &F, const DataLayout& TD, AliasAnalysis& AA) { +#else bool SimplifyDRuntimeCalls::runOnce(Function &F, const TargetData& TD, AliasAnalysis& AA) { +#endif IRBuilder<> Builder(F.getContext()); bool Changed = false; diff --git a/gen/runtime.cpp b/gen/runtime.cpp index 5763cf1e..589603c4 100644 --- a/gen/runtime.cpp +++ b/gen/runtime.cpp @@ -19,7 +19,9 @@ #include "gen/irstate.h" #include "ir/irtype.h" +#if LDC_LLVM_VER < 302 using namespace llvm::Attribute; +#endif ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -217,6 +219,40 @@ static void LLVM_D_BuildRuntimeModule() ///////////////////////////////////////////////////////////////////////////////////// // Construct some attribute lists used below (possibly multiple times) +#if LDC_LLVM_VER >= 302 + llvm::AttrListPtr + NoAttrs, + Attr_NoAlias + = NoAttrs.addAttr(0, llvm::Attributes::get(llvm::Attributes::Builder().addAttribute(llvm::Attributes::NoAlias))), + Attr_NoUnwind + = NoAttrs.addAttr(~0U, llvm::Attributes::get(llvm::Attributes::Builder().addAttribute(llvm::Attributes::NoUnwind))), + Attr_ReadOnly + = NoAttrs.addAttr(~0U, llvm::Attributes::get(llvm::Attributes::Builder().addAttribute(llvm::Attributes::ReadOnly))), + Attr_ReadOnly_NoUnwind + = Attr_ReadOnly.addAttr(~0U, llvm::Attributes::get(llvm::Attributes::Builder().addAttribute(llvm::Attributes::NoUnwind))), + Attr_ReadOnly_1_NoCapture + = Attr_ReadOnly.addAttr(1, llvm::Attributes::get(llvm::Attributes::Builder().addAttribute(llvm::Attributes::NoCapture))), + Attr_ReadOnly_1_3_NoCapture + = Attr_ReadOnly_1_NoCapture.addAttr(3, llvm::Attributes::get(llvm::Attributes::Builder().addAttribute(llvm::Attributes::NoCapture))), + Attr_ReadOnly_1_4_NoCapture + = Attr_ReadOnly_1_NoCapture.addAttr(4, llvm::Attributes::get(llvm::Attributes::Builder().addAttribute(llvm::Attributes::NoCapture))), + Attr_ReadOnly_NoUnwind_1_NoCapture + = Attr_ReadOnly_1_NoCapture.addAttr(~0U, llvm::Attributes::get(llvm::Attributes::Builder().addAttribute(llvm::Attributes::NoUnwind))), + Attr_ReadNone + = NoAttrs.addAttr(~0U, llvm::Attributes::get(llvm::Attributes::Builder().addAttribute(llvm::Attributes::ReadNone))), + Attr_1_NoCapture + = NoAttrs.addAttr(1, llvm::Attributes::get(llvm::Attributes::Builder().addAttribute(llvm::Attributes::NoCapture))), + Attr_NoAlias_1_NoCapture + = Attr_1_NoCapture.addAttr(0, llvm::Attributes::get(llvm::Attributes::Builder().addAttribute(llvm::Attributes::NoAlias))), + Attr_NoAlias_3_NoCapture + = Attr_NoAlias.addAttr(3, llvm::Attributes::get(llvm::Attributes::Builder().addAttribute(llvm::Attributes::NoCapture))), + Attr_1_2_NoCapture + = Attr_1_NoCapture.addAttr(2, llvm::Attributes::get(llvm::Attributes::Builder().addAttribute(llvm::Attributes::NoCapture))), + Attr_1_3_NoCapture + = Attr_1_NoCapture.addAttr(3, llvm::Attributes::get(llvm::Attributes::Builder().addAttribute(llvm::Attributes::NoCapture))), + Attr_1_4_NoCapture + = Attr_1_NoCapture.addAttr(4, llvm::Attributes::get(llvm::Attributes::Builder().addAttribute(llvm::Attributes::NoCapture))); +#else llvm::AttrListPtr NoAttrs, Attr_NoAlias @@ -249,6 +285,7 @@ static void LLVM_D_BuildRuntimeModule() = Attr_1_NoCapture.addAttr(3, NoCapture), Attr_1_4_NoCapture = Attr_1_NoCapture.addAttr(4, NoCapture); +#endif ///////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////// diff --git a/gen/structs.cpp b/gen/structs.cpp index 93e9f103..96380838 100644 --- a/gen/structs.cpp +++ b/gen/structs.cpp @@ -275,7 +275,7 @@ std::vector DtoStructLiteralValues(const StructDeclaration* sd, // sometimes size of the initializer is less than size of the variable, // so make sure that lastsize is correct if (inits[i]->getType()->isSized()) - lastsize = ceil(gTargetData->getTypeSizeInBits(inits[i]->getType()) / 8.0); + lastsize = ceil(gDataLayout->getTypeSizeInBits(inits[i]->getType()) / 8.0); else #endif lastsize = sz; diff --git a/gen/tocall.cpp b/gen/tocall.cpp index 6d6ff765..23cd54d7 100644 --- a/gen/tocall.cpp +++ b/gen/tocall.cpp @@ -397,8 +397,13 @@ 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 + assert((Attr.Attrs.hasAttribute(llvm::Attributes::StructRet) || Attr.Attrs.hasAttribute(llvm::Attributes::InReg)) + && "Sret arg not sret or inreg?"); +#else assert((Attr.Attrs & (llvm::Attribute::StructRet | llvm::Attribute::InReg)) && "Sret arg not sret or inreg?"); +#endif attrs.push_back(Attr); } @@ -510,7 +515,11 @@ DValue* DtoCallFunction(Loc& loc, Type* resulttype, DValue* fnval, Expressions* } size_t n = Parameter::dim(tf->parameters); +#if LDC_LLVM_VER >= 302 + LLSmallVector attrptr(n, llvm::Attributes()); +#else LLSmallVector attrptr(n, llvm::Attribute::None); +#endif std::vector argvals; if (dfnval && dfnval->func->isArrayOp) { // slightly different approach for array operators diff --git a/gen/todebug.h b/gen/todebug.h index 77b9071e..ec69bc2f 100644 --- a/gen/todebug.h +++ b/gen/todebug.h @@ -60,7 +60,7 @@ void dwarfOpOffset(T &addr, LLStructType *type, int index) if (!global.params.symdebug) return; - uint64_t offset = gTargetData->getStructLayout(type)->getElementOffset(index); + uint64_t offset = gDataLayout->getStructLayout(type)->getElementOffset(index); LLType *int64Ty = LLType::getInt64Ty(gIR->context()); addr.push_back(LLConstantInt::get(int64Ty, llvm::DIBuilder::OpPlus)); addr.push_back(LLConstantInt::get(int64Ty, offset)); diff --git a/gen/tollvm.cpp b/gen/tollvm.cpp index 01342cec..b26dd5a9 100644 --- a/gen/tollvm.cpp +++ b/gen/tollvm.cpp @@ -43,14 +43,26 @@ llvm::Attributes DtoShouldExtend(Type* type) { case Tint8: case Tint16: +#if LDC_LLVM_VER >= 302 + return llvm::Attributes::get(llvm::Attributes::Builder().addAttribute(llvm::Attributes::SExt)); +#else return llvm::Attribute::SExt; +#endif case Tuns8: case Tuns16: +#if LDC_LLVM_VER >= 302 + return llvm::Attributes::get(llvm::Attributes::Builder().addAttribute(llvm::Attributes::ZExt)); +#else return llvm::Attribute::ZExt; +#endif } } +#if LDC_LLVM_VER >= 302 + return llvm::Attributes(); +#else return llvm::Attribute::None; +#endif } LLType* DtoType(Type* t) @@ -864,34 +876,34 @@ LLConstant* getNullValue(LLType* t) size_t getTypeBitSize(LLType* t) { - return gTargetData->getTypeSizeInBits(t); + return gDataLayout->getTypeSizeInBits(t); } size_t getTypeStoreSize(LLType* t) { - return gTargetData->getTypeStoreSize(t); + return gDataLayout->getTypeStoreSize(t); } size_t getTypePaddedSize(LLType* t) { - size_t sz = gTargetData->getTypeAllocSize(t); + size_t sz = gDataLayout->getTypeAllocSize(t); //Logger::cout() << "abi type size of: " << *t << " == " << sz << '\n'; return sz; } size_t getTypeAllocSize(LLType* t) { - return gTargetData->getTypeAllocSize(t); + return gDataLayout->getTypeAllocSize(t); } unsigned char getABITypeAlign(LLType* t) { - return gTargetData->getABITypeAlignment(t); + return gDataLayout->getABITypeAlignment(t); } unsigned char getPrefTypeAlign(LLType* t) { - return gTargetData->getPrefTypeAlignment(t); + return gDataLayout->getPrefTypeAlignment(t); } LLType* getBiggestType(LLType** begin, size_t n) diff --git a/ir/ir.cpp b/ir/ir.cpp index 16589223..7c4d3f90 100644 --- a/ir/ir.cpp +++ b/ir/ir.cpp @@ -1,4 +1,8 @@ +#if LDC_LLVM_VER >= 302 +#include "llvm/DataLayout.h" +#else #include "llvm/Target/TargetData.h" +#endif #include "gen/irstate.h" #include "gen/tollvm.h" @@ -10,22 +14,22 @@ unsigned GetTypeAlignment(Ir* ir, Type* t) { - return gTargetData->getABITypeAlignment(DtoType(t)); + return gDataLayout->getABITypeAlignment(DtoType(t)); } unsigned GetPointerSize(Ir* ir) { - return gTargetData->getPointerSize(); + return gDataLayout->getPointerSize(); } unsigned GetTypeStoreSize(Ir* ir, Type* t) { - return gTargetData->getTypeStoreSize(DtoType(t)); + return gDataLayout->getTypeStoreSize(DtoType(t)); } unsigned GetTypeAllocSize(Ir* ir, Type* t) { - return gTargetData->getTypeAllocSize(DtoType(t)); + return gDataLayout->getTypeAllocSize(DtoType(t)); } Ir::Ir() diff --git a/ir/irforw.h b/ir/irforw.h index 747714a1..720d2790 100644 --- a/ir/irforw.h +++ b/ir/irforw.h @@ -33,7 +33,11 @@ namespace llvm class Constant; class ConstantStruct; class ConstantArray; +#if LDC_LLVM_VER >= 302 + class DataLayout; +#else class TargetData; +#endif class Type; class StructType; class ArrayType; diff --git a/ir/irfunction.cpp b/ir/irfunction.cpp index 6b56c86b..99a59f69 100644 --- a/ir/irfunction.cpp +++ b/ir/irfunction.cpp @@ -21,9 +21,15 @@ IrFuncTyArg::IrFuncTyArg(Type* t, bool bref, llvm::Attributes a) : type(t) rewrite = NULL; } +#if 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); } +#else bool IrFuncTyArg::isInReg() const { return (attrs & llvm::Attribute::InReg) != 0; } bool IrFuncTyArg::isSRet() const { return (attrs & llvm::Attribute::StructRet) != 0; } bool IrFuncTyArg::isByVal() const { return (attrs & llvm::Attribute::ByVal) != 0; } +#endif ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// @@ -152,19 +158,21 @@ IrFunction::IrFunction(FuncDeclaration* fd) void IrFunction::setNeverInline() { #if LDC_LLVM_VER >= 302 - assert(!func->getFnAttributes().hasAlwaysInlineAttr() && "function can't be never- and always-inline at the same time"); + 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 assert(!func->hasFnAttr(llvm::Attribute::AlwaysInline) && "function can't be never- and always-inline at the same time"); -#endif func->addFnAttr(llvm::Attribute::NoInline); +#endif } void IrFunction::setAlwaysInline() { #if LDC_LLVM_VER >= 302 - assert(!func->getFnAttributes().hasNoInlineAttr() && "function can't be never- and always-inline at the same time"); + 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 assert(!func->hasFnAttr(llvm::Attribute::NoInline) && "function can't be never- and always-inline at the same time"); -#endif func->addFnAttr(llvm::Attribute::AlwaysInline); +#endif } diff --git a/ir/irfuncty.h b/ir/irfuncty.h index 10fb1eec..22fbdf2e 100644 --- a/ir/irfuncty.h +++ b/ir/irfuncty.h @@ -51,7 +51,11 @@ 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 + IrFuncTyArg(Type* t, bool byref, llvm::Attributes a = llvm::Attributes()); +#else IrFuncTyArg(Type* t, bool byref, llvm::Attributes a = llvm::Attribute::None); +#endif }; // represents a function type