@@ -72,7 +72,6 @@ struct V8Engine : m::WasmEngine
72
72
static inline v8::Platform *PLATFORM_ = nullptr ;
73
73
v8::ArrayBuffer::Allocator *allocator_ = nullptr ;
74
74
v8::Isolate *isolate_ = nullptr ;
75
- std::unique_ptr<PhysicalOptimizer> phys_opt_ = std::make_unique<PhysicalOptimizerImpl<ConcretePhysicalPlanTable>>();
76
75
77
76
/* ----- Objects for remote debugging via CDT. --------------------------------------------------------------------*/
78
77
std::unique_ptr<V8InspectorClientImpl> inspector_;
@@ -90,8 +89,8 @@ struct V8Engine : m::WasmEngine
90
89
}
91
90
92
91
void initialize ();
93
- void compile (const m::Operator &plan) const override ;
94
- void execute (const m::Operator &plan) override ;
92
+ void compile (const MatchBase &plan) const override ;
93
+ void execute (const MatchBase &plan) override ;
95
94
};
96
95
97
96
@@ -294,7 +293,8 @@ void m::wasm::detail::read_result_set(const v8::FunctionCallbackInfo<v8::Value>
294
293
{
295
294
auto &context = WasmEngine::Get_Wasm_Context_By_ID (Module::ID ());
296
295
297
- auto &schema = context.plan .schema ();
296
+ auto &root_op = context.plan .get_matched_singleton ();
297
+ auto &schema = root_op.schema ();
298
298
auto deduplicated_schema = schema.deduplicate ();
299
299
auto deduplicated_schema_without_constants = deduplicated_schema.drop_constants ();
300
300
@@ -332,7 +332,7 @@ void m::wasm::detail::read_result_set(const v8::FunctionCallbackInfo<v8::Value>
332
332
};
333
333
return find_projection_impl (op, find_projection_impl);
334
334
};
335
- auto &projections = find_projection (context. plan ).projections ();
335
+ auto &projections = find_projection (root_op ).projections ();
336
336
337
337
// /> helper function to print given `ast::Constant` \p c of `Type` \p type to \p out
338
338
auto print_constant = [](std::ostringstream &out, const ast::Constant &c, const Type *type){
@@ -389,7 +389,7 @@ void m::wasm::detail::read_result_set(const v8::FunctionCallbackInfo<v8::Value>
389
389
390
390
if (deduplicated_schema_without_constants.num_entries () == 0 ) {
391
391
/* Schema contains only constants. Create simple loop to generate `num_tuples` constant result tuples. */
392
- if (auto callback_op = cast<const CallbackOperator>(&context. plan )) {
392
+ if (auto callback_op = cast<const CallbackOperator>(&root_op )) {
393
393
Tuple tup (schema); // tuple entries which are not set are implicitly NULL
394
394
for (std::size_t i = 0 ; i < schema.num_entries (); ++i) {
395
395
auto &e = schema[i];
@@ -399,7 +399,7 @@ void m::wasm::detail::read_result_set(const v8::FunctionCallbackInfo<v8::Value>
399
399
}
400
400
for (std::size_t i = 0 ; i < num_tuples; ++i)
401
401
callback_op->callback ()(schema, tup);
402
- } else if (auto print_op = cast<const PrintOperator>(&context. plan )) {
402
+ } else if (auto print_op = cast<const PrintOperator>(&root_op )) {
403
403
std::ostringstream tup;
404
404
for (std::size_t i = 0 ; i < schema.num_entries (); ++i) {
405
405
auto &e = schema[i];
@@ -419,7 +419,7 @@ void m::wasm::detail::read_result_set(const v8::FunctionCallbackInfo<v8::Value>
419
419
auto layout = context.result_set_factory ->make (deduplicated_schema_without_constants);
420
420
421
421
/* Extract results. */
422
- if (auto callback_op = cast<const CallbackOperator>(&context. plan )) {
422
+ if (auto callback_op = cast<const CallbackOperator>(&root_op )) {
423
423
auto loader = Interpreter::compile_load (deduplicated_schema_without_constants, result_set, layout,
424
424
deduplicated_schema_without_constants);
425
425
if (schema.num_entries () == deduplicated_schema.num_entries ()) {
@@ -468,7 +468,7 @@ void m::wasm::detail::read_result_set(const v8::FunctionCallbackInfo<v8::Value>
468
468
callback_op->callback ()(schema, tup_dupl);
469
469
}
470
470
}
471
- } else if (auto print_op = cast<const PrintOperator>(&context. plan )) {
471
+ } else if (auto print_op = cast<const PrintOperator>(&root_op )) {
472
472
/* Compute a `Tuple` with duplicates and constants. */
473
473
Tuple tup (deduplicated_schema_without_constants);
474
474
Tuple *args[] = { &tup };
@@ -599,12 +599,7 @@ struct CollectStringLiterals : ConstOperatorVisitor, ast::ConstASTExprVisitor
599
599
* V8Engine implementation
600
600
*====================================================================================================================*/
601
601
602
- V8Engine::V8Engine ()
603
- {
604
- register_wasm_operators (*phys_opt_);
605
-
606
- initialize ();
607
- }
602
+ V8Engine::V8Engine () { initialize (); }
608
603
609
604
V8Engine::~V8Engine ()
610
605
{
@@ -661,24 +656,27 @@ void V8Engine::initialize()
661
656
isolate_ = v8::Isolate::New (create_params);
662
657
}
663
658
664
- void V8Engine::compile (const Operator &plan) const
659
+ void V8Engine::compile (const MatchBase &plan) const
665
660
{
666
661
#if 1
667
662
/* ----- Add print function. --------------------------------------------------------------------------------------*/
668
663
Module::Get ().emit_function_import <void (uint32_t )>(" print" );
669
664
#endif
670
665
666
+ /* ----- Emit code for run function which computes the last pipeline and calls other pipeline functions. ----------*/
667
+ FUNCTION (run, void (void ))
668
+ {
669
+ auto S = CodeGenContext::Get ().scoped_environment (); // create scoped environment for this function
670
+ plan.execute (setup_t::Make_Without_Parent (), pipeline_t (), teardown_t::Make_Without_Parent ()); // emit code
671
+ }
672
+
671
673
/* ----- Create function `main` which executes the given query. ---------------------------------------------------*/
672
674
m::wasm::Function<uint32_t (uint32_t )> main (" main" );
673
675
BLOCK_OPEN (main.body ())
674
676
{
675
677
auto S = CodeGenContext::Get ().scoped_environment (); // create scoped environment for this function
676
-
677
- /* ----- Compile plan. ----------------------------------------------------------------------------------------*/
678
- phys_opt_->execute (); // emit code
679
-
680
- /* ----- Return size of result set. ---------------------------------------------------------------------------*/
681
- main.emit_return (CodeGenContext::Get ().num_tuples ());
678
+ run (); // call run function
679
+ main.emit_return (CodeGenContext::Get ().num_tuples ()); // return size of result set
682
680
}
683
681
684
682
/* ----- Export main. ---------------------------------------------------------------------------------------------*/
@@ -719,21 +717,12 @@ void V8Engine::compile(const Operator &plan) const
719
717
#endif
720
718
}
721
719
722
- void V8Engine::execute (const Operator &plan)
720
+ void V8Engine::execute (const MatchBase &plan)
723
721
{
724
- Module::Init ();
725
- CodeGenContext::Init (); // fresh context
726
-
727
722
Catalog &C = Catalog::Get ();
728
723
729
- M_TIME_EXPR (phys_opt_->cover (plan), " Compute optimal physical operator covering" , C.timer ());
730
- if (Options::Get ().physplan ) phys_opt_->dump_plan ();
731
- if (Options::Get ().physplandot ) {
732
- Diagnostic diag (Options::Get ().has_color , std::cout, std::cerr);
733
- DotTool dot (diag);
734
- phys_opt_->dot_plan (dot.stream ());
735
- dot.show (" physical_plan" , true );
736
- }
724
+ Module::Init ();
725
+ CodeGenContext::Init (); // fresh context
737
726
738
727
M_insist (bool (isolate_), " must have an isolate" );
739
728
v8::Locker locker (isolate_);
@@ -755,7 +744,7 @@ void V8Engine::execute(const Operator &plan)
755
744
WasmContext::config_t wasm_config{0 };
756
745
if (options::cdt_port < 1024 )
757
746
wasm_config |= WasmContext::TRAP_GUARD_PAGES;
758
- auto &wasm_context = Create_Wasm_Context_For_ID (Module::ID (), wasm_config, plan );
747
+ auto &wasm_context = Create_Wasm_Context_For_ID (Module::ID (), plan, wasm_config );
759
748
760
749
auto imports = v8::Object::New (isolate_);
761
750
auto env = create_env (*isolate_, plan);
@@ -795,10 +784,11 @@ void V8Engine::execute(const Operator &plan)
795
784
" Execute machine code" , C.timer ());
796
785
797
786
/* Print total number of result tuples. */
798
- if (auto print_op = cast<const PrintOperator>(&plan)) {
787
+ auto &root_op = plan.get_matched_singleton ();
788
+ if (auto print_op = cast<const PrintOperator>(&root_op)) {
799
789
if (not Options::Get ().quiet )
800
790
print_op->out << num_rows << " rows\n " ;
801
- } else if (auto noop_op = cast<const NoOpOperator>(&plan )) {
791
+ } else if (auto noop_op = cast<const NoOpOperator>(&root_op )) {
802
792
if (not Options::Get ().quiet )
803
793
noop_op->out << num_rows << " rows\n " ;
804
794
}
@@ -905,7 +895,7 @@ v8::Local<v8::WasmModuleObject> m::wasm::detail::instantiate(v8::Isolate &isolat
905
895
->CallAsConstructor (Ctx, 2 , instance_args).ToLocalChecked ().As <v8::WasmModuleObject>();
906
896
}
907
897
908
- v8::Local<v8::Object> m::wasm::detail::create_env (v8::Isolate &isolate, const Operator &plan)
898
+ v8::Local<v8::Object> m::wasm::detail::create_env (v8::Isolate &isolate, const MatchBase &plan)
909
899
{
910
900
auto &context = WasmEngine::Get_Wasm_Context_By_ID (Module::ID ());
911
901
auto Ctx = isolate.GetCurrentContext ();
@@ -931,7 +921,7 @@ v8::Local<v8::Object> m::wasm::detail::create_env(v8::Isolate &isolate, const Op
931
921
932
922
/* Map all string literals into the Wasm module. */
933
923
M_insist (Is_Page_Aligned (context.heap ));
934
- auto literals = CollectStringLiterals::Collect (plan);
924
+ auto literals = CollectStringLiterals::Collect (plan. get_matched_singleton () );
935
925
std::size_t bytes = 0 ;
936
926
for (auto literal : literals)
937
927
bytes += strlen (literal) + 1 ;
0 commit comments