Commit b9af6604 authored by Leszek Swirski's avatar Leszek Swirski Committed by V8 LUCI CQ

[maglev] Allow graph building to bail out

Start allowing heavier testing of maglev by allowing graph building to
bail out if passed an unsupported bytecode.

Bug: v8:7700
Change-Id: I7e3d2c5a8896d4f4e0da5ef444c95a286f9ac117
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3500417Reviewed-by: 's avatarVictor Gomes <victorgomes@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Auto-Submit: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/main@{#79371}
parent 5704f86c
......@@ -309,7 +309,7 @@ class MaglevCodeGeneratingNodeProcessor {
class MaglevCodeGeneratorImpl final {
public:
static Handle<Code> Generate(MaglevCompilationUnit* compilation_unit,
static MaybeHandle<Code> Generate(MaglevCompilationUnit* compilation_unit,
Graph* graph) {
return MaglevCodeGeneratorImpl(compilation_unit, graph).Generate();
}
......@@ -321,7 +321,7 @@ class MaglevCodeGeneratorImpl final {
processor_(compilation_unit, &code_gen_state_),
graph_(graph) {}
Handle<Code> Generate() {
MaybeHandle<Code> Generate() {
EmitCode();
EmitMetadata();
return BuildCodeObject();
......@@ -337,14 +337,14 @@ class MaglevCodeGeneratorImpl final {
stack_slot_count_with_fixed_frame());
}
Handle<Code> BuildCodeObject() {
MaybeHandle<Code> BuildCodeObject() {
CodeDesc desc;
static constexpr int kNoHandlerTableOffset = 0;
masm()->GetCode(isolate(), &desc, safepoint_table_builder(),
kNoHandlerTableOffset);
return Factory::CodeBuilder{isolate(), desc, CodeKind::MAGLEV}
.set_stack_slots(stack_slot_count_with_fixed_frame())
.Build();
.TryBuild();
}
int stack_slot_count() const { return code_gen_state_.vreg_slots(); }
......@@ -367,7 +367,7 @@ class MaglevCodeGeneratorImpl final {
};
// static
Handle<Code> MaglevCodeGenerator::Generate(
MaybeHandle<Code> MaglevCodeGenerator::Generate(
MaglevCompilationUnit* compilation_unit, Graph* graph) {
return MaglevCodeGeneratorImpl::Generate(compilation_unit, graph);
}
......
......@@ -16,7 +16,7 @@ struct MaglevCompilationUnit;
class MaglevCodeGenerator : public AllStatic {
public:
static Handle<Code> Generate(MaglevCompilationUnit* compilation_unit,
static MaybeHandle<Code> Generate(MaglevCompilationUnit* compilation_unit,
Graph* graph);
};
......
......@@ -131,7 +131,7 @@ MaglevCompiler::MaglevCompiler(compiler::JSHeapBroker* broker,
: compilation_data_(broker),
toplevel_compilation_unit_(&compilation_data_, function) {}
Handle<Code> MaglevCompiler::Compile() {
MaybeHandle<Code> MaglevCompiler::Compile() {
// Build graph.
if (FLAG_print_maglev_code || FLAG_code_comments || FLAG_print_maglev_graph ||
FLAG_trace_maglev_regalloc) {
......@@ -142,6 +142,11 @@ Handle<Code> MaglevCompiler::Compile() {
graph_builder.Build();
// TODO(v8:7700): Clean up after all bytecodes are supported.
if (graph_builder.found_unsupported_bytecode()) {
return {};
}
if (FLAG_print_maglev_graph) {
std::cout << "After graph buiding" << std::endl;
PrintGraph(std::cout, &toplevel_compilation_unit_, graph_builder.graph());
......@@ -167,8 +172,13 @@ Handle<Code> MaglevCompiler::Compile() {
PrintGraph(std::cout, &toplevel_compilation_unit_, graph_builder.graph());
}
Handle<Code> code = MaglevCodeGenerator::Generate(&toplevel_compilation_unit_,
graph_builder.graph());
Handle<Code> code;
if (!MaglevCodeGenerator::Generate(&toplevel_compilation_unit_,
graph_builder.graph())
.ToHandle(&code)) {
return {};
}
const bool deps_committed_successfully =
broker()->dependencies()->Commit(code);
......
......@@ -24,7 +24,7 @@ class MaglevCompiler {
explicit MaglevCompiler(compiler::JSHeapBroker* broker,
Handle<JSFunction> function);
Handle<Code> Compile();
MaybeHandle<Code> Compile();
compiler::JSHeapBroker* broker() const { return compilation_data_.broker; }
Zone* zone() { return &compilation_data_.zone; }
......
This diff is collapsed.
......@@ -111,11 +111,18 @@ class MaglevGraphBuilder {
void Build() {
for (iterator_.Reset(); !iterator_.done(); iterator_.Advance()) {
VisitSingleBytecode();
// TODO(v8:7700): Clean up after all bytecodes are supported.
if (found_unsupported_bytecode()) break;
}
}
Graph* graph() { return &graph_; }
// TODO(v8:7700): Clean up after all bytecodes are supported.
bool found_unsupported_bytecode() const {
return found_unsupported_bytecode_;
}
private:
BasicBlock* CreateEmptyBlock(int offset, BasicBlock* predecessor) {
DCHECK_NULL(current_block_);
......@@ -425,6 +432,12 @@ class MaglevGraphBuilder {
Graph graph_;
InterpreterFrameState current_interpreter_frame_;
// Allow marking some bytecodes as unsupported during graph building, so that
// we can test maglev incrementally.
// TODO(v8:7700): Clean up after all bytecodes are supported.
bool found_unsupported_bytecode_ = false;
bool this_field_will_be_unused_once_all_bytecodes_are_supported_;
};
} // namespace maglev
......
......@@ -284,6 +284,17 @@ inline Handle<CodeT> ToCodeT(Handle<Code> code, Isolate* isolate) {
#endif
}
inline MaybeHandle<CodeT> ToCodeT(MaybeHandle<Code> maybe_code,
Isolate* isolate) {
#ifdef V8_EXTERNAL_CODE_SPACE
Handle<Code> code;
if (maybe_code.ToHandle(&code)) return ToCodeT(code, isolate);
return {};
#else
return maybe_code;
#endif
}
inline Code FromCodeT(CodeT code) {
#ifdef V8_EXTERNAL_CODE_SPACE
return code.code();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment