diff --git a/runtime/vm/compiler/backend/il_test_helper.cc b/runtime/vm/compiler/backend/il_test_helper.cc index 9523ad859c4..df48df42844 100644 --- a/runtime/vm/compiler/backend/il_test_helper.cc +++ b/runtime/vm/compiler/backend/il_test_helper.cc @@ -92,6 +92,25 @@ ObjectPtr Invoke(const Library& lib, const char* name) { return Api::UnwrapHandle(result); } +InstructionsPtr BuildInstructions( + std::function fun) { + auto thread = Thread::Current(); + compiler::Assembler assembler(nullptr); + + fun(&assembler); + + auto& code = Code::Handle(); + auto install_code_fun = [&] { + code = Code::FinalizeCode(nullptr, &assembler, + Code::PoolAttachment::kNotAttachPool, + /*optimized=*/false, /*stats=*/nullptr); + }; + SafepointWriteRwLocker ml(thread, thread->isolate_group()->program_lock()); + thread->isolate_group()->RunWithStoppedMutators(install_code_fun, + /*use_force_growth=*/true); + return code.instructions(); +} + FlowGraph* TestPipeline::RunPasses( std::initializer_list passes) { auto thread = Thread::Current(); @@ -144,11 +163,29 @@ FlowGraph* TestPipeline::RunPasses( } else { flow_graph_ = CompilerPass::RunPipeline(mode_, pass_state_); } + pass_state_->call_specializer = nullptr; } return flow_graph_; } +void TestPipeline::RunAdditionalPasses( + std::initializer_list passes) { + SpeculativeInliningPolicy speculative_policy(/*enable_suppression=*/false); + + JitCallSpecializer jit_call_specializer(flow_graph_, &speculative_policy); + AotCallSpecializer aot_call_specializer(/*precompiler=*/nullptr, flow_graph_, + &speculative_policy); + if (mode_ == CompilerPass::kAOT) { + pass_state_->call_specializer = &aot_call_specializer; + } else { + pass_state_->call_specializer = &jit_call_specializer; + } + + flow_graph_ = CompilerPass::RunPipelineWithPasses(pass_state_, passes); + pass_state_->call_specializer = nullptr; +} + void TestPipeline::CompileGraphAndAttachFunction() { Zone* zone = thread_->zone(); const bool optimized = true; diff --git a/runtime/vm/compiler/backend/il_test_helper.h b/runtime/vm/compiler/backend/il_test_helper.h index 73f32bf89bb..babe42728c3 100644 --- a/runtime/vm/compiler/backend/il_test_helper.h +++ b/runtime/vm/compiler/backend/il_test_helper.h @@ -65,6 +65,9 @@ TypeParameterPtr GetFunctionTypeParameter(const Function& fun, intptr_t index); ObjectPtr Invoke(const Library& lib, const char* name); +InstructionsPtr BuildInstructions( + std::function fun); + class TestPipeline : public ValueObject { public: explicit TestPipeline(const Function& function, @@ -86,6 +89,8 @@ class TestPipeline : public ValueObject { // - [flow_graph_] FlowGraph* RunPasses(std::initializer_list passes); + void RunAdditionalPasses(std::initializer_list passes); + void CompileGraphAndAttachFunction(); private: