| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 | 90 |
| 91 void HDeadCodeEliminationPhase::RemoveDeadInstructions() { | 91 void HDeadCodeEliminationPhase::RemoveDeadInstructions() { |
| 92 ZoneList<HPhi*> worklist(graph()->blocks()->length(), zone()); | 92 ZoneList<HPhi*> worklist(graph()->blocks()->length(), zone()); |
| 93 | 93 |
| 94 // Remove any instruction not marked kIsLive. | 94 // Remove any instruction not marked kIsLive. |
| 95 for (int i = 0; i < graph()->blocks()->length(); ++i) { | 95 for (int i = 0; i < graph()->blocks()->length(); ++i) { |
| 96 HBasicBlock* block = graph()->blocks()->at(i); | 96 HBasicBlock* block = graph()->blocks()->at(i); |
| 97 for (HInstructionIterator it(block); !it.Done(); it.Advance()) { | 97 for (HInstructionIterator it(block); !it.Done(); it.Advance()) { |
| 98 HInstruction* instr = it.Current(); | 98 HInstruction* instr = it.Current(); |
| 99 if (!instr->CheckFlag(HValue::kIsLive)) { | 99 if (!instr->CheckFlag(HValue::kIsLive)) { |
| 100 // Instruction has not been marked live; assume it is dead and remove. | 100 // Instruction has not been marked live, so remove it. |
| 101 // TODO(titzer): we don't remove constants because some special ones | 101 if (!instr->IsConstant() || instr->block()->block_id() != 0) { |
| 102 // might be used by later phases and are assumed to be in the graph | 102 // TODO(titzer): Some global constants in block 0 can be used |
| 103 if (!instr->IsConstant()) instr->DeleteAndReplaceWith(NULL); | 103 // again later, and can't currently be removed. Fix that. |
| 104 instr->DeleteAndReplaceWith(NULL); |
| 105 } |
| 104 } else { | 106 } else { |
| 105 // Clear the liveness flag to leave the graph clean for the next DCE. | 107 // Clear the liveness flag to leave the graph clean for the next DCE. |
| 106 instr->ClearFlag(HValue::kIsLive); | 108 instr->ClearFlag(HValue::kIsLive); |
| 107 } | 109 } |
| 108 } | 110 } |
| 109 // Collect phis that are dead and remove them in the next pass. | 111 // Collect phis that are dead and remove them in the next pass. |
| 110 for (int j = 0; j < block->phis()->length(); j++) { | 112 for (int j = 0; j < block->phis()->length(); j++) { |
| 111 HPhi* phi = block->phis()->at(j); | 113 HPhi* phi = block->phis()->at(j); |
| 112 if (!phi->CheckFlag(HValue::kIsLive)) { | 114 if (!phi->CheckFlag(HValue::kIsLive)) { |
| 113 worklist.Add(phi, zone()); | 115 worklist.Add(phi, zone()); |
| 114 } else { | 116 } else { |
| 115 phi->ClearFlag(HValue::kIsLive); | 117 phi->ClearFlag(HValue::kIsLive); |
| 116 } | 118 } |
| 117 } | 119 } |
| 118 } | 120 } |
| 119 | 121 |
| 120 // Process phis separately to avoid simultaneously mutating the phi list. | 122 // Process phis separately to avoid simultaneously mutating the phi list. |
| 121 while (!worklist.is_empty()) { | 123 while (!worklist.is_empty()) { |
| 122 HPhi* phi = worklist.RemoveLast(); | 124 HPhi* phi = worklist.RemoveLast(); |
| 123 HBasicBlock* block = phi->block(); | 125 HBasicBlock* block = phi->block(); |
| 124 phi->DeleteAndReplaceWith(NULL); | 126 phi->DeleteAndReplaceWith(NULL); |
| 125 if (phi->HasMergedIndex()) { | 127 if (phi->HasMergedIndex()) { |
| 126 block->RecordDeletedPhi(phi->merged_index()); | 128 block->RecordDeletedPhi(phi->merged_index()); |
| 127 } | 129 } |
| 128 } | 130 } |
| 129 } | 131 } |
| 130 | 132 |
| 131 } } // namespace v8::internal | 133 } } // namespace v8::internal |
| OLD | NEW |