OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 Handle<Object> literal = node->handle(); | 259 Handle<Object> literal = node->handle(); |
260 if (literal->IsSmi()) { | 260 if (literal->IsSmi()) { |
261 node->type()->SetAsLikelySmi(); | 261 node->type()->SetAsLikelySmi(); |
262 node->set_side_effect_free(true); | 262 node->set_side_effect_free(true); |
263 } else if (literal->IsString()) { | 263 } else if (literal->IsString()) { |
264 Handle<String> lit_str(Handle<String>::cast(literal)); | 264 Handle<String> lit_str(Handle<String>::cast(literal)); |
265 if (!Heap::prototype_symbol()->Equals(*lit_str)) { | 265 if (!Heap::prototype_symbol()->Equals(*lit_str)) { |
266 func_name_inferrer_.PushName(lit_str); | 266 func_name_inferrer_.PushName(lit_str); |
267 } | 267 } |
268 } else if (literal->IsHeapNumber()) { | 268 } else if (literal->IsHeapNumber()) { |
269 node->set_side_effect_free(true); | 269 if (node->to_int32()) { |
| 270 // Any HeapNumber has an int32 value if it is the input to a bit op. |
| 271 node->set_side_effect_free(true); |
| 272 } else { |
| 273 double double_value = HeapNumber::cast(*literal)->value(); |
| 274 int32_t int32_value = DoubleToInt32(double_value); |
| 275 node->set_side_effect_free(double_value == int32_value); |
| 276 } |
270 } | 277 } |
271 } | 278 } |
272 | 279 |
273 | 280 |
274 void AstOptimizer::VisitRegExpLiteral(RegExpLiteral* node) { | 281 void AstOptimizer::VisitRegExpLiteral(RegExpLiteral* node) { |
275 USE(node); | 282 USE(node); |
276 } | 283 } |
277 | 284 |
278 | 285 |
279 void AstOptimizer::VisitArrayLiteral(ArrayLiteral* node) { | 286 void AstOptimizer::VisitArrayLiteral(ArrayLiteral* node) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 break; | 320 break; |
314 case Token::ASSIGN_BIT_OR: | 321 case Token::ASSIGN_BIT_OR: |
315 case Token::ASSIGN_BIT_XOR: | 322 case Token::ASSIGN_BIT_XOR: |
316 case Token::ASSIGN_BIT_AND: | 323 case Token::ASSIGN_BIT_AND: |
317 case Token::ASSIGN_SHL: | 324 case Token::ASSIGN_SHL: |
318 case Token::ASSIGN_SAR: | 325 case Token::ASSIGN_SAR: |
319 case Token::ASSIGN_SHR: | 326 case Token::ASSIGN_SHR: |
320 node->type()->SetAsLikelySmiIfUnknown(); | 327 node->type()->SetAsLikelySmiIfUnknown(); |
321 node->target()->type()->SetAsLikelySmiIfUnknown(); | 328 node->target()->type()->SetAsLikelySmiIfUnknown(); |
322 node->value()->type()->SetAsLikelySmiIfUnknown(); | 329 node->value()->type()->SetAsLikelySmiIfUnknown(); |
| 330 node->value()->set_to_int32(true); |
323 node->value()->set_no_negative_zero(true); | 331 node->value()->set_no_negative_zero(true); |
324 break; | 332 break; |
325 case Token::ASSIGN_ADD: | 333 case Token::ASSIGN_ADD: |
326 case Token::ASSIGN_SUB: | 334 case Token::ASSIGN_SUB: |
327 case Token::ASSIGN_MUL: | 335 case Token::ASSIGN_MUL: |
328 case Token::ASSIGN_DIV: | 336 case Token::ASSIGN_DIV: |
329 case Token::ASSIGN_MOD: | 337 case Token::ASSIGN_MOD: |
330 if (node->type()->IsLikelySmi()) { | 338 if (node->type()->IsLikelySmi()) { |
331 node->target()->type()->SetAsLikelySmiIfUnknown(); | 339 node->target()->type()->SetAsLikelySmiIfUnknown(); |
332 node->value()->type()->SetAsLikelySmiIfUnknown(); | 340 node->value()->type()->SetAsLikelySmiIfUnknown(); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 node->expression()->set_no_negative_zero(true); | 439 node->expression()->set_no_negative_zero(true); |
432 } | 440 } |
433 Visit(node->expression()); | 441 Visit(node->expression()); |
434 if (FLAG_safe_int32_compiler) { | 442 if (FLAG_safe_int32_compiler) { |
435 switch (node->op()) { | 443 switch (node->op()) { |
436 case Token::BIT_NOT: | 444 case Token::BIT_NOT: |
437 node->expression()->set_to_int32(true); | 445 node->expression()->set_to_int32(true); |
438 // Fall through. | 446 // Fall through. |
439 case Token::ADD: | 447 case Token::ADD: |
440 case Token::SUB: | 448 case Token::SUB: |
441 case Token::NOT: | |
442 node->set_side_effect_free(node->expression()->side_effect_free()); | 449 node->set_side_effect_free(node->expression()->side_effect_free()); |
443 break; | 450 break; |
| 451 case Token::NOT: |
444 case Token::DELETE: | 452 case Token::DELETE: |
445 case Token::TYPEOF: | 453 case Token::TYPEOF: |
446 case Token::VOID: | 454 case Token::VOID: |
447 break; | 455 break; |
448 default: | 456 default: |
449 UNREACHABLE(); | 457 UNREACHABLE(); |
450 break; | 458 break; |
451 } | 459 } |
452 } else if (node->op() == Token::BIT_NOT) { | 460 } else if (node->op() == Token::BIT_NOT) { |
453 node->expression()->set_to_int32(true); | 461 node->expression()->set_to_int32(true); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 case Token::COMMA: | 554 case Token::COMMA: |
547 case Token::OR: | 555 case Token::OR: |
548 case Token::AND: | 556 case Token::AND: |
549 break; | 557 break; |
550 case Token::BIT_OR: | 558 case Token::BIT_OR: |
551 case Token::BIT_XOR: | 559 case Token::BIT_XOR: |
552 case Token::BIT_AND: | 560 case Token::BIT_AND: |
553 case Token::SHL: | 561 case Token::SHL: |
554 case Token::SAR: | 562 case Token::SAR: |
555 case Token::SHR: | 563 case Token::SHR: |
| 564 // Add one to the number of bit operations in this expression. |
| 565 node->set_num_bit_ops(1); |
| 566 // Fall through. |
556 case Token::ADD: | 567 case Token::ADD: |
557 case Token::SUB: | 568 case Token::SUB: |
558 case Token::MUL: | 569 case Token::MUL: |
559 case Token::DIV: | 570 case Token::DIV: |
560 case Token::MOD: | 571 case Token::MOD: |
561 node->set_side_effect_free(node->left()->side_effect_free() && | 572 node->set_side_effect_free(node->left()->side_effect_free() && |
562 node->right()->side_effect_free()); | 573 node->right()->side_effect_free()); |
| 574 node->set_num_bit_ops(node->num_bit_ops() + |
| 575 node->left()->num_bit_ops() + |
| 576 node->right()->num_bit_ops()); |
| 577 if (!node->no_negative_zero() && node->op() == Token::MUL) { |
| 578 node->set_side_effect_free(false); |
| 579 } |
563 break; | 580 break; |
564 default: | 581 default: |
565 UNREACHABLE(); | 582 UNREACHABLE(); |
566 break; | 583 break; |
567 } | 584 } |
568 } | 585 } |
569 } | 586 } |
570 | 587 |
571 | 588 |
572 void AstOptimizer::VisitCompareOperation(CompareOperation* node) { | 589 void AstOptimizer::VisitCompareOperation(CompareOperation* node) { |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
933 optimizer.Optimize(body); | 950 optimizer.Optimize(body); |
934 if (optimizer.HasStackOverflow()) { | 951 if (optimizer.HasStackOverflow()) { |
935 return false; | 952 return false; |
936 } | 953 } |
937 } | 954 } |
938 return true; | 955 return true; |
939 } | 956 } |
940 | 957 |
941 | 958 |
942 } } // namespace v8::internal | 959 } } // namespace v8::internal |
OLD | NEW |