Commit 2681ec65 authored by Maya Lekova's avatar Maya Lekova Committed by Commit Bot

[turbofan] Introduce serializer for background compilation phase

Design doc:
https://docs.google.com/document/d/1vCQYhtFPqXafSMweSnGD8l0TKEIB6cPV5UGMHJtpy8k/edit?ts=5bf7d341

This CL only introduces a skeleton of the new phase that implements a bytecode
walker. The SUPPORTED_BYTECODE_LIST is supposed to be filled in gradually.

Bug:v8:7790

R=jarin@chromium.org, neis@chromium.org

Change-Id: I57fea91c55dca888581f2490bdf7b831fc61eda4
Reviewed-on: https://chromium-review.googlesource.com/c/1386872Reviewed-by: 's avatarGeorg Neis <neis@chromium.org>
Reviewed-by: 's avatarJaroslav Sevcik <jarin@chromium.org>
Commit-Queue: Maya Lekova <mslekova@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58582}
parent 3b6efcdc
......@@ -1902,6 +1902,8 @@ v8_source_set("v8_base") {
"src/compiler/scheduler.h",
"src/compiler/select-lowering.cc",
"src/compiler/select-lowering.h",
"src/compiler/serializer-for-background-compilation.cc",
"src/compiler/serializer-for-background-compilation.h",
"src/compiler/simd-scalar-lowering.cc",
"src/compiler/simd-scalar-lowering.h",
"src/compiler/simplified-lowering.cc",
......
......@@ -870,7 +870,7 @@ void BytecodeGraphBuilder::VisitSingleBytecode(
Visit##name(); \
break;
BYTECODE_LIST(BYTECODE_CASE)
#undef BYTECODE_CODE
#undef BYTECODE_CASE
}
}
}
......
......@@ -64,6 +64,7 @@
#include "src/compiler/schedule.h"
#include "src/compiler/scheduler.h"
#include "src/compiler/select-lowering.h"
#include "src/compiler/serializer-for-background-compilation.h"
#include "src/compiler/simplified-lowering.h"
#include "src/compiler/simplified-operator-reducer.h"
#include "src/compiler/simplified-operator.h"
......@@ -1201,6 +1202,19 @@ struct CopyMetadataForConcurrentCompilePhase {
}
};
// TODO(turbofan): Move all calls from CopyMetaDataForConcurrentCompilePhase
// here. Also all the calls to Serialize* methods that are currently sprinkled
// over inlining will move here as well.
struct SerializationPhase {
static const char* phase_name() { return "serialize bytecode"; }
void Run(PipelineData* data, Zone* temp_zone) {
SerializerForBackgroundCompilation serializer(data->broker(), temp_zone,
data->info()->closure());
serializer.Run();
}
};
struct TypedLoweringPhase {
static const char* phase_name() { return "typed lowering"; }
......@@ -1903,17 +1917,21 @@ bool PipelineImpl::CreateGraph() {
data->node_origins()->AddDecorator();
}
Run<GraphBuilderPhase>();
RunPrintAndVerify(GraphBuilderPhase::phase_name(), true);
if (FLAG_concurrent_inlining) {
data->broker()->StartSerializing();
Run<SerializeStandardObjectsPhase>();
Run<CopyMetadataForConcurrentCompilePhase>();
Run<SerializationPhase>();
} else {
data->broker()->SetNativeContextRef();
}
Run<GraphBuilderPhase>();
RunPrintAndVerify(GraphBuilderPhase::phase_name(), true);
if (FLAG_concurrent_inlining) {
Run<CopyMetadataForConcurrentCompilePhase>();
}
// Perform function context specialization and inlining (if enabled).
Run<InliningPhase>();
RunPrintAndVerify(InliningPhase::phase_name(), true);
......
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/compiler/serializer-for-background-compilation.h"
#include "src/compiler/js-heap-broker.h"
#include "src/handles-inl.h"
#include "src/interpreter/bytecode-array-iterator.h"
#include "src/objects/code.h"
#include "src/objects/shared-function-info-inl.h"
#include "src/zone/zone.h"
namespace v8 {
namespace internal {
namespace compiler {
class SerializerForBackgroundCompilation::Environment : public ZoneObject {
public:
explicit Environment(Zone* zone, Isolate* isolate,
MaybeHandle<JSFunction> closure);
private:
Zone* zone() const { return zone_; }
Zone* zone_;
MaybeHandle<JSFunction> closure_;
};
SerializerForBackgroundCompilation::Environment::Environment(
Zone* zone, Isolate* isolate, MaybeHandle<JSFunction> closure)
: zone_(zone), closure_(closure) {
USE(isolate);
}
SerializerForBackgroundCompilation::SerializerForBackgroundCompilation(
JSHeapBroker* broker, Zone* zone, Handle<JSFunction> closure)
: broker_(broker),
zone_(zone),
environment_(new (zone) Environment(zone, broker_->isolate(), closure)),
closure_(closure),
bytecode_array_(
handle(closure->shared()->GetBytecodeArray(), broker->isolate())) {}
void SerializerForBackgroundCompilation::Run() { TraverseBytecode(); }
void SerializerForBackgroundCompilation::TraverseBytecode() {
interpreter::BytecodeArrayIterator bytecode_iterator(bytecode_array());
for (; !bytecode_iterator.done(); bytecode_iterator.Advance()) {
switch (bytecode_iterator.current_bytecode()) {
#define DEFINE_BYTECODE_CASE(name) \
case interpreter::Bytecode::k##name: \
Visit##name(); \
break;
SUPPORTED_BYTECODE_LIST(DEFINE_BYTECODE_CASE)
#undef DEFINE_BYTECODE_CASE
default:
break;
}
}
}
void SerializerForBackgroundCompilation::VisitIllegal() {}
} // namespace compiler
} // namespace internal
} // namespace v8
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_COMPILER_SERIALIZER_FOR_BACKGROUND_COMPILATION_H_
#define V8_COMPILER_SERIALIZER_FOR_BACKGROUND_COMPILATION_H_
#include "src/handles.h"
namespace v8 {
namespace internal {
namespace interpreter {
class BytecodeArrayIterator;
}
class FeedbackVector;
class SharedFunctionInfo;
class BytecodeArray;
class SourcePositionTableIterator;
class Zone;
namespace compiler {
#define SUPPORTED_BYTECODE_LIST(V) V(Illegal)
class JSHeapBroker;
// The SerializerForBackgroundCompilation makes sure that the relevant function
// data such as bytecode, SharedFunctionInfo and FeedbackVector, used by later
// optimizations in the compiler, is copied to the heap broker.
class SerializerForBackgroundCompilation {
public:
explicit SerializerForBackgroundCompilation(JSHeapBroker* broker, Zone* zone,
Handle<JSFunction> closure);
void Run();
Zone* zone() const { return zone_; }
const Handle<BytecodeArray>& bytecode_array() const {
return bytecode_array_;
}
private:
class Environment;
void TraverseBytecode();
#define DECLARE_VISIT_BYTECODE(name, ...) void Visit##name();
SUPPORTED_BYTECODE_LIST(DECLARE_VISIT_BYTECODE)
#undef DECLARE_VISIT_BYTECODE
JSHeapBroker* broker() { return broker_; }
Environment* environment() { return environment_; }
JSHeapBroker* broker_;
Zone* zone_;
Environment* environment_;
Handle<JSFunction> closure_;
Handle<BytecodeArray> bytecode_array_;
};
} // namespace compiler
} // namespace internal
} // namespace v8
#endif // V8_COMPILER_SERIALIZER_FOR_BACKGROUND_COMPILATION_H_
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