Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(699)

Side by Side Diff: test/unittests/compiler/js-create-lowering-unittest.cc

Issue 1678833002: [turbofan] Introduce JSCreateLowering for optimizing JSCreate nodes. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix length_type check. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "src/compiler/js-create-lowering.h"
6 #include "src/code-factory.h"
7 #include "src/compiler/access-builder.h"
8 #include "src/compiler/js-graph.h"
9 #include "src/compiler/js-operator.h"
10 #include "src/compiler/machine-operator.h"
11 #include "src/compiler/node-properties.h"
12 #include "src/compiler/operator-properties.h"
13 #include "src/isolate-inl.h"
14 #include "test/unittests/compiler/compiler-test-utils.h"
15 #include "test/unittests/compiler/graph-unittest.h"
16 #include "test/unittests/compiler/node-test-utils.h"
17 #include "testing/gmock-support.h"
18
19 using testing::_;
20 using testing::BitEq;
21 using testing::IsNaN;
22
23 namespace v8 {
24 namespace internal {
25 namespace compiler {
26
27 class JSCreateLoweringTest : public TypedGraphTest {
28 public:
29 JSCreateLoweringTest()
30 : TypedGraphTest(3), javascript_(zone()), deps_(isolate(), zone()) {}
31 ~JSCreateLoweringTest() override {}
32
33 protected:
34 Reduction Reduce(Node* node) {
35 MachineOperatorBuilder machine(zone());
36 SimplifiedOperatorBuilder simplified(zone());
37 JSGraph jsgraph(isolate(), graph(), common(), javascript(), &simplified,
38 &machine);
39 // TODO(titzer): mock the GraphReducer here for better unit testing.
40 GraphReducer graph_reducer(zone(), graph());
41 JSCreateLowering reducer(&graph_reducer, &deps_, &jsgraph);
42 return reducer.Reduce(node);
43 }
44
45 Node* FrameState(Handle<SharedFunctionInfo> shared, Node* outer_frame_state) {
46 Node* state_values = graph()->NewNode(common()->StateValues(0));
47 return graph()->NewNode(
48 common()->FrameState(BailoutId::None(),
49 OutputFrameStateCombine::Ignore(),
50 common()->CreateFrameStateFunctionInfo(
51 FrameStateType::kJavaScriptFunction, 1, 0,
52 shared, CALL_MAINTAINS_NATIVE_CONTEXT)),
53 state_values, state_values, state_values, NumberConstant(0),
54 UndefinedConstant(), outer_frame_state);
55 }
56
57 Handle<JSArrayBuffer> NewArrayBuffer(void* bytes, size_t byte_length) {
Michael Starzinger 2016/02/08 12:10:40 nit: This method is not used, let's drop it.
Benedikt Meurer 2016/02/08 12:12:05 Done.
58 Handle<JSArrayBuffer> buffer = factory()->NewJSArrayBuffer();
59 JSArrayBuffer::Setup(buffer, isolate(), true, bytes, byte_length);
60 return buffer;
61 }
62
63 JSOperatorBuilder* javascript() { return &javascript_; }
64
65 private:
66 JSOperatorBuilder javascript_;
67 CompilationDependencies deps_;
68 };
69
70 TEST_F(JSCreateLoweringTest, JSCreate) {
71 Handle<JSFunction> function = isolate()->object_function();
72 Node* const target = Parameter(Type::Constant(function, graph()->zone()));
73 Node* const context = Parameter(Type::Any());
74 Node* const effect = graph()->start();
75 Reduction r = Reduce(graph()->NewNode(javascript()->Create(), target, target,
76 context, EmptyFrameState(), effect));
77 ASSERT_TRUE(r.Changed());
78 EXPECT_THAT(
79 r.replacement(),
80 IsFinishRegion(
81 IsAllocate(IsNumberConstant(function->initial_map()->instance_size()),
82 IsBeginRegion(effect), _),
83 _));
84 }
85
86 // -----------------------------------------------------------------------------
87 // JSCreateArguments
88
89 TEST_F(JSCreateLoweringTest, JSCreateArgumentsViaStub) {
90 Node* const closure = Parameter(Type::Any());
91 Node* const context = UndefinedConstant();
92 Node* const effect = graph()->start();
93 Node* const control = graph()->start();
94 Handle<SharedFunctionInfo> shared(isolate()->object_function()->shared());
95 Node* const frame_state = FrameState(shared, graph()->start());
96 Reduction r = Reduce(graph()->NewNode(
97 javascript()->CreateArguments(CreateArgumentsType::kMappedArguments),
98 closure, context, frame_state, effect, control));
99 ASSERT_TRUE(r.Changed());
100 EXPECT_THAT(
101 r.replacement(),
102 IsCall(_,
103 IsHeapConstant(
104 CodeFactory::ArgumentsAccess(isolate(), false, false).code()),
105 closure, IsNumberConstant(0), _, effect, control));
106 }
107
108 TEST_F(JSCreateLoweringTest, JSCreateArgumentsRestParameterViaStub) {
109 Node* const closure = Parameter(Type::Any());
110 Node* const context = UndefinedConstant();
111 Node* const effect = graph()->start();
112 Node* const control = graph()->start();
113 Handle<SharedFunctionInfo> shared(isolate()->object_function()->shared());
114 Node* const frame_state = FrameState(shared, graph()->start());
115 Reduction r = Reduce(graph()->NewNode(
116 javascript()->CreateArguments(CreateArgumentsType::kRestParameter),
117 closure, context, frame_state, effect, control));
118 ASSERT_TRUE(r.Changed());
119 EXPECT_THAT(
120 r.replacement(),
121 IsCall(_, IsHeapConstant(
122 CodeFactory::FastNewRestParameter(isolate()).code()),
123 closure, context, frame_state, effect, control));
124 }
125
126 TEST_F(JSCreateLoweringTest, JSCreateArgumentsInlinedMapped) {
127 Node* const closure = Parameter(Type::Any());
128 Node* const context = UndefinedConstant();
129 Node* const effect = graph()->start();
130 Node* const control = graph()->start();
131 Handle<SharedFunctionInfo> shared(isolate()->object_function()->shared());
132 Node* const frame_state_outer = FrameState(shared, graph()->start());
133 Node* const frame_state_inner = FrameState(shared, frame_state_outer);
134 Reduction r = Reduce(graph()->NewNode(
135 javascript()->CreateArguments(CreateArgumentsType::kMappedArguments),
136 closure, context, frame_state_inner, effect, control));
137 ASSERT_TRUE(r.Changed());
138 EXPECT_THAT(r.replacement(),
139 IsFinishRegion(
140 IsAllocate(IsNumberConstant(Heap::kSloppyArgumentsObjectSize),
141 _, control),
142 _));
143 }
144
145 TEST_F(JSCreateLoweringTest, JSCreateArgumentsInlinedUnmapped) {
146 Node* const closure = Parameter(Type::Any());
147 Node* const context = UndefinedConstant();
148 Node* const effect = graph()->start();
149 Node* const control = graph()->start();
150 Handle<SharedFunctionInfo> shared(isolate()->object_function()->shared());
151 Node* const frame_state_outer = FrameState(shared, graph()->start());
152 Node* const frame_state_inner = FrameState(shared, frame_state_outer);
153 Reduction r = Reduce(graph()->NewNode(
154 javascript()->CreateArguments(CreateArgumentsType::kUnmappedArguments),
155 closure, context, frame_state_inner, effect, control));
156 ASSERT_TRUE(r.Changed());
157 EXPECT_THAT(r.replacement(),
158 IsFinishRegion(
159 IsAllocate(IsNumberConstant(Heap::kStrictArgumentsObjectSize),
160 _, control),
161 _));
162 }
163
164 TEST_F(JSCreateLoweringTest, JSCreateArgumentsInlinedRestArray) {
165 Node* const closure = Parameter(Type::Any());
166 Node* const context = UndefinedConstant();
167 Node* const effect = graph()->start();
168 Node* const control = graph()->start();
169 Handle<SharedFunctionInfo> shared(isolate()->object_function()->shared());
170 Node* const frame_state_outer = FrameState(shared, graph()->start());
171 Node* const frame_state_inner = FrameState(shared, frame_state_outer);
172 Reduction r = Reduce(graph()->NewNode(
173 javascript()->CreateArguments(CreateArgumentsType::kRestParameter),
174 closure, context, frame_state_inner, effect, control));
175 ASSERT_TRUE(r.Changed());
176 EXPECT_THAT(r.replacement(),
177 IsFinishRegion(
178 IsAllocate(IsNumberConstant(JSArray::kSize), _, control), _));
179 }
180
181 // -----------------------------------------------------------------------------
182 // JSCreateFunctionContext
183
184 TEST_F(JSCreateLoweringTest, JSCreateFunctionContextViaInlinedAllocation) {
185 Node* const closure = Parameter(Type::Any());
186 Node* const context = Parameter(Type::Any());
187 Node* const effect = graph()->start();
188 Node* const control = graph()->start();
189 Reduction const r =
190 Reduce(graph()->NewNode(javascript()->CreateFunctionContext(8), closure,
191 context, effect, control));
192 ASSERT_TRUE(r.Changed());
193 EXPECT_THAT(r.replacement(),
194 IsFinishRegion(IsAllocate(IsNumberConstant(Context::SizeFor(
195 8 + Context::MIN_CONTEXT_SLOTS)),
196 IsBeginRegion(_), control),
197 _));
198 }
199
200 // -----------------------------------------------------------------------------
201 // JSCreateWithContext
202
203 TEST_F(JSCreateLoweringTest, JSCreateWithContext) {
204 Node* const object = Parameter(Type::Receiver());
205 Node* const closure = Parameter(Type::Function());
206 Node* const context = Parameter(Type::Any());
207 Node* const effect = graph()->start();
208 Node* const control = graph()->start();
209 Reduction r =
210 Reduce(graph()->NewNode(javascript()->CreateWithContext(), object,
211 closure, context, effect, control));
212 ASSERT_TRUE(r.Changed());
213 EXPECT_THAT(r.replacement(),
214 IsFinishRegion(IsAllocate(IsNumberConstant(Context::SizeFor(
215 Context::MIN_CONTEXT_SLOTS)),
216 IsBeginRegion(_), control),
217 _));
218 }
219
220 // -----------------------------------------------------------------------------
221 // JSCreateCatchContext
222
223 TEST_F(JSCreateLoweringTest, JSCreateCatchContext) {
224 Handle<String> name = factory()->length_string();
225 Node* const exception = Parameter(Type::Receiver());
226 Node* const closure = Parameter(Type::Function());
227 Node* const context = Parameter(Type::Any());
228 Node* const effect = graph()->start();
229 Node* const control = graph()->start();
230 Reduction r =
231 Reduce(graph()->NewNode(javascript()->CreateCatchContext(name), exception,
232 closure, context, effect, control));
233 ASSERT_TRUE(r.Changed());
234 EXPECT_THAT(r.replacement(),
235 IsFinishRegion(IsAllocate(IsNumberConstant(Context::SizeFor(
236 Context::MIN_CONTEXT_SLOTS + 1)),
237 IsBeginRegion(_), control),
238 _));
239 }
240
241 } // namespace compiler
242 } // namespace internal
243 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698