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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 return ConvertAndSetOverflow(result, overflow); | 278 return ConvertAndSetOverflow(result, overflow); |
279 } | 279 } |
280 | 280 |
281 | 281 |
282 static int32_t MulWithoutOverflow(int32_t a, int32_t b, bool* overflow) { | 282 static int32_t MulWithoutOverflow(int32_t a, int32_t b, bool* overflow) { |
283 int64_t result = static_cast<int64_t>(a) * static_cast<int64_t>(b); | 283 int64_t result = static_cast<int64_t>(a) * static_cast<int64_t>(b); |
284 return ConvertAndSetOverflow(result, overflow); | 284 return ConvertAndSetOverflow(result, overflow); |
285 } | 285 } |
286 | 286 |
287 | 287 |
288 int32_t Range::Mask() const { | 288 void Range::ToBitRange(BitRange* bits) const { |
289 if (lower_ == upper_) return lower_; | 289 BitRange::SetFromRange(bits, lower_, upper_); |
290 if (lower_ >= 0) { | |
291 int32_t res = 1; | |
292 while (res < upper_) { | |
293 res = (res << 1) | 1; | |
294 } | |
295 return res; | |
296 } | |
297 return 0xffffffff; | |
298 } | 290 } |
299 | 291 |
300 | 292 |
301 void Range::AddConstant(int32_t value) { | 293 void Range::AddConstant(int32_t value) { |
302 if (value == 0) return; | 294 if (value == 0) return; |
303 bool may_overflow = false; // Overflow is ignored here. | 295 bool may_overflow = false; // Overflow is ignored here. |
304 lower_ = AddWithoutOverflow(lower_, value, &may_overflow); | 296 lower_ = AddWithoutOverflow(lower_, value, &may_overflow); |
305 upper_ = AddWithoutOverflow(upper_, value, &may_overflow); | 297 upper_ = AddWithoutOverflow(upper_, value, &may_overflow); |
306 #ifdef DEBUG | 298 #ifdef DEBUG |
307 Verify(); | 299 Verify(); |
(...skipping 2048 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2356 | 2348 |
2357 void HMathMinMax::InferRepresentation(HInferRepresentation* h_infer) { | 2349 void HMathMinMax::InferRepresentation(HInferRepresentation* h_infer) { |
2358 ASSERT(CheckFlag(kFlexibleRepresentation)); | 2350 ASSERT(CheckFlag(kFlexibleRepresentation)); |
2359 Representation new_rep = RepresentationFromInputs(); | 2351 Representation new_rep = RepresentationFromInputs(); |
2360 UpdateRepresentation(new_rep, h_infer, "inputs"); | 2352 UpdateRepresentation(new_rep, h_infer, "inputs"); |
2361 // Do not care about uses. | 2353 // Do not care about uses. |
2362 } | 2354 } |
2363 | 2355 |
2364 | 2356 |
2365 Range* HBitwise::InferRange(Zone* zone) { | 2357 Range* HBitwise::InferRange(Zone* zone) { |
2366 if (op() == Token::BIT_XOR) { | 2358 if (representation().IsInteger32()) { |
2367 if (left()->HasRange() && right()->HasRange()) { | 2359 BitRange left_bits, right_bits; |
2368 // The maximum value has the high bit, and all bits below, set: | |
2369 // (1 << high) - 1. | |
2370 // If the range can be negative, the minimum int is a negative number with | |
2371 // the high bit, and all bits below, unset: | |
2372 // -(1 << high). | |
2373 // If it cannot be negative, conservatively choose 0 as minimum int. | |
2374 int64_t left_upper = left()->range()->upper(); | |
2375 int64_t left_lower = left()->range()->lower(); | |
2376 int64_t right_upper = right()->range()->upper(); | |
2377 int64_t right_lower = right()->range()->lower(); | |
2378 | 2360 |
2379 if (left_upper < 0) left_upper = ~left_upper; | 2361 if (left()->HasRange()) { |
2380 if (left_lower < 0) left_lower = ~left_lower; | 2362 left()->range()->ToBitRange(&left_bits); |
2381 if (right_upper < 0) right_upper = ~right_upper; | 2363 } |
2382 if (right_lower < 0) right_lower = ~right_lower; | |
2383 | 2364 |
2384 int high = MostSignificantBit( | 2365 if (right()->HasRange()) { |
2385 static_cast<uint32_t>( | 2366 right()->range()->ToBitRange(&right_bits); |
2386 left_upper | left_lower | right_upper | right_lower)); | 2367 } |
2387 | 2368 |
2388 int64_t limit = 1; | 2369 BitRange result; |
2389 limit <<= high; | 2370 switch (op()) { |
2390 int32_t min = (left()->range()->CanBeNegative() || | 2371 case Token::BIT_AND: |
2391 right()->range()->CanBeNegative()) | 2372 result = BitRange::And(left_bits, right_bits); |
2392 ? static_cast<int32_t>(-limit) : 0; | 2373 break; |
2393 return new(zone) Range(min, static_cast<int32_t>(limit - 1)); | 2374 case Token::BIT_OR: |
| 2375 result = BitRange::Or(left_bits, right_bits); |
| 2376 break; |
| 2377 case Token::BIT_XOR: |
| 2378 result = BitRange::Xor(left_bits, right_bits); |
| 2379 break; |
| 2380 default: |
| 2381 UNREACHABLE(); |
2394 } | 2382 } |
| 2383 |
| 2384 int32_t lower = kMaxInt, upper = kMinInt; // 'empty' range. |
| 2385 result.ExtendRange(&lower, &upper); |
| 2386 return new(zone) Range(lower, upper); |
| 2387 } else { |
2395 return HValue::InferRange(zone); | 2388 return HValue::InferRange(zone); |
2396 } | 2389 } |
2397 const int32_t kDefaultMask = static_cast<int32_t>(0xffffffff); | |
2398 int32_t left_mask = (left()->range() != NULL) | |
2399 ? left()->range()->Mask() | |
2400 : kDefaultMask; | |
2401 int32_t right_mask = (right()->range() != NULL) | |
2402 ? right()->range()->Mask() | |
2403 : kDefaultMask; | |
2404 int32_t result_mask = (op() == Token::BIT_AND) | |
2405 ? left_mask & right_mask | |
2406 : left_mask | right_mask; | |
2407 return (result_mask >= 0) | |
2408 ? new(zone) Range(0, result_mask) | |
2409 : HValue::InferRange(zone); | |
2410 } | 2390 } |
2411 | 2391 |
2412 | 2392 |
2413 Range* HSar::InferRange(Zone* zone) { | 2393 Range* HSar::InferRange(Zone* zone) { |
2414 if (right()->IsConstant()) { | 2394 if (right()->IsConstant()) { |
2415 HConstant* c = HConstant::cast(right()); | 2395 HConstant* c = HConstant::cast(right()); |
2416 if (c->HasInteger32Value()) { | 2396 if (c->HasInteger32Value()) { |
2417 Range* result = (left()->range() != NULL) | 2397 Range* result = (left()->range() != NULL) |
2418 ? left()->range()->Copy(zone) | 2398 ? left()->range()->Copy(zone) |
2419 : new(zone) Range(); | 2399 : new(zone) Range(); |
(...skipping 1435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3855 case kBackingStore: | 3835 case kBackingStore: |
3856 if (!name_.is_null()) stream->Add(*String::cast(*name_)->ToCString()); | 3836 if (!name_.is_null()) stream->Add(*String::cast(*name_)->ToCString()); |
3857 stream->Add("[backing-store]"); | 3837 stream->Add("[backing-store]"); |
3858 break; | 3838 break; |
3859 } | 3839 } |
3860 | 3840 |
3861 stream->Add("@%d", offset()); | 3841 stream->Add("@%d", offset()); |
3862 } | 3842 } |
3863 | 3843 |
3864 } } // namespace v8::internal | 3844 } } // namespace v8::internal |
OLD | NEW |