diff options
Diffstat (limited to 'src/TosaSerialize.cpp')
-rw-r--r-- | src/TosaSerialize.cpp | 52 |
1 files changed, 14 insertions, 38 deletions
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<mlir::tosa::TransposeOp>( return nullptr; std::vector<int> perm; - auto values = perm_elems.getValues<mlir::IntegerAttr>(); - for (int32_t i = 0; i < values.size(); i++) { - perm.push_back(values[i].getInt()); + for (auto value : perm_elems.getValues<mlir::IntegerAttr>()) { + perm.push_back(value.getInt()); } TosaTransposeAttribute attribute(perm); @@ -1231,9 +1231,8 @@ TosaSerializationOperatorBuilder::build<mlir::tosa::TableOp>( return nullptr; std::vector<int> table; - auto values = table_elems.getValues<mlir::IntegerAttr>(); - for (int32_t i = 0; i < values.size(); i++) { - table.push_back(values[i].getInt()); + for (auto value : table_elems.getValues<mlir::IntegerAttr>()) { + table.push_back(value.getInt()); } TosaTableAttribute attribute(table); @@ -1718,22 +1717,10 @@ namespace tosa { namespace { -class TosaSerialize : public PassWrapper<TosaSerialize, FunctionPass> { +class TosaSerialize : public TosaSerializationPassBase<TosaSerialize> { 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<TosaSerializeJSON, FunctionPass> { +class TosaSerializeJSON + : public TosaSerializationJSONPassBase<TosaSerializeJSON> { 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<OperationPass<FuncOp>> createTosaSerializePass() { +std::unique_ptr<Pass> createTosaSerializePass() { return std::make_unique<TosaSerialize>(); } -std::unique_ptr<OperationPass<FuncOp>> createTosaSerializeJSONPass() { +std::unique_ptr<Pass> createTosaSerializeJSONPass() { return std::make_unique<TosaSerializeJSON>(); } |