MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / compile

Function compile

src/Interpreters/ExpressionJIT.cpp:299–338  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

297};
298
299static 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
340static bool isCompilableConstant(const ActionsDAG::Node & node)
341{

Callers 9

jquery.min.jsFile · 0.85
selectFunction · 0.85
prql_to_sql_implFunction · 0.85
compileFunctionsMethod · 0.85
compileModuleWithEngineFunction · 0.85
compileImplMethod · 0.85
compileImplMethod · 0.85
compileImplMethod · 0.85

Calls 8

compileFunctionFunction · 0.85
tryGetCacheMethod · 0.80
setCompiledFunctionMethod · 0.80
getLoggerFunction · 0.70
getJITInstancePtrFunction · 0.70
hashMethod · 0.45
getOrSetMethod · 0.45
getNameMethod · 0.45

Tested by

no test coverage detected