From b491e75a5632c2ca720ead46fdcf106fbbd09e2a Mon Sep 17 00:00:00 2001 From: Maksim Kita Date: Fri, 4 Jun 2021 15:42:46 +0300 Subject: [PATCH] Fix compile functions data type offset --- src/Interpreters/JIT/CHJIT.cpp | 25 +++++++++++++++++++++--- src/Interpreters/JIT/compileFunction.cpp | 11 ++++------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/Interpreters/JIT/CHJIT.cpp b/src/Interpreters/JIT/CHJIT.cpp index 55dfc0b2e62..c06b4132309 100644 --- a/src/Interpreters/JIT/CHJIT.cpp +++ b/src/Interpreters/JIT/CHJIT.cpp @@ -80,6 +80,28 @@ private: llvm::TargetMachine & target_machine; }; +// class AssemblyPrinter +// { +// public: + +// explicit AssemblyPrinter(llvm::TargetMachine &target_machine_) +// : target_machine(target_machine_) +// { +// } + +// void print(llvm::Module & module) +// { +// llvm::legacy::PassManager pass_manager; +// target_machine.Options.MCOptions.AsmVerbose = true; +// if (target_machine.addPassesToEmitFile(pass_manager, llvm::errs(), nullptr, llvm::CodeGenFileType::CGFT_AssemblyFile)) +// throw Exception(ErrorCodes::CANNOT_COMPILE_CODE, "MachineCode cannot be printed"); + +// pass_manager.run(module); +// } +// private: +// llvm::TargetMachine & target_machine; +// }; + /** MemoryManager for module. * Keep total allocated size during RuntimeDyld linker execution. * Actual compiled code memory is stored in llvm::SectionMemoryManager member, we cannot use ZeroBase optimization here @@ -216,9 +238,6 @@ CHJIT::CompiledModule CHJIT::compileModule(std::unique_ptr module) auto buffer = compiler->compile(*module); - // llvm::errs() << "Module after optimizations " << "\n"; - // module->print(llvm::errs(), nullptr); - llvm::Expected> object = llvm::object::ObjectFile::createObjectFile(*buffer); if (!object) diff --git a/src/Interpreters/JIT/compileFunction.cpp b/src/Interpreters/JIT/compileFunction.cpp index f79272ac4ff..813d8abc7df 100644 --- a/src/Interpreters/JIT/compileFunction.cpp +++ b/src/Interpreters/JIT/compileFunction.cpp @@ -329,21 +329,18 @@ static void compileAddIntoAggregateStatesFunctions(llvm::Module & module, const std::vector columns; size_t previous_columns_size = 0; - for (size_t i = 0; i < functions.size(); ++i) + for (const auto & function : functions) { - auto argument_types = functions[i].function->getArgumentTypes(); + auto argument_types = function.function->getArgumentTypes(); ColumnDataPlaceholder data_placeholder; - std::cerr << "Function " << functions[i].function->getName() << std::endl; - size_t function_arguments_size = argument_types.size(); for (size_t column_argument_index = 0; column_argument_index < function_arguments_size; ++column_argument_index) { - const auto & argument_type = argument_types[previous_columns_size + column_argument_index]; - auto * data = b.CreateLoad(column_data_type, b.CreateConstInBoundsGEP1_32(column_data_type, columns_arg, column_argument_index)); - std::cerr << "Argument type " << argument_type->getName() << std::endl; + const auto & argument_type = argument_types[column_argument_index]; + auto * data = b.CreateLoad(column_data_type, b.CreateConstInBoundsGEP1_32(column_data_type, columns_arg, previous_columns_size + column_argument_index)); data_placeholder.data_init = b.CreatePointerCast(b.CreateExtractValue(data, {0}), toNativeType(b, removeNullable(argument_type))->getPointerTo()); columns.emplace_back(data_placeholder); }