Commit 44b291d0 authored by Leszek Swirski's avatar Leszek Swirski Committed by Commit Bot

[compiler] Move OSR entry point calculation into bytecode analysis

Instead of calculating the OSR entry point both in the bytecode analysis
and in the bytecode graph builder, calculate it once in the analysis and
use that calculation in the graph builder.

Old TODO from https://codereview.chromium.org/2558093005.

Change-Id: I071bc622beb55dc5eddaee25ef28e21fc4b477f0
Reviewed-on: https://chromium-review.googlesource.com/485899
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44888}
parent e7bb85dc
...@@ -90,6 +90,7 @@ BytecodeAnalysis::BytecodeAnalysis(Handle<BytecodeArray> bytecode_array, ...@@ -90,6 +90,7 @@ BytecodeAnalysis::BytecodeAnalysis(Handle<BytecodeArray> bytecode_array,
loop_end_index_queue_(zone), loop_end_index_queue_(zone),
end_to_header_(zone), end_to_header_(zone),
header_to_info_(zone), header_to_info_(zone),
osr_entry_point_(-1),
liveness_map_(bytecode_array->length(), zone) {} liveness_map_(bytecode_array->length(), zone) {}
namespace { namespace {
...@@ -256,7 +257,8 @@ void BytecodeAnalysis::Analyze(BailoutId osr_bailout_id) { ...@@ -256,7 +257,8 @@ void BytecodeAnalysis::Analyze(BailoutId osr_bailout_id) {
// Every byte up to and including the last byte within the backwards jump // Every byte up to and including the last byte within the backwards jump
// instruction is considered part of the loop, set loop end accordingly. // instruction is considered part of the loop, set loop end accordingly.
int loop_end = current_offset + iterator.current_bytecode_size(); int loop_end = current_offset + iterator.current_bytecode_size();
PushLoop(iterator.GetJumpTargetOffset(), loop_end); int loop_header = iterator.GetJumpTargetOffset();
PushLoop(loop_header, loop_end);
// Normally prefixed bytecodes are treated as if the prefix's offset was // Normally prefixed bytecodes are treated as if the prefix's offset was
// the actual bytecode's offset. However, the OSR id is the offset of the // the actual bytecode's offset. However, the OSR id is the offset of the
...@@ -270,9 +272,10 @@ void BytecodeAnalysis::Analyze(BailoutId osr_bailout_id) { ...@@ -270,9 +272,10 @@ void BytecodeAnalysis::Analyze(BailoutId osr_bailout_id) {
DCHECK(!is_osr_loop || DCHECK(!is_osr_loop ||
iterator.OffsetWithinBytecode(osr_loop_end_offset)); iterator.OffsetWithinBytecode(osr_loop_end_offset));
// OSR "assigns" everything to OSR values on entry into an OSR loop, so we
// need to make sure to considered everything to be assigned.
if (is_osr_loop) { if (is_osr_loop) {
osr_entry_point_ = loop_header;
// OSR "assigns" everything to OSR values on entry into an OSR loop, so
// we need to make sure to considered everything to be assigned.
loop_stack_.top().loop_info->assignments().AddAll(); loop_stack_.top().loop_info->assignments().AddAll();
} }
......
...@@ -80,6 +80,11 @@ class V8_EXPORT_PRIVATE BytecodeAnalysis BASE_EMBEDDED { ...@@ -80,6 +80,11 @@ class V8_EXPORT_PRIVATE BytecodeAnalysis BASE_EMBEDDED {
// Get the loop info of the loop header at {header_offset}. // Get the loop info of the loop header at {header_offset}.
const LoopInfo& GetLoopInfoFor(int header_offset) const; const LoopInfo& GetLoopInfoFor(int header_offset) const;
// True if the current analysis has an OSR entry point.
bool HasOSREntryPoint() const { return osr_entry_point_ != -1; }
// True if {offset} is the OSR entry loop header.
bool IsOSREntryPoint(int offset) const { return osr_entry_point_ == offset; }
// Gets the in-liveness for the bytecode at {offset}. // Gets the in-liveness for the bytecode at {offset}.
const BytecodeLivenessState* GetInLivenessFor(int offset) const; const BytecodeLivenessState* GetInLivenessFor(int offset) const;
...@@ -113,6 +118,7 @@ class V8_EXPORT_PRIVATE BytecodeAnalysis BASE_EMBEDDED { ...@@ -113,6 +118,7 @@ class V8_EXPORT_PRIVATE BytecodeAnalysis BASE_EMBEDDED {
ZoneMap<int, int> end_to_header_; ZoneMap<int, int> end_to_header_;
ZoneMap<int, LoopInfo> header_to_info_; ZoneMap<int, LoopInfo> header_to_info_;
int osr_entry_point_;
BytecodeLivenessMap liveness_map_; BytecodeLivenessMap liveness_map_;
......
...@@ -475,7 +475,6 @@ BytecodeGraphBuilder::BytecodeGraphBuilder( ...@@ -475,7 +475,6 @@ BytecodeGraphBuilder::BytecodeGraphBuilder(
bytecode_analysis_(nullptr), bytecode_analysis_(nullptr),
environment_(nullptr), environment_(nullptr),
osr_ast_id_(osr_ast_id), osr_ast_id_(osr_ast_id),
osr_loop_offset_(-1),
merge_environments_(local_zone), merge_environments_(local_zone),
exception_handlers_(local_zone), exception_handlers_(local_zone),
current_exception_handler_(0), current_exception_handler_(0),
...@@ -2380,7 +2379,7 @@ void BytecodeGraphBuilder::MergeControlToLeaveFunction(Node* exit) { ...@@ -2380,7 +2379,7 @@ void BytecodeGraphBuilder::MergeControlToLeaveFunction(Node* exit) {
void BytecodeGraphBuilder::BuildOSRLoopEntryPoint(int current_offset) { void BytecodeGraphBuilder::BuildOSRLoopEntryPoint(int current_offset) {
DCHECK(bytecode_analysis()->IsLoopHeader(current_offset)); DCHECK(bytecode_analysis()->IsLoopHeader(current_offset));
if (!osr_ast_id_.IsNone() && osr_loop_offset_ == current_offset) { if (bytecode_analysis()->IsOSREntryPoint(current_offset)) {
// For OSR add a special {OsrLoopEntry} node into the current loop header. // For OSR add a special {OsrLoopEntry} node into the current loop header.
// It will be turned into a usable entry by the OSR deconstruction. // It will be turned into a usable entry by the OSR deconstruction.
Environment* osr_env = environment()->Copy(); Environment* osr_env = environment()->Copy();
...@@ -2390,15 +2389,10 @@ void BytecodeGraphBuilder::BuildOSRLoopEntryPoint(int current_offset) { ...@@ -2390,15 +2389,10 @@ void BytecodeGraphBuilder::BuildOSRLoopEntryPoint(int current_offset) {
} }
void BytecodeGraphBuilder::BuildOSRNormalEntryPoint() { void BytecodeGraphBuilder::BuildOSRNormalEntryPoint() {
if (!osr_ast_id_.IsNone()) { if (bytecode_analysis()->HasOSREntryPoint()) {
// For OSR add an {OsrNormalEntry} as the the top-level environment start. // For OSR add an {OsrNormalEntry} as the the top-level environment start.
// It will be replaced with {Dead} by the OSR deconstruction. // It will be replaced with {Dead} by the OSR deconstruction.
NewNode(common()->OsrNormalEntry()); NewNode(common()->OsrNormalEntry());
// Translate the offset of the jump instruction to the jump target offset of
// that instruction so that the derived BailoutId points to the loop header.
osr_loop_offset_ =
bytecode_analysis()->GetLoopOffsetFor(osr_ast_id_.ToInt());
DCHECK(bytecode_analysis()->IsLoopHeader(osr_loop_offset_));
} }
} }
...@@ -2545,7 +2539,7 @@ Node* BytecodeGraphBuilder::TryBuildSimplifiedLoadNamed(const Operator* op, ...@@ -2545,7 +2539,7 @@ Node* BytecodeGraphBuilder::TryBuildSimplifiedLoadNamed(const Operator* op,
// TODO(mstarzinger,6112): This is a workaround for OSR loop entries being // TODO(mstarzinger,6112): This is a workaround for OSR loop entries being
// pruned from the graph by a soft-deopt. It can happen that a LoadIC that // pruned from the graph by a soft-deopt. It can happen that a LoadIC that
// control-dominates the OSR entry is still in "uninitialized" state. // control-dominates the OSR entry is still in "uninitialized" state.
if (!osr_ast_id_.IsNone()) return nullptr; if (bytecode_analysis()->HasOSREntryPoint()) return nullptr;
Node* effect = environment()->GetEffectDependency(); Node* effect = environment()->GetEffectDependency();
Node* control = environment()->GetControlDependency(); Node* control = environment()->GetControlDependency();
Reduction early_reduction = type_hint_lowering().ReduceLoadNamedOperation( Reduction early_reduction = type_hint_lowering().ReduceLoadNamedOperation(
...@@ -2564,7 +2558,7 @@ Node* BytecodeGraphBuilder::TryBuildSimplifiedLoadKeyed(const Operator* op, ...@@ -2564,7 +2558,7 @@ Node* BytecodeGraphBuilder::TryBuildSimplifiedLoadKeyed(const Operator* op,
// TODO(mstarzinger,6112): This is a workaround for OSR loop entries being // TODO(mstarzinger,6112): This is a workaround for OSR loop entries being
// pruned from the graph by a soft-deopt. It can happen that a LoadIC that // pruned from the graph by a soft-deopt. It can happen that a LoadIC that
// control-dominates the OSR entry is still in "uninitialized" state. // control-dominates the OSR entry is still in "uninitialized" state.
if (!osr_ast_id_.IsNone()) return nullptr; if (bytecode_analysis()->HasOSREntryPoint()) return nullptr;
Node* effect = environment()->GetEffectDependency(); Node* effect = environment()->GetEffectDependency();
Node* control = environment()->GetControlDependency(); Node* control = environment()->GetControlDependency();
Reduction early_reduction = type_hint_lowering().ReduceLoadKeyedOperation( Reduction early_reduction = type_hint_lowering().ReduceLoadKeyedOperation(
...@@ -2583,7 +2577,7 @@ Node* BytecodeGraphBuilder::TryBuildSimplifiedStoreNamed(const Operator* op, ...@@ -2583,7 +2577,7 @@ Node* BytecodeGraphBuilder::TryBuildSimplifiedStoreNamed(const Operator* op,
// TODO(mstarzinger,6112): This is a workaround for OSR loop entries being // TODO(mstarzinger,6112): This is a workaround for OSR loop entries being
// pruned from the graph by a soft-deopt. It can happen that a LoadIC that // pruned from the graph by a soft-deopt. It can happen that a LoadIC that
// control-dominates the OSR entry is still in "uninitialized" state. // control-dominates the OSR entry is still in "uninitialized" state.
if (!osr_ast_id_.IsNone()) return nullptr; if (bytecode_analysis()->HasOSREntryPoint()) return nullptr;
Node* effect = environment()->GetEffectDependency(); Node* effect = environment()->GetEffectDependency();
Node* control = environment()->GetControlDependency(); Node* control = environment()->GetControlDependency();
Reduction early_reduction = type_hint_lowering().ReduceStoreNamedOperation( Reduction early_reduction = type_hint_lowering().ReduceStoreNamedOperation(
...@@ -2602,7 +2596,7 @@ Node* BytecodeGraphBuilder::TryBuildSimplifiedStoreKeyed(const Operator* op, ...@@ -2602,7 +2596,7 @@ Node* BytecodeGraphBuilder::TryBuildSimplifiedStoreKeyed(const Operator* op,
// TODO(mstarzinger,6112): This is a workaround for OSR loop entries being // TODO(mstarzinger,6112): This is a workaround for OSR loop entries being
// pruned from the graph by a soft-deopt. It can happen that a LoadIC that // pruned from the graph by a soft-deopt. It can happen that a LoadIC that
// control-dominates the OSR entry is still in "uninitialized" state. // control-dominates the OSR entry is still in "uninitialized" state.
if (!osr_ast_id_.IsNone()) return nullptr; if (bytecode_analysis()->HasOSREntryPoint()) return nullptr;
Node* effect = environment()->GetEffectDependency(); Node* effect = environment()->GetEffectDependency();
Node* control = environment()->GetControlDependency(); Node* control = environment()->GetControlDependency();
Reduction early_reduction = type_hint_lowering().ReduceStoreKeyedOperation( Reduction early_reduction = type_hint_lowering().ReduceStoreKeyedOperation(
......
...@@ -325,7 +325,6 @@ class BytecodeGraphBuilder { ...@@ -325,7 +325,6 @@ class BytecodeGraphBuilder {
const BytecodeAnalysis* bytecode_analysis_; const BytecodeAnalysis* bytecode_analysis_;
Environment* environment_; Environment* environment_;
BailoutId osr_ast_id_; BailoutId osr_ast_id_;
int osr_loop_offset_;
// Merge environments are snapshots of the environment at points where the // Merge environments are snapshots of the environment at points where the
// control flow merges. This models a forward data flow propagation of all // control flow merges. This models a forward data flow propagation of all
......
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