From ef49a0ae57ce16c71172390dc123485da0f1a4fd Mon Sep 17 00:00:00 2001 From: Dmitry Babokin Date: Tue, 5 Jun 2018 15:27:00 -0700 Subject: [PATCH 1/2] Compile time fixes --- cbackend.cpp | 8 ++++++-- module.cpp | 9 +++++++++ opt.cpp | 1 + 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/cbackend.cpp b/cbackend.cpp index 2da435f9ed..8b548dfae5 100644 --- a/cbackend.cpp +++ b/cbackend.cpp @@ -4190,8 +4190,10 @@ void CWriter::lowerIntrinsics(llvm::Function &F) { #define Intrinsic llvm::Intrinsic #if ISPC_LLVM_VERSION == ISPC_LLVM_3_2 #include "llvm/Intrinsics.gen" -#else /* LLVM 3.3+ */ +#elif ISPC_LLVM_VERSION <= ISPC_LLVM_6_0 /* LLVM 3.3-6.0 */ #include "llvm/IR/Intrinsics.gen" +#else /* LLVM 7.0+ */ + #include "llvm/IR/Intrinsics.inc" #endif #undef Intrinsic #undef GET_GCC_BUILTIN_NAME @@ -4422,8 +4424,10 @@ bool CWriter::visitBuiltinCall(llvm::CallInst &I, llvm::Intrinsic::ID ID, #define Intrinsic llvm::Intrinsic #if ISPC_LLVM_VERSION == ISPC_LLVM_3_2 #include "llvm/Intrinsics.gen" -#else /* LLVM 3.3+ */ +#elif ISPC_LLVM_VERSION <= ISPC_LLVM_6_0 /* LLVM 3.3-6.0 */ #include "llvm/IR/Intrinsics.gen" +#else /* LLVM 7.0+ */ + #include "llvm/IR/Intrinsics.inc" #endif #undef Intrinsic #undef GET_GCC_BUILTIN_NAME diff --git a/module.cpp b/module.cpp index 4aa459df84..71bdf66335 100644 --- a/module.cpp +++ b/module.cpp @@ -1573,10 +1573,19 @@ Module::writeObjectFileOrAssembly(llvm::TargetMachine *targetMachine, #else // LLVM 3.7+ llvm::raw_fd_ostream &fos(of->os()); #endif +#if ISPC_LLVM_VERSION <= ISPC_LLVM_6_0 if (targetMachine->addPassesToEmitFile(pm, fos, fileType)) { fprintf(stderr, "Fatal error adding passes to emit object file!"); exit(1); } +#else // LLVM 7.0+ + // Third parameter is for generation of .dwo file, which is separate DWARF + // file for ELF targets. We don't support it currently. + if (targetMachine->addPassesToEmitFile(pm, fos, nullptr, fileType)) { + fprintf(stderr, "Fatal error adding passes to emit object file!"); + exit(1); + } +#endif // Finally, run the passes to emit the object file/assembly pm.run(*module); diff --git a/opt.cpp b/opt.cpp index 1edbe33bab..e26eccfd8f 100644 --- a/opt.cpp +++ b/opt.cpp @@ -101,6 +101,7 @@ #include #if ISPC_LLVM_VERSION >= ISPC_LLVM_7_0 #include "llvm/Transforms/Utils.h" + #include "llvm/Transforms/InstCombine/InstCombine.h" #endif #include #include From 1434904ebf11b854e108c0d1d0abc651859ad05c Mon Sep 17 00:00:00 2001 From: Dmitry Babokin Date: Wed, 6 Jun 2018 15:05:49 -0700 Subject: [PATCH 2/2] Fix ispc compile time assert caused by changed signature of memcpy intrinsic. --- ctx.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ctx.cpp b/ctx.cpp index 44feeef00c..403b841e6b 100644 --- a/ctx.cpp +++ b/ctx.cpp @@ -3461,11 +3461,18 @@ FunctionEmitContext::MemcpyInst(llvm::Value *dest, llvm::Value *src, LLVMTypes::VoidType, LLVMTypes::VoidPointerType, LLVMTypes::VoidPointerType, LLVMTypes::Int64Type, LLVMTypes::Int32Type, LLVMTypes::BoolType, NULL); -#else // LLVM 5.0+ +#elif ISPC_LLVM_VERSION <= ISPC_LLVM_6_0 // LLVM 5.0-6.0 m->module->getOrInsertFunction("llvm.memcpy.p0i8.p0i8.i64", LLVMTypes::VoidType, LLVMTypes::VoidPointerType, LLVMTypes::VoidPointerType, LLVMTypes::Int64Type, LLVMTypes::Int32Type, LLVMTypes::BoolType); +#else // LLVM 7.0+ + // Now alignment goes as an attribute, not as a parameter. + // See LLVM r322965/r323597 for more details. + m->module->getOrInsertFunction("llvm.memcpy.p0i8.p0i8.i64", + LLVMTypes::VoidType, LLVMTypes::VoidPointerType, + LLVMTypes::VoidPointerType, LLVMTypes::Int64Type, + LLVMTypes::BoolType); #endif AssertPos(currentPos, mcFunc != NULL); @@ -3475,7 +3482,10 @@ FunctionEmitContext::MemcpyInst(llvm::Value *dest, llvm::Value *src, args.push_back(dest); args.push_back(src); args.push_back(count); +#if ISPC_LLVM_VERSION < ISPC_LLVM_7_0 + // Don't bother about setting alignment for 7.0+, as this parameter is never really used by ISPC. args.push_back(align); +#endif args.push_back(LLVMFalse); /* not volatile */ CallInst(mcFunc, NULL, args, ""); }