forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Flang][OpenMP] Fixes for unstructured OpenMP code
Since the FIR operations are mostly structured, it is only the functions that could contain multiple blocks inside an operation. This changes with OpenMP since OpenMP regions can contain multiple blocks. For unstructured code, the blocks are created in advance and belong to the top-level function. This caused code in OpenMP region to be placed under the function level. In this fix, if the OpenMP region is unstructured then new blocks are created inside it. Note1: This is part of upstreaming from the fir-dev branch of https://github.com/flang-compiler/f18-llvm-project. The code in this patch is a subset of the changes in flang-compiler#1178. Reviewed By: vdonaldson Differential Revision: https://reviews.llvm.org/D126293 Co-authored-by: Val Donaldson <[email protected]> Co-authored-by: Eric Schweitz <[email protected]> Co-authored-by: Valentin Clement <[email protected]>
- Loading branch information
1 parent
0bf3c38
commit 29f167a
Showing
2 changed files
with
159 additions
and
17 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,113 @@ | ||
! Test unstructured code adjacent to and inside OpenMP constructs. | ||
|
||
! RUN: bbc %s -fopenmp -o "-" | FileCheck %s | ||
|
||
! CHECK-LABEL: func @_QPss1{{.*}} { | ||
! CHECK: br ^bb1 | ||
! CHECK: ^bb1: // 2 preds: ^bb0, ^bb3 | ||
! CHECK: cond_br %{{[0-9]*}}, ^bb2, ^bb4 | ||
! CHECK: ^bb2: // pred: ^bb1 | ||
! CHECK: cond_br %{{[0-9]*}}, ^bb4, ^bb3 | ||
! CHECK: ^bb3: // pred: ^bb2 | ||
! CHECK: @_FortranAioBeginExternalListOutput | ||
! CHECK: br ^bb1 | ||
! CHECK: ^bb4: // 2 preds: ^bb1, ^bb2 | ||
! CHECK: omp.master { | ||
! CHECK: @_FortranAioBeginExternalListOutput | ||
! CHECK: omp.terminator | ||
! CHECK: } | ||
! CHECK: @_FortranAioBeginExternalListOutput | ||
! CHECK: } | ||
subroutine ss1(n) ! unstructured code followed by a structured OpenMP construct | ||
do i = 1, 3 | ||
if (i .eq. n) exit | ||
print*, 'ss1-A', i | ||
enddo | ||
!$omp master | ||
print*, 'ss1-B', i | ||
!$omp end master | ||
print* | ||
end | ||
|
||
! CHECK-LABEL: func @_QPss2{{.*}} { | ||
! CHECK: omp.master { | ||
! CHECK: @_FortranAioBeginExternalListOutput | ||
! CHECK: br ^bb1 | ||
! CHECK: ^bb1: // 2 preds: ^bb0, ^bb3 | ||
! CHECK: cond_br %{{[0-9]*}}, ^bb2, ^bb4 | ||
! CHECK: ^bb2: // pred: ^bb1 | ||
! CHECK: cond_br %{{[0-9]*}}, ^bb4, ^bb3 | ||
! CHECK: ^bb3: // pred: ^bb2 | ||
! CHECK: @_FortranAioBeginExternalListOutput | ||
! CHECK: br ^bb1 | ||
! CHECK: ^bb4: // 2 preds: ^bb1, ^bb2 | ||
! CHECK: omp.terminator | ||
! CHECK: } | ||
! CHECK: @_FortranAioBeginExternalListOutput | ||
! CHECK: @_FortranAioBeginExternalListOutput | ||
! CHECK: } | ||
subroutine ss2(n) ! unstructured OpenMP construct; loop exit inside construct | ||
!$omp master | ||
print*, 'ss2-A', n | ||
do i = 1, 3 | ||
if (i .eq. n) exit | ||
print*, 'ss2-B', i | ||
enddo | ||
!$omp end master | ||
print*, 'ss2-C', i | ||
print* | ||
end | ||
|
||
! CHECK-LABEL: func @_QPss3{{.*}} { | ||
! CHECK: omp.parallel { | ||
! CHECK: br ^bb1 | ||
! CHECK: ^bb1: // 2 preds: ^bb0, ^bb2 | ||
! CHECK: cond_br %{{[0-9]*}}, ^bb2, ^bb3 | ||
! CHECK: ^bb2: // pred: ^bb1 | ||
! CHECK: omp.wsloop {{.*}} { | ||
! CHECK: @_FortranAioBeginExternalListOutput | ||
! CHECK: omp.yield | ||
! CHECK: } | ||
! CHECK: omp.wsloop {{.*}} { | ||
! CHECK: br ^bb1 | ||
! CHECK: ^bb1: // 2 preds: ^bb0, ^bb3 | ||
! CHECK: cond_br %{{[0-9]*}}, ^bb2, ^bb4 | ||
! CHECK: ^bb2: // pred: ^bb1 | ||
! CHECK: cond_br %{{[0-9]*}}, ^bb4, ^bb3 | ||
! CHECK: ^bb3: // pred: ^bb2 | ||
! CHECK: @_FortranAioBeginExternalListOutput | ||
! CHECK: br ^bb1 | ||
! CHECK: ^bb4: // 2 preds: ^bb1, ^bb2 | ||
! CHECK: omp.yield | ||
! CHECK: } | ||
! CHECK: br ^bb1 | ||
! CHECK: ^bb3: // pred: ^bb1 | ||
! CHECK: omp.terminator | ||
! CHECK: } | ||
! CHECK: } | ||
subroutine ss3(n) ! nested unstructured OpenMP constructs | ||
!$omp parallel | ||
do i = 1, 3 | ||
!$omp do | ||
do k = 1, 3 | ||
print*, 'ss3-A', k | ||
enddo | ||
!$omp end do | ||
!$omp do | ||
do j = 1, 3 | ||
do k = 1, 3 | ||
if (k .eq. n) exit | ||
print*, 'ss3-B', k | ||
enddo | ||
enddo | ||
!$omp end do | ||
enddo | ||
!$omp end parallel | ||
end | ||
|
||
! CHECK-LABEL: func @_QQmain | ||
program p | ||
call ss1(2) | ||
call ss2(2) | ||
call ss3(2) | ||
end |