ONE - On-device Neural Engine
Loading...
Searching...
No Matches
nnc::DeadCodeElimination Class Reference

This pass removes operations without uses. Importers currently only generate sConstantOps without uses. More...

#include <DeadCodeElimination.h>

Collaboration diagram for nnc::DeadCodeElimination:

Public Member Functions

PassData run (PassData data) override
 run compiler pass
 
std::string getName () override
 
- Public Member Functions inherited from nnc::Pass
virtual void cleanup ()
 clean compiler pass data
 
virtual ~Pass ()=default
 

Detailed Description

This pass removes operations without uses. Importers currently only generate sConstantOps without uses.

Definition at line 30 of file DeadCodeElimination.h.

Member Function Documentation

◆ getName()

std::string nnc::DeadCodeElimination::getName ( )
inlineoverridevirtual

Reimplemented from nnc::Pass.

Definition at line 35 of file DeadCodeElimination.h.

35{ return "RemoveDeadEnds"; };

◆ run()

nnc::PassData nnc::DeadCodeElimination::run ( PassData  data)
overridevirtual

run compiler pass

Parameters
data- data that pass is taken
Returns
data that can be passed to the next pass
Exceptions
PassExceptionobject if errors occured

Implements nnc::Pass.

Definition at line 24 of file DeadCodeElimination.cpp.

25{
26 auto graph = static_cast<Graph *>(data);
27 assert(graph);
28
29 std::vector<Operation *> sorted_nodes = getSortedNodes(graph);
30
31 auto remove_if_unused = [graph](Operation *op) {
32 if (op->getType() == Operation::Type::input || op->getType() == Operation::Type::output)
33 return;
34
35 bool has_no_uses =
36 std::all_of(op->getOutputs().cbegin(), op->getOutputs().cend(),
37 [](const Operation::Output &output) { return output.getUses().empty(); });
38
39 if (has_no_uses)
40 {
41 graph->removeNode(op);
42 }
43 };
44
45 std::for_each(sorted_nodes.rbegin(), sorted_nodes.rend(), remove_if_unused);
46
47 return graph;
48}
std::vector< Operation * > getSortedNodes(Graph *graph)
Returns nodes of the graph sorted topologically.
Definition Graph.cpp:42

References mir::getSortedNodes().

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


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