-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Flang][MLIR] Add !$omp unroll
and omp.unroll_heuristic
#144785
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
Open
Meinersbur
wants to merge
1
commit into
main
Choose a base branch
from
users/meinersbur/flang_canonical-loop_unroll-heuristic
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
! RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=51 -o - %s 2>&1 | FileCheck %s | ||
|
||
|
||
subroutine omp_unroll_heuristic01(lb, ub, inc) | ||
integer res, i, lb, ub, inc | ||
|
||
!$omp unroll | ||
do i = lb, ub, inc | ||
res = i | ||
end do | ||
!$omp end unroll | ||
|
||
end subroutine omp_unroll_heuristic01 | ||
|
||
|
||
!CHECK-LABEL: func.func @_QPomp_unroll_heuristic01( | ||
!CHECK: %c0_i32 = arith.constant 0 : i32 | ||
!CHECK-NEXT: %c1_i32 = arith.constant 1 : i32 | ||
!CHECK-NEXT: %13 = arith.cmpi slt, %12, %c0_i32 : i32 | ||
!CHECK-NEXT: %14 = arith.subi %c0_i32, %12 : i32 | ||
!CHECK-NEXT: %15 = arith.select %13, %14, %12 : i32 | ||
!CHECK-NEXT: %16 = arith.select %13, %11, %10 : i32 | ||
!CHECK-NEXT: %17 = arith.select %13, %10, %11 : i32 | ||
!CHECK-NEXT: %18 = arith.subi %17, %16 overflow<nuw> : i32 | ||
!CHECK-NEXT: %19 = arith.divui %18, %15 : i32 | ||
!CHECK-NEXT: %20 = arith.addi %19, %c1_i32 overflow<nuw> : i32 | ||
!CHECK-NEXT: %21 = arith.cmpi slt, %17, %16 : i32 | ||
!CHECK-NEXT: %22 = arith.select %21, %c0_i32, %20 : i32 | ||
!CHECK-NEXT: %canonloop_s0 = omp.new_cli | ||
!CHECK-NEXT: omp.canonical_loop(%canonloop_s0) %iv : i32 in range(%22) { | ||
!CHECK-NEXT: %23 = arith.muli %iv, %12 : i32 | ||
!CHECK-NEXT: %24 = arith.addi %10, %23 : i32 | ||
!CHECK-NEXT: hlfir.assign %24 to %9#0 : i32, !fir.ref<i32> | ||
!CHECK-NEXT: %25 = fir.load %9#0 : !fir.ref<i32> | ||
!CHECK-NEXT: hlfir.assign %25 to %6#0 : i32, !fir.ref<i32> | ||
!CHECK-NEXT: omp.terminator | ||
!CHECK-NEXT: } | ||
!CHECK-NEXT: omp.unroll_heuristic(%canonloop_s0) | ||
!CHECK-NEXT: return |
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,70 @@ | ||
! RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=51 -o - %s 2>&1 | FileCheck %s | ||
|
||
|
||
subroutine omp_unroll_heuristic_nested02(outer_lb, outer_ub, outer_inc, inner_lb, inner_ub, inner_inc) | ||
integer res, i, j, inner_lb, inner_ub, inner_inc, outer_lb, outer_ub, outer_inc | ||
|
||
!$omp unroll | ||
do i = outer_lb, outer_ub, outer_inc | ||
!$omp unroll | ||
do j = inner_lb, inner_ub, inner_inc | ||
res = i + j | ||
end do | ||
!$omp end unroll | ||
end do | ||
!$omp end unroll | ||
|
||
end subroutine omp_unroll_heuristic_nested02 | ||
|
||
|
||
!CHECK-LABEL: func.func @_QPomp_unroll_heuristic_nested02(%arg0: !fir.ref<i32> {fir.bindc_name = "outer_lb"}, %arg1: !fir.ref<i32> {fir.bindc_name = "outer_ub"}, %arg2: !fir.ref<i32> {fir.bindc_name = "outer_inc"}, %arg3: !fir.ref<i32> {fir.bindc_name = "inner_lb"}, %arg4: !fir.ref<i32> {fir.bindc_name = "inner_ub"}, %arg5: !fir.ref<i32> {fir.bindc_name = "inner_inc"}) { | ||
!CHECK: %c0_i32 = arith.constant 0 : i32 | ||
!CHECK-NEXT: %c1_i32 = arith.constant 1 : i32 | ||
!CHECK-NEXT: %18 = arith.cmpi slt, %17, %c0_i32 : i32 | ||
!CHECK-NEXT: %19 = arith.subi %c0_i32, %17 : i32 | ||
!CHECK-NEXT: %20 = arith.select %18, %19, %17 : i32 | ||
!CHECK-NEXT: %21 = arith.select %18, %16, %15 : i32 | ||
!CHECK-NEXT: %22 = arith.select %18, %15, %16 : i32 | ||
!CHECK-NEXT: %23 = arith.subi %22, %21 overflow<nuw> : i32 | ||
!CHECK-NEXT: %24 = arith.divui %23, %20 : i32 | ||
!CHECK-NEXT: %25 = arith.addi %24, %c1_i32 overflow<nuw> : i32 | ||
!CHECK-NEXT: %26 = arith.cmpi slt, %22, %21 : i32 | ||
!CHECK-NEXT: %27 = arith.select %26, %c0_i32, %25 : i32 | ||
!CHECK-NEXT: %canonloop_s0 = omp.new_cli | ||
!CHECK-NEXT: omp.canonical_loop(%canonloop_s0) %iv : i32 in range(%27) { | ||
!CHECK-NEXT: %28 = arith.muli %iv, %17 : i32 | ||
!CHECK-NEXT: %29 = arith.addi %15, %28 : i32 | ||
!CHECK-NEXT: hlfir.assign %29 to %14#0 : i32, !fir.ref<i32> | ||
!CHECK-NEXT: %30 = fir.alloca i32 {bindc_name = "j", pinned, uniq_name = "_QFomp_unroll_heuristic_nested02Ej"} | ||
!CHECK-NEXT: %31:2 = hlfir.declare %30 {uniq_name = "_QFomp_unroll_heuristic_nested02Ej"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>) | ||
!CHECK-NEXT: %32 = fir.load %4#0 : !fir.ref<i32> | ||
!CHECK-NEXT: %33 = fir.load %5#0 : !fir.ref<i32> | ||
!CHECK-NEXT: %34 = fir.load %3#0 : !fir.ref<i32> | ||
!CHECK-NEXT: %c0_i32_0 = arith.constant 0 : i32 | ||
!CHECK-NEXT: %c1_i32_1 = arith.constant 1 : i32 | ||
!CHECK-NEXT: %35 = arith.cmpi slt, %34, %c0_i32_0 : i32 | ||
!CHECK-NEXT: %36 = arith.subi %c0_i32_0, %34 : i32 | ||
!CHECK-NEXT: %37 = arith.select %35, %36, %34 : i32 | ||
!CHECK-NEXT: %38 = arith.select %35, %33, %32 : i32 | ||
!CHECK-NEXT: %39 = arith.select %35, %32, %33 : i32 | ||
!CHECK-NEXT: %40 = arith.subi %39, %38 overflow<nuw> : i32 | ||
!CHECK-NEXT: %41 = arith.divui %40, %37 : i32 | ||
!CHECK-NEXT: %42 = arith.addi %41, %c1_i32_1 overflow<nuw> : i32 | ||
!CHECK-NEXT: %43 = arith.cmpi slt, %39, %38 : i32 | ||
!CHECK-NEXT: %44 = arith.select %43, %c0_i32_0, %42 : i32 | ||
!CHECK-NEXT: %canonloop_s0_s0 = omp.new_cli | ||
!CHECK-NEXT: omp.canonical_loop(%canonloop_s0_s0) %iv_2 : i32 in range(%44) { | ||
!CHECK-NEXT: %45 = arith.muli %iv_2, %34 : i32 | ||
!CHECK-NEXT: %46 = arith.addi %32, %45 : i32 | ||
!CHECK-NEXT: hlfir.assign %46 to %31#0 : i32, !fir.ref<i32> | ||
!CHECK-NEXT: %47 = fir.load %14#0 : !fir.ref<i32> | ||
!CHECK-NEXT: %48 = fir.load %31#0 : !fir.ref<i32> | ||
!CHECK-NEXT: %49 = arith.addi %47, %48 : i32 | ||
!CHECK-NEXT: hlfir.assign %49 to %12#0 : i32, !fir.ref<i32> | ||
!CHECK-NEXT: omp.terminator | ||
!CHECK-NEXT: } | ||
!CHECK-NEXT: omp.unroll_heuristic(%canonloop_s0_s0) | ||
!CHECK-NEXT: omp.terminator | ||
!CHECK-NEXT: } | ||
!CHECK-NEXT: omp.unroll_heuristic(%canonloop_s0) | ||
!CHECK-NEXT: return |
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,43 @@ | ||
! RUN: %flang_fc1 -fopenmp -fopenmp-version=51 %s -fdebug-unparse | FileCheck --check-prefix=UNPARSE %s | ||
! RUN: %flang_fc1 -fopenmp -fopenmp-version=51 %s -fdebug-dump-parse-tree | FileCheck --check-prefix=PTREE %s | ||
|
||
subroutine openmp_parse_unroll_heuristic | ||
integer i | ||
|
||
!$omp unroll | ||
do i = 1, 100 | ||
call func(i) | ||
end do | ||
!$omp end unroll | ||
END subroutine openmp_parse_unroll_heuristic | ||
|
||
|
||
!UNPARSE: !$OMP UNROLL | ||
!UNPARSE-NEXT: DO i=1_4,100_4 | ||
!UNPARSE-NEXT: CALL func(i) | ||
!UNPARSE-NEXT: END DO | ||
!UNPARSE-NEXT: !$OMP END UNROLL | ||
|
||
!PTREE: OpenMPConstruct -> OpenMPLoopConstruct | ||
!PTREE-NEXT: | OmpBeginLoopDirective | ||
!PTREE-NEXT: | | OmpLoopDirective -> llvm::omp::Directive = unroll | ||
!PTREE-NEXT: | | OmpClauseList -> | ||
!PTREE-NEXT: | DoConstruct | ||
!PTREE-NEXT: | | NonLabelDoStmt | ||
!PTREE-NEXT: | | | LoopControl -> LoopBounds | ||
!PTREE-NEXT: | | | | Scalar -> Name = 'i' | ||
!PTREE-NEXT: | | | | Scalar -> Expr = '1_4' | ||
!PTREE-NEXT: | | | | | LiteralConstant -> IntLiteralConstant = '1' | ||
!PTREE-NEXT: | | | | Scalar -> Expr = '100_4' | ||
!PTREE-NEXT: | | | | | LiteralConstant -> IntLiteralConstant = '100' | ||
!PTREE-NEXT: | | Block | ||
!PTREE-NEXT: | | | ExecutionPartConstruct -> ExecutableConstruct -> ActionStmt -> CallStmt = 'CALL func(i)' | ||
!PTREE-NEXT: | | | | | | Call | ||
!PTREE-NEXT: | | | | | ProcedureDesignator -> Name = 'func' | ||
!PTREE-NEXT: | | | | | ActualArgSpec | ||
!PTREE-NEXT: | | | | | | ActualArg -> Expr = 'i' | ||
!PTREE-NEXT: | | | | | | | Designator -> DataRef -> Name = 'i' | ||
!PTREE-NEXT: | | EndDoStmt -> | ||
!PTREE-NEXT: | OmpEndLoopDirective | ||
!PTREE-NEXT: | | OmpLoopDirective -> llvm::omp::Directive = unroll | ||
!PTREE-NEXT: | | OmpClauseList -> |
File renamed without changes.
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
Oops, something went wrong.
Oops, something went wrong.
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.
what about OMPD_tile?
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.
This PR intends to only implement one of the simplest directives for now:
omp unroll
. As outlined in the summary, full feature support requires significantly more work. I was working on it, but was aleady taking forever.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.
Sorry my comment was pretty ambiguous.
The old case handling for tile (to generate the "unhandled loop directive" NYI error, has been removed. I expect that will now lead to an assertion failure in the default case.