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

Side by Side Diff: test/unittests/compiler/js-builtin-reducer-unittest.cc

Issue 2125583002: [turbofan] Recognize fast path for Number.parseInt. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 5 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
« no previous file with comments | « src/type-cache.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/compiler/js-builtin-reducer.h" 5 #include "src/compiler/js-builtin-reducer.h"
6 #include "src/compiler/js-graph.h" 6 #include "src/compiler/js-graph.h"
7 #include "src/compiler/node-properties.h" 7 #include "src/compiler/node-properties.h"
8 #include "src/compiler/simplified-operator.h" 8 #include "src/compiler/simplified-operator.h"
9 #include "src/compiler/typer.h" 9 #include "src/compiler/typer.h"
10 #include "src/isolate-inl.h" 10 #include "src/isolate-inl.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 JSObject::GetProperty(isolate()->global_object(), 42 JSObject::GetProperty(isolate()->global_object(),
43 isolate()->factory()->NewStringFromAsciiChecked( 43 isolate()->factory()->NewStringFromAsciiChecked(
44 "Math")).ToHandleChecked(); 44 "Math")).ToHandleChecked();
45 Handle<JSFunction> f = Handle<JSFunction>::cast( 45 Handle<JSFunction> f = Handle<JSFunction>::cast(
46 Object::GetProperty( 46 Object::GetProperty(
47 m, isolate()->factory()->NewStringFromAsciiChecked(name)) 47 m, isolate()->factory()->NewStringFromAsciiChecked(name))
48 .ToHandleChecked()); 48 .ToHandleChecked());
49 return HeapConstant(f); 49 return HeapConstant(f);
50 } 50 }
51 51
52 Node* NumberFunction(const char* name) {
53 Handle<Object> m =
54 JSObject::GetProperty(
55 isolate()->global_object(),
56 isolate()->factory()->NewStringFromAsciiChecked("Number"))
57 .ToHandleChecked();
58 Handle<JSFunction> f = Handle<JSFunction>::cast(
59 Object::GetProperty(
60 m, isolate()->factory()->NewStringFromAsciiChecked(name))
61 .ToHandleChecked());
62 return HeapConstant(f);
63 }
64
52 Node* StringFunction(const char* name) { 65 Node* StringFunction(const char* name) {
53 Handle<Object> m = 66 Handle<Object> m =
54 JSObject::GetProperty( 67 JSObject::GetProperty(
55 isolate()->global_object(), 68 isolate()->global_object(),
56 isolate()->factory()->NewStringFromAsciiChecked("String")) 69 isolate()->factory()->NewStringFromAsciiChecked("String"))
57 .ToHandleChecked(); 70 .ToHandleChecked();
58 Handle<JSFunction> f = Handle<JSFunction>::cast( 71 Handle<JSFunction> f = Handle<JSFunction>::cast(
59 Object::GetProperty( 72 Object::GetProperty(
60 m, isolate()->factory()->NewStringFromAsciiChecked(name)) 73 m, isolate()->factory()->NewStringFromAsciiChecked(name))
61 .ToHandleChecked()); 74 .ToHandleChecked());
(...skipping 1274 matching lines...) Expand 10 before | Expand all | Expand 10 after
1336 Node* call = graph()->NewNode(javascript()->CallFunction(3), function, 1349 Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
1337 UndefinedConstant(), p0, context, frame_state, 1350 UndefinedConstant(), p0, context, frame_state,
1338 effect, control); 1351 effect, control);
1339 Reduction r = Reduce(call); 1352 Reduction r = Reduce(call);
1340 1353
1341 ASSERT_TRUE(r.Changed()); 1354 ASSERT_TRUE(r.Changed());
1342 EXPECT_THAT(r.replacement(), IsNumberTrunc(IsPlainPrimitiveToNumber(p0))); 1355 EXPECT_THAT(r.replacement(), IsNumberTrunc(IsPlainPrimitiveToNumber(p0)));
1343 } 1356 }
1344 1357
1345 // ----------------------------------------------------------------------------- 1358 // -----------------------------------------------------------------------------
1359 // Number.parseInt
1360
1361 TEST_F(JSBuiltinReducerTest, NumberParseIntWithIntegral32) {
1362 Node* function = NumberFunction("parseInt");
1363
1364 Node* effect = graph()->start();
1365 Node* control = graph()->start();
1366 Node* context = UndefinedConstant();
1367 Node* frame_state = graph()->start();
1368 TRACED_FOREACH(Type*, t0, kIntegral32Types) {
1369 Node* p0 = Parameter(t0, 0);
1370 Node* call = graph()->NewNode(javascript()->CallFunction(3), function,
1371 UndefinedConstant(), p0, context, frame_state,
1372 effect, control);
1373 Reduction r = Reduce(call);
1374
1375 ASSERT_TRUE(r.Changed());
1376 EXPECT_THAT(r.replacement(), IsNumberToInt32(p0));
1377 }
1378 }
1379
1380 TEST_F(JSBuiltinReducerTest, NumberParseIntWithIntegral32AndUndefined) {
1381 Node* function = NumberFunction("parseInt");
1382
1383 Node* effect = graph()->start();
1384 Node* control = graph()->start();
1385 Node* context = UndefinedConstant();
1386 Node* frame_state = graph()->start();
1387 TRACED_FOREACH(Type*, t0, kIntegral32Types) {
1388 Node* p0 = Parameter(t0, 0);
1389 Node* p1 = Parameter(Type::Undefined(), 1);
1390 Node* call = graph()->NewNode(javascript()->CallFunction(4), function,
1391 UndefinedConstant(), p0, p1, context,
1392 frame_state, effect, control);
1393 Reduction r = Reduce(call);
1394
1395 ASSERT_TRUE(r.Changed());
1396 EXPECT_THAT(r.replacement(), IsNumberToInt32(p0));
1397 }
1398 }
1399
1400 // -----------------------------------------------------------------------------
1346 // String.fromCharCode 1401 // String.fromCharCode
1347 1402
1348 TEST_F(JSBuiltinReducerTest, StringFromCharCodeWithNumber) { 1403 TEST_F(JSBuiltinReducerTest, StringFromCharCodeWithNumber) {
1349 Node* function = StringFunction("fromCharCode"); 1404 Node* function = StringFunction("fromCharCode");
1350 1405
1351 Node* effect = graph()->start(); 1406 Node* effect = graph()->start();
1352 Node* control = graph()->start(); 1407 Node* control = graph()->start();
1353 Node* context = UndefinedConstant(); 1408 Node* context = UndefinedConstant();
1354 Node* frame_state = graph()->start(); 1409 Node* frame_state = graph()->start();
1355 TRACED_FOREACH(Type*, t0, kNumberTypes) { 1410 TRACED_FOREACH(Type*, t0, kNumberTypes) {
(...skipping 22 matching lines...) Expand all
1378 Reduction r = Reduce(call); 1433 Reduction r = Reduce(call);
1379 1434
1380 ASSERT_TRUE(r.Changed()); 1435 ASSERT_TRUE(r.Changed());
1381 EXPECT_THAT(r.replacement(), 1436 EXPECT_THAT(r.replacement(),
1382 IsStringFromCharCode(IsPlainPrimitiveToNumber(p0))); 1437 IsStringFromCharCode(IsPlainPrimitiveToNumber(p0)));
1383 } 1438 }
1384 1439
1385 } // namespace compiler 1440 } // namespace compiler
1386 } // namespace internal 1441 } // namespace internal
1387 } // namespace v8 1442 } // namespace v8
OLDNEW
« no previous file with comments | « src/type-cache.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698