diff --git a/ci/scripts/msys2_setup.sh b/ci/scripts/msys2_setup.sh index 3addee814c5..6f6012c879a 100755 --- a/ci/scripts/msys2_setup.sh +++ b/ci/scripts/msys2_setup.sh @@ -39,6 +39,7 @@ case "${target}" in packages+=(${MINGW_PACKAGE_PREFIX}-llvm) packages+=(${MINGW_PACKAGE_PREFIX}-lz4) packages+=(${MINGW_PACKAGE_PREFIX}-make) + packages+=(${MINGW_PACKAGE_PREFIX}-mlir) packages+=(${MINGW_PACKAGE_PREFIX}-ninja) packages+=(${MINGW_PACKAGE_PREFIX}-polly) packages+=(${MINGW_PACKAGE_PREFIX}-protobuf) @@ -60,7 +61,7 @@ case "${target}" in ;; esac -case "${target}" in +case "${target}" in cgo) packages+=(${MINGW_PACKAGE_PREFIX}-arrow) packages+=(${MINGW_PACKAGE_PREFIX}-gcc) diff --git a/cpp/Brewfile b/cpp/Brewfile index a96f786fb2d..78ee5e64c8f 100644 --- a/cpp/Brewfile +++ b/cpp/Brewfile @@ -25,7 +25,7 @@ brew "flatbuffers" brew "git" brew "glog" brew "grpc" -brew "llvm@12" +brew "llvm" brew "llvm@8" brew "lz4" brew "minio" diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 45b27174052..b314dca8b94 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -111,6 +111,7 @@ set(ARROW_CMAKE_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") set(ARROW_DOC_DIR "share/doc/${PROJECT_NAME}") set(ARROW_LLVM_VERSIONS + "13.0" "12.0" "11.1" "11.0" diff --git a/cpp/src/gandiva/decimal_ir.cc b/cpp/src/gandiva/decimal_ir.cc index 8ccd00fc949..5d5d30b4a75 100644 --- a/cpp/src/gandiva/decimal_ir.cc +++ b/cpp/src/gandiva/decimal_ir.cc @@ -96,8 +96,8 @@ void DecimalIR::InitializeIntrinsics() { // CPP: return kScaleMultipliers[scale] llvm::Value* DecimalIR::GetScaleMultiplier(llvm::Value* scale) { auto const_array = module()->getGlobalVariable(kScaleMultipliersName); - auto ptr = ir_builder()->CreateGEP(const_array, {types()->i32_constant(0), scale}); - return ir_builder()->CreateLoad(ptr); + auto ptr = CreateGEP(ir_builder(), const_array, {types()->i32_constant(0), scale}); + return CreateLoad(ir_builder(), ptr); } // CPP: x <= y ? y : x @@ -248,8 +248,8 @@ llvm::Value* DecimalIR::AddLarge(const ValueFull& x, const ValueFull& y, ir_builder()->CreateCall(module()->getFunction("add_large_decimal128_decimal128"), args); - auto out_high = ir_builder()->CreateLoad(out_high_ptr); - auto out_low = ir_builder()->CreateLoad(out_low_ptr); + auto out_high = CreateLoad(ir_builder(), out_high_ptr); + auto out_low = CreateLoad(ir_builder(), out_low_ptr); auto sum = ValueSplit(out_high, out_low).AsInt128(this); ADD_TRACE_128("AddLarge : sum", sum); return sum; @@ -445,8 +445,8 @@ llvm::Value* DecimalIR::CallDecimalFunction(const std::string& function_name, // Make call to pre-compiled IR function. ir_builder()->CreateCall(module()->getFunction(function_name), dis_assembled_args); - auto out_high = ir_builder()->CreateLoad(out_high_ptr); - auto out_low = ir_builder()->CreateLoad(out_low_ptr); + auto out_high = CreateLoad(ir_builder(), out_high_ptr); + auto out_low = CreateLoad(ir_builder(), out_low_ptr); result = ValueSplit(out_high, out_low).AsInt128(this); } else { DCHECK_NE(return_type, types()->void_type()); diff --git a/cpp/src/gandiva/engine_llvm_test.cc b/cpp/src/gandiva/engine_llvm_test.cc index d5a6c04b3bb..ef2275b3424 100644 --- a/cpp/src/gandiva/engine_llvm_test.cc +++ b/cpp/src/gandiva/engine_llvm_test.cc @@ -80,8 +80,8 @@ class TestEngine : public ::testing::Test { loop_var->addIncoming(loop_update, loop_body); // get the current value - llvm::Value* offset = builder->CreateGEP(arg_elements, loop_var, "offset"); - llvm::Value* current_value = builder->CreateLoad(offset, "value"); + llvm::Value* offset = CreateGEP(builder, arg_elements, loop_var, "offset"); + llvm::Value* current_value = CreateLoad(builder, offset, "value"); // setup sum PHI llvm::Value* sum_update = builder->CreateAdd(sum, current_value, "sum+ith"); diff --git a/cpp/src/gandiva/llvm_generator.cc b/cpp/src/gandiva/llvm_generator.cc index d84a0374e6b..0129e52784f 100644 --- a/cpp/src/gandiva/llvm_generator.cc +++ b/cpp/src/gandiva/llvm_generator.cc @@ -143,8 +143,8 @@ Status LLVMGenerator::Execute(const arrow::RecordBatch& record_batch, llvm::Value* LLVMGenerator::LoadVectorAtIndex(llvm::Value* arg_addrs, int idx, const std::string& name) { auto* idx_val = types()->i32_constant(idx); - auto* offset = ir_builder()->CreateGEP(arg_addrs, idx_val, name + "_mem_addr"); - return ir_builder()->CreateLoad(offset, name + "_mem"); + auto* offset = CreateGEP(ir_builder(), arg_addrs, idx_val, name + "_mem_addr"); + return CreateLoad(ir_builder(), offset, name + "_mem"); } /// Get reference to validity array at specified index in the args list. @@ -314,8 +314,8 @@ Status LLVMGenerator::CodeGenExprValue(DexPtr value_expr, int buffer_count, std::vector slice_offsets; for (int idx = 0; idx < buffer_count; idx++) { - auto offsetAddr = builder->CreateGEP(arg_addr_offsets, types()->i32_constant(idx)); - auto offset = builder->CreateLoad(offsetAddr); + auto offsetAddr = CreateGEP(builder, arg_addr_offsets, types()->i32_constant(idx)); + auto offset = CreateLoad(builder, offsetAddr); slice_offsets.push_back(offset); } @@ -328,8 +328,8 @@ Status LLVMGenerator::CodeGenExprValue(DexPtr value_expr, int buffer_count, llvm::Value* position_var = loop_var; if (selection_vector_mode != SelectionVector::MODE_NONE) { position_var = builder->CreateIntCast( - builder->CreateLoad(builder->CreateGEP(arg_selection_vector, loop_var), - "uncasted_position_var"), + CreateLoad(builder, CreateGEP(builder, arg_selection_vector, loop_var), + "uncasted_position_var"), types()->i64_type(), true, "position_var"); } @@ -354,7 +354,7 @@ Status LLVMGenerator::CodeGenExprValue(DexPtr value_expr, int buffer_count, SetPackedBitValue(output_ref, loop_var, output_value->data()); } else if (arrow::is_primitive(output_type_id) || output_type_id == arrow::Type::DECIMAL) { - llvm::Value* slot_offset = builder->CreateGEP(output_ref, loop_var); + llvm::Value* slot_offset = CreateGEP(builder, output_ref, loop_var); builder->CreateStore(output_value->data(), slot_offset); } else if (arrow::is_binary_like(output_type_id)) { // Var-len output. Make a function call to populate the data. @@ -550,15 +550,15 @@ void LLVMGenerator::Visitor::Visit(const VectorReadFixedLenValueDex& dex) { break; case arrow::Type::DECIMAL: { - auto slot_offset = builder->CreateGEP(slot_ref, slot_index); - slot_value = builder->CreateLoad(slot_offset, dex.FieldName()); + auto slot_offset = CreateGEP(builder, slot_ref, slot_index); + slot_value = CreateLoad(builder, slot_offset, dex.FieldName()); lvalue = generator_->BuildDecimalLValue(slot_value, dex.FieldType()); break; } default: { - auto slot_offset = builder->CreateGEP(slot_ref, slot_index); - slot_value = builder->CreateLoad(slot_offset, dex.FieldName()); + auto slot_offset = CreateGEP(builder, slot_ref, slot_index); + slot_value = CreateLoad(builder, slot_offset, dex.FieldName()); lvalue = std::make_shared(slot_value); break; } @@ -579,14 +579,14 @@ void LLVMGenerator::Visitor::Visit(const VectorReadVarLenValueDex& dex) { builder->CreateAdd(loop_var_, GetSliceOffset(dex.OffsetsIdx())); // => offset_start = offsets[loop_var] - slot = builder->CreateGEP(offsets_slot_ref, offsets_slot_index); - llvm::Value* offset_start = builder->CreateLoad(slot, "offset_start"); + slot = CreateGEP(builder, offsets_slot_ref, offsets_slot_index); + llvm::Value* offset_start = CreateLoad(builder, slot, "offset_start"); // => offset_end = offsets[loop_var + 1] llvm::Value* offsets_slot_index_next = builder->CreateAdd( offsets_slot_index, generator_->types()->i64_constant(1), "loop_var+1"); - slot = builder->CreateGEP(offsets_slot_ref, offsets_slot_index_next); - llvm::Value* offset_end = builder->CreateLoad(slot, "offset_end"); + slot = CreateGEP(builder, offsets_slot_ref, offsets_slot_index_next); + llvm::Value* offset_end = CreateLoad(builder, slot, "offset_end"); // => len_value = offset_end - offset_start llvm::Value* len_value = @@ -595,7 +595,7 @@ void LLVMGenerator::Visitor::Visit(const VectorReadVarLenValueDex& dex) { // get the data from the data array, at offset 'offset_start'. llvm::Value* data_slot_ref = GetBufferReference(dex.DataIdx(), kBufferTypeData, dex.Field()); - llvm::Value* data_value = builder->CreateGEP(data_slot_ref, offset_start); + llvm::Value* data_value = CreateGEP(builder, data_slot_ref, offset_start); ADD_VISITOR_TRACE("visit var-len data vector " + dex.FieldName() + " len %T", len_value); result_.reset(new LValue(data_value, len_value)); @@ -806,7 +806,7 @@ void LLVMGenerator::Visitor::Visit(const NullableInternalFuncDex& dex) { result_ = BuildFunctionCall(native_function, arrow_return_type, ¶ms); // load the result validity and truncate to i1. - llvm::Value* result_valid_i8 = builder->CreateLoad(result_valid_ptr); + llvm::Value* result_valid_i8 = CreateLoad(builder, result_valid_ptr); llvm::Value* result_valid = builder->CreateTrunc(result_valid_i8, types->i1_type()); // set validity bit in the local bitmap. @@ -1221,7 +1221,7 @@ LValuePtr LLVMGenerator::Visitor::BuildFunctionCall(const NativeFunction* func, ? decimalIR.CallDecimalFunction(func->pc_name(), llvm_return_type, *params) : generator_->AddFunctionCall(func->pc_name(), llvm_return_type, *params); auto value_len = - (result_len_ptr == nullptr) ? nullptr : builder->CreateLoad(result_len_ptr); + (result_len_ptr == nullptr) ? nullptr : CreateLoad(builder, result_len_ptr); return std::make_shared(value, value_len); } } diff --git a/cpp/src/gandiva/llvm_includes.h b/cpp/src/gandiva/llvm_includes.h index 3d455591895..37f915eb571 100644 --- a/cpp/src/gandiva/llvm_includes.h +++ b/cpp/src/gandiva/llvm_includes.h @@ -41,3 +41,16 @@ #if defined(_MSC_VER) #pragma warning(pop) #endif + +// Workaround for deprecated builder methods as of LLVM 13: ARROW-14363 +inline llvm::Value* CreateGEP(llvm::IRBuilder<>* builder, llvm::Value* Ptr, + llvm::ArrayRef IdxList, + const llvm::Twine& Name = "") { + return builder->CreateGEP(Ptr->getType()->getScalarType()->getPointerElementType(), Ptr, + IdxList, Name); +} + +inline llvm::LoadInst* CreateLoad(llvm::IRBuilder<>* builder, llvm::Value* Ptr, + const llvm::Twine& Name = "") { + return builder->CreateLoad(Ptr->getType()->getPointerElementType(), Ptr, Name); +}