From 8a19e35ba3de3edf4e3b48e200638d1baefa17ce Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=9C=A4=ED=98=84=EC=8B=9D/On-Device=20Lab=28SR=29/Princip?= =?utf8?q?al=20Engineer/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Mon, 26 Aug 2019 17:19:46 +0900 Subject: [PATCH] [exo-tflite] Adding FixedArityNode (#6917) FixedArityNode is copied from loco since loco::FixedArityNode's destiny is doomed. Signed-off-by: Hyun Sik Yoon --- compiler/exo-tflite/src/Dialect/IR/TFLNodes.h | 39 +++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/compiler/exo-tflite/src/Dialect/IR/TFLNodes.h b/compiler/exo-tflite/src/Dialect/IR/TFLNodes.h index 5feee48..4b648ac 100644 --- a/compiler/exo-tflite/src/Dialect/IR/TFLNodes.h +++ b/compiler/exo-tflite/src/Dialect/IR/TFLNodes.h @@ -23,9 +23,48 @@ #include #include +#include + namespace locoex { +/** + * @brief Nodes with the fixed number of inputs + */ +template class FixedArityNode : public Base +{ +public: + FixedArityNode() + { + for (uint32_t n = 0; n < N; ++n) + { + _args[n] = std::unique_ptr(new loco::Use{this}); + } + } + + virtual ~FixedArityNode() = default; + +public: + unsigned arity(void) const final { return N; } + + loco::Node *arg(uint32_t n) const final { return _args.at(n)->node(); } + + void drop(void) final + { + for (uint32_t n = 0; n < N; ++n) + { + _args.at(n)->node(nullptr); + } + } + +protected: + // This API allows inherited classes to access "_args" field. + loco::Use *at(unsigned n) const { return _args.at(n).get(); } + +private: + std::array, N> _args; +}; + class TFLRelu final : public loco::FixedArityNode<1, TFLNodeImpl> { public: -- 2.7.4