Index: src/compiler/graph-reducer.cc |
diff --git a/src/compiler/graph-reducer.cc b/src/compiler/graph-reducer.cc |
index 7f3a66e0decdba47017d5980f172d3bc5b379351..579af10d2a9e9fe01c0d508c02457ec681ef322e 100644 |
--- a/src/compiler/graph-reducer.cc |
+++ b/src/compiler/graph-reducer.cc |
@@ -12,6 +12,9 @@ namespace v8 { |
namespace internal { |
namespace compiler { |
+bool Reducer::Finish() { return true; } |
+ |
+ |
enum class GraphReducer::State : uint8_t { |
kUnvisited, |
kRevisit, |
@@ -28,6 +31,9 @@ GraphReducer::GraphReducer(Graph* graph, Zone* zone) |
stack_(zone) {} |
+GraphReducer::~GraphReducer() {} |
+ |
+ |
void GraphReducer::AddReducer(Reducer* reducer) { |
reducers_.push_back(reducer); |
} |
@@ -59,7 +65,14 @@ void GraphReducer::ReduceNode(Node* node) { |
} |
-void GraphReducer::ReduceGraph() { ReduceNode(graph()->end()); } |
+void GraphReducer::ReduceGraph() { |
+ for (;;) { |
+ ReduceNode(graph()->end()); |
+ if (Finish()) break; |
+ // Reset all marks on the graph in preparation to re-reduce the graph. |
+ state_.Reset(graph()); |
+ } |
+} |
Reduction GraphReducer::Reduce(Node* const node) { |
@@ -135,39 +148,52 @@ void GraphReducer::ReduceTop() { |
// After reducing the node, pop it off the stack. |
Pop(); |
- // Revisit all uses of the node. |
- for (Node* const use : node->uses()) { |
- // Don't revisit this node if it refers to itself. |
- if (use != node) Revisit(use); |
- } |
- |
// Check if we have a new replacement. |
if (replacement != node) { |
- if (node == graph()->start()) graph()->SetStart(replacement); |
- if (node == graph()->end()) graph()->SetEnd(replacement); |
// If {node} was replaced by an old node, unlink {node} and assume that |
// {replacement} was already reduced and finish. |
if (replacement->id() < node_count) { |
- node->ReplaceUses(replacement); |
- node->Kill(); |
+ Replace(node, replacement); |
} else { |
// Otherwise {node} was replaced by a new node. Replace all old uses of |
// {node} with {replacement}. New nodes created by this reduction can |
// use {node}. |
+ if (node == graph()->start()) graph()->SetStart(replacement); |
+ if (node == graph()->end()) graph()->SetEnd(replacement); |
for (Edge edge : node->use_edges()) { |
- if (edge.from()->id() < node_count) { |
+ Node* const user = edge.from(); |
+ if (user->id() < node_count) { |
edge.UpdateTo(replacement); |
+ // Don't revisit this node if it refers to itself. |
+ if (user != node) Revisit(user); |
} |
} |
// Unlink {node} if it's no longer used. |
- if (node->uses().empty()) { |
- node->Kill(); |
- } |
+ if (node->uses().empty()) node->Kill(); |
// If there was a replacement, reduce it after popping {node}. |
Recurse(replacement); |
} |
+ } else { |
+ // Revisit all uses of the node. |
+ for (Node* const user : node->uses()) { |
+ // Don't revisit this node if it refers to itself. |
+ if (user != node) Revisit(user); |
+ } |
+ } |
+} |
+ |
+ |
+void GraphReducer::Replace(Node* node, Node* replacement) { |
titzer
2015/05/06 09:22:08
I prefer the simplification in my other CL which m
Benedikt Meurer
2015/05/06 09:33:30
Done.
|
+ if (node == graph()->start()) graph()->SetStart(replacement); |
+ if (node == graph()->end()) graph()->SetEnd(replacement); |
+ for (Edge edge : node->use_edges()) { |
+ Node* const user = edge.from(); |
+ edge.UpdateTo(replacement); |
+ // Don't revisit this node if it refers to itself. |
+ if (user != node) Revisit(user); |
} |
+ node->Kill(); |
} |