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

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

Issue 768543002: [WIP] TrapHandler 2014/11/27. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 6 years 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
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/base/platform/platform.h"
5 #include "src/compiler/access-builder.h" 6 #include "src/compiler/access-builder.h"
6 #include "src/compiler/js-graph.h" 7 #include "src/compiler/js-graph.h"
7 #include "src/compiler/js-operator.h" 8 #include "src/compiler/js-operator.h"
8 #include "src/compiler/js-typed-lowering.h" 9 #include "src/compiler/js-typed-lowering.h"
9 #include "src/compiler/machine-operator.h" 10 #include "src/compiler/machine-operator.h"
10 #include "src/compiler/node-properties-inl.h" 11 #include "src/compiler/node-properties-inl.h"
11 #include "src/compiler/typer.h" 12 #include "src/compiler/typer.h"
12 #include "test/unittests/compiler/compiler-test-utils.h" 13 #include "test/unittests/compiler/compiler-test-utils.h"
13 #include "test/unittests/compiler/graph-unittest.h" 14 #include "test/unittests/compiler/graph-unittest.h"
14 #include "test/unittests/compiler/node-test-utils.h" 15 #include "test/unittests/compiler/node-test-utils.h"
15 16
16 namespace v8 { 17 namespace v8 {
17 namespace internal { 18 namespace internal {
18 namespace compiler { 19 namespace compiler {
19 20
20 namespace { 21 namespace {
21 22
22 const ExternalArrayType kExternalArrayTypes[] = {
23 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) kExternal##Type##Array,
24 TYPED_ARRAYS(TYPED_ARRAY_CASE)
25 #undef TYPED_ARRAY_CASE
26 };
27
28
29 Type* const kJSTypes[] = {Type::Undefined(), Type::Null(), Type::Boolean(), 23 Type* const kJSTypes[] = {Type::Undefined(), Type::Null(), Type::Boolean(),
30 Type::Number(), Type::String(), Type::Object()}; 24 Type::Number(), Type::String(), Type::Object()};
31 25
32 26
33 const StrictMode kStrictModes[] = {SLOPPY, STRICT};
34
35 } // namespace 27 } // namespace
36 28
37 29
38 class JSTypedLoweringTest : public TypedGraphTest { 30 class JSTypedLoweringTest : public TypedGraphTest {
39 public: 31 public:
40 JSTypedLoweringTest() : TypedGraphTest(3), javascript_(zone()) {} 32 JSTypedLoweringTest()
33 : TypedGraphTest(3), javascript_(zone()), machine_(zone()) {}
41 virtual ~JSTypedLoweringTest() {} 34 virtual ~JSTypedLoweringTest() {}
42 35
43 protected: 36 protected:
44 Reduction Reduce(Node* node) { 37 Reduction Reduce(Node* node) {
45 MachineOperatorBuilder machine(zone()); 38 JSGraph jsgraph(graph(), common(), javascript(), machine());
46 JSGraph jsgraph(graph(), common(), javascript(), &machine);
47 JSTypedLowering reducer(&jsgraph); 39 JSTypedLowering reducer(&jsgraph);
48 return reducer.Reduce(node); 40 return reducer.Reduce(node);
49 } 41 }
50 42
51 Node* Parameter(Type* type, int index = 0) { 43 Node* Parameter(Type* type, int index = 0) {
52 Node* node = graph()->NewNode(common()->Parameter(index), graph()->start()); 44 Node* node = graph()->NewNode(common()->Parameter(index), graph()->start());
53 NodeProperties::SetBounds(node, Bounds(Type::None(), type)); 45 NodeProperties::SetBounds(node, Bounds(Type::None(), type));
54 return node; 46 return node;
55 } 47 }
56 48
57 Handle<JSArrayBuffer> NewArrayBuffer(void* bytes, size_t byte_length) { 49 Handle<JSArrayBuffer> NewArrayBuffer(void* bytes, size_t byte_length) {
58 Handle<JSArrayBuffer> buffer = factory()->NewJSArrayBuffer(); 50 Handle<JSArrayBuffer> buffer = factory()->NewJSArrayBuffer();
59 Runtime::SetupArrayBuffer(isolate(), buffer, true, bytes, byte_length); 51 // TODO(bmeurer): Use SetupAllocatingData here.
52 Runtime::SetupArrayBuffer(isolate(), buffer, true, false, bytes,
53 byte_length);
60 return buffer; 54 return buffer;
61 } 55 }
62 56
63 Matcher<Node*> IsIntPtrConstant(intptr_t value) { 57 Matcher<Node*> IsIntPtrConstant(intptr_t value) {
64 return sizeof(value) == 4 ? IsInt32Constant(static_cast<int32_t>(value)) 58 return sizeof(value) == 4 ? IsInt32Constant(static_cast<int32_t>(value))
65 : IsInt64Constant(static_cast<int64_t>(value)); 59 : IsInt64Constant(static_cast<int64_t>(value));
66 } 60 }
67 61
68 JSOperatorBuilder* javascript() { return &javascript_; } 62 JSOperatorBuilder* javascript() { return &javascript_; }
63 MachineOperatorBuilder* machine() { return &machine_; }
69 64
70 private: 65 private:
71 JSOperatorBuilder javascript_; 66 JSOperatorBuilder javascript_;
67 MachineOperatorBuilder machine_;
72 }; 68 };
73 69
74 70
75 // ----------------------------------------------------------------------------- 71 // -----------------------------------------------------------------------------
76 // JSToBoolean 72 // JSToBoolean
77 73
78 74
79 TEST_F(JSTypedLoweringTest, JSToBooleanWithString) { 75 TEST_F(JSTypedLoweringTest, JSToBooleanWithString) {
80 Node* input = Parameter(Type::String()); 76 Node* input = Parameter(Type::String());
81 Node* context = UndefinedConstant(); 77 Node* context = UndefinedConstant();
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 Node* const context = UndefinedConstant(); 218 Node* const context = UndefinedConstant();
223 Node* const effect = graph()->start(); 219 Node* const effect = graph()->start();
224 Node* const control = graph()->start(); 220 Node* const control = graph()->start();
225 Reduction r = Reduce(graph()->NewNode(javascript()->ShiftRightLogical(), lhs, 221 Reduction r = Reduce(graph()->NewNode(javascript()->ShiftRightLogical(), lhs,
226 rhs, context, effect, control)); 222 rhs, context, effect, control));
227 ASSERT_TRUE(r.Changed()); 223 ASSERT_TRUE(r.Changed());
228 EXPECT_THAT(r.replacement(), 224 EXPECT_THAT(r.replacement(),
229 IsWord32Shr(lhs, IsWord32And(rhs, IsInt32Constant(0x1f)))); 225 IsWord32Shr(lhs, IsWord32And(rhs, IsInt32Constant(0x1f))));
230 } 226 }
231 227
232
233 // -----------------------------------------------------------------------------
234 // JSLoadProperty
235
236
237 TEST_F(JSTypedLoweringTest, JSLoadPropertyFromExternalTypedArray) {
238 const size_t kLength = 17;
239 double backing_store[kLength];
240 Handle<JSArrayBuffer> buffer =
241 NewArrayBuffer(backing_store, sizeof(backing_store));
242 VectorSlotPair feedback(Handle<TypeFeedbackVector>::null(),
243 FeedbackVectorICSlot::Invalid());
244 TRACED_FOREACH(ExternalArrayType, type, kExternalArrayTypes) {
245 Handle<JSTypedArray> array =
246 factory()->NewJSTypedArray(type, buffer, 0, kLength);
247
248 Node* key = Parameter(Type::Integral32());
249 Node* base = HeapConstant(array);
250 Node* context = UndefinedConstant();
251 Node* effect = graph()->start();
252 Node* control = graph()->start();
253 Node* node = graph()->NewNode(javascript()->LoadProperty(feedback), base,
254 key, context);
255 if (FLAG_turbo_deoptimization) {
256 node->AppendInput(zone(), UndefinedConstant());
257 }
258 node->AppendInput(zone(), effect);
259 node->AppendInput(zone(), control);
260 Reduction r = Reduce(node);
261
262 ASSERT_TRUE(r.Changed());
263 EXPECT_THAT(r.replacement(),
264 IsLoadElement(
265 AccessBuilder::ForTypedArrayElement(type, true),
266 IsIntPtrConstant(bit_cast<intptr_t>(&backing_store[0])),
267 key, IsNumberConstant(array->length()->Number()), effect));
268 }
269 }
270
271
272 // -----------------------------------------------------------------------------
273 // JSStoreProperty
274
275
276 TEST_F(JSTypedLoweringTest, JSStorePropertyToExternalTypedArray) {
277 const size_t kLength = 17;
278 double backing_store[kLength];
279 Handle<JSArrayBuffer> buffer =
280 NewArrayBuffer(backing_store, sizeof(backing_store));
281 TRACED_FOREACH(ExternalArrayType, type, kExternalArrayTypes) {
282 TRACED_FOREACH(StrictMode, strict_mode, kStrictModes) {
283 Handle<JSTypedArray> array =
284 factory()->NewJSTypedArray(type, buffer, 0, kLength);
285
286 Node* key = Parameter(Type::Integral32());
287 Node* base = HeapConstant(array);
288 Node* value =
289 Parameter(AccessBuilder::ForTypedArrayElement(type, true).type);
290 Node* context = UndefinedConstant();
291 Node* effect = graph()->start();
292 Node* control = graph()->start();
293 Node* node = graph()->NewNode(javascript()->StoreProperty(strict_mode),
294 base, key, value, context);
295 if (FLAG_turbo_deoptimization) {
296 node->AppendInput(zone(), UndefinedConstant());
297 }
298 node->AppendInput(zone(), effect);
299 node->AppendInput(zone(), control);
300 Reduction r = Reduce(node);
301
302 ASSERT_TRUE(r.Changed());
303 EXPECT_THAT(r.replacement(),
304 IsStoreElement(
305 AccessBuilder::ForTypedArrayElement(type, true),
306 IsIntPtrConstant(bit_cast<intptr_t>(&backing_store[0])),
307 key, IsNumberConstant(array->length()->Number()), value,
308 effect, control));
309 }
310 }
311 }
312
313
314 TEST_F(JSTypedLoweringTest, JSStorePropertyToExternalTypedArrayWithConversion) {
315 const size_t kLength = 17;
316 double backing_store[kLength];
317 Handle<JSArrayBuffer> buffer =
318 NewArrayBuffer(backing_store, sizeof(backing_store));
319 TRACED_FOREACH(ExternalArrayType, type, kExternalArrayTypes) {
320 TRACED_FOREACH(StrictMode, strict_mode, kStrictModes) {
321 Handle<JSTypedArray> array =
322 factory()->NewJSTypedArray(type, buffer, 0, kLength);
323
324 Node* key = Parameter(Type::Integral32());
325 Node* base = HeapConstant(array);
326 Node* value = Parameter(Type::Any());
327 Node* context = UndefinedConstant();
328 Node* effect = graph()->start();
329 Node* control = graph()->start();
330 Node* node = graph()->NewNode(javascript()->StoreProperty(strict_mode),
331 base, key, value, context);
332 if (FLAG_turbo_deoptimization) {
333 node->AppendInput(zone(), UndefinedConstant());
334 }
335 node->AppendInput(zone(), effect);
336 node->AppendInput(zone(), control);
337 Reduction r = Reduce(node);
338
339 Matcher<Node*> value_matcher =
340 IsToNumber(value, context, effect, control);
341 Matcher<Node*> effect_matcher = value_matcher;
342 if (AccessBuilder::ForTypedArrayElement(type, true)
343 .type->Is(Type::Signed32())) {
344 value_matcher = IsNumberToInt32(value_matcher);
345 } else if (AccessBuilder::ForTypedArrayElement(type, true)
346 .type->Is(Type::Unsigned32())) {
347 value_matcher = IsNumberToUint32(value_matcher);
348 }
349
350 ASSERT_TRUE(r.Changed());
351 EXPECT_THAT(r.replacement(),
352 IsStoreElement(
353 AccessBuilder::ForTypedArrayElement(type, true),
354 IsIntPtrConstant(bit_cast<intptr_t>(&backing_store[0])),
355 key, IsNumberConstant(array->length()->Number()),
356 value_matcher, effect_matcher, control));
357 }
358 }
359 }
360
361 } // namespace compiler 228 } // namespace compiler
362 } // namespace internal 229 } // namespace internal
363 } // namespace v8 230 } // namespace v8
OLDNEW
« no previous file with comments | « test/cctest/compiler/test-simplified-lowering.cc ('k') | test/unittests/compiler/node-test-utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698