Commit 8893d4ff authored by mstarzinger's avatar mstarzinger Committed by Commit bot

[turbofan] Move OSR BailoutId translation into graph builder.

This moves the location of the bytecode-offset translation that turns
offsets of back jumps into offsets of loop headers. This translation is
now done by the {BytecodeGraphBuilder} after loop analysis has been
performed. It safes one redudant iteration over the bytecode array. Note
that this changes the semantics of the BailoutId used as an {osr_ast_id}
throughout the compiler pipeline for OSR from Ignition.

R=jarin@chromium.org

Review-Url: https://codereview.chromium.org/2465913002
Cr-Commit-Position: refs/heads/master@{#41431}
parent a72380f8
......@@ -161,7 +161,10 @@ void BytecodeAnalysis::Analyze() {
int current_offset = iterator.current_offset();
if (bytecode == Bytecode::kJumpLoop) {
PushLoop(iterator.GetJumpTargetOffset(), current_offset);
// 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);
// Save the last offset so that we can do another pass later.
if (last_invalid_jumploop_offset == -1) {
......@@ -296,7 +299,7 @@ bool BytecodeAnalysis::IsLoopHeader(int offset) const {
}
int BytecodeAnalysis::GetLoopOffsetFor(int offset) const {
auto loop_end_to_header = end_to_header_.lower_bound(offset);
auto loop_end_to_header = end_to_header_.upper_bound(offset);
// If there is no next end => offset is not in a loop.
if (loop_end_to_header == end_to_header_.end()) {
return -1;
......
......@@ -465,6 +465,7 @@ BytecodeGraphBuilder::BytecodeGraphBuilder(
bytecode_array()->parameter_count(),
bytecode_array()->register_count(), info->shared_info())),
osr_ast_id_(info->osr_ast_id()),
osr_loop_offset_(-1),
merge_environments_(local_zone),
exception_handlers_(local_zone),
current_exception_handler_(0),
......@@ -1898,7 +1899,7 @@ void BytecodeGraphBuilder::MergeControlToLeaveFunction(Node* exit) {
}
void BytecodeGraphBuilder::BuildOSRLoopEntryPoint(int current_offset) {
if (!osr_ast_id_.IsNone() && osr_ast_id_.ToInt() == current_offset) {
if (!osr_ast_id_.IsNone() && osr_loop_offset_ == 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* loop_env = merge_environments_[current_offset];
......@@ -1913,8 +1914,11 @@ void BytecodeGraphBuilder::BuildOSRNormalEntryPoint() {
// 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());
// Note that the requested OSR entry point must be the header of a loop.
DCHECK(bytecode_analysis()->IsLoopHeader(osr_ast_id_.ToInt()));
// 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_));
}
}
......
......@@ -204,6 +204,10 @@ class BytecodeGraphBuilder {
// Simulates entry and exit of exception handlers.
void EnterAndExitExceptionHandlers(int current_offset);
// Update the current position of the {SourcePositionTable} to that of the
// bytecode at {offset}, if any.
void UpdateCurrentSourcePosition(SourcePositionTableIterator* it, int offset);
// Growth increment for the temporary buffer used to construct input lists to
// new nodes.
static const int kInputBufferSizeIncrement = 64;
......@@ -275,6 +279,7 @@ 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
......@@ -301,15 +306,11 @@ class BytecodeGraphBuilder {
StateValuesCache state_values_cache_;
// The Turbofan source position table, to be populated.
// The source position table, to be populated.
SourcePositionTable* source_positions_;
SourcePosition const start_position_;
// Update [source_positions_]'s current position to that of the bytecode at
// [offset], if any.
void UpdateCurrentSourcePosition(SourcePositionTableIterator* it, int offset);
static int const kBinaryOperationHintIndex = 1;
static int const kCountOperationHintIndex = 0;
static int const kBinaryOperationSmiHintIndex = 2;
......
......@@ -11,7 +11,6 @@
#include "src/deoptimizer.h"
#include "src/frames-inl.h"
#include "src/full-codegen/full-codegen.h"
#include "src/interpreter/bytecode-array-iterator.h"
#include "src/isolate-inl.h"
#include "src/messages.h"
#include "src/v8threads.h"
......@@ -270,9 +269,9 @@ BailoutId DetermineEntryAndDisarmOSRForBaseline(JavaScriptFrame* frame) {
// Revert the patched back edge table, regardless of whether OSR succeeds.
BackEdgeTable::Revert(frame->isolate(), *caller_code);
// Return a BailoutId representing an AST id of the {IterationStatement}.
uint32_t pc_offset =
static_cast<uint32_t>(frame->pc() - caller_code->instruction_start());
return caller_code->TranslatePcOffsetToAstId(pc_offset);
}
......@@ -293,20 +292,8 @@ BailoutId DetermineEntryAndDisarmOSRForInterpreter(JavaScriptFrame* frame) {
// Reset the OSR loop nesting depth to disarm back edges.
bytecode->set_osr_loop_nesting_level(0);
// 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.
// TODO(mstarzinger): This can be merged with {BytecodeBranchAnalysis} which
// already performs a pre-pass over the bytecode stream anyways.
int jump_offset = iframe->GetBytecodeOffset();
interpreter::BytecodeArrayIterator iterator(bytecode);
while (iterator.current_offset() + iterator.current_prefix_offset() <
jump_offset) {
iterator.Advance();
}
DCHECK(interpreter::Bytecodes::IsJump(iterator.current_bytecode()));
int jump_target_offset = iterator.GetJumpTargetOffset();
return BailoutId(jump_target_offset);
// Return a BailoutId representing the bytecode offset of the back branch.
return BailoutId(iframe->GetBytecodeOffset());
}
} // namespace
......
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