[locop] Extract NodeSummary (#6076)
author박종현/On-Device Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Thu, 1 Aug 2019 05:10:07 +0000 (14:10 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Thu, 1 Aug 2019 05:10:07 +0000 (14:10 +0900)
This commit introduces a dedicated header/source file for NodeSummary class.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
compiler/locop/include/locop/FormattedGraph.h
compiler/locop/include/locop/NodeSummary.h [new file with mode: 0644]
compiler/locop/src/FormattedGraph.cpp
compiler/locop/src/NodeSummary.cpp [new file with mode: 0644]

index 9ac79d7..c0f5b5e 100644 (file)
@@ -18,6 +18,7 @@
 #define __LOCOP_FORMATTED_GRAPH_H__
 
 #include "locop/SymbolTable.h"
+#include "locop/NodeSummary.h"
 
 #include <loco.h>
 
 namespace locop
 {
 
-using OpName = std::string;
-using ArgName = std::string;
-using ArgValue = std::string;
-using ArgElem = std::pair<ArgName, ArgValue>;
-
-class ArgDesc
-{
-public:
-  ArgDesc() = default;
-
-public:
-  /// @brief The number of presented arguments
-  uint32_t count(void) const { return _args.size(); }
-
-  const ArgElem &at(uint32_t n) const { return _args.at(n); }
-  void append(const ArgName &name, const ArgValue &value) { _args.emplace_back(name, value); }
-
-private:
-  std::vector<ArgElem> _args;
-};
-
-struct NodeDesc
-{
-public:
-  enum class State
-  {
-    // All the node descriptions are "Invalid" at the beginning.
-    //
-    // Any valid node description SHOULD NOT be at this state.
-    Invalid,
-    // This state means that the producer is **NOT** confident about the information that
-    // it generates.
-    //
-    // There may be some missing information.
-    PartiallyKnown,
-    // This state means that the producer is confident about the information that it
-    // generates.
-    Complete,
-  };
-
-public:
-  NodeDesc() = default;
-  NodeDesc(const OpName &opname) { this->opname(opname); }
-
-public:
-  const OpName &opname(void) const;
-  void opname(const OpName &value);
-
-  const ArgDesc &args(void) const { return _args; }
-  ArgDesc &args(void) { return _args; }
-
-  const State &state(void) const { return _state; }
-  void state(const State &s) { _state = s; }
-
-private:
-  std::unique_ptr<OpName> _name = nullptr;
-  ArgDesc _args;
-  State _state = State::Invalid;
-};
-
-using NodeSummary = NodeDesc;
-
 /**
  * @brief Build a summary from loco Node
  */
diff --git a/compiler/locop/include/locop/NodeSummary.h b/compiler/locop/include/locop/NodeSummary.h
new file mode 100644 (file)
index 0000000..e10758a
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __LOCO_NODE_SUMMARY_H__
+#define __LOCO_NODE_SUMMARY_H__
+
+#include <memory>
+#include <string>
+#include <utility>
+#include <vector>
+
+namespace locop
+{
+
+using OpName = std::string;
+using ArgName = std::string;
+using ArgValue = std::string;
+using ArgElem = std::pair<ArgName, ArgValue>;
+
+class ArgDesc
+{
+public:
+  ArgDesc() = default;
+
+public:
+  /// @brief The number of presented arguments
+  uint32_t count(void) const { return _args.size(); }
+
+  const ArgElem &at(uint32_t n) const { return _args.at(n); }
+  void append(const ArgName &name, const ArgValue &value) { _args.emplace_back(name, value); }
+
+private:
+  std::vector<ArgElem> _args;
+};
+
+struct NodeDesc
+{
+public:
+  enum class State
+  {
+    // All the node descriptions are "Invalid" at the beginning.
+    //
+    // Any valid node description SHOULD NOT be at this state.
+    Invalid,
+    // This state means that the producer is **NOT** confident about the information that
+    // it generates.
+    //
+    // There may be some missing information.
+    PartiallyKnown,
+    // This state means that the producer is confident about the information that it
+    // generates.
+    Complete,
+  };
+
+public:
+  NodeDesc() = default;
+  NodeDesc(const OpName &opname) { this->opname(opname); }
+
+public:
+  const OpName &opname(void) const;
+  void opname(const OpName &value);
+
+  const ArgDesc &args(void) const { return _args; }
+  ArgDesc &args(void) { return _args; }
+
+  const State &state(void) const { return _state; }
+  void state(const State &s) { _state = s; }
+
+private:
+  std::unique_ptr<OpName> _name = nullptr;
+  ArgDesc _args;
+  State _state = State::Invalid;
+};
+
+using NodeSummary = NodeDesc;
+
+} // namespace locop
+
+#endif // __LOCO_NODE_SUMMARY_H__
index 8645d87..7410c57 100644 (file)
@@ -171,20 +171,6 @@ public:
 
 } // namespace
 
-namespace locop
-{
-
-const std::string &NodeDesc::opname(void) const
-{
-  // _name SHOULD BE set before use
-  assert(_name != nullptr);
-  return *_name;
-}
-
-void NodeDesc::opname(const std::string &v) { _name = stdex::make_unique<std::string>(v); }
-
-} // namespace locop
-
 // TODO Remove this workaround
 namespace locop
 {
diff --git a/compiler/locop/src/NodeSummary.cpp b/compiler/locop/src/NodeSummary.cpp
new file mode 100644 (file)
index 0000000..34afc80
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "locop/NodeSummary.h"
+
+#include <stdex/Memory.h>
+
+#include <cassert>
+
+namespace locop
+{
+
+const std::string &NodeDesc::opname(void) const
+{
+  // _name SHOULD BE set before use
+  assert(_name != nullptr);
+  return *_name;
+}
+
+void NodeDesc::opname(const std::string &v) { _name = stdex::make_unique<std::string>(v); }
+
+} // namespace loco