Skip to content

Commit 5dce680

Browse files
Pindikura Ravindrawesm
authored andcommitted
ARROW-3472: [Gandiva] remove gandiva_helpers library
This change eliminates the gandiva_helpers library, which was needless duplication. Instead, the entry-points required for LLVM from gandiva are now added as a global-symbols at the time of engine startup. Author: Pindikura Ravindra <ravindra@dremio.com> Closes apache#2747 from pravindra/arrow-3472 and squashes the following commits: 8f16e66 <Pindikura Ravindra> ARROW-3472: add comment on dead-code pass 8ccb56f <Pindikura Ravindra> ARROW-3472: registry for fns exported to LLVM 453ea49 <Pindikura Ravindra> ARROW-3472: remove gandiva_helpers lib
1 parent 2d0d3d0 commit 5dce680

42 files changed

Lines changed: 462 additions & 448 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cpp/cmake_modules/GandivaBuildUtils.cmake

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ function(add_precompiled_unit_test REL_TEST_NAME)
107107
target_include_directories(${TEST_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/src)
108108
target_link_libraries(${TEST_NAME} PRIVATE ${GANDIVA_TEST_LINK_LIBS})
109109
target_compile_definitions(${TEST_NAME} PRIVATE GANDIVA_UNIT_TEST=1)
110-
target_compile_definitions(${TEST_NAME} PRIVATE -DGDV_HELPERS)
111110
add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
112111
set_property(TEST ${TEST_NAME} PROPERTY LABELS gandiva,unittest ${TEST_NAME})
113112
endfunction(add_precompiled_unit_test REL_TEST_NAME)
@@ -118,7 +117,10 @@ function(add_gandiva_integ_test REL_TEST_NAME GANDIVA_LIB)
118117

119118
add_executable(${TEST_NAME}_${GANDIVA_LIB} ${REL_TEST_NAME} ${ARGN})
120119
target_include_directories(${TEST_NAME}_${GANDIVA_LIB} PRIVATE ${CMAKE_SOURCE_DIR})
121-
target_link_libraries(${TEST_NAME}_${GANDIVA_LIB} PRIVATE ${GANDIVA_LIB} ${GANDIVA_TEST_LINK_LIBS})
120+
target_link_libraries(${TEST_NAME}_${GANDIVA_LIB} PRIVATE
121+
${GANDIVA_LIB}
122+
${GANDIVA_TEST_LINK_LIBS}
123+
)
122124

123125
add_test(NAME ${TEST_NAME}_${GANDIVA_LIB} COMMAND ${TEST_NAME}_${GANDIVA_LIB})
124126
set_property(TEST ${TEST_NAME}_${GANDIVA_LIB} PROPERTY LABELS gandiva,integ ${TEST_NAME}_${GANDIVA_LIB})

cpp/src/gandiva/CMakeLists.txt

Lines changed: 20 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -32,43 +32,32 @@ set(GANDIVA_BC_FILE_NAME irhelpers.bc)
3232
set(GANDIVA_BC_INSTALL_PATH ${GANDIVA_BC_INSTALL_DIR}/${GANDIVA_BC_FILE_NAME})
3333
set(GANDIVA_BC_OUTPUT_PATH ${CMAKE_BINARY_DIR}/${GANDIVA_BC_FILE_NAME})
3434

35-
# Set the path where the so lib file will be installed.
36-
if (APPLE)
37-
set(GANDIVA_HELPER_LIB_FILE_NAME libgandiva_helpers.dylib)
38-
else()
39-
set(GANDIVA_HELPER_LIB_FILE_NAME libgandiva_helpers.so)
40-
endif(APPLE)
41-
42-
set(GANDIVA_HELPER_LIB_INSTALL_PATH ${GANDIVA_BC_INSTALL_DIR}/${GANDIVA_HELPER_LIB_FILE_NAME})
43-
set(GANDIVA_HELPER_LIB_OUTPUT_PATH ${CMAKE_BINARY_DIR}/debug/${GANDIVA_HELPER_LIB_FILE_NAME})
44-
4535
set(BC_FILE_PATH_CC "${CMAKE_CURRENT_BINARY_DIR}/bc_file_path.cc")
4636
configure_file(bc_file_path.cc.in ${BC_FILE_PATH_CC})
4737

48-
# helper files that are shared between libgandiva and libgandiva_helpers
49-
set(SHARED_HELPER_FILES
50-
like_holder.cc
51-
regex_util.cc
52-
execution_context.cc
53-
to_date_holder.cc
54-
date_utils.cc)
55-
5638
set(SRC_FILES annotator.cc
5739
bitmap_accumulator.cc
5840
configuration.cc
41+
context_helper.cc
5942
engine.cc
43+
date_utils.cc
6044
expr_decomposer.cc
6145
expr_validator.cc
6246
expression.cc
6347
expression_registry.cc
48+
exported_funcs_registry.cc
6449
filter.cc
6550
function_registry.cc
6651
function_signature.cc
52+
gdv_function_stubs.cc
6753
llvm_generator.cc
6854
llvm_types.cc
55+
like_holder.cc
6956
projector.cc
57+
regex_util.cc
7058
selection_vector.cc
7159
tree_expr_builder.cc
60+
to_date_holder.cc
7261
${SHARED_HELPER_FILES}
7362
${BC_FILE_PATH_CC})
7463

@@ -103,39 +92,12 @@ build_gandiva_lib("shared" arrow_shared)
10392

10493
build_gandiva_lib("static" arrow_static)
10594

106-
# Pre-compiled .so library for function helpers.
107-
add_library(gandiva_helpers SHARED
108-
${SHARED_HELPER_FILES}
109-
function_holder_stubs.cc)
110-
111-
add_dependencies(gandiva_helpers arrow_dependencies)
112-
113-
target_compile_definitions(gandiva_helpers
114-
PRIVATE -DGDV_HELPERS
115-
)
116-
117-
target_include_directories(gandiva_helpers
118-
PRIVATE
119-
${CMAKE_SOURCE_DIR}/include
120-
${CMAKE_SOURCE_DIR}/src
121-
${ARROW_INCLUDE_DIR}
122-
)
123-
124-
target_link_libraries(gandiva_helpers PRIVATE Boost::boost re2)
125-
126-
# hide all symbols that are not needed.
127-
if (NOT APPLE)
128-
# apple linker does not support version scripts, not needed since we package from travis.
129-
set_target_properties(gandiva_helpers PROPERTIES LINK_FLAGS "-Wl,--version-script=${CMAKE_SOURCE_DIR}/src/gandiva/symbols-helpers.map")
130-
target_link_libraries(gandiva_helpers LINK_PRIVATE -static-libstdc++ -static-libgcc)
131-
endif()
132-
13395
# install for gandiva
13496
include(GNUInstallDirs)
13597

13698
# install libgandiva
13799
install(
138-
TARGETS gandiva_shared gandiva_static gandiva_helpers
100+
TARGETS gandiva_shared gandiva_static
139101
DESTINATION ${CMAKE_INSTALL_LIBDIR}
140102
)
141103

@@ -166,20 +128,26 @@ install(
166128
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig/")
167129

168130
#args: label test-file src-files
169-
add_gandiva_unit_test(bitmap_accumulator_test.cc bitmap_accumulator.cc execution_context.cc)
170-
add_gandiva_unit_test(engine_llvm_test.cc engine.cc llvm_types.cc configuration.cc execution_context.cc ${BC_FILE_PATH_CC})
131+
add_gandiva_unit_test(bitmap_accumulator_test.cc bitmap_accumulator.cc)
132+
add_gandiva_unit_test(engine_llvm_test.cc engine.cc llvm_types.cc configuration.cc
133+
gdv_function_stubs.cc context_helper.cc to_date_holder.cc date_utils.cc
134+
exported_funcs_registry.cc ${BC_FILE_PATH_CC})
171135
add_gandiva_unit_test(function_signature_test.cc function_signature.cc)
172136
add_gandiva_unit_test(function_registry_test.cc function_registry.cc function_signature.cc)
173137
add_gandiva_unit_test(llvm_types_test.cc llvm_types.cc)
174-
add_gandiva_unit_test(llvm_generator_test.cc llvm_generator.cc regex_util.cc engine.cc llvm_types.cc expr_decomposer.cc function_registry.cc annotator.cc bitmap_accumulator.cc configuration.cc function_signature.cc like_holder.cc to_date_holder.cc date_utils.cc regex_util.cc execution_context.cc ${BC_FILE_PATH_CC})
138+
add_gandiva_unit_test(llvm_generator_test.cc llvm_generator.cc regex_util.cc engine.cc
139+
llvm_types.cc expr_decomposer.cc function_registry.cc annotator.cc
140+
bitmap_accumulator.cc configuration.cc function_signature.cc like_holder.cc
141+
to_date_holder.cc date_utils.cc regex_util.cc gdv_function_stubs.cc context_helper.cc
142+
exported_funcs_registry.cc ${BC_FILE_PATH_CC})
175143
add_gandiva_unit_test(annotator_test.cc annotator.cc function_signature.cc)
176-
add_gandiva_unit_test(tree_expr_test.cc tree_expr_builder.cc expr_decomposer.cc annotator.cc function_registry.cc function_signature.cc like_holder.cc regex_util.cc to_date_holder.cc date_utils.cc execution_context.cc)
177-
add_gandiva_unit_test(expr_decomposer_test.cc expr_decomposer.cc tree_expr_builder.cc annotator.cc function_registry.cc function_signature.cc like_holder.cc regex_util.cc to_date_holder.cc date_utils.cc execution_context.cc)
144+
add_gandiva_unit_test(tree_expr_test.cc tree_expr_builder.cc expr_decomposer.cc annotator.cc function_registry.cc function_signature.cc like_holder.cc regex_util.cc to_date_holder.cc date_utils.cc)
145+
add_gandiva_unit_test(expr_decomposer_test.cc expr_decomposer.cc tree_expr_builder.cc annotator.cc function_registry.cc function_signature.cc like_holder.cc regex_util.cc to_date_holder.cc date_utils.cc)
178146
add_gandiva_unit_test(status_test.cc)
179147
add_gandiva_unit_test(expression_registry_test.cc llvm_types.cc expression_registry.cc function_signature.cc function_registry.cc)
180148
add_gandiva_unit_test(selection_vector_test.cc selection_vector.cc)
181149
add_gandiva_unit_test(lru_cache_test.cc)
182-
add_gandiva_unit_test(to_date_holder_test.cc to_date_holder.cc date_utils.cc execution_context.cc)
150+
add_gandiva_unit_test(to_date_holder_test.cc to_date_holder.cc date_utils.cc)
183151

184152
add_subdirectory(jni)
185153
add_subdirectory(precompiled)

cpp/src/gandiva/bc_file_path.cc.in

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,4 @@ namespace gandiva {
2020
// Path to the byte-code file.
2121
extern const char kByteCodeFilePath[] = "${GANDIVA_BC_OUTPUT_PATH}";
2222

23-
// Path to the pre-compiled solib file.
24-
extern const char kHelperLibFilePath[] = "${GANDIVA_HELPER_LIB_OUTPUT_PATH}";
25-
2623
} // namespace gandiva

cpp/src/gandiva/configuration.h

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
namespace gandiva {
2727

2828
extern const char kByteCodeFilePath[];
29-
extern const char kHelperLibFilePath[];
3029

3130
class ConfigurationBuilder;
3231
/// \brief runtime config for gandiva
@@ -38,20 +37,16 @@ class Configuration {
3837
friend class ConfigurationBuilder;
3938

4039
const std::string& byte_code_file_path() const { return byte_code_file_path_; }
41-
const std::string& helper_lib_file_path() const { return helper_lib_file_path_; }
4240

4341
std::size_t Hash() const;
4442
bool operator==(const Configuration& other) const;
4543
bool operator!=(const Configuration& other) const;
4644

4745
private:
48-
explicit Configuration(const std::string& byte_code_file_path,
49-
const std::string& helper_lib_file_path)
50-
: byte_code_file_path_(byte_code_file_path),
51-
helper_lib_file_path_(helper_lib_file_path) {}
46+
explicit Configuration(const std::string& byte_code_file_path)
47+
: byte_code_file_path_(byte_code_file_path) {}
5248

5349
const std::string byte_code_file_path_;
54-
const std::string helper_lib_file_path_;
5550
};
5651

5752
/// \brief configuration builder for gandiva
@@ -60,24 +55,15 @@ class Configuration {
6055
/// to override specific values and build a custom instance
6156
class ConfigurationBuilder {
6257
public:
63-
ConfigurationBuilder()
64-
: byte_code_file_path_(kByteCodeFilePath),
65-
helper_lib_file_path_(kHelperLibFilePath) {}
58+
ConfigurationBuilder() : byte_code_file_path_(kByteCodeFilePath) {}
6659

6760
ConfigurationBuilder& set_byte_code_file_path(const std::string& byte_code_file_path) {
6861
byte_code_file_path_ = byte_code_file_path;
6962
return *this;
7063
}
7164

72-
ConfigurationBuilder& set_helper_lib_file_path(
73-
const std::string& helper_lib_file_path) {
74-
helper_lib_file_path_ = helper_lib_file_path;
75-
return *this;
76-
}
77-
7865
std::shared_ptr<Configuration> build() {
79-
std::shared_ptr<Configuration> configuration(
80-
new Configuration(byte_code_file_path_, helper_lib_file_path_));
66+
std::shared_ptr<Configuration> configuration(new Configuration(byte_code_file_path_));
8167
return configuration;
8268
}
8369

@@ -87,11 +73,9 @@ class ConfigurationBuilder {
8773

8874
private:
8975
std::string byte_code_file_path_;
90-
std::string helper_lib_file_path_;
9176

9277
static std::shared_ptr<Configuration> InitDefaultConfig() {
93-
std::shared_ptr<Configuration> configuration(
94-
new Configuration(kByteCodeFilePath, kHelperLibFilePath));
78+
std::shared_ptr<Configuration> configuration(new Configuration(kByteCodeFilePath));
9579
return configuration;
9680
}
9781

cpp/src/gandiva/context_helper.cc

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
// This file is also used in the pre-compiled unit tests, which do include
19+
// llvm/engine/..
20+
#ifndef GANDIVA_UNIT_TEST
21+
#include "gandiva/exported_funcs.h"
22+
#include "gandiva/gdv_function_stubs.h"
23+
24+
#include "gandiva/engine.h"
25+
26+
namespace gandiva {
27+
28+
void ExportedContextFunctions::AddMappings(Engine& engine) const {
29+
std::vector<llvm::Type*> args;
30+
auto types = engine.types();
31+
32+
// gdv_fn_context_set_error_msg
33+
args = {types.i64_type(), // int64_t context_ptr
34+
types.i8_ptr_type()}; // char const* err_msg
35+
36+
engine.AddGlobalMappingForFunc("gdv_fn_context_set_error_msg", types.void_type(), args,
37+
reinterpret_cast<void*>(gdv_fn_context_set_error_msg));
38+
}
39+
40+
} // namespace gandiva
41+
#endif // !GANDIVA_UNIT_TEST
42+
43+
#include "gandiva/execution_context.h"
44+
45+
extern "C" {
46+
47+
void gdv_fn_context_set_error_msg(int64_t context_ptr, char const* err_msg) {
48+
gandiva::ExecutionContext* execution_context_ptr =
49+
reinterpret_cast<gandiva::ExecutionContext*>(context_ptr);
50+
(execution_context_ptr)->set_error_msg(err_msg);
51+
}
52+
}

cpp/src/gandiva/date_utils.cc

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@
2323

2424
namespace gandiva {
2525

26-
#ifdef GDV_HELPERS
27-
namespace helpers {
28-
#endif
29-
3026
std::vector<std::string> DateUtils::GetMatches(std::string pattern, bool exactMatch) {
3127
// we are case insensitive
3228
std::transform(pattern.begin(), pattern.end(), pattern.begin(), ::tolower);
@@ -238,8 +234,4 @@ DateUtils::date_format_converter DateUtils::InitMap() {
238234
return map;
239235
}
240236

241-
#ifdef GDV_HELPERS
242-
} // namespace helpers
243-
#endif
244-
245237
} // namespace gandiva

cpp/src/gandiva/date_utils.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@
2727

2828
namespace gandiva {
2929

30-
#ifdef GDV_HELPERS
31-
namespace helpers {
32-
#endif
33-
3430
/// \brief Utility class for converting sql date patterns to internal date patterns.
3531
class DateUtils {
3632
public:
@@ -51,10 +47,6 @@ class DateUtils {
5147
static std::vector<std::string> GetExactMatches(const std::string& pattern);
5248
};
5349

54-
#ifdef GDV_HELPERS
55-
} // namespace helpers
56-
#endif
57-
5850
} // namespace gandiva
5951

6052
#endif // TO_DATE_HELPER_H

0 commit comments

Comments
 (0)