forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[flang][OpenMP] Implement more robust loop-nest detection logic
The previous loop-nest detection algorithm fell short, in some cases, to detect whether a pair of `do concurrent` loops are perfectly nested or not. This is a re-implementation using forward and backward slice extraction algorithms to compare the set of ops required to setup the inner loop bounds vs. the set of ops nested in the outer loop other thatn the nested loop itself.
- Loading branch information
Showing
2 changed files
with
209 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
! Tests loop-nest detection algorithm for do-concurrent mapping. | ||
|
||
! RUN: %flang_fc1 -emit-hlfir -fopenmp -fdo-concurrent-parallel=host \ | ||
! RUN: -mmlir -debug %s -o - &> %t.log || true | ||
|
||
! RUN: FileCheck %s < %t.log | ||
|
||
program main | ||
implicit none | ||
|
||
contains | ||
|
||
subroutine foo(n) | ||
implicit none | ||
integer :: n, m | ||
integer :: i, j, k | ||
integer :: x | ||
integer, dimension(n) :: a | ||
integer, dimension(n, n, n) :: b | ||
|
||
! CHECK: Loop pair starting at location loc("{{.*}}":[[# @LINE + 2]]:{{.*}}) | ||
! CHECK-SAME: is perfectly nested | ||
do concurrent(i=1:n, j=1:bar(n*m, n/m)) | ||
a(i) = n | ||
end do | ||
|
||
! CHECK: Loop pair starting at location loc("{{.*}}":[[# @LINE + 2]]:{{.*}}) | ||
! CHECK-SAME: is perfectly nested | ||
do concurrent(i=bar(n, x):n, j=1:bar(n*m, n/m)) | ||
a(i) = n | ||
end do | ||
|
||
! CHECK: Loop pair starting at location loc("{{.*}}":[[# @LINE + 2]]:{{.*}}) | ||
! CHECK-SAME: is perfectly nested | ||
do concurrent(i=bar(n, x):n) | ||
do concurrent(j=1:bar(n*m, n/m)) | ||
a(i) = n | ||
end do | ||
end do | ||
|
||
! CHECK: Loop pair starting at location loc("{{.*}}":[[# @LINE + 2]]:{{.*}}) | ||
! CHECK-SAME: is not perfectly nested | ||
do concurrent(i=1:n) | ||
x = 10 | ||
do concurrent(j=1:m) | ||
b(i,j,k) = i * j + k | ||
end do | ||
end do | ||
|
||
! CHECK: Loop pair starting at location loc("{{.*}}":[[# @LINE + 2]]:{{.*}}) | ||
! CHECK-SAME: is not perfectly nested | ||
do concurrent(i=1:n) | ||
do concurrent(j=1:m) | ||
b(i,j,k) = i * j + k | ||
end do | ||
x = 10 | ||
end do | ||
|
||
! CHECK: Loop pair starting at location loc("{{.*}}":[[# @LINE + 2]]:{{.*}}) | ||
! CHECK-SAME: is perfectly nested | ||
do concurrent(i=1:n) | ||
do concurrent(j=1:m) | ||
b(i,j,k) = i * j + k | ||
x = 10 | ||
end do | ||
end do | ||
end subroutine | ||
|
||
pure function bar(n, m) | ||
implicit none | ||
integer, intent(in) :: n, m | ||
integer :: bar | ||
|
||
bar = n + m | ||
end function | ||
|
||
end program main |