[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
This commit is contained in:
Valentin Clement 2020-09-27 21:20:35 -04:00 committed by clementval
parent 3d2bab176f
commit 12ab4f8aca
3 changed files with 41 additions and 185 deletions

View File

@ -178,8 +178,7 @@ def OpenACC_DataOp : OpenACC_Op<"data",
}];
let arguments = (ins Variadic<AnyType>:$presentOperands,
Variadic<AnyType>:$copyOperands,
let arguments = (ins Variadic<AnyType>:$copyOperands,
Variadic<AnyType>:$copyinOperands,
Variadic<AnyType>:$copyinReadonlyOperands,
Variadic<AnyType>:$copyoutOperands,
@ -187,21 +186,26 @@ def OpenACC_DataOp : OpenACC_Op<"data",
Variadic<AnyType>:$createOperands,
Variadic<AnyType>:$createZeroOperands,
Variadic<AnyType>:$noCreateOperands,
Variadic<AnyType>:$presentOperands,
Variadic<AnyType>:$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 = ?;

View File

@ -444,154 +444,6 @@ static void print(OpAsmPrinter &printer, ParallelOp &op) {
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<OpAsmParser::OperandType, 2> presentOperands, copyOperands,
copyinOperands, copyinReadonlyOperands, copyoutOperands,
copyoutZeroOperands, createOperands, createZeroOperands, noCreateOperands,
attachOperands;
SmallVector<Type, 2> 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<ParallelOp>(parser, result)))
return failure();
result.addAttribute(ParallelOp::getOperandSegmentSizeAttr(),
builder.getI32VectorAttr(
{static_cast<int32_t>(presentOperands.size()),
static_cast<int32_t>(copyOperands.size()),
static_cast<int32_t>(copyinOperands.size()),
static_cast<int32_t>(copyinReadonlyOperands.size()),
static_cast<int32_t>(copyoutOperands.size()),
static_cast<int32_t>(copyoutZeroOperands.size()),
static_cast<int32_t>(createOperands.size()),
static_cast<int32_t>(createZeroOperands.size()),
static_cast<int32_t>(noCreateOperands.size()),
static_cast<int32_t>(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
//===----------------------------------------------------------------------===//

View File

@ -121,7 +121,7 @@ func @compute3(%a: memref<10x10xf32>, %b: memref<10x10xf32>, %c: memref<10xf32>,
%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 @@ func @compute3(%a: memref<10x10xf32>, %b: memref<10x10xf32>, %c: memref<10xf32>,
// 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 @testparallelop(%a: memref<10xf32>, %b: memref<10xf32>, %c: memref<10x10xf3
// -----
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: }