From 48728606e201f9b8650c863a2982961d0c6211c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Cumplido?= Date: Tue, 2 Sep 2025 12:09:52 +0200 Subject: [PATCH 1/2] GH-47469: [C++][Gandiva] Add support for LLVM 21.1.0 --- cpp/CMakeLists.txt | 1 + cpp/src/gandiva/engine.cc | 6 ++++++ cpp/src/gandiva/llvm_types.h | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 18841ac874bd..5d3d58cb12cb 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -177,6 +177,7 @@ set(ARROW_DOC_DIR "share/doc/${PROJECT_NAME}") set(BUILD_SUPPORT_DIR "${CMAKE_SOURCE_DIR}/build-support") set(ARROW_LLVM_VERSIONS + "21.1" "20.1" "19.1" "18.1" diff --git a/cpp/src/gandiva/engine.cc b/cpp/src/gandiva/engine.cc index 6148cfab7480..8457e5c42501 100644 --- a/cpp/src/gandiva/engine.cc +++ b/cpp/src/gandiva/engine.cc @@ -202,10 +202,16 @@ Status UseJITLinkIfEnabled(llvm::orc::LLJITBuilder& jit_builder) { static auto maybe_use_jit_link = ::arrow::internal::GetEnvVar("GANDIVA_USE_JIT_LINK"); if (maybe_use_jit_link.ok()) { ARROW_ASSIGN_OR_RAISE(static auto memory_manager, CreateMemmoryManager()); +# if LLVM_VERSION_MAJOR >= 21 + jit_builder.setObjectLinkingLayerCreator([&](llvm::orc::ExecutionSession& ES) { + return std::make_unique(ES, *memory_manager); + }); +# else jit_builder.setObjectLinkingLayerCreator( [&](llvm::orc::ExecutionSession& ES, const llvm::Triple& TT) { return std::make_unique(ES, *memory_manager); }); +# endif } return Status::OK(); } diff --git a/cpp/src/gandiva/llvm_types.h b/cpp/src/gandiva/llvm_types.h index 3541e5e40402..b8f9bec3ff9c 100644 --- a/cpp/src/gandiva/llvm_types.h +++ b/cpp/src/gandiva/llvm_types.h @@ -56,7 +56,7 @@ class GANDIVA_EXPORT LLVMTypes { llvm::Type* double_type() { return llvm::Type::getDoubleTy(context_); } llvm::PointerType* ptr_type(llvm::Type* type) { - return llvm::PointerType::get(type, 0); + return llvm::PointerType::get(context_, 0); } llvm::PointerType* i8_ptr_type() { return ptr_type(i8_type()); } From c0e329e731a45c6ff68671be6144be8c1e1ae054 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Cumplido?= Date: Tue, 2 Sep 2025 13:08:14 +0200 Subject: [PATCH 2/2] Use old API for old LLVM versions --- cpp/src/gandiva/llvm_types.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cpp/src/gandiva/llvm_types.h b/cpp/src/gandiva/llvm_types.h index b8f9bec3ff9c..04715391ff14 100644 --- a/cpp/src/gandiva/llvm_types.h +++ b/cpp/src/gandiva/llvm_types.h @@ -56,7 +56,11 @@ class GANDIVA_EXPORT LLVMTypes { llvm::Type* double_type() { return llvm::Type::getDoubleTy(context_); } llvm::PointerType* ptr_type(llvm::Type* type) { +#if LLVM_VERSION_MAJOR >= 21 return llvm::PointerType::get(context_, 0); +#else + return llvm::PointerType::get(type, 0); +#endif } llvm::PointerType* i8_ptr_type() { return ptr_type(i8_type()); }