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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 | 68 |
69 | 69 |
70 int HValue::LoopWeight() const { | 70 int HValue::LoopWeight() const { |
71 const int w = FLAG_loop_weight; | 71 const int w = FLAG_loop_weight; |
72 static const int weights[] = { 1, w, w*w, w*w*w, w*w*w*w }; | 72 static const int weights[] = { 1, w, w*w, w*w*w, w*w*w*w }; |
73 return weights[Min(block()->LoopNestingDepth(), | 73 return weights[Min(block()->LoopNestingDepth(), |
74 static_cast<int>(ARRAY_SIZE(weights)-1))]; | 74 static_cast<int>(ARRAY_SIZE(weights)-1))]; |
75 } | 75 } |
76 | 76 |
77 | 77 |
| 78 Isolate* HValue::isolate() const { |
| 79 ASSERT(block() != NULL); |
| 80 return block()->graph()->isolate(); |
| 81 } |
| 82 |
| 83 |
78 void HValue::AssumeRepresentation(Representation r) { | 84 void HValue::AssumeRepresentation(Representation r) { |
79 if (CheckFlag(kFlexibleRepresentation)) { | 85 if (CheckFlag(kFlexibleRepresentation)) { |
80 ChangeRepresentation(r); | 86 ChangeRepresentation(r); |
81 // The representation of the value is dictated by type feedback and | 87 // The representation of the value is dictated by type feedback and |
82 // will not be changed later. | 88 // will not be changed later. |
83 ClearFlag(kFlexibleRepresentation); | 89 ClearFlag(kFlexibleRepresentation); |
84 } | 90 } |
85 } | 91 } |
86 | 92 |
87 | 93 |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 case kNonPrimitive: return "non-primitive"; | 340 case kNonPrimitive: return "non-primitive"; |
335 case kJSArray: return "array"; | 341 case kJSArray: return "array"; |
336 case kJSObject: return "object"; | 342 case kJSObject: return "object"; |
337 case kUninitialized: return "uninitialized"; | 343 case kUninitialized: return "uninitialized"; |
338 } | 344 } |
339 UNREACHABLE(); | 345 UNREACHABLE(); |
340 return "Unreachable code"; | 346 return "Unreachable code"; |
341 } | 347 } |
342 | 348 |
343 | 349 |
344 HType HType::TypeFromValue(Handle<Object> value) { | 350 HType HType::TypeFromValue(Isolate* isolate, Handle<Object> value) { |
345 // Handle dereferencing is safe here: an object's type as checked below | 351 // Handle dereferencing is safe here: an object's type as checked below |
346 // never changes. | 352 // never changes. |
347 AllowHandleDereference allow_handle_deref; | 353 AllowHandleDereference allow_handle_deref(isolate); |
348 | 354 |
349 HType result = HType::Tagged(); | 355 HType result = HType::Tagged(); |
350 if (value->IsSmi()) { | 356 if (value->IsSmi()) { |
351 result = HType::Smi(); | 357 result = HType::Smi(); |
352 } else if (value->IsHeapNumber()) { | 358 } else if (value->IsHeapNumber()) { |
353 result = HType::HeapNumber(); | 359 result = HType::HeapNumber(); |
354 } else if (value->IsString()) { | 360 } else if (value->IsString()) { |
355 result = HType::String(); | 361 result = HType::String(); |
356 } else if (value->IsBoolean()) { | 362 } else if (value->IsBoolean()) { |
357 result = HType::Boolean(); | 363 result = HType::Boolean(); |
(...skipping 912 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1270 | 1276 |
1271 HValue* HCheckInstanceType::Canonicalize() { | 1277 HValue* HCheckInstanceType::Canonicalize() { |
1272 if (check_ == IS_STRING && | 1278 if (check_ == IS_STRING && |
1273 !value()->type().IsUninitialized() && | 1279 !value()->type().IsUninitialized() && |
1274 value()->type().IsString()) { | 1280 value()->type().IsString()) { |
1275 return NULL; | 1281 return NULL; |
1276 } | 1282 } |
1277 | 1283 |
1278 if (check_ == IS_SYMBOL && value()->IsConstant()) { | 1284 if (check_ == IS_SYMBOL && value()->IsConstant()) { |
1279 // Dereferencing is safe here: a symbol cannot become a non-symbol. | 1285 // Dereferencing is safe here: a symbol cannot become a non-symbol. |
1280 AllowHandleDereference allow_handle_deref; | 1286 AllowHandleDereference allow_handle_deref(isolate()); |
1281 if (HConstant::cast(value())->handle()->IsSymbol()) return NULL; | 1287 if (HConstant::cast(value())->handle()->IsSymbol()) return NULL; |
1282 } | 1288 } |
1283 return this; | 1289 return this; |
1284 } | 1290 } |
1285 | 1291 |
1286 | 1292 |
1287 void HCheckInstanceType::GetCheckInterval(InstanceType* first, | 1293 void HCheckInstanceType::GetCheckInterval(InstanceType* first, |
1288 InstanceType* last) { | 1294 InstanceType* last) { |
1289 ASSERT(is_interval_check()); | 1295 ASSERT(is_interval_check()); |
1290 switch (check_) { | 1296 switch (check_) { |
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1757 double roundtrip_value = static_cast<double>(static_cast<int32_t>(value)); | 1763 double roundtrip_value = static_cast<double>(static_cast<int32_t>(value)); |
1758 return BitCast<int64_t>(roundtrip_value) == BitCast<int64_t>(value); | 1764 return BitCast<int64_t>(roundtrip_value) == BitCast<int64_t>(value); |
1759 } | 1765 } |
1760 | 1766 |
1761 | 1767 |
1762 HConstant::HConstant(Handle<Object> handle, Representation r) | 1768 HConstant::HConstant(Handle<Object> handle, Representation r) |
1763 : handle_(handle), | 1769 : handle_(handle), |
1764 has_int32_value_(false), | 1770 has_int32_value_(false), |
1765 has_double_value_(false) { | 1771 has_double_value_(false) { |
1766 // Dereferencing here is safe: the value of a number object does not change. | 1772 // Dereferencing here is safe: the value of a number object does not change. |
1767 AllowHandleDereference allow_handle_deref; | 1773 AllowHandleDereference allow_handle_deref(Isolate::Current()); |
1768 SetFlag(kUseGVN); | 1774 SetFlag(kUseGVN); |
1769 if (handle_->IsNumber()) { | 1775 if (handle_->IsNumber()) { |
1770 double n = handle_->Number(); | 1776 double n = handle_->Number(); |
1771 has_int32_value_ = IsInteger32(n); | 1777 has_int32_value_ = IsInteger32(n); |
1772 int32_value_ = DoubleToInt32(n); | 1778 int32_value_ = DoubleToInt32(n); |
1773 double_value_ = n; | 1779 double_value_ = n; |
1774 has_double_value_ = true; | 1780 has_double_value_ = true; |
1775 } | 1781 } |
1776 if (r.IsNone()) { | 1782 if (r.IsNone()) { |
1777 if (has_int32_value_) { | 1783 if (has_int32_value_) { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1838 bool HConstant::ToBoolean() { | 1844 bool HConstant::ToBoolean() { |
1839 // Converts the constant's boolean value according to | 1845 // Converts the constant's boolean value according to |
1840 // ECMAScript section 9.2 ToBoolean conversion. | 1846 // ECMAScript section 9.2 ToBoolean conversion. |
1841 if (HasInteger32Value()) return Integer32Value() != 0; | 1847 if (HasInteger32Value()) return Integer32Value() != 0; |
1842 if (HasDoubleValue()) { | 1848 if (HasDoubleValue()) { |
1843 double v = DoubleValue(); | 1849 double v = DoubleValue(); |
1844 return v != 0 && !isnan(v); | 1850 return v != 0 && !isnan(v); |
1845 } | 1851 } |
1846 // Dereferencing is safe: singletons do not change and strings are | 1852 // Dereferencing is safe: singletons do not change and strings are |
1847 // immutable. | 1853 // immutable. |
1848 AllowHandleDereference allow_handle_deref; | 1854 AllowHandleDereference allow_handle_deref(isolate()); |
1849 if (handle_->IsTrue()) return true; | 1855 if (handle_->IsTrue()) return true; |
1850 if (handle_->IsFalse()) return false; | 1856 if (handle_->IsFalse()) return false; |
1851 if (handle_->IsUndefined()) return false; | 1857 if (handle_->IsUndefined()) return false; |
1852 if (handle_->IsNull()) return false; | 1858 if (handle_->IsNull()) return false; |
1853 if (handle_->IsString() && String::cast(*handle_)->length() == 0) { | 1859 if (handle_->IsString() && String::cast(*handle_)->length() == 0) { |
1854 return false; | 1860 return false; |
1855 } | 1861 } |
1856 return true; | 1862 return true; |
1857 } | 1863 } |
1858 | 1864 |
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2526 } | 2532 } |
2527 return result; | 2533 return result; |
2528 } | 2534 } |
2529 | 2535 |
2530 | 2536 |
2531 HType HConstant::CalculateInferredType() { | 2537 HType HConstant::CalculateInferredType() { |
2532 if (has_int32_value_) { | 2538 if (has_int32_value_) { |
2533 return Smi::IsValid(int32_value_) ? HType::Smi() : HType::HeapNumber(); | 2539 return Smi::IsValid(int32_value_) ? HType::Smi() : HType::HeapNumber(); |
2534 } | 2540 } |
2535 if (has_double_value_) return HType::HeapNumber(); | 2541 if (has_double_value_) return HType::HeapNumber(); |
2536 return HType::TypeFromValue(handle_); | 2542 return HType::TypeFromValue(isolate(), handle_); |
2537 } | 2543 } |
2538 | 2544 |
2539 | 2545 |
2540 HType HCompareGeneric::CalculateInferredType() { | 2546 HType HCompareGeneric::CalculateInferredType() { |
2541 return HType::Boolean(); | 2547 return HType::Boolean(); |
2542 } | 2548 } |
2543 | 2549 |
2544 | 2550 |
2545 HType HInstanceOf::CalculateInferredType() { | 2551 HType HInstanceOf::CalculateInferredType() { |
2546 return HType::Boolean(); | 2552 return HType::Boolean(); |
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3060 | 3066 |
3061 | 3067 |
3062 void HCheckFunction::Verify() { | 3068 void HCheckFunction::Verify() { |
3063 HInstruction::Verify(); | 3069 HInstruction::Verify(); |
3064 ASSERT(HasNoUses()); | 3070 ASSERT(HasNoUses()); |
3065 } | 3071 } |
3066 | 3072 |
3067 #endif | 3073 #endif |
3068 | 3074 |
3069 } } // namespace v8::internal | 3075 } } // namespace v8::internal |
OLD | NEW |