Skip to content

Commit 6cfc410

Browse files
committed
[circle-mlir] Apply ONNX-MLIR upgrade
This will add changes for ONNX-MLIR and llvm-project upgrade. Most of the changes are from llvm-project changes. ONE-DCO-1.0-Signed-off-by: SaeHie Park <saehie.park@gmail.com>
1 parent c6eb5a0 commit 6cfc410

File tree

11 files changed

+44
-42
lines changed

11 files changed

+44
-42
lines changed

circle-mlir/circle-mlir/lib/dialect/include/circle-mlir/dialect/CircleDialect.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#ifndef __CIRCLE_MLIR_DIALECT_CIRCLE_DIALECT_H__
2121
#define __CIRCLE_MLIR_DIALECT_CIRCLE_DIALECT_H__
2222

23+
#include <mlir/Bytecode/BytecodeOpInterface.h> // from @llvm-project
2324
#include <mlir/Dialect/Traits.h> // from @llvm-project
2425
#include <mlir/IR/Dialect.h> // from @llvm-project
2526
#include <mlir/IR/DialectImplementation.h> // from @llvm-project
@@ -46,6 +47,7 @@ class ControlType : public Type::TypeBase<ControlType, Type, TypeStorage>
4647
{
4748
public:
4849
using Base::Base;
50+
static constexpr StringLiteral name = "cir.control";
4951
};
5052

5153
#include "mlir/CircleOpInterface.h.inc"

circle-mlir/circle-mlir/lib/dialect/mlir/CircleOps.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#ifndef CIRCLE_OPS
2121
#define CIRCLE_OPS
2222

23-
include "mlir/IR/FunctionInterfaces.td"
2423
include "mlir/IR/OpBase.td"
2524
include "mlir/Interfaces/InferTypeOpInterface.td"
2625
include "mlir/Interfaces/SideEffectInterfaces.td"

circle-mlir/circle-mlir/lib/dialect/src/NameUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ std::string GetNameFromLoc(Location loc)
4646
// in functions where the op's name is first.
4747
auto name = name_loc.getName().strref().split('@').first;
4848
// Skip if the name is for op type.
49-
if (!name.endswith(":"))
49+
if (!name.ends_with(":"))
5050
{
5151
loc_names.push_back(name);
5252
if (!name.empty())

circle-mlir/circle-mlir/lib/import/src/CircleImport.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ inline constexpr unsigned int flatbuffer_size_max = 2147483648;
3939
#include <llvm/Support/FormatVariadic.h>
4040
#include <mlir/IR/Matchers.h> // m_Constant
4141
#include <mlir/Dialect/Func/IR/FuncOps.h>
42-
#include <mlir/Dialect/Quant/QuantOps.h>
43-
#include <mlir/Dialect/Quant/QuantTypes.h>
42+
#include <mlir/Dialect/Quant/IR/QuantTypes.h>
4443

4544
#include <circle_schema/schema_generated.h>
4645

@@ -226,8 +225,8 @@ template <typename T> llvm::SmallVector<mlir::APInt> ReadAsHostEndian(llvm::Arra
226225
const char *data_ptr = reinterpret_cast<const char *>(bytes.data());
227226
for (size_t i = 0; i < elem_count; i++)
228227
{
229-
T val = llvm::support::endian::readNext<T, llvm::support::endianness::native,
230-
llvm::support::unaligned>(data_ptr);
228+
T val = llvm::support::endian::readNext<T, llvm::endianness::native, llvm::support::unaligned>(
229+
data_ptr);
231230
ret.push_back(mlir::APInt(sizeof(T) * 8, val));
232231
}
233232
return ret;
@@ -254,9 +253,8 @@ std::optional<mlir::ElementsAttr> ConvertFloatBuffer(mlir::RankedTensorType shap
254253

255254
for (int i = 0; i < elem_count; i++)
256255
{
257-
uint32_t bit_repr =
258-
llvm::support::endian::readNext<uint32_t, llvm::support::endianness::native,
259-
llvm::support::unaligned>(data);
256+
uint32_t bit_repr = llvm::support::endian::readNext<uint32_t, llvm::endianness::native,
257+
llvm::support::unaligned>(data);
260258
values.push_back(absl::bit_cast<float>(bit_repr));
261259
}
262260
auto num = shaped_type.getNumElements();

circle-mlir/circle-mlir/lib/pass/src/RewriteCirclePass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ void RewriteCirclePass::applyActivationFusion()
112112

113113
// TODO add more patterns
114114

115-
(void)applyPatternsAndFoldGreedily(func, std::move(patterns));
115+
(void)applyPatternsGreedily(func, std::move(patterns));
116116
}
117117

118118
std::unique_ptr<mlir::Pass> createRewriteCirclePass(void)

circle-mlir/circle-mlir/lib/pass/src/opt/ConvertMirrorPadPad32.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ struct ConvertMirrorPadPad32 : public OpRewritePattern<MirrorPadOp>
5757
auto intattr = DenseIntElementsAttr::get(si32stype, values);
5858
mlir::Value shape32 = rewriter.create<ConstOp>(opLoc, intattr);
5959

60-
auto pad_mutable = mirrorpad_op.getPadMutable();
60+
auto &pad_mutable = mirrorpad_op.getPadMutable();
6161
pad_mutable.assign(shape32);
6262

6363
return mlir::success();

circle-mlir/circle-mlir/lib/pass/src/opt/ConvertReshapeShape32.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ struct ConvertReshapeShape32 : public OpRewritePattern<ReshapeOp>
5959
mlir::Value shape32 =
6060
rewriter.create<ConstOp>(opLoc, DenseIntElementsAttr::get(si32stype, values));
6161

62-
auto shape_mutable = reshape_op.getShapeMutable();
62+
auto &shape_mutable = reshape_op.getShapeMutable();
6363
shape_mutable.assign(shape32);
6464

6565
return mlir::success();

circle-mlir/circle-mlir/lib/pass/src/opt/ConvertResizeNearestSize32.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ struct ConvertResizeNearestSize32 : public OpRewritePattern<ResizeNearestNeighbo
7474
mlir::Value size32 =
7575
rewriter.create<ConstOp>(opLoc, DenseIntElementsAttr::get(si32stype, values));
7676

77-
auto resize_mutable = resize_op.getSizeMutable();
77+
auto &resize_mutable = resize_op.getSizeMutable();
7878
resize_mutable.assign(size32);
7979

8080
return mlir::success();

circle-mlir/circle-mlir/lib/tools/converter-gen/converter_gen.cc

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ llvm::cl::opt<ActionType> action(
6464

6565
// Returns the associated option name for the given op definition.
6666
static inline std::string GetOperatorOptionName(const Record &def) {
67-
assert(def.getName().startswith("CIR_") && "unexpected op prefix");
68-
assert(def.getName().endswith("Op") && "unexpected op suffix");
67+
assert(def.getName().starts_with("CIR_") && "unexpected op prefix");
68+
assert(def.getName().ends_with("Op") && "unexpected op suffix");
6969

7070
auto *custom_option = dyn_cast<StringInit>(def.getValueInit("customOption"));
7171
std::ostringstream oss;
@@ -78,8 +78,8 @@ static inline std::string GetOperatorOptionName(const Record &def) {
7878

7979
// Returns the builder function name for the given op definition.
8080
static inline std::string GetOperatorBuilderName(StringRef op_name) {
81-
assert(op_name.startswith("CIR_") && "unexpected op prefix");
82-
assert(op_name.endswith("Op") && "unexpected op suffix");
81+
assert(op_name.starts_with("CIR_") && "unexpected op prefix");
82+
assert(op_name.ends_with("Op") && "unexpected op suffix");
8383

8484
// E.g., AddOp -> CreateAddOperator
8585
std::ostringstream oss;
@@ -92,7 +92,7 @@ static inline bool IsLstmOp(const StringRef op_name) {
9292
}
9393

9494
static void EmitOptionBuilders(const RecordKeeper &record_keeper,
95-
const std::vector<Record *> &defs,
95+
const std::vector<const Record *> &defs,
9696
raw_ostream *ostream) {
9797
raw_ostream &os = *ostream;
9898

@@ -117,7 +117,7 @@ static void EmitOptionBuilders(const RecordKeeper &record_keeper,
117117
mlir::tblgen::Operator op(*def);
118118
for (unsigned i = 0, e = arg_values->getNumArgs(); i != e; ++i) {
119119
auto arg = arg_values->getArg(i);
120-
DefInit *arg_def = dyn_cast<DefInit>(arg);
120+
const auto *arg_def = dyn_cast<DefInit>(arg);
121121
if (!arg_def) continue;
122122
if (arg_def->getDef()->isSubClassOf(attr_type)) {
123123
// This binds the name of the attribute in the TD file with the name
@@ -175,7 +175,7 @@ static void EmitOptionBuilders(const RecordKeeper &record_keeper,
175175
// arguments that depend on op definitions should be auto-generated and then
176176
// operator should be built by the caller because it does not require
177177
// auto-generation.
178-
static void EmitOperatorBuilders(const std::vector<Record *> &defs,
178+
static void EmitOperatorBuilders(const std::vector<const Record *> &defs,
179179
raw_ostream *ostream) {
180180
raw_ostream &os = *ostream;
181181

@@ -240,7 +240,7 @@ static inline std::string GetOperatorName(const Record &def) {
240240
//
241241
// TODO(hinsu): Consider converting this to a static constant associative
242242
// container instead of a series of if conditions, if required.
243-
static void EmitGetBuiltinOpCode(const std::vector<Record *> &defs,
243+
static void EmitGetBuiltinOpCode(const std::vector<const Record *> &defs,
244244
raw_ostream *ostream) {
245245
raw_ostream &os = *ostream;
246246

@@ -279,7 +279,7 @@ static void EmitGetBuiltinOpCode(const std::vector<Record *> &defs,
279279
// return {0, 0};
280280
// }
281281
static void EmitOperandNumbers(const RecordKeeper &record_keeper,
282-
const std::vector<Record *> &defs,
282+
const std::vector<const Record *> &defs,
283283
raw_ostream *ostream) {
284284
raw_ostream &os = *ostream;
285285
const auto attr_type = record_keeper.getClass("Attr");
@@ -324,7 +324,7 @@ static void EmitOperandNumbers(const RecordKeeper &record_keeper,
324324
// const std::vector<int32_t>& results,
325325
// const std::vector<int32_t>& intermediates,
326326
// flatbuffers::FlatBufferBuilder *fbb);
327-
static void EmitBuildOperator(const std::vector<Record *> &defs,
327+
static void EmitBuildOperator(const std::vector<const Record *> &defs,
328328
raw_ostream *ostream) {
329329
raw_ostream &os = *ostream;
330330

@@ -360,7 +360,7 @@ static void EmitBuildOperator(const std::vector<Record *> &defs,
360360
// mlir::Builder builder,
361361
// llvm::SmallVectorImpl<mlir::NamedAttribute> &attributes);
362362
static void EmitBuiltinOptionsToAttributes(const RecordKeeper &record_keeper,
363-
const std::vector<Record *> &defs,
363+
const std::vector<const Record *> &defs,
364364
raw_ostream *ostream) {
365365
raw_ostream &os = *ostream;
366366

@@ -385,7 +385,7 @@ static void EmitBuiltinOptionsToAttributes(const RecordKeeper &record_keeper,
385385
auto *arg_values = def->getValueAsDag("arguments");
386386
for (unsigned i = 0, e = arg_values->getNumArgs(); i != e; ++i) {
387387
auto arg = arg_values->getArg(i);
388-
DefInit *arg_def = dyn_cast<DefInit>(arg);
388+
const auto *arg_def = dyn_cast<DefInit>(arg);
389389
if (!arg_def) continue;
390390
if (arg_def->getDef()->isSubClassOf(attr_type)) {
391391
StringRef arg_name = arg_values->getArgNameStr(i);
@@ -411,11 +411,11 @@ static void EmitBuiltinOptionsToAttributes(const RecordKeeper &record_keeper,
411411
// The function below has a non-constant reference as that is required by LLVM's
412412
// TableGenMain.
413413
// NOLINTNEXTLINE
414-
static bool OperatorWritersMain(raw_ostream &os, RecordKeeper &records) {
414+
static bool OperatorWritersMain(raw_ostream &os, const RecordKeeper &records) {
415415
emitSourceFileHeader("MLIR Circle FlatBuffer Builders", os);
416416

417417
// Retrieve all the definitions derived from CIR_Op and sort by record name.
418-
std::vector<Record *> defs = records.getAllDerivedDefinitions("CIR_Op");
418+
std::vector<const Record *> defs = records.getAllDerivedDefinitions("CIR_Op");
419419
llvm::sort(defs, LessRecord());
420420

421421
for (const auto *def : defs) {
@@ -424,10 +424,10 @@ static bool OperatorWritersMain(raw_ostream &os, RecordKeeper &records) {
424424
// The generated Circle op C++ class should be circle::<OpName>Op.
425425
// The generated operator's options should be circle::<OpName>Options.
426426
// The option builder should be Create<OpName>Options.
427-
if (!def->getName().startswith("CIR_"))
427+
if (!def->getName().starts_with("CIR_"))
428428
PrintFatalError(def->getLoc(),
429429
"unexpected op name format: 'CIR_' prefix missing");
430-
if (!def->getName().endswith("Op"))
430+
if (!def->getName().ends_with("Op"))
431431
PrintFatalError(def->getLoc(),
432432
"unexpected op name format: 'Op' suffix missing");
433433
}
@@ -448,7 +448,7 @@ static bool OperatorWritersMain(raw_ostream &os, RecordKeeper &records) {
448448
}
449449

450450
static void GenOperandResultVerifier(raw_ostream &os,
451-
llvm::ArrayRef<llvm::Init *> values,
451+
llvm::ArrayRef<const llvm::Init *> values,
452452
StringRef valueKind) {
453453
mlir::tblgen::FmtContext fctx;
454454

@@ -496,11 +496,12 @@ static void GenOperandResultVerifier(raw_ostream &os,
496496
}
497497

498498
// NOLINTNEXTLINE
499-
static bool RuntimeVerifierWriterMain(raw_ostream &os, RecordKeeper &records) {
499+
static bool RuntimeVerifierWriterMain(raw_ostream &os,
500+
const RecordKeeper &records) {
500501
emitSourceFileHeader("MLIR Circle Runtime Verifiers", os);
501502

502503
// Retrieve all the definitions derived from CIR_Op and sort by record name.
503-
std::vector<Record *> defs = records.getAllDerivedDefinitions("Op");
504+
std::vector<const Record *> defs = records.getAllDerivedDefinitions("Op");
504505
llvm::sort(defs, LessRecord());
505506

506507
// Iterate through all the ops defined.

circle-mlir/circle-mlir/tools/onnx2circle/src/onnx2circle.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ int loadONNX(const std::string &onnx_path, mlir::MLIRContext &context,
7373
{
7474
llvm::StringRef inputFilename(onnx_path);
7575
std::string errorMessage;
76-
if (inputFilename.endswith(".mlir"))
76+
if (inputFilename.ends_with(".mlir"))
7777
{
7878
auto input = mlir::openInputFile(inputFilename, &errorMessage);
7979
if (!input)
@@ -95,7 +95,7 @@ int loadONNX(const std::string &onnx_path, mlir::MLIRContext &context,
9595
return -1;
9696
}
9797
}
98-
else if (inputFilename.endswith(".onnx"))
98+
else if (inputFilename.ends_with(".onnx"))
9999
{
100100
onnx_mlir::ImportOptions options;
101101
options.useOnnxModelTypes = onnx_mlir::useOnnxModelTypes;

0 commit comments

Comments
 (0)