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 3340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3351 rangeAnalysis.Analyze(); | 3351 rangeAnalysis.Analyze(); |
3352 } | 3352 } |
3353 ComputeMinusZeroChecks(); | 3353 ComputeMinusZeroChecks(); |
3354 | 3354 |
3355 // Eliminate redundant stack checks on backwards branches. | 3355 // Eliminate redundant stack checks on backwards branches. |
3356 HStackCheckEliminator sce(this); | 3356 HStackCheckEliminator sce(this); |
3357 sce.Process(); | 3357 sce.Process(); |
3358 | 3358 |
3359 EliminateRedundantBoundsChecks(); | 3359 EliminateRedundantBoundsChecks(); |
3360 DehoistSimpleArrayIndexComputations(); | 3360 DehoistSimpleArrayIndexComputations(); |
| 3361 if (FLAG_dead_code_elimination) DeadCodeElimination(); |
3361 | 3362 |
3362 return true; | 3363 return true; |
3363 } | 3364 } |
3364 | 3365 |
3365 | 3366 |
3366 // We try to "factor up" HBoundsCheck instructions towards the root of the | 3367 // We try to "factor up" HBoundsCheck instructions towards the root of the |
3367 // dominator tree. | 3368 // dominator tree. |
3368 // For now we handle checks where the index is like "exp + int32value". | 3369 // For now we handle checks where the index is like "exp + int32value". |
3369 // If in the dominator tree we check "exp + v1" and later (dominated) | 3370 // If in the dominator tree we check "exp + v1" and later (dominated) |
3370 // "exp + v2", if v2 <= v1 we can safely remove the second check, and if | 3371 // "exp + v2", if v2 <= v1 we can safely remove the second check, and if |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3780 array_instruction = static_cast<ArrayInstructionInterface*>(op); | 3781 array_instruction = static_cast<ArrayInstructionInterface*>(op); |
3781 } else { | 3782 } else { |
3782 continue; | 3783 continue; |
3783 } | 3784 } |
3784 DehoistArrayIndex(array_instruction); | 3785 DehoistArrayIndex(array_instruction); |
3785 } | 3786 } |
3786 } | 3787 } |
3787 } | 3788 } |
3788 | 3789 |
3789 | 3790 |
| 3791 void HGraph::DeadCodeElimination() { |
| 3792 HPhase phase("H_Dead code elimination", this); |
| 3793 ZoneList<HInstruction*> worklist(blocks_.length(), zone()); |
| 3794 for (int i = 0; i < blocks()->length(); ++i) { |
| 3795 for (HInstruction* instr = blocks()->at(i)->first(); |
| 3796 instr != NULL; |
| 3797 instr = instr->next()) { |
| 3798 if (instr->IsDead()) worklist.Add(instr, zone()); |
| 3799 } |
| 3800 } |
| 3801 |
| 3802 while (!worklist.is_empty()) { |
| 3803 HInstruction* instr = worklist.RemoveLast(); |
| 3804 if (FLAG_trace_dead_code_elimination) { |
| 3805 HeapStringAllocator allocator; |
| 3806 StringStream stream(&allocator); |
| 3807 instr->PrintNameTo(&stream); |
| 3808 stream.Add(" = "); |
| 3809 instr->PrintTo(&stream); |
| 3810 PrintF("[removing dead instruction %s]\n", *stream.ToCString()); |
| 3811 } |
| 3812 instr->DeleteAndReplaceWith(NULL); |
| 3813 for (int i = 0; i < instr->OperandCount(); ++i) { |
| 3814 HValue* operand = instr->OperandAt(i); |
| 3815 if (operand->IsDead()) worklist.Add(HInstruction::cast(operand), zone()); |
| 3816 } |
| 3817 } |
| 3818 } |
| 3819 |
| 3820 |
3790 HInstruction* HGraphBuilder::AddInstruction(HInstruction* instr) { | 3821 HInstruction* HGraphBuilder::AddInstruction(HInstruction* instr) { |
3791 ASSERT(current_block() != NULL); | 3822 ASSERT(current_block() != NULL); |
3792 current_block()->AddInstruction(instr); | 3823 current_block()->AddInstruction(instr); |
3793 return instr; | 3824 return instr; |
3794 } | 3825 } |
3795 | 3826 |
3796 | 3827 |
3797 void HGraphBuilder::AddSimulate(BailoutId ast_id) { | 3828 void HGraphBuilder::AddSimulate(BailoutId ast_id) { |
3798 ASSERT(current_block() != NULL); | 3829 ASSERT(current_block() != NULL); |
3799 current_block()->AddSimulate(ast_id); | 3830 current_block()->AddSimulate(ast_id); |
(...skipping 6140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9940 } | 9971 } |
9941 } | 9972 } |
9942 | 9973 |
9943 #ifdef DEBUG | 9974 #ifdef DEBUG |
9944 if (graph_ != NULL) graph_->Verify(false); // No full verify. | 9975 if (graph_ != NULL) graph_->Verify(false); // No full verify. |
9945 if (allocator_ != NULL) allocator_->Verify(); | 9976 if (allocator_ != NULL) allocator_->Verify(); |
9946 #endif | 9977 #endif |
9947 } | 9978 } |
9948 | 9979 |
9949 } } // namespace v8::internal | 9980 } } // namespace v8::internal |
OLD | NEW |