-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[Flang] Add FIR and LLVM lowering support for prefetch directive #167272
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
Thirumalai-Shaktivel
wants to merge
7
commits into
llvm:main
Choose a base branch
from
Thirumalai-Shaktivel:llvm/prefetch_02
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
Show all changes
7 commits
Select commit
Hold shift + click to select a range
79adc2b
[Flang] Add FIR and LLVM lowering support for prefetch directive
Thirumalai-Shaktivel 32738eb
Fix the build failure
Thirumalai-Shaktivel 9557cd0
Remove debug print
Thirumalai-Shaktivel c28bbc2
Use UnitAttr instead of I32Attr
Thirumalai-Shaktivel 7c921f8
Fix the tests
Thirumalai-Shaktivel 7c98c64
Revert a space fix
Thirumalai-Shaktivel 1da8a95
Use Data instead of Box for allocatable array
Thirumalai-Shaktivel 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
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 @@ | ||
| !===----------------------------------------------------------------------===! | ||
| ! This directory can be used to add Integration tests involving multiple | ||
| ! stages of the compiler (for eg. from Fortran to LLVM IR). It should not | ||
| ! contain executable tests. We should only add tests here sparingly and only | ||
| ! if there is no other way to test. Repeat this message in each test that is | ||
| ! added to this directory and sub-directories. | ||
| !===----------------------------------------------------------------------===! | ||
|
|
||
| ! RUN: %flang_fc1 -emit-llvm -o - %s | FileCheck %s --check-prefixes=LLVM | ||
|
|
||
| !=============================================================================== | ||
| ! Test lowering of prefetch directive | ||
| !=============================================================================== | ||
|
|
||
| subroutine test_prefetch_01() | ||
| ! LLVM: {{.*}} = alloca i32, i64 1, align 4 | ||
| ! LLVM: %[[VAR_J:.*]] = alloca i32, i64 1, align 4 | ||
| ! LLVM: %[[VAR_I:.*]] = alloca i32, i64 1, align 4 | ||
| ! LLVM: %[[VAR_A:.*]] = alloca [256 x i32], i64 1, align 4 | ||
|
|
||
| integer :: i, j | ||
| integer :: a(256) | ||
|
|
||
| a = 23 | ||
| ! LLVM: call void @llvm.prefetch.p0(ptr %[[VAR_A]], i32 0, i32 3, i32 1) | ||
| !dir$ prefetch a | ||
| i = sum(a) | ||
|
|
||
| ! LLVM: %[[LOAD_I:.*]] = load i32, ptr %[[VAR_I]], align 4 | ||
| ! LLVM: %{{.*}} = add nsw i32 %[[LOAD_I]], 64 | ||
| ! LLVM: %[[GEP_A:.*]] = getelementptr i32, ptr %[[VAR_A]], i64 {{.*}} | ||
|
|
||
| ! LLVM: call void @llvm.prefetch.p0(ptr %[[GEP_A]], i32 0, i32 3, i32 1) | ||
| ! LLVM: call void @llvm.prefetch.p0(ptr %[[VAR_J]], i32 0, i32 3, i32 1) | ||
| do i = 1, (256 - 64) | ||
| !dir$ prefetch a(i+64), j | ||
| a(i) = a(i-32) + a(i+32) + j | ||
| end do | ||
| end subroutine test_prefetch_01 |
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,65 @@ | ||
| ! Test lowering of prefetch directive | ||
| ! RUN: %flang_fc1 -emit-hlfir -o - %s | FileCheck %s --check-prefixes=HLFIR | ||
|
|
||
| module test_prefetch_mod | ||
| implicit none | ||
| type :: t | ||
| integer :: a(256, 256) | ||
| end type t | ||
| end module test_prefetch_mod | ||
|
|
||
| subroutine test_prefetch_01() | ||
| ! HLFIR: %[[H_A:.*]]:2 = hlfir.declare {{.*}} {uniq_name = "_QFtest_prefetch_01Ea"} : (!fir.ref<!fir.array<256xi32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<256xi32>>, !fir.ref<!fir.array<256xi32>>) | ||
| ! HLFIR: %[[H_I:.*]]:2 = hlfir.declare {{.*}} {uniq_name = "_QFtest_prefetch_01Ei"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>) | ||
| ! HLFIR: %[[H_J:.*]]:2 = hlfir.declare {{.*}} {uniq_name = "_QFtest_prefetch_01Ej"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>) | ||
|
|
||
| integer :: i, j | ||
| integer :: a(256) | ||
|
|
||
| a = 23 | ||
|
|
||
| ! HLFIR: fir.prefetch %[[H_A]]#0 {cacheType, localityHint = 3 : i32} : !fir.ref<!fir.array<256xi32>> | ||
| !dir$ prefetch a | ||
| i = sum(a) | ||
|
|
||
| ! HLFIR: %[[H_LOAD:.*]] = fir.load %[[H_I]]#0 : !fir.ref<i32> | ||
| ! HLFIR: %[[H_C64:.*]] = arith.constant 64 : i32 | ||
| ! HLFIR: %[[H_ADD:.*]] = arith.addi %[[H_LOAD]], %[[H_C64]] overflow<nsw> : i32 | ||
| ! HLFIR: %[[H_CON:.*]] = fir.convert %[[H_ADD]] : (i32) -> i64 | ||
| ! HLFIR: %[[H_DESIG:.*]] = hlfir.designate %[[H_A]]#0 (%[[H_CON]]) : (!fir.ref<!fir.array<256xi32>>, i64) -> !fir.ref<i32> | ||
|
|
||
| ! HLFIR: fir.prefetch %[[H_DESIG]] {cacheType, localityHint = 3 : i32} : !fir.ref<i32> | ||
| ! HLFIR: fir.prefetch %[[H_J]]#0 {cacheType, localityHint = 3 : i32} : !fir.ref<i32> | ||
|
|
||
| do i = 1, (256 - 64) | ||
| !dir$ prefetch a(i+64), j | ||
| a(i) = a(i-32) + a(i+32) + j | ||
| end do | ||
| end subroutine test_prefetch_01 | ||
|
|
||
| subroutine test_prefetch_02(t1) | ||
| use test_prefetch_mod | ||
| ! HLFIR: %[[H_A:.*]]:2 = hlfir.declare {{.*}} {fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QFtest_prefetch_02Ea"} | ||
| ! HLFIR: %[[H_ARG0:.*]]:2 = hlfir.declare {{.*}} dummy_scope {{.*}} {fortran_attrs = #fir.var_attrs<intent_inout>, uniq_name = "_QFtest_prefetch_02Et1"} | ||
| type(t), intent(inout) :: t1 | ||
| integer, allocatable :: a(:, :) | ||
|
|
||
| ! HLFIR: %[[H_DESIG_01:.*]] = hlfir.designate %[[H_ARG0]]#0{"a"} shape {{.*}} | ||
| ! HLFIR: fir.prefetch %[[H_DESIG_01]] {cacheType, localityHint = 3 : i32} : !fir.ref<!fir.array<256x256xi32>> | ||
| !dir$ prefetch t1%a | ||
| a = t1%a ** 2 | ||
|
|
||
| do i = 1, 256 | ||
| ! HLFIR: %[[A_LOAD:.*]] = fir.load %[[H_A]]#0 : !fir.ref<!fir.box<!fir.heap<!fir.array<?x?xi32>>>> | ||
| ! HLFIR: %[[A_BOX:.*]] = fir.box_addr %[[A_LOAD]] : (!fir.box<!fir.heap<!fir.array<?x?xi32>>>) -> !fir.heap<!fir.array<?x?xi32>> | ||
| ! HLFIR: fir.prefetch %[[A_BOX]] {cacheType, localityHint = 3 : i32} : !fir.heap<!fir.array<?x?xi32>> | ||
| !dir$ prefetch a | ||
| a(i, :) = a(i, :) + i | ||
| do j = 1, 256 | ||
| ! HLFIR: %[[H_DESIG_02:.*]] = hlfir.designate %[[H_ARG0]]#0{"a"} {{.*}} | ||
| ! HLFIR: fir.prefetch %[[H_DESIG_02]] {cacheType, localityHint = 3 : i32} : !fir.ref<i32> | ||
| !dir$ prefetch t1%a(i, j) | ||
| t1%a(i, j) = (a(i, j) + i*j) / t1%a(i, j) | ||
| end do | ||
| end do | ||
| end subroutine test_prefetch_02 |
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.
Without any side effects, I think this operation could pessimize some analysis/optimizations.
Do you know how LLVM handles the side effects of this operation?
Should it simply be given read/write effects on its arguments depending on the rw attribute?