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 769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
780 | 780 |
781 LInstruction* LChunkBuilder::DoArithmeticT(Token::Value op, | 781 LInstruction* LChunkBuilder::DoArithmeticT(Token::Value op, |
782 HArithmeticBinaryOperation* instr) { | 782 HArithmeticBinaryOperation* instr) { |
783 ASSERT(op == Token::ADD || | 783 ASSERT(op == Token::ADD || |
784 op == Token::DIV || | 784 op == Token::DIV || |
785 op == Token::MOD || | 785 op == Token::MOD || |
786 op == Token::MUL || | 786 op == Token::MUL || |
787 op == Token::SUB); | 787 op == Token::SUB); |
788 HValue* left = instr->left(); | 788 HValue* left = instr->left(); |
789 HValue* right = instr->right(); | 789 HValue* right = instr->right(); |
790 ASSERT(left->representation().IsSmiOrTagged()); | 790 ASSERT(left->representation().IsTagged()); |
791 ASSERT(right->representation().IsSmiOrTagged()); | 791 ASSERT(right->representation().IsTagged()); |
792 LOperand* left_operand = UseFixed(left, rdx); | 792 LOperand* left_operand = UseFixed(left, rdx); |
793 LOperand* right_operand = UseFixed(right, rax); | 793 LOperand* right_operand = UseFixed(right, rax); |
794 LArithmeticT* result = | 794 LArithmeticT* result = |
795 new(zone()) LArithmeticT(op, left_operand, right_operand); | 795 new(zone()) LArithmeticT(op, left_operand, right_operand); |
796 return MarkAsCall(DefineFixed(result, rax), instr); | 796 return MarkAsCall(DefineFixed(result, rax), instr); |
797 } | 797 } |
798 | 798 |
799 | 799 |
800 void LChunkBuilder::DoBasicBlock(HBasicBlock* block, HBasicBlock* next_block) { | 800 void LChunkBuilder::DoBasicBlock(HBasicBlock* block, HBasicBlock* next_block) { |
801 ASSERT(is_building()); | 801 ASSERT(is_building()); |
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1312 return DoShift(Token::SAR, instr); | 1312 return DoShift(Token::SAR, instr); |
1313 } | 1313 } |
1314 | 1314 |
1315 | 1315 |
1316 LInstruction* LChunkBuilder::DoShl(HShl* instr) { | 1316 LInstruction* LChunkBuilder::DoShl(HShl* instr) { |
1317 return DoShift(Token::SHL, instr); | 1317 return DoShift(Token::SHL, instr); |
1318 } | 1318 } |
1319 | 1319 |
1320 | 1320 |
1321 LInstruction* LChunkBuilder::DoBitwise(HBitwise* instr) { | 1321 LInstruction* LChunkBuilder::DoBitwise(HBitwise* instr) { |
1322 if (instr->representation().IsInteger32()) { | 1322 if (instr->representation().IsSmiOrInteger32()) { |
1323 ASSERT(instr->left()->representation().IsInteger32()); | 1323 ASSERT(instr->left()->representation().Equals(instr->representation())); |
1324 ASSERT(instr->right()->representation().IsInteger32()); | 1324 ASSERT(instr->right()->representation().Equals(instr->representation())); |
1325 | 1325 |
1326 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand()); | 1326 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand()); |
1327 LOperand* right = UseOrConstantAtStart(instr->BetterRightOperand()); | 1327 LOperand* right = UseOrConstantAtStart(instr->BetterRightOperand()); |
1328 return DefineSameAsFirst(new(zone()) LBitI(left, right)); | 1328 return DefineSameAsFirst(new(zone()) LBitI(left, right)); |
1329 } else { | 1329 } else { |
1330 ASSERT(instr->representation().IsSmiOrTagged()); | 1330 ASSERT(instr->representation().IsTagged()); |
1331 ASSERT(instr->left()->representation().IsSmiOrTagged()); | 1331 ASSERT(instr->left()->representation().IsTagged()); |
1332 ASSERT(instr->right()->representation().IsSmiOrTagged()); | 1332 ASSERT(instr->right()->representation().IsTagged()); |
1333 | 1333 |
1334 LOperand* left = UseFixed(instr->left(), rdx); | 1334 LOperand* left = UseFixed(instr->left(), rdx); |
1335 LOperand* right = UseFixed(instr->right(), rax); | 1335 LOperand* right = UseFixed(instr->right(), rax); |
1336 LArithmeticT* result = new(zone()) LArithmeticT(instr->op(), left, right); | 1336 LArithmeticT* result = new(zone()) LArithmeticT(instr->op(), left, right); |
1337 return MarkAsCall(DefineFixed(result, rax), instr); | 1337 return MarkAsCall(DefineFixed(result, rax), instr); |
1338 } | 1338 } |
1339 } | 1339 } |
1340 | 1340 |
1341 | 1341 |
1342 LInstruction* LChunkBuilder::DoBitNot(HBitNot* instr) { | 1342 LInstruction* LChunkBuilder::DoBitNot(HBitNot* instr) { |
1343 ASSERT(instr->value()->representation().IsInteger32()); | 1343 ASSERT(instr->value()->representation().IsInteger32()); |
1344 ASSERT(instr->representation().IsInteger32()); | 1344 ASSERT(instr->representation().IsInteger32()); |
1345 if (instr->HasNoUses()) return NULL; | 1345 if (instr->HasNoUses()) return NULL; |
1346 LOperand* input = UseRegisterAtStart(instr->value()); | 1346 LOperand* input = UseRegisterAtStart(instr->value()); |
1347 LBitNotI* result = new(zone()) LBitNotI(input); | 1347 LBitNotI* result = new(zone()) LBitNotI(input); |
1348 return DefineSameAsFirst(result); | 1348 return DefineSameAsFirst(result); |
1349 } | 1349 } |
1350 | 1350 |
1351 | 1351 |
1352 LInstruction* LChunkBuilder::DoDiv(HDiv* instr) { | 1352 LInstruction* LChunkBuilder::DoDiv(HDiv* instr) { |
1353 if (instr->representation().IsDouble()) { | 1353 if (instr->representation().IsDouble()) { |
1354 return DoArithmeticD(Token::DIV, instr); | 1354 return DoArithmeticD(Token::DIV, instr); |
1355 } else if (instr->representation().IsInteger32()) { | 1355 } else if (instr->representation().IsSmiOrInteger32()) { |
| 1356 ASSERT(instr->left()->representation().Equals(instr->representation())); |
| 1357 ASSERT(instr->right()->representation().Equals(instr->representation())); |
1356 if (instr->HasPowerOf2Divisor()) { | 1358 if (instr->HasPowerOf2Divisor()) { |
1357 ASSERT(!instr->CheckFlag(HValue::kCanBeDivByZero)); | 1359 ASSERT(!instr->CheckFlag(HValue::kCanBeDivByZero)); |
1358 LOperand* value = UseRegisterAtStart(instr->left()); | 1360 LOperand* value = UseRegisterAtStart(instr->left()); |
1359 LDivI* div = | 1361 LDivI* div = |
1360 new(zone()) LDivI(value, UseOrConstant(instr->right()), NULL); | 1362 new(zone()) LDivI(value, UseOrConstant(instr->right()), NULL); |
1361 return AssignEnvironment(DefineSameAsFirst(div)); | 1363 return AssignEnvironment(DefineSameAsFirst(div)); |
1362 } | 1364 } |
1363 // The temporary operand is necessary to ensure that right is not allocated | 1365 // The temporary operand is necessary to ensure that right is not allocated |
1364 // into rdx. | 1366 // into rdx. |
1365 LOperand* temp = FixedTemp(rdx); | 1367 LOperand* temp = FixedTemp(rdx); |
1366 LOperand* dividend = UseFixed(instr->left(), rax); | 1368 LOperand* dividend = UseFixed(instr->left(), rax); |
1367 LOperand* divisor = UseRegister(instr->right()); | 1369 LOperand* divisor = UseRegister(instr->right()); |
1368 LDivI* result = new(zone()) LDivI(dividend, divisor, temp); | 1370 LDivI* result = new(zone()) LDivI(dividend, divisor, temp); |
1369 return AssignEnvironment(DefineFixed(result, rax)); | 1371 return AssignEnvironment(DefineFixed(result, rax)); |
1370 } else { | 1372 } else { |
1371 ASSERT(instr->representation().IsSmiOrTagged()); | 1373 ASSERT(instr->representation().IsTagged()); |
1372 return DoArithmeticT(Token::DIV, instr); | 1374 return DoArithmeticT(Token::DIV, instr); |
1373 } | 1375 } |
1374 } | 1376 } |
1375 | 1377 |
1376 | 1378 |
1377 HValue* LChunkBuilder::SimplifiedDivisorForMathFloorOfDiv(HValue* divisor) { | 1379 HValue* LChunkBuilder::SimplifiedDivisorForMathFloorOfDiv(HValue* divisor) { |
1378 if (divisor->IsConstant() && | 1380 if (divisor->IsConstant() && |
1379 HConstant::cast(divisor)->HasInteger32Value()) { | 1381 HConstant::cast(divisor)->HasInteger32Value()) { |
1380 HConstant* constant_val = HConstant::cast(divisor); | 1382 HConstant* constant_val = HConstant::cast(divisor); |
1381 return constant_val->CopyToRepresentation(Representation::Integer32(), | 1383 return constant_val->CopyToRepresentation(Representation::Integer32(), |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1425 LInstruction* result = DefineAsRegister( | 1427 LInstruction* result = DefineAsRegister( |
1426 new(zone()) LMathFloorOfDiv(dividend, divisor, temp)); | 1428 new(zone()) LMathFloorOfDiv(dividend, divisor, temp)); |
1427 return divisor_si < 0 ? AssignEnvironment(result) : result; | 1429 return divisor_si < 0 ? AssignEnvironment(result) : result; |
1428 } | 1430 } |
1429 } | 1431 } |
1430 | 1432 |
1431 | 1433 |
1432 LInstruction* LChunkBuilder::DoMod(HMod* instr) { | 1434 LInstruction* LChunkBuilder::DoMod(HMod* instr) { |
1433 HValue* left = instr->left(); | 1435 HValue* left = instr->left(); |
1434 HValue* right = instr->right(); | 1436 HValue* right = instr->right(); |
1435 if (instr->representation().IsInteger32()) { | 1437 if (instr->representation().IsSmiOrInteger32()) { |
1436 ASSERT(left->representation().IsInteger32()); | 1438 ASSERT(left->representation().Equals(instr->representation())); |
1437 ASSERT(right->representation().IsInteger32()); | 1439 ASSERT(right->representation().Equals(instr->representation())); |
1438 if (instr->HasPowerOf2Divisor()) { | 1440 if (instr->HasPowerOf2Divisor()) { |
1439 ASSERT(!right->CanBeZero()); | 1441 ASSERT(!right->CanBeZero()); |
1440 LModI* mod = new(zone()) LModI(UseRegisterAtStart(left), | 1442 LModI* mod = new(zone()) LModI(UseRegisterAtStart(left), |
1441 UseOrConstant(right), | 1443 UseOrConstant(right), |
1442 NULL); | 1444 NULL); |
1443 LInstruction* result = DefineSameAsFirst(mod); | 1445 LInstruction* result = DefineSameAsFirst(mod); |
1444 return (left->CanBeNegative() && | 1446 return (left->CanBeNegative() && |
1445 instr->CheckFlag(HValue::kBailoutOnMinusZero)) | 1447 instr->CheckFlag(HValue::kBailoutOnMinusZero)) |
1446 ? AssignEnvironment(result) | 1448 ? AssignEnvironment(result) |
1447 : result; | 1449 : result; |
(...skipping 12 matching lines...) Expand all Loading... |
1460 return (right->CanBeZero() || | 1462 return (right->CanBeZero() || |
1461 (left->RangeCanInclude(kMinInt) && | 1463 (left->RangeCanInclude(kMinInt) && |
1462 right->RangeCanInclude(-1) && | 1464 right->RangeCanInclude(-1) && |
1463 instr->CheckFlag(HValue::kBailoutOnMinusZero)) || | 1465 instr->CheckFlag(HValue::kBailoutOnMinusZero)) || |
1464 (left->CanBeNegative() && | 1466 (left->CanBeNegative() && |
1465 instr->CanBeZero() && | 1467 instr->CanBeZero() && |
1466 instr->CheckFlag(HValue::kBailoutOnMinusZero))) | 1468 instr->CheckFlag(HValue::kBailoutOnMinusZero))) |
1467 ? AssignEnvironment(result) | 1469 ? AssignEnvironment(result) |
1468 : result; | 1470 : result; |
1469 } | 1471 } |
1470 } else if (instr->representation().IsSmiOrTagged()) { | 1472 } else if (instr->representation().IsTagged()) { |
1471 return DoArithmeticT(Token::MOD, instr); | 1473 return DoArithmeticT(Token::MOD, instr); |
1472 } else { | 1474 } else { |
1473 ASSERT(instr->representation().IsDouble()); | 1475 ASSERT(instr->representation().IsDouble()); |
1474 // We call a C function for double modulo. It can't trigger a GC. We need to | 1476 // We call a C function for double modulo. It can't trigger a GC. We need to |
1475 // use fixed result register for the call. | 1477 // use fixed result register for the call. |
1476 // TODO(fschneider): Allow any register as input registers. | 1478 // TODO(fschneider): Allow any register as input registers. |
1477 LArithmeticD* mod = new(zone()) LArithmeticD(Token::MOD, | 1479 LArithmeticD* mod = new(zone()) LArithmeticD(Token::MOD, |
1478 UseFixedDouble(left, xmm2), | 1480 UseFixedDouble(left, xmm2), |
1479 UseFixedDouble(right, xmm1)); | 1481 UseFixedDouble(right, xmm1)); |
1480 return MarkAsCall(DefineFixedDouble(mod, xmm1), instr); | 1482 return MarkAsCall(DefineFixedDouble(mod, xmm1), instr); |
1481 } | 1483 } |
1482 } | 1484 } |
1483 | 1485 |
1484 | 1486 |
1485 LInstruction* LChunkBuilder::DoMul(HMul* instr) { | 1487 LInstruction* LChunkBuilder::DoMul(HMul* instr) { |
1486 if (instr->representation().IsInteger32()) { | 1488 if (instr->representation().IsSmiOrInteger32()) { |
1487 ASSERT(instr->left()->representation().IsInteger32()); | 1489 ASSERT(instr->left()->representation().Equals(instr->representation())); |
1488 ASSERT(instr->right()->representation().IsInteger32()); | 1490 ASSERT(instr->right()->representation().Equals(instr->representation())); |
1489 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand()); | 1491 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand()); |
1490 LOperand* right = UseOrConstant(instr->BetterRightOperand()); | 1492 LOperand* right = UseOrConstant(instr->BetterRightOperand()); |
1491 LMulI* mul = new(zone()) LMulI(left, right); | 1493 LMulI* mul = new(zone()) LMulI(left, right); |
1492 if (instr->CheckFlag(HValue::kCanOverflow) || | 1494 if (instr->CheckFlag(HValue::kCanOverflow) || |
1493 instr->CheckFlag(HValue::kBailoutOnMinusZero)) { | 1495 instr->CheckFlag(HValue::kBailoutOnMinusZero)) { |
1494 AssignEnvironment(mul); | 1496 AssignEnvironment(mul); |
1495 } | 1497 } |
1496 return DefineSameAsFirst(mul); | 1498 return DefineSameAsFirst(mul); |
1497 } else if (instr->representation().IsDouble()) { | 1499 } else if (instr->representation().IsDouble()) { |
1498 return DoArithmeticD(Token::MUL, instr); | 1500 return DoArithmeticD(Token::MUL, instr); |
1499 } else { | 1501 } else { |
1500 ASSERT(instr->representation().IsSmiOrTagged()); | 1502 ASSERT(instr->representation().IsTagged()); |
1501 return DoArithmeticT(Token::MUL, instr); | 1503 return DoArithmeticT(Token::MUL, instr); |
1502 } | 1504 } |
1503 } | 1505 } |
1504 | 1506 |
1505 | 1507 |
1506 LInstruction* LChunkBuilder::DoSub(HSub* instr) { | 1508 LInstruction* LChunkBuilder::DoSub(HSub* instr) { |
1507 if (instr->representation().IsInteger32()) { | 1509 if (instr->representation().IsSmiOrInteger32()) { |
1508 ASSERT(instr->left()->representation().IsInteger32()); | 1510 ASSERT(instr->left()->representation().Equals(instr->representation())); |
1509 ASSERT(instr->right()->representation().IsInteger32()); | 1511 ASSERT(instr->right()->representation().Equals(instr->representation())); |
1510 LOperand* left = UseRegisterAtStart(instr->left()); | 1512 LOperand* left = UseRegisterAtStart(instr->left()); |
1511 LOperand* right = UseOrConstantAtStart(instr->right()); | 1513 LOperand* right = UseOrConstantAtStart(instr->right()); |
1512 LSubI* sub = new(zone()) LSubI(left, right); | 1514 LSubI* sub = new(zone()) LSubI(left, right); |
1513 LInstruction* result = DefineSameAsFirst(sub); | 1515 LInstruction* result = DefineSameAsFirst(sub); |
1514 if (instr->CheckFlag(HValue::kCanOverflow)) { | 1516 if (instr->CheckFlag(HValue::kCanOverflow)) { |
1515 result = AssignEnvironment(result); | 1517 result = AssignEnvironment(result); |
1516 } | 1518 } |
1517 return result; | 1519 return result; |
1518 } else if (instr->representation().IsDouble()) { | 1520 } else if (instr->representation().IsDouble()) { |
1519 return DoArithmeticD(Token::SUB, instr); | 1521 return DoArithmeticD(Token::SUB, instr); |
1520 } else { | 1522 } else { |
1521 ASSERT(instr->representation().IsSmiOrTagged()); | 1523 ASSERT(instr->representation().IsTagged()); |
1522 return DoArithmeticT(Token::SUB, instr); | 1524 return DoArithmeticT(Token::SUB, instr); |
1523 } | 1525 } |
1524 } | 1526 } |
1525 | 1527 |
1526 | 1528 |
1527 LInstruction* LChunkBuilder::DoAdd(HAdd* instr) { | 1529 LInstruction* LChunkBuilder::DoAdd(HAdd* instr) { |
1528 if (instr->representation().IsInteger32()) { | 1530 if (instr->representation().IsSmiOrInteger32()) { |
1529 // Check to see if it would be advantageous to use an lea instruction rather | 1531 // Check to see if it would be advantageous to use an lea instruction rather |
1530 // than an add. This is the case when no overflow check is needed and there | 1532 // than an add. This is the case when no overflow check is needed and there |
1531 // are multiple uses of the add's inputs, so using a 3-register add will | 1533 // are multiple uses of the add's inputs, so using a 3-register add will |
1532 // preserve all input values for later uses. | 1534 // preserve all input values for later uses. |
1533 bool use_lea = LAddI::UseLea(instr); | 1535 bool use_lea = LAddI::UseLea(instr); |
1534 ASSERT(instr->left()->representation().IsInteger32()); | 1536 ASSERT(instr->left()->representation().Equals(instr->representation())); |
1535 ASSERT(instr->right()->representation().IsInteger32()); | 1537 ASSERT(instr->right()->representation().Equals(instr->representation())); |
1536 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand()); | 1538 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand()); |
1537 HValue* right_candidate = instr->BetterRightOperand(); | 1539 HValue* right_candidate = instr->BetterRightOperand(); |
1538 LOperand* right = use_lea | 1540 LOperand* right = use_lea |
1539 ? UseRegisterOrConstantAtStart(right_candidate) | 1541 ? UseRegisterOrConstantAtStart(right_candidate) |
1540 : UseOrConstantAtStart(right_candidate); | 1542 : UseOrConstantAtStart(right_candidate); |
1541 LAddI* add = new(zone()) LAddI(left, right); | 1543 LAddI* add = new(zone()) LAddI(left, right); |
1542 bool can_overflow = instr->CheckFlag(HValue::kCanOverflow); | 1544 bool can_overflow = instr->CheckFlag(HValue::kCanOverflow); |
1543 LInstruction* result = use_lea | 1545 LInstruction* result = use_lea |
1544 ? DefineAsRegister(add) | 1546 ? DefineAsRegister(add) |
1545 : DefineSameAsFirst(add); | 1547 : DefineSameAsFirst(add); |
1546 if (can_overflow) { | 1548 if (can_overflow) { |
1547 result = AssignEnvironment(result); | 1549 result = AssignEnvironment(result); |
1548 } | 1550 } |
1549 return result; | 1551 return result; |
1550 } else if (instr->representation().IsDouble()) { | 1552 } else if (instr->representation().IsDouble()) { |
1551 return DoArithmeticD(Token::ADD, instr); | 1553 return DoArithmeticD(Token::ADD, instr); |
1552 } else { | 1554 } else { |
1553 ASSERT(instr->representation().IsSmiOrTagged()); | 1555 ASSERT(instr->representation().IsTagged()); |
1554 return DoArithmeticT(Token::ADD, instr); | 1556 return DoArithmeticT(Token::ADD, instr); |
1555 } | 1557 } |
1556 return NULL; | 1558 return NULL; |
1557 } | 1559 } |
1558 | 1560 |
1559 | 1561 |
1560 LInstruction* LChunkBuilder::DoMathMinMax(HMathMinMax* instr) { | 1562 LInstruction* LChunkBuilder::DoMathMinMax(HMathMinMax* instr) { |
1561 LOperand* left = NULL; | 1563 LOperand* left = NULL; |
1562 LOperand* right = NULL; | 1564 LOperand* right = NULL; |
1563 if (instr->representation().IsInteger32()) { | 1565 if (instr->representation().IsInteger32()) { |
(...skipping 1016 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2580 LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) { | 2582 LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) { |
2581 LOperand* object = UseRegister(instr->object()); | 2583 LOperand* object = UseRegister(instr->object()); |
2582 LOperand* index = UseTempRegister(instr->index()); | 2584 LOperand* index = UseTempRegister(instr->index()); |
2583 return DefineSameAsFirst(new(zone()) LLoadFieldByIndex(object, index)); | 2585 return DefineSameAsFirst(new(zone()) LLoadFieldByIndex(object, index)); |
2584 } | 2586 } |
2585 | 2587 |
2586 | 2588 |
2587 } } // namespace v8::internal | 2589 } } // namespace v8::internal |
2588 | 2590 |
2589 #endif // V8_TARGET_ARCH_X64 | 2591 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |