From ef2c301b14dad329ab02810b44d2f157dbc4d944 Mon Sep 17 00:00:00 2001 From: Eric Kunze Date: Tue, 15 Feb 2022 10:00:53 -0800 Subject: Align serialize passes with current LLVM Remove FunctionPass Simplify getValues code Change-Id: I054466ccb480148b82d81d900e1e9ffb4560e8af Signed-off-by: Eric Kunze --- include/SerializationPasses.h | 6 +++-- include/SerializationPasses.td | 8 +++++-- src/TosaSerialize.cpp | 52 ++++++++++++------------------------------ 3 files changed, 24 insertions(+), 42 deletions(-) diff --git a/include/SerializationPasses.h b/include/SerializationPasses.h index 0991f87..2c04ca1 100644 --- a/include/SerializationPasses.h +++ b/include/SerializationPasses.h @@ -23,10 +23,12 @@ namespace mlir { namespace tosa { -std::unique_ptr> createTosaSerializePass(); +std::unique_ptr createTosaSerializePass(); +std::unique_ptr createTosaSerializeJSONPass(); #define GEN_PASS_REGISTRATION -#include "SerializationPasses.h.inc" +#define GEN_PASS_CLASSES +#include "include/SerializationPasses.h.inc" } // namespace tosa } // namespace mlir diff --git a/include/SerializationPasses.td b/include/SerializationPasses.td index 6df996e..ec272e4 100644 --- a/include/SerializationPasses.td +++ b/include/SerializationPasses.td @@ -1,7 +1,7 @@ // Copyright (c) 2020-2021, ARM Limited. // -// Licensed under the Apache License, Version 2.0 with LLVM Exceptions -// (the "License"); you may not use this file except in compliance with +// Licensed under the Apache License, Version 2.0 with LLVM Exceptions +// (the "License"); you may not use this file except in compliance with // the License. You may obtain a copy of the License at // // https://llvm.org/LICENSE.txt @@ -19,3 +19,7 @@ def TosaSerializationPass : Pass<"tosa-serialize", "FuncOp"> { let constructor = "createTosaSerializePass()"; } +def TosaSerializationJSONPass : Pass<"tosa-serialize-json", "FuncOp"> { + let summary = "Generate TOSA flatbuffer JSON form"; + let constructor = "createTosaSerializeJSONPass()"; +} diff --git a/src/TosaSerialize.cpp b/src/TosaSerialize.cpp index 8435fe9..4e75cf8 100644 --- a/src/TosaSerialize.cpp +++ b/src/TosaSerialize.cpp @@ -15,6 +15,7 @@ // TOSA flatbuffer generation +#include "include/SerializationPasses.h" #include "mlir/Dialect/Quant/QuantTypes.h" // from @llvm-project #include "mlir/Dialect/StandardOps/IR/Ops.h" // from @llvm-project #include "mlir/Dialect/Tosa/IR/TosaOps.h" // from @llvm-project @@ -992,9 +993,8 @@ TosaSerializationOperatorBuilder::build( return nullptr; std::vector perm; - auto values = perm_elems.getValues(); - for (int32_t i = 0; i < values.size(); i++) { - perm.push_back(values[i].getInt()); + for (auto value : perm_elems.getValues()) { + perm.push_back(value.getInt()); } TosaTransposeAttribute attribute(perm); @@ -1231,9 +1231,8 @@ TosaSerializationOperatorBuilder::build( return nullptr; std::vector table; - auto values = table_elems.getValues(); - for (int32_t i = 0; i < values.size(); i++) { - table.push_back(values[i].getInt()); + for (auto value : table_elems.getValues()) { + table.push_back(value.getInt()); } TosaTableAttribute attribute(table); @@ -1718,22 +1717,10 @@ namespace tosa { namespace { -class TosaSerialize : public PassWrapper { +class TosaSerialize : public TosaSerializationPassBase { public: - TosaSerialize() = default; - - StringRef getArgument() const final { - // This is the argument used to refer to the pass in - // the textual format (on the commandline for example). - return "tosa-serialize"; - } - StringRef getDescription() const final { - // This is a brief description of the pass. - return "Run the TOSA serialization (flatbuffer generation) pass"; - } - - void runOnFunction() override { - auto function = getFunction(); + void runOnOperation() final { + auto function = getOperation(); if (dumpTosaFlatbuffer(function).failed()) { llvm::errs() << "Failed to generate TOSA flatbuffer...\n"; @@ -1742,22 +1729,11 @@ public: } }; -class TosaSerializeJSON : public PassWrapper { +class TosaSerializeJSON + : public TosaSerializationJSONPassBase { public: - TosaSerializeJSON() = default; - - StringRef getArgument() const final { - // This is the argument used to refer to the pass in - // the textual format (on the commandline for example). - return "tosa-serialize-json"; - } - StringRef getDescription() const final { - // This is a brief description of the pass. - return "Run the TOSA serialization (JSON generation) pass"; - } - - void runOnFunction() override { - auto function = getFunction(); + void runOnOperation() final { + auto function = getOperation(); if (dumpTosaJSON(function).failed()) { llvm::errs() << "Failed to generate TOSA JSON...\n"; @@ -1769,11 +1745,11 @@ public: } // anonymous namespace // Creates an instance of the TOSA flatbuffer generation pass -std::unique_ptr> createTosaSerializePass() { +std::unique_ptr createTosaSerializePass() { return std::make_unique(); } -std::unique_ptr> createTosaSerializeJSONPass() { +std::unique_ptr createTosaSerializeJSONPass() { return std::make_unique(); } -- cgit v1.2.1