ONE - On-device Neural Engine
Loading...
Searching...
No Matches
onert::compiler::pass::UnusedOperandEliminationPass Class Reference

A pass to eliminate unused operands from the graph. More...

#include <UnusedOperandEliminationPass.h>

Collaboration diagram for onert::compiler::pass::UnusedOperandEliminationPass:

Public Member Functions

std::string id () override
 
void run () final
 
 Pass (ir::Graph &graph)
 
- Public Member Functions inherited from onert::compiler::pass::Pass
 Pass (ir::Graph &graph)
 
virtual ~Pass ()=default
 
- Public Member Functions inherited from onert::compiler::pass::IPass
virtual ~IPass ()=default
 

Additional Inherited Members

- Protected Attributes inherited from onert::compiler::pass::Pass
ir::Graph_graph
 

Detailed Description

A pass to eliminate unused operands from the graph.

Remove operands that are not used by any operations, except Graph inputs/outputs.

Definition at line 40 of file UnusedOperandEliminationPass.h.

Member Function Documentation

◆ id()

std::string onert::compiler::pass::UnusedOperandEliminationPass::id ( )
inlineoverridevirtual

Implements onert::compiler::pass::Pass.

Definition at line 46 of file UnusedOperandEliminationPass.h.

46{ return "UnusedOperandEliminationPass"; }

◆ Pass()

onert::compiler::pass::Pass::Pass ( ir::Graph graph)
inline

Definition at line 42 of file Pass.h.

◆ run()

void onert::compiler::pass::UnusedOperandEliminationPass::run ( )
finalvirtual

Implements onert::compiler::pass::Pass.

Definition at line 36 of file UnusedOperandEliminationPass.cc.

37{
38 util::Set<ir::OperandIndex> used;
39
40 _graph.operations().iterate([&](const ir::OperationIndex &, const ir::IOperation &node) {
41 for (auto &&ind : (node.getInputs() + node.getOutputs()) | ir::Remove::UNDEFINED)
42 {
43 used.add(ind);
44 }
45 });
46
47 // Graph's inputs/outputs are always considered as used
48 for (auto &&ind : (_graph.getInputs() + _graph.getOutputs()) | ir::Remove::UNDEFINED)
49 {
50 used.add(ind);
51 }
52
53 _graph.operands().iterate([&](const ir::OperandIndex &ind, const ir::Operand &) {
54 if (!used.contains(ind))
55 {
56 VERBOSE() << "Remove unused operand " << ind << std::endl;
57 _graph.operands().remove(ind);
58 }
59 });
60}
const Operands & operands() const override
Definition Graph.h:112
const Operations & operations() const override
Definition Graph.h:114
void iterate(const std::function< void(const Index &, const Object &)> &fn) const
Iterate over the container with given function.
::onert::util::Index< uint32_t, OperationIndexTag > OperationIndex
Definition Index.h:32
::onert::util::Index< uint32_t, OperandIndexTag > OperandIndex
Definition Index.h:35

References onert::compiler::pass::Pass::_graph, onert::util::Set< Element >::add(), onert::util::Set< Element >::contains(), onert::ir::IOperation::getInputs(), onert::ir::Graph::getInputs(), onert::ir::IOperation::getOutputs(), onert::ir::Graph::getOutputs(), onert::util::ObjectManager< Index, Object >::iterate(), onert::ir::Graph::operands(), onert::ir::Graph::operations(), onert::util::ObjectManager< Index, Object >::remove(), onert::ir::UNDEFINED, and VERBOSE.

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


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