Index: src/hydrogen-gvn.cc |
diff --git a/src/hydrogen-gvn.cc b/src/hydrogen-gvn.cc |
index 0628ff76fbac5f3ae0bcfee0359972d60ccabd14..daca593b39908ff899e84587506e8e05d4bce392 100644 |
--- a/src/hydrogen-gvn.cc |
+++ b/src/hydrogen-gvn.cc |
@@ -364,47 +364,48 @@ void HSideEffectMap::Store(GVNFlagSet flags, HInstruction* instr) { |
HGlobalValueNumberingPhase::HGlobalValueNumberingPhase(HGraph* graph) |
- : HPhase("H_Global value numbering", graph), |
- removed_side_effects_(false), |
- block_side_effects_(graph->blocks()->length(), zone()), |
- loop_side_effects_(graph->blocks()->length(), zone()), |
- visited_on_paths_(graph->blocks()->length(), zone()) { |
- ASSERT(!AllowHandleAllocation::IsAllowed()); |
- block_side_effects_.AddBlock(GVNFlagSet(), graph->blocks()->length(), |
- zone()); |
- loop_side_effects_.AddBlock(GVNFlagSet(), graph->blocks()->length(), |
+ : HPhase("H_Global value numbering", graph), |
+ removed_side_effects_(false), |
+ block_side_effects_(graph->blocks()->length(), zone()), |
+ loop_side_effects_(graph->blocks()->length(), zone()), |
+ visited_on_paths_(graph->blocks()->length(), zone()) { |
+ ASSERT(!AllowHandleAllocation::IsAllowed()); |
+ block_side_effects_.AddBlock(GVNFlagSet(), graph->blocks()->length(), |
zone()); |
+ loop_side_effects_.AddBlock(GVNFlagSet(), graph->blocks()->length(), |
+ zone()); |
} |
-void HGlobalValueNumberingPhase::Reset() { |
- ASSERT(block_side_effects_.length() == graph()->blocks()->length()); |
- ASSERT(loop_side_effects_.length() == graph()->blocks()->length()); |
- for (int i = 0; i < graph()->blocks()->length(); ++i) { |
- block_side_effects_[i] = GVNFlagSet(); |
- loop_side_effects_[i] = GVNFlagSet(); |
- } |
- visited_on_paths_.Clear(); |
-} |
+void HGlobalValueNumberingPhase::Run() { |
+ ASSERT(!removed_side_effects_); |
+ for (int i = FLAG_gvn_iterations; i > 0; --i) { |
+ // Compute the side effects. |
+ ComputeBlockSideEffects(); |
+ |
+ // Perform loop invariant code motion if requested. |
+ if (FLAG_loop_invariant_code_motion) LoopInvariantCodeMotion(); |
+ // Perform the actual value numbering. |
+ AnalyzeGraph(); |
-void HGlobalValueNumberingPhase::Analyze() { |
- removed_side_effects_ = false; |
- ComputeBlockSideEffects(); |
- if (FLAG_loop_invariant_code_motion) { |
- LoopInvariantCodeMotion(); |
+ // Continue GVN if we removed any side effects. |
+ if (!removed_side_effects_) break; |
+ removed_side_effects_ = false; |
+ |
+ // Clear all side effects. |
+ ASSERT_EQ(block_side_effects_.length(), graph()->blocks()->length()); |
+ ASSERT_EQ(loop_side_effects_.length(), graph()->blocks()->length()); |
+ for (int i = 0; i < graph()->blocks()->length(); ++i) { |
+ block_side_effects_[i].RemoveAll(); |
+ loop_side_effects_[i].RemoveAll(); |
+ } |
+ visited_on_paths_.Clear(); |
} |
- AnalyzeGraph(); |
} |
void HGlobalValueNumberingPhase::ComputeBlockSideEffects() { |
- // The Analyze phase of GVN can be called multiple times. Clear loop side |
- // effects before computing them to erase the contents from previous Analyze |
- // passes. |
- for (int i = 0; i < loop_side_effects_.length(); ++i) { |
- loop_side_effects_[i].RemoveAll(); |
- } |
for (int i = graph()->blocks()->length() - 1; i >= 0; --i) { |
// Compute side effects for the block. |
HBasicBlock* block = graph()->blocks()->at(i); |