Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions circle-mlir/circle-mlir/lib/dialect/mlir/CircleOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -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>>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -247,6 +248,7 @@ void ConvertONNXToCirclePass::runOnOperation()
patterns.insert<ConvPow>(typeConverter, context);
patterns.insert<ConvPRelu>(typeConverter, context);
patterns.insert<ConvQuantizeLinear>(typeConverter, context);
patterns.insert<ConvRange>(typeConverter, context);
patterns.insert<ConvReciprocal>(typeConverter, context);
patterns.insert<ConvReduceMax>(typeConverter, context);
patterns.insert<ConvReduceMaxV13>(typeConverter, context);
Expand Down
55 changes: 55 additions & 0 deletions circle-mlir/circle-mlir/lib/pass/src/ops/RangeOp.h
Original file line number Diff line number Diff line change
@@ -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 <circle-mlir/dialect/CircleDialect.h>

#include "ConvertHelper.h"

#include <mlir/Transforms/DialectConversion.h>

#include <src/Dialect/ONNX/ONNXOps.hpp>

namespace mlir
{
namespace Circle
{

class ConvRange : public mlir::OpConversionPattern<mlir::ONNXRangeOp>
{
public:
using mlir::OpConversionPattern<mlir::ONNXRangeOp>::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<RangeOp>(op, op.getType(), start, limit, delta);

return mlir::success();
}
};

} // namespace Circle
} // namespace mlir

#endif // __CIRCLE_MLIR_PASS_OPS_RANGE_OP_H__