mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-25 17:12:03 +00:00
Fixed code review issues
This commit is contained in:
parent
8bc511eaa0
commit
e72c139bf6
@ -197,7 +197,10 @@ void AsynchronousMetrics::update()
|
||||
#if USE_EMBEDDED_COMPILER
|
||||
{
|
||||
if (auto * compiled_expression_cache = CompiledExpressionCacheFactory::instance().tryGetCache())
|
||||
{
|
||||
new_values["CompiledExpressionCacheBytes"] = compiled_expression_cache->weight();
|
||||
new_values["CompiledExpressionCacheCount"] = compiled_expression_cache->count();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -54,7 +54,7 @@ public:
|
||||
handleAllErrors(std::move(materialize_error),
|
||||
[&](const llvm::ErrorInfoBase & error_info) { error_message = error_info.message(); });
|
||||
|
||||
throw Exception(ErrorCodes::CANNOT_COMPILE_CODE, "Cannot materialize module {}", error_message);
|
||||
throw Exception(ErrorCodes::CANNOT_COMPILE_CODE, "Cannot materialize module: {}", error_message);
|
||||
}
|
||||
|
||||
llvm::SmallVector<char, 4096> object_buffer;
|
||||
@ -82,7 +82,8 @@ private:
|
||||
|
||||
/** MemoryManager for module.
|
||||
* Keep total allocated size during RuntimeDyld linker execution.
|
||||
* Release compiled module memory in destructor.
|
||||
* Actual compiled code memory is stored in llvm::SectionMemoryManager member, we cannot use ZeroBase optimization here
|
||||
* because it is required for llvm::SectionMemoryManager::MemoryMapper to live longer than llvm::SectionMemoryManager.
|
||||
*/
|
||||
class JITModuleMemoryManager
|
||||
{
|
||||
@ -222,7 +223,7 @@ CHJIT::CompiledModuleInfo CHJIT::compileModule(std::unique_ptr<llvm::Module> mod
|
||||
std::string error_message;
|
||||
handleAllErrors(object.takeError(), [&](const llvm::ErrorInfoBase & error_info) { error_message = error_info.message(); });
|
||||
|
||||
throw Exception(ErrorCodes::CANNOT_COMPILE_CODE, "Cannot create object file from compiled buffer {}", error_message);
|
||||
throw Exception(ErrorCodes::CANNOT_COMPILE_CODE, "Cannot create object file from compiled buffer: {}", error_message);
|
||||
}
|
||||
|
||||
std::unique_ptr<JITModuleMemoryManager> module_memory_manager = std::make_unique<JITModuleMemoryManager>();
|
||||
@ -335,29 +336,22 @@ void CHJIT::runOptimizationPassesOnModule(llvm::Module & module) const
|
||||
mpm.run(module);
|
||||
}
|
||||
|
||||
std::atomic<bool> initialized = false;
|
||||
|
||||
static void initializeLLVMTarget()
|
||||
{
|
||||
if (initialized)
|
||||
return;
|
||||
|
||||
initialized = true;
|
||||
llvm::InitializeNativeTarget();
|
||||
llvm::InitializeNativeTargetAsmPrinter();
|
||||
llvm::sys::DynamicLibrary::LoadLibraryPermanently(nullptr);
|
||||
}
|
||||
|
||||
std::unique_ptr<llvm::TargetMachine> CHJIT::getTargetMachine()
|
||||
{
|
||||
initializeLLVMTarget();
|
||||
static std::once_flag llvm_target_initialized;
|
||||
std::call_once(llvm_target_initialized, []()
|
||||
{
|
||||
llvm::InitializeNativeTarget();
|
||||
llvm::InitializeNativeTargetAsmPrinter();
|
||||
llvm::sys::DynamicLibrary::LoadLibraryPermanently(nullptr);
|
||||
});
|
||||
|
||||
std::string error;
|
||||
auto cpu = llvm::sys::getHostCPUName();
|
||||
auto triple = llvm::sys::getProcessTriple();
|
||||
const auto * target = llvm::TargetRegistry::lookupTarget(triple, error);
|
||||
if (!target)
|
||||
throw Exception(ErrorCodes::CANNOT_COMPILE_CODE, "Cannot find target triple {} error {}", triple, error);
|
||||
throw Exception(ErrorCodes::CANNOT_COMPILE_CODE, "Cannot find target triple {} error: {}", triple, error);
|
||||
|
||||
llvm::SubtargetFeatures features;
|
||||
llvm::StringMap<bool> feature_map;
|
||||
|
@ -32,9 +32,11 @@ class JITCompiler;
|
||||
* llvm::Module can be removed, but compiled object code cannot be removed. Memory for compiled code
|
||||
* will be release only during MCJIT instance destruction. It is too expensive to create MCJIT
|
||||
* instance for each compiled module.
|
||||
* Also important reason is that if some error occurred during compilation steps, MCJIT can just terminate
|
||||
* our program.
|
||||
*
|
||||
* Main reasons for custom implementation vs ORCv2.
|
||||
* ORC is on request compiled, we does not need support for asynchronous compilation.
|
||||
* ORC is on request compiler, we do not need support for asynchronous compilation.
|
||||
* It was possible to remove compiled code with ORCv1 but it was deprecated.
|
||||
* In ORCv2 this probably can be done only with custom layer and materialization unit.
|
||||
* But it is inconvenient, discard is only called for materialization units by JITDylib that are not yet materialized.
|
||||
|
@ -135,36 +135,14 @@ std::string CompileDAG::dump() const
|
||||
|
||||
UInt128 CompileDAG::hash() const
|
||||
{
|
||||
std::string dag_dump = dump();
|
||||
|
||||
SipHash hash;
|
||||
for (const auto & node : nodes)
|
||||
{
|
||||
hash.update(node.type);
|
||||
hash.update(node.result_type->getName());
|
||||
|
||||
switch (node.type)
|
||||
{
|
||||
case CompileType::CONSTANT:
|
||||
{
|
||||
assert_cast<const ColumnConst *>(node.column.get())->getDataColumn().updateHashWithValue(0, hash);
|
||||
break;
|
||||
}
|
||||
case CompileType::FUNCTION:
|
||||
{
|
||||
hash.update(node.function->getName());
|
||||
for (size_t arg : node.arguments)
|
||||
hash.update(arg);
|
||||
|
||||
break;
|
||||
}
|
||||
case CompileType::INPUT:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
hash.update(dag_dump);
|
||||
|
||||
UInt128 result;
|
||||
hash.get128(result.low, result.high);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user