ONE - On-device Neural Engine
Loading...
Searching...
No Matches
luci::CommonSubExpressionEliminationPass Class Reference

Pass to perform CSE (Common Sub-expression Elimination) More...

#include <CommonSubExpressionEliminationPass.h>

Collaboration diagram for luci::CommonSubExpressionEliminationPass:

Public Member Functions

virtual const char * name (void) const
 
bool run (loco::Graph *graph)
 Run the pass.
 
- Public Member Functions inherited from logo::Pass
virtual ~Pass ()=default
 

Detailed Description

Pass to perform CSE (Common Sub-expression Elimination)

Definition at line 28 of file CommonSubExpressionEliminationPass.h.

Member Function Documentation

◆ name()

virtual const char * luci::CommonSubExpressionEliminationPass::name ( void  ) const
inlinevirtual

Reimplemented from logo::Pass.

Definition at line 31 of file CommonSubExpressionEliminationPass.h.

31{ return "luci::CommonSubExpressionEliminationPass"; }

◆ run()

bool luci::CommonSubExpressionEliminationPass::run ( loco::Graph graph)
virtual

Run the pass.

Returns
false if there was nothing changed

Implements logo::Pass.

Definition at line 52 of file CommonSubExpressionEliminationPass.cpp.

53{
54 // Build cache
55 ExpressionCache cache;
56
57 bool changed = false;
58 for (auto node : loco::active_nodes(loco::output_nodes(g)))
59 {
60 auto cnode = loco::must_cast<luci::CircleNode *>(node);
61
62 // Skip virtual Ops
63 // Why? virtual Ops do not perform actual computations
64 // NOTE Fix this if the assumption is not true
65 if (virtual_op(cnode->opcode()))
66 continue;
67
68 // Build expression
69 auto expr = Expression::build(cnode);
70
71 // Invalid (NYI) expression
72 if (expr.op == nullptr)
73 continue;
74
75 // Cache hit
76 if (auto saved_node = cache.get(expr))
77 {
78 loco::replace(cnode).with(saved_node);
79 changed = true;
80 }
81 // Cache miss
82 else
83 {
84 cache.put(expr, cnode);
85 }
86 }
87
88 return changed;
89}
void with(Node *into) const
Definition Node.cpp:66
void put(const Key &k, const Value v)
Value get(const Key &k) const
std::set< loco::Node * > active_nodes(const std::vector< loco::Node * > &roots)
Enumerate all the nodes required to compute "roots".
std::vector< Node * > output_nodes(Graph *)
Definition Graph.cpp:101
Subst< SubstQualifier::Default > replace(Node *node)
Definition Node.cpp:82
static Expression build(luci::CircleNode *node)

References loco::active_nodes(), luci::pass::Expression::build(), luci::pass::ExpressionCache::get(), loco::output_nodes(), luci::pass::ExpressionCache::put(), loco::replace(), and loco::Subst< SubstQualifier::Default >::with().

Referenced by package.infer.session::inference().


The documentation for this class was generated from the following files: