Index: src/hydrogen-mark-unreachable.cc |
diff --git a/src/hydrogen-infer-types.cc b/src/hydrogen-mark-unreachable.cc |
similarity index 53% |
copy from src/hydrogen-infer-types.cc |
copy to src/hydrogen-mark-unreachable.cc |
index 01c608473672f0e3bdfc507b2c8a03526242983f..73123b325763639f5e4b7b7a0305ff2d4abf39e5 100644 |
--- a/src/hydrogen-infer-types.cc |
+++ b/src/hydrogen-mark-unreachable.cc |
@@ -25,53 +25,54 @@ |
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
-#include "hydrogen-infer-types.h" |
+#include "hydrogen-mark-unreachable.h" |
namespace v8 { |
namespace internal { |
-void HInferTypesPhase::InferTypes(int from_inclusive, int to_inclusive) { |
- for (int i = from_inclusive; i <= to_inclusive; ++i) { |
- HBasicBlock* block = graph()->blocks()->at(i); |
- const ZoneList<HPhi*>* phis = block->phis(); |
- for (int j = 0; j < phis->length(); j++) { |
- phis->at(j)->UpdateInferredType(); |
- } |
- |
- for (HInstructionIterator it(block); !it.Done(); it.Advance()) { |
- it.Current()->UpdateInferredType(); |
- } |
- |
- if (block->IsLoopHeader()) { |
- HBasicBlock* last_back_edge = |
- block->loop_information()->GetLastBackEdge(); |
- InferTypes(i + 1, last_back_edge->block_id()); |
- // Skip all blocks already processed by the recursive call. |
- i = last_back_edge->block_id(); |
- // Update phis of the loop header now after the whole loop body is |
- // guaranteed to be processed. |
- for (int j = 0; j < block->phis()->length(); ++j) { |
- HPhi* phi = block->phis()->at(j); |
- worklist_.Add(phi, zone()); |
- in_worklist_.Add(phi->id()); |
- } |
- while (!worklist_.is_empty()) { |
- HValue* current = worklist_.RemoveLast(); |
- in_worklist_.Remove(current->id()); |
- if (current->UpdateInferredType()) { |
- for (HUseIterator it(current->uses()); !it.Done(); it.Advance()) { |
- HValue* use = it.value(); |
- if (!in_worklist_.Contains(use->id())) { |
- in_worklist_.Add(use->id()); |
- worklist_.Add(use, zone()); |
+void HMarkUnreachableBlocksPhase::MarkUnreachableBlocks() { |
+ // If there is unreachable code in the graph, propagate the unreachable marks |
+ // using a fixed-point iteration. |
+ bool changed = true; |
+ const ZoneList<HBasicBlock*>* blocks = graph()->blocks(); |
+ while (changed) { |
+ changed = false; |
+ for (int i = 0; i < blocks->length(); i++) { |
+ HBasicBlock* block = blocks->at(i); |
+ if (block->IsReachable()) { |
Jakob Kummerow
2013/10/01 11:59:20
nit: you can avoid one level of indentation by tur
danno
2013/10/23 11:46:51
Done.
|
+ bool is_reachable = blocks->at(0) == block; |
+ for (HPredecessorIterator it(block); !it.Done(); it.Advance()) { |
+ HBasicBlock* predecessor = it.Current(); |
+ // A block is reachable if one of it's predecessor is reachable, |
Jakob Kummerow
2013/10/01 17:47:13
nit: s/it's predecessor/its predecessors/
danno
2013/10/23 11:46:51
Done.
|
+ // doesn't deoptimize and either is known to transfer control to the |
+ // block or has a control flow instruction for which the next block |
+ // cannot be determined. |
+ if (predecessor->IsReachable() && !predecessor->IsDeoptimizing()) { |
+ HBasicBlock* pred_succ; |
+ bool known_pred_succ = |
+ predecessor->end()->KnownSuccessorBlock(&pred_succ); |
+ if (!known_pred_succ || pred_succ == block) { |
+ is_reachable = true; |
+ break; |
} |
} |
+ if (block->is_osr_entry()) { |
+ is_reachable = true; |
+ } |
+ } |
+ if (!is_reachable) { |
+ block->MarkUnreachable(); |
+ changed = true; |
} |
} |
- ASSERT(in_worklist_.IsEmpty()); |
} |
} |
} |
+ |
+void HMarkUnreachableBlocksPhase::Run() { |
+ MarkUnreachableBlocks(); |
+} |
+ |
} } // namespace v8::internal |