ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 36 of file UnusedOperandEliminationPass.h.

Member Function Documentation

◆ id()

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

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

Definition at line 42 of file UnusedOperandEliminationPass.h.

42{ return "UnusedOperandEliminationPass"; }

◆ Pass()

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

Definition at line 35 of file Pass.h.

◆ run()

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

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

Definition at line 32 of file UnusedOperandEliminationPass.cc.

33{
34 util::Set<ir::OperandIndex> used;
35
36 _graph.operations().iterate([&](const ir::OperationIndex &, const ir::IOperation &node) {
37 for (auto &&ind : (node.getInputs() + node.getOutputs()) | ir::Remove::UNDEFINED)
38 {
39 used.add(ind);
40 }
41 });
42
43 // Graph's inputs/outputs are always considered as used
44 for (auto &&ind : (_graph.getInputs() + _graph.getOutputs()) | ir::Remove::UNDEFINED)
45 {
46 used.add(ind);
47 }
48
49 _graph.operands().iterate([&](const ir::OperandIndex &ind, const ir::Operand &) {
50 if (!used.contains(ind))
51 {
52 VERBOSE() << "Remove unused operand " << ind << std::endl;
53 _graph.operands().remove(ind);
54 }
55 });
56}
const Operands & operands() const override
Definition Graph.h:110
const Operations & operations() const override
Definition Graph.h:112
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:30
::onert::util::Index< uint32_t, OperandIndexTag > OperandIndex
Definition Index.h:33

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.


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