[exo-tflite] Use loco type inference framework (#5807)
author박종현/On-Device Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Wed, 24 Jul 2019 07:09:00 +0000 (16:09 +0900)
committer오형석/On-Device Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Wed, 24 Jul 2019 07:09:00 +0000 (16:09 +0900)
This commit revises the implementation of exo-tflite type inferene framework
by using loco type inference framework.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
compiler/exo-tflite/src/TypeInference.cpp

index e542f3d..31477f1 100644 (file)
 
 #include <loco/IR/CanonicalNode.h>
 #include <loco/IR/CanonicalNodeVisitor.h>
+#include <loco/Service/TypeInference.h>
 
 #include <stdex/Memory.h>
 
 #include <type_traits>
 
+// TODO Remove unused code
 namespace
 {
 
@@ -194,24 +196,12 @@ private:
 
 void TypeInference::run(loco::Graph *g)
 {
-  TypeContext ctx;
-  TypeGetter type_getter{ctx};
-
-  for (auto node : loco::postorder_traversal(loco::output_nodes(g)))
-  {
-    if (auto canonical_node = dynamic_cast<loco::CanonicalNode *>(node))
-    {
-      auto tflite_type = canonical_node->accept(&type_getter);
-      node->annot(stdex::make_unique<TypeAnnotation>(tflite_type));
-
-      // Update type context to allow type getter to retrieve the type of node's arguments
-      ctx._node_to_type[node] = tflite_type;
-    }
-  }
+  loco::CanonicalTypeInferenceRule rule;
+  loco::apply(&rule).to(g);
 }
 
 tflite::TensorType TypeInference::get(loco::Node *node)
 {
-  assert(node->annot<TypeAnnotation>() != nullptr);
-  return node->annot<TypeAnnotation>()->type();
+  assert(loco::dtype_known(node));
+  return translateLocoTypeToTFLite(loco::dtype_get(node));
 }