From c8f03a7fe80212b35b150910f5b73bfa5d272053 Mon Sep 17 00:00:00 2001 From: Eric Schweitz Date: Thu, 30 Sep 2021 10:22:16 +0200 Subject: [PATCH] [fir] Update fir.extract_value and fir.insert_value ops Move coor operand from variadic values to ArrayAttr. Update assembly format. This patch is part of the upstreaming effort from fir-dev branch. Reviewed By: kiranchandramohan Differential Revision: https://reviews.llvm.org/D110652 Co-authored-by: Jean Perier Co-authored-by: Valentin Clement --- flang/include/flang/Optimizer/Dialect/FIROps.td | 17 ++++++++++--- flang/lib/Optimizer/Dialect/FIROps.cpp | 33 +++++++++++++++++++------ flang/test/Fir/fir-ops.fir | 16 ++++++------ 3 files changed, 46 insertions(+), 20 deletions(-) diff --git a/flang/include/flang/Optimizer/Dialect/FIROps.td b/flang/include/flang/Optimizer/Dialect/FIROps.td index 470a1ff..c4903fb 100644 --- a/flang/include/flang/Optimizer/Dialect/FIROps.td +++ b/flang/include/flang/Optimizer/Dialect/FIROps.td @@ -1920,12 +1920,17 @@ def fir_ExtractValueOp : fir_OneResultOp<"extract_value", [NoSideEffect]> { let arguments = (ins AnyCompositeLike:$adt, - Variadic:$coor + ArrayAttr:$coor ); let assemblyFormat = [{ $adt `,` $coor attr-dict `:` functional-type(operands, results) }]; + + let builders = [ + OpBuilder<(ins "mlir::Type":$rty, "mlir::Value":$adt, + "llvm::ArrayRef":$vcoor)> + ]; } def fir_FieldIndexOp : fir_OneResultOp<"field_index", [NoSideEffect]> { @@ -2235,14 +2240,18 @@ def fir_InsertValueOp : fir_OneResultOp<"insert_value", [NoSideEffect]> { ``` }]; - let arguments = (ins AnyCompositeLike:$adt, AnyType:$val, - Variadic:$coor); + let arguments = (ins AnyCompositeLike:$adt, AnyType:$val, ArrayAttr:$coor); let results = (outs AnyCompositeLike); let assemblyFormat = [{ - operands attr-dict `:` functional-type(operands, results) + $adt `,` $val `,` $coor attr-dict `:` functional-type(operands, results) }]; + let builders = [ + OpBuilder<(ins "mlir::Type":$rty, "mlir::Value":$adt, "mlir::Value":$val, + "llvm::ArrayRef":$vcoor)> + ]; + let hasCanonicalizer = 1; } diff --git a/flang/lib/Optimizer/Dialect/FIROps.cpp b/flang/lib/Optimizer/Dialect/FIROps.cpp index 8810158..457e1b1 100644 --- a/flang/lib/Optimizer/Dialect/FIROps.cpp +++ b/flang/lib/Optimizer/Dialect/FIROps.cpp @@ -806,6 +806,18 @@ static mlir::ArrayAttr collectAsAttributes(mlir::MLIRContext *ctxt, } //===----------------------------------------------------------------------===// +// ExtractValueOp +//===----------------------------------------------------------------------===// + +void fir::ExtractValueOp::build(mlir::OpBuilder &builder, + OperationState &result, mlir::Type resTy, + mlir::Value aggVal, + llvm::ArrayRef inds) { + auto aa = collectAsAttributes<>(builder.getContext(), result, inds); + build(builder, result, resTy, aggVal, aa); +} + +//===----------------------------------------------------------------------===// // InsertOnRangeOp //===----------------------------------------------------------------------===// @@ -840,16 +852,21 @@ static mlir::LogicalResult verify(fir::InsertOnRangeOp op) { // InsertValueOp //===----------------------------------------------------------------------===// -static bool checkIsIntegerConstant(mlir::Value v, int64_t conVal) { - if (auto c = dyn_cast_or_null(v.getDefiningOp())) { - auto attr = c.getValue(); - if (auto iattr = attr.dyn_cast()) - return iattr.getInt() == conVal; - } +void fir::InsertValueOp::build(mlir::OpBuilder &builder, OperationState &result, + mlir::Type resTy, mlir::Value aggVal, + mlir::Value eleVal, + llvm::ArrayRef inds) { + auto aa = collectAsAttributes<>(builder.getContext(), result, inds); + build(builder, result, resTy, aggVal, eleVal, aa); +} + +static bool checkIsIntegerConstant(mlir::Attribute attr, int64_t conVal) { + if (auto iattr = attr.dyn_cast()) + return iattr.getInt() == conVal; return false; } -static bool isZero(mlir::Value v) { return checkIsIntegerConstant(v, 0); } -static bool isOne(mlir::Value v) { return checkIsIntegerConstant(v, 1); } +static bool isZero(mlir::Attribute a) { return checkIsIntegerConstant(a, 0); } +static bool isOne(mlir::Attribute a) { return checkIsIntegerConstant(a, 1); } // Undo some complex patterns created in the front-end and turn them back into // complex ops. diff --git a/flang/test/Fir/fir-ops.fir b/flang/test/Fir/fir-ops.fir index 4f57c6a..2abbcd3 100644 --- a/flang/test/Fir/fir-ops.fir +++ b/flang/test/Fir/fir-ops.fir @@ -89,22 +89,22 @@ func @instructions() { // CHECK: [[VAL_22:%.*]] = fir.coordinate_of [[VAL_5]], [[VAL_21]] : (!fir.heap>, i32) -> !fir.ref // CHECK: [[VAL_23:%.*]] = fir.field_index f, !fir.type // CHECK: [[VAL_24:%.*]] = fir.undefined !fir.type -// CHECK: [[VAL_25:%.*]] = fir.extract_value [[VAL_24]], [[VAL_23]] : (!fir.type, !fir.field) -> f32 +// CHECK: [[VAL_25:%.*]] = fir.extract_value [[VAL_24]], ["f", !fir.type] : (!fir.type) -> f32 %19 = constant 10 : i32 %20 = fir.coordinate_of %5, %19 : (!fir.heap>, i32) -> !fir.ref %21 = fir.field_index f, !fir.type %22 = fir.undefined !fir.type - %23 = fir.extract_value %22, %21 : (!fir.type, !fir.field) -> f32 + %23 = fir.extract_value %22, ["f", !fir.type] : (!fir.type) -> f32 // CHECK: [[VAL_26:%.*]] = constant 1 : i32 // CHECK: [[VAL_27:%.*]] = fir.shape [[VAL_21]] : (i32) -> !fir.shape<1> // CHECK: [[VAL_28:%.*]] = constant 1.0 -// CHECK: [[VAL_29:%.*]] = fir.insert_value [[VAL_24]], [[VAL_28]], [[VAL_23]] : (!fir.type, f32, !fir.field) -> !fir.type +// CHECK: [[VAL_29:%.*]] = fir.insert_value [[VAL_24]], [[VAL_28]], ["f", !fir.type] : (!fir.type, f32) -> !fir.type // CHECK: [[VAL_30:%.*]] = fir.len_param_index f, !fir.type %c1 = constant 1 : i32 %24 = fir.shape %19 : (i32) -> !fir.shape<1> %cf1 = constant 1.0 : f32 - %25 = fir.insert_value %22, %cf1, %21 : (!fir.type, f32, !fir.field) -> !fir.type + %25 = fir.insert_value %22, %cf1, ["f", !fir.type] : (!fir.type, f32) -> !fir.type %26 = fir.len_param_index f, !fir.type // CHECK: [[VAL_31:%.*]] = fir.call @box3() : () -> !fir.box> @@ -150,10 +150,10 @@ func @boxing_match() { // CHECK: [[VAL_48:%.*]] = fir.undefined !fir.type // CHECK: [[VAL_49:%.*]] = constant 0 : i32 // CHECK: [[VAL_50:%.*]] = constant 12 : i32 -// CHECK: [[VAL_51:%.*]] = fir.insert_value [[VAL_48]], [[VAL_50]], [[VAL_49]] : (!fir.type, i32, i32) -> !fir.type +// CHECK: [[VAL_51:%.*]] = fir.insert_value [[VAL_48]], [[VAL_50]], [0 : i32] : (!fir.type, i32) -> !fir.type // CHECK: [[VAL_52:%.*]] = constant 1 : i32 // CHECK: [[VAL_53:%.*]] = constant 4.213000e+01 : f64 -// CHECK: [[VAL_54:%.*]] = fir.insert_value [[VAL_48]], [[VAL_53]], [[VAL_52]] : (!fir.type, f64, i32) -> !fir.type +// CHECK: [[VAL_54:%.*]] = fir.insert_value [[VAL_48]], [[VAL_53]], [1 : i32] : (!fir.type, f64) -> !fir.type // CHECK: fir.store [[VAL_54]] to [[VAL_39]] : !fir.ref> // CHECK: [[VAL_55:%.*]] = fir.emboxproc @method_impl, [[VAL_41]] : ((!fir.box>) -> (), !fir.ref>) -> !fir.boxproc<(!fir.box>) -> ()> // CHECK: [[VAL_56:%.*]], [[VAL_57:%.*]] = fir.unboxproc [[VAL_55]] : (!fir.boxproc<(!fir.box>) -> ()>) -> ((!fir.box>) -> (), !fir.ref>>) @@ -176,10 +176,10 @@ func @boxing_match() { %6 = fir.undefined !fir.type %z = constant 0 : i32 %c12 = constant 12 : i32 - %a2 = fir.insert_value %6, %c12, %z : (!fir.type, i32, i32) -> !fir.type + %a2 = fir.insert_value %6, %c12, [0 : i32] : (!fir.type, i32) -> !fir.type %z1 = constant 1 : i32 %c42 = constant 42.13 : f64 - %a3 = fir.insert_value %6, %c42, %z1 : (!fir.type, f64, i32) -> !fir.type + %a3 = fir.insert_value %6, %c42, [1 : i32] : (!fir.type, f64) -> !fir.type fir.store %a3 to %d6 : !fir.ref> %7 = fir.emboxproc @method_impl, %e6 : ((!fir.box>) -> (), !fir.ref>) -> !fir.boxproc<(!fir.box>) -> ()> %8:2 = fir.unboxproc %7 : (!fir.boxproc<(!fir.box>) -> ()>) -> ((!fir.box>) -> (), !fir.ref>>) -- 2.7.4