OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
708 } | 708 } |
709 | 709 |
710 | 710 |
711 LInstruction* LChunkBuilder::DoDeoptimize(HDeoptimize* instr) { | 711 LInstruction* LChunkBuilder::DoDeoptimize(HDeoptimize* instr) { |
712 return AssignEnvironment(new(zone()) LDeoptimize); | 712 return AssignEnvironment(new(zone()) LDeoptimize); |
713 } | 713 } |
714 | 714 |
715 | 715 |
716 LInstruction* LChunkBuilder::DoShift(Token::Value op, | 716 LInstruction* LChunkBuilder::DoShift(Token::Value op, |
717 HBitwiseBinaryOperation* instr) { | 717 HBitwiseBinaryOperation* instr) { |
718 if (instr->representation().IsTagged()) { | 718 if (instr->representation().IsSmiOrInteger32()) { |
719 ASSERT(instr->left()->representation().IsTagged()); | 719 ASSERT(instr->left()->representation().Equals(instr->representation())); |
720 ASSERT(instr->right()->representation().IsTagged()); | 720 ASSERT(instr->right()->representation().Equals(instr->representation())); |
| 721 LOperand* left = UseRegisterAtStart(instr->left()); |
721 | 722 |
722 LOperand* left = UseFixed(instr->left(), a1); | 723 HValue* right_value = instr->right(); |
723 LOperand* right = UseFixed(instr->right(), a0); | 724 LOperand* right = NULL; |
724 LArithmeticT* result = new(zone()) LArithmeticT(op, left, right); | 725 int constant_value = 0; |
725 return MarkAsCall(DefineFixed(result, v0), instr); | 726 bool does_deopt = false; |
| 727 if (right_value->IsConstant()) { |
| 728 HConstant* constant = HConstant::cast(right_value); |
| 729 right = chunk_->DefineConstantOperand(constant); |
| 730 constant_value = constant->Integer32Value() & 0x1f; |
| 731 // Left shifts can deoptimize if we shift by > 0 and the result cannot be |
| 732 // truncated to smi. |
| 733 if (instr->representation().IsSmi() && constant_value > 0) { |
| 734 does_deopt = !instr->CheckUsesForFlag(HValue::kTruncatingToSmi); |
| 735 } |
| 736 } else { |
| 737 right = UseRegisterAtStart(right_value); |
| 738 } |
| 739 |
| 740 // Shift operations can only deoptimize if we do a logical shift |
| 741 // by 0 and the result cannot be truncated to int32. |
| 742 if (op == Token::SHR && constant_value == 0) { |
| 743 if (FLAG_opt_safe_uint32_operations) { |
| 744 does_deopt = !instr->CheckFlag(HInstruction::kUint32); |
| 745 } else { |
| 746 does_deopt = !instr->CheckUsesForFlag(HValue::kTruncatingToInt32); |
| 747 } |
| 748 } |
| 749 |
| 750 LInstruction* result = |
| 751 DefineAsRegister(new(zone()) LShiftI(op, left, right, does_deopt)); |
| 752 return does_deopt ? AssignEnvironment(result) : result; |
| 753 } else { |
| 754 return DoArithmeticT(op, instr); |
726 } | 755 } |
727 | |
728 ASSERT(instr->representation().IsSmiOrInteger32()); | |
729 ASSERT(instr->left()->representation().Equals(instr->representation())); | |
730 ASSERT(instr->right()->representation().Equals(instr->representation())); | |
731 LOperand* left = UseRegisterAtStart(instr->left()); | |
732 | |
733 HValue* right_value = instr->right(); | |
734 LOperand* right = NULL; | |
735 int constant_value = 0; | |
736 bool does_deopt = false; | |
737 if (right_value->IsConstant()) { | |
738 HConstant* constant = HConstant::cast(right_value); | |
739 right = chunk_->DefineConstantOperand(constant); | |
740 constant_value = constant->Integer32Value() & 0x1f; | |
741 // Left shifts can deoptimize if we shift by > 0 and the result cannot be | |
742 // truncated to smi. | |
743 if (instr->representation().IsSmi() && constant_value > 0) { | |
744 does_deopt = !instr->CheckUsesForFlag(HValue::kTruncatingToSmi); | |
745 } | |
746 } else { | |
747 right = UseRegisterAtStart(right_value); | |
748 } | |
749 | |
750 // Shift operations can deoptimize if we do a logical shift | |
751 // by 0 and the result cannot be truncated to int32. | |
752 if (op == Token::SHR && constant_value == 0) { | |
753 if (FLAG_opt_safe_uint32_operations) { | |
754 does_deopt = !instr->CheckFlag(HInstruction::kUint32); | |
755 } else { | |
756 does_deopt = !instr->CheckUsesForFlag(HValue::kTruncatingToInt32); | |
757 } | |
758 } | |
759 | |
760 LInstruction* result = | |
761 DefineAsRegister(new(zone()) LShiftI(op, left, right, does_deopt)); | |
762 return does_deopt ? AssignEnvironment(result) : result; | |
763 } | 756 } |
764 | 757 |
765 | 758 |
766 LInstruction* LChunkBuilder::DoArithmeticD(Token::Value op, | 759 LInstruction* LChunkBuilder::DoArithmeticD(Token::Value op, |
767 HArithmeticBinaryOperation* instr) { | 760 HArithmeticBinaryOperation* instr) { |
768 ASSERT(instr->representation().IsDouble()); | 761 ASSERT(instr->representation().IsDouble()); |
769 ASSERT(instr->left()->representation().IsDouble()); | 762 ASSERT(instr->left()->representation().IsDouble()); |
770 ASSERT(instr->right()->representation().IsDouble()); | 763 ASSERT(instr->right()->representation().IsDouble()); |
771 ASSERT(op != Token::MOD); | 764 LOperand* left = NULL; |
772 LOperand* left = UseRegisterAtStart(instr->left()); | 765 LOperand* right = NULL; |
773 LOperand* right = UseRegisterAtStart(instr->right()); | 766 if (op == Token::MOD) { |
| 767 left = UseFixedDouble(instr->left(), f2); |
| 768 right = UseFixedDouble(instr->right(), f4); |
| 769 LArithmeticD* result = new(zone()) LArithmeticD(op, left, right); |
| 770 // We call a C function for double modulo. It can't trigger a GC. We need |
| 771 // to use fixed result register for the call. |
| 772 // TODO(fschneider): Allow any register as input registers. |
| 773 return MarkAsCall(DefineFixedDouble(result, f2), instr); |
| 774 } |
| 775 left = UseRegisterAtStart(instr->left()); |
| 776 right = UseRegisterAtStart(instr->right()); |
774 LArithmeticD* result = new(zone()) LArithmeticD(op, left, right); | 777 LArithmeticD* result = new(zone()) LArithmeticD(op, left, right); |
775 return DefineAsRegister(result); | 778 return DefineAsRegister(result); |
776 } | 779 } |
777 | 780 |
778 | 781 |
779 LInstruction* LChunkBuilder::DoArithmeticT(Token::Value op, | 782 LInstruction* LChunkBuilder::DoArithmeticT(Token::Value op, |
780 HArithmeticBinaryOperation* instr) { | 783 HBinaryOperation* instr) { |
781 ASSERT(op == Token::ADD || | |
782 op == Token::DIV || | |
783 op == Token::MOD || | |
784 op == Token::MUL || | |
785 op == Token::SUB); | |
786 HValue* left = instr->left(); | 784 HValue* left = instr->left(); |
787 HValue* right = instr->right(); | 785 HValue* right = instr->right(); |
788 ASSERT(left->representation().IsTagged()); | 786 ASSERT(left->representation().IsTagged()); |
789 ASSERT(right->representation().IsTagged()); | 787 ASSERT(right->representation().IsTagged()); |
790 LOperand* left_operand = UseFixed(left, a1); | 788 LOperand* left_operand = UseFixed(left, a1); |
791 LOperand* right_operand = UseFixed(right, a0); | 789 LOperand* right_operand = UseFixed(right, a0); |
792 LArithmeticT* result = | 790 LArithmeticT* result = |
793 new(zone()) LArithmeticT(op, left_operand, right_operand); | 791 new(zone()) LArithmeticT(op, left_operand, right_operand); |
794 return MarkAsCall(DefineFixed(result, v0), instr); | 792 return MarkAsCall(DefineFixed(result, v0), instr); |
795 } | 793 } |
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1342 | 1340 |
1343 LInstruction* LChunkBuilder::DoShl(HShl* instr) { | 1341 LInstruction* LChunkBuilder::DoShl(HShl* instr) { |
1344 return DoShift(Token::SHL, instr); | 1342 return DoShift(Token::SHL, instr); |
1345 } | 1343 } |
1346 | 1344 |
1347 | 1345 |
1348 LInstruction* LChunkBuilder::DoBitwise(HBitwise* instr) { | 1346 LInstruction* LChunkBuilder::DoBitwise(HBitwise* instr) { |
1349 if (instr->representation().IsSmiOrInteger32()) { | 1347 if (instr->representation().IsSmiOrInteger32()) { |
1350 ASSERT(instr->left()->representation().Equals(instr->representation())); | 1348 ASSERT(instr->left()->representation().Equals(instr->representation())); |
1351 ASSERT(instr->right()->representation().Equals(instr->representation())); | 1349 ASSERT(instr->right()->representation().Equals(instr->representation())); |
| 1350 ASSERT(instr->CheckFlag(HValue::kTruncatingToInt32)); |
1352 | 1351 |
1353 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand()); | 1352 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand()); |
1354 LOperand* right = UseOrConstantAtStart(instr->BetterRightOperand()); | 1353 LOperand* right = UseOrConstantAtStart(instr->BetterRightOperand()); |
1355 return DefineAsRegister(new(zone()) LBitI(left, right)); | 1354 return DefineAsRegister(new(zone()) LBitI(left, right)); |
1356 } else { | 1355 } else { |
1357 ASSERT(instr->representation().IsTagged()); | 1356 return DoArithmeticT(instr->op(), instr); |
1358 ASSERT(instr->left()->representation().IsTagged()); | |
1359 ASSERT(instr->right()->representation().IsTagged()); | |
1360 | |
1361 LOperand* left = UseFixed(instr->left(), a1); | |
1362 LOperand* right = UseFixed(instr->right(), a0); | |
1363 LArithmeticT* result = new(zone()) LArithmeticT(instr->op(), left, right); | |
1364 return MarkAsCall(DefineFixed(result, v0), instr); | |
1365 } | 1357 } |
1366 } | 1358 } |
1367 | 1359 |
1368 | 1360 |
1369 LInstruction* LChunkBuilder::DoDiv(HDiv* instr) { | 1361 LInstruction* LChunkBuilder::DoDiv(HDiv* instr) { |
1370 if (instr->representation().IsDouble()) { | 1362 if (instr->representation().IsSmiOrInteger32()) { |
1371 return DoArithmeticD(Token::DIV, instr); | |
1372 } else if (instr->representation().IsSmiOrInteger32()) { | |
1373 ASSERT(instr->left()->representation().Equals(instr->representation())); | 1363 ASSERT(instr->left()->representation().Equals(instr->representation())); |
1374 ASSERT(instr->right()->representation().Equals(instr->representation())); | 1364 ASSERT(instr->right()->representation().Equals(instr->representation())); |
1375 LOperand* dividend = UseRegister(instr->left()); | 1365 LOperand* dividend = UseRegister(instr->left()); |
1376 LOperand* divisor = UseRegister(instr->right()); | 1366 LOperand* divisor = UseRegister(instr->right()); |
1377 LDivI* div = new(zone()) LDivI(dividend, divisor); | 1367 LDivI* div = new(zone()) LDivI(dividend, divisor); |
1378 return AssignEnvironment(DefineAsRegister(div)); | 1368 return AssignEnvironment(DefineAsRegister(div)); |
| 1369 } else if (instr->representation().IsDouble()) { |
| 1370 return DoArithmeticD(Token::DIV, instr); |
1379 } else { | 1371 } else { |
1380 return DoArithmeticT(Token::DIV, instr); | 1372 return DoArithmeticT(Token::DIV, instr); |
1381 } | 1373 } |
1382 } | 1374 } |
1383 | 1375 |
1384 | 1376 |
1385 bool LChunkBuilder::HasMagicNumberForDivisor(int32_t divisor) { | 1377 bool LChunkBuilder::HasMagicNumberForDivisor(int32_t divisor) { |
1386 uint32_t divisor_abs = abs(divisor); | 1378 uint32_t divisor_abs = abs(divisor); |
1387 // Dividing by 0, 1, and powers of 2 is easy. | 1379 // Dividing by 0, 1, and powers of 2 is easy. |
1388 // Note that IsPowerOf2(0) returns true; | 1380 // Note that IsPowerOf2(0) returns true; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1459 FixedTemp(f20), | 1451 FixedTemp(f20), |
1460 FixedTemp(f22)); | 1452 FixedTemp(f22)); |
1461 LInstruction* result = DefineAsRegister(mod); | 1453 LInstruction* result = DefineAsRegister(mod); |
1462 return (right->CanBeZero() || | 1454 return (right->CanBeZero() || |
1463 (left->RangeCanInclude(kMinInt) && | 1455 (left->RangeCanInclude(kMinInt) && |
1464 right->RangeCanInclude(-1)) || | 1456 right->RangeCanInclude(-1)) || |
1465 instr->CheckFlag(HValue::kBailoutOnMinusZero)) | 1457 instr->CheckFlag(HValue::kBailoutOnMinusZero)) |
1466 ? AssignEnvironment(result) | 1458 ? AssignEnvironment(result) |
1467 : result; | 1459 : result; |
1468 } | 1460 } |
1469 } else if (instr->representation().IsTagged()) { | 1461 } else if (instr->representation().IsDouble()) { |
| 1462 return DoArithmeticD(Token::MOD, instr); |
| 1463 } else { |
1470 return DoArithmeticT(Token::MOD, instr); | 1464 return DoArithmeticT(Token::MOD, instr); |
1471 } else { | |
1472 ASSERT(instr->representation().IsDouble()); | |
1473 // We call a C function for double modulo. It can't trigger a GC. We need | |
1474 // to use fixed result register for the call. | |
1475 // TODO(fschneider): Allow any register as input registers. | |
1476 LArithmeticD* mod = new(zone()) LArithmeticD(Token::MOD, | |
1477 UseFixedDouble(left, f2), | |
1478 UseFixedDouble(right, f4)); | |
1479 return MarkAsCall(DefineFixedDouble(mod, f2), instr); | |
1480 } | 1465 } |
1481 } | 1466 } |
1482 | 1467 |
1483 | 1468 |
1484 LInstruction* LChunkBuilder::DoMul(HMul* instr) { | 1469 LInstruction* LChunkBuilder::DoMul(HMul* instr) { |
1485 if (instr->representation().IsSmiOrInteger32()) { | 1470 if (instr->representation().IsSmiOrInteger32()) { |
1486 ASSERT(instr->left()->representation().Equals(instr->representation())); | 1471 ASSERT(instr->left()->representation().Equals(instr->representation())); |
1487 ASSERT(instr->right()->representation().Equals(instr->representation())); | 1472 ASSERT(instr->right()->representation().Equals(instr->representation())); |
1488 LOperand* left; | 1473 LOperand* left; |
1489 LOperand* right = UseOrConstant(instr->BetterRightOperand()); | 1474 LOperand* right = UseOrConstant(instr->BetterRightOperand()); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1572 if (instr->left()->IsMul()) | 1557 if (instr->left()->IsMul()) |
1573 return DoMultiplyAdd(HMul::cast(instr->left()), instr->right()); | 1558 return DoMultiplyAdd(HMul::cast(instr->left()), instr->right()); |
1574 | 1559 |
1575 if (instr->right()->IsMul()) { | 1560 if (instr->right()->IsMul()) { |
1576 ASSERT(!instr->left()->IsMul()); | 1561 ASSERT(!instr->left()->IsMul()); |
1577 return DoMultiplyAdd(HMul::cast(instr->right()), instr->left()); | 1562 return DoMultiplyAdd(HMul::cast(instr->right()), instr->left()); |
1578 } | 1563 } |
1579 } | 1564 } |
1580 return DoArithmeticD(Token::ADD, instr); | 1565 return DoArithmeticD(Token::ADD, instr); |
1581 } else { | 1566 } else { |
1582 ASSERT(instr->representation().IsTagged()); | |
1583 return DoArithmeticT(Token::ADD, instr); | 1567 return DoArithmeticT(Token::ADD, instr); |
1584 } | 1568 } |
1585 } | 1569 } |
1586 | 1570 |
1587 | 1571 |
1588 LInstruction* LChunkBuilder::DoMathMinMax(HMathMinMax* instr) { | 1572 LInstruction* LChunkBuilder::DoMathMinMax(HMathMinMax* instr) { |
1589 LOperand* left = NULL; | 1573 LOperand* left = NULL; |
1590 LOperand* right = NULL; | 1574 LOperand* right = NULL; |
1591 if (instr->representation().IsSmiOrInteger32()) { | 1575 if (instr->representation().IsSmiOrInteger32()) { |
1592 ASSERT(instr->left()->representation().Equals(instr->representation())); | 1576 ASSERT(instr->left()->representation().Equals(instr->representation())); |
(...skipping 931 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2524 | 2508 |
2525 | 2509 |
2526 LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) { | 2510 LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) { |
2527 LOperand* object = UseRegister(instr->object()); | 2511 LOperand* object = UseRegister(instr->object()); |
2528 LOperand* index = UseRegister(instr->index()); | 2512 LOperand* index = UseRegister(instr->index()); |
2529 return DefineAsRegister(new(zone()) LLoadFieldByIndex(object, index)); | 2513 return DefineAsRegister(new(zone()) LLoadFieldByIndex(object, index)); |
2530 } | 2514 } |
2531 | 2515 |
2532 | 2516 |
2533 } } // namespace v8::internal | 2517 } } // namespace v8::internal |
OLD | NEW |