Imported Upstream version 1.8.0
[platform/core/ml/nnfw.git] / runtime / onert / core / src / ir / LoweredGraph.cc
index 6e93a23..8aedfbd 100644 (file)
@@ -23,6 +23,7 @@
 #include "pass/ConstantLoweringPass.h"
 #include "pass/PermutationOperationPass.h"
 #include "pass/PermutationInsertionPass.h"
+#include "pass/PermutationEliminationPass.h"
 #include "ir/GraphIterator.h"
 #include "verifier/Verifier.h"
 #include "backend/Backend.h"
@@ -122,9 +123,9 @@ LoweredGraph::LoweredGraph(const Graph &graph, const compiler::CompilerOptions &
 
     pass::PermutationInsertionPass pi_pass(*this);
     pi_pass.run();
-    // Implemented code no longer works.
-    // pass::PermutationEliminationPass pe_pass(*this);
-    // pe_pass.run();
+
+    pass::PermutationEliminationPass pe_pass(*this);
+    pe_pass.run();
 
     _op_seqs.dump("merged and sorted operations with permutation", _graph.operations());
   }
@@ -414,7 +415,8 @@ void LoweredGraph::dumpLowerInfo()
 
       const auto lower_info = getLowerInfo(index);
       const auto &shape = object.shape();
-      std::string def_ops = operation_index_to_string(object.getDef());
+      std::string def_ops =
+          object.getDef().valid() ? std::to_string(object.getDef().value()) : "N/A";
       std::string use_ops = operation_index_to_string(object.getUses());
       std::string def_layouts = factors_to_string(lower_info->def_factors());
       std::string use_layouts = factors_to_string(lower_info->use_factors());
@@ -474,7 +476,8 @@ bool LoweredGraph::mergeable(const OpSequenceIndex &op_seq_index, const Operatio
     for (const auto &input : op_seq.getInputs() | Remove::DUPLICATED | ir::Remove::UNDEFINED)
     {
       const auto &input_obj = _graph.operands().at(input);
-      for (const auto &def : input_obj.getDef())
+      auto def = input_obj.getDef();
+      if (def.valid())
       {
         branched_set.insert(def);
         if (branched_set.size() > 1)
@@ -488,6 +491,12 @@ bool LoweredGraph::mergeable(const OpSequenceIndex &op_seq_index, const Operatio
     // Check for branching down
     for (const auto &output : node.getOutputs() | Remove::DUPLICATED)
     {
+      // TODO Fix this workaround for the case of model outputs that are used by another operation
+      //      This is needed since the branching is decided by operation, but for model outputs,
+      //      there is controlflow backen(use backend) but no actual use operation exists
+      if (_graph.getOutputs().contains(output))
+        return false;
+
       const auto &output_obj = _graph.operands().at(output);
       for (const auto &use : output_obj.getUses())
       {