2016-02-08 12:33:44 +00:00
|
|
|
// Copyright 2016 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-create-lowering.h"
|
|
|
|
#include "src/code-factory.h"
|
|
|
|
#include "src/compiler/access-builder.h"
|
2018-07-06 11:05:49 +00:00
|
|
|
#include "src/compiler/compilation-dependencies.h"
|
2016-02-08 12:33:44 +00:00
|
|
|
#include "src/compiler/js-graph.h"
|
|
|
|
#include "src/compiler/js-operator.h"
|
|
|
|
#include "src/compiler/machine-operator.h"
|
|
|
|
#include "src/compiler/node-properties.h"
|
|
|
|
#include "src/compiler/operator-properties.h"
|
2017-02-07 14:05:02 +00:00
|
|
|
#include "src/feedback-vector.h"
|
2016-02-08 12:33:44 +00:00
|
|
|
#include "src/isolate-inl.h"
|
2018-05-23 13:29:02 +00:00
|
|
|
#include "src/objects/arguments.h"
|
2016-02-08 12:33:44 +00:00
|
|
|
#include "test/unittests/compiler/compiler-test-utils.h"
|
|
|
|
#include "test/unittests/compiler/graph-unittest.h"
|
|
|
|
#include "test/unittests/compiler/node-test-utils.h"
|
|
|
|
#include "testing/gmock-support.h"
|
|
|
|
|
|
|
|
using testing::_;
|
|
|
|
using testing::BitEq;
|
|
|
|
using testing::IsNaN;
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace compiler {
|
|
|
|
|
|
|
|
class JSCreateLoweringTest : public TypedGraphTest {
|
|
|
|
public:
|
|
|
|
JSCreateLoweringTest()
|
2018-07-09 08:22:14 +00:00
|
|
|
: TypedGraphTest(3),
|
|
|
|
javascript_(zone()),
|
|
|
|
deps_(isolate(), zone()),
|
2018-08-30 10:22:27 +00:00
|
|
|
handle_scope_(isolate()) {
|
|
|
|
}
|
2018-09-17 11:30:48 +00:00
|
|
|
~JSCreateLoweringTest() override = default;
|
2016-02-08 12:33:44 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
Reduction Reduce(Node* node) {
|
|
|
|
MachineOperatorBuilder machine(zone());
|
|
|
|
SimplifiedOperatorBuilder simplified(zone());
|
|
|
|
JSGraph jsgraph(isolate(), graph(), common(), javascript(), &simplified,
|
|
|
|
&machine);
|
|
|
|
// TODO(titzer): mock the GraphReducer here for better unit testing.
|
|
|
|
GraphReducer graph_reducer(zone(), graph());
|
2018-10-12 09:18:57 +00:00
|
|
|
JSCreateLowering reducer(&graph_reducer, &deps_, &jsgraph, broker(),
|
2018-09-19 09:23:17 +00:00
|
|
|
zone());
|
2016-02-08 12:33:44 +00:00
|
|
|
return reducer.Reduce(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
Node* FrameState(Handle<SharedFunctionInfo> shared, Node* outer_frame_state) {
|
2017-01-05 10:44:44 +00:00
|
|
|
Node* state_values =
|
|
|
|
graph()->NewNode(common()->StateValues(0, SparseInputMask::Dense()));
|
2016-02-08 12:33:44 +00:00
|
|
|
return graph()->NewNode(
|
[turbofan] Remove the JSContextRelaxation reducer.
This reducer doesn't really add value, because:
(a) it is only concerned with JSCallFunction and JSToNumber, but when
we get to it, all JSCallFunction nodes will have been replaced by
Call nodes, and in the not so far future, we will also have
replaced almost all JSToNumber nodes with better code,
(b) and the reducer tries to be smart and use one of the outermost
contexts, but that might not be beneficial always; actually it
might even create longer live ranges and lead to more spilling
in some cases.
But most importantly, the JSContextRelaxation currently blocks inlining
based on SharedFunctionInfo, because it requires the inliner to check
the native context, which in turn requires JSFunction knowledge. So I'm
removing this reducer for now to unblock the more important inliner
changes.
R=jarin@chromium.org
Review URL: https://codereview.chromium.org/1715633002
Cr-Commit-Position: refs/heads/master@{#34139}
2016-02-19 07:55:26 +00:00
|
|
|
common()->FrameState(
|
|
|
|
BailoutId::None(), OutputFrameStateCombine::Ignore(),
|
|
|
|
common()->CreateFrameStateFunctionInfo(
|
2017-06-14 11:21:43 +00:00
|
|
|
FrameStateType::kInterpretedFunction, 1, 0, shared)),
|
2016-02-08 12:33:44 +00:00
|
|
|
state_values, state_values, state_values, NumberConstant(0),
|
|
|
|
UndefinedConstant(), outer_frame_state);
|
|
|
|
}
|
|
|
|
|
|
|
|
JSOperatorBuilder* javascript() { return &javascript_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
JSOperatorBuilder javascript_;
|
|
|
|
CompilationDependencies deps_;
|
2018-07-09 08:22:14 +00:00
|
|
|
CanonicalHandleScope handle_scope_;
|
2016-02-08 12:33:44 +00:00
|
|
|
};
|
|
|
|
|
2017-02-07 09:00:18 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// JSCreate
|
|
|
|
|
2016-02-08 12:33:44 +00:00
|
|
|
TEST_F(JSCreateLoweringTest, JSCreate) {
|
|
|
|
Handle<JSFunction> function = isolate()->object_function();
|
2018-10-12 09:18:57 +00:00
|
|
|
Node* const target =
|
|
|
|
Parameter(Type::HeapConstant(broker(), function, graph()->zone()));
|
2016-02-08 12:33:44 +00:00
|
|
|
Node* const context = Parameter(Type::Any());
|
|
|
|
Node* const effect = graph()->start();
|
2017-02-07 09:00:18 +00:00
|
|
|
Node* const control = graph()->start();
|
|
|
|
Reduction r =
|
|
|
|
Reduce(graph()->NewNode(javascript()->Create(), target, target, context,
|
|
|
|
EmptyFrameState(), effect, control));
|
2016-02-08 12:33:44 +00:00
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(
|
|
|
|
r.replacement(),
|
|
|
|
IsFinishRegion(
|
|
|
|
IsAllocate(IsNumberConstant(function->initial_map()->instance_size()),
|
2017-02-07 09:00:18 +00:00
|
|
|
IsBeginRegion(effect), control),
|
2016-02-08 12:33:44 +00:00
|
|
|
_));
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// JSCreateArguments
|
|
|
|
|
|
|
|
TEST_F(JSCreateLoweringTest, JSCreateArgumentsInlinedMapped) {
|
|
|
|
Node* const closure = Parameter(Type::Any());
|
|
|
|
Node* const context = UndefinedConstant();
|
|
|
|
Node* const effect = graph()->start();
|
2018-07-05 20:34:14 +00:00
|
|
|
Handle<SharedFunctionInfo> shared(isolate()->regexp_function()->shared(),
|
2018-06-26 10:14:12 +00:00
|
|
|
isolate());
|
2016-02-08 12:33:44 +00:00
|
|
|
Node* const frame_state_outer = FrameState(shared, graph()->start());
|
|
|
|
Node* const frame_state_inner = FrameState(shared, frame_state_outer);
|
|
|
|
Reduction r = Reduce(graph()->NewNode(
|
|
|
|
javascript()->CreateArguments(CreateArgumentsType::kMappedArguments),
|
2016-05-11 06:10:46 +00:00
|
|
|
closure, context, frame_state_inner, effect));
|
2016-02-08 12:33:44 +00:00
|
|
|
ASSERT_TRUE(r.Changed());
|
2016-05-11 06:10:46 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
r.replacement(),
|
|
|
|
IsFinishRegion(
|
|
|
|
IsAllocate(IsNumberConstant(JSSloppyArgumentsObject::kSize), _, _),
|
|
|
|
_));
|
2016-02-08 12:33:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(JSCreateLoweringTest, JSCreateArgumentsInlinedUnmapped) {
|
|
|
|
Node* const closure = Parameter(Type::Any());
|
|
|
|
Node* const context = UndefinedConstant();
|
|
|
|
Node* const effect = graph()->start();
|
2018-07-05 20:34:14 +00:00
|
|
|
Handle<SharedFunctionInfo> shared(isolate()->regexp_function()->shared(),
|
2018-06-26 10:14:12 +00:00
|
|
|
isolate());
|
2016-02-08 12:33:44 +00:00
|
|
|
Node* const frame_state_outer = FrameState(shared, graph()->start());
|
|
|
|
Node* const frame_state_inner = FrameState(shared, frame_state_outer);
|
|
|
|
Reduction r = Reduce(graph()->NewNode(
|
|
|
|
javascript()->CreateArguments(CreateArgumentsType::kUnmappedArguments),
|
2016-05-11 06:10:46 +00:00
|
|
|
closure, context, frame_state_inner, effect));
|
2016-02-08 12:33:44 +00:00
|
|
|
ASSERT_TRUE(r.Changed());
|
2016-05-11 06:10:46 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
r.replacement(),
|
|
|
|
IsFinishRegion(
|
|
|
|
IsAllocate(IsNumberConstant(JSStrictArgumentsObject::kSize), _, _),
|
|
|
|
_));
|
2016-02-08 12:33:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(JSCreateLoweringTest, JSCreateArgumentsInlinedRestArray) {
|
|
|
|
Node* const closure = Parameter(Type::Any());
|
|
|
|
Node* const context = UndefinedConstant();
|
|
|
|
Node* const effect = graph()->start();
|
2018-07-05 20:34:14 +00:00
|
|
|
Handle<SharedFunctionInfo> shared(isolate()->regexp_function()->shared(),
|
2018-06-26 10:14:12 +00:00
|
|
|
isolate());
|
2016-02-08 12:33:44 +00:00
|
|
|
Node* const frame_state_outer = FrameState(shared, graph()->start());
|
|
|
|
Node* const frame_state_inner = FrameState(shared, frame_state_outer);
|
|
|
|
Reduction r = Reduce(graph()->NewNode(
|
|
|
|
javascript()->CreateArguments(CreateArgumentsType::kRestParameter),
|
2016-05-11 06:10:46 +00:00
|
|
|
closure, context, frame_state_inner, effect));
|
2016-02-08 12:33:44 +00:00
|
|
|
ASSERT_TRUE(r.Changed());
|
2016-05-11 06:10:46 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
r.replacement(),
|
|
|
|
IsFinishRegion(IsAllocate(IsNumberConstant(JSArray::kSize), _, _), _));
|
2016-02-08 12:33:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// JSCreateFunctionContext
|
|
|
|
|
|
|
|
TEST_F(JSCreateLoweringTest, JSCreateFunctionContextViaInlinedAllocation) {
|
|
|
|
Node* const context = Parameter(Type::Any());
|
|
|
|
Node* const effect = graph()->start();
|
|
|
|
Node* const control = graph()->start();
|
2018-05-02 13:57:26 +00:00
|
|
|
Reduction const r = Reduce(graph()->NewNode(
|
2018-06-26 10:14:12 +00:00
|
|
|
javascript()->CreateFunctionContext(
|
|
|
|
handle(ScopeInfo::Empty(isolate()), isolate()), 8, FUNCTION_SCOPE),
|
2018-05-02 13:57:26 +00:00
|
|
|
context, effect, control));
|
2016-02-08 12:33:44 +00:00
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(),
|
|
|
|
IsFinishRegion(IsAllocate(IsNumberConstant(Context::SizeFor(
|
|
|
|
8 + Context::MIN_CONTEXT_SLOTS)),
|
|
|
|
IsBeginRegion(_), control),
|
|
|
|
_));
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// JSCreateWithContext
|
|
|
|
|
|
|
|
TEST_F(JSCreateLoweringTest, JSCreateWithContext) {
|
2018-09-14 13:12:59 +00:00
|
|
|
Handle<ScopeInfo> scope_info = ScopeInfo::CreateForEmptyFunction(isolate());
|
2016-02-08 12:33:44 +00:00
|
|
|
Node* const object = Parameter(Type::Receiver());
|
|
|
|
Node* const context = Parameter(Type::Any());
|
|
|
|
Node* const effect = graph()->start();
|
|
|
|
Node* const control = graph()->start();
|
|
|
|
Reduction r =
|
2016-09-06 08:27:36 +00:00
|
|
|
Reduce(graph()->NewNode(javascript()->CreateWithContext(scope_info),
|
2018-05-02 13:57:26 +00:00
|
|
|
object, context, effect, control));
|
2016-02-08 12:33:44 +00:00
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(),
|
|
|
|
IsFinishRegion(IsAllocate(IsNumberConstant(Context::SizeFor(
|
|
|
|
Context::MIN_CONTEXT_SLOTS)),
|
|
|
|
IsBeginRegion(_), control),
|
|
|
|
_));
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// JSCreateCatchContext
|
|
|
|
|
|
|
|
TEST_F(JSCreateLoweringTest, JSCreateCatchContext) {
|
2018-09-14 13:12:59 +00:00
|
|
|
Handle<ScopeInfo> scope_info = ScopeInfo::CreateForEmptyFunction(isolate());
|
2016-02-08 12:33:44 +00:00
|
|
|
Node* const exception = Parameter(Type::Receiver());
|
|
|
|
Node* const context = Parameter(Type::Any());
|
|
|
|
Node* const effect = graph()->start();
|
|
|
|
Node* const control = graph()->start();
|
2018-05-04 09:29:20 +00:00
|
|
|
Reduction r =
|
|
|
|
Reduce(graph()->NewNode(javascript()->CreateCatchContext(scope_info),
|
|
|
|
exception, context, effect, control));
|
2016-02-08 12:33:44 +00:00
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(),
|
|
|
|
IsFinishRegion(IsAllocate(IsNumberConstant(Context::SizeFor(
|
|
|
|
Context::MIN_CONTEXT_SLOTS + 1)),
|
|
|
|
IsBeginRegion(_), control),
|
|
|
|
_));
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace compiler
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|