diff --git a/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td b/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td --- a/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td +++ b/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td @@ -178,8 +178,7 @@ }]; - let arguments = (ins Variadic:$presentOperands, - Variadic:$copyOperands, + let arguments = (ins Variadic:$copyOperands, Variadic:$copyinOperands, Variadic:$copyinReadonlyOperands, Variadic:$copyoutOperands, @@ -187,21 +186,26 @@ Variadic:$createOperands, Variadic:$createZeroOperands, Variadic:$noCreateOperands, + Variadic:$presentOperands, Variadic:$attachOperands); let regions = (region AnyRegion:$region); - let extraClassDeclaration = [{ - static StringRef getAttachKeyword() { return "attach"; } - static StringRef getCopyinKeyword() { return "copyin"; } - static StringRef getCopyinReadonlyKeyword() { return "copyin_readonly"; } - static StringRef getCopyKeyword() { return "copy"; } - static StringRef getCopyoutKeyword() { return "copyout"; } - static StringRef getCopyoutZeroKeyword() { return "copyout_zero"; } - static StringRef getCreateKeyword() { return "create"; } - static StringRef getCreateZeroKeyword() { return "create_zero"; } - static StringRef getNoCreateKeyword() { return "no_create"; } - static StringRef getPresentKeyword() { return "present"; } + let assemblyFormat = [{ + ( `copy` `(` $copyOperands^ `:` type($copyOperands) `)` )? + ( `copyin` `(` $copyinOperands^ `:` type($copyinOperands) `)` )? + ( `copyin_readonly` `(` $copyinReadonlyOperands^ `:` + type($copyinReadonlyOperands) `)` )? + ( `copyout` `(` $copyoutOperands^ `:` type($copyoutOperands) `)` )? + ( `copyout_zero` `(` $copyoutZeroOperands^ `:` + type($copyoutZeroOperands) `)` )? + ( `create` `(` $createOperands^ `:` type($createOperands) `)` )? + ( `create_zero` `(` $createZeroOperands^ `:` + type($createZeroOperands) `)` )? + ( `no_create` `(` $noCreateOperands^ `:` type($noCreateOperands) `)` )? + ( `present` `(` $presentOperands^ `:` type($presentOperands) `)` )? + ( `attach` `(` $attachOperands^ `:` type($attachOperands) `)` )? + $region attr-dict-with-keyword }]; let verifier = ?; diff --git a/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp b/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp --- a/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp +++ b/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp @@ -444,154 +444,6 @@ op.getAttrs(), ParallelOp::getOperandSegmentSizeAttr()); } -//===----------------------------------------------------------------------===// -// DataOp -//===----------------------------------------------------------------------===// - -/// Parse acc.data operation -/// operation := `acc.data` (`present` `(` value-list `)`)? -/// (`copy` `(` value-list `)`)? -/// (`copyin` `(` value-list `)`)? -/// (`copyin_readonly` `(` value-list `)`)? -/// (`copyout` `(` value-list `)`)? -/// (`copyout_zero` `(` value-list `)`)? -/// (`create` `(` value-list `)`)? -/// (`create_zero` `(` value-list `)`)? -/// (`no_create` `(` value-list `)`)? -/// (`attach` `(` value-list `)`)? -/// region attr-dict? -static ParseResult parseDataOp(OpAsmParser &parser, OperationState &result) { - Builder &builder = parser.getBuilder(); - SmallVector presentOperands, copyOperands, - copyinOperands, copyinReadonlyOperands, copyoutOperands, - copyoutZeroOperands, createOperands, createZeroOperands, noCreateOperands, - attachOperands; - SmallVector presentOperandTypes, copyOperandTypes, - copyinOperandTypes, copyinReadonlyOperandTypes, copyoutOperandTypes, - copyoutZeroOperandTypes, createOperandTypes, createZeroOperandTypes, - noCreateOperandTypes, attachOperandTypes; - - // present(value-list)? - if (failed(parseOperandList(parser, DataOp::getPresentKeyword(), - presentOperands, presentOperandTypes, result))) - return failure(); - - // copy(value-list)? - if (failed(parseOperandList(parser, DataOp::getCopyKeyword(), copyOperands, - copyOperandTypes, result))) - return failure(); - - // copyin(value-list)? - if (failed(parseOperandList(parser, DataOp::getCopyinKeyword(), - copyinOperands, copyinOperandTypes, result))) - return failure(); - - // copyin_readonly(value-list)? - if (failed(parseOperandList(parser, DataOp::getCopyinReadonlyKeyword(), - copyinReadonlyOperands, copyinOperandTypes, - result))) - return failure(); - - // copyout(value-list)? - if (failed(parseOperandList(parser, DataOp::getCopyoutKeyword(), - copyoutOperands, copyoutOperandTypes, result))) - return failure(); - - // copyout_zero(value-list)? - if (failed(parseOperandList(parser, DataOp::getCopyoutZeroKeyword(), - copyoutZeroOperands, copyoutZeroOperandTypes, - result))) - return failure(); - - // create(value-list)? - if (failed(parseOperandList(parser, DataOp::getCreateKeyword(), - createOperands, createOperandTypes, result))) - return failure(); - - // create_zero(value-list)? - if (failed(parseOperandList(parser, DataOp::getCreateZeroKeyword(), - createZeroOperands, createZeroOperandTypes, - result))) - return failure(); - - // no_create(value-list)? - if (failed(parseOperandList(parser, DataOp::getNoCreateKeyword(), - noCreateOperands, noCreateOperandTypes, result))) - return failure(); - - // attach(value-list)? - if (failed(parseOperandList(parser, DataOp::getAttachKeyword(), - attachOperands, attachOperandTypes, result))) - return failure(); - - // Data op region - if (failed(parseRegions(parser, result))) - return failure(); - - result.addAttribute(ParallelOp::getOperandSegmentSizeAttr(), - builder.getI32VectorAttr( - {static_cast(presentOperands.size()), - static_cast(copyOperands.size()), - static_cast(copyinOperands.size()), - static_cast(copyinReadonlyOperands.size()), - static_cast(copyoutOperands.size()), - static_cast(copyoutZeroOperands.size()), - static_cast(createOperands.size()), - static_cast(createZeroOperands.size()), - static_cast(noCreateOperands.size()), - static_cast(attachOperands.size())})); - - // Additional attributes - if (failed(parser.parseOptionalAttrDictWithKeyword(result.attributes))) - return failure(); - - return success(); -} - -static void print(OpAsmPrinter &printer, DataOp &op) { - printer << DataOp::getOperationName(); - - // present(value-list)? - printOperandList(op.presentOperands(), DataOp::getPresentKeyword(), printer); - - // copy(value-list)? - printOperandList(op.copyOperands(), DataOp::getCopyKeyword(), printer); - - // copyin(value-list)? - printOperandList(op.copyinOperands(), DataOp::getCopyinKeyword(), printer); - - // copyin_readonly(value-list)? - printOperandList(op.copyinReadonlyOperands(), - DataOp::getCopyinReadonlyKeyword(), printer); - - // copyout(value-list)? - printOperandList(op.copyoutOperands(), DataOp::getCopyoutKeyword(), printer); - - // copyout(value-list)? - printOperandList(op.copyoutZeroOperands(), DataOp::getCopyoutZeroKeyword(), - printer); - - // create(value-list)? - printOperandList(op.createOperands(), DataOp::getCreateKeyword(), printer); - - // create_zero(value-list)? - printOperandList(op.createZeroOperands(), DataOp::getCreateZeroKeyword(), - printer); - - // no_create(value-list)? - printOperandList(op.noCreateOperands(), DataOp::getNoCreateKeyword(), - printer); - - // attach(value-list)? - printOperandList(op.attachOperands(), DataOp::getAttachKeyword(), printer); - - printer.printRegion(op.region(), - /*printEntryBlockArgs=*/false, - /*printBlockTerminators=*/true); - printer.printOptionalAttrDictWithKeyword( - op.getAttrs(), ParallelOp::getOperandSegmentSizeAttr()); -} - //===----------------------------------------------------------------------===// // LoopOp //===----------------------------------------------------------------------===// diff --git a/mlir/test/Dialect/OpenACC/ops.mlir b/mlir/test/Dialect/OpenACC/ops.mlir --- a/mlir/test/Dialect/OpenACC/ops.mlir +++ b/mlir/test/Dialect/OpenACC/ops.mlir @@ -121,7 +121,7 @@ %numGangs = constant 10 : i64 %numWorkers = constant 10 : i64 - acc.data present(%a: memref<10x10xf32>, %b: memref<10x10xf32>, %c: memref<10xf32>, %d: memref<10xf32>) { + acc.data present(%a, %b, %c, %d: memref<10x10xf32>, memref<10x10xf32>, memref<10xf32>, memref<10xf32>) { acc.parallel num_gangs(%numGangs: i64) num_workers(%numWorkers: i64) private(%c : memref<10xf32>) { acc.loop gang { scf.for %x = %lb to %c10 step %st { @@ -163,7 +163,7 @@ // CHECK-NEXT: [[C10:%.*]] = constant 10 : index // CHECK-NEXT: [[NUMGANG:%.*]] = constant 10 : i64 // CHECK-NEXT: [[NUMWORKERS:%.*]] = constant 10 : i64 -// CHECK-NEXT: acc.data present(%{{.*}}: memref<10x10xf32>, %{{.*}}: memref<10x10xf32>, %{{.*}}: memref<10xf32>, %{{.*}}: memref<10xf32>) { +// CHECK-NEXT: acc.data present(%{{.*}}, %{{.*}}, %{{.*}}, %{{.*}} : memref<10x10xf32>, memref<10x10xf32>, memref<10xf32>, memref<10xf32>) { // CHECK-NEXT: acc.parallel num_gangs([[NUMGANG]]: i64) num_workers([[NUMWORKERS]]: i64) private([[ARG2]]: memref<10xf32>) { // CHECK-NEXT: acc.loop gang { // CHECK-NEXT: scf.for %{{.*}} = [[C0]] to [[C10]] step [[C1]] { @@ -454,51 +454,51 @@ // ----- func @testdataop(%a: memref<10xf32>, %b: memref<10xf32>, %c: memref<10x10xf32>) -> () { - acc.data present(%a: memref<10xf32>, %b: memref<10xf32>, %c: memref<10x10xf32>) { + acc.data present(%a, %b, %c : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) { } - acc.data copy(%a: memref<10xf32>, %b: memref<10xf32>, %c: memref<10x10xf32>) { + acc.data copy(%a, %b, %c : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) { } - acc.data copyin(%a: memref<10xf32>, %b: memref<10xf32>, %c: memref<10x10xf32>) { + acc.data copyin(%a, %b, %c : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) { } - acc.data copyin_readonly(%a: memref<10xf32>, %b: memref<10xf32>, %c: memref<10x10xf32>) { + acc.data copyin_readonly(%a, %b, %c : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) { } - acc.data copyout(%a: memref<10xf32>, %b: memref<10xf32>, %c: memref<10x10xf32>) { + acc.data copyout(%a, %b, %c : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) { } - acc.data copyout_zero(%a: memref<10xf32>, %b: memref<10xf32>, %c: memref<10x10xf32>) { + acc.data copyout_zero(%a, %b, %c : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) { } - acc.data create(%a: memref<10xf32>, %b: memref<10xf32>, %c: memref<10x10xf32>) { + acc.data create(%a, %b, %c : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) { } - acc.data create_zero(%a: memref<10xf32>, %b: memref<10xf32>, %c: memref<10x10xf32>) { + acc.data create_zero(%a, %b, %c : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) { } - acc.data no_create(%a: memref<10xf32>, %b: memref<10xf32>, %c: memref<10x10xf32>) { + acc.data no_create(%a, %b, %c : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) { } - acc.data attach(%a: memref<10xf32>, %b: memref<10xf32>, %c: memref<10x10xf32>) { + acc.data attach(%a, %b, %c : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) { } - acc.data present(%a: memref<10xf32>) copyin(%b: memref<10xf32>) copyout(%c: memref<10x10xf32>) { + acc.data copyin(%b: memref<10xf32>) copyout(%c: memref<10x10xf32>) present(%a: memref<10xf32>) { } return } // CHECK: func @testdataop([[ARGA:%.*]]: memref<10xf32>, [[ARGB:%.*]]: memref<10xf32>, [[ARGC:%.*]]: memref<10x10xf32>) { -// CHECK: acc.data present([[ARGA]]: memref<10xf32>, [[ARGB]]: memref<10xf32>, [[ARGC]]: memref<10x10xf32>) { +// CHECK: acc.data present([[ARGA]], [[ARGB]], [[ARGC]] : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) { // CHECK-NEXT: } -// CHECK: acc.data copy([[ARGA]]: memref<10xf32>, [[ARGB]]: memref<10xf32>, [[ARGC]]: memref<10x10xf32>) { +// CHECK: acc.data copy([[ARGA]], [[ARGB]], [[ARGC]] : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) { // CHECK-NEXT: } -// CHECK: acc.data copyin([[ARGA]]: memref<10xf32>, [[ARGB]]: memref<10xf32>, [[ARGC]]: memref<10x10xf32>) { +// CHECK: acc.data copyin([[ARGA]], [[ARGB]], [[ARGC]] : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) { // CHECK-NEXT: } -// CHECK: acc.data copyin_readonly([[ARGA]]: memref<10xf32>, [[ARGB]]: memref<10xf32>, [[ARGC]]: memref<10x10xf32>) { +// CHECK: acc.data copyin_readonly([[ARGA]], [[ARGB]], [[ARGC]] : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) { // CHECK-NEXT: } -// CHECK: acc.data copyout([[ARGA]]: memref<10xf32>, [[ARGB]]: memref<10xf32>, [[ARGC]]: memref<10x10xf32>) { +// CHECK: acc.data copyout([[ARGA]], [[ARGB]], [[ARGC]] : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) { // CHECK-NEXT: } -// CHECK: acc.data copyout_zero([[ARGA]]: memref<10xf32>, [[ARGB]]: memref<10xf32>, [[ARGC]]: memref<10x10xf32>) { +// CHECK: acc.data copyout_zero([[ARGA]], [[ARGB]], [[ARGC]] : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) { // CHECK-NEXT: } -// CHECK: acc.data create([[ARGA]]: memref<10xf32>, [[ARGB]]: memref<10xf32>, [[ARGC]]: memref<10x10xf32>) { +// CHECK: acc.data create([[ARGA]], [[ARGB]], [[ARGC]] : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) { // CHECK-NEXT: } -// CHECK: acc.data create_zero([[ARGA]]: memref<10xf32>, [[ARGB]]: memref<10xf32>, [[ARGC]]: memref<10x10xf32>) { +// CHECK: acc.data create_zero([[ARGA]], [[ARGB]], [[ARGC]] : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) { // CHECK-NEXT: } -// CHECK: acc.data no_create([[ARGA]]: memref<10xf32>, [[ARGB]]: memref<10xf32>, [[ARGC]]: memref<10x10xf32>) { +// CHECK: acc.data no_create([[ARGA]], [[ARGB]], [[ARGC]] : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) { // CHECK-NEXT: } -// CHECK: acc.data attach([[ARGA]]: memref<10xf32>, [[ARGB]]: memref<10xf32>, [[ARGC]]: memref<10x10xf32>) { +// CHECK: acc.data attach([[ARGA]], [[ARGB]], [[ARGC]] : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) { // CHECK-NEXT: } -// CHECK: acc.data present([[ARGA]]: memref<10xf32>) copyin([[ARGB]]: memref<10xf32>) copyout([[ARGC]]: memref<10x10xf32>) { +// CHECK: acc.data copyin([[ARGB]] : memref<10xf32>) copyout([[ARGC]] : memref<10x10xf32>) present([[ARGA]] : memref<10xf32>) { // CHECK-NEXT: }