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 1370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1381 | 1381 |
1382 void HEnterInlined::PrintDataTo(StringStream* stream) { | 1382 void HEnterInlined::PrintDataTo(StringStream* stream) { |
1383 SmartArrayPointer<char> name = function()->debug_name()->ToCString(); | 1383 SmartArrayPointer<char> name = function()->debug_name()->ToCString(); |
1384 stream->Add("%s, id=%d", *name, function()->id()); | 1384 stream->Add("%s, id=%d", *name, function()->id()); |
1385 } | 1385 } |
1386 | 1386 |
1387 | 1387 |
1388 HConstant::HConstant(Handle<Object> handle, Representation r) | 1388 HConstant::HConstant(Handle<Object> handle, Representation r) |
1389 : handle_(handle), | 1389 : handle_(handle), |
1390 has_int32_value_(false), | 1390 has_int32_value_(false), |
1391 has_double_value_(false), | 1391 has_double_value_(false) { |
1392 int32_value_(0), | |
1393 double_value_(0) { | |
1394 set_representation(r); | 1392 set_representation(r); |
1395 SetFlag(kUseGVN); | 1393 SetFlag(kUseGVN); |
1396 if (handle_->IsNumber()) { | 1394 if (handle_->IsNumber()) { |
1397 double n = handle_->Number(); | 1395 double n = handle_->Number(); |
1398 double roundtrip_value = static_cast<double>(static_cast<int32_t>(n)); | 1396 double roundtrip_value = static_cast<double>(static_cast<int32_t>(n)); |
1399 has_int32_value_ = BitCast<int64_t>(roundtrip_value) == BitCast<int64_t>(n); | 1397 has_int32_value_ = BitCast<int64_t>(roundtrip_value) == |
Michael Starzinger
2012/07/10 12:05:51
Can we move this predicate into a static helper fu
sanjoy
2012/07/10 19:25:17
Done.
| |
1400 if (has_int32_value_) int32_value_ = static_cast<int32_t>(n); | 1398 BitCast<int64_t>(n); |
1399 | |
1400 int32_value_ = DoubleToInt32(n); | |
1401 double_value_ = n; | 1401 double_value_ = n; |
1402 has_double_value_ = true; | 1402 has_double_value_ = true; |
1403 } | 1403 } |
1404 } | 1404 } |
1405 | 1405 |
1406 | 1406 |
1407 HConstant::HConstant(int32_t integer_value, Representation r) | |
1408 : has_int32_value_(true), has_double_value_(true), | |
1409 int32_value_(integer_value) { | |
1410 set_representation(r); | |
1411 SetFlag(kUseGVN); | |
1412 double_value_ = FastI2D(integer_value); | |
1413 } | |
1414 | |
1415 | |
1416 HConstant::HConstant(double double_value, Representation r) | |
1417 : has_int32_value_(false), | |
1418 has_double_value_(true), | |
1419 int32_value_(DoubleToInt32(double_value)), | |
1420 double_value_(double_value) { | |
1421 set_representation(r); | |
1422 SetFlag(kUseGVN); | |
1423 double roundtrip_value = static_cast<double>( | |
1424 static_cast<int32_t>(double_value)); | |
1425 has_int32_value_ = BitCast<int64_t>(roundtrip_value) == | |
Michael Starzinger
2012/07/10 12:05:51
Likewise.
sanjoy
2012/07/10 19:25:17
Done.
| |
1426 BitCast<int64_t>(double_value); | |
1427 } | |
1428 | |
1429 | |
1407 HConstant* HConstant::CopyToRepresentation(Representation r, Zone* zone) const { | 1430 HConstant* HConstant::CopyToRepresentation(Representation r, Zone* zone) const { |
1408 if (r.IsInteger32() && !has_int32_value_) return NULL; | 1431 if (r.IsInteger32() && !has_int32_value_) return NULL; |
1409 if (r.IsDouble() && !has_double_value_) return NULL; | 1432 if (r.IsDouble() && !has_double_value_) return NULL; |
1433 | |
1434 if (handle_.is_null()) { | |
1435 ASSERT(has_int32_value_ || has_double_value_); | |
1436 if (has_int32_value_) return new(zone) HConstant(int32_value_, r); | |
1437 return new(zone) HConstant(double_value_, r); | |
1438 } | |
1410 return new(zone) HConstant(handle_, r); | 1439 return new(zone) HConstant(handle_, r); |
1411 } | 1440 } |
1412 | 1441 |
1413 | 1442 |
1414 HConstant* HConstant::CopyToTruncatedInt32(Zone* zone) const { | 1443 HConstant* HConstant::CopyToTruncatedInt32(Zone* zone) const { |
1415 if (!has_double_value_) return NULL; | 1444 if (has_int32_value_) { |
1416 int32_t truncated = NumberToInt32(*handle_); | 1445 if (handle_.is_null()) { |
1417 return new(zone) HConstant(FACTORY->NewNumberFromInt(truncated), | 1446 return new(zone) HConstant(int32_value_, Representation::Integer32()); |
1418 Representation::Integer32()); | 1447 } else { |
1448 // Re-use the existing Handle if possible. | |
1449 return new(zone) HConstant(handle_, Representation::Integer32()); | |
1450 } | |
1451 } else if (has_double_value_) { | |
1452 return new(zone) HConstant(DoubleToInt32(double_value_), | |
1453 Representation::Integer32()); | |
1454 } else { | |
1455 return NULL; | |
1456 } | |
1419 } | 1457 } |
1420 | 1458 |
1421 | 1459 |
1422 bool HConstant::ToBoolean() const { | 1460 bool HConstant::ToBoolean() { |
1423 // Converts the constant's boolean value according to | 1461 // Converts the constant's boolean value according to |
1424 // ECMAScript section 9.2 ToBoolean conversion. | 1462 // ECMAScript section 9.2 ToBoolean conversion. |
1425 if (HasInteger32Value()) return Integer32Value() != 0; | 1463 if (HasInteger32Value()) return Integer32Value() != 0; |
1426 if (HasDoubleValue()) { | 1464 if (HasDoubleValue()) { |
1427 double v = DoubleValue(); | 1465 double v = DoubleValue(); |
1428 return v != 0 && !isnan(v); | 1466 return v != 0 && !isnan(v); |
1429 } | 1467 } |
1430 if (handle()->IsTrue()) return true; | 1468 Handle<Object> literal = handle(); |
1431 if (handle()->IsFalse()) return false; | 1469 if (literal->IsTrue()) return true; |
1432 if (handle()->IsUndefined()) return false; | 1470 if (literal->IsFalse()) return false; |
1433 if (handle()->IsNull()) return false; | 1471 if (literal->IsUndefined()) return false; |
1434 if (handle()->IsString() && | 1472 if (literal->IsNull()) return false; |
1435 String::cast(*handle())->length() == 0) return false; | 1473 if (literal->IsString() && String::cast(*literal)->length() == 0) { |
1474 return false; | |
1475 } | |
1436 return true; | 1476 return true; |
1437 } | 1477 } |
1438 | 1478 |
1439 void HConstant::PrintDataTo(StringStream* stream) { | 1479 void HConstant::PrintDataTo(StringStream* stream) { |
1440 handle()->ShortPrint(stream); | 1480 if (has_int32_value_) { |
1481 stream->Add("%d ", int32_value_); | |
1482 } else if (has_double_value_) { | |
1483 stream->Add("%lf ", double_value_); | |
1484 } else { | |
1485 handle()->ShortPrint(stream); | |
1486 } | |
1441 } | 1487 } |
1442 | 1488 |
1443 | 1489 |
1444 bool HArrayLiteral::IsCopyOnWrite() const { | 1490 bool HArrayLiteral::IsCopyOnWrite() const { |
1445 if (!boilerplate_object_->IsJSObject()) return false; | 1491 if (!boilerplate_object_->IsJSObject()) return false; |
1446 return Handle<JSObject>::cast(boilerplate_object_)->elements()->map() == | 1492 return Handle<JSObject>::cast(boilerplate_object_)->elements()->map() == |
1447 HEAP->fixed_cow_array_map(); | 1493 HEAP->fixed_cow_array_map(); |
1448 } | 1494 } |
1449 | 1495 |
1450 | 1496 |
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2082 HType result = HType::Uninitialized(); | 2128 HType result = HType::Uninitialized(); |
2083 for (int i = 0; i < OperandCount(); ++i) { | 2129 for (int i = 0; i < OperandCount(); ++i) { |
2084 HType current = OperandAt(i)->type(); | 2130 HType current = OperandAt(i)->type(); |
2085 result = result.Combine(current); | 2131 result = result.Combine(current); |
2086 } | 2132 } |
2087 return result; | 2133 return result; |
2088 } | 2134 } |
2089 | 2135 |
2090 | 2136 |
2091 HType HConstant::CalculateInferredType() { | 2137 HType HConstant::CalculateInferredType() { |
2092 return HType::TypeFromValue(handle_); | 2138 if (has_int32_value_) { |
2139 return Smi::IsValid(int32_value_) ? HType::Smi() : HType::HeapNumber(); | |
2140 } | |
2141 if (has_double_value_) return HType::HeapNumber(); | |
2142 return HType::TypeFromValue(Handle<Object>(handle_)); | |
Michael Starzinger
2012/07/10 12:05:51
There is no need to apply the copy constructor of
sanjoy
2012/07/10 19:25:17
Done.
| |
2093 } | 2143 } |
2094 | 2144 |
2095 | 2145 |
2096 HType HCompareGeneric::CalculateInferredType() { | 2146 HType HCompareGeneric::CalculateInferredType() { |
2097 return HType::Boolean(); | 2147 return HType::Boolean(); |
2098 } | 2148 } |
2099 | 2149 |
2100 | 2150 |
2101 HType HInstanceOf::CalculateInferredType() { | 2151 HType HInstanceOf::CalculateInferredType() { |
2102 return HType::Boolean(); | 2152 return HType::Boolean(); |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2540 | 2590 |
2541 | 2591 |
2542 void HCheckPrototypeMaps::Verify() { | 2592 void HCheckPrototypeMaps::Verify() { |
2543 HInstruction::Verify(); | 2593 HInstruction::Verify(); |
2544 ASSERT(HasNoUses()); | 2594 ASSERT(HasNoUses()); |
2545 } | 2595 } |
2546 | 2596 |
2547 #endif | 2597 #endif |
2548 | 2598 |
2549 } } // namespace v8::internal | 2599 } } // namespace v8::internal |
OLD | NEW |