Blender  V3.3
deg_builder_remove_noop.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2020 Blender Foundation. All rights reserved. */
3 
9 
10 #include "MEM_guardedalloc.h"
11 
12 #include "intern/node/deg_node.h"
14 
15 #include "intern/debug/deg_debug.h"
16 #include "intern/depsgraph.h"
18 #include "intern/depsgraph_type.h"
19 
20 namespace blender::deg {
21 
22 static inline bool is_unused_noop(OperationNode *op_node)
23 {
24  if (op_node == nullptr) {
25  return false;
26  }
27  if (op_node->flag & OperationFlag::DEPSOP_FLAG_PINNED) {
28  return false;
29  }
30  return op_node->is_noop() && op_node->outlinks.is_empty();
31 }
32 
34 {
35  int num_removed_relations = 0;
36  deque<OperationNode *> queue;
37 
39  if (is_unused_noop(node)) {
40  queue.push_back(node);
41  }
42  }
43 
44  while (!queue.empty()) {
45  OperationNode *to_remove = queue.front();
46  queue.pop_front();
47 
48  while (!to_remove->inlinks.is_empty()) {
49  Relation *rel_in = to_remove->inlinks[0];
50  Node *dependency = rel_in->from;
51 
52  /* Remove the relation. */
53  rel_in->unlink();
54  delete rel_in;
55  num_removed_relations++;
56 
57  /* Queue parent no-op node that has now become unused. */
58  OperationNode *operation = dependency->get_exit_operation();
59  if (is_unused_noop(operation)) {
60  queue.push_back(operation);
61  }
62  }
63 
64  /* TODO(Sybren): Remove the node itself. */
65  }
66 
68  (::Depsgraph *)graph, BUILD, "Removed %d relations to no-op nodes\n", num_removed_relations);
69 }
70 
71 } // namespace blender::deg
Read Guarded memory(de)allocation.
bool is_empty() const
Definition: BLI_vector.hh:706
OperationNode * node
Depsgraph * graph
#define DEG_DEBUG_PRINTF(depsgraph, type,...)
Definition: deg_debug.h:51
SyclQueue * queue
void deg_graph_remove_unused_noops(Depsgraph *graph)
static bool is_unused_noop(OperationNode *op_node)
OperationNodes operations
Definition: depsgraph.h:120
Relations inlinks
Definition: deg_node.h:173
virtual OperationNode * get_exit_operation()
Definition: deg_node.h:202
Relations outlinks
Definition: deg_node.h:174