diff --git a/circle-mlir/circle-mlir/lib/dialect/mlir/CircleOps.td b/circle-mlir/circle-mlir/lib/dialect/mlir/CircleOps.td index 5728e0cba53..1c0989feec7 100644 --- a/circle-mlir/circle-mlir/lib/dialect/mlir/CircleOps.td +++ b/circle-mlir/circle-mlir/lib/dialect/mlir/CircleOps.td @@ -334,6 +334,32 @@ def CIR_ConstOp : Op, + DeclareOpInterfaceMethods + ]> { + let summary = "Custom op"; + + let description = [{ + A generic op for any Circle custom operation. + + input: A list of inputs in the original op. + custom_code: A string used to identify which exactly this op is, which + corresponds to operator_codes.custom_code in the flatbuffer. + custom_option: a holder to save the op attributes in bytes fashion. + output: A list of outputs in the original op. + }]; + + let arguments = (ins + Variadic>:$input, + StrAttr:$custom_code, + CIR_ConstBytesAttr:$custom_option + ); + let results = (outs Variadic:$output); + + let hasVerifier = 1; +} + def CIR_NoValueOp : Op { let summary = "constant representing no value."; diff --git a/circle-mlir/circle-mlir/lib/dialect/src/CircleDialect.cpp b/circle-mlir/circle-mlir/lib/dialect/src/CircleDialect.cpp index 6a5f08445c8..a43b626e05f 100644 --- a/circle-mlir/circle-mlir/lib/dialect/src/CircleDialect.cpp +++ b/circle-mlir/circle-mlir/lib/dialect/src/CircleDialect.cpp @@ -443,6 +443,7 @@ void ConstBytesAttr::print(mlir::AsmPrinter &printer) const } // namespace mlir // TODO add AddOp +#include "ops/CustomOp.h" #include "mlir/CircleOpsDialect.cc.inc" #include "mlir/CircleOpsEnums.cc.inc" diff --git a/circle-mlir/circle-mlir/lib/dialect/src/ops/CustomOp.h b/circle-mlir/circle-mlir/lib/dialect/src/ops/CustomOp.h new file mode 100644 index 00000000000..1cc803e4ef2 --- /dev/null +++ b/circle-mlir/circle-mlir/lib/dialect/src/ops/CustomOp.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2025 Samsung Electronics Co., Ltd. All Rights Reserved + * Copyright 2019 The TensorFlow Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// from tensorflow/compiler/mlir/lite/ir/tfl_ops.cc + +#ifndef __CIRCLE_MLIR_DIALECT_OPS_CUSTOM_OP_H__ +#define __CIRCLE_MLIR_DIALECT_OPS_CUSTOM_OP_H__ + +#include "circle-mlir/dialect/CircleDialect.h" + +namespace mlir +{ +namespace Circle +{ + +//===----------------------------------------------------------------------===// +// CustomOp +//===----------------------------------------------------------------------===// + +// TODO(b/241745316): Confirm that this is always valid +mlir::LogicalResult CustomOp::verify() +{ + // Currently, this is always valid as it is a wrapper around a StringRef of 0 + // or more characters. + return success(); +} + +} // namespace Circle +} // namespace mlir + +#endif // __CIRCLE_MLIR_DIALECT_OPS_CUSTOM_OP_H__