diff --git a/src/CodeGen_Hexagon.cpp b/src/CodeGen_Hexagon.cpp index 84e5934f579e..74ff095b2ff5 100644 --- a/src/CodeGen_Hexagon.cpp +++ b/src/CodeGen_Hexagon.cpp @@ -867,7 +867,11 @@ void CodeGen_Hexagon::init_module() { llvm::Intrinsic::ID id = i.id; internal_assert(id != llvm::Intrinsic::not_intrinsic); // Get the real intrinsic. +#if LLVM_VERSION >= 200 + llvm::Function *intrin = llvm::Intrinsic::getOrInsertDeclaration(module.get(), id); +#else llvm::Function *intrin = llvm::Intrinsic::getDeclaration(module.get(), id); +#endif halide_type_t ret_type = fix_lanes(i.ret_type); arg_types.clear(); for (const auto &a : i.arg_types) { @@ -1015,8 +1019,11 @@ Value *CodeGen_Hexagon::call_intrin_cast(llvm::Type *ret_ty, llvm::Function *F, Value *CodeGen_Hexagon::call_intrin_cast(llvm::Type *ret_ty, int id, vector Ops) { - llvm::Function *intrin = - llvm::Intrinsic::getDeclaration(module.get(), (llvm::Intrinsic::ID)id); +#if LLVM_VERSION >= 200 + llvm::Function *intrin = llvm::Intrinsic::getOrInsertDeclaration(module.get(), (llvm::Intrinsic::ID)id); +#else + llvm::Function *intrin = llvm::Intrinsic::getDeclaration(module.get(), (llvm::Intrinsic::ID)id); +#endif return call_intrin_cast(ret_ty, intrin, std::move(Ops)); } @@ -1182,9 +1189,11 @@ Value *CodeGen_Hexagon::shuffle_vectors(Value *a, Value *b, if (max < a_elements) { BitCastInst *a_cast = dyn_cast(a); CallInst *a_call = dyn_cast(a_cast ? a_cast->getOperand(0) : a); - llvm::Function *vcombine = llvm::Intrinsic::getDeclaration( - module.get(), - INTRINSIC_128B(vcombine)); +#if LLVM_VERSION >= 200 + llvm::Function *vcombine = llvm::Intrinsic::getOrInsertDeclaration(module.get(), INTRINSIC_128B(vcombine)); +#else + llvm::Function *vcombine = llvm::Intrinsic::getDeclaration(module.get(), INTRINSIC_128B(vcombine)); +#endif if (a_call && a_call->getCalledFunction() == vcombine) { // Rewrite shuffle(vcombine(a, b), x) to shuffle(a, b) return shuffle_vectors( diff --git a/src/CodeGen_LLVM.cpp b/src/CodeGen_LLVM.cpp index 11142daeb2c7..4178f4bcfe1e 100644 --- a/src/CodeGen_LLVM.cpp +++ b/src/CodeGen_LLVM.cpp @@ -2778,7 +2778,11 @@ void CodeGen_LLVM::visit(const Call *op) { internal_assert(op->args.size() == 1); std::vector arg_type(1); arg_type[0] = llvm_type_of(op->args[0].type()); +#if LLVM_VERSION >= 200 + llvm::Function *fn = llvm::Intrinsic::getOrInsertDeclaration(module.get(), llvm::Intrinsic::ctpop, arg_type); +#else llvm::Function *fn = llvm::Intrinsic::getDeclaration(module.get(), llvm::Intrinsic::ctpop, arg_type); +#endif Value *a = codegen(op->args[0]); CallInst *call = builder->CreateCall(fn, a); value = call; @@ -2787,9 +2791,15 @@ void CodeGen_LLVM::visit(const Call *op) { internal_assert(op->args.size() == 1); std::vector arg_type(1); arg_type[0] = llvm_type_of(op->args[0].type()); +#if LLVM_VERSION >= 200 + llvm::Function *fn = llvm::Intrinsic::getOrInsertDeclaration(module.get(), + (op->is_intrinsic(Call::count_leading_zeros)) ? llvm::Intrinsic::ctlz : llvm::Intrinsic::cttz, + arg_type); +#else llvm::Function *fn = llvm::Intrinsic::getDeclaration(module.get(), (op->is_intrinsic(Call::count_leading_zeros)) ? llvm::Intrinsic::ctlz : llvm::Intrinsic::cttz, arg_type); +#endif llvm::Value *is_const_zero_poison = llvm::ConstantInt::getFalse(*context); llvm::Value *args[2] = {codegen(op->args[0]), is_const_zero_poison}; CallInst *call = builder->CreateCall(fn, args); diff --git a/src/LLVM_Runtime_Linker.cpp b/src/LLVM_Runtime_Linker.cpp index eda1a3b170c5..a5db7b2c5ed5 100644 --- a/src/LLVM_Runtime_Linker.cpp +++ b/src/LLVM_Runtime_Linker.cpp @@ -394,7 +394,11 @@ llvm::DataLayout get_data_layout_for_target(Target target) { } else if (target.os == Target::Windows) { return llvm::DataLayout("e-m:w-p:64:64-i32:32-i64:64-i128:128-n32:64-S128-Fn32"); } else { +#if LLVM_VERSION >= 200 + return llvm::DataLayout("e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32"); +#else return llvm::DataLayout("e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32"); +#endif } #else if (target.os == Target::IOS) {