Home | History | Annotate | Download | only in compiler

Lines Matching refs:Node

10 #include "src/compiler/node.h"
11 #include "src/compiler/node-properties.h"
28 GraphReducer::GraphReducer(Zone* zone, Graph* graph, Node* dead)
48 void GraphReducer::ReduceNode(Node* node) {
51 Push(node);
54 // Process the node on the top of the stack, potentially pushing more or
55 // popping the node off the stack.
59 Node* const node = revisit_.top();
61 if (state_.Get(node) == State::kRevisit) {
63 Push(node);
81 Reduction GraphReducer::Reduce(Node* const node) {
85 Reduction reduction = (*i)->Reduce(node);
88 } else if (reduction.replacement() == node) {
89 // {replacement} == {node} represents an in-place reduction. Rerun
90 // all the other reducers for this node, as now there may be more
96 // {node} was replaced by another node.
107 return Reducer::Changed(node);
113 Node* node = entry.node;
114 DCHECK(state_.Get(node) == State::kOnStack);
116 if (node->IsDead()) return Pop(); // Node was killed while on stack.
118 Node::Inputs node_inputs = node->inputs();
123 Node* input = node_inputs[i];
124 if (input != node && Recurse(input)) {
130 Node* input = node_inputs[i];
131 if (input != node && Recurse(input)) {
137 // Remember the max node id before reduction.
140 // All inputs should be visited or on stack. Apply reductions to node.
141 Reduction reduction = Reduce(node);
143 // If there was no reduction, pop {node} and continue.
146 // Check if the reduction is an in-place update of the {node}.
147 Node* const replacement = reduction.replacement();
148 if (replacement == node) {
149 // In-place update of {node}, may need to recurse on an input.
150 Node::Inputs node_inputs = node->inputs();
152 Node* input = node_inputs[i];
153 if (input != node && Recurse(input)) {
160 // After reducing the node, pop it off the stack.
164 if (replacement != node) {
165 Replace(node, replacement, max_id);
167 // Revisit all uses of the node.
168 for (Node* const user : node->uses()) {
169 // Don't revisit this node if it refers to itself.
170 if (user != node) Revisit(user);
176 void GraphReducer::Replace(Node* node, Node* replacement) {
177 Replace(node, replacement, std::numeric_limits<NodeId>::max());
181 void GraphReducer::Replace(Node* node, Node* replacement, NodeId max_id) {
184 os << "- Replacing " << *node << " with " << *replacement << std::endl;
186 if (node == graph()->start()) graph()->SetStart(replacement);
187 if (node == graph()->end()) graph()->SetEnd(replacement);
189 // {replacement} is an old node, so unlink {node} and assume that
191 for (Edge edge : node->use_edges()) {
192 Node* const user = edge.from();
195 // Don't revisit this node if it refers to itself.
196 if (user != node) Revisit(user);
198 node->Kill();
200 // Replace all old uses of {node} with {replacement}, but allow new nodes
201 // created by this reduction to use {node}.
202 for (Edge edge : node->use_edges()) {
203 Node* const user = edge.from();
206 // Don't revisit this node if it refers to itself.
207 if (user != node) Revisit(user);
210 // Unlink {node} if it's no longer used.
211 if (node->uses().empty()) node->Kill();
213 // If there was a replacement, reduce it after popping {node}.
219 void GraphReducer::ReplaceWithValue(Node* node, Node* value, Node* effect,
220 Node* control) {
221 if (effect == nullptr && node->op()->EffectInputCount() > 0) {
222 effect = NodeProperties::GetEffectInput(node);
224 if (control == nullptr && node->op()->ControlInputCount() > 0) {
225 control = NodeProperties::GetControlInput(node);
229 for (Edge edge : node->use_edges()) {
230 Node* const user = edge.from();
243 // TODO(jarin) Check that the node cannot throw (otherwise, it
260 Node* node = stack_.top().node;
261 state_.Set(node, State::kVisited);
266 void GraphReducer::Push(Node* const node) {
267 DCHECK(state_.Get(node) != State::kOnStack);
268 state_.Set(node, State::kOnStack);
269 stack_.push({node, 0});
273 bool GraphReducer::Recurse(Node* node) {
274 if (state_.Get(node) > State::kRevisit) return false;
275 Push(node);
280 void GraphReducer::Revisit(Node* node) {
281 if (state_.Get(node) == State::kVisited) {
282 state_.Set(node, State::kRevisit);
283 revisit_.push(node);