aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/SerializationPasses.h6
-rw-r--r--include/SerializationPasses.td8
-rw-r--r--src/TosaSerialize.cpp52
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<OperationPass<FuncOp>> createTosaSerializePass();
+std::unique_ptr<Pass> createTosaSerializePass();
+std::unique_ptr<Pass> 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<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>();
}