Lines Matching defs:node

13 #include "src/compiler/node-observer.h"
14 #include "src/compiler/node-properties.h"
15 #include "src/compiler/node.h"
32 Reduction Reducer::Reduce(Node* node,
34 Reduction reduction = Reduce(node);
36 observe_node_manager->OnNodeChanged(reducer_name(), node,
67 void GraphReducer::ReduceNode(Node* node) {
70 Push(node);
73 // Process the node on the top of the stack, potentially pushing more or
74 // popping the node off the stack.
78 node = revisit_.front();
80 if (state_.Get(node) == State::kRevisit) {
82 Push(node);
100 Reduction GraphReducer::Reduce(Node* const node) {
105 Reduction reduction = (*i)->Reduce(node, observe_node_manager_);
108 } else if (reduction.replacement() == node) {
109 // {replacement} == {node} represents an in-place reduction. Rerun
110 // all the other reducers for this node, as now there may be more
117 StdoutStream{} << "- In-place update of #" << *node << " by reducer "
124 // {node} was replaced by another node.
130 StdoutStream{} << "- Replacement of #" << *node << " with #"
144 return Reducer::Changed(node);
150 Node* node = entry.node;
151 DCHECK_EQ(State::kOnStack, state_.Get(node));
153 if (node->IsDead()) return Pop(); // Node was killed while on stack.
155 Node::Inputs node_inputs = node->inputs();
161 if (input != node && Recurse(input)) {
168 if (input != node && Recurse(input)) {
174 // Remember the max node id before reduction.
177 // All inputs should be visited or on stack. Apply reductions to node.
178 Reduction reduction = Reduce(node);
180 // If there was no reduction, pop {node} and continue.
183 // Check if the reduction is an in-place update of the {node}.
185 if (replacement == node) {
186 for (Node* const user : node->uses()) {
187 DCHECK_IMPLIES(user == node, state_.Get(node) != State::kVisited);
191 // In-place update of {node}, may need to recurse on an input.
192 node_inputs = node->inputs();
195 if (input != node && Recurse(input)) {
202 // After reducing the node, pop it off the stack.
206 if (replacement != node) {
207 Replace(node, replacement, max_id);
212 void GraphReducer::Replace(Node* node, Node* replacement) {
213 Replace(node, replacement, std::numeric_limits<NodeId>::max());
217 void GraphReducer::Replace(Node* node, Node* replacement, NodeId max_id) {
218 if (node == graph()->start()) graph()->SetStart(replacement);
219 if (node == graph()->end()) graph()->SetEnd(replacement);
221 // {replacement} is an old node, so unlink {node} and assume that
223 for (Edge edge : node->use_edges()) {
227 // Don't revisit this node if it refers to itself.
228 if (user != node) Revisit(user);
230 node->Kill();
232 // Replace all old uses of {node} with {replacement}, but allow new nodes
233 // created by this reduction to use {node}.
234 for (Edge edge : node->use_edges()) {
238 // Don't revisit this node if it refers to itself.
239 if (user != node) Revisit(user);
242 // Unlink {node} if it's no longer used.
243 if (node->uses().empty()) node->Kill();
245 // If there was a replacement, reduce it after popping {node}.
251 void GraphReducer::ReplaceWithValue(Node* node, Node* value, Node* effect,
253 if (effect == nullptr && node->op()->EffectInputCount() > 0) {
254 effect = NodeProperties::GetEffectInput(node);
256 if (control == nullptr && node->op()->ControlInputCount() > 0) {
257 control = NodeProperties::GetControlInput(node);
261 for (Edge edge : node->use_edges()) {
290 Node* node = stack_.top().node;
291 state_.Set(node, State::kVisited);
296 void GraphReducer::Push(Node* const node) {
297 DCHECK_NE(State::kOnStack, state_.Get(node));
298 state_.Set(node, State::kOnStack);
299 stack_.push({node, 0});
303 bool GraphReducer::Recurse(Node* node) {
304 if (state_.Get(node) > State::kRevisit) return false;
305 Push(node);
310 void GraphReducer::Revisit(Node* node) {
311 if (state_.Get(node) == State::kVisited) {
312 state_.Set(node, State::kRevisit);
313 revisit_.push(node);