Commit fb7904c6 authored by jarin's avatar jarin Committed by Commit bot

[turbofan] Explicit OSR environment merge for bytecode graph builder.

Review-Url: https://codereview.chromium.org/2377343002
Cr-Commit-Position: refs/heads/master@{#39875}
parent 57b0e374
...@@ -65,8 +65,9 @@ class BytecodeGraphBuilder::Environment : public ZoneObject { ...@@ -65,8 +65,9 @@ class BytecodeGraphBuilder::Environment : public ZoneObject {
Environment* CopyForConditional(); Environment* CopyForConditional();
Environment* CopyForLoop(); Environment* CopyForLoop();
Environment* CopyForOsrEntry();
void Merge(Environment* other); void Merge(Environment* other);
void PrepareForOsr(); void PrepareForOsrEntry();
void PrepareForLoopExit(Node* loop); void PrepareForLoopExit(Node* loop);
...@@ -345,6 +346,12 @@ BytecodeGraphBuilder::Environment::CopyForLoop() { ...@@ -345,6 +346,12 @@ BytecodeGraphBuilder::Environment::CopyForLoop() {
return new (zone()) Environment(this, liveness_block()); return new (zone()) Environment(this, liveness_block());
} }
BytecodeGraphBuilder::Environment*
BytecodeGraphBuilder::Environment::CopyForOsrEntry() {
return new (zone())
Environment(this, builder_->liveness_analyzer()->NewBlock());
}
BytecodeGraphBuilder::Environment* BytecodeGraphBuilder::Environment*
BytecodeGraphBuilder::Environment::CopyForConditional() { BytecodeGraphBuilder::Environment::CopyForConditional() {
LivenessAnalyzerBlock* copy_liveness_block = nullptr; LivenessAnalyzerBlock* copy_liveness_block = nullptr;
...@@ -409,34 +416,27 @@ void BytecodeGraphBuilder::Environment::PrepareForLoop() { ...@@ -409,34 +416,27 @@ void BytecodeGraphBuilder::Environment::PrepareForLoop() {
builder()->exit_controls_.push_back(terminate); builder()->exit_controls_.push_back(terminate);
} }
void BytecodeGraphBuilder::Environment::PrepareForOsr() { void BytecodeGraphBuilder::Environment::PrepareForOsrEntry() {
DCHECK_EQ(IrOpcode::kLoop, GetControlDependency()->opcode()); DCHECK_EQ(IrOpcode::kLoop, GetControlDependency()->opcode());
DCHECK_EQ(1, GetControlDependency()->InputCount()); DCHECK_EQ(1, GetControlDependency()->InputCount());
Node* start = graph()->start(); Node* start = graph()->start();
// Create a control node for the OSR entry point and merge it into the loop // Create a control node for the OSR entry point and update the current
// header. Update the current environment's control dependency accordingly. // environment's dependencies accordingly.
Node* entry = graph()->NewNode(common()->OsrLoopEntry(), start, start); Node* entry = graph()->NewNode(common()->OsrLoopEntry(), start, start);
Node* control = builder()->MergeControl(GetControlDependency(), entry); UpdateControlDependency(entry);
UpdateControlDependency(control); UpdateEffectDependency(entry);
// Create a merge of the effect from the OSR entry and the existing effect
// dependency. Update the current environment's effect dependency accordingly.
Node* effect = builder()->MergeEffect(GetEffectDependency(), entry, control);
UpdateEffectDependency(effect);
// Rename all values in the environment which will extend or introduce Phi // Create OSR values for each environment value.
// nodes to contain the OSR values available at the entry point. SetContext(graph()->NewNode(
Node* osr_context = graph()->NewNode( common()->OsrValue(Linkage::kOsrContextSpillSlotIndex), entry));
common()->OsrValue(Linkage::kOsrContextSpillSlotIndex), entry);
context_ = builder()->MergeValue(context_, osr_context, control);
int size = static_cast<int>(values()->size()); int size = static_cast<int>(values()->size());
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
int idx = i; // Indexing scheme follows {StandardFrame}, adapt accordingly. int idx = i; // Indexing scheme follows {StandardFrame}, adapt accordingly.
if (i >= register_base()) idx += InterpreterFrameConstants::kExtraSlotCount; if (i >= register_base()) idx += InterpreterFrameConstants::kExtraSlotCount;
if (i >= accumulator_base()) idx = Linkage::kOsrAccumulatorRegisterIndex; if (i >= accumulator_base()) idx = Linkage::kOsrAccumulatorRegisterIndex;
Node* osr_value = graph()->NewNode(common()->OsrValue(idx), entry); values()->at(i) = graph()->NewNode(common()->OsrValue(idx), entry);
values_[i] = builder()->MergeValue(values_[i], osr_value, control);
} }
} }
...@@ -1912,7 +1912,10 @@ void BytecodeGraphBuilder::BuildOSRLoopEntryPoint(int current_offset) { ...@@ -1912,7 +1912,10 @@ void BytecodeGraphBuilder::BuildOSRLoopEntryPoint(int current_offset) {
if (!osr_ast_id_.IsNone() && osr_ast_id_.ToInt() == current_offset) { if (!osr_ast_id_.IsNone() && osr_ast_id_.ToInt() == 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()->PrepareForOsr(); Environment* loop_env = merge_environments_[current_offset];
Environment* osr_env = loop_env->CopyForOsrEntry();
osr_env->PrepareForOsrEntry();
loop_env->Merge(osr_env);
} }
} }
......
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