From c75cbf4ac7340938c9fe64d4a47d7fb3003dd112 Mon Sep 17 00:00:00 2001 From: Rahul Joshi Date: Wed, 14 Apr 2021 12:05:33 -0700 Subject: [PATCH] [MLIR][NFC] Rename ReduceOp operands() => inputs(). - Rename to avoid confusion as operands generally includes all operands of an operation PiperOrigin-RevId: 368479524 --- include/mlir-hlo/Dialect/mhlo/IR/hlo_ops.td | 4 ++-- include/mlir-hlo/Dialect/mhlo/IR/lhlo_ops.td | 2 +- lib/Dialect/mhlo/IR/hlo_ops.cc | 12 ++++++------ lib/Dialect/mhlo/transforms/legalize_to_linalg.cc | 10 +++++----- lib/Dialect/mhlo/transforms/lhlo_legalize_to_gpu.cc | 4 ++-- .../transforms/lhlo_legalize_to_parallel_loops.cc | 6 +++--- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/include/mlir-hlo/Dialect/mhlo/IR/hlo_ops.td b/include/mlir-hlo/Dialect/mhlo/IR/hlo_ops.td index 87f0e78..e9286fa 100644 --- a/include/mlir-hlo/Dialect/mhlo/IR/hlo_ops.td +++ b/include/mlir-hlo/Dialect/mhlo/IR/hlo_ops.td @@ -625,7 +625,7 @@ def HLO_ReduceOp: HLO_Op<"reduce", [ InferFusibilityOpInterface ]>, BASE_HLO_ReduceOp { let arguments = (ins - Variadic:$operands, + Variadic:$inputs, Variadic:$init_values, I64ElementsAttr:$dimensions ); @@ -633,7 +633,7 @@ def HLO_ReduceOp: HLO_Op<"reduce", [ let results = (outs Variadic); let builders = [ - OpBuilder<(ins "ValueRange":$operands, "ValueRange":$init_values, + OpBuilder<(ins "ValueRange":$inputs, "ValueRange":$init_values, "DenseIntElementsAttr":$dimensions)>]; let extraClassDeclaration = [{ diff --git a/include/mlir-hlo/Dialect/mhlo/IR/lhlo_ops.td b/include/mlir-hlo/Dialect/mhlo/IR/lhlo_ops.td index 9e3dffe..e7c7819 100644 --- a/include/mlir-hlo/Dialect/mhlo/IR/lhlo_ops.td +++ b/include/mlir-hlo/Dialect/mhlo/IR/lhlo_ops.td @@ -205,7 +205,7 @@ def LHLO_XorOp : LHLO_BinaryElementwiseOp<"xor", LHLO_PredOrIntBuffer>, BASE_HLO // TODO(timshen): cleanup lmhlo.TerminatorOp. def LHLO_ReduceOp: LHLO_Op<"reduce", [SameVariadicOperandSize]>, BASE_HLO_ReduceOp { let arguments = (ins - Arg, "", [MemRead]>:$operands, + Arg, "", [MemRead]>:$inputs, Arg, "", [MemRead]>:$init_values, Arg, "", [MemWrite]>:$out, I64ElementsAttr:$dimensions diff --git a/lib/Dialect/mhlo/IR/hlo_ops.cc b/lib/Dialect/mhlo/IR/hlo_ops.cc index 62dc881..f2a1aa6 100644 --- a/lib/Dialect/mhlo/IR/hlo_ops.cc +++ b/lib/Dialect/mhlo/IR/hlo_ops.cc @@ -1882,23 +1882,23 @@ static TensorType GetReduceResultType(Type operand_ty, } void ReduceOp::build(OpBuilder& builder, OperationState& state, - ValueRange operands, ValueRange init_values, + ValueRange inputs, ValueRange init_values, DenseIntElementsAttr dimensions) { SmallVector result_ty; - result_ty.reserve(operands.size()); + result_ty.reserve(inputs.size()); - for (Value operand : operands) { + for (Value input : inputs) { result_ty.push_back( - GetReduceResultType(operand.getType(), dimensions, &builder)); + GetReduceResultType(input.getType(), dimensions, &builder)); } - build(builder, state, result_ty, operands, init_values, dimensions); + build(builder, state, result_ty, inputs, init_values, dimensions); } LogicalResult ReduceOp::fold(ArrayRef operands, SmallVectorImpl& results) { // No dimensions to reduce. if (dimensions().getNumElements() == 0) { - for (Value input : this->operands()) { + for (Value input : this->inputs()) { results.push_back(input); } return success(); diff --git a/lib/Dialect/mhlo/transforms/legalize_to_linalg.cc b/lib/Dialect/mhlo/transforms/legalize_to_linalg.cc index e482f2b..306813c 100644 --- a/lib/Dialect/mhlo/transforms/legalize_to_linalg.cc +++ b/lib/Dialect/mhlo/transforms/legalize_to_linalg.cc @@ -984,7 +984,7 @@ class ReduceConverter : public OpConversionPattern { auto loc = reduce_op.getLoc(); lmhlo::ReduceOp::Adaptor adaptor(args); auto operand_shape = - adaptor.operands()[0].getType().template dyn_cast(); + adaptor.inputs()[0].getType().template dyn_cast(); if (!operand_shape || !operand_shape.hasRank()) { emitError(loc, "lhlo to linalg conversion expects known-rank args"); return failure(); @@ -1019,7 +1019,7 @@ class ReduceConverter : public OpConversionPattern { auto linalg_op = rewriter.create( loc, /*resultTensorTypes=*/ArrayRef{}, - /*inputs=*/adaptor.operands(), /*outputBuffers=*/adaptor.out(), maps, + /*inputs=*/adaptor.inputs(), /*outputBuffers=*/adaptor.out(), maps, types); rewriter.inlineRegionBefore(reduce_op.body(), linalg_op.region(), linalg_op.region().end()); @@ -1423,7 +1423,7 @@ class ReduceOnTensorsConversion : public OpConversionPattern { if (op.getNumOperands() != 2) { return op.emitError("expects exactly two operands"); } - Value src = adaptor.operands()[0]; + Value src = adaptor.inputs()[0]; auto src_type = src.getType().cast(); int src_rank = src_type.getRank(); if (!src_rank) { @@ -1458,11 +1458,11 @@ class ReduceOnTensorsConversion : public OpConversionPattern { indexing_maps.emplace_back(AffineMap::get(src_rank, /*symbolCount=*/0, exprs, rewriter.getContext())); - SmallVector inputs = {adaptor.operands()[0]}; + SmallVector inputs = {adaptor.inputs()[0]}; Type result_type = op.getResult(0).getType(); auto shaped_type = result_type.cast(); SmallVector dyn_shape = GetReduceOpInitTensorDynSizes( - rewriter, loc, adaptor.operands()[0], result_type.cast(), + rewriter, loc, adaptor.inputs()[0], result_type.cast(), reduction_dims); auto init_tensor = GetInitTensor(rewriter, loc, shaped_type, dyn_shape); Value filled_tensor = diff --git a/lib/Dialect/mhlo/transforms/lhlo_legalize_to_gpu.cc b/lib/Dialect/mhlo/transforms/lhlo_legalize_to_gpu.cc index cc15c61..e068fa7 100644 --- a/lib/Dialect/mhlo/transforms/lhlo_legalize_to_gpu.cc +++ b/lib/Dialect/mhlo/transforms/lhlo_legalize_to_gpu.cc @@ -72,7 +72,7 @@ class LhloReduceToGPULaunchConverter : public OpConversionPattern { // Require all inputs to have the same shape. int64_t reduce_dim_size = 0; - for (auto input : reduce_op.operands()) { + for (auto input : reduce_op.inputs()) { auto shaped_type = input.getType().dyn_cast(); if (!shaped_type || !shaped_type.hasStaticShape()) { return failure(); @@ -133,7 +133,7 @@ class LhloReduceToGPULaunchConverter : public OpConversionPattern { auto accumulator = rewriter.create( loc, resType, output, offset, size, stride); llvm::SmallVector indexings; - auto input_buffer = *reduce_op.operands().begin(); + Value input_buffer = reduce_op.inputs().front(); auto input_type_rank = input_buffer.getType().cast().getRank(); diff --git a/lib/Dialect/mhlo/transforms/lhlo_legalize_to_parallel_loops.cc b/lib/Dialect/mhlo/transforms/lhlo_legalize_to_parallel_loops.cc index 777f3a1..d054ee5 100644 --- a/lib/Dialect/mhlo/transforms/lhlo_legalize_to_parallel_loops.cc +++ b/lib/Dialect/mhlo/transforms/lhlo_legalize_to_parallel_loops.cc @@ -234,8 +234,8 @@ class ReduceOpConverter : public OpConversionPattern { reducing_dims.insert(rdim.getSExtValue()); } - Value operand = *reduce_op.operands().begin(); - Value out = *reduce_op.out().begin(); + Value operand = reduce_op.inputs().front(); + Value out = reduce_op.out().front(); SmallVector parallel_lower, parallel_upper, parallel_step; SmallVector reduce_lower, reduce_upper, reduce_step; auto operand_shape = operand.getType().cast().getShape(); @@ -293,7 +293,7 @@ class ReduceOpConverter : public OpConversionPattern { rewriter->setInsertionPointToStart(inner.getBody()); Value elem = rewriter->create( - loc, *reduce_op.operands().begin(), indices); + loc, reduce_op.inputs().front(), indices); return rewriter->create(loc, elem); } };