| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/compiler/graph-reducer.h" | 5 #include "src/compiler/graph-reducer.h" |
| 6 | 6 |
| 7 #include <functional> | 7 #include <functional> |
| 8 | 8 |
| 9 #include "src/compiler/graph-inl.h" | 9 #include "src/compiler/graph-inl.h" |
| 10 | 10 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 // as now there may be more opportunities for reduction. | 42 // as now there may be more opportunities for reduction. |
| 43 reduce = true; | 43 reduce = true; |
| 44 skip = i; | 44 skip = i; |
| 45 break; | 45 break; |
| 46 } else { | 46 } else { |
| 47 if (node == graph_->start()) graph_->SetStart(replacement); | 47 if (node == graph_->start()) graph_->SetStart(replacement); |
| 48 if (node == graph_->end()) graph_->SetEnd(replacement); | 48 if (node == graph_->end()) graph_->SetEnd(replacement); |
| 49 // If {node} was replaced by an old node, unlink {node} and assume that | 49 // If {node} was replaced by an old node, unlink {node} and assume that |
| 50 // {replacement} was already reduced and finish. | 50 // {replacement} was already reduced and finish. |
| 51 if (replacement->id() < before) { | 51 if (replacement->id() < before) { |
| 52 node->RemoveAllInputs(); | |
| 53 node->ReplaceUses(replacement); | 52 node->ReplaceUses(replacement); |
| 53 node->Kill(); |
| 54 return; | 54 return; |
| 55 } | 55 } |
| 56 // Otherwise, {node} was replaced by a new node. Replace all old uses of | 56 // Otherwise, {node} was replaced by a new node. Replace all old uses of |
| 57 // {node} with {replacement}. New nodes created by this reduction can | 57 // {node} with {replacement}. New nodes created by this reduction can |
| 58 // use {node}. | 58 // use {node}. |
| 59 node->ReplaceUsesIf( | 59 node->ReplaceUsesIf( |
| 60 std::bind2nd(std::ptr_fun(&NodeIdIsLessThan), before), replacement); | 60 std::bind2nd(std::ptr_fun(&NodeIdIsLessThan), before), replacement); |
| 61 // Unlink {node} if it's no longer used. | 61 // Unlink {node} if it's no longer used. |
| 62 if (node->uses().empty()) node->RemoveAllInputs(); | 62 if (node->uses().empty()) { |
| 63 node->Kill(); |
| 64 } |
| 63 // Rerun all the reductions on the {replacement}. | 65 // Rerun all the reductions on the {replacement}. |
| 64 skip = reducers_.end(); | 66 skip = reducers_.end(); |
| 65 node = replacement; | 67 node = replacement; |
| 66 reduce = true; | 68 reduce = true; |
| 67 break; | 69 break; |
| 68 } | 70 } |
| 69 } | 71 } |
| 70 } | 72 } |
| 71 } | 73 } |
| 72 | 74 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 83 | 85 |
| 84 | 86 |
| 85 void GraphReducer::ReduceGraph() { | 87 void GraphReducer::ReduceGraph() { |
| 86 GraphReducerVisitor visitor(this); | 88 GraphReducerVisitor visitor(this); |
| 87 // Perform a post-order reduction of all nodes starting from the end. | 89 // Perform a post-order reduction of all nodes starting from the end. |
| 88 graph()->VisitNodeInputsFromEnd(&visitor); | 90 graph()->VisitNodeInputsFromEnd(&visitor); |
| 89 } | 91 } |
| 90 | 92 |
| 91 | 93 |
| 92 // TODO(titzer): partial graph reductions. | 94 // TODO(titzer): partial graph reductions. |
| 93 } | 95 |
| 94 } | 96 } // namespace compiler |
| 95 } // namespace v8::internal::compiler | 97 } // namespace internal |
| 98 } // namespace v8 |
| OLD | NEW |