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 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 new_value->use_list_ = | 488 new_value->use_list_ = |
489 new HUseListNode(this, index, new_value->use_list_); | 489 new HUseListNode(this, index, new_value->use_list_); |
490 } else { | 490 } else { |
491 removed->set_tail(new_value->use_list_); | 491 removed->set_tail(new_value->use_list_); |
492 new_value->use_list_ = removed; | 492 new_value->use_list_ = removed; |
493 } | 493 } |
494 } | 494 } |
495 } | 495 } |
496 | 496 |
497 | 497 |
498 void HValue::AddNewRange(Range* r) { | 498 void HValue::AddNewRange(Range* r, Zone* zone) { |
499 if (!HasRange()) ComputeInitialRange(); | 499 if (!HasRange()) ComputeInitialRange(zone); |
500 if (!HasRange()) range_ = new Range(); | 500 if (!HasRange()) range_ = new(zone) Range(); |
501 ASSERT(HasRange()); | 501 ASSERT(HasRange()); |
502 r->StackUpon(range_); | 502 r->StackUpon(range_); |
503 range_ = r; | 503 range_ = r; |
504 } | 504 } |
505 | 505 |
506 | 506 |
507 void HValue::RemoveLastAddedRange() { | 507 void HValue::RemoveLastAddedRange() { |
508 ASSERT(HasRange()); | 508 ASSERT(HasRange()); |
509 ASSERT(range_->next() != NULL); | 509 ASSERT(range_->next() != NULL); |
510 range_ = range_->next(); | 510 range_ = range_->next(); |
511 } | 511 } |
512 | 512 |
513 | 513 |
514 void HValue::ComputeInitialRange() { | 514 void HValue::ComputeInitialRange(Zone* zone) { |
515 ASSERT(!HasRange()); | 515 ASSERT(!HasRange()); |
516 range_ = InferRange(); | 516 range_ = InferRange(zone); |
517 ASSERT(HasRange()); | 517 ASSERT(HasRange()); |
518 } | 518 } |
519 | 519 |
520 | 520 |
521 void HInstruction::PrintTo(StringStream* stream) { | 521 void HInstruction::PrintTo(StringStream* stream) { |
522 PrintMnemonicTo(stream); | 522 PrintMnemonicTo(stream); |
523 PrintDataTo(stream); | 523 PrintDataTo(stream); |
524 PrintRangeTo(stream); | 524 PrintRangeTo(stream); |
525 PrintChangesTo(stream); | 525 PrintChangesTo(stream); |
526 PrintTypeTo(stream); | 526 PrintTypeTo(stream); |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
979 | 979 |
980 void HInstanceOf::PrintDataTo(StringStream* stream) { | 980 void HInstanceOf::PrintDataTo(StringStream* stream) { |
981 left()->PrintNameTo(stream); | 981 left()->PrintNameTo(stream); |
982 stream->Add(" "); | 982 stream->Add(" "); |
983 right()->PrintNameTo(stream); | 983 right()->PrintNameTo(stream); |
984 stream->Add(" "); | 984 stream->Add(" "); |
985 context()->PrintNameTo(stream); | 985 context()->PrintNameTo(stream); |
986 } | 986 } |
987 | 987 |
988 | 988 |
989 Range* HValue::InferRange() { | 989 Range* HValue::InferRange(Zone* zone) { |
990 // Untagged integer32 cannot be -0, all other representations can. | 990 // Untagged integer32 cannot be -0, all other representations can. |
991 Range* result = new Range(); | 991 Range* result = new(zone) Range(); |
992 result->set_can_be_minus_zero(!representation().IsInteger32()); | 992 result->set_can_be_minus_zero(!representation().IsInteger32()); |
993 return result; | 993 return result; |
994 } | 994 } |
995 | 995 |
996 | 996 |
997 Range* HChange::InferRange() { | 997 Range* HChange::InferRange(Zone* zone) { |
998 Range* input_range = value()->range(); | 998 Range* input_range = value()->range(); |
999 if (from().IsInteger32() && | 999 if (from().IsInteger32() && |
1000 to().IsTagged() && | 1000 to().IsTagged() && |
1001 input_range != NULL && input_range->IsInSmiRange()) { | 1001 input_range != NULL && input_range->IsInSmiRange()) { |
1002 set_type(HType::Smi()); | 1002 set_type(HType::Smi()); |
1003 } | 1003 } |
1004 Range* result = (input_range != NULL) | 1004 Range* result = (input_range != NULL) |
1005 ? input_range->Copy() | 1005 ? input_range->Copy(zone) |
1006 : HValue::InferRange(); | 1006 : HValue::InferRange(zone); |
1007 if (to().IsInteger32()) result->set_can_be_minus_zero(false); | 1007 if (to().IsInteger32()) result->set_can_be_minus_zero(false); |
1008 return result; | 1008 return result; |
1009 } | 1009 } |
1010 | 1010 |
1011 | 1011 |
1012 Range* HConstant::InferRange() { | 1012 Range* HConstant::InferRange(Zone* zone) { |
1013 if (has_int32_value_) { | 1013 if (has_int32_value_) { |
1014 Range* result = new Range(int32_value_, int32_value_); | 1014 Range* result = new(zone) Range(int32_value_, int32_value_); |
1015 result->set_can_be_minus_zero(false); | 1015 result->set_can_be_minus_zero(false); |
1016 return result; | 1016 return result; |
1017 } | 1017 } |
1018 return HValue::InferRange(); | 1018 return HValue::InferRange(zone); |
1019 } | 1019 } |
1020 | 1020 |
1021 | 1021 |
1022 Range* HPhi::InferRange() { | 1022 Range* HPhi::InferRange(Zone* zone) { |
1023 if (representation().IsInteger32()) { | 1023 if (representation().IsInteger32()) { |
1024 if (block()->IsLoopHeader()) { | 1024 if (block()->IsLoopHeader()) { |
1025 Range* range = new Range(kMinInt, kMaxInt); | 1025 Range* range = new(zone) Range(kMinInt, kMaxInt); |
1026 return range; | 1026 return range; |
1027 } else { | 1027 } else { |
1028 Range* range = OperandAt(0)->range()->Copy(); | 1028 Range* range = OperandAt(0)->range()->Copy(zone); |
1029 for (int i = 1; i < OperandCount(); ++i) { | 1029 for (int i = 1; i < OperandCount(); ++i) { |
1030 range->Union(OperandAt(i)->range()); | 1030 range->Union(OperandAt(i)->range()); |
1031 } | 1031 } |
1032 return range; | 1032 return range; |
1033 } | 1033 } |
1034 } else { | 1034 } else { |
1035 return HValue::InferRange(); | 1035 return HValue::InferRange(zone); |
1036 } | 1036 } |
1037 } | 1037 } |
1038 | 1038 |
1039 | 1039 |
1040 Range* HAdd::InferRange() { | 1040 Range* HAdd::InferRange(Zone* zone) { |
1041 if (representation().IsInteger32()) { | 1041 if (representation().IsInteger32()) { |
1042 Range* a = left()->range(); | 1042 Range* a = left()->range(); |
1043 Range* b = right()->range(); | 1043 Range* b = right()->range(); |
1044 Range* res = a->Copy(); | 1044 Range* res = a->Copy(zone); |
1045 if (!res->AddAndCheckOverflow(b)) { | 1045 if (!res->AddAndCheckOverflow(b)) { |
1046 ClearFlag(kCanOverflow); | 1046 ClearFlag(kCanOverflow); |
1047 } | 1047 } |
1048 bool m0 = a->CanBeMinusZero() && b->CanBeMinusZero(); | 1048 bool m0 = a->CanBeMinusZero() && b->CanBeMinusZero(); |
1049 res->set_can_be_minus_zero(m0); | 1049 res->set_can_be_minus_zero(m0); |
1050 return res; | 1050 return res; |
1051 } else { | 1051 } else { |
1052 return HValue::InferRange(); | 1052 return HValue::InferRange(zone); |
1053 } | 1053 } |
1054 } | 1054 } |
1055 | 1055 |
1056 | 1056 |
1057 Range* HSub::InferRange() { | 1057 Range* HSub::InferRange(Zone* zone) { |
1058 if (representation().IsInteger32()) { | 1058 if (representation().IsInteger32()) { |
1059 Range* a = left()->range(); | 1059 Range* a = left()->range(); |
1060 Range* b = right()->range(); | 1060 Range* b = right()->range(); |
1061 Range* res = a->Copy(); | 1061 Range* res = a->Copy(zone); |
1062 if (!res->SubAndCheckOverflow(b)) { | 1062 if (!res->SubAndCheckOverflow(b)) { |
1063 ClearFlag(kCanOverflow); | 1063 ClearFlag(kCanOverflow); |
1064 } | 1064 } |
1065 res->set_can_be_minus_zero(a->CanBeMinusZero() && b->CanBeZero()); | 1065 res->set_can_be_minus_zero(a->CanBeMinusZero() && b->CanBeZero()); |
1066 return res; | 1066 return res; |
1067 } else { | 1067 } else { |
1068 return HValue::InferRange(); | 1068 return HValue::InferRange(zone); |
1069 } | 1069 } |
1070 } | 1070 } |
1071 | 1071 |
1072 | 1072 |
1073 Range* HMul::InferRange() { | 1073 Range* HMul::InferRange(Zone* zone) { |
1074 if (representation().IsInteger32()) { | 1074 if (representation().IsInteger32()) { |
1075 Range* a = left()->range(); | 1075 Range* a = left()->range(); |
1076 Range* b = right()->range(); | 1076 Range* b = right()->range(); |
1077 Range* res = a->Copy(); | 1077 Range* res = a->Copy(zone); |
1078 if (!res->MulAndCheckOverflow(b)) { | 1078 if (!res->MulAndCheckOverflow(b)) { |
1079 ClearFlag(kCanOverflow); | 1079 ClearFlag(kCanOverflow); |
1080 } | 1080 } |
1081 bool m0 = (a->CanBeZero() && b->CanBeNegative()) || | 1081 bool m0 = (a->CanBeZero() && b->CanBeNegative()) || |
1082 (a->CanBeNegative() && b->CanBeZero()); | 1082 (a->CanBeNegative() && b->CanBeZero()); |
1083 res->set_can_be_minus_zero(m0); | 1083 res->set_can_be_minus_zero(m0); |
1084 return res; | 1084 return res; |
1085 } else { | 1085 } else { |
1086 return HValue::InferRange(); | 1086 return HValue::InferRange(zone); |
1087 } | 1087 } |
1088 } | 1088 } |
1089 | 1089 |
1090 | 1090 |
1091 Range* HDiv::InferRange() { | 1091 Range* HDiv::InferRange(Zone* zone) { |
1092 if (representation().IsInteger32()) { | 1092 if (representation().IsInteger32()) { |
1093 Range* result = new Range(); | 1093 Range* result = new(zone) Range(); |
1094 if (left()->range()->CanBeMinusZero()) { | 1094 if (left()->range()->CanBeMinusZero()) { |
1095 result->set_can_be_minus_zero(true); | 1095 result->set_can_be_minus_zero(true); |
1096 } | 1096 } |
1097 | 1097 |
1098 if (left()->range()->CanBeZero() && right()->range()->CanBeNegative()) { | 1098 if (left()->range()->CanBeZero() && right()->range()->CanBeNegative()) { |
1099 result->set_can_be_minus_zero(true); | 1099 result->set_can_be_minus_zero(true); |
1100 } | 1100 } |
1101 | 1101 |
1102 if (right()->range()->Includes(-1) && left()->range()->Includes(kMinInt)) { | 1102 if (right()->range()->Includes(-1) && left()->range()->Includes(kMinInt)) { |
1103 SetFlag(HValue::kCanOverflow); | 1103 SetFlag(HValue::kCanOverflow); |
1104 } | 1104 } |
1105 | 1105 |
1106 if (!right()->range()->CanBeZero()) { | 1106 if (!right()->range()->CanBeZero()) { |
1107 ClearFlag(HValue::kCanBeDivByZero); | 1107 ClearFlag(HValue::kCanBeDivByZero); |
1108 } | 1108 } |
1109 return result; | 1109 return result; |
1110 } else { | 1110 } else { |
1111 return HValue::InferRange(); | 1111 return HValue::InferRange(zone); |
1112 } | 1112 } |
1113 } | 1113 } |
1114 | 1114 |
1115 | 1115 |
1116 Range* HMod::InferRange() { | 1116 Range* HMod::InferRange(Zone* zone) { |
1117 if (representation().IsInteger32()) { | 1117 if (representation().IsInteger32()) { |
1118 Range* a = left()->range(); | 1118 Range* a = left()->range(); |
1119 Range* result = new Range(); | 1119 Range* result = new(zone) Range(); |
1120 if (a->CanBeMinusZero() || a->CanBeNegative()) { | 1120 if (a->CanBeMinusZero() || a->CanBeNegative()) { |
1121 result->set_can_be_minus_zero(true); | 1121 result->set_can_be_minus_zero(true); |
1122 } | 1122 } |
1123 if (!right()->range()->CanBeZero()) { | 1123 if (!right()->range()->CanBeZero()) { |
1124 ClearFlag(HValue::kCanBeDivByZero); | 1124 ClearFlag(HValue::kCanBeDivByZero); |
1125 } | 1125 } |
1126 return result; | 1126 return result; |
1127 } else { | 1127 } else { |
1128 return HValue::InferRange(); | 1128 return HValue::InferRange(zone); |
1129 } | 1129 } |
1130 } | 1130 } |
1131 | 1131 |
1132 | 1132 |
1133 void HPhi::PrintTo(StringStream* stream) { | 1133 void HPhi::PrintTo(StringStream* stream) { |
1134 stream->Add("["); | 1134 stream->Add("["); |
1135 for (int i = 0; i < OperandCount(); ++i) { | 1135 for (int i = 0; i < OperandCount(); ++i) { |
1136 HValue* value = OperandAt(i); | 1136 HValue* value = OperandAt(i); |
1137 stream->Add(" "); | 1137 stream->Add(" "); |
1138 value->PrintNameTo(stream); | 1138 value->PrintNameTo(stream); |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1317 | 1317 |
1318 void HBinaryOperation::PrintDataTo(StringStream* stream) { | 1318 void HBinaryOperation::PrintDataTo(StringStream* stream) { |
1319 left()->PrintNameTo(stream); | 1319 left()->PrintNameTo(stream); |
1320 stream->Add(" "); | 1320 stream->Add(" "); |
1321 right()->PrintNameTo(stream); | 1321 right()->PrintNameTo(stream); |
1322 if (CheckFlag(kCanOverflow)) stream->Add(" !"); | 1322 if (CheckFlag(kCanOverflow)) stream->Add(" !"); |
1323 if (CheckFlag(kBailoutOnMinusZero)) stream->Add(" -0?"); | 1323 if (CheckFlag(kBailoutOnMinusZero)) stream->Add(" -0?"); |
1324 } | 1324 } |
1325 | 1325 |
1326 | 1326 |
1327 Range* HBitwise::InferRange() { | 1327 Range* HBitwise::InferRange(Zone* zone) { |
1328 if (op() == Token::BIT_XOR) return HValue::InferRange(); | 1328 if (op() == Token::BIT_XOR) return HValue::InferRange(zone); |
1329 int32_t left_mask = (left()->range() != NULL) | 1329 int32_t left_mask = (left()->range() != NULL) |
1330 ? left()->range()->Mask() | 1330 ? left()->range()->Mask() |
1331 : 0xffffffff; | 1331 : 0xffffffff; |
1332 int32_t right_mask = (right()->range() != NULL) | 1332 int32_t right_mask = (right()->range() != NULL) |
1333 ? right()->range()->Mask() | 1333 ? right()->range()->Mask() |
1334 : 0xffffffff; | 1334 : 0xffffffff; |
1335 int32_t result_mask = (op() == Token::BIT_AND) | 1335 int32_t result_mask = (op() == Token::BIT_AND) |
1336 ? left_mask & right_mask | 1336 ? left_mask & right_mask |
1337 : left_mask | right_mask; | 1337 : left_mask | right_mask; |
1338 return (result_mask >= 0) | 1338 return (result_mask >= 0) |
1339 ? new Range(0, result_mask) | 1339 ? new(zone) Range(0, result_mask) |
1340 : HValue::InferRange(); | 1340 : HValue::InferRange(zone); |
1341 } | 1341 } |
1342 | 1342 |
1343 | 1343 |
1344 Range* HSar::InferRange() { | 1344 Range* HSar::InferRange(Zone* zone) { |
1345 if (right()->IsConstant()) { | 1345 if (right()->IsConstant()) { |
1346 HConstant* c = HConstant::cast(right()); | 1346 HConstant* c = HConstant::cast(right()); |
1347 if (c->HasInteger32Value()) { | 1347 if (c->HasInteger32Value()) { |
1348 Range* result = (left()->range() != NULL) | 1348 Range* result = (left()->range() != NULL) |
1349 ? left()->range()->Copy() | 1349 ? left()->range()->Copy(zone) |
1350 : new Range(); | 1350 : new(zone) Range(); |
1351 result->Sar(c->Integer32Value()); | 1351 result->Sar(c->Integer32Value()); |
1352 result->set_can_be_minus_zero(false); | 1352 result->set_can_be_minus_zero(false); |
1353 return result; | 1353 return result; |
1354 } | 1354 } |
1355 } | 1355 } |
1356 return HValue::InferRange(); | 1356 return HValue::InferRange(zone); |
1357 } | 1357 } |
1358 | 1358 |
1359 | 1359 |
1360 Range* HShr::InferRange() { | 1360 Range* HShr::InferRange(Zone* zone) { |
1361 if (right()->IsConstant()) { | 1361 if (right()->IsConstant()) { |
1362 HConstant* c = HConstant::cast(right()); | 1362 HConstant* c = HConstant::cast(right()); |
1363 if (c->HasInteger32Value()) { | 1363 if (c->HasInteger32Value()) { |
1364 int shift_count = c->Integer32Value() & 0x1f; | 1364 int shift_count = c->Integer32Value() & 0x1f; |
1365 if (left()->range()->CanBeNegative()) { | 1365 if (left()->range()->CanBeNegative()) { |
1366 // Only compute bounds if the result always fits into an int32. | 1366 // Only compute bounds if the result always fits into an int32. |
1367 return (shift_count >= 1) | 1367 return (shift_count >= 1) |
1368 ? new Range(0, static_cast<uint32_t>(0xffffffff) >> shift_count) | 1368 ? new(zone) Range(0, |
1369 : new Range(); | 1369 static_cast<uint32_t>(0xffffffff) >> shift_count) |
| 1370 : new(zone) Range(); |
1370 } else { | 1371 } else { |
1371 // For positive inputs we can use the >> operator. | 1372 // For positive inputs we can use the >> operator. |
1372 Range* result = (left()->range() != NULL) | 1373 Range* result = (left()->range() != NULL) |
1373 ? left()->range()->Copy() | 1374 ? left()->range()->Copy(zone) |
1374 : new Range(); | 1375 : new(zone) Range(); |
1375 result->Sar(c->Integer32Value()); | 1376 result->Sar(c->Integer32Value()); |
1376 result->set_can_be_minus_zero(false); | 1377 result->set_can_be_minus_zero(false); |
1377 return result; | 1378 return result; |
1378 } | 1379 } |
1379 } | 1380 } |
1380 } | 1381 } |
1381 return HValue::InferRange(); | 1382 return HValue::InferRange(zone); |
1382 } | 1383 } |
1383 | 1384 |
1384 | 1385 |
1385 Range* HShl::InferRange() { | 1386 Range* HShl::InferRange(Zone* zone) { |
1386 if (right()->IsConstant()) { | 1387 if (right()->IsConstant()) { |
1387 HConstant* c = HConstant::cast(right()); | 1388 HConstant* c = HConstant::cast(right()); |
1388 if (c->HasInteger32Value()) { | 1389 if (c->HasInteger32Value()) { |
1389 Range* result = (left()->range() != NULL) | 1390 Range* result = (left()->range() != NULL) |
1390 ? left()->range()->Copy() | 1391 ? left()->range()->Copy(zone) |
1391 : new Range(); | 1392 : new(zone) Range(); |
1392 result->Shl(c->Integer32Value()); | 1393 result->Shl(c->Integer32Value()); |
1393 result->set_can_be_minus_zero(false); | 1394 result->set_can_be_minus_zero(false); |
1394 return result; | 1395 return result; |
1395 } | 1396 } |
1396 } | 1397 } |
1397 return HValue::InferRange(); | 1398 return HValue::InferRange(zone); |
1398 } | 1399 } |
1399 | 1400 |
1400 | 1401 |
1401 Range* HLoadKeyedSpecializedArrayElement::InferRange() { | 1402 Range* HLoadKeyedSpecializedArrayElement::InferRange(Zone* zone) { |
1402 switch (elements_kind()) { | 1403 switch (elements_kind()) { |
1403 case EXTERNAL_PIXEL_ELEMENTS: | 1404 case EXTERNAL_PIXEL_ELEMENTS: |
1404 return new Range(0, 255); | 1405 return new(zone) Range(0, 255); |
1405 case EXTERNAL_BYTE_ELEMENTS: | 1406 case EXTERNAL_BYTE_ELEMENTS: |
1406 return new Range(-128, 127); | 1407 return new(zone) Range(-128, 127); |
1407 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: | 1408 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: |
1408 return new Range(0, 255); | 1409 return new(zone) Range(0, 255); |
1409 case EXTERNAL_SHORT_ELEMENTS: | 1410 case EXTERNAL_SHORT_ELEMENTS: |
1410 return new Range(-32768, 32767); | 1411 return new(zone) Range(-32768, 32767); |
1411 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: | 1412 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: |
1412 return new Range(0, 65535); | 1413 return new(zone) Range(0, 65535); |
1413 default: | 1414 default: |
1414 return HValue::InferRange(); | 1415 return HValue::InferRange(zone); |
1415 } | 1416 } |
1416 } | 1417 } |
1417 | 1418 |
1418 | 1419 |
1419 void HCompareGeneric::PrintDataTo(StringStream* stream) { | 1420 void HCompareGeneric::PrintDataTo(StringStream* stream) { |
1420 stream->Add(Token::Name(token())); | 1421 stream->Add(Token::Name(token())); |
1421 stream->Add(" "); | 1422 stream->Add(" "); |
1422 HBinaryOperation::PrintDataTo(stream); | 1423 HBinaryOperation::PrintDataTo(stream); |
1423 } | 1424 } |
1424 | 1425 |
(...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2249 | 2250 |
2250 | 2251 |
2251 void HCheckPrototypeMaps::Verify() { | 2252 void HCheckPrototypeMaps::Verify() { |
2252 HInstruction::Verify(); | 2253 HInstruction::Verify(); |
2253 ASSERT(HasNoUses()); | 2254 ASSERT(HasNoUses()); |
2254 } | 2255 } |
2255 | 2256 |
2256 #endif | 2257 #endif |
2257 | 2258 |
2258 } } // namespace v8::internal | 2259 } } // namespace v8::internal |
OLD | NEW |