Skip to content

[flang][OpenMP] Further handling of target ... do fixup logic #115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions flang/lib/Lower/OpenMP/OpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,20 @@ class HostClausesInsertionGuard {

mlir::IRMapping mapper;
builder.setInsertionPoint(escapingOperand->getOwner());
mlir::Operation *lastSliceOp;
mlir::Operation *lastSliceOp = nullptr;

for (auto *op : backwardSlice) {
// DeclareOps need special handling by searching for the corresponding ops
// in the host. Therefore, do not clone them since this special handling
// is done later in the fix-up process.
//
// TODO this might need a more elaborate handling in the future but for
// now this seems sufficient for our purposes.
if (llvm::isa<hlfir::DeclareOp>(op))
break;

for (auto *op : backwardSlice)
lastSliceOp = builder.clone(*op, mapper);
}

builder.restoreInsertionPoint(ip);
return lastSliceOp;
Expand All @@ -201,6 +211,9 @@ class HostClausesInsertionGuard {
"a block argument)");
mlir::Operation *lastSliceOp = cloneOperandSliceOutsideTargetOp(operand);

if (lastSliceOp == nullptr)
continue;

// Find the index of the operand in the list of results produced by its
// defining op.
unsigned operandResultIdx = 0;
Expand Down
29 changes: 29 additions & 0 deletions flang/test/Lower/OpenMP/target-do-loop-control-exprs.f90
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,32 @@ subroutine foo(upper_bound)
! CHECK: omp.target

! CHECK: }

subroutine foo_with_dummy_arg(nodes)
implicit none
integer, intent(inout) :: nodes( : )
integer :: i

!$omp target teams distribute parallel do
do i = 1, ubound(nodes, 1)
nodes(i) = i
end do
!$omp end target teams distribute parallel do
end subroutine

! CHECK: func.func @_QPfoo_with_dummy_arg(%[[FUNC_ARG:.*]]: !fir.box<!fir.array<?xi32>> {fir.bindc_name = "nodes"}) {

! CHECK: %[[ARR_DECL:.*]]:2 = hlfir.declare %[[FUNC_ARG]] dummy_scope

! CHECK: omp.map.info
! CHECK: omp.map.info
! CHECK: omp.map.info

! Verify that we get the box dims of the host array declaration not the target
! one.

! CHECK: fir.box_dims %[[ARR_DECL]]

! CHECK: omp.target

! CHECK: }