From 9969c3e02ef0146aefcb35dcf95e2a5a3a099db1 Mon Sep 17 00:00:00 2001 From: turingcompl33t Date: Tue, 29 Sep 2020 10:00:36 -0400 Subject: [PATCH 1/5] naive solution; need to benchmark and compare against solution implemented within LLVM engine --- src/execution/vm/bytecode_generator.cpp | 25 +++++++++++++++++-------- src/execution/vm/llvm_engine.cpp | 3 ++- src/include/main/db_main.h | 8 +++++--- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/execution/vm/bytecode_generator.cpp b/src/execution/vm/bytecode_generator.cpp index f26390c33a..62fa364c20 100644 --- a/src/execution/vm/bytecode_generator.cpp +++ b/src/execution/vm/bytecode_generator.cpp @@ -3505,14 +3505,23 @@ void BytecodeGenerator::VisitMemberExpr(ast::MemberExpr *node) { // object is zero, we needn't do anything - we can just reinterpret the object // pointer. If the field offset is greater than zero, we generate a LEA. - LocalVar field_ptr; - if (offset == 0) { - field_ptr = obj_ptr; - } else { - field_ptr = GetCurrentFunction()->NewLocal(node->GetType()->PointerTo()); - GetEmitter()->EmitLea(field_ptr, obj_ptr, offset); - field_ptr = field_ptr.ValueOf(); - } + // TODO(Kyle): the optimization described above is ultimately what leads + // us to attempt a non-type-system-compliant store when compiling the + // resulting bytecode to LLVM IR; eliding the optimization entirely solves + // the issue here at the bytecode level, but always incurs the cost of an + // additional Lea bytecode as well as an additional store in the IR + +// LocalVar field_ptr; +// if (offset == 0) { +// field_ptr = obj_ptr; +// } else { +// field_ptr = GetCurrentFunction()->NewLocal(node->GetType()->PointerTo()); +// GetEmitter()->EmitLea(field_ptr, obj_ptr, offset); +// field_ptr = field_ptr.ValueOf(); +// } + LocalVar field_ptr = GetCurrentFunction()->NewLocal(node->GetType()->PointerTo()); + GetEmitter()->EmitLea(field_ptr, obj_ptr, offset); + field_ptr = field_ptr.ValueOf(); if (GetExecutionResult()->IsLValue()) { TERRIER_ASSERT(!GetExecutionResult()->HasDestination(), "L-Values produce their destination"); diff --git a/src/execution/vm/llvm_engine.cpp b/src/execution/vm/llvm_engine.cpp index 0689501850..d7b38ffea0 100644 --- a/src/execution/vm/llvm_engine.cpp +++ b/src/execution/vm/llvm_engine.cpp @@ -731,7 +731,8 @@ void LLVMEngine::CompiledModuleBuilder::DefineFunction(const FunctionInfo &func_ case OperandType::LocalCount: { std::vector locals; iter.GetLocalCountOperand(i, &locals); - for (const auto local : locals) { + // TODO(Kyle): need to make & in order to compile? + for (const auto& local : locals) { args.push_back(locals_map.GetArgumentById(local)); } break; diff --git a/src/include/main/db_main.h b/src/include/main/db_main.h index 43e3c85da6..6d67772b6d 100644 --- a/src/include/main/db_main.h +++ b/src/include/main/db_main.h @@ -709,9 +709,11 @@ class DBMain { optimizer_timeout_ = static_cast(settings_manager->GetInt(settings::Param::task_execution_timeout)); use_query_cache_ = settings_manager->GetBool(settings::Param::use_query_cache); - execution_mode_ = settings_manager->GetBool(settings::Param::compiled_query_execution) - ? execution::vm::ExecutionMode::Compiled - : execution::vm::ExecutionMode::Interpret; + // TODO(Kyle): manually setting exec mode to compiled for testing purposes + execution_mode_ = execution::vm::ExecutionMode::Compiled; +// execution_mode_ = settings_manager->GetBool(settings::Param::compiled_query_execution) +// ? execution::vm::ExecutionMode::Compiled +// : execution::vm::ExecutionMode::Interpret; metrics_query_trace_ = settings_manager->GetBool(settings::Param::metrics_query_trace); metrics_pipeline_ = settings_manager->GetBool(settings::Param::metrics_pipeline); From 18dd10a8a4a544bafaf89ee548f15d1ac75bb2c7 Mon Sep 17 00:00:00 2001 From: turingcompl33t Date: Wed, 20 Jan 2021 14:12:38 -0500 Subject: [PATCH 2/5] remove unnecessary temporary items from diff --- src/execution/vm/bytecode_generator.cpp | 16 ++++++++-------- src/execution/vm/llvm_engine.cpp | 3 +-- src/include/main/db_main.h | 8 +++----- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/execution/vm/bytecode_generator.cpp b/src/execution/vm/bytecode_generator.cpp index 2eb2217919..ad8814dec4 100644 --- a/src/execution/vm/bytecode_generator.cpp +++ b/src/execution/vm/bytecode_generator.cpp @@ -3651,14 +3651,14 @@ void BytecodeGenerator::VisitMemberExpr(ast::MemberExpr *node) { // the issue here at the bytecode level, but always incurs the cost of an // additional Lea bytecode as well as an additional store in the IR -// LocalVar field_ptr; -// if (offset == 0) { -// field_ptr = obj_ptr; -// } else { -// field_ptr = GetCurrentFunction()->NewLocal(node->GetType()->PointerTo()); -// GetEmitter()->EmitLea(field_ptr, obj_ptr, offset); -// field_ptr = field_ptr.ValueOf(); -// } + // LocalVar field_ptr; + // if (offset == 0) { + // field_ptr = obj_ptr; + // } else { + // field_ptr = GetCurrentFunction()->NewLocal(node->GetType()->PointerTo()); + // GetEmitter()->EmitLea(field_ptr, obj_ptr, offset); + // field_ptr = field_ptr.ValueOf(); + // } LocalVar field_ptr = GetCurrentFunction()->NewLocal(node->GetType()->PointerTo()); GetEmitter()->EmitLea(field_ptr, obj_ptr, offset); field_ptr = field_ptr.ValueOf(); diff --git a/src/execution/vm/llvm_engine.cpp b/src/execution/vm/llvm_engine.cpp index f9a51586c3..33e8d56364 100644 --- a/src/execution/vm/llvm_engine.cpp +++ b/src/execution/vm/llvm_engine.cpp @@ -738,8 +738,7 @@ void LLVMEngine::CompiledModuleBuilder::DefineFunction(const FunctionInfo &func_ case OperandType::LocalCount: { std::vector locals; iter.GetLocalCountOperand(i, &locals); - // TODO(Kyle): need to make & in order to compile? - for (const auto& local : locals) { + for (const auto local : locals) { args.push_back(locals_map.GetArgumentById(local)); } break; diff --git a/src/include/main/db_main.h b/src/include/main/db_main.h index 18c14a9acf..16ca613fe6 100644 --- a/src/include/main/db_main.h +++ b/src/include/main/db_main.h @@ -863,11 +863,9 @@ class DBMain { optimizer_timeout_ = static_cast(settings_manager->GetInt(settings::Param::task_execution_timeout)); use_query_cache_ = settings_manager->GetBool(settings::Param::use_query_cache); - // TODO(Kyle): manually setting exec mode to compiled for testing purposes - execution_mode_ = execution::vm::ExecutionMode::Compiled; -// execution_mode_ = settings_manager->GetBool(settings::Param::compiled_query_execution) -// ? execution::vm::ExecutionMode::Compiled -// : execution::vm::ExecutionMode::Interpret; + execution_mode_ = settings_manager->GetBool(settings::Param::compiled_query_execution) + ? execution::vm::ExecutionMode::Compiled + : execution::vm::ExecutionMode::Interpret; query_trace_metrics_ = settings_manager->GetBool(settings::Param::query_trace_metrics_enable); pipeline_metrics_ = settings_manager->GetBool(settings::Param::pipeline_metrics_enable); From 1e51799a7bd55ec3f1cd2ddbd2e3a172ab17ba56 Mon Sep 17 00:00:00 2001 From: turingcompl33t Date: Fri, 22 Jan 2021 09:48:08 -0500 Subject: [PATCH 3/5] remove old commented code --- src/execution/vm/bytecode_generator.cpp | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/execution/vm/bytecode_generator.cpp b/src/execution/vm/bytecode_generator.cpp index ad8814dec4..fc0d5ed3a5 100644 --- a/src/execution/vm/bytecode_generator.cpp +++ b/src/execution/vm/bytecode_generator.cpp @@ -3649,16 +3649,8 @@ void BytecodeGenerator::VisitMemberExpr(ast::MemberExpr *node) { // us to attempt a non-type-system-compliant store when compiling the // resulting bytecode to LLVM IR; eliding the optimization entirely solves // the issue here at the bytecode level, but always incurs the cost of an - // additional Lea bytecode as well as an additional store in the IR - - // LocalVar field_ptr; - // if (offset == 0) { - // field_ptr = obj_ptr; - // } else { - // field_ptr = GetCurrentFunction()->NewLocal(node->GetType()->PointerTo()); - // GetEmitter()->EmitLea(field_ptr, obj_ptr, offset); - // field_ptr = field_ptr.ValueOf(); - // } + // additional Lea bytecode as well as an additional store in the IR. + LocalVar field_ptr = GetCurrentFunction()->NewLocal(node->GetType()->PointerTo()); GetEmitter()->EmitLea(field_ptr, obj_ptr, offset); field_ptr = field_ptr.ValueOf(); From 525ff0d6ecaf2d4d6bbd146f56c86704fb794f6b Mon Sep 17 00:00:00 2001 From: turingcompl33t Date: Fri, 19 Mar 2021 08:39:03 -0400 Subject: [PATCH 4/5] wip --- src/execution/vm/bytecode_generator.cpp | 17 +++++++++++++---- src/execution/vm/llvm_engine.cpp | 4 ++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/execution/vm/bytecode_generator.cpp b/src/execution/vm/bytecode_generator.cpp index 2c3f52b0a3..451d322298 100644 --- a/src/execution/vm/bytecode_generator.cpp +++ b/src/execution/vm/bytecode_generator.cpp @@ -3745,10 +3745,19 @@ void BytecodeGenerator::VisitMemberExpr(ast::MemberExpr *node) { // resulting bytecode to LLVM IR; eliding the optimization entirely solves // the issue here at the bytecode level, but always incurs the cost of an // additional Lea bytecode as well as an additional store in the IR. - - LocalVar field_ptr = GetCurrentFunction()->NewLocal(node->GetType()->PointerTo()); - GetEmitter()->EmitLea(field_ptr, obj_ptr, offset); - field_ptr = field_ptr.ValueOf(); + + // LocalVar field_ptr = GetCurrentFunction()->NewLocal(node->GetType()->PointerTo()); + // GetEmitter()->EmitLea(field_ptr, obj_ptr, offset); + // field_ptr = field_ptr.ValueOf(); + + LocalVar field_ptr; + if (offset == 0) { + field_ptr = obj_ptr; + } else { + field_ptr = GetCurrentFunction()->NewLocal(node->GetType()->PointerTo()); + GetEmitter()->EmitLea(field_ptr, obj_ptr, offset); + field_ptr = field_ptr.ValueOf(); + } if (GetExecutionResult()->IsLValue()) { NOISEPAGE_ASSERT(!GetExecutionResult()->HasDestination(), "L-Values produce their destination"); diff --git a/src/execution/vm/llvm_engine.cpp b/src/execution/vm/llvm_engine.cpp index 5bf74ec236..89a492e3ee 100644 --- a/src/execution/vm/llvm_engine.cpp +++ b/src/execution/vm/llvm_engine.cpp @@ -28,6 +28,8 @@ #include #include +#include + #include "execution/ast/type.h" #include "execution/vm/bytecode_module.h" #include "execution/vm/bytecode_traits.h" @@ -1160,6 +1162,8 @@ std::unique_ptr LLVMEngine::Compile(const BytecodeMo const CompilerOptions &options) { CompiledModuleBuilder builder(options, module); + // module.Dump(std::cerr); + builder.DeclareStaticLocals(); builder.DeclareFunctions(); From 383e328a57e704978d5f2aef70300929edd7f3c8 Mon Sep 17 00:00:00 2001 From: turingcompl33t Date: Fri, 19 Mar 2021 10:40:28 -0400 Subject: [PATCH 5/5] trying to get back to a null diff --- src/execution/vm/bytecode_generator.cpp | 10 ---------- src/execution/vm/llvm_engine.cpp | 4 ---- 2 files changed, 14 deletions(-) diff --git a/src/execution/vm/bytecode_generator.cpp b/src/execution/vm/bytecode_generator.cpp index 451d322298..06019228be 100644 --- a/src/execution/vm/bytecode_generator.cpp +++ b/src/execution/vm/bytecode_generator.cpp @@ -3740,16 +3740,6 @@ void BytecodeGenerator::VisitMemberExpr(ast::MemberExpr *node) { // object is zero, we needn't do anything - we can just reinterpret the object // pointer. If the field offset is greater than zero, we generate a LEA. - // TODO(Kyle): the optimization described above is ultimately what leads - // us to attempt a non-type-system-compliant store when compiling the - // resulting bytecode to LLVM IR; eliding the optimization entirely solves - // the issue here at the bytecode level, but always incurs the cost of an - // additional Lea bytecode as well as an additional store in the IR. - - // LocalVar field_ptr = GetCurrentFunction()->NewLocal(node->GetType()->PointerTo()); - // GetEmitter()->EmitLea(field_ptr, obj_ptr, offset); - // field_ptr = field_ptr.ValueOf(); - LocalVar field_ptr; if (offset == 0) { field_ptr = obj_ptr; diff --git a/src/execution/vm/llvm_engine.cpp b/src/execution/vm/llvm_engine.cpp index 89a492e3ee..5bf74ec236 100644 --- a/src/execution/vm/llvm_engine.cpp +++ b/src/execution/vm/llvm_engine.cpp @@ -28,8 +28,6 @@ #include #include -#include - #include "execution/ast/type.h" #include "execution/vm/bytecode_module.h" #include "execution/vm/bytecode_traits.h" @@ -1162,8 +1160,6 @@ std::unique_ptr LLVMEngine::Compile(const BytecodeMo const CompilerOptions &options) { CompiledModuleBuilder builder(options, module); - // module.Dump(std::cerr); - builder.DeclareStaticLocals(); builder.DeclareFunctions();