Skip to content

Commit 48ea3cc

Browse files
committed
convert yielded result
1 parent 49df027 commit 48ea3cc

File tree

4 files changed

+25
-24
lines changed

4 files changed

+25
-24
lines changed

flang/lib/Lower/OpenMP/DataSharingProcessor.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,6 @@ void DataSharingProcessor::doPrivatize(const semantics::Symbol *sym,
530530
fir::ExtendedValue symExV = converter.getSymbolExtendedValue(*sym);
531531

532532
symTable->pushScope();
533-
mlir::Type yieldedType;
534533

535534
// Populate the `alloc` region.
536535
{
@@ -550,10 +549,17 @@ void DataSharingProcessor::doPrivatize(const semantics::Symbol *sym,
550549
symTable->addSymbol(*sym, localExV);
551550
symTable->pushScope();
552551
cloneSymbol(sym);
552+
mlir::Value cloneAddr = symTable->shallowLookupSymbol(*sym).getAddr();
553+
mlir::Type cloneType = cloneAddr.getType();
554+
555+
mlir::Value yieldedValue =
556+
(symType == cloneType) ? cloneAddr
557+
: firOpBuilder.createConvert(
558+
cloneAddr.getLoc(), symType, cloneAddr);
559+
553560
auto yieldOp = firOpBuilder.create<mlir::omp::YieldOp>(
554-
hsb.getAddr().getLoc(),
555-
symTable->shallowLookupSymbol(*sym).getAddr());
556-
yieldedType = yieldOp.getOperand(0).getType();
561+
hsb.getAddr().getLoc(), yieldedValue);
562+
yieldOp.getOperand(0).getType();
557563
symTable->popScope();
558564
}
559565

@@ -562,9 +568,8 @@ void DataSharingProcessor::doPrivatize(const semantics::Symbol *sym,
562568
mlir::Region &copyRegion = result.getCopyRegion();
563569
// First block argument corresponding to the original/host value while
564570
// second block argument corresponding to the privatized value.
565-
mlir::Block *copyEntryBlock =
566-
firOpBuilder.createBlock(&copyRegion, /*insertPt=*/{},
567-
{symType, yieldedType}, {symLoc, symLoc});
571+
mlir::Block *copyEntryBlock = firOpBuilder.createBlock(
572+
&copyRegion, /*insertPt=*/{}, {symType, symType}, {symLoc, symLoc});
568573
firOpBuilder.setInsertionPointToEnd(copyEntryBlock);
569574

570575
auto addSymbol = [&](unsigned argIdx, bool force = false) {

flang/test/Lower/OpenMP/DelayedPrivatization/equivalence.f90

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ subroutine private_common
1717
! CHECK: ^bb0(%{{.*}}: ![[X_TYPE]]):
1818
! CHECK: %[[PRIV_ALLOC:.*]] = fir.alloca f32 {bindc_name = "x", {{.*}}}
1919
! CHECK: %[[PRIV_DECL:.*]]:2 = hlfir.declare %[[PRIV_ALLOC]] {{{.*}}} : (![[PRIV_TYPE:fir.ref<f32>]]) -> ({{.*}})
20-
! CHECK: omp.yield(%[[PRIV_DECL]]#0 : ![[PRIV_TYPE]])
20+
! CHECK: %[[PRIV_CONV:.*]] = fir.convert %[[PRIV_DECL]]#0 : (![[PRIV_TYPE]]) -> ![[X_TYPE]]
21+
! CHECK: omp.yield(%[[PRIV_CONV]] : ![[X_TYPE]])
2122
! CHECK: } copy {
22-
! CHECK: ^bb0(%[[ORIG_PTR:.*]]: ![[X_TYPE]], %[[PRIV_REF:.*]]: ![[PRIV_TYPE]]):
23+
! CHECK: ^bb0(%[[ORIG_PTR:.*]]: ![[X_TYPE]], %[[PRIV_REF:.*]]: ![[X_TYPE]]):
2324
! CHECK: %[[ORIG_VAL:.*]] = fir.load %[[ORIG_PTR]] : !fir.ptr<f32>
24-
! CHECK: hlfir.assign %[[ORIG_VAL]] to %[[PRIV_REF]] temporary_lhs : f32, ![[PRIV_TYPE]]
25-
! CHECK: omp.yield(%[[PRIV_REF]] : ![[PRIV_TYPE]])
25+
! CHECK: hlfir.assign %[[ORIG_VAL]] to %[[PRIV_REF]] temporary_lhs : f32, ![[X_TYPE]]
26+
! CHECK: omp.yield(%[[PRIV_REF]] : ![[X_TYPE]])
2627
! CHECK: }
2728

2829
! CHECK: func.func @_QPprivate_common() {

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2493,11 +2493,7 @@ LogicalResult PrivateClauseOp::verify() {
24932493
<< "Did not expect any values to be yielded.";
24942494
}
24952495

2496-
// TODO How can we check that 2 types are compatible without leaking
2497-
// dialect-specific (e.g. FIR) information? The problem is that in some
2498-
// cases, we would get the input type of the symbol as, e.g. `fir.ptr<i32>`
2499-
// while the allocated private memory is of type `fir.ref<i32>`.
2500-
if (yieldedTypes.size() == 1 /*&& yieldedTypes.front() == symType*/)
2496+
if (yieldedTypes.size() == 1 && yieldedTypes.front() == symType)
25012497
return success();
25022498

25032499
auto error = mlir::emitError(yieldOp.getLoc())

mlir/test/Dialect/OpenMP/invalid.mlir

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2207,14 +2207,13 @@ func.func @omp_distribute_unconstrained_order() -> () {
22072207
}
22082208
return
22092209
}
2210-
2211-
// Disabled for now. See relevant TODO in PrivateClauseOp::verify().
2212-
//omp.private {type = private} @x.privatizer : i32 alloc {
2213-
//^bb0(%arg0: i32):
2214-
// %0 = arith.constant 0.0 : f32
2215-
// // _expected-error_ @below {{Invalid yielded value. Expected type: 'i32', got: 'f32'}}
2216-
// omp.yield(%0 : f32)
2217-
//}
2210+
// -----
2211+
omp.private {type = private} @x.privatizer : i32 alloc {
2212+
^bb0(%arg0: i32):
2213+
%0 = arith.constant 0.0 : f32
2214+
// expected-error @below {{Invalid yielded value. Expected type: 'i32', got: 'f32'}}
2215+
omp.yield(%0 : f32)
2216+
}
22182217

22192218
// -----
22202219

0 commit comments

Comments
 (0)