Skip to content

Commit 23e7c7d

Browse files
committed
Handle review comments.
1 parent f4ad640 commit 23e7c7d

File tree

4 files changed

+52
-50
lines changed

4 files changed

+52
-50
lines changed

mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -153,31 +153,28 @@ def DataSharingClauseTypeAttr : EnumAttr<
153153
let assemblyFormat = "`{` `type` `=` $value `}`";
154154
}
155155

156-
def PrivateClauseOp : OpenMP_Op<"private", [
157-
IsolatedFromAbove
158-
]> {
159-
let summary = "Outline [first]private logic in a separate op.";
156+
def PrivateClauseOp : OpenMP_Op<"private", [IsolatedFromAbove]> {
157+
let summary = "Provides declaration of [first]private logic.";
160158
let description = [{
161-
Using this operation, the dialect can model the data-sharing attributes of
162-
`private` and `firstprivate` variables on the IR level. This means that of
163-
"eagerly" privatizing variables in the frontend, we can instead model which
164-
variables should be privatized and only materialze the privatization when
165-
necessary; e.g. directly before lowering to LLVM IR.
159+
This operation provides a declaration of how to implement the
160+
[first]privatization of a variable. The dialect users should provide
161+
information about how to create an instance of the type in the alloc region
162+
and how to initialize the copy from the original item in the copy region.
166163

167164
Examples:
168165
---------
169166
* `private(x)` would be emitted as:
170167
```mlir
171-
omp.private {type = private} @x.privatizer : !fir.ref<i32> (alloc {
168+
omp.private {type = private} @x.privatizer : !fir.ref<i32> alloc {
172169
^bb0(%arg0: !fir.ref<i32>):
173170
%0 = ... allocate proper memory for the private clone ...
174171
omp.yield(%0 : !fir.ref<i32>)
175-
})
172+
}
176173
```
177174

178175
* `firstprivate(x)` would be emitted as:
179176
```mlir
180-
omp.private {type = firstprivate} @y.privatizer : !fir.ref<i32> (alloc {
177+
omp.private {type = firstprivate} @y.privatizer : !fir.ref<i32> alloc {
181178
^bb0(%arg0: !fir.ref<i32>):
182179
%0 = ... allocate proper memory for the private clone ...
183180
omp.yield(%0 : !fir.ref<i32>)
@@ -187,35 +184,40 @@ def PrivateClauseOp : OpenMP_Op<"private", [
187184
// %arg1 represents the memory allocated in `alloc`.
188185
... copy from host to the privatized clone ....
189186
omp.yield(%arg1 : !fir.ref<i32>)
190-
})
187+
}
191188
```
192189

193-
However, the body of the `omp.private` op really depends on the code-gen
194-
done by the emitting frontend. There are no restrictions on the body except
195-
for:
190+
There are no restrictions on the body except for:
196191
- The `alloc` region has a single argument.
197192
- The `copy` region has 2 arguments.
198-
- Both regions are existed by `omp.yield` ops.
193+
- Both regions are terminated by `omp.yield` ops.
199194
The above restrictions and other obvious restrictions (e.g. verifying the
200195
type of yielded values) are verified by the custom op verifier. The actual
201196
contents of the blocks inside both regions are not verified.
202197

203198
Instances of this op would then be used by ops that model directives that
204199
accept data-sharing attribute clauses.
200+
201+
The $sym_name attribute provides a symbol by which the privatizer op can be
202+
referenced by other dialect ops.
203+
204+
The $type attribute is the type of the value being privatized.
205+
206+
The $data_sharing_type attribute specifies whether privatizer corresponds
207+
to a `private` or a `firstprivate` clause.
205208
}];
206209

207210
let arguments = (ins SymbolNameAttr:$sym_name,
208-
TypeAttrOf<AnyType>:$sym_type,
211+
TypeAttrOf<AnyType>:$type,
209212
DataSharingClauseTypeAttr:$data_sharing_type);
210213

211214
let regions = (region MinSizedRegion<1>:$alloc_region,
212215
AnyRegion:$copy_region);
213216

214217
let assemblyFormat = [{
215-
$data_sharing_type $sym_name `:` $sym_type `(`
218+
$data_sharing_type $sym_name `:` $type
216219
`alloc` $alloc_region
217220
(`copy` $copy_region^)?
218-
`)`
219221
attr-dict
220222
}];
221223

mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1595,7 +1595,7 @@ LogicalResult DataBoundsOp::verify() {
15951595
}
15961596

15971597
LogicalResult PrivateClauseOp::verify() {
1598-
Type symType = getSymType();
1598+
Type symType = getType();
15991599

16001600
auto verifyTerminator = [&](Operation *terminator) -> LogicalResult {
16011601
if (!terminator->hasSuccessors() && !llvm::isa<YieldOp>(terminator))

mlir/test/Dialect/OpenMP/invalid.mlir

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1741,70 +1741,70 @@ func.func @omp_distribute(%data_var : memref<i32>) -> () {
17411741

17421742
// -----
17431743

1744-
omp.private {type = private} @x.privatizer : i32 (alloc {
1744+
omp.private {type = private} @x.privatizer : i32 alloc {
17451745
^bb0(%arg0: i32):
17461746
%0 = arith.constant 0.0 : f32
17471747
// expected-error @below {{Invalid yielded value. Expected type: 'i32', got: 'f32'}}
17481748
omp.yield(%0 : f32)
1749-
})
1749+
}
17501750

17511751
// -----
17521752

1753-
omp.private {type = private} @x.privatizer : i32 (alloc {
1753+
omp.private {type = private} @x.privatizer : i32 alloc {
17541754
^bb0(%arg0: i32):
17551755
// expected-error @below {{Invalid yielded value. Expected type: 'i32', got: None}}
17561756
omp.yield
1757-
})
1757+
}
17581758

17591759
// -----
17601760

17611761
// expected-error @below {{expected all blocks to have terminators.}}
1762-
omp.private {type = private} @x.privatizer : i32 (alloc {
1762+
omp.private {type = private} @x.privatizer : i32 alloc {
17631763
^bb0(%arg0: i32):
1764-
})
1764+
}
17651765

17661766
// -----
17671767

1768-
omp.private {type = private} @x.privatizer : i32 (alloc {
1768+
omp.private {type = private} @x.privatizer : i32 alloc {
17691769
^bb0(%arg0: i32):
17701770
// expected-error @below {{expected exit block terminator to be an `omp.yield` op.}}
17711771
omp.terminator
1772-
})
1772+
}
17731773

17741774
// -----
17751775

17761776
// expected-error @below {{`alloc`: expected 1 region arguments, got: 2}}
1777-
omp.private {type = private} @x.privatizer : f32 (alloc {
1777+
omp.private {type = private} @x.privatizer : f32 alloc {
17781778
^bb0(%arg0: f32, %arg1: f32):
17791779
omp.yield(%arg0 : f32)
1780-
})
1780+
}
17811781

17821782
// -----
17831783

17841784
// expected-error @below {{`copy`: expected 2 region arguments, got: 1}}
1785-
omp.private {type = firstprivate} @x.privatizer : f32 (alloc {
1785+
omp.private {type = firstprivate} @x.privatizer : f32 alloc {
17861786
^bb0(%arg0: f32):
17871787
omp.yield(%arg0 : f32)
17881788
} copy {
17891789
^bb0(%arg0: f32):
17901790
omp.yield(%arg0 : f32)
1791-
})
1791+
}
17921792

17931793
// -----
17941794

17951795
// expected-error @below {{`private` clauses require only an `alloc` region.}}
1796-
omp.private {type = private} @x.privatizer : f32 (alloc {
1796+
omp.private {type = private} @x.privatizer : f32 alloc {
17971797
^bb0(%arg0: f32):
17981798
omp.yield(%arg0 : f32)
17991799
} copy {
18001800
^bb0(%arg0: f32, %arg1 : f32):
18011801
omp.yield(%arg0 : f32)
1802-
})
1802+
}
18031803

18041804
// -----
18051805

18061806
// expected-error @below {{`firstprivate` clauses require both `alloc` and `copy` regions.}}
1807-
omp.private {type = firstprivate} @x.privatizer : f32 (alloc {
1807+
omp.private {type = firstprivate} @x.privatizer : f32 alloc {
18081808
^bb0(%arg0: f32):
18091809
omp.yield(%arg0 : f32)
1810-
})
1810+
}
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
// RUN: fir-opt -verify-diagnostics %s | fir-opt | FileCheck %s
1+
// RUN: mlir-opt -verify-diagnostics %s | mlir-opt | FileCheck %s
22

3-
// CHECK: omp.private {type = private} @x.privatizer : !fir.ref<i32>(alloc {
4-
omp.private {type = private} @x.privatizer : !fir.ref<i32> (alloc {
3+
// CHECK: omp.private {type = private} @x.privatizer : !llvm.ptr alloc {
4+
omp.private {type = private} @x.privatizer : !llvm.ptr alloc {
55
// CHECK: ^bb0(%arg0: {{.*}}):
6-
^bb0(%arg0: !fir.ref<i32>):
7-
omp.yield(%arg0 : !fir.ref<i32>)
8-
})
6+
^bb0(%arg0: !llvm.ptr):
7+
omp.yield(%arg0 : !llvm.ptr)
8+
}
99

10-
// CHECK: omp.private {type = firstprivate} @y.privatizer : !fir.ref<i32>(alloc {
11-
omp.private {type = firstprivate} @y.privatizer : !fir.ref<i32> (alloc {
10+
// CHECK: omp.private {type = firstprivate} @y.privatizer : !llvm.ptr alloc {
11+
omp.private {type = firstprivate} @y.privatizer : !llvm.ptr alloc {
1212
// CHECK: ^bb0(%arg0: {{.*}}):
13-
^bb0(%arg0: !fir.ref<i32>):
14-
omp.yield(%arg0 : !fir.ref<i32>)
13+
^bb0(%arg0: !llvm.ptr):
14+
omp.yield(%arg0 : !llvm.ptr)
1515
// CHECK: } copy {
1616
} copy {
1717
// CHECK: ^bb0(%arg0: {{.*}}, %arg1: {{.*}}):
18-
^bb0(%arg0: !fir.ref<i32>, %arg1: !fir.ref<i32>):
19-
omp.yield(%arg0 : !fir.ref<i32>)
20-
})
18+
^bb0(%arg0: !llvm.ptr, %arg1: !llvm.ptr):
19+
omp.yield(%arg0 : !llvm.ptr)
20+
}
2121

0 commit comments

Comments
 (0)