Index: src/compiler/ast-graph-builder.cc |
diff --git a/src/compiler/ast-graph-builder.cc b/src/compiler/ast-graph-builder.cc |
index 0abc9918df6595454e83f095732f71049ddc4088..c0f706d3b178e7fc17b185ce5c5d60251bacb7e4 100644 |
--- a/src/compiler/ast-graph-builder.cc |
+++ b/src/compiler/ast-graph-builder.cc |
@@ -483,31 +483,18 @@ Node* AstGraphBuilder::GetFunctionClosure() { |
} |
-void AstGraphBuilder::CreateFunctionContext(bool constant_context) { |
- function_context_.set(constant_context |
- ? jsgraph()->HeapConstant(info()->context()) |
- : NewOuterContextParam()); |
-} |
- |
- |
-Node* AstGraphBuilder::NewOuterContextParam() { |
- // Parameter (arity + 1) is special for the outer context of the function |
- const Operator* op = |
- common()->Parameter(info()->num_parameters_including_this(), "%context"); |
- return NewNode(op, graph()->start()); |
-} |
- |
- |
-Node* AstGraphBuilder::NewCurrentContextOsrValue() { |
- // TODO(titzer): use a real OSR value here; a parameter works by accident. |
- // Parameter (arity + 1) is special for the outer context of the function |
- const Operator* op = common()->Parameter( |
- info()->num_parameters_including_this(), "%osr-context"); |
- return NewNode(op, graph()->start()); |
+Node* AstGraphBuilder::GetFunctionContext() { |
+ if (!function_context_.is_set()) { |
+ const Operator* op = common()->Parameter( |
+ info()->num_parameters_including_this(), "%context"); |
+ Node* node = NewNode(op, graph()->start()); |
+ function_context_.set(node); |
+ } |
+ return function_context_.get(); |
} |
-bool AstGraphBuilder::CreateGraph(bool constant_context, bool stack_check) { |
+bool AstGraphBuilder::CreateGraph(bool stack_check) { |
Scope* scope = info()->scope(); |
DCHECK(graph() != NULL); |
@@ -526,8 +513,7 @@ bool AstGraphBuilder::CreateGraph(bool constant_context, bool stack_check) { |
} |
// Initialize the incoming context. |
- CreateFunctionContext(constant_context); |
- ContextScope incoming(this, scope, function_context_.get()); |
+ ContextScope incoming(this, scope, GetFunctionContext()); |
// Initialize control scope. |
ControlScope control(this); |
@@ -547,7 +533,7 @@ bool AstGraphBuilder::CreateGraph(bool constant_context, bool stack_check) { |
if (info()->num_heap_slots() > 0) { |
// Push a new inner context scope for the function. |
Node* inner_context = |
- BuildLocalFunctionContext(function_context_.get(), patched_receiver); |
+ BuildLocalFunctionContext(GetFunctionContext(), patched_receiver); |
ContextScope top_context(this, scope, inner_context); |
CreateGraphBody(stack_check); |
} else { |
@@ -3636,7 +3622,7 @@ Node* AstGraphBuilder::BuildLoadBuiltinsObject() { |
Node* AstGraphBuilder::BuildLoadGlobalObject() { |
const Operator* load_op = |
javascript()->LoadContext(0, Context::GLOBAL_OBJECT_INDEX, true); |
- return NewNode(load_op, function_context_.get()); |
+ return NewNode(load_op, GetFunctionContext()); |
} |
@@ -4063,7 +4049,9 @@ void AstGraphBuilder::Environment::PrepareForLoop(BitVector* assigned, |
// Introduce phis for all context values in the case of an OSR graph. |
for (int i = 0; i < static_cast<int>(contexts()->size()); ++i) { |
Node* val = contexts()->at(i); |
- if (!IrOpcode::IsConstantOpcode(val->opcode())) { |
+ if (!IrOpcode::IsConstantOpcode(val->opcode()) && |
+ (val != builder_->GetFunctionContext() || |
+ !builder_->info()->is_context_specializing())) { |
contexts()->at(i) = builder_->NewPhi(1, val, control); |
} |
} |
@@ -4090,14 +4078,21 @@ void AstGraphBuilder::Environment::PrepareForLoop(BitVector* assigned, |
// Rename all the contexts in the environment. |
// The innermost context is the OSR value, and the outer contexts are |
// reconstructed by dynamically walking up the context chain. |
+ // TODO(titzer): use a real OSR value here; a parameter works by accident. |
titzer
2015/07/03 09:28:17
To get rid of this TODO, we need a special OSR val
Michael Starzinger
2015/07/06 13:08:40
Done, see: https://codereview.chromium.org/1213043
|
+ Node* innermost_context = graph->NewNode( |
+ builder_->common()->Parameter( |
+ builder_->info()->num_parameters_including_this(), "%osr-context"), |
+ graph->start()); |
Node* osr_context = nullptr; |
const Operator* op = |
builder_->javascript()->LoadContext(0, Context::PREVIOUS_INDEX, true); |
int last = static_cast<int>(contexts()->size() - 1); |
for (int i = last; i >= 0; i--) { |
Node* val = contexts()->at(i); |
- if (!IrOpcode::IsConstantOpcode(val->opcode())) { |
- osr_context = (i == last) ? builder_->NewCurrentContextOsrValue() |
+ if (!IrOpcode::IsConstantOpcode(val->opcode()) && |
+ (val != builder_->GetFunctionContext() || |
+ !builder_->info()->is_context_specializing())) { |
+ osr_context = (i == last) ? innermost_context |
: graph->NewNode(op, osr_context, osr_context, |
osr_loop_entry); |
contexts()->at(i) = builder_->MergeValue(val, osr_context, control); |