From: danno Date: Mon, 20 Jul 2015 17:15:59 +0000 (-0700) Subject: [turbofan]: Add a context relaxation Reducer X-Git-Tag: upstream/4.7.83~1277 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cca5e74a5814543e7446167ba47bfa498ae10c16;p=platform%2Fupstream%2Fv8.git [turbofan]: Add a context relaxation Reducer In many cases, the context that TurboFan's ASTGraphBuilder or subsequent reduction operations attaches to nodes does not need to be that exact context, but rather only needs to be one with the same native context, because it is used internally only to fetch the native context, e.g. for creating and throwing exceptions. This reducer recognizes common cases where the context that is specified for a node can be relaxed to a canonical, less specific one. This relaxed context can either be the enclosing function's context or a specific Module or Script context that is explicitly created within the function. This optimization is especially important for TurboFan-generated code stubs which use context specialization and inlining to generate optimal code. Without context relaxation, many extraneous moves are generated to pass exactly the right context to internal functions like ToNumber and AllocateHeapNumber, which only need the native context. By turning context relaxation on, these moves disappear because all these common internal context uses are unified to the context passed into the stub function, which is typically already in the correct context register and remains there for short stubs. It also eliminates the explicit use of a specialized context constant in the code stub in these cases, which could cause memory leaks. Review URL: https://codereview.chromium.org/1244583003 Cr-Commit-Position: refs/heads/master@{#29763} --- diff --git a/BUILD.gn b/BUILD.gn index 2f13da3..65e4076 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -715,6 +715,8 @@ source_set("v8_base") { "src/compiler/instruction.h", "src/compiler/js-builtin-reducer.cc", "src/compiler/js-builtin-reducer.h", + "src/compiler/js-context-relaxation.cc", + "src/compiler/js-context-relaxation.h", "src/compiler/js-context-specialization.cc", "src/compiler/js-context-specialization.h", "src/compiler/js-frame-specialization.cc", diff --git a/src/code-stubs.cc b/src/code-stubs.cc index 3b41f9e..5d802bd 100644 --- a/src/code-stubs.cc +++ b/src/code-stubs.cc @@ -506,6 +506,7 @@ Handle TurboFanCodeStub::GenerateCode() { CompilationInfo info(&parse_info); info.SetFunctionType(GetCallInterfaceDescriptor().GetFunctionType()); info.MarkAsContextSpecializing(); + info.MarkAsDeoptimizationEnabled(); info.SetStub(this); return info.GenerateCodeStub(); } diff --git a/src/compiler/ast-graph-builder.cc b/src/compiler/ast-graph-builder.cc index 7d3bab2..67dc0a3 100644 --- a/src/compiler/ast-graph-builder.cc +++ b/src/compiler/ast-graph-builder.cc @@ -449,9 +449,9 @@ AstGraphBuilder::AstGraphBuilder(Zone* local_zone, CompilationInfo* info, liveness_analyzer_(static_cast(info->scope()->num_stack_slots()), local_zone), frame_state_function_info_(common()->CreateFrameStateFunctionInfo( - FrameStateType::kJavaScriptFunction, - info->num_parameters_including_this(), - info->scope()->num_stack_slots(), info->shared_info())), + FrameStateType::kJavaScriptFunction, info->num_parameters() + 1, + info->scope()->num_stack_slots(), info->shared_info(), + CALL_MAINTAINS_NATIVE_CONTEXT)), js_type_feedback_(js_type_feedback) { InitializeAstVisitor(info->isolate(), local_zone); } diff --git a/src/compiler/common-operator.cc b/src/compiler/common-operator.cc index ac1f754..a809cc8 100644 --- a/src/compiler/common-operator.cc +++ b/src/compiler/common-operator.cc @@ -776,9 +776,11 @@ const Operator* CommonOperatorBuilder::ResizeMergeOrPhi(const Operator* op, const FrameStateFunctionInfo* CommonOperatorBuilder::CreateFrameStateFunctionInfo( FrameStateType type, int parameter_count, int local_count, - Handle shared_info) { + Handle shared_info, + ContextCallingMode context_calling_mode) { return new (zone()->New(sizeof(FrameStateFunctionInfo))) - FrameStateFunctionInfo(type, parameter_count, local_count, shared_info); + FrameStateFunctionInfo(type, parameter_count, local_count, shared_info, + context_calling_mode); } } // namespace compiler diff --git a/src/compiler/common-operator.h b/src/compiler/common-operator.h index d9e5f85..cc2ae22 100644 --- a/src/compiler/common-operator.h +++ b/src/compiler/common-operator.h @@ -163,7 +163,8 @@ class CommonOperatorBuilder final : public ZoneObject { // Constructs function info for frame state construction. const FrameStateFunctionInfo* CreateFrameStateFunctionInfo( FrameStateType type, int parameter_count, int local_count, - Handle shared_info); + Handle shared_info, + ContextCallingMode context_calling_mode); private: Zone* zone() const { return zone_; } diff --git a/src/compiler/frame-states.h b/src/compiler/frame-states.h index 42c41f9..328679f 100644 --- a/src/compiler/frame-states.h +++ b/src/compiler/frame-states.h @@ -76,26 +76,38 @@ enum class FrameStateType { }; +enum ContextCallingMode { + CALL_MAINTAINS_NATIVE_CONTEXT, + CALL_CHANGES_NATIVE_CONTEXT +}; + + class FrameStateFunctionInfo { public: FrameStateFunctionInfo(FrameStateType type, int parameter_count, int local_count, - Handle shared_info) + Handle shared_info, + ContextCallingMode context_calling_mode) : type_(type), parameter_count_(parameter_count), local_count_(local_count), - shared_info_(shared_info) {} + shared_info_(shared_info), + context_calling_mode_(context_calling_mode) {} int local_count() const { return local_count_; } int parameter_count() const { return parameter_count_; } Handle shared_info() const { return shared_info_; } FrameStateType type() const { return type_; } + ContextCallingMode context_calling_mode() const { + return context_calling_mode_; + } private: FrameStateType const type_; int const parameter_count_; int const local_count_; Handle const shared_info_; + ContextCallingMode context_calling_mode_; }; diff --git a/src/compiler/js-context-relaxation.cc b/src/compiler/js-context-relaxation.cc new file mode 100644 index 0000000..0ca3c0c --- /dev/null +++ b/src/compiler/js-context-relaxation.cc @@ -0,0 +1,67 @@ +// Copyright 2014 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "src/compiler/frame-states.h" +#include "src/compiler/js-context-relaxation.h" +#include "src/compiler/js-operator.h" +#include "src/compiler/node.h" +#include "src/compiler/node-properties.h" + +namespace v8 { +namespace internal { +namespace compiler { + +Reduction JSContextRelaxation::Reduce(Node* node) { + switch (node->opcode()) { + case IrOpcode::kJSCallFunction: + case IrOpcode::kJSToNumber: { + Node* frame_state = NodeProperties::GetFrameStateInput(node, 0); + Node* outer_frame = frame_state; + Node* original_context = NodeProperties::GetContextInput(node); + Node* candidate_new_context = original_context; + do { + FrameStateInfo frame_state_info( + OpParameter(outer_frame->op())); + const FrameStateFunctionInfo* function_info = + frame_state_info.function_info(); + if (function_info == nullptr || + (function_info->context_calling_mode() == + CALL_CHANGES_NATIVE_CONTEXT)) { + break; + } + candidate_new_context = outer_frame->InputAt(kFrameStateContextInput); + outer_frame = outer_frame->InputAt(kFrameStateOuterStateInput); + } while (outer_frame->opcode() == IrOpcode::kFrameState); + + while (true) { + switch (candidate_new_context->opcode()) { + case IrOpcode::kParameter: + case IrOpcode::kJSCreateModuleContext: + case IrOpcode::kJSCreateScriptContext: + if (candidate_new_context != original_context) { + NodeProperties::ReplaceContextInput(node, candidate_new_context); + return Changed(node); + } else { + return NoChange(); + } + case IrOpcode::kJSCreateCatchContext: + case IrOpcode::kJSCreateWithContext: + case IrOpcode::kJSCreateBlockContext: + candidate_new_context = + NodeProperties::GetContextInput(candidate_new_context); + break; + default: + return NoChange(); + } + } + } + default: + break; + } + return NoChange(); +} + +} // namespace compiler +} // namespace internal +} // namespace v8 diff --git a/src/compiler/js-context-relaxation.h b/src/compiler/js-context-relaxation.h new file mode 100644 index 0000000..4320e92 --- /dev/null +++ b/src/compiler/js-context-relaxation.h @@ -0,0 +1,32 @@ +// Copyright 2014 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef V8_COMPILER_JS_CONTEXT_RELAXATION_H_ +#define V8_COMPILER_JS_CONTEXT_RELAXATION_H_ + +#include "src/compiler/graph-reducer.h" + +namespace v8 { +namespace internal { +namespace compiler { + +// Ensures that operations that only need to access the native context use the +// outer-most context rather than the specific context given by the AST graph +// builder. This makes it possible to use these operations with context +// specialization (e.g. for generating stubs) without forcing inner contexts to +// be embedded in generated code thus causing leaks and potentially using the +// wrong native context (i.e. stubs are shared between native contexts). +class JSContextRelaxation final : public Reducer { + public: + JSContextRelaxation() {} + ~JSContextRelaxation() final {} + + Reduction Reduce(Node* node) final; +}; + +} // namespace compiler +} // namespace internal +} // namespace v8 + +#endif // V8_COMPILER_JS_CONTEXT_RELAXATION_H_ diff --git a/src/compiler/js-inlining.cc b/src/compiler/js-inlining.cc index 058a364..a17eeab 100644 --- a/src/compiler/js-inlining.cc +++ b/src/compiler/js-inlining.cc @@ -214,7 +214,8 @@ Node* JSInliner::CreateArgumentsAdaptorFrameState( const FrameStateFunctionInfo* state_info = jsgraph_->common()->CreateFrameStateFunctionInfo( FrameStateType::kArgumentsAdaptor, - static_cast(call->formal_arguments()) + 1, 0, shared_info); + static_cast(call->formal_arguments()) + 1, 0, shared_info, + CALL_MAINTAINS_NATIVE_CONTEXT); const Operator* op = jsgraph_->common()->FrameState( BailoutId(-1), OutputFrameStateCombine::Ignore(), state_info); diff --git a/src/compiler/pipeline.cc b/src/compiler/pipeline.cc index 04301c8..d2c5fa6 100644 --- a/src/compiler/pipeline.cc +++ b/src/compiler/pipeline.cc @@ -25,6 +25,7 @@ #include "src/compiler/instruction.h" #include "src/compiler/instruction-selector.h" #include "src/compiler/js-builtin-reducer.h" +#include "src/compiler/js-context-relaxation.h" #include "src/compiler/js-context-specialization.h" #include "src/compiler/js-frame-specialization.h" #include "src/compiler/js-generic-lowering.h" @@ -704,6 +705,7 @@ struct GenericLoweringPhase { void Run(PipelineData* data, Zone* temp_zone) { JSGraphReducer graph_reducer(data->jsgraph(), temp_zone); + JSContextRelaxation context_relaxing; DeadCodeElimination dead_code_elimination(&graph_reducer, data->graph(), data->common()); CommonOperatorReducer common_reducer(&graph_reducer, data->graph(), @@ -713,6 +715,7 @@ struct GenericLoweringPhase { SelectLowering select_lowering(data->jsgraph()->graph(), data->jsgraph()->common()); TailCallOptimization tco(data->common(), data->graph()); + AddReducer(data, &graph_reducer, &context_relaxing); AddReducer(data, &graph_reducer, &dead_code_elimination); AddReducer(data, &graph_reducer, &common_reducer); AddReducer(data, &graph_reducer, &generic_lowering); diff --git a/test/unittests/compiler/instruction-selector-unittest.cc b/test/unittests/compiler/instruction-selector-unittest.cc index acab91b..1636b7e 100644 --- a/test/unittests/compiler/instruction-selector-unittest.cc +++ b/test/unittests/compiler/instruction-selector-unittest.cc @@ -153,7 +153,7 @@ InstructionSelectorTest::StreamBuilder::GetFrameStateFunctionInfo( int parameter_count, int local_count) { return common()->CreateFrameStateFunctionInfo( FrameStateType::kJavaScriptFunction, parameter_count, local_count, - Handle()); + Handle(), CALL_MAINTAINS_NATIVE_CONTEXT); } diff --git a/test/unittests/compiler/js-context-relaxation-unittest.cc b/test/unittests/compiler/js-context-relaxation-unittest.cc new file mode 100644 index 0000000..b52417d --- /dev/null +++ b/test/unittests/compiler/js-context-relaxation-unittest.cc @@ -0,0 +1,306 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "src/compiler/js-context-relaxation.h" +#include "src/compiler/js-graph.h" +#include "test/unittests/compiler/graph-unittest.h" +#include "test/unittests/compiler/node-test-utils.h" + +namespace v8 { +namespace internal { +namespace compiler { + +class JSContextRelaxationTest : public GraphTest { + public: + JSContextRelaxationTest() : GraphTest(3), javascript_(zone()) {} + ~JSContextRelaxationTest() override {} + + protected: + Reduction Reduce(Node* node, MachineOperatorBuilder::Flags flags = + MachineOperatorBuilder::kNoFlags) { + MachineOperatorBuilder machine(zone(), kMachPtr, flags); + JSGraph jsgraph(isolate(), graph(), common(), javascript(), &machine); + // TODO(titzer): mock the GraphReducer here for better unit testing. + GraphReducer graph_reducer(zone(), graph()); + JSContextRelaxation reducer; + return reducer.Reduce(node); + } + + Node* EmptyFrameState() { + MachineOperatorBuilder machine(zone()); + JSGraph jsgraph(isolate(), graph(), common(), javascript(), &machine); + return jsgraph.EmptyFrameState(); + } + + Node* ShallowFrameStateChain(Node* outer_context, + ContextCallingMode context_calling_mode) { + const FrameStateFunctionInfo* const frame_state_function_info = + common()->CreateFrameStateFunctionInfo( + FrameStateType::kJavaScriptFunction, 3, 0, + Handle(), context_calling_mode); + const Operator* op = common()->FrameState(BailoutId::None(), + OutputFrameStateCombine::Ignore(), + frame_state_function_info); + return graph()->NewNode(op, graph()->start(), graph()->start(), + graph()->start(), outer_context, graph()->start(), + graph()->start()); + } + + Node* DeepFrameStateChain(Node* outer_context, + ContextCallingMode context_calling_mode) { + const FrameStateFunctionInfo* const frame_state_function_info = + common()->CreateFrameStateFunctionInfo( + FrameStateType::kJavaScriptFunction, 3, 0, + Handle(), context_calling_mode); + const Operator* op = common()->FrameState(BailoutId::None(), + OutputFrameStateCombine::Ignore(), + frame_state_function_info); + Node* shallow_frame_state = + ShallowFrameStateChain(outer_context, CALL_MAINTAINS_NATIVE_CONTEXT); + return graph()->NewNode(op, graph()->start(), graph()->start(), + graph()->start(), graph()->start(), + graph()->start(), shallow_frame_state); + } + + JSOperatorBuilder* javascript() { return &javascript_; } + + private: + JSOperatorBuilder javascript_; +}; + + +TEST_F(JSContextRelaxationTest, + RelaxJSCallFunctionShallowFrameStateChainNoCrossCtx) { + Node* const input0 = Parameter(0); + Node* const input1 = Parameter(1); + Node* const context = Parameter(2); + Node* const outer_context = Parameter(3); + Node* const frame_state = + ShallowFrameStateChain(outer_context, CALL_MAINTAINS_NATIVE_CONTEXT); + Node* const effect = graph()->start(); + Node* const control = graph()->start(); + Node* node = + graph()->NewNode(javascript()->CallFunction(2, NO_CALL_FUNCTION_FLAGS, + STRICT, VectorSlotPair()), + input0, input1, context, frame_state, effect, control); + Reduction const r = Reduce(node); + EXPECT_TRUE(r.Changed()); + EXPECT_EQ(outer_context, NodeProperties::GetContextInput(node)); +} + +TEST_F(JSContextRelaxationTest, + RelaxJSCallFunctionShallowFrameStateChainCrossCtx) { + Node* const input0 = Parameter(0); + Node* const input1 = Parameter(1); + Node* const context = Parameter(2); + Node* const outer_context = Parameter(3); + Node* const frame_state = + ShallowFrameStateChain(outer_context, CALL_CHANGES_NATIVE_CONTEXT); + Node* const effect = graph()->start(); + Node* const control = graph()->start(); + Node* node = + graph()->NewNode(javascript()->CallFunction(2, NO_CALL_FUNCTION_FLAGS, + STRICT, VectorSlotPair()), + input0, input1, context, frame_state, effect, control); + Reduction const r = Reduce(node); + EXPECT_FALSE(r.Changed()); + EXPECT_EQ(context, NodeProperties::GetContextInput(node)); +} + +TEST_F(JSContextRelaxationTest, + RelaxJSCallFunctionDeepFrameStateChainNoCrossCtx) { + Node* const input0 = Parameter(0); + Node* const input1 = Parameter(1); + Node* const context = Parameter(2); + Node* const outer_context = Parameter(3); + Node* const frame_state = + DeepFrameStateChain(outer_context, CALL_MAINTAINS_NATIVE_CONTEXT); + Node* const effect = graph()->start(); + Node* const control = graph()->start(); + Node* node = + graph()->NewNode(javascript()->CallFunction(2, NO_CALL_FUNCTION_FLAGS, + STRICT, VectorSlotPair()), + input0, input1, context, frame_state, effect, control); + Reduction const r = Reduce(node); + EXPECT_TRUE(r.Changed()); + EXPECT_EQ(outer_context, NodeProperties::GetContextInput(node)); +} + +TEST_F(JSContextRelaxationTest, + RelaxJSCallFunctionDeepFrameStateChainCrossCtx) { + Node* const input0 = Parameter(0); + Node* const input1 = Parameter(1); + Node* const context = Parameter(2); + Node* const outer_context = Parameter(3); + Node* const frame_state = + DeepFrameStateChain(outer_context, CALL_CHANGES_NATIVE_CONTEXT); + Node* const effect = graph()->start(); + Node* const control = graph()->start(); + Node* node = + graph()->NewNode(javascript()->CallFunction(2, NO_CALL_FUNCTION_FLAGS, + STRICT, VectorSlotPair()), + input0, input1, context, frame_state, effect, control); + Reduction const r = Reduce(node); + EXPECT_FALSE(r.Changed()); + EXPECT_EQ(context, NodeProperties::GetContextInput(node)); +} + +TEST_F(JSContextRelaxationTest, + RelaxJSCallFunctionDeepContextChainFullRelaxForCatch) { + Node* const input0 = Parameter(0); + Node* const input1 = Parameter(1); + Node* const context = Parameter(2); + Node* const outer_context = Parameter(3); + const Operator* op = javascript()->CreateCatchContext(Unique()); + Node* const frame_state_1 = + ShallowFrameStateChain(outer_context, CALL_MAINTAINS_NATIVE_CONTEXT); + Node* const effect = graph()->start(); + Node* const control = graph()->start(); + Node* nested_context = + graph()->NewNode(op, graph()->start(), graph()->start(), outer_context, + frame_state_1, effect, control); + Node* const frame_state_2 = + ShallowFrameStateChain(nested_context, CALL_MAINTAINS_NATIVE_CONTEXT); + Node* node = + graph()->NewNode(javascript()->CallFunction(2, NO_CALL_FUNCTION_FLAGS, + STRICT, VectorSlotPair()), + input0, input1, context, frame_state_2, effect, control); + Reduction const r = Reduce(node); + EXPECT_TRUE(r.Changed()); + EXPECT_EQ(outer_context, NodeProperties::GetContextInput(node)); +} + + +TEST_F(JSContextRelaxationTest, + RelaxJSCallFunctionDeepContextChainFullRelaxForWith) { + Node* const input0 = Parameter(0); + Node* const input1 = Parameter(1); + Node* const context = Parameter(2); + Node* const outer_context = Parameter(3); + const Operator* op = javascript()->CreateWithContext(); + Node* const frame_state_1 = + ShallowFrameStateChain(outer_context, CALL_MAINTAINS_NATIVE_CONTEXT); + Node* const effect = graph()->start(); + Node* const control = graph()->start(); + Node* nested_context = + graph()->NewNode(op, graph()->start(), graph()->start(), outer_context, + frame_state_1, effect, control); + Node* const frame_state_2 = + ShallowFrameStateChain(nested_context, CALL_MAINTAINS_NATIVE_CONTEXT); + Node* node = + graph()->NewNode(javascript()->CallFunction(2, NO_CALL_FUNCTION_FLAGS, + STRICT, VectorSlotPair()), + input0, input1, context, frame_state_2, effect, control); + Reduction const r = Reduce(node); + EXPECT_TRUE(r.Changed()); + EXPECT_EQ(outer_context, NodeProperties::GetContextInput(node)); +} + + +TEST_F(JSContextRelaxationTest, + RelaxJSCallFunctionDeepContextChainFullRelaxForBlock) { + Node* const input0 = Parameter(0); + Node* const input1 = Parameter(1); + Node* const context = Parameter(2); + Node* const outer_context = Parameter(3); + const Operator* op = javascript()->CreateBlockContext(); + Node* const frame_state_1 = + ShallowFrameStateChain(outer_context, CALL_MAINTAINS_NATIVE_CONTEXT); + Node* const effect = graph()->start(); + Node* const control = graph()->start(); + Node* nested_context = + graph()->NewNode(op, graph()->start(), graph()->start(), outer_context, + frame_state_1, effect, control); + Node* const frame_state_2 = + ShallowFrameStateChain(nested_context, CALL_MAINTAINS_NATIVE_CONTEXT); + Node* node = + graph()->NewNode(javascript()->CallFunction(2, NO_CALL_FUNCTION_FLAGS, + STRICT, VectorSlotPair()), + input0, input1, context, frame_state_2, effect, control); + Reduction const r = Reduce(node); + EXPECT_TRUE(r.Changed()); + EXPECT_EQ(outer_context, NodeProperties::GetContextInput(node)); +} + + +TEST_F(JSContextRelaxationTest, + RelaxJSCallFunctionDeepContextChainPartialRelaxForScript) { + Node* const input0 = Parameter(0); + Node* const input1 = Parameter(1); + Node* const context = Parameter(2); + Node* const outer_context = Parameter(3); + const Operator* op = javascript()->CreateScriptContext(); + Node* const frame_state_1 = + ShallowFrameStateChain(outer_context, CALL_MAINTAINS_NATIVE_CONTEXT); + Node* const effect = graph()->start(); + Node* const control = graph()->start(); + Node* nested_context = + graph()->NewNode(op, graph()->start(), graph()->start(), outer_context, + frame_state_1, effect, control); + Node* const frame_state_2 = + ShallowFrameStateChain(nested_context, CALL_MAINTAINS_NATIVE_CONTEXT); + Node* node = + graph()->NewNode(javascript()->CallFunction(2, NO_CALL_FUNCTION_FLAGS, + STRICT, VectorSlotPair()), + input0, input1, context, frame_state_2, effect, control); + Reduction const r = Reduce(node); + EXPECT_TRUE(r.Changed()); + EXPECT_EQ(nested_context, NodeProperties::GetContextInput(node)); +} + + +TEST_F(JSContextRelaxationTest, + RelaxJSCallFunctionDeepContextChainPartialRelaxForModule) { + Node* const input0 = Parameter(0); + Node* const input1 = Parameter(1); + Node* const context = Parameter(2); + Node* const outer_context = Parameter(3); + const Operator* op = javascript()->CreateModuleContext(); + Node* const frame_state_1 = + ShallowFrameStateChain(outer_context, CALL_MAINTAINS_NATIVE_CONTEXT); + Node* const effect = graph()->start(); + Node* const control = graph()->start(); + Node* nested_context = + graph()->NewNode(op, graph()->start(), graph()->start(), outer_context, + frame_state_1, effect, control); + Node* const frame_state_2 = + ShallowFrameStateChain(nested_context, CALL_MAINTAINS_NATIVE_CONTEXT); + Node* node = + graph()->NewNode(javascript()->CallFunction(2, NO_CALL_FUNCTION_FLAGS, + STRICT, VectorSlotPair()), + input0, input1, context, frame_state_2, effect, control); + Reduction const r = Reduce(node); + EXPECT_TRUE(r.Changed()); + EXPECT_EQ(nested_context, NodeProperties::GetContextInput(node)); +} + + +TEST_F(JSContextRelaxationTest, + RelaxJSCallFunctionDeepContextChainPartialNoRelax) { + Node* const input0 = Parameter(0); + Node* const input1 = Parameter(1); + Node* const context = Parameter(2); + Node* const outer_context = Parameter(3); + const Operator* op = javascript()->CreateFunctionContext(); + Node* const frame_state_1 = + ShallowFrameStateChain(outer_context, CALL_MAINTAINS_NATIVE_CONTEXT); + Node* const effect = graph()->start(); + Node* const control = graph()->start(); + Node* nested_context = + graph()->NewNode(op, graph()->start(), graph()->start(), outer_context, + frame_state_1, effect, control); + Node* const frame_state_2 = + ShallowFrameStateChain(nested_context, CALL_MAINTAINS_NATIVE_CONTEXT); + Node* node = + graph()->NewNode(javascript()->CallFunction(2, NO_CALL_FUNCTION_FLAGS, + STRICT, VectorSlotPair()), + input0, input1, context, frame_state_2, effect, control); + Reduction const r = Reduce(node); + EXPECT_FALSE(r.Changed()); + EXPECT_EQ(context, NodeProperties::GetContextInput(node)); +} + +} // namespace compiler +} // namespace internal +} // namespace v8 diff --git a/test/unittests/compiler/liveness-analyzer-unittest.cc b/test/unittests/compiler/liveness-analyzer-unittest.cc index 1e14255..3c94c25 100644 --- a/test/unittests/compiler/liveness-analyzer-unittest.cc +++ b/test/unittests/compiler/liveness-analyzer-unittest.cc @@ -60,7 +60,7 @@ class LivenessAnalysisTest : public GraphTest { const FrameStateFunctionInfo* state_info = common()->CreateFrameStateFunctionInfo( FrameStateType::kJavaScriptFunction, 0, locals_count_, - Handle()); + Handle(), CALL_MAINTAINS_NATIVE_CONTEXT); const Operator* op = common()->FrameState( BailoutId(ast_num), OutputFrameStateCombine::Ignore(), state_info); diff --git a/test/unittests/unittests.gyp b/test/unittests/unittests.gyp index 1b73f20..b255575 100644 --- a/test/unittests/unittests.gyp +++ b/test/unittests/unittests.gyp @@ -60,6 +60,7 @@ 'compiler/instruction-sequence-unittest.cc', 'compiler/instruction-sequence-unittest.h', 'compiler/js-builtin-reducer-unittest.cc', + 'compiler/js-context-relaxation-unittest.cc', 'compiler/js-intrinsic-lowering-unittest.cc', 'compiler/js-operator-unittest.cc', 'compiler/js-typed-lowering-unittest.cc', diff --git a/tools/gyp/v8.gyp b/tools/gyp/v8.gyp index d2619f7..399f07d 100644 --- a/tools/gyp/v8.gyp +++ b/tools/gyp/v8.gyp @@ -507,6 +507,8 @@ '../../src/compiler/instruction.h', '../../src/compiler/js-builtin-reducer.cc', '../../src/compiler/js-builtin-reducer.h', + '../../src/compiler/js-context-relaxation.cc', + '../../src/compiler/js-context-relaxation.h', '../../src/compiler/js-context-specialization.cc', '../../src/compiler/js-context-specialization.h', '../../src/compiler/js-frame-specialization.cc',