diff --git a/circle-mlir/circle-mlir/lib/dialect/mlir/CircleOps.td b/circle-mlir/circle-mlir/lib/dialect/mlir/CircleOps.td index 99f30bc7cf0..eaa0abfebd0 100644 --- a/circle-mlir/circle-mlir/lib/dialect/mlir/CircleOps.td +++ b/circle-mlir/circle-mlir/lib/dialect/mlir/CircleOps.td @@ -1619,6 +1619,32 @@ def CIR_PReluOp : CIR_Op<"prelu", [ */ } +def CIR_RangeOp : CIR_Op<"range", [ + Pure, + CIR_OperandHasRank<0, 0>, + CIR_OperandHasRank<1, 0>, + CIR_OperandHasRank<2, 0>, + PredOpTrait<"operands and output must have same element type", + And<[TCresVTEtIsSameAsOp<0, 0>, TCresVTEtIsSameAsOp<0, 1>, + TCresVTEtIsSameAsOp<0, 2>]>>]> { + let summary = "Range operator"; + + let description = [{ + Returns a 1D tensor defined by a sequence from `start` to `limit` with + a given `delta`. + }]; + + let arguments = (ins + CIR_TensorOf<[I32, F32, I64]>:$start, + CIR_TensorOf<[I32, F32, I64]>:$limit, + CIR_TensorOf<[I32, F32, I64]>:$delta + ); + + let results = (outs CIR_TensorOf<[I32, F32, I64]>:$result); + + let hasOptions = 1; +} + def CIR_ReduceMaxOp: CIR_Op<"reduce_max", [ PredOpTrait<"input and output must have same element type", CIR_TCresVTEtIsSameAsOp<0, 0>>, diff --git a/circle-mlir/circle-mlir/lib/pass/src/ConvertONNXToCirclePass.cpp b/circle-mlir/circle-mlir/lib/pass/src/ConvertONNXToCirclePass.cpp index 7fa691f0d11..90a3a505e85 100644 --- a/circle-mlir/circle-mlir/lib/pass/src/ConvertONNXToCirclePass.cpp +++ b/circle-mlir/circle-mlir/lib/pass/src/ConvertONNXToCirclePass.cpp @@ -64,6 +64,7 @@ #include "ops/PowOp.h" #include "ops/PReluOp.h" #include "ops/QuantizeLinearOp.h" +#include "ops/RangeOp.h" #include "ops/ReciprocalOp.h" #include "ops/ReduceMaxOp.h" #include "ops/ReduceMeanOp.h" @@ -247,6 +248,7 @@ void ConvertONNXToCirclePass::runOnOperation() patterns.insert(typeConverter, context); patterns.insert(typeConverter, context); patterns.insert(typeConverter, context); + patterns.insert(typeConverter, context); patterns.insert(typeConverter, context); patterns.insert(typeConverter, context); patterns.insert(typeConverter, context); diff --git a/circle-mlir/circle-mlir/lib/pass/src/ops/RangeOp.h b/circle-mlir/circle-mlir/lib/pass/src/ops/RangeOp.h new file mode 100644 index 00000000000..dae5f55c697 --- /dev/null +++ b/circle-mlir/circle-mlir/lib/pass/src/ops/RangeOp.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2026 Samsung Electronics Co., Ltd. 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. + */ + +#ifndef __CIRCLE_MLIR_PASS_OPS_RANGE_OP_H__ +#define __CIRCLE_MLIR_PASS_OPS_RANGE_OP_H__ + +#include + +#include "ConvertHelper.h" + +#include + +#include + +namespace mlir +{ +namespace Circle +{ + +class ConvRange : public mlir::OpConversionPattern +{ +public: + using mlir::OpConversionPattern::OpConversionPattern; + using OpAdaptor = typename mlir::ONNXRangeOp::Adaptor; + + mlir::LogicalResult matchAndRewrite(mlir::ONNXRangeOp op, OpAdaptor adaptor, + mlir::ConversionPatternRewriter &rewriter) const override + { + mlir::Value start = adaptor.getStart(); + mlir::Value limit = adaptor.getLimit(); + mlir::Value delta = adaptor.getDelta(); + + rewriter.replaceOpWithNewOp(op, op.getType(), start, limit, delta); + + return mlir::success(); + } +}; + +} // namespace Circle +} // namespace mlir + +#endif // __CIRCLE_MLIR_PASS_OPS_RANGE_OP_H__