diff --git a/src/compiler/bytecode-analysis.cc b/src/compiler/bytecode-analysis.cc index 6d8afe1744..92896be822 100644 --- a/src/compiler/bytecode-analysis.cc +++ b/src/compiler/bytecode-analysis.cc @@ -90,6 +90,7 @@ BytecodeAnalysis::BytecodeAnalysis(Handle bytecode_array, loop_end_index_queue_(zone), end_to_header_(zone), header_to_info_(zone), + osr_entry_point_(-1), liveness_map_(bytecode_array->length(), zone) {} namespace { @@ -256,7 +257,8 @@ void BytecodeAnalysis::Analyze(BailoutId osr_bailout_id) { // Every byte up to and including the last byte within the backwards jump // instruction is considered part of the loop, set loop end accordingly. 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 // 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) { DCHECK(!is_osr_loop || 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) { + 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(); } diff --git a/src/compiler/bytecode-analysis.h b/src/compiler/bytecode-analysis.h index ad93f8a652..63dfa3107c 100644 --- a/src/compiler/bytecode-analysis.h +++ b/src/compiler/bytecode-analysis.h @@ -80,6 +80,11 @@ class V8_EXPORT_PRIVATE BytecodeAnalysis BASE_EMBEDDED { // Get the loop info of the loop header at {header_offset}. 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}. const BytecodeLivenessState* GetInLivenessFor(int offset) const; @@ -113,6 +118,7 @@ class V8_EXPORT_PRIVATE BytecodeAnalysis BASE_EMBEDDED { ZoneMap end_to_header_; ZoneMap header_to_info_; + int osr_entry_point_; BytecodeLivenessMap liveness_map_; diff --git a/src/compiler/bytecode-graph-builder.cc b/src/compiler/bytecode-graph-builder.cc index e4dd0e1aaf..f06c8569d1 100644 --- a/src/compiler/bytecode-graph-builder.cc +++ b/src/compiler/bytecode-graph-builder.cc @@ -475,7 +475,6 @@ BytecodeGraphBuilder::BytecodeGraphBuilder( bytecode_analysis_(nullptr), environment_(nullptr), osr_ast_id_(osr_ast_id), - osr_loop_offset_(-1), merge_environments_(local_zone), exception_handlers_(local_zone), current_exception_handler_(0), @@ -2380,7 +2379,7 @@ void BytecodeGraphBuilder::MergeControlToLeaveFunction(Node* exit) { void BytecodeGraphBuilder::BuildOSRLoopEntryPoint(int 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. // It will be turned into a usable entry by the OSR deconstruction. Environment* osr_env = environment()->Copy(); @@ -2390,15 +2389,10 @@ void BytecodeGraphBuilder::BuildOSRLoopEntryPoint(int current_offset) { } void BytecodeGraphBuilder::BuildOSRNormalEntryPoint() { - if (!osr_ast_id_.IsNone()) { + if (bytecode_analysis()->HasOSREntryPoint()) { // For OSR add an {OsrNormalEntry} as the the top-level environment start. // It will be replaced with {Dead} by the OSR deconstruction. 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, // 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 // 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* control = environment()->GetControlDependency(); Reduction early_reduction = type_hint_lowering().ReduceLoadNamedOperation( @@ -2564,7 +2558,7 @@ Node* BytecodeGraphBuilder::TryBuildSimplifiedLoadKeyed(const Operator* op, // 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 // 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* control = environment()->GetControlDependency(); Reduction early_reduction = type_hint_lowering().ReduceLoadKeyedOperation( @@ -2583,7 +2577,7 @@ Node* BytecodeGraphBuilder::TryBuildSimplifiedStoreNamed(const Operator* op, // 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 // 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* control = environment()->GetControlDependency(); Reduction early_reduction = type_hint_lowering().ReduceStoreNamedOperation( @@ -2602,7 +2596,7 @@ Node* BytecodeGraphBuilder::TryBuildSimplifiedStoreKeyed(const Operator* op, // 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 // 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* control = environment()->GetControlDependency(); Reduction early_reduction = type_hint_lowering().ReduceStoreKeyedOperation( diff --git a/src/compiler/bytecode-graph-builder.h b/src/compiler/bytecode-graph-builder.h index 809a995dff..d099327011 100644 --- a/src/compiler/bytecode-graph-builder.h +++ b/src/compiler/bytecode-graph-builder.h @@ -325,7 +325,6 @@ class BytecodeGraphBuilder { const BytecodeAnalysis* bytecode_analysis_; Environment* environment_; BailoutId osr_ast_id_; - int osr_loop_offset_; // Merge environments are snapshots of the environment at points where the // control flow merges. This models a forward data flow propagation of all