Home | History | Annotate | Download | only in compiler

Lines Matching refs:Node

10 #include "src/compiler/node.h"
11 #include "src/compiler/node-properties.h"
29 GraphReducer::GraphReducer(Zone* zone, Graph* graph, Node* dead)
46 void GraphReducer::ReduceNode(Node* node) {
49 Push(node);
52 // Process the node on the top of the stack, potentially pushing more or
53 // popping the node off the stack.
57 Node* const node = revisit_.top();
59 if (state_.Get(node) == State::kRevisit) {
61 Push(node);
79 Reduction GraphReducer::Reduce(Node* const node) {
83 Reduction reduction = (*i)->Reduce(node);
86 } else if (reduction.replacement() == node) {
87 // {replacement} == {node} represents an in-place reduction. Rerun
88 // all the other reducers for this node, as now there may be more
94 // {node} was replaced by another node.
105 return Reducer::Changed(node);
111 Node* node = entry.node;
112 DCHECK(state_.Get(node) == State::kOnStack);
114 if (node->IsDead()) return Pop(); // Node was killed while on stack.
117 int start = entry.input_index < node->InputCount() ? entry.input_index : 0;
118 for (int i = start; i < node->InputCount(); i++) {
119 Node* input = node->InputAt(i);
121 if (input != node && Recurse(input)) return;
124 Node* input = node->InputAt(i);
126 if (input != node && Recurse(input)) return;
129 // Remember the max node id before reduction.
132 // All inputs should be visited or on stack. Apply reductions to node.
133 Reduction reduction = Reduce(node);
135 // If there was no reduction, pop {node} and continue.
138 // Check if the reduction is an in-place update of the {node}.
139 Node* const replacement = reduction.replacement();
140 if (replacement == node) {
141 // In-place update of {node}, may need to recurse on an input.
142 for (int i = 0; i < node->InputCount(); ++i) {
143 Node* input = node->InputAt(i);
145 if (input != node && Recurse(input)) return;
149 // After reducing the node, pop it off the stack.
153 if (replacement != node) {
154 Replace(node, replacement, max_id);
156 // Revisit all uses of the node.
157 for (Node* const user : node->uses()) {
158 // Don't revisit this node if it refers to itself.
159 if (user != node) Revisit(user);
165 void GraphReducer::Replace(Node* node, Node* replacement) {
166 Replace(node, replacement, std::numeric_limits<NodeId>::max());
170 void GraphReducer::Replace(Node* node, Node* replacement, NodeId max_id) {
171 if (node == graph()->start()) graph()->SetStart(replacement);
172 if (node == graph()->end()) graph()->SetEnd(replacement);
174 // {replacement} is an old node, so unlink {node} and assume that
176 for (Edge edge : node->use_edges()) {
177 Node* const user = edge.from();
180 // Don't revisit this node if it refers to itself.
181 if (user != node) Revisit(user);
183 node->Kill();
185 // Replace all old uses of {node} with {replacement}, but allow new nodes
186 // created by this reduction to use {node}.
187 for (Edge edge : node->use_edges()) {
188 Node* const user = edge.from();
191 // Don't revisit this node if it refers to itself.
192 if (user != node) Revisit(user);
195 // Unlink {node} if it's no longer used.
196 if (node->uses().empty()) node->Kill();
198 // If there was a replacement, reduce it after popping {node}.
204 void GraphReducer::ReplaceWithValue(Node* node, Node* value, Node* effect,
205 Node* control) {
206 if (effect == nullptr && node->op()->EffectInputCount() > 0) {
207 effect = NodeProperties::GetEffectInput(node);
209 if (control == nullptr && node->op()->ControlInputCount() > 0) {
210 control = NodeProperties::GetControlInput(node);
214 for (Edge edge : node->use_edges()) {
215 Node* const user = edge.from();
241 Node* node = stack_.top().node;
242 state_.Set(node, State::kVisited);
247 void GraphReducer::Push(Node* const node) {
248 DCHECK(state_.Get(node) != State::kOnStack);
249 state_.Set(node, State::kOnStack);
250 stack_.push({node, 0});
254 bool GraphReducer::Recurse(Node* node) {
255 if (state_.Get(node) > State::kRevisit) return false;
256 Push(node);
261 void GraphReducer::Revisit(Node* node) {
262 if (state_.Get(node) == State::kVisited) {
263 state_.Set(node, State::kRevisit);
264 revisit_.push(node);