mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 08:32:02 +00:00
Merge pull request #24550 from kitaisreal/jit_example_update
Update jit_example
This commit is contained in:
commit
4ca651838c
@ -1,57 +1,57 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
// #include <llvm/IR/IRBuilder.h>
|
#include <llvm/IR/IRBuilder.h>
|
||||||
|
|
||||||
// #include <Interpreters/JIT/CHJIT.h>
|
#include <Interpreters/JIT/CHJIT.h>
|
||||||
|
|
||||||
// void test_function()
|
void test_function()
|
||||||
// {
|
{
|
||||||
// std::cerr << "Test function" << std::endl;
|
std::cerr << "Test function" << std::endl;
|
||||||
// }
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
(void)(argc);
|
(void)(argc);
|
||||||
(void)(argv);
|
(void)(argv);
|
||||||
|
|
||||||
// auto jit = DB::CHJIT();
|
auto jit = DB::CHJIT();
|
||||||
|
|
||||||
// jit.registerExternalSymbol("test_function", reinterpret_cast<void *>(&test_function));
|
jit.registerExternalSymbol("test_function", reinterpret_cast<void *>(&test_function));
|
||||||
|
|
||||||
// auto compiled_module_info = jit.compileModule([](llvm::Module & module)
|
auto compiled_module_info = jit.compileModule([](llvm::Module & module)
|
||||||
// {
|
{
|
||||||
// auto & context = module.getContext();
|
auto & context = module.getContext();
|
||||||
// llvm::IRBuilder<> b (context);
|
llvm::IRBuilder<> b (context);
|
||||||
|
|
||||||
// auto * func_declaration_type = llvm::FunctionType::get(b.getVoidTy(), { }, /*isVarArg=*/false);
|
auto * func_declaration_type = llvm::FunctionType::get(b.getVoidTy(), { }, /*isVarArg=*/false);
|
||||||
// auto * func_declaration = llvm::Function::Create(func_declaration_type, llvm::Function::ExternalLinkage, "test_function", module);
|
auto * func_declaration = llvm::Function::Create(func_declaration_type, llvm::Function::ExternalLinkage, "test_function", module);
|
||||||
|
|
||||||
// auto * value_type = b.getInt64Ty();
|
auto * value_type = b.getInt64Ty();
|
||||||
// auto * pointer_type = value_type->getPointerTo();
|
auto * pointer_type = value_type->getPointerTo();
|
||||||
|
|
||||||
// auto * func_type = llvm::FunctionType::get(b.getVoidTy(), { pointer_type }, /*isVarArg=*/false);
|
auto * func_type = llvm::FunctionType::get(b.getVoidTy(), { pointer_type }, /*isVarArg=*/false);
|
||||||
// auto * function = llvm::Function::Create(func_type, llvm::Function::ExternalLinkage, "test_name", module);
|
auto * function = llvm::Function::Create(func_type, llvm::Function::ExternalLinkage, "test_name", module);
|
||||||
// auto * entry = llvm::BasicBlock::Create(context, "entry", function);
|
auto * entry = llvm::BasicBlock::Create(context, "entry", function);
|
||||||
|
|
||||||
// auto * argument = function->args().begin();
|
auto * argument = function->args().begin();
|
||||||
// b.SetInsertPoint(entry);
|
b.SetInsertPoint(entry);
|
||||||
|
|
||||||
// b.CreateCall(func_declaration);
|
b.CreateCall(func_declaration);
|
||||||
|
|
||||||
// auto * load_argument = b.CreateLoad(value_type, argument);
|
auto * load_argument = b.CreateLoad(value_type, argument);
|
||||||
// auto * value = b.CreateAdd(load_argument, load_argument);
|
auto * value = b.CreateAdd(load_argument, load_argument);
|
||||||
// b.CreateRet(value);
|
b.CreateRet(value);
|
||||||
// });
|
});
|
||||||
|
|
||||||
// for (const auto & compiled_function_name : compiled_module_info.compiled_functions)
|
for (const auto & compiled_function_name : compiled_module_info.compiled_functions)
|
||||||
// {
|
{
|
||||||
// std::cerr << compiled_function_name << std::endl;
|
std::cerr << compiled_function_name << std::endl;
|
||||||
// }
|
}
|
||||||
|
|
||||||
// int64_t value = 5;
|
int64_t value = 5;
|
||||||
// auto * test_name_function = reinterpret_cast<int64_t (*)(int64_t *)>(jit.findCompiledFunction(compiled_module_info, "test_name"));
|
auto * test_name_function = reinterpret_cast<int64_t (*)(int64_t *)>(jit.findCompiledFunction(compiled_module_info, "test_name"));
|
||||||
// auto result = test_name_function(&value);
|
auto result = test_name_function(&value);
|
||||||
// std::cerr << "Result " << result << std::endl;
|
std::cerr << "Result " << result << std::endl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user