[flang-commits] [flang] eaa583c - [flang] Use assembly format for fir.dispatch
Valentin Clement via flang-commits
flang-commits at lists.llvm.org
Thu Oct 6 12:41:27 PDT 2022
Author: Valentin Clement
Date: 2022-10-06T21:41:13+02:00
New Revision: eaa583c330a280698b227ecc80e3f5a7ebfa0244
URL: https://github.com/llvm/llvm-project/commit/eaa583c330a280698b227ecc80e3f5a7ebfa0244
DIFF: https://github.com/llvm/llvm-project/commit/eaa583c330a280698b227ecc80e3f5a7ebfa0244.diff
LOG: [flang] Use assembly format for fir.dispatch
Remove custom parser/printer and make use of the assembly format
for the fir.dispatch operation.
Depends on D135358
Reviewed By: PeteSteinfeld, jeanPerier
Differential Revision: https://reviews.llvm.org/D135363
Added:
Modified:
flang/include/flang/Optimizer/Dialect/FIROps.td
flang/lib/Optimizer/Dialect/FIROps.cpp
flang/test/Fir/Todo/dispatch.fir
flang/test/Fir/fir-ops.fir
flang/test/Fir/invalid.fir
Removed:
################################################################################
diff --git a/flang/include/flang/Optimizer/Dialect/FIROps.td b/flang/include/flang/Optimizer/Dialect/FIROps.td
index 3dd74db488fcf..5b61011998c6a 100644
--- a/flang/include/flang/Optimizer/Dialect/FIROps.td
+++ b/flang/include/flang/Optimizer/Dialect/FIROps.td
@@ -2336,7 +2336,7 @@ def fir_DispatchOp : fir_Op<"dispatch", []> {
%r = fir.dispatch "methodA"(%o) : (!fir.class<T>) -> i32
// fir.dispatch with the `pass_arg_pos` attribute.
- %r = fir.dispatch "methodA"(%o, %o) : (!fir.class<T>, !fir.class<T>) -> i32 {pass_arg_pos = 0 : i32}
+ %r = fir.dispatch "methodA"(%o : !fir.class<T>) (%o : !fir.class<T>) -> i32 {pass_arg_pos = 0 : i32}
```
}];
@@ -2347,11 +2347,14 @@ def fir_DispatchOp : fir_Op<"dispatch", []> {
OptionalAttr<I32Attr>:$pass_arg_pos
);
- let results = (outs Variadic<AnyType>);
+ let results = (outs Variadic<AnyType>:$results);
let hasVerifier = 1;
- let hasCustomAssemblyFormat = 1;
+ let assemblyFormat = [{
+ $method `(` $object `:` qualified(type($object)) `)`
+ ( `(` $args^ `:` type($args) `)` )? (`->` type($results)^)? attr-dict
+ }];
let extraClassDeclaration = [{
mlir::FunctionType getFunctionType();
diff --git a/flang/lib/Optimizer/Dialect/FIROps.cpp b/flang/lib/Optimizer/Dialect/FIROps.cpp
index 782f50d1ff5fd..577fe4dda5f3b 100644
--- a/flang/lib/Optimizer/Dialect/FIROps.cpp
+++ b/flang/lib/Optimizer/Dialect/FIROps.cpp
@@ -1057,47 +1057,6 @@ mlir::FunctionType fir::DispatchOp::getFunctionType() {
getResultTypes());
}
-mlir::ParseResult fir::DispatchOp::parse(mlir::OpAsmParser &parser,
- mlir::OperationState &result) {
- mlir::FunctionType calleeType;
- llvm::SmallVector<mlir::OpAsmParser::UnresolvedOperand> operands;
- auto calleeLoc = parser.getNameLoc();
- llvm::StringRef calleeName;
- if (failed(parser.parseOptionalKeyword(&calleeName))) {
- mlir::StringAttr calleeAttr;
- if (parser.parseAttribute(calleeAttr,
- fir::DispatchOp::getMethodAttrNameStr(),
- result.attributes))
- return mlir::failure();
- } else {
- result.addAttribute(fir::DispatchOp::getMethodAttrNameStr(),
- parser.getBuilder().getStringAttr(calleeName));
- }
- if (parser.parseOperandList(operands, mlir::OpAsmParser::Delimiter::Paren) ||
- parser.parseColonType(calleeType) ||
- parser.addTypesToList(calleeType.getResults(), result.types) ||
- parser.resolveOperands(operands, calleeType.getInputs(), calleeLoc,
- result.operands) ||
- parser.parseOptionalAttrDict(result.attributes))
- return mlir::failure();
- return mlir::success();
-}
-
-void fir::DispatchOp::print(mlir::OpAsmPrinter &p) {
- p << ' ' << getMethodAttr() << '(';
- p.printOperand(getObject());
- if (!getArgs().empty()) {
- p << ", ";
- p.printOperands(getArgs());
- }
- p << ") : ";
- p.printFunctionalType(getOperation()->getOperandTypes(),
- getOperation()->getResultTypes());
- p.printOptionalAttrDict(getOperation()->getAttrs(),
- {mlir::SymbolTable::getSymbolAttrName(),
- fir::DispatchOp::getMethodAttrNameStr()});
-}
-
//===----------------------------------------------------------------------===//
// DispatchTableOp
//===----------------------------------------------------------------------===//
diff --git a/flang/test/Fir/Todo/dispatch.fir b/flang/test/Fir/Todo/dispatch.fir
index dcc24bd818a3f..93ff86a800f9b 100644
--- a/flang/test/Fir/Todo/dispatch.fir
+++ b/flang/test/Fir/Todo/dispatch.fir
@@ -5,6 +5,6 @@
func.func @dispatch(%arg0: !fir.class<!fir.type<derived3{f:f32}>>) {
// CHECK: not yet implemented: fir.class type conversion
- %0 = fir.dispatch "method"(%arg0) : (!fir.class<!fir.type<derived3{f:f32}>>) -> i32
+ %0 = fir.dispatch "method"(%arg0 : !fir.class<!fir.type<derived3{f:f32}>>) -> i32
return
}
diff --git a/flang/test/Fir/fir-ops.fir b/flang/test/Fir/fir-ops.fir
index 66e46e340ab6b..2d89a63a67cd1 100644
--- a/flang/test/Fir/fir-ops.fir
+++ b/flang/test/Fir/fir-ops.fir
@@ -115,13 +115,13 @@ func.func @instructions() {
%26 = fir.len_param_index f, !fir.type<derived3{f:f32}>
// CHECK: [[VAL_31:%.*]] = fir.call @box3() : () -> !fir.class<!fir.type<derived3{f:f32}>>
-// CHECK: [[VAL_32:%.*]] = fir.dispatch "method"([[VAL_31]]) : (!fir.class<!fir.type<derived3{f:f32}>>) -> i32
+// CHECK: [[VAL_32:%.*]] = fir.dispatch "method"([[VAL_31]] : !fir.class<!fir.type<derived3{f:f32}>>) -> i32
// CHECK: [[VAL_33:%.*]] = fir.convert [[VAL_32]] : (i32) -> i64
// CHECK: [[VAL_34:%.*]] = fir.gentypedesc !fir.type<x>
// CHECK: fir.call @user_tdesc([[VAL_34]]) : (!fir.tdesc<!fir.type<x>>) -> ()
// CHECK: [[VAL_35:%.*]] = fir.no_reassoc [[VAL_33]] : i64
%27 = fir.call @box3() : () -> !fir.class<!fir.type<derived3{f:f32}>>
- %28 = fir.dispatch "method"(%27) : (!fir.class<!fir.type<derived3{f:f32}>>) -> i32
+ %28 = fir.dispatch "method"(%27 : !fir.class<!fir.type<derived3{f:f32}>>) -> i32
%29 = fir.convert %28 : (i32) -> i64
%30 = fir.gentypedesc !fir.type<x>
fir.call @user_tdesc(%30) : (!fir.tdesc<!fir.type<x>>) -> ()
@@ -310,11 +310,11 @@ func.func @bar_select_rank(%arg : i32, %arg2 : i32) -> i32 {
// CHECK: ^bb5:
// CHECK: [[VAL_99:%.*]] = arith.constant 0 : i32
// CHECK: [[VAL_100:%.*]] = fir.call @get_method_box() : () -> !fir.class<!fir.type<derived3{f:f32}>>
-// CHECK: fir.dispatch "method"([[VAL_100]]) : (!fir.class<!fir.type<derived3{f:f32}>>) -> ()
+// CHECK: fir.dispatch "method"([[VAL_100]] : !fir.class<!fir.type<derived3{f:f32}>>)
^bb5 :
%zero = arith.constant 0 : i32
%7 = fir.call @get_method_box() : () -> !fir.class<!fir.type<derived3{f:f32}>>
- fir.dispatch method(%7) : (!fir.class<!fir.type<derived3{f:f32}>>) -> ()
+ fir.dispatch "method"(%7 : !fir.class<!fir.type<derived3{f:f32}>>)
// CHECK: return [[VAL_99]] : i32
// CHECK: }
@@ -809,13 +809,13 @@ func.func @array_amend_ops(%a : !fir.ref<!fir.array<?x?xf32>>) {
func.func private @dispatch(%arg0: !fir.class<!fir.type<dispatch_derived1{a:i32,b:i32}>>, %arg1: i32) -> () {
// CHECK-LABEL: func.func private @dispatch(
// CHECK-SAME: %[[CLASS:.*]]: !fir.class<!fir.type<dispatch_derived1{a:i32,b:i32}>>, %[[INTARG:.*]]: i32)
- fir.dispatch "proc1"(%arg0, %arg0) : (!fir.class<!fir.type<dispatch_derived1{a:i32,b:i32}>>, !fir.class<!fir.type<dispatch_derived1{a:i32,b:i32}>>) -> () {pass_arg_pos = 0 : i32}
- // CHECK: fir.dispatch "proc1"(%[[CLASS]], %[[CLASS]]) : (!fir.class<!fir.type<dispatch_derived1{a:i32,b:i32}>>, !fir.class<!fir.type<dispatch_derived1{a:i32,b:i32}>>) -> () {pass_arg_pos = 0 : i32}
+ fir.dispatch "proc1"(%arg0 : !fir.class<!fir.type<dispatch_derived1{a:i32,b:i32}>>) (%arg0 : !fir.class<!fir.type<dispatch_derived1{a:i32,b:i32}>>) {pass_arg_pos = 0 : i32}
+ // CHECK: fir.dispatch "proc1"(%[[CLASS]] : !fir.class<!fir.type<dispatch_derived1{a:i32,b:i32}>>) (%[[CLASS]] : !fir.class<!fir.type<dispatch_derived1{a:i32,b:i32}>>) {pass_arg_pos = 0 : i32}
- fir.dispatch "proc2"(%arg0) : (!fir.class<!fir.type<dispatch_derived1{a:i32,b:i32}>>) -> () {nopass}
- // CHECK: fir.dispatch "proc2"(%[[CLASS]]) : (!fir.class<!fir.type<dispatch_derived1{a:i32,b:i32}>>) -> () {nopass}
+ fir.dispatch "proc2"(%arg0 : !fir.class<!fir.type<dispatch_derived1{a:i32,b:i32}>>)
+ // CHECK: fir.dispatch "proc2"(%[[CLASS]] : !fir.class<!fir.type<dispatch_derived1{a:i32,b:i32}>>)
- fir.dispatch "proc3"(%arg0, %arg1, %arg0) : (!fir.class<!fir.type<dispatch_derived1{a:i32,b:i32}>>, i32, !fir.class<!fir.type<dispatch_derived1{a:i32,b:i32}>>) -> () {pass_arg_pos = 1 : i32}
- // CHECK: fir.dispatch "proc3"(%[[CLASS]], %[[INTARG]], %[[CLASS]]) : (!fir.class<!fir.type<dispatch_derived1{a:i32,b:i32}>>, i32, !fir.class<!fir.type<dispatch_derived1{a:i32,b:i32}>>) -> () {pass_arg_pos = 1 : i32}
+ fir.dispatch "proc3"(%arg0 : !fir.class<!fir.type<dispatch_derived1{a:i32,b:i32}>>) (%arg1, %arg0 : i32, !fir.class<!fir.type<dispatch_derived1{a:i32,b:i32}>>) {pass_arg_pos = 1 : i32}
+ // CHECK: fir.dispatch "proc3"(%[[CLASS]] : !fir.class<!fir.type<dispatch_derived1{a:i32,b:i32}>>) (%[[INTARG]], %[[CLASS]] : i32, !fir.class<!fir.type<dispatch_derived1{a:i32,b:i32}>>) {pass_arg_pos = 1 : i32}
return
}
diff --git a/flang/test/Fir/invalid.fir b/flang/test/Fir/invalid.fir
index 6bf0612887f6d..05adc07fb919d 100644
--- a/flang/test/Fir/invalid.fir
+++ b/flang/test/Fir/invalid.fir
@@ -761,7 +761,7 @@ func.func private @ifoo(!fir.ref<f32>) -> i32
func.func private @dispatch(%arg0: !fir.class<!fir.type<derived{a:i32,b:i32}>>) -> () {
// expected-error at +1 {{'fir.dispatch' op pass_arg_pos must be smaller than the number of operands}}
- fir.dispatch "proc1"(%arg0, %arg0) : (!fir.class<!fir.type<derived{a:i32,b:i32}>>, !fir.class<!fir.type<derived{a:i32,b:i32}>>) -> () {pass_arg_pos = 1 : i32}
+ fir.dispatch "proc1"(%arg0 : !fir.class<!fir.type<derived{a:i32,b:i32}>>) (%arg0 : !fir.class<!fir.type<derived{a:i32,b:i32}>>) {pass_arg_pos = 1 : i32}
return
}
@@ -769,6 +769,6 @@ func.func private @dispatch(%arg0: !fir.class<!fir.type<derived{a:i32,b:i32}>>)
func.func private @dispatch(%arg0: !fir.class<!fir.type<derived{a:i32,b:i32}>>, %arg1: i32) -> () {
// expected-error at +1 {{'fir.dispatch' op pass_arg_pos must be a polymorphic operand}}
- fir.dispatch "proc1"(%arg0, %arg0, %arg1) : (!fir.class<!fir.type<derived{a:i32,b:i32}>>, !fir.class<!fir.type<derived{a:i32,b:i32}>>, i32) -> () {pass_arg_pos = 1 : i32}
+ fir.dispatch "proc1"(%arg0 : !fir.class<!fir.type<derived{a:i32,b:i32}>>) (%arg0, %arg1 : !fir.class<!fir.type<derived{a:i32,b:i32}>>, i32) {pass_arg_pos = 1 : i32}
return
}
More information about the flang-commits
mailing list