forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 16
[flang][OpenMP] Parallel region codegen support #424
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,118 @@ | ||
! This test checks lowering of OpenMP parallel Directive with arbitrary code | ||
! inside it. | ||
|
||
! RUN: bbc -fopenmp -emit-fir %s -o - | \ | ||
! RUN: FileCheck %s --check-prefix=FIRDialect | ||
! RUN: bbc -fopenmp -emit-llvm %s -o - | \ | ||
! RUN: FileCheck %s --check-prefix=LLVMIRDialect | ||
! RUN: bbc -fopenmp -emit-fir %s -o - | \ | ||
! RUN: tco | FileCheck %s --check-prefix=LLVMIR | ||
|
||
program parallel | ||
|
||
integer :: a,b,c | ||
integer :: num_threads | ||
|
||
a = 1 | ||
b = 2 | ||
!FIRDialect: %[[VAR_A:.*]] = fir.alloca i32 {name = "a"} | ||
!FIRDialect: %[[VAR_B:.*]] = fir.alloca i32 {name = "b"} | ||
!FIRDialect: %[[VAR_C:.*]] = fir.alloca i32 {name = "c"} | ||
!FIRDialect: %[[VAR_NUM_THREADS:.*]] = fir.alloca i32 {name = "num_threads"} | ||
|
||
!LLVMIRDialect: %[[VAR_A:.*]] = llvm.alloca %{{.*}} x !llvm.i32 {in_type = i32, name = "a"} | ||
!LLVMIRDialect: %[[VAR_B:.*]] = llvm.alloca %{{.*}} x !llvm.i32 {in_type = i32, name = "b"} | ||
!LLVMIRDialect: %[[VAR_C:.*]] = llvm.alloca %{{.*}} x !llvm.i32 {in_type = i32, name = "c"} | ||
!LLVMIRDialect: %[[VAR_NUM_THREADS:.*]] = llvm.alloca %{{.*}} x !llvm.i32 {in_type = i32, name = "num_threads"} | ||
|
||
!LLVMIR: %[[OMP_GLOBAL_THREAD_NUM:.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @{{.*}}) | ||
!LLVMIR: call void @__kmpc_push_num_threads(%struct.ident_t* @{{.*}}, i32 %[[OMP_GLOBAL_THREAD_NUM]], i32 %{{.*}}) | ||
|
||
!$OMP PARALLEL NUM_THREADS(num_threads) | ||
!FIRDialect: omp.parallel num_threads(%{{.*}} : i32) { | ||
!FIRDialect-DAG: %[[OMP_VAR_A:.*]] = fir.load %[[VAR_A]] | ||
!FIRDialect-DAG: %[[OMP_VAR_B:.*]] = fir.load %[[VAR_B]] | ||
!FIRDialect: %[[OMP_VAR_C:.*]] = addi %[[OMP_VAR_A]], %[[OMP_VAR_B]] | ||
!FIRDialect: fir.store %[[OMP_VAR_C]] to %[[VAR_C]] | ||
!FIRDialect: %[[CONSTANT:.*]] = constant 4 : i32 | ||
!FIRDialect: %[[COND_C:.*]] = fir.load %[[VAR_C]] : !fir.ref<i32> | ||
!FIRDialect: %[[COND_RES:.*]] = cmpi "sgt", %[[COND_C]], %[[CONSTANT]] : i32 | ||
!FIRDialect: fir.if %[[COND_RES]] { | ||
!FIRDialect: fir.call @_FortranAioBeginExternalListOutput | ||
!FIRDialect: fir.call @_FortranAioOutputAscii | ||
!FIRDialect: fir.call @_FortranAioEndIoStatement | ||
!FIRDialect: } else { | ||
!FIRDialect-NEXT: } | ||
!FIRDialect: fir.call @_FortranAioBeginExternalListOutput | ||
!FIRDialect: fir.load %[[VAR_C]] | ||
!FIRDialect: fir.call @_FortranAioOutputInteger64 | ||
!FIRDialect: fir.call @_FortranAioEndIoStatement | ||
!FIRDialect: omp.terminator | ||
!FIRDialect-NEXT: } | ||
|
||
!LLVMIRDialect-LABEL: omp.parallel num_threads(%{{.*}} : !llvm.i32) { | ||
!LLVMIRDialect-DAG: %[[OMP_VAR_A:.*]] = llvm.load %[[VAR_A:.*]] | ||
!LLVMIRDialect-DAG: %[[OMP_VAR_B:.*]] = llvm.load %[[VAR_B:.*]] | ||
!LLVMIRDialect: %[[OMP_VAR_C:.*]] = llvm.add %[[OMP_VAR_B]], %[[OMP_VAR_A]] | ||
!LLVMIRDialect: llvm.store %[[OMP_VAR_C]], %[[VAR_C]] | ||
!LLVMIRDialect: %[[COND_C:.*]] = llvm.load %[[VAR_C]] : !llvm.ptr<i32> | ||
!LLVMIRDialect: %[[COND_RES:.*]] = llvm.icmp "sgt" %[[COND_C]], %{{.*}} : !llvm.i32 | ||
!LLVMIRDialect: llvm.cond_br %[[COND_RES]], ^bb1, ^bb2 | ||
!LLVMIRDialect: ^bb1: // pred: ^bb0 | ||
!LLVMIRDialect: llvm.call @_FortranAioBeginExternalListOutput | ||
!LLVMIRDialect: llvm.call @_FortranAioOutputAscii | ||
!LLVMIRDialect: llvm.call @_FortranAioEndIoStatement | ||
!LLVMIRDialect: llvm.br ^bb2 | ||
!LLVMIRDialect: ^bb2: // 2 preds: ^bb0, ^bb1 | ||
!LLVMIRDialect: llvm.call @_FortranAioBeginExternalListOutput | ||
!LLVMIRDialect: llvm.load %[[VAR_C]] : !llvm.ptr<i32> | ||
!LLVMIRDialect: llvm.call @_FortranAioOutputInteger64 | ||
!LLVMIRDialect: llvm.call @_FortranAioEndIoStatement | ||
!LLVMIRDialect: omp.terminator | ||
!LLVMIRDialect-NEXT: } | ||
|
||
!LLVMIR: call {{.*}} @__kmpc_fork_call(%struct.ident_t* @{{.*}} @_QQmain..omp_par | ||
|
||
!LLVMIR-LABEL: define internal void @_QQmain..omp_par | ||
!LLVMIR: br label %[[REGION_1:.*]] | ||
!LLVMIR: [[REGION_1]]: | ||
!LLVMIR: br label %[[REGION_1_1:.*]] | ||
!LLVMIR: [[REGION_1_1]]: | ||
!LLVMIR: %[[COND_RES:.*]] = icmp sgt i32 %{{.*}}, 4 | ||
!LLVMIR: br i1 %[[COND_RES]], label %{{.*}}, label %{{.*}} | ||
!LLVMIR: call i8* @_FortranAioBeginExternalListOutput | ||
!LLVMIR: call i1 @_FortranAioOutputInteger64 | ||
!LLVMIR: call i32 @_FortranAioEndIoStatement | ||
c = a + b | ||
|
||
if (c .gt. 4) then | ||
print*, "Inside If Statement" | ||
endif | ||
|
||
print*, c | ||
|
||
!$OMP END PARALLEL | ||
|
||
!$OMP PARALLEL | ||
print*, "Second Region" | ||
!FIRDialect: omp.parallel { | ||
!FIRDialect: fir.call @_FortranAioBeginExternalListOutput | ||
!FIRDialect: fir.call @_FortranAioOutputAscii | ||
!FIRDialect: fir.call @_FortranAioEndIoStatement | ||
!FIRDialect: omp.terminator | ||
!FIRDialect-NEXT: } | ||
|
||
!LLVMIRDialect: omp.parallel { | ||
!LLVMIRDialect: llvm.call @_FortranAioBeginExternalListOutput | ||
!LLVMIRDialect: llvm.call @_FortranAioOutputAscii | ||
!LLVMIRDialect: llvm.call @_FortranAioEndIoStatement | ||
!LLVMIRDialect: omp.terminator | ||
!LLVMIRDialect: } | ||
|
||
!LLVMIR-DAG-LABEL: call {{.*}} @__kmpc_fork_call(%struct.ident_t* @{{.*}} @_QQmain..omp_par.1 | ||
!LLVMIR-DAG-LABEL: define internal void @_QQmain..omp_par.1 | ||
!LLVMIR: call i8* @_FortranAioBeginExternalListOutput | ||
!LLVMIR: call i32 @_FortranAioEndIoStatement | ||
!$OMP END PARALLEL | ||
|
||
end program |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add more tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure will take care of this in next revision.