OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 next_block_id_(0), | 677 next_block_id_(0), |
678 info_(info), | 678 info_(info), |
679 blocks_(8), | 679 blocks_(8), |
680 values_(16), | 680 values_(16), |
681 phi_list_(NULL) { | 681 phi_list_(NULL) { |
682 start_environment_ = new HEnvironment(NULL, info->scope(), info->closure()); | 682 start_environment_ = new HEnvironment(NULL, info->scope(), info->closure()); |
683 start_environment_->set_ast_id(info->function()->id()); | 683 start_environment_->set_ast_id(info->function()->id()); |
684 } | 684 } |
685 | 685 |
686 | 686 |
687 bool HGraph::AllowAggressiveOptimizations() const { | 687 bool HGraph::AllowCodeMotion() const { |
688 return info()->shared_info()->opt_count() + 1 < Compiler::kDefaultMaxOptCount; | 688 return info()->shared_info()->opt_count() + 1 < Compiler::kDefaultMaxOptCount; |
689 } | 689 } |
690 | 690 |
691 | 691 |
692 Handle<Code> HGraph::Compile() { | 692 Handle<Code> HGraph::Compile() { |
693 int values = GetMaximumValueID(); | 693 int values = GetMaximumValueID(); |
694 if (values > LAllocator::max_initial_value_ids()) { | 694 if (values > LAllocator::max_initial_value_ids()) { |
695 if (FLAG_trace_bailout) PrintF("Function is too big\n"); | 695 if (FLAG_trace_bailout) PrintF("Function is too big\n"); |
696 return Handle<Code>::null(); | 696 return Handle<Code>::null(); |
697 } | 697 } |
(...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1439 TraceGVN("Found loop invariant instruction %d\n", instr->id()); | 1439 TraceGVN("Found loop invariant instruction %d\n", instr->id()); |
1440 // Move the instruction out of the loop. | 1440 // Move the instruction out of the loop. |
1441 instr->Unlink(); | 1441 instr->Unlink(); |
1442 instr->InsertBefore(pre_header->end()); | 1442 instr->InsertBefore(pre_header->end()); |
1443 } | 1443 } |
1444 } | 1444 } |
1445 instr = next; | 1445 instr = next; |
1446 } | 1446 } |
1447 } | 1447 } |
1448 | 1448 |
1449 // Only move instructions that postdominate the loop header (i.e. are | 1449 |
1450 // always executed inside the loop). This is to avoid unnecessary | |
1451 // deoptimizations assuming the loop is executed at least once. | |
1452 // TODO(fschneider): Better type feedback should give us information | |
1453 // about code that was never executed. | |
1454 bool HGlobalValueNumberer::ShouldMove(HInstruction* instr, | 1450 bool HGlobalValueNumberer::ShouldMove(HInstruction* instr, |
1455 HBasicBlock* loop_header) { | 1451 HBasicBlock* loop_header) { |
1456 if (FLAG_aggressive_loop_invariant_motion && | 1452 // If we've disabled code motion, don't move any instructions. |
1457 !instr->IsChange() && | 1453 if (!graph_->AllowCodeMotion()) return false; |
1458 (!instr->IsCheckInstruction() || | 1454 |
1459 graph_->AllowAggressiveOptimizations())) { | 1455 // If --aggressive-loop-invariant-motion, move everything except change |
| 1456 // instructions. |
| 1457 if (FLAG_aggressive_loop_invariant_motion && !instr->IsChange()) { |
1460 return true; | 1458 return true; |
1461 } | 1459 } |
| 1460 |
| 1461 // Otherwise only move instructions that postdominate the loop header |
| 1462 // (i.e. are always executed inside the loop). This is to avoid |
| 1463 // unnecessary deoptimizations assuming the loop is executed at least |
| 1464 // once. TODO(fschneider): Better type feedback should give us |
| 1465 // information about code that was never executed. |
1462 HBasicBlock* block = instr->block(); | 1466 HBasicBlock* block = instr->block(); |
1463 bool result = true; | 1467 bool result = true; |
1464 if (block != loop_header) { | 1468 if (block != loop_header) { |
1465 for (int i = 1; i < loop_header->predecessors()->length(); ++i) { | 1469 for (int i = 1; i < loop_header->predecessors()->length(); ++i) { |
1466 bool found = false; | 1470 bool found = false; |
1467 HBasicBlock* pred = loop_header->predecessors()->at(i); | 1471 HBasicBlock* pred = loop_header->predecessors()->at(i); |
1468 while (pred != loop_header) { | 1472 while (pred != loop_header) { |
1469 if (pred == block) found = true; | 1473 if (pred == block) found = true; |
1470 pred = pred->dominator(); | 1474 pred = pred->dominator(); |
1471 } | 1475 } |
(...skipping 4394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5866 } | 5870 } |
5867 } | 5871 } |
5868 | 5872 |
5869 #ifdef DEBUG | 5873 #ifdef DEBUG |
5870 if (graph_ != NULL) graph_->Verify(); | 5874 if (graph_ != NULL) graph_->Verify(); |
5871 if (allocator_ != NULL) allocator_->Verify(); | 5875 if (allocator_ != NULL) allocator_->Verify(); |
5872 #endif | 5876 #endif |
5873 } | 5877 } |
5874 | 5878 |
5875 } } // namespace v8::internal | 5879 } } // namespace v8::internal |
OLD | NEW |