Skip to content

Commit 12ab4f8

Browse files
committed
[mlir][openacc] Switch to assembly format for acc.data
This patch remove the printer/parser for the acc.data operation since its syntax fits nicely with the assembly format. It reduces the maintenance for this op. Reviewed By: kiranchandramohan Differential Revision: https://reviews.llvm.org/D88330
1 parent 3d2bab1 commit 12ab4f8

File tree

3 files changed

+41
-185
lines changed

3 files changed

+41
-185
lines changed

mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -178,30 +178,34 @@ def OpenACC_DataOp : OpenACC_Op<"data",
178178
}];
179179

180180

181-
let arguments = (ins Variadic<AnyType>:$presentOperands,
182-
Variadic<AnyType>:$copyOperands,
181+
let arguments = (ins Variadic<AnyType>:$copyOperands,
183182
Variadic<AnyType>:$copyinOperands,
184183
Variadic<AnyType>:$copyinReadonlyOperands,
185184
Variadic<AnyType>:$copyoutOperands,
186185
Variadic<AnyType>:$copyoutZeroOperands,
187186
Variadic<AnyType>:$createOperands,
188187
Variadic<AnyType>:$createZeroOperands,
189188
Variadic<AnyType>:$noCreateOperands,
189+
Variadic<AnyType>:$presentOperands,
190190
Variadic<AnyType>:$attachOperands);
191191

192192
let regions = (region AnyRegion:$region);
193193

194-
let extraClassDeclaration = [{
195-
static StringRef getAttachKeyword() { return "attach"; }
196-
static StringRef getCopyinKeyword() { return "copyin"; }
197-
static StringRef getCopyinReadonlyKeyword() { return "copyin_readonly"; }
198-
static StringRef getCopyKeyword() { return "copy"; }
199-
static StringRef getCopyoutKeyword() { return "copyout"; }
200-
static StringRef getCopyoutZeroKeyword() { return "copyout_zero"; }
201-
static StringRef getCreateKeyword() { return "create"; }
202-
static StringRef getCreateZeroKeyword() { return "create_zero"; }
203-
static StringRef getNoCreateKeyword() { return "no_create"; }
204-
static StringRef getPresentKeyword() { return "present"; }
194+
let assemblyFormat = [{
195+
( `copy` `(` $copyOperands^ `:` type($copyOperands) `)` )?
196+
( `copyin` `(` $copyinOperands^ `:` type($copyinOperands) `)` )?
197+
( `copyin_readonly` `(` $copyinReadonlyOperands^ `:`
198+
type($copyinReadonlyOperands) `)` )?
199+
( `copyout` `(` $copyoutOperands^ `:` type($copyoutOperands) `)` )?
200+
( `copyout_zero` `(` $copyoutZeroOperands^ `:`
201+
type($copyoutZeroOperands) `)` )?
202+
( `create` `(` $createOperands^ `:` type($createOperands) `)` )?
203+
( `create_zero` `(` $createZeroOperands^ `:`
204+
type($createZeroOperands) `)` )?
205+
( `no_create` `(` $noCreateOperands^ `:` type($noCreateOperands) `)` )?
206+
( `present` `(` $presentOperands^ `:` type($presentOperands) `)` )?
207+
( `attach` `(` $attachOperands^ `:` type($attachOperands) `)` )?
208+
$region attr-dict-with-keyword
205209
}];
206210

207211
let verifier = ?;

mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp

Lines changed: 0 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -444,154 +444,6 @@ static void print(OpAsmPrinter &printer, ParallelOp &op) {
444444
op.getAttrs(), ParallelOp::getOperandSegmentSizeAttr());
445445
}
446446

447-
//===----------------------------------------------------------------------===//
448-
// DataOp
449-
//===----------------------------------------------------------------------===//
450-
451-
/// Parse acc.data operation
452-
/// operation := `acc.data` (`present` `(` value-list `)`)?
453-
/// (`copy` `(` value-list `)`)?
454-
/// (`copyin` `(` value-list `)`)?
455-
/// (`copyin_readonly` `(` value-list `)`)?
456-
/// (`copyout` `(` value-list `)`)?
457-
/// (`copyout_zero` `(` value-list `)`)?
458-
/// (`create` `(` value-list `)`)?
459-
/// (`create_zero` `(` value-list `)`)?
460-
/// (`no_create` `(` value-list `)`)?
461-
/// (`attach` `(` value-list `)`)?
462-
/// region attr-dict?
463-
static ParseResult parseDataOp(OpAsmParser &parser, OperationState &result) {
464-
Builder &builder = parser.getBuilder();
465-
SmallVector<OpAsmParser::OperandType, 2> presentOperands, copyOperands,
466-
copyinOperands, copyinReadonlyOperands, copyoutOperands,
467-
copyoutZeroOperands, createOperands, createZeroOperands, noCreateOperands,
468-
attachOperands;
469-
SmallVector<Type, 2> presentOperandTypes, copyOperandTypes,
470-
copyinOperandTypes, copyinReadonlyOperandTypes, copyoutOperandTypes,
471-
copyoutZeroOperandTypes, createOperandTypes, createZeroOperandTypes,
472-
noCreateOperandTypes, attachOperandTypes;
473-
474-
// present(value-list)?
475-
if (failed(parseOperandList(parser, DataOp::getPresentKeyword(),
476-
presentOperands, presentOperandTypes, result)))
477-
return failure();
478-
479-
// copy(value-list)?
480-
if (failed(parseOperandList(parser, DataOp::getCopyKeyword(), copyOperands,
481-
copyOperandTypes, result)))
482-
return failure();
483-
484-
// copyin(value-list)?
485-
if (failed(parseOperandList(parser, DataOp::getCopyinKeyword(),
486-
copyinOperands, copyinOperandTypes, result)))
487-
return failure();
488-
489-
// copyin_readonly(value-list)?
490-
if (failed(parseOperandList(parser, DataOp::getCopyinReadonlyKeyword(),
491-
copyinReadonlyOperands, copyinOperandTypes,
492-
result)))
493-
return failure();
494-
495-
// copyout(value-list)?
496-
if (failed(parseOperandList(parser, DataOp::getCopyoutKeyword(),
497-
copyoutOperands, copyoutOperandTypes, result)))
498-
return failure();
499-
500-
// copyout_zero(value-list)?
501-
if (failed(parseOperandList(parser, DataOp::getCopyoutZeroKeyword(),
502-
copyoutZeroOperands, copyoutZeroOperandTypes,
503-
result)))
504-
return failure();
505-
506-
// create(value-list)?
507-
if (failed(parseOperandList(parser, DataOp::getCreateKeyword(),
508-
createOperands, createOperandTypes, result)))
509-
return failure();
510-
511-
// create_zero(value-list)?
512-
if (failed(parseOperandList(parser, DataOp::getCreateZeroKeyword(),
513-
createZeroOperands, createZeroOperandTypes,
514-
result)))
515-
return failure();
516-
517-
// no_create(value-list)?
518-
if (failed(parseOperandList(parser, DataOp::getNoCreateKeyword(),
519-
noCreateOperands, noCreateOperandTypes, result)))
520-
return failure();
521-
522-
// attach(value-list)?
523-
if (failed(parseOperandList(parser, DataOp::getAttachKeyword(),
524-
attachOperands, attachOperandTypes, result)))
525-
return failure();
526-
527-
// Data op region
528-
if (failed(parseRegions<ParallelOp>(parser, result)))
529-
return failure();
530-
531-
result.addAttribute(ParallelOp::getOperandSegmentSizeAttr(),
532-
builder.getI32VectorAttr(
533-
{static_cast<int32_t>(presentOperands.size()),
534-
static_cast<int32_t>(copyOperands.size()),
535-
static_cast<int32_t>(copyinOperands.size()),
536-
static_cast<int32_t>(copyinReadonlyOperands.size()),
537-
static_cast<int32_t>(copyoutOperands.size()),
538-
static_cast<int32_t>(copyoutZeroOperands.size()),
539-
static_cast<int32_t>(createOperands.size()),
540-
static_cast<int32_t>(createZeroOperands.size()),
541-
static_cast<int32_t>(noCreateOperands.size()),
542-
static_cast<int32_t>(attachOperands.size())}));
543-
544-
// Additional attributes
545-
if (failed(parser.parseOptionalAttrDictWithKeyword(result.attributes)))
546-
return failure();
547-
548-
return success();
549-
}
550-
551-
static void print(OpAsmPrinter &printer, DataOp &op) {
552-
printer << DataOp::getOperationName();
553-
554-
// present(value-list)?
555-
printOperandList(op.presentOperands(), DataOp::getPresentKeyword(), printer);
556-
557-
// copy(value-list)?
558-
printOperandList(op.copyOperands(), DataOp::getCopyKeyword(), printer);
559-
560-
// copyin(value-list)?
561-
printOperandList(op.copyinOperands(), DataOp::getCopyinKeyword(), printer);
562-
563-
// copyin_readonly(value-list)?
564-
printOperandList(op.copyinReadonlyOperands(),
565-
DataOp::getCopyinReadonlyKeyword(), printer);
566-
567-
// copyout(value-list)?
568-
printOperandList(op.copyoutOperands(), DataOp::getCopyoutKeyword(), printer);
569-
570-
// copyout(value-list)?
571-
printOperandList(op.copyoutZeroOperands(), DataOp::getCopyoutZeroKeyword(),
572-
printer);
573-
574-
// create(value-list)?
575-
printOperandList(op.createOperands(), DataOp::getCreateKeyword(), printer);
576-
577-
// create_zero(value-list)?
578-
printOperandList(op.createZeroOperands(), DataOp::getCreateZeroKeyword(),
579-
printer);
580-
581-
// no_create(value-list)?
582-
printOperandList(op.noCreateOperands(), DataOp::getNoCreateKeyword(),
583-
printer);
584-
585-
// attach(value-list)?
586-
printOperandList(op.attachOperands(), DataOp::getAttachKeyword(), printer);
587-
588-
printer.printRegion(op.region(),
589-
/*printEntryBlockArgs=*/false,
590-
/*printBlockTerminators=*/true);
591-
printer.printOptionalAttrDictWithKeyword(
592-
op.getAttrs(), ParallelOp::getOperandSegmentSizeAttr());
593-
}
594-
595447
//===----------------------------------------------------------------------===//
596448
// LoopOp
597449
//===----------------------------------------------------------------------===//

mlir/test/Dialect/OpenACC/ops.mlir

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func @compute3(%a: memref<10x10xf32>, %b: memref<10x10xf32>, %c: memref<10xf32>,
121121
%numGangs = constant 10 : i64
122122
%numWorkers = constant 10 : i64
123123

124-
acc.data present(%a: memref<10x10xf32>, %b: memref<10x10xf32>, %c: memref<10xf32>, %d: memref<10xf32>) {
124+
acc.data present(%a, %b, %c, %d: memref<10x10xf32>, memref<10x10xf32>, memref<10xf32>, memref<10xf32>) {
125125
acc.parallel num_gangs(%numGangs: i64) num_workers(%numWorkers: i64) private(%c : memref<10xf32>) {
126126
acc.loop gang {
127127
scf.for %x = %lb to %c10 step %st {
@@ -163,7 +163,7 @@ func @compute3(%a: memref<10x10xf32>, %b: memref<10x10xf32>, %c: memref<10xf32>,
163163
// CHECK-NEXT: [[C10:%.*]] = constant 10 : index
164164
// CHECK-NEXT: [[NUMGANG:%.*]] = constant 10 : i64
165165
// CHECK-NEXT: [[NUMWORKERS:%.*]] = constant 10 : i64
166-
// CHECK-NEXT: acc.data present(%{{.*}}: memref<10x10xf32>, %{{.*}}: memref<10x10xf32>, %{{.*}}: memref<10xf32>, %{{.*}}: memref<10xf32>) {
166+
// CHECK-NEXT: acc.data present(%{{.*}}, %{{.*}}, %{{.*}}, %{{.*}} : memref<10x10xf32>, memref<10x10xf32>, memref<10xf32>, memref<10xf32>) {
167167
// CHECK-NEXT: acc.parallel num_gangs([[NUMGANG]]: i64) num_workers([[NUMWORKERS]]: i64) private([[ARG2]]: memref<10xf32>) {
168168
// CHECK-NEXT: acc.loop gang {
169169
// CHECK-NEXT: scf.for %{{.*}} = [[C0]] to [[C10]] step [[C1]] {
@@ -454,51 +454,51 @@ func @testparallelop(%a: memref<10xf32>, %b: memref<10xf32>, %c: memref<10x10xf3
454454
// -----
455455

456456
func @testdataop(%a: memref<10xf32>, %b: memref<10xf32>, %c: memref<10x10xf32>) -> () {
457-
acc.data present(%a: memref<10xf32>, %b: memref<10xf32>, %c: memref<10x10xf32>) {
457+
acc.data present(%a, %b, %c : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) {
458458
}
459-
acc.data copy(%a: memref<10xf32>, %b: memref<10xf32>, %c: memref<10x10xf32>) {
459+
acc.data copy(%a, %b, %c : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) {
460460
}
461-
acc.data copyin(%a: memref<10xf32>, %b: memref<10xf32>, %c: memref<10x10xf32>) {
461+
acc.data copyin(%a, %b, %c : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) {
462462
}
463-
acc.data copyin_readonly(%a: memref<10xf32>, %b: memref<10xf32>, %c: memref<10x10xf32>) {
463+
acc.data copyin_readonly(%a, %b, %c : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) {
464464
}
465-
acc.data copyout(%a: memref<10xf32>, %b: memref<10xf32>, %c: memref<10x10xf32>) {
465+
acc.data copyout(%a, %b, %c : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) {
466466
}
467-
acc.data copyout_zero(%a: memref<10xf32>, %b: memref<10xf32>, %c: memref<10x10xf32>) {
467+
acc.data copyout_zero(%a, %b, %c : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) {
468468
}
469-
acc.data create(%a: memref<10xf32>, %b: memref<10xf32>, %c: memref<10x10xf32>) {
469+
acc.data create(%a, %b, %c : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) {
470470
}
471-
acc.data create_zero(%a: memref<10xf32>, %b: memref<10xf32>, %c: memref<10x10xf32>) {
471+
acc.data create_zero(%a, %b, %c : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) {
472472
}
473-
acc.data no_create(%a: memref<10xf32>, %b: memref<10xf32>, %c: memref<10x10xf32>) {
473+
acc.data no_create(%a, %b, %c : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) {
474474
}
475-
acc.data attach(%a: memref<10xf32>, %b: memref<10xf32>, %c: memref<10x10xf32>) {
475+
acc.data attach(%a, %b, %c : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) {
476476
}
477-
acc.data present(%a: memref<10xf32>) copyin(%b: memref<10xf32>) copyout(%c: memref<10x10xf32>) {
477+
acc.data copyin(%b: memref<10xf32>) copyout(%c: memref<10x10xf32>) present(%a: memref<10xf32>) {
478478
}
479479
return
480480
}
481481

482482
// CHECK: func @testdataop([[ARGA:%.*]]: memref<10xf32>, [[ARGB:%.*]]: memref<10xf32>, [[ARGC:%.*]]: memref<10x10xf32>) {
483-
// CHECK: acc.data present([[ARGA]]: memref<10xf32>, [[ARGB]]: memref<10xf32>, [[ARGC]]: memref<10x10xf32>) {
483+
// CHECK: acc.data present([[ARGA]], [[ARGB]], [[ARGC]] : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) {
484484
// CHECK-NEXT: }
485-
// CHECK: acc.data copy([[ARGA]]: memref<10xf32>, [[ARGB]]: memref<10xf32>, [[ARGC]]: memref<10x10xf32>) {
485+
// CHECK: acc.data copy([[ARGA]], [[ARGB]], [[ARGC]] : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) {
486486
// CHECK-NEXT: }
487-
// CHECK: acc.data copyin([[ARGA]]: memref<10xf32>, [[ARGB]]: memref<10xf32>, [[ARGC]]: memref<10x10xf32>) {
487+
// CHECK: acc.data copyin([[ARGA]], [[ARGB]], [[ARGC]] : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) {
488488
// CHECK-NEXT: }
489-
// CHECK: acc.data copyin_readonly([[ARGA]]: memref<10xf32>, [[ARGB]]: memref<10xf32>, [[ARGC]]: memref<10x10xf32>) {
489+
// CHECK: acc.data copyin_readonly([[ARGA]], [[ARGB]], [[ARGC]] : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) {
490490
// CHECK-NEXT: }
491-
// CHECK: acc.data copyout([[ARGA]]: memref<10xf32>, [[ARGB]]: memref<10xf32>, [[ARGC]]: memref<10x10xf32>) {
491+
// CHECK: acc.data copyout([[ARGA]], [[ARGB]], [[ARGC]] : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) {
492492
// CHECK-NEXT: }
493-
// CHECK: acc.data copyout_zero([[ARGA]]: memref<10xf32>, [[ARGB]]: memref<10xf32>, [[ARGC]]: memref<10x10xf32>) {
493+
// CHECK: acc.data copyout_zero([[ARGA]], [[ARGB]], [[ARGC]] : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) {
494494
// CHECK-NEXT: }
495-
// CHECK: acc.data create([[ARGA]]: memref<10xf32>, [[ARGB]]: memref<10xf32>, [[ARGC]]: memref<10x10xf32>) {
495+
// CHECK: acc.data create([[ARGA]], [[ARGB]], [[ARGC]] : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) {
496496
// CHECK-NEXT: }
497-
// CHECK: acc.data create_zero([[ARGA]]: memref<10xf32>, [[ARGB]]: memref<10xf32>, [[ARGC]]: memref<10x10xf32>) {
497+
// CHECK: acc.data create_zero([[ARGA]], [[ARGB]], [[ARGC]] : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) {
498498
// CHECK-NEXT: }
499-
// CHECK: acc.data no_create([[ARGA]]: memref<10xf32>, [[ARGB]]: memref<10xf32>, [[ARGC]]: memref<10x10xf32>) {
499+
// CHECK: acc.data no_create([[ARGA]], [[ARGB]], [[ARGC]] : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) {
500500
// CHECK-NEXT: }
501-
// CHECK: acc.data attach([[ARGA]]: memref<10xf32>, [[ARGB]]: memref<10xf32>, [[ARGC]]: memref<10x10xf32>) {
501+
// CHECK: acc.data attach([[ARGA]], [[ARGB]], [[ARGC]] : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) {
502502
// CHECK-NEXT: }
503-
// CHECK: acc.data present([[ARGA]]: memref<10xf32>) copyin([[ARGB]]: memref<10xf32>) copyout([[ARGC]]: memref<10x10xf32>) {
503+
// CHECK: acc.data copyin([[ARGB]] : memref<10xf32>) copyout([[ARGC]] : memref<10x10xf32>) present([[ARGA]] : memref<10xf32>) {
504504
// CHECK-NEXT: }

0 commit comments

Comments
 (0)