Skip to content

Commit fa08afc

Browse files
committed
[mlir][openacc] Add if, deviceptr operands and default attribute
Add operands to represent if and deviceptr. Default clause is represented with an attribute. Reviewed By: kiranchandramohan Differential Revision: https://reviews.llvm.org/D88331
1 parent 12ab4f8 commit fa08afc

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,19 @@ def OpenACC_ReductionOpAttr : StrEnumAttr<"ReductionOpAttr",
6363
// Type used in operation below.
6464
def IntOrIndex : AnyTypeOf<[AnyInteger, Index]>;
6565

66-
//===----------------------------------------------------------------------===//
67-
// 2.5.1 parallel Construct
68-
//===----------------------------------------------------------------------===//
69-
70-
// Parallel op default enumeration
66+
// Parallel and data op default enumeration
7167
def OpenACC_DefaultNone : StrEnumAttrCase<"none">;
7268
def OpenACC_DefaultPresent : StrEnumAttrCase<"present">;
7369
def OpenACC_DefaultAttr : StrEnumAttr<"DefaultAttr",
74-
"default attribute value for parallel op",
70+
"default attribute values",
7571
[OpenACC_DefaultNone, OpenACC_DefaultPresent]> {
7672
let cppNamespace = "::mlir::acc";
7773
}
7874

75+
//===----------------------------------------------------------------------===//
76+
// 2.5.1 parallel Construct
77+
//===----------------------------------------------------------------------===//
78+
7979
def OpenACC_ParallelOp : OpenACC_Op<"parallel",
8080
[AttrSizedOperandSegments]> {
8181
let summary = "parallel construct";
@@ -178,7 +178,8 @@ def OpenACC_DataOp : OpenACC_Op<"data",
178178
}];
179179

180180

181-
let arguments = (ins Variadic<AnyType>:$copyOperands,
181+
let arguments = (ins Optional<I1>:$ifCond,
182+
Variadic<AnyType>:$copyOperands,
182183
Variadic<AnyType>:$copyinOperands,
183184
Variadic<AnyType>:$copyinReadonlyOperands,
184185
Variadic<AnyType>:$copyoutOperands,
@@ -187,11 +188,14 @@ def OpenACC_DataOp : OpenACC_Op<"data",
187188
Variadic<AnyType>:$createZeroOperands,
188189
Variadic<AnyType>:$noCreateOperands,
189190
Variadic<AnyType>:$presentOperands,
190-
Variadic<AnyType>:$attachOperands);
191+
Variadic<AnyType>:$deviceptrOperands,
192+
Variadic<AnyType>:$attachOperands,
193+
OptionalAttr<OpenACC_DefaultAttr>:$defaultAttr);
191194

192195
let regions = (region AnyRegion:$region);
193196

194197
let assemblyFormat = [{
198+
( `if` `(` $ifCond^ `)` )?
195199
( `copy` `(` $copyOperands^ `:` type($copyOperands) `)` )?
196200
( `copyin` `(` $copyinOperands^ `:` type($copyinOperands) `)` )?
197201
( `copyin_readonly` `(` $copyinReadonlyOperands^ `:`
@@ -204,6 +208,7 @@ def OpenACC_DataOp : OpenACC_Op<"data",
204208
type($createZeroOperands) `)` )?
205209
( `no_create` `(` $noCreateOperands^ `:` type($noCreateOperands) `)` )?
206210
( `present` `(` $presentOperands^ `:` type($presentOperands) `)` )?
211+
( `deviceptr` `(` $deviceptrOperands^ `:` type($deviceptrOperands) `)` )?
207212
( `attach` `(` $attachOperands^ `:` type($attachOperands) `)` )?
208213
$region attr-dict-with-keyword
209214
}];

mlir/test/Dialect/OpenACC/ops.mlir

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,9 @@ 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+
%ifCond = constant true
458+
acc.data if(%ifCond) present(%a : memref<10xf32>) {
459+
}
457460
acc.data present(%a, %b, %c : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) {
458461
}
459462
acc.data copy(%a, %b, %c : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) {
@@ -472,14 +475,23 @@ func @testdataop(%a: memref<10xf32>, %b: memref<10xf32>, %c: memref<10x10xf32>)
472475
}
473476
acc.data no_create(%a, %b, %c : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) {
474477
}
478+
acc.data deviceptr(%a, %b, %c : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) {
479+
}
475480
acc.data attach(%a, %b, %c : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) {
476481
}
477482
acc.data copyin(%b: memref<10xf32>) copyout(%c: memref<10x10xf32>) present(%a: memref<10xf32>) {
478483
}
484+
acc.data present(%a : memref<10xf32>) {
485+
} attributes { defaultAttr = "none" }
486+
acc.data present(%a : memref<10xf32>) {
487+
} attributes { defaultAttr = "present" }
479488
return
480489
}
481490

482491
// CHECK: func @testdataop([[ARGA:%.*]]: memref<10xf32>, [[ARGB:%.*]]: memref<10xf32>, [[ARGC:%.*]]: memref<10x10xf32>) {
492+
// CHECK: [[IFCOND1:%.*]] = constant true
493+
// CHECK: acc.data if([[IFCOND1]]) present([[ARGA]] : memref<10xf32>) {
494+
// CHECK-NEXT: }
483495
// CHECK: acc.data present([[ARGA]], [[ARGB]], [[ARGC]] : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) {
484496
// CHECK-NEXT: }
485497
// CHECK: acc.data copy([[ARGA]], [[ARGB]], [[ARGC]] : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) {
@@ -498,7 +510,13 @@ func @testdataop(%a: memref<10xf32>, %b: memref<10xf32>, %c: memref<10x10xf32>)
498510
// CHECK-NEXT: }
499511
// CHECK: acc.data no_create([[ARGA]], [[ARGB]], [[ARGC]] : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) {
500512
// CHECK-NEXT: }
513+
// CHECK: acc.data deviceptr([[ARGA]], [[ARGB]], [[ARGC]] : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) {
514+
// CHECK-NEXT: }
501515
// CHECK: acc.data attach([[ARGA]], [[ARGB]], [[ARGC]] : memref<10xf32>, memref<10xf32>, memref<10x10xf32>) {
502516
// CHECK-NEXT: }
503517
// CHECK: acc.data copyin([[ARGB]] : memref<10xf32>) copyout([[ARGC]] : memref<10x10xf32>) present([[ARGA]] : memref<10xf32>) {
504518
// CHECK-NEXT: }
519+
// CHECK: acc.data present([[ARGA]] : memref<10xf32>) {
520+
// CHECK-NEXT: } attributes {defaultAttr = "none"}
521+
// CHECK: acc.data present([[ARGA]] : memref<10xf32>) {
522+
// CHECK-NEXT: } attributes {defaultAttr = "present"}

0 commit comments

Comments
 (0)