Commit 9ef7ab1e authored by neis's avatar neis Committed by Commit bot

[compiler] Remove context value input from JSLoadContext and JSStoreContext.

JS operators always have an implicit context input, so just use that instead.

BUG=

Review-Url: https://codereview.chromium.org/2541813002
Cr-Commit-Position: refs/heads/master@{#41392}
parent ec90ccb5
...@@ -305,7 +305,7 @@ Node* AstGraphBuilder::GetFunctionClosureForContext() { ...@@ -305,7 +305,7 @@ Node* AstGraphBuilder::GetFunctionClosureForContext() {
// calling eval, not the anonymous closure containing the eval code. // calling eval, not the anonymous closure containing the eval code.
const Operator* op = const Operator* op =
javascript()->LoadContext(0, Context::CLOSURE_INDEX, false); javascript()->LoadContext(0, Context::CLOSURE_INDEX, false);
return NewNode(op, current_context()); return NewNode(op);
} else { } else {
DCHECK(closure_scope->is_function_scope()); DCHECK(closure_scope->is_function_scope());
return GetFunctionClosure(); return GetFunctionClosure();
...@@ -945,7 +945,7 @@ void AstGraphBuilder::VisitVariableDeclaration(VariableDeclaration* decl) { ...@@ -945,7 +945,7 @@ void AstGraphBuilder::VisitVariableDeclaration(VariableDeclaration* decl) {
if (variable->binding_needs_init()) { if (variable->binding_needs_init()) {
Node* value = jsgraph()->TheHoleConstant(); Node* value = jsgraph()->TheHoleConstant();
const Operator* op = javascript()->StoreContext(0, variable->index()); const Operator* op = javascript()->StoreContext(0, variable->index());
NewNode(op, current_context(), value); NewNode(op, value);
} }
break; break;
case VariableLocation::LOOKUP: case VariableLocation::LOOKUP:
...@@ -981,7 +981,7 @@ void AstGraphBuilder::VisitFunctionDeclaration(FunctionDeclaration* decl) { ...@@ -981,7 +981,7 @@ void AstGraphBuilder::VisitFunctionDeclaration(FunctionDeclaration* decl) {
VisitForValue(decl->fun()); VisitForValue(decl->fun());
Node* value = environment()->Pop(); Node* value = environment()->Pop();
const Operator* op = javascript()->StoreContext(0, variable->index()); const Operator* op = javascript()->StoreContext(0, variable->index());
NewNode(op, current_context(), value); NewNode(op, value);
break; break;
} }
case VariableLocation::LOOKUP: case VariableLocation::LOOKUP:
...@@ -2650,7 +2650,8 @@ Node* AstGraphBuilder::BuildLocalActivationContext(Node* context) { ...@@ -2650,7 +2650,8 @@ Node* AstGraphBuilder::BuildLocalActivationContext(Node* context) {
Variable* variable = scope->receiver(); Variable* variable = scope->receiver();
DCHECK_EQ(0, scope->ContextChainLength(variable->scope())); DCHECK_EQ(0, scope->ContextChainLength(variable->scope()));
const Operator* op = javascript()->StoreContext(0, variable->index()); const Operator* op = javascript()->StoreContext(0, variable->index());
NewNode(op, local_context, receiver); Node* node = NewNode(op, receiver);
NodeProperties::ReplaceContextInput(node, local_context);
} }
// Copy parameters into context if necessary. // Copy parameters into context if necessary.
...@@ -2662,7 +2663,8 @@ Node* AstGraphBuilder::BuildLocalActivationContext(Node* context) { ...@@ -2662,7 +2663,8 @@ Node* AstGraphBuilder::BuildLocalActivationContext(Node* context) {
// Context variable (at bottom of the context chain). // Context variable (at bottom of the context chain).
DCHECK_EQ(0, scope->ContextChainLength(variable->scope())); DCHECK_EQ(0, scope->ContextChainLength(variable->scope()));
const Operator* op = javascript()->StoreContext(0, variable->index()); const Operator* op = javascript()->StoreContext(0, variable->index());
NewNode(op, local_context, parameter); Node* node = NewNode(op, parameter);
NodeProperties::ReplaceContextInput(node, local_context);
} }
return local_context; return local_context;
...@@ -2801,7 +2803,7 @@ Node* AstGraphBuilder::BuildVariableLoad(Variable* variable, ...@@ -2801,7 +2803,7 @@ Node* AstGraphBuilder::BuildVariableLoad(Variable* variable,
info()->is_function_context_specializing(); info()->is_function_context_specializing();
const Operator* op = const Operator* op =
javascript()->LoadContext(depth, variable->index(), immutable); javascript()->LoadContext(depth, variable->index(), immutable);
Node* value = NewNode(op, current_context()); Node* value = NewNode(op);
// TODO(titzer): initialization checks are redundant for already // TODO(titzer): initialization checks are redundant for already
// initialized immutable context loads, but only specialization knows. // initialized immutable context loads, but only specialization knows.
// Maybe specializer should be a parameter to the graph builder? // Maybe specializer should be a parameter to the graph builder?
...@@ -2918,7 +2920,7 @@ Node* AstGraphBuilder::BuildVariableAssignment( ...@@ -2918,7 +2920,7 @@ Node* AstGraphBuilder::BuildVariableAssignment(
// Perform an initialization check for let declared variables. // Perform an initialization check for let declared variables.
const Operator* op = const Operator* op =
javascript()->LoadContext(depth, variable->index(), false); javascript()->LoadContext(depth, variable->index(), false);
Node* current = NewNode(op, current_context()); Node* current = NewNode(op);
value = BuildHoleCheckThenThrow(current, variable, value, bailout_id); value = BuildHoleCheckThenThrow(current, variable, value, bailout_id);
} else if (mode == CONST && op == Token::INIT) { } else if (mode == CONST && op == Token::INIT) {
// Perform an initialization check for const {this} variables. // Perform an initialization check for const {this} variables.
...@@ -2927,7 +2929,7 @@ Node* AstGraphBuilder::BuildVariableAssignment( ...@@ -2927,7 +2929,7 @@ Node* AstGraphBuilder::BuildVariableAssignment(
if (variable->is_this()) { if (variable->is_this()) {
const Operator* op = const Operator* op =
javascript()->LoadContext(depth, variable->index(), false); javascript()->LoadContext(depth, variable->index(), false);
Node* current = NewNode(op, current_context()); Node* current = NewNode(op);
value = BuildHoleCheckElseThrow(current, variable, value, bailout_id); value = BuildHoleCheckElseThrow(current, variable, value, bailout_id);
} }
} else if (mode == CONST && op != Token::INIT && } else if (mode == CONST && op != Token::INIT &&
...@@ -2944,14 +2946,14 @@ Node* AstGraphBuilder::BuildVariableAssignment( ...@@ -2944,14 +2946,14 @@ Node* AstGraphBuilder::BuildVariableAssignment(
if (variable->binding_needs_init()) { if (variable->binding_needs_init()) {
const Operator* op = const Operator* op =
javascript()->LoadContext(depth, variable->index(), false); javascript()->LoadContext(depth, variable->index(), false);
Node* current = NewNode(op, current_context()); Node* current = NewNode(op);
BuildHoleCheckThenThrow(current, variable, value, bailout_id); BuildHoleCheckThenThrow(current, variable, value, bailout_id);
} }
// Assignment to const is exception in all modes. // Assignment to const is exception in all modes.
return BuildThrowConstAssignError(bailout_id); return BuildThrowConstAssignError(bailout_id);
} }
const Operator* op = javascript()->StoreContext(depth, variable->index()); const Operator* op = javascript()->StoreContext(depth, variable->index());
return NewNode(op, current_context(), value); return NewNode(op, value);
} }
case VariableLocation::LOOKUP: case VariableLocation::LOOKUP:
case VariableLocation::MODULE: case VariableLocation::MODULE:
...@@ -3063,8 +3065,10 @@ Node* AstGraphBuilder::BuildLoadGlobalObject() { ...@@ -3063,8 +3065,10 @@ Node* AstGraphBuilder::BuildLoadGlobalObject() {
Node* AstGraphBuilder::BuildLoadNativeContextField(int index) { Node* AstGraphBuilder::BuildLoadNativeContextField(int index) {
const Operator* op = const Operator* op =
javascript()->LoadContext(0, Context::NATIVE_CONTEXT_INDEX, true); javascript()->LoadContext(0, Context::NATIVE_CONTEXT_INDEX, true);
Node* native_context = NewNode(op, current_context()); Node* native_context = NewNode(op);
return NewNode(javascript()->LoadContext(0, index, true), native_context); Node* result = NewNode(javascript()->LoadContext(0, index, true));
NodeProperties::ReplaceContextInput(result, native_context);
return result;
} }
...@@ -3499,8 +3503,7 @@ void AstGraphBuilder::Environment::PrepareForOsrEntry() { ...@@ -3499,8 +3503,7 @@ void AstGraphBuilder::Environment::PrepareForOsrEntry() {
Node* osr_context = effect = contexts()->back(); Node* osr_context = effect = contexts()->back();
int last = static_cast<int>(contexts()->size() - 1); int last = static_cast<int>(contexts()->size() - 1);
for (int i = last - 1; i >= 0; i--) { for (int i = last - 1; i >= 0; i--) {
osr_context = effect = osr_context = effect = graph->NewNode(load_op, osr_context, effect);
graph->NewNode(load_op, osr_context, osr_context, effect);
contexts()->at(i) = osr_context; contexts()->at(i) = osr_context;
} }
UpdateEffectDependency(effect); UpdateEffectDependency(effect);
......
...@@ -517,8 +517,10 @@ Node* BytecodeGraphBuilder::GetFunctionClosure() { ...@@ -517,8 +517,10 @@ Node* BytecodeGraphBuilder::GetFunctionClosure() {
Node* BytecodeGraphBuilder::BuildLoadNativeContextField(int index) { Node* BytecodeGraphBuilder::BuildLoadNativeContextField(int index) {
const Operator* op = const Operator* op =
javascript()->LoadContext(0, Context::NATIVE_CONTEXT_INDEX, true); javascript()->LoadContext(0, Context::NATIVE_CONTEXT_INDEX, true);
Node* native_context = NewNode(op, environment()->Context()); Node* native_context = NewNode(op);
return NewNode(javascript()->LoadContext(0, index, true), native_context); Node* result = NewNode(javascript()->LoadContext(0, index, true));
NodeProperties::ReplaceContextInput(result, native_context);
return result;
} }
...@@ -777,9 +779,10 @@ void BytecodeGraphBuilder::VisitLdaContextSlot() { ...@@ -777,9 +779,10 @@ void BytecodeGraphBuilder::VisitLdaContextSlot() {
const Operator* op = javascript()->LoadContext( const Operator* op = javascript()->LoadContext(
bytecode_iterator().GetUnsignedImmediateOperand(2), bytecode_iterator().GetUnsignedImmediateOperand(2),
bytecode_iterator().GetIndexOperand(1), false); bytecode_iterator().GetIndexOperand(1), false);
Node* node = NewNode(op);
Node* context = Node* context =
environment()->LookupRegister(bytecode_iterator().GetRegisterOperand(0)); environment()->LookupRegister(bytecode_iterator().GetRegisterOperand(0));
Node* node = NewNode(op, context); NodeProperties::ReplaceContextInput(node, context);
environment()->BindAccumulator(node); environment()->BindAccumulator(node);
} }
...@@ -789,8 +792,7 @@ void BytecodeGraphBuilder::VisitLdaCurrentContextSlot() { ...@@ -789,8 +792,7 @@ void BytecodeGraphBuilder::VisitLdaCurrentContextSlot() {
// changes. // changes.
const Operator* op = javascript()->LoadContext( const Operator* op = javascript()->LoadContext(
0, bytecode_iterator().GetIndexOperand(0), false); 0, bytecode_iterator().GetIndexOperand(0), false);
Node* context = environment()->Context(); Node* node = NewNode(op);
Node* node = NewNode(op, context);
environment()->BindAccumulator(node); environment()->BindAccumulator(node);
} }
...@@ -798,18 +800,18 @@ void BytecodeGraphBuilder::VisitStaContextSlot() { ...@@ -798,18 +800,18 @@ void BytecodeGraphBuilder::VisitStaContextSlot() {
const Operator* op = javascript()->StoreContext( const Operator* op = javascript()->StoreContext(
bytecode_iterator().GetUnsignedImmediateOperand(2), bytecode_iterator().GetUnsignedImmediateOperand(2),
bytecode_iterator().GetIndexOperand(1)); bytecode_iterator().GetIndexOperand(1));
Node* value = environment()->LookupAccumulator();
Node* node = NewNode(op, value);
Node* context = Node* context =
environment()->LookupRegister(bytecode_iterator().GetRegisterOperand(0)); environment()->LookupRegister(bytecode_iterator().GetRegisterOperand(0));
Node* value = environment()->LookupAccumulator(); NodeProperties::ReplaceContextInput(node, context);
NewNode(op, context, value);
} }
void BytecodeGraphBuilder::VisitStaCurrentContextSlot() { void BytecodeGraphBuilder::VisitStaCurrentContextSlot() {
const Operator* op = const Operator* op =
javascript()->StoreContext(0, bytecode_iterator().GetIndexOperand(0)); javascript()->StoreContext(0, bytecode_iterator().GetIndexOperand(0));
Node* context = environment()->Context();
Node* value = environment()->LookupAccumulator(); Node* value = environment()->LookupAccumulator();
NewNode(op, context, value); NewNode(op, value);
} }
void BytecodeGraphBuilder::BuildLdaLookupSlot(TypeofMode typeof_mode) { void BytecodeGraphBuilder::BuildLdaLookupSlot(TypeofMode typeof_mode) {
...@@ -841,8 +843,7 @@ BytecodeGraphBuilder::Environment* BytecodeGraphBuilder::CheckContextExtensions( ...@@ -841,8 +843,7 @@ BytecodeGraphBuilder::Environment* BytecodeGraphBuilder::CheckContextExtensions(
// the same scope as the variable itself has no way of shadowing it. // the same scope as the variable itself has no way of shadowing it.
for (uint32_t d = 0; d < depth; d++) { for (uint32_t d = 0; d < depth; d++) {
Node* extension_slot = Node* extension_slot =
NewNode(javascript()->LoadContext(d, Context::EXTENSION_INDEX, false), NewNode(javascript()->LoadContext(d, Context::EXTENSION_INDEX, false));
environment()->Context());
Node* check_no_extension = Node* check_no_extension =
NewNode(javascript()->StrictEqual(CompareOperationHint::kAny), NewNode(javascript()->StrictEqual(CompareOperationHint::kAny),
...@@ -888,8 +889,7 @@ void BytecodeGraphBuilder::BuildLdaLookupContextSlot(TypeofMode typeof_mode) { ...@@ -888,8 +889,7 @@ void BytecodeGraphBuilder::BuildLdaLookupContextSlot(TypeofMode typeof_mode) {
uint32_t slot_index = bytecode_iterator().GetIndexOperand(1); uint32_t slot_index = bytecode_iterator().GetIndexOperand(1);
const Operator* op = javascript()->LoadContext(depth, slot_index, false); const Operator* op = javascript()->LoadContext(depth, slot_index, false);
Node* context = environment()->Context(); environment()->BindAccumulator(NewNode(op));
environment()->BindAccumulator(NewNode(op, context));
} }
// Only build the slow path if there were any slow-path checks. // Only build the slow path if there were any slow-path checks.
...@@ -1070,9 +1070,8 @@ void BytecodeGraphBuilder::VisitStaKeyedPropertyStrict() { ...@@ -1070,9 +1070,8 @@ void BytecodeGraphBuilder::VisitStaKeyedPropertyStrict() {
void BytecodeGraphBuilder::VisitLdaModuleVariable() { void BytecodeGraphBuilder::VisitLdaModuleVariable() {
int32_t cell_index = bytecode_iterator().GetImmediateOperand(0); int32_t cell_index = bytecode_iterator().GetImmediateOperand(0);
uint32_t depth = bytecode_iterator().GetUnsignedImmediateOperand(1); uint32_t depth = bytecode_iterator().GetUnsignedImmediateOperand(1);
Node* module = Node* module = NewNode(
NewNode(javascript()->LoadContext(depth, Context::EXTENSION_INDEX, false), javascript()->LoadContext(depth, Context::EXTENSION_INDEX, false));
environment()->Context());
Node* value = NewNode(javascript()->LoadModule(cell_index), module); Node* value = NewNode(javascript()->LoadModule(cell_index), module);
environment()->BindAccumulator(value); environment()->BindAccumulator(value);
} }
...@@ -1080,9 +1079,8 @@ void BytecodeGraphBuilder::VisitLdaModuleVariable() { ...@@ -1080,9 +1079,8 @@ void BytecodeGraphBuilder::VisitLdaModuleVariable() {
void BytecodeGraphBuilder::VisitStaModuleVariable() { void BytecodeGraphBuilder::VisitStaModuleVariable() {
int32_t cell_index = bytecode_iterator().GetImmediateOperand(0); int32_t cell_index = bytecode_iterator().GetImmediateOperand(0);
uint32_t depth = bytecode_iterator().GetUnsignedImmediateOperand(1); uint32_t depth = bytecode_iterator().GetUnsignedImmediateOperand(1);
Node* module = Node* module = NewNode(
NewNode(javascript()->LoadContext(depth, Context::EXTENSION_INDEX, false), javascript()->LoadContext(depth, Context::EXTENSION_INDEX, false));
environment()->Context());
Node* value = environment()->LookupAccumulator(); Node* value = environment()->LookupAccumulator();
NewNode(javascript()->StoreModule(cell_index), module, value); NewNode(javascript()->StoreModule(cell_index), module, value);
} }
......
...@@ -33,7 +33,7 @@ MaybeHandle<Context> JSContextSpecialization::GetSpecializationContext( ...@@ -33,7 +33,7 @@ MaybeHandle<Context> JSContextSpecialization::GetSpecializationContext(
Node* node) { Node* node) {
DCHECK(node->opcode() == IrOpcode::kJSLoadContext || DCHECK(node->opcode() == IrOpcode::kJSLoadContext ||
node->opcode() == IrOpcode::kJSStoreContext); node->opcode() == IrOpcode::kJSStoreContext);
Node* const object = NodeProperties::GetValueInput(node, 0); Node* const object = NodeProperties::GetContextInput(node);
return NodeProperties::GetSpecializationContext(object, context()); return NodeProperties::GetSpecializationContext(object, context());
} }
...@@ -59,7 +59,7 @@ Reduction JSContextSpecialization::ReduceJSLoadContext(Node* node) { ...@@ -59,7 +59,7 @@ Reduction JSContextSpecialization::ReduceJSLoadContext(Node* node) {
} }
const Operator* op = jsgraph_->javascript()->LoadContext( const Operator* op = jsgraph_->javascript()->LoadContext(
0, access.index(), access.immutable()); 0, access.index(), access.immutable());
node->ReplaceInput(0, jsgraph_->Constant(context)); NodeProperties::ReplaceContextInput(node, jsgraph_->Constant(context));
NodeProperties::ChangeOp(node, op); NodeProperties::ChangeOp(node, op);
return Changed(node); return Changed(node);
} }
...@@ -101,7 +101,7 @@ Reduction JSContextSpecialization::ReduceJSStoreContext(Node* node) { ...@@ -101,7 +101,7 @@ Reduction JSContextSpecialization::ReduceJSStoreContext(Node* node) {
context = handle(context->previous(), isolate()); context = handle(context->previous(), isolate());
} }
node->ReplaceInput(0, jsgraph_->Constant(context)); NodeProperties::ReplaceContextInput(node, jsgraph_->Constant(context));
NodeProperties::ChangeOp(node, javascript()->StoreContext(0, access.index())); NodeProperties::ChangeOp(node, javascript()->StoreContext(0, access.index()));
return Changed(node); return Changed(node);
} }
......
...@@ -76,7 +76,7 @@ Reduction JSGlobalObjectSpecialization::ReduceJSLoadGlobal(Node* node) { ...@@ -76,7 +76,7 @@ Reduction JSGlobalObjectSpecialization::ReduceJSLoadGlobal(Node* node) {
Node* context = jsgraph()->HeapConstant(result.context); Node* context = jsgraph()->HeapConstant(result.context);
Node* value = effect = graph()->NewNode( Node* value = effect = graph()->NewNode(
javascript()->LoadContext(0, result.index, result.immutable), context, javascript()->LoadContext(0, result.index, result.immutable), context,
context, effect); effect);
ReplaceWithValue(node, value, effect); ReplaceWithValue(node, value, effect);
return Replace(value); return Replace(value);
} }
...@@ -157,7 +157,7 @@ Reduction JSGlobalObjectSpecialization::ReduceJSStoreGlobal(Node* node) { ...@@ -157,7 +157,7 @@ Reduction JSGlobalObjectSpecialization::ReduceJSStoreGlobal(Node* node) {
if (result.immutable) return NoChange(); if (result.immutable) return NoChange();
Node* context = jsgraph()->HeapConstant(result.context); Node* context = jsgraph()->HeapConstant(result.context);
effect = graph()->NewNode(javascript()->StoreContext(0, result.index), effect = graph()->NewNode(javascript()->StoreContext(0, result.index),
context, value, context, effect, control); value, context, effect, control);
ReplaceWithValue(node, value, effect, control); ReplaceWithValue(node, value, effect, control);
return Replace(value); return Replace(value);
} }
......
...@@ -756,7 +756,7 @@ const Operator* JSOperatorBuilder::LoadContext(size_t depth, size_t index, ...@@ -756,7 +756,7 @@ const Operator* JSOperatorBuilder::LoadContext(size_t depth, size_t index,
IrOpcode::kJSLoadContext, // opcode IrOpcode::kJSLoadContext, // opcode
Operator::kNoWrite | Operator::kNoThrow, // flags Operator::kNoWrite | Operator::kNoThrow, // flags
"JSLoadContext", // name "JSLoadContext", // name
1, 1, 0, 1, 1, 0, // counts 0, 1, 0, 1, 1, 0, // counts
access); // parameter access); // parameter
} }
...@@ -767,7 +767,7 @@ const Operator* JSOperatorBuilder::StoreContext(size_t depth, size_t index) { ...@@ -767,7 +767,7 @@ const Operator* JSOperatorBuilder::StoreContext(size_t depth, size_t index) {
IrOpcode::kJSStoreContext, // opcode IrOpcode::kJSStoreContext, // opcode
Operator::kNoRead | Operator::kNoThrow, // flags Operator::kNoRead | Operator::kNoThrow, // flags
"JSStoreContext", // name "JSStoreContext", // name
2, 1, 1, 0, 1, 0, // counts 1, 1, 1, 0, 1, 0, // counts
access); // parameter access); // parameter
} }
......
...@@ -1507,16 +1507,17 @@ Reduction JSTypedLowering::ReduceJSLoadContext(Node* node) { ...@@ -1507,16 +1507,17 @@ Reduction JSTypedLowering::ReduceJSLoadContext(Node* node) {
DCHECK_EQ(IrOpcode::kJSLoadContext, node->opcode()); DCHECK_EQ(IrOpcode::kJSLoadContext, node->opcode());
ContextAccess const& access = ContextAccessOf(node->op()); ContextAccess const& access = ContextAccessOf(node->op());
Node* effect = NodeProperties::GetEffectInput(node); Node* effect = NodeProperties::GetEffectInput(node);
Node* context = NodeProperties::GetContextInput(node);
Node* control = graph()->start(); Node* control = graph()->start();
for (size_t i = 0; i < access.depth(); ++i) { for (size_t i = 0; i < access.depth(); ++i) {
Node* previous = effect = graph()->NewNode( context = effect = graph()->NewNode(
simplified()->LoadField( simplified()->LoadField(
AccessBuilder::ForContextSlot(Context::PREVIOUS_INDEX)), AccessBuilder::ForContextSlot(Context::PREVIOUS_INDEX)),
NodeProperties::GetValueInput(node, 0), effect, control); context, effect, control);
node->ReplaceInput(0, previous);
} }
node->ReplaceInput(0, context);
node->ReplaceInput(1, effect); node->ReplaceInput(1, effect);
node->ReplaceInput(2, control); node->AppendInput(jsgraph()->zone(), control);
NodeProperties::ChangeOp( NodeProperties::ChangeOp(
node, node,
simplified()->LoadField(AccessBuilder::ForContextSlot(access.index()))); simplified()->LoadField(AccessBuilder::ForContextSlot(access.index())));
...@@ -1527,15 +1528,17 @@ Reduction JSTypedLowering::ReduceJSStoreContext(Node* node) { ...@@ -1527,15 +1528,17 @@ Reduction JSTypedLowering::ReduceJSStoreContext(Node* node) {
DCHECK_EQ(IrOpcode::kJSStoreContext, node->opcode()); DCHECK_EQ(IrOpcode::kJSStoreContext, node->opcode());
ContextAccess const& access = ContextAccessOf(node->op()); ContextAccess const& access = ContextAccessOf(node->op());
Node* effect = NodeProperties::GetEffectInput(node); Node* effect = NodeProperties::GetEffectInput(node);
Node* context = NodeProperties::GetContextInput(node);
Node* control = graph()->start(); Node* control = graph()->start();
Node* value = NodeProperties::GetValueInput(node, 0);
for (size_t i = 0; i < access.depth(); ++i) { for (size_t i = 0; i < access.depth(); ++i) {
Node* previous = effect = graph()->NewNode( context = effect = graph()->NewNode(
simplified()->LoadField( simplified()->LoadField(
AccessBuilder::ForContextSlot(Context::PREVIOUS_INDEX)), AccessBuilder::ForContextSlot(Context::PREVIOUS_INDEX)),
NodeProperties::GetValueInput(node, 0), effect, control); context, effect, control);
node->ReplaceInput(0, previous);
} }
node->RemoveInput(2); node->ReplaceInput(0, context);
node->ReplaceInput(1, value);
node->ReplaceInput(2, effect); node->ReplaceInput(2, effect);
NodeProperties::ChangeOp( NodeProperties::ChangeOp(
node, node,
...@@ -1648,10 +1651,10 @@ Reduction JSTypedLowering::ReduceJSConvertReceiver(Node* node) { ...@@ -1648,10 +1651,10 @@ Reduction JSTypedLowering::ReduceJSConvertReceiver(Node* node) {
} else { } else {
Node* native_context = effect = graph()->NewNode( Node* native_context = effect = graph()->NewNode(
javascript()->LoadContext(0, Context::NATIVE_CONTEXT_INDEX, true), javascript()->LoadContext(0, Context::NATIVE_CONTEXT_INDEX, true),
context, context, effect); context, effect);
receiver = effect = graph()->NewNode( receiver = effect = graph()->NewNode(
javascript()->LoadContext(0, Context::GLOBAL_PROXY_INDEX, true), javascript()->LoadContext(0, Context::GLOBAL_PROXY_INDEX, true),
native_context, native_context, effect); native_context, effect);
} }
ReplaceWithValue(node, receiver, effect, control); ReplaceWithValue(node, receiver, effect, control);
return Replace(receiver); return Replace(receiver);
...@@ -1753,10 +1756,10 @@ Reduction JSTypedLowering::ReduceJSConvertReceiver(Node* node) { ...@@ -1753,10 +1756,10 @@ Reduction JSTypedLowering::ReduceJSConvertReceiver(Node* node) {
} else { } else {
Node* native_context = eglobal = graph()->NewNode( Node* native_context = eglobal = graph()->NewNode(
javascript()->LoadContext(0, Context::NATIVE_CONTEXT_INDEX, true), javascript()->LoadContext(0, Context::NATIVE_CONTEXT_INDEX, true),
context, context, eglobal); context, eglobal);
rglobal = eglobal = graph()->NewNode( rglobal = eglobal = graph()->NewNode(
javascript()->LoadContext(0, Context::GLOBAL_PROXY_INDEX, true), javascript()->LoadContext(0, Context::GLOBAL_PROXY_INDEX, true),
native_context, native_context, eglobal); native_context, eglobal);
} }
} }
......
...@@ -72,7 +72,7 @@ TEST(ReduceJSLoadContext) { ...@@ -72,7 +72,7 @@ TEST(ReduceJSLoadContext) {
{ {
// Mutable slot, constant context, depth = 0 => do nothing. // Mutable slot, constant context, depth = 0 => do nothing.
Node* load = t.graph()->NewNode(t.javascript()->LoadContext(0, 0, false), Node* load = t.graph()->NewNode(t.javascript()->LoadContext(0, 0, false),
const_context, const_context, start); const_context, start);
Reduction r = t.spec()->Reduce(load); Reduction r = t.spec()->Reduce(load);
CHECK(!r.Changed()); CHECK(!r.Changed());
} }
...@@ -80,7 +80,7 @@ TEST(ReduceJSLoadContext) { ...@@ -80,7 +80,7 @@ TEST(ReduceJSLoadContext) {
{ {
// Mutable slot, non-constant context, depth = 0 => do nothing. // Mutable slot, non-constant context, depth = 0 => do nothing.
Node* load = t.graph()->NewNode(t.javascript()->LoadContext(0, 0, false), Node* load = t.graph()->NewNode(t.javascript()->LoadContext(0, 0, false),
param_context, param_context, start); param_context, start);
Reduction r = t.spec()->Reduce(load); Reduction r = t.spec()->Reduce(load);
CHECK(!r.Changed()); CHECK(!r.Changed());
} }
...@@ -89,10 +89,10 @@ TEST(ReduceJSLoadContext) { ...@@ -89,10 +89,10 @@ TEST(ReduceJSLoadContext) {
// Mutable slot, constant context, depth > 0 => fold-in parent context. // Mutable slot, constant context, depth > 0 => fold-in parent context.
Node* load = t.graph()->NewNode( Node* load = t.graph()->NewNode(
t.javascript()->LoadContext(2, Context::GLOBAL_EVAL_FUN_INDEX, false), t.javascript()->LoadContext(2, Context::GLOBAL_EVAL_FUN_INDEX, false),
deep_const_context, deep_const_context, start); deep_const_context, start);
Reduction r = t.spec()->Reduce(load); Reduction r = t.spec()->Reduce(load);
CHECK(r.Changed()); CHECK(r.Changed());
Node* new_context_input = NodeProperties::GetValueInput(r.replacement(), 0); Node* new_context_input = NodeProperties::GetContextInput(r.replacement());
CHECK_EQ(IrOpcode::kHeapConstant, new_context_input->opcode()); CHECK_EQ(IrOpcode::kHeapConstant, new_context_input->opcode());
HeapObjectMatcher match(new_context_input); HeapObjectMatcher match(new_context_input);
CHECK_EQ(*native, *match.Value()); CHECK_EQ(*native, *match.Value());
...@@ -105,7 +105,7 @@ TEST(ReduceJSLoadContext) { ...@@ -105,7 +105,7 @@ TEST(ReduceJSLoadContext) {
{ {
// Immutable slot, constant context, depth = 0 => specialize. // Immutable slot, constant context, depth = 0 => specialize.
Node* load = t.graph()->NewNode(t.javascript()->LoadContext(0, slot, true), Node* load = t.graph()->NewNode(t.javascript()->LoadContext(0, slot, true),
const_context, const_context, start); const_context, start);
Reduction r = t.spec()->Reduce(load); Reduction r = t.spec()->Reduce(load);
CHECK(r.Changed()); CHECK(r.Changed());
CHECK(r.replacement() != load); CHECK(r.replacement() != load);
...@@ -142,27 +142,24 @@ TEST(ReduceJSStoreContext) { ...@@ -142,27 +142,24 @@ TEST(ReduceJSStoreContext) {
{ {
// Mutable slot, constant context, depth = 0 => do nothing. // Mutable slot, constant context, depth = 0 => do nothing.
Node* load = Node* load = t.graph()->NewNode(t.javascript()->StoreContext(0, 0),
t.graph()->NewNode(t.javascript()->StoreContext(0, 0), const_context, const_context, const_context, start, start);
const_context, const_context, start, start);
Reduction r = t.spec()->Reduce(load); Reduction r = t.spec()->Reduce(load);
CHECK(!r.Changed()); CHECK(!r.Changed());
} }
{ {
// Mutable slot, non-constant context, depth = 0 => do nothing. // Mutable slot, non-constant context, depth = 0 => do nothing.
Node* load = Node* load = t.graph()->NewNode(t.javascript()->StoreContext(0, 0),
t.graph()->NewNode(t.javascript()->StoreContext(0, 0), param_context, param_context, param_context, start, start);
param_context, const_context, start, start);
Reduction r = t.spec()->Reduce(load); Reduction r = t.spec()->Reduce(load);
CHECK(!r.Changed()); CHECK(!r.Changed());
} }
{ {
// Immutable slot, constant context, depth = 0 => do nothing. // Immutable slot, constant context, depth = 0 => do nothing.
Node* load = Node* load = t.graph()->NewNode(t.javascript()->StoreContext(0, slot),
t.graph()->NewNode(t.javascript()->StoreContext(0, slot), const_context, const_context, const_context, start, start);
const_context, const_context, start, start);
Reduction r = t.spec()->Reduce(load); Reduction r = t.spec()->Reduce(load);
CHECK(!r.Changed()); CHECK(!r.Changed());
} }
...@@ -171,10 +168,10 @@ TEST(ReduceJSStoreContext) { ...@@ -171,10 +168,10 @@ TEST(ReduceJSStoreContext) {
// Mutable slot, constant context, depth > 0 => fold-in parent context. // Mutable slot, constant context, depth > 0 => fold-in parent context.
Node* load = t.graph()->NewNode( Node* load = t.graph()->NewNode(
t.javascript()->StoreContext(2, Context::GLOBAL_EVAL_FUN_INDEX), t.javascript()->StoreContext(2, Context::GLOBAL_EVAL_FUN_INDEX),
deep_const_context, deep_const_context, const_context, start, start); deep_const_context, deep_const_context, start, start);
Reduction r = t.spec()->Reduce(load); Reduction r = t.spec()->Reduce(load);
CHECK(r.Changed()); CHECK(r.Changed());
Node* new_context_input = NodeProperties::GetValueInput(r.replacement(), 0); Node* new_context_input = NodeProperties::GetContextInput(r.replacement());
CHECK_EQ(IrOpcode::kHeapConstant, new_context_input->opcode()); CHECK_EQ(IrOpcode::kHeapConstant, new_context_input->opcode());
HeapObjectMatcher match(new_context_input); HeapObjectMatcher match(new_context_input);
CHECK_EQ(*native, *match.Value()); CHECK_EQ(*native, *match.Value());
......
...@@ -523,17 +523,15 @@ TEST_F(JSTypedLoweringTest, JSLoadContext) { ...@@ -523,17 +523,15 @@ TEST_F(JSTypedLoweringTest, JSLoadContext) {
static bool kBooleans[] = {false, true}; static bool kBooleans[] = {false, true};
TRACED_FOREACH(size_t, index, kIndices) { TRACED_FOREACH(size_t, index, kIndices) {
TRACED_FOREACH(bool, immutable, kBooleans) { TRACED_FOREACH(bool, immutable, kBooleans) {
Reduction const r1 = Reduce( Reduction const r1 = Reduce(graph()->NewNode(
graph()->NewNode(javascript()->LoadContext(0, index, immutable), javascript()->LoadContext(0, index, immutable), context, effect));
context, context, effect));
ASSERT_TRUE(r1.Changed()); ASSERT_TRUE(r1.Changed());
EXPECT_THAT(r1.replacement(), EXPECT_THAT(r1.replacement(),
IsLoadField(AccessBuilder::ForContextSlot(index), context, IsLoadField(AccessBuilder::ForContextSlot(index), context,
effect, graph()->start())); effect, graph()->start()));
Reduction const r2 = Reduce( Reduction const r2 = Reduce(graph()->NewNode(
graph()->NewNode(javascript()->LoadContext(1, index, immutable), javascript()->LoadContext(1, index, immutable), context, effect));
context, context, effect));
ASSERT_TRUE(r2.Changed()); ASSERT_TRUE(r2.Changed());
EXPECT_THAT(r2.replacement(), EXPECT_THAT(r2.replacement(),
IsLoadField(AccessBuilder::ForContextSlot(index), IsLoadField(AccessBuilder::ForContextSlot(index),
...@@ -559,16 +557,16 @@ TEST_F(JSTypedLoweringTest, JSStoreContext) { ...@@ -559,16 +557,16 @@ TEST_F(JSTypedLoweringTest, JSStoreContext) {
Node* const value = Parameter(type); Node* const value = Parameter(type);
Reduction const r1 = Reduction const r1 =
Reduce(graph()->NewNode(javascript()->StoreContext(0, index), context, Reduce(graph()->NewNode(javascript()->StoreContext(0, index), value,
value, context, effect, control)); context, effect, control));
ASSERT_TRUE(r1.Changed()); ASSERT_TRUE(r1.Changed());
EXPECT_THAT(r1.replacement(), EXPECT_THAT(r1.replacement(),
IsStoreField(AccessBuilder::ForContextSlot(index), context, IsStoreField(AccessBuilder::ForContextSlot(index), context,
value, effect, control)); value, effect, control));
Reduction const r2 = Reduction const r2 =
Reduce(graph()->NewNode(javascript()->StoreContext(1, index), context, Reduce(graph()->NewNode(javascript()->StoreContext(1, index), value,
value, context, effect, control)); context, effect, control));
ASSERT_TRUE(r2.Changed()); ASSERT_TRUE(r2.Changed());
EXPECT_THAT(r2.replacement(), EXPECT_THAT(r2.replacement(),
IsStoreField(AccessBuilder::ForContextSlot(index), IsStoreField(AccessBuilder::ForContextSlot(index),
......
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