| 297 | }; |
| 298 | |
| 299 | static FunctionBasePtr compile( |
| 300 | const CompileDAG & dag, |
| 301 | size_t min_count_to_compile_expression) |
| 302 | { |
| 303 | static std::unordered_map<UInt128, UInt64, UInt128Hash> counter; |
| 304 | static std::mutex mutex; |
| 305 | |
| 306 | auto hash_key = dag.hash(); |
| 307 | { |
| 308 | std::lock_guard lock(mutex); |
| 309 | if (counter[hash_key]++ < min_count_to_compile_expression) |
| 310 | return nullptr; |
| 311 | } |
| 312 | |
| 313 | auto llvm_function = std::make_shared<LLVMFunction>(dag); |
| 314 | |
| 315 | if (auto * compilation_cache = CompiledExpressionCacheFactory::instance().tryGetCache()) |
| 316 | { |
| 317 | auto [compiled_function_cache_entry, _] = compilation_cache->getOrSet(hash_key, [&] () |
| 318 | { |
| 319 | LOG_TRACE(getLogger(), "Compile expression {}", llvm_function->getName()); |
| 320 | auto jit_owner = getJITInstancePtr(); |
| 321 | auto compiled_function = compileFunction(*jit_owner, *llvm_function); |
| 322 | return std::make_shared<CompiledFunctionHolder>(compiled_function, std::move(jit_owner)); |
| 323 | }); |
| 324 | |
| 325 | std::shared_ptr<CompiledFunctionHolder> compiled_function_holder = std::static_pointer_cast<CompiledFunctionHolder>(compiled_function_cache_entry); |
| 326 | llvm_function->setCompiledFunction(std::move(compiled_function_holder)); |
| 327 | } |
| 328 | else |
| 329 | { |
| 330 | auto jit_owner = getJITInstancePtr(); |
| 331 | auto compiled_function = compileFunction(*jit_owner, *llvm_function); |
| 332 | auto compiled_function_holder = std::make_shared<CompiledFunctionHolder>(compiled_function, std::move(jit_owner)); |
| 333 | |
| 334 | llvm_function->setCompiledFunction(std::move(compiled_function_holder)); |
| 335 | } |
| 336 | |
| 337 | return llvm_function; |
| 338 | } |
| 339 | |
| 340 | static bool isCompilableConstant(const ActionsDAG::Node & node) |
| 341 | { |
no test coverage detected