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

Side by Side Diff: src/compiler/effect-control-linearizer.cc

Issue 2059653002: [turbofan] Introduce PlainPrimitiveToNumber. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Tweak Created 4 years, 6 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/compiler/effect-control-linearizer.h ('k') | src/compiler/js-graph.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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/effect-control-linearizer.h" 5 #include "src/compiler/effect-control-linearizer.h"
6 6
7 #include "src/code-factory.h" 7 #include "src/code-factory.h"
8 #include "src/compiler/access-builder.h" 8 #include "src/compiler/access-builder.h"
9 #include "src/compiler/js-graph.h" 9 #include "src/compiler/js-graph.h"
10 #include "src/compiler/linkage.h" 10 #include "src/compiler/linkage.h"
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 state = LowerObjectIsString(node, *effect, *control); 447 state = LowerObjectIsString(node, *effect, *control);
448 break; 448 break;
449 case IrOpcode::kObjectIsUndetectable: 449 case IrOpcode::kObjectIsUndetectable:
450 state = LowerObjectIsUndetectable(node, *effect, *control); 450 state = LowerObjectIsUndetectable(node, *effect, *control);
451 break; 451 break;
452 case IrOpcode::kStringFromCharCode: 452 case IrOpcode::kStringFromCharCode:
453 state = LowerStringFromCharCode(node, *effect, *control); 453 state = LowerStringFromCharCode(node, *effect, *control);
454 break; 454 break;
455 case IrOpcode::kCheckIf: 455 case IrOpcode::kCheckIf:
456 state = LowerCheckIf(node, frame_state, *effect, *control); 456 state = LowerCheckIf(node, frame_state, *effect, *control);
457 case IrOpcode::kPlainPrimitiveToNumber:
458 state = LowerPlainPrimitiveToNumber(node, *effect, *control);
459 break;
460 case IrOpcode::kPlainPrimitiveToWord32:
461 state = LowerPlainPrimitiveToWord32(node, *effect, *control);
462 break;
463 case IrOpcode::kPlainPrimitiveToFloat64:
464 state = LowerPlainPrimitiveToFloat64(node, *effect, *control);
457 break; 465 break;
458 default: 466 default:
459 return false; 467 return false;
460 } 468 }
461 NodeProperties::ReplaceUses(node, state.value, state.effect, state.control); 469 NodeProperties::ReplaceUses(node, state.value, state.effect, state.control);
462 *effect = state.effect; 470 *effect = state.effect;
463 *control = state.control; 471 *control = state.control;
464 return true; 472 return true;
465 } 473 }
466 474
(...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after
1323 return graph()->NewNode(machine()->ChangeUint32ToFloat64(), value); 1331 return graph()->NewNode(machine()->ChangeUint32ToFloat64(), value);
1324 } 1332 }
1325 1333
1326 Node* EffectControlLinearizer::ChangeSmiToInt32(Node* value) { 1334 Node* EffectControlLinearizer::ChangeSmiToInt32(Node* value) {
1327 value = graph()->NewNode(machine()->WordSar(), value, SmiShiftBitsConstant()); 1335 value = graph()->NewNode(machine()->WordSar(), value, SmiShiftBitsConstant());
1328 if (machine()->Is64()) { 1336 if (machine()->Is64()) {
1329 value = graph()->NewNode(machine()->TruncateInt64ToInt32(), value); 1337 value = graph()->NewNode(machine()->TruncateInt64ToInt32(), value);
1330 } 1338 }
1331 return value; 1339 return value;
1332 } 1340 }
1333
1334 Node* EffectControlLinearizer::ObjectIsSmi(Node* value) { 1341 Node* EffectControlLinearizer::ObjectIsSmi(Node* value) {
1335 return graph()->NewNode( 1342 return graph()->NewNode(
1336 machine()->WordEqual(), 1343 machine()->WordEqual(),
1337 graph()->NewNode(machine()->WordAnd(), value, 1344 graph()->NewNode(machine()->WordAnd(), value,
1338 jsgraph()->IntPtrConstant(kSmiTagMask)), 1345 jsgraph()->IntPtrConstant(kSmiTagMask)),
1339 jsgraph()->IntPtrConstant(kSmiTag)); 1346 jsgraph()->IntPtrConstant(kSmiTag));
1340 } 1347 }
1341 1348
1342 Node* EffectControlLinearizer::SmiMaxValueConstant() { 1349 Node* EffectControlLinearizer::SmiMaxValueConstant() {
1343 return jsgraph()->Int32Constant(Smi::kMaxValue); 1350 return jsgraph()->Int32Constant(Smi::kMaxValue);
1344 } 1351 }
1345 1352
1346 Node* EffectControlLinearizer::SmiShiftBitsConstant() { 1353 Node* EffectControlLinearizer::SmiShiftBitsConstant() {
1347 return jsgraph()->IntPtrConstant(kSmiShiftSize + kSmiTagSize); 1354 return jsgraph()->IntPtrConstant(kSmiShiftSize + kSmiTagSize);
1348 } 1355 }
1349 1356
1357 EffectControlLinearizer::ValueEffectControl
1358 EffectControlLinearizer::LowerPlainPrimitiveToNumber(Node* node, Node* effect,
1359 Node* control) {
1360 Node* value = node->InputAt(0);
1361 Node* result = effect =
1362 graph()->NewNode(ToNumberOperator(), jsgraph()->ToNumberBuiltinConstant(),
1363 value, jsgraph()->NoContextConstant(), effect, control);
1364 return ValueEffectControl(result, effect, control);
1365 }
1366
1367 EffectControlLinearizer::ValueEffectControl
1368 EffectControlLinearizer::LowerPlainPrimitiveToWord32(Node* node, Node* effect,
1369 Node* control) {
1370 Node* value = node->InputAt(0);
1371
1372 Node* check0 = ObjectIsSmi(value);
1373 Node* branch0 =
1374 graph()->NewNode(common()->Branch(BranchHint::kTrue), check0, control);
1375
1376 Node* if_true0 = graph()->NewNode(common()->IfTrue(), branch0);
1377 Node* etrue0 = effect;
1378 Node* vtrue0 = ChangeSmiToInt32(value);
1379
1380 Node* if_false0 = graph()->NewNode(common()->IfFalse(), branch0);
1381 Node* efalse0 = effect;
1382 Node* vfalse0;
1383 {
1384 vfalse0 = efalse0 = graph()->NewNode(
1385 ToNumberOperator(), jsgraph()->ToNumberBuiltinConstant(), value,
1386 jsgraph()->NoContextConstant(), efalse0, if_false0);
1387
1388 Node* check1 = ObjectIsSmi(vfalse0);
1389 Node* branch1 = graph()->NewNode(common()->Branch(), check1, if_false0);
1390
1391 Node* if_true1 = graph()->NewNode(common()->IfTrue(), branch1);
1392 Node* etrue1 = efalse0;
1393 Node* vtrue1 = ChangeSmiToInt32(vfalse0);
1394
1395 Node* if_false1 = graph()->NewNode(common()->IfFalse(), branch1);
1396 Node* efalse1 = efalse0;
1397 Node* vfalse1;
1398 {
1399 vfalse1 = efalse1 = graph()->NewNode(
1400 simplified()->LoadField(AccessBuilder::ForHeapNumberValue()), efalse0,
1401 efalse1, if_false1);
1402 vfalse1 = graph()->NewNode(machine()->TruncateFloat64ToWord32(), vfalse1);
1403 }
1404
1405 if_false0 = graph()->NewNode(common()->Merge(2), if_true1, if_false1);
1406 efalse0 =
1407 graph()->NewNode(common()->EffectPhi(2), etrue1, efalse1, if_false0);
1408 vfalse0 = graph()->NewNode(common()->Phi(MachineRepresentation::kWord32, 2),
1409 vtrue1, vfalse1, if_false0);
1410 }
1411
1412 control = graph()->NewNode(common()->Merge(2), if_true0, if_false0);
1413 effect = graph()->NewNode(common()->EffectPhi(2), etrue0, efalse0, control);
1414 value = graph()->NewNode(common()->Phi(MachineRepresentation::kWord32, 2),
1415 vtrue0, vfalse0, control);
1416 return ValueEffectControl(value, effect, control);
1417 }
1418
1419 EffectControlLinearizer::ValueEffectControl
1420 EffectControlLinearizer::LowerPlainPrimitiveToFloat64(Node* node, Node* effect,
1421 Node* control) {
1422 Node* value = node->InputAt(0);
1423
1424 Node* check0 = ObjectIsSmi(value);
1425 Node* branch0 =
1426 graph()->NewNode(common()->Branch(BranchHint::kTrue), check0, control);
1427
1428 Node* if_true0 = graph()->NewNode(common()->IfTrue(), branch0);
1429 Node* etrue0 = effect;
1430 Node* vtrue0;
1431 {
1432 vtrue0 = ChangeSmiToInt32(value);
1433 vtrue0 = graph()->NewNode(machine()->ChangeInt32ToFloat64(), vtrue0);
1434 }
1435
1436 Node* if_false0 = graph()->NewNode(common()->IfFalse(), branch0);
1437 Node* efalse0 = effect;
1438 Node* vfalse0;
1439 {
1440 vfalse0 = efalse0 = graph()->NewNode(
1441 ToNumberOperator(), jsgraph()->ToNumberBuiltinConstant(), value,
1442 jsgraph()->NoContextConstant(), efalse0, if_false0);
1443
1444 Node* check1 = ObjectIsSmi(vfalse0);
1445 Node* branch1 = graph()->NewNode(common()->Branch(), check1, if_false0);
1446
1447 Node* if_true1 = graph()->NewNode(common()->IfTrue(), branch1);
1448 Node* etrue1 = efalse0;
1449 Node* vtrue1;
1450 {
1451 vtrue1 = ChangeSmiToInt32(vfalse0);
1452 vtrue1 = graph()->NewNode(machine()->ChangeInt32ToFloat64(), vtrue1);
1453 }
1454
1455 Node* if_false1 = graph()->NewNode(common()->IfFalse(), branch1);
1456 Node* efalse1 = efalse0;
1457 Node* vfalse1;
1458 {
1459 vfalse1 = efalse1 = graph()->NewNode(
1460 simplified()->LoadField(AccessBuilder::ForHeapNumberValue()), efalse0,
1461 efalse1, if_false1);
1462 }
1463
1464 if_false0 = graph()->NewNode(common()->Merge(2), if_true1, if_false1);
1465 efalse0 =
1466 graph()->NewNode(common()->EffectPhi(2), etrue1, efalse1, if_false0);
1467 vfalse0 =
1468 graph()->NewNode(common()->Phi(MachineRepresentation::kFloat64, 2),
1469 vtrue1, vfalse1, if_false0);
1470 }
1471
1472 control = graph()->NewNode(common()->Merge(2), if_true0, if_false0);
1473 effect = graph()->NewNode(common()->EffectPhi(2), etrue0, efalse0, control);
1474 value = graph()->NewNode(common()->Phi(MachineRepresentation::kFloat64, 2),
1475 vtrue0, vfalse0, control);
1476 return ValueEffectControl(value, effect, control);
1477 }
1478
1350 Factory* EffectControlLinearizer::factory() const { 1479 Factory* EffectControlLinearizer::factory() const {
1351 return isolate()->factory(); 1480 return isolate()->factory();
1352 } 1481 }
1353 1482
1354 Isolate* EffectControlLinearizer::isolate() const { 1483 Isolate* EffectControlLinearizer::isolate() const {
1355 return jsgraph()->isolate(); 1484 return jsgraph()->isolate();
1356 } 1485 }
1357 1486
1487 Operator const* EffectControlLinearizer::ToNumberOperator() {
1488 if (!to_number_operator_.is_set()) {
1489 Callable callable = CodeFactory::ToNumber(isolate());
1490 CallDescriptor::Flags flags = CallDescriptor::kNoFlags;
1491 CallDescriptor* desc = Linkage::GetStubCallDescriptor(
1492 isolate(), graph()->zone(), callable.descriptor(), 0, flags,
1493 Operator::kNoThrow);
1494 to_number_operator_.set(common()->Call(desc));
1495 }
1496 return to_number_operator_.get();
1497 }
1498
1358 } // namespace compiler 1499 } // namespace compiler
1359 } // namespace internal 1500 } // namespace internal
1360 } // namespace v8 1501 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/effect-control-linearizer.h ('k') | src/compiler/js-graph.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698