[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}
2015-07-20 17:15:59 +00:00
|
|
|
// 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);
|
2015-10-16 12:38:46 +00:00
|
|
|
JSGraph jsgraph(isolate(), graph(), common(), javascript(), nullptr,
|
|
|
|
&machine);
|
[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}
2015-07-20 17:15:59 +00:00
|
|
|
// 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());
|
2015-10-16 12:38:46 +00:00
|
|
|
JSGraph jsgraph(isolate(), graph(), common(), javascript(), nullptr,
|
|
|
|
&machine);
|
[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}
2015-07-20 17:15:59 +00:00
|
|
|
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<SharedFunctionInfo>(), 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<SharedFunctionInfo>(), 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();
|
2015-10-30 06:58:56 +00:00
|
|
|
Node* node = graph()->NewNode(
|
2015-11-04 15:04:19 +00:00
|
|
|
javascript()->CallFunction(2, STRICT, VectorSlotPair()), input0, input1,
|
|
|
|
context, frame_state, frame_state, effect, control);
|
[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}
2015-07-20 17:15:59 +00:00
|
|
|
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();
|
2015-10-30 06:58:56 +00:00
|
|
|
Node* node = graph()->NewNode(
|
2015-11-04 15:04:19 +00:00
|
|
|
javascript()->CallFunction(2, STRICT, VectorSlotPair()), input0, input1,
|
|
|
|
context, frame_state, frame_state, effect, control);
|
[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}
2015-07-20 17:15:59 +00:00
|
|
|
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();
|
2015-10-30 06:58:56 +00:00
|
|
|
Node* node = graph()->NewNode(
|
2015-11-04 15:04:19 +00:00
|
|
|
javascript()->CallFunction(2, STRICT, VectorSlotPair()), input0, input1,
|
|
|
|
context, frame_state, frame_state, effect, control);
|
[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}
2015-07-20 17:15:59 +00:00
|
|
|
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();
|
2015-10-30 06:58:56 +00:00
|
|
|
Node* node = graph()->NewNode(
|
2015-11-04 15:04:19 +00:00
|
|
|
javascript()->CallFunction(2, STRICT, VectorSlotPair()), input0, input1,
|
|
|
|
context, frame_state, frame_state, effect, control);
|
[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}
2015-07-20 17:15:59 +00:00
|
|
|
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);
|
2015-08-31 08:24:52 +00:00
|
|
|
const Operator* op = javascript()->CreateCatchContext(Handle<String>());
|
[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}
2015-07-20 17:15:59 +00:00
|
|
|
Node* const effect = graph()->start();
|
|
|
|
Node* const control = graph()->start();
|
2015-09-23 09:08:15 +00:00
|
|
|
Node* nested_context = graph()->NewNode(
|
|
|
|
op, graph()->start(), graph()->start(), outer_context, effect, control);
|
[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}
2015-07-20 17:15:59 +00:00
|
|
|
Node* const frame_state_2 =
|
|
|
|
ShallowFrameStateChain(nested_context, CALL_MAINTAINS_NATIVE_CONTEXT);
|
2015-10-30 06:58:56 +00:00
|
|
|
Node* node = graph()->NewNode(
|
2015-11-04 15:04:19 +00:00
|
|
|
javascript()->CallFunction(2, STRICT, VectorSlotPair()), input0, input1,
|
|
|
|
context, frame_state_2, frame_state_2, effect, control);
|
[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}
2015-07-20 17:15:59 +00:00
|
|
|
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);
|
2015-10-30 06:58:56 +00:00
|
|
|
Node* node = graph()->NewNode(
|
2015-11-04 15:04:19 +00:00
|
|
|
javascript()->CallFunction(2, STRICT, VectorSlotPair()), input0, input1,
|
|
|
|
context, frame_state_2, frame_state_2, effect, control);
|
[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}
2015-07-20 17:15:59 +00:00
|
|
|
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);
|
2015-09-29 15:53:08 +00:00
|
|
|
Handle<ScopeInfo> scope_info = Handle<ScopeInfo>::null();
|
|
|
|
const Operator* op = javascript()->CreateBlockContext(scope_info);
|
[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}
2015-07-20 17:15:59 +00:00
|
|
|
Node* const effect = graph()->start();
|
|
|
|
Node* const control = graph()->start();
|
2015-09-29 15:53:08 +00:00
|
|
|
Node* nested_context =
|
|
|
|
graph()->NewNode(op, graph()->start(), outer_context, effect, control);
|
[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}
2015-07-20 17:15:59 +00:00
|
|
|
Node* const frame_state_2 =
|
|
|
|
ShallowFrameStateChain(nested_context, CALL_MAINTAINS_NATIVE_CONTEXT);
|
2015-10-30 06:58:56 +00:00
|
|
|
Node* node = graph()->NewNode(
|
2015-11-04 15:04:19 +00:00
|
|
|
javascript()->CallFunction(2, STRICT, VectorSlotPair()), input0, input1,
|
|
|
|
context, frame_state_2, frame_state_2, effect, control);
|
[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}
2015-07-20 17:15:59 +00:00
|
|
|
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);
|
2015-09-29 15:53:08 +00:00
|
|
|
Handle<ScopeInfo> scope_info = Handle<ScopeInfo>::null();
|
|
|
|
const Operator* op = javascript()->CreateScriptContext(scope_info);
|
[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}
2015-07-20 17:15:59 +00:00
|
|
|
Node* const frame_state_1 =
|
|
|
|
ShallowFrameStateChain(outer_context, CALL_MAINTAINS_NATIVE_CONTEXT);
|
|
|
|
Node* const effect = graph()->start();
|
|
|
|
Node* const control = graph()->start();
|
2015-09-29 15:53:08 +00:00
|
|
|
Node* nested_context = graph()->NewNode(op, graph()->start(), outer_context,
|
|
|
|
frame_state_1, effect, control);
|
[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}
2015-07-20 17:15:59 +00:00
|
|
|
Node* const frame_state_2 =
|
|
|
|
ShallowFrameStateChain(nested_context, CALL_MAINTAINS_NATIVE_CONTEXT);
|
2015-10-30 06:58:56 +00:00
|
|
|
Node* node = graph()->NewNode(
|
2015-11-04 15:04:19 +00:00
|
|
|
javascript()->CallFunction(2, STRICT, VectorSlotPair()), input0, input1,
|
|
|
|
context, frame_state_2, frame_state_2, effect, control);
|
[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}
2015-07-20 17:15:59 +00:00
|
|
|
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 effect = graph()->start();
|
|
|
|
Node* const control = graph()->start();
|
2015-09-23 09:08:15 +00:00
|
|
|
Node* nested_context = graph()->NewNode(
|
|
|
|
op, graph()->start(), graph()->start(), outer_context, effect, control);
|
[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}
2015-07-20 17:15:59 +00:00
|
|
|
Node* const frame_state_2 =
|
|
|
|
ShallowFrameStateChain(nested_context, CALL_MAINTAINS_NATIVE_CONTEXT);
|
2015-10-30 06:58:56 +00:00
|
|
|
Node* node = graph()->NewNode(
|
2015-11-04 15:04:19 +00:00
|
|
|
javascript()->CallFunction(2, STRICT, VectorSlotPair()), input0, input1,
|
|
|
|
context, frame_state_2, frame_state_2, effect, control);
|
[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}
2015-07-20 17:15:59 +00:00
|
|
|
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);
|
2015-10-02 09:30:15 +00:00
|
|
|
const Operator* op = javascript()->CreateFunctionContext(0);
|
[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}
2015-07-20 17:15:59 +00:00
|
|
|
Node* const effect = graph()->start();
|
|
|
|
Node* const control = graph()->start();
|
|
|
|
Node* nested_context =
|
2015-09-23 09:08:15 +00:00
|
|
|
graph()->NewNode(op, graph()->start(), outer_context, effect, control);
|
[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}
2015-07-20 17:15:59 +00:00
|
|
|
Node* const frame_state_2 =
|
|
|
|
ShallowFrameStateChain(nested_context, CALL_MAINTAINS_NATIVE_CONTEXT);
|
2015-10-30 06:58:56 +00:00
|
|
|
Node* node = graph()->NewNode(
|
2015-11-04 15:04:19 +00:00
|
|
|
javascript()->CallFunction(2, STRICT, VectorSlotPair()), input0, input1,
|
|
|
|
context, frame_state_2, frame_state_2, effect, control);
|
[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}
2015-07-20 17:15:59 +00:00
|
|
|
Reduction const r = Reduce(node);
|
|
|
|
EXPECT_FALSE(r.Changed());
|
|
|
|
EXPECT_EQ(context, NodeProperties::GetContextInput(node));
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace compiler
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|