kou commented on code in PR #38116:
URL: https://github.com/apache/arrow/pull/38116#discussion_r1351136942


##########
cpp/src/gandiva/cmake/GenerateBitcode.cmake:
##########


Review Comment:
   How about moving this to `cpp/cmake_modules/GandivaAddBitcode.cmake`, 
calling `provide_find_module(GandivaAddBitcode "Gandiva")` and including this 
from `cpp/src/gandiva/GandivaConfig.cmake.in`?
   
   ```diff
   diff --git a/cpp/cmake_modules/ThirdpartyToolchain.cmake 
b/cpp/cmake_modules/ThirdpartyToolchain.cmake
   index a6b5db382..fd0f6075a 100644
   --- a/cpp/cmake_modules/ThirdpartyToolchain.cmake
   +++ b/cpp/cmake_modules/ThirdpartyToolchain.cmake
   @@ -222,12 +222,10 @@ macro(build_dependency DEPENDENCY_NAME)
      endif()
    endmacro()
    
   -# Find modules are needed by the consumer in case of a static build, or if 
the
   -# linkage is PUBLIC or INTERFACE.
   -macro(provide_find_module PACKAGE_NAME ARROW_CMAKE_PACKAGE_NAME)
   -  set(module_ "${CMAKE_SOURCE_DIR}/cmake_modules/Find${PACKAGE_NAME}.cmake")
   +macro(provide_cmake_module MODULE_NAME ARROW_CMAKE_PACKAGE_NAME)
   +  set(module_ "${CMAKE_SOURCE_DIR}/cmake_modules/{MODULE_NAME}.cmake")
      if(EXISTS "${module_}")
   -    message(STATUS "Providing CMake module for ${PACKAGE_NAME} as part of 
${ARROW_CMAKE_PACKAGE_NAME} CMake package"
   +    message(STATUS "Providing CMake module for ${MODULE_NAME} as part of 
${ARROW_CMAKE_PACKAGE_NAME} CMake package"
        )
        install(FILES "${module_}"
                DESTINATION "${ARROW_CMAKE_DIR}/${ARROW_CMAKE_PACKAGE_NAME}")
   @@ -235,6 +233,12 @@ macro(provide_find_module PACKAGE_NAME 
ARROW_CMAKE_PACKAGE_NAME)
      unset(module_)
    endmacro()
    
   +# Find modules are needed by the consumer in case of a static build, or if 
the
   +# linkage is PUBLIC or INTERFACE.
   +macro(provide_find_module PACKAGE_NAME ARROW_CMAKE_PACKAGE_NAME)
   +  provide_cmake_module("Find${PACKAGE_NAME}.cmake" 
${ARROW_CMAKE_PACKAGE_NAME})
   +endmacro()
   +
    macro(resolve_dependency DEPENDENCY_NAME)
      set(options)
      set(one_value_args
   diff --git a/cpp/src/gandiva/CMakeLists.txt b/cpp/src/gandiva/CMakeLists.txt
   index d2810c39f..a9d392ddd 100644
   --- a/cpp/src/gandiva/CMakeLists.txt
   +++ b/cpp/src/gandiva/CMakeLists.txt
   @@ -30,6 +30,7 @@ provide_find_module(LLVMAlt "Gandiva")
    if(ARROW_WITH_ZSTD AND "${zstd_SOURCE}" STREQUAL "SYSTEM")
      provide_find_module(zstdAlt "Gandiva")
    endif()
   +provide_cmake_module(GandivaAddBitCode "Gandiva")
    
    # Set the path where the bitcode file generated, see 
precompiled/CMakeLists.txt
    set(GANDIVA_PRECOMPILED_BC_PATH "${CMAKE_CURRENT_BINARY_DIR}/irhelpers.bc")
   diff --git a/cpp/src/gandiva/GandivaConfig.cmake.in 
b/cpp/src/gandiva/GandivaConfig.cmake.in
   index f02e29f25..68579debd 100644
   --- a/cpp/src/gandiva/GandivaConfig.cmake.in
   +++ b/cpp/src/gandiva/GandivaConfig.cmake.in
   @@ -49,6 +49,7 @@ else()
    endif()
    
    include("${CMAKE_CURRENT_LIST_DIR}/GandivaTargets.cmake")
   +include("${CMAKE_CURRENT_LIST_DIR}/GandivaAddBitcode.cmake")
    
    arrow_keep_backward_compatibility(Gandiva gandiva)
    ```
   
   This feature will be useful for Gandiva users who wants to build external 
functions.



##########
cpp/src/gandiva/llvm_ir_store.cc:
##########
@@ -0,0 +1,52 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "gandiva/llvm_ir_store.h"
+
+#include <llvm/Bitcode/BitcodeReader.h>
+
+namespace gandiva {
+
+LLVMIRStore* LLVMIRStore::Get() {
+  static auto* singleton = new LLVMIRStore();
+  return singleton;
+}
+
+Status LLVMIRStore::Add(const std::string& bitcode_file_path) {
+  llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> buffer_or_error =

Review Comment:
   Can we use `auto` here?



##########
cpp/src/gandiva/engine.cc:
##########
@@ -152,6 +153,7 @@ Status Engine::LoadFunctionIRs() {
   if (!functions_loaded_) {
     ARROW_RETURN_NOT_OK(LoadPreCompiledIR());
     ARROW_RETURN_NOT_OK(DecimalIR::AddFunctions(this));
+    ARROW_RETURN_NOT_OK(LoadExternalPreCompiledIR());

Review Comment:
   Can we add `Engine::AddPreCompiledID()` instead of adding 
`LoadExternalPreCompiledIR()` (and `LLVMIRStore`) and calling it here?



##########
cpp/src/gandiva/llvm_generator_test.cc:
##########
@@ -115,4 +117,14 @@ TEST_F(TestLLVMGenerator, TestAdd) {
   EXPECT_EQ(out_bitmap, 0ULL);
 }
 
+TEST_F(TestLLVMGenerator, VerifyExtendedPCFunctions) {
+  ARROW_EXPECT_OK(LoadTestLLVMIR());
+  std::unique_ptr<LLVMGenerator> generator;
+  ASSERT_OK(LLVMGenerator::Make(TestConfiguration(), false, &generator));
+
+  llvm::Module* module = generator->module();

Review Comment:
   ```suggestion
    auto module = generator->module();
   ```



##########
cpp/src/gandiva/cmake/GenerateBitcode.cmake:
##########
@@ -0,0 +1,86 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Create bitcode for each of the source files.
+function(generate_bitcode PRECOMPILED_SRC_LIST OUTPUT_VAR)

Review Comment:
   How about processing only one file instead of multiple files?
   
   How about renaming this to `function(gandiva_add_bitcode OUTPUT_PATH 
SOURCE_PATH)`?
   * Use `add_XXX()` to align with `add_library()`, `add_custom_code()` and so 
son.
   * Specify output path instead of output variable like 
`add_custom_code(OUTPUT)`: 
https://cmake.org/cmake/help/latest/command/add_custom_command.html#generating-files



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to