[vm] Add some helper methods to il_test_helper.h

These helpers will allow building a graph, modifying it and runnign more
compiler passes on them as well as easily building assembly stubs for
testing purposes.

TEST=Adds test helpers

Change-Id: I3bfef21e1370a7c99c9bbbe4f123211f6d9fe964
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/233781
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
This commit is contained in:
Martin Kustermann
2022-02-21 10:56:15 +00:00
committed by Commit Bot
parent de1c206e98
commit bbe065b817
2 changed files with 42 additions and 0 deletions
@@ -92,6 +92,25 @@ ObjectPtr Invoke(const Library& lib, const char* name) {
return Api::UnwrapHandle(result);
}
InstructionsPtr BuildInstructions(
std::function<void(compiler::Assembler* assembler)> 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<CompilerPass::Id> 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<CompilerPass::Id> 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;
@@ -65,6 +65,9 @@ TypeParameterPtr GetFunctionTypeParameter(const Function& fun, intptr_t index);
ObjectPtr Invoke(const Library& lib, const char* name);
InstructionsPtr BuildInstructions(
std::function<void(compiler::Assembler* assembler)> 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<CompilerPass::Id> passes);
void RunAdditionalPasses(std::initializer_list<CompilerPass::Id> passes);
void CompileGraphAndAttachFunction();
private: