| 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 #ifndef V8_COMPILER_GRAPH_REDUCER_H_ | 5 #ifndef V8_COMPILER_GRAPH_REDUCER_H_ |
| 6 #define V8_COMPILER_GRAPH_REDUCER_H_ | 6 #define V8_COMPILER_GRAPH_REDUCER_H_ |
| 7 | 7 |
| 8 #include "src/compiler/node-marker.h" | 8 #include "src/compiler/node-marker.h" |
| 9 #include "src/zone-containers.h" | 9 #include "src/zone-containers.h" |
| 10 | 10 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 public: | 67 public: |
| 68 // Observe the actions of this reducer. | 68 // Observe the actions of this reducer. |
| 69 class Editor { | 69 class Editor { |
| 70 public: | 70 public: |
| 71 virtual ~Editor() {} | 71 virtual ~Editor() {} |
| 72 | 72 |
| 73 // Replace {node} with {replacement}. | 73 // Replace {node} with {replacement}. |
| 74 virtual void Replace(Node* node, Node* replacement) = 0; | 74 virtual void Replace(Node* node, Node* replacement) = 0; |
| 75 // Revisit the {node} again later. | 75 // Revisit the {node} again later. |
| 76 virtual void Revisit(Node* node) = 0; | 76 virtual void Revisit(Node* node) = 0; |
| 77 // Replace value uses of {node} with {value} and effect uses of {node} with |
| 78 // {effect}. If {effect == NULL}, then use the effect input to {node}. All |
| 79 // control uses will be relaxed assuming {node} cannot throw. |
| 80 virtual void ReplaceWithValue(Node* node, Node* value, |
| 81 Node* effect = nullptr, |
| 82 Node* control = nullptr) = 0; |
| 77 }; | 83 }; |
| 78 | 84 |
| 79 explicit AdvancedReducer(Editor* editor) : editor_(editor) {} | 85 explicit AdvancedReducer(Editor* editor) : editor_(editor) {} |
| 80 | 86 |
| 81 protected: | 87 protected: |
| 82 // Helper functions for subclasses to produce reductions for a node. | 88 // Helper functions for subclasses to produce reductions for a node. |
| 83 static Reduction Replace(Node* node) { return Reducer::Replace(node); } | 89 static Reduction Replace(Node* node) { return Reducer::Replace(node); } |
| 84 | 90 |
| 85 // Helper functions for subclasses to edit the graph. | 91 // Helper functions for subclasses to edit the graph. |
| 86 void Replace(Node* node, Node* replacement) { | 92 void Replace(Node* node, Node* replacement) { |
| 87 DCHECK_NOT_NULL(editor_); | 93 DCHECK_NOT_NULL(editor_); |
| 88 editor_->Replace(node, replacement); | 94 editor_->Replace(node, replacement); |
| 89 } | 95 } |
| 90 void Revisit(Node* node) { | 96 void Revisit(Node* node) { |
| 91 DCHECK_NOT_NULL(editor_); | 97 DCHECK_NOT_NULL(editor_); |
| 92 editor_->Revisit(node); | 98 editor_->Revisit(node); |
| 93 } | 99 } |
| 100 void ReplaceWithValue(Node* node, Node* value, Node* effect = nullptr, |
| 101 Node* control = nullptr) { |
| 102 DCHECK_NOT_NULL(editor_); |
| 103 editor_->ReplaceWithValue(node, value, effect, control); |
| 104 } |
| 94 | 105 |
| 95 private: | 106 private: |
| 96 Editor* const editor_; | 107 Editor* const editor_; |
| 97 }; | 108 }; |
| 98 | 109 |
| 99 | 110 |
| 100 // Performs an iterative reduction of a node graph. | 111 // Performs an iterative reduction of a node graph. |
| 101 class GraphReducer final : public AdvancedReducer::Editor { | 112 class GraphReducer final : public AdvancedReducer::Editor { |
| 102 public: | 113 public: |
| 103 GraphReducer(Graph* graph, Zone* zone); | 114 GraphReducer(Graph* graph, Zone* zone); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 119 int input_index; | 130 int input_index; |
| 120 }; | 131 }; |
| 121 | 132 |
| 122 // Reduce a single node. | 133 // Reduce a single node. |
| 123 Reduction Reduce(Node* const); | 134 Reduction Reduce(Node* const); |
| 124 // Reduce the node on top of the stack. | 135 // Reduce the node on top of the stack. |
| 125 void ReduceTop(); | 136 void ReduceTop(); |
| 126 | 137 |
| 127 // Replace {node} with {replacement}. | 138 // Replace {node} with {replacement}. |
| 128 void Replace(Node* node, Node* replacement) final; | 139 void Replace(Node* node, Node* replacement) final; |
| 140 |
| 141 // Replace value uses of {node} with {value} and effect uses of {node} with |
| 142 // {effect}. If {effect == NULL}, then use the effect input to {node}. All |
| 143 // control uses will be relaxed assuming {node} cannot throw. |
| 144 void ReplaceWithValue(Node* node, Node* value, Node* effect = nullptr, |
| 145 Node* control = nullptr) final; |
| 146 |
| 129 // Replace all uses of {node} with {replacement} if the id of {replacement} is | 147 // Replace all uses of {node} with {replacement} if the id of {replacement} is |
| 130 // less than or equal to {max_id}. Otherwise, replace all uses of {node} whose | 148 // less than or equal to {max_id}. Otherwise, replace all uses of {node} whose |
| 131 // id is less than or equal to {max_id} with the {replacement}. | 149 // id is less than or equal to {max_id} with the {replacement}. |
| 132 void Replace(Node* node, Node* replacement, NodeId max_id); | 150 void Replace(Node* node, Node* replacement, NodeId max_id); |
| 133 | 151 |
| 134 // Node stack operations. | 152 // Node stack operations. |
| 135 void Pop(); | 153 void Pop(); |
| 136 void Push(Node* node); | 154 void Push(Node* node); |
| 137 | 155 |
| 138 // Revisit queue operations. | 156 // Revisit queue operations. |
| 139 bool Recurse(Node* node); | 157 bool Recurse(Node* node); |
| 140 void Revisit(Node* node) final; | 158 void Revisit(Node* node) final; |
| 141 | 159 |
| 142 Graph* const graph_; | 160 Graph* const graph_; |
| 143 NodeMarker<State> state_; | 161 NodeMarker<State> state_; |
| 144 ZoneVector<Reducer*> reducers_; | 162 ZoneVector<Reducer*> reducers_; |
| 145 ZoneStack<Node*> revisit_; | 163 ZoneStack<Node*> revisit_; |
| 146 ZoneStack<NodeState> stack_; | 164 ZoneStack<NodeState> stack_; |
| 147 | 165 |
| 148 DISALLOW_COPY_AND_ASSIGN(GraphReducer); | 166 DISALLOW_COPY_AND_ASSIGN(GraphReducer); |
| 149 }; | 167 }; |
| 150 | 168 |
| 151 } // namespace compiler | 169 } // namespace compiler |
| 152 } // namespace internal | 170 } // namespace internal |
| 153 } // namespace v8 | 171 } // namespace v8 |
| 154 | 172 |
| 155 #endif // V8_COMPILER_GRAPH_REDUCER_H_ | 173 #endif // V8_COMPILER_GRAPH_REDUCER_H_ |
| OLD | NEW |