From 5248c141a151760a162f2afbba1b18993d530bbf Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Thu, 2 Jul 2020 19:04:22 -0500 Subject: [PATCH] [LLVM] VectorType::get with two parameters is deprecated in LLVM 11+ (#5984) In LLVM 11+ the distinction between fixed and scalable vector types has become more explicit. Before the introduction of scalable vector types VectorType::get(e,n) created what is now a fixed vector type. With the addition of scalable types, it is recommended to use FixedVectorType and ScalableVectorType classes directly. Alternatively, there is a VectorType::get that accepts a 3rd parameter indicating whether the type should be fixed or scalable. Using the older VectorType::get that implicitly assumes the fixed type is deprecated and LLVM now generates a warning. Change calls to VectorType::get to FixedVectorType::get to avoid compilation warnings. --- src/target/llvm/codegen_llvm.cc | 11 ++++++++++- src/target/llvm/codegen_x86_64.cc | 10 ++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/target/llvm/codegen_llvm.cc b/src/target/llvm/codegen_llvm.cc index 41437f86362f..289ac1c6767d 100644 --- a/src/target/llvm/codegen_llvm.cc +++ b/src/target/llvm/codegen_llvm.cc @@ -326,7 +326,11 @@ llvm::Type* CodeGenLLVM::DTypeToLLVMType(const DataType& dtype) const { } } if (dtype.lanes() != 1) { +#if TVM_LLVM_VERSION >= 110 + return llvm::FixedVectorType::get(etype, dtype.lanes()); +#else return llvm::VectorType::get(etype, dtype.lanes()); +#endif } else { return etype; } @@ -453,7 +457,12 @@ std::unique_ptr CodeGenLLVM::CreateDebugInfo(llvm::Modul } llvm::Value* CodeGenLLVM::CreateBroadcast(llvm::Value* value, int lanes) { - llvm::Constant* undef = llvm::UndefValue::get(llvm::VectorType::get(value->getType(), lanes)); +#if TVM_LLVM_VERSION >= 110 + llvm::Type* type = llvm::FixedVectorType::get(value->getType(), lanes); +#else + llvm::Type* type = llvm::VectorType::get(value->getType(), lanes); +#endif + llvm::Constant* undef = llvm::UndefValue::get(type); llvm::Constant* zero = ConstInt32(0); value = builder_->CreateInsertElement(undef, value, zero); #if TVM_LLVM_VERSION >= 110 diff --git a/src/target/llvm/codegen_x86_64.cc b/src/target/llvm/codegen_x86_64.cc index 6f3d4f7cb25e..f3362fb0f1eb 100644 --- a/src/target/llvm/codegen_x86_64.cc +++ b/src/target/llvm/codegen_x86_64.cc @@ -115,7 +115,6 @@ llvm::Value* CodeGenX86_64::VisitExpr_(const CastNode* op) { llvm::Value* CodeGenX86_64::CallVectorIntrin(llvm::Intrinsic::ID id, size_t intrin_lanes, llvm::Type* result_ty, - const std::vector& args) { llvm::Function* f = llvm::Intrinsic::getDeclaration(module_.get(), id, {}); size_t num_elems = llvm::cast(result_ty)->getNumElements(); @@ -137,9 +136,12 @@ llvm::Value* CodeGenX86_64::CallVectorIntrin(llvm::Intrinsic::ID id, size_t intr split_args.push_back(v); } } - split_results.push_back(CallVectorIntrin( - id, intrin_lanes, llvm::VectorType::get(result_ty->getScalarType(), intrin_lanes), - split_args)); +#if TVM_LLVM_VERSION >= 110 + llvm::Type* type = llvm::FixedVectorType::get(result_ty->getScalarType(), intrin_lanes); +#else + llvm::Type* type = llvm::VectorType::get(result_ty->getScalarType(), intrin_lanes); +#endif + split_results.push_back(CallVectorIntrin(id, intrin_lanes, type, split_args)); } return CreateVecSlice(CreateVecConcat(split_results), 0, num_elems); }