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.
[OMPIRBuilder][OpenMP][LLVM] Modify and use ReplaceConstant utility i…
…n convertTarget This PR seeks to expand/replace the Constant -> Instruction conversion that needs to occur inside of the OpenMP Target kernel generation to allow kernel argument replacement of uses within the kernel (cannot replace constant uses within constant expressions with non-constants). It does so by making use of the new-ish utility convertUsersOfConstantsToInstructions which is a much more expansive version of what the smaller "version" of the function I wrote does, effectively expanding uses of the input argument that are constant expressions into instructions so that we can replace with the appropriate kernel argument. Also alters convertUsersOfConstantsToInstructions to optionally leave dead constants alone is necessary when lowering from MLIR as we cannot be sure we can remove the constants at this stage, even if rewritten to instructions the ModuleTranslation may maintain links to the original constants and utilise them in further lowering steps (as when we're lowering the kernel, the module is still in the process of being lowered). This can result in unusual ICEs later. These dead constants can be tidied up later (and appear to be in subsequent lowering from checking with emit-llvm). The one possible downside to this replacement is that the constant -> instruction rewriting is no longer constrained to within the kernel, it will expand the available uses of an input argument that is constant and has constant uses in the module. This hasn't lowered the correctness of the examples I have tested with, however, it may impact performance, a possibility in the future may be to optionally constrain rewrites of uses of constants in convertUsersOfConstantsToInstructions to a provided llvm::Function.
- Loading branch information
Showing
5 changed files
with
79 additions
and
37 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
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
51 changes: 51 additions & 0 deletions
51
offload/test/offloading/fortran/dtype-array-constant-index-map.f90
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,51 @@ | ||
! Offloading test which maps a specific element of a | ||
! derived type to the device and then accesses the | ||
! element alongside an individual element of an array | ||
! that the derived type contains. In particular, this | ||
! test helps to check that we can replace the constants | ||
! within the kernel with instructions and then replace | ||
! these instructions with the kernel parameters. | ||
! REQUIRES: flang | ||
! UNSUPPORTED: nvptx64-nvidia-cuda | ||
! UNSUPPORTED: nvptx64-nvidia-cuda-LTO | ||
! UNSUPPORTED: aarch64-unknown-linux-gnu | ||
! UNSUPPORTED: aarch64-unknown-linux-gnu-LTO | ||
! UNSUPPORTED: x86_64-pc-linux-gnu | ||
! UNSUPPORTED: x86_64-pc-linux-gnu-LTO | ||
|
||
! RUN: %libomptarget-compile-fortran-run-and-check-generic | ||
module test_0 | ||
type dtype | ||
integer elements(20) | ||
integer value | ||
end type dtype | ||
|
||
type (dtype) array_dtype(5) | ||
contains | ||
|
||
subroutine assign() | ||
implicit none | ||
!$omp target map(tofrom: array_dtype(5)) | ||
array_dtype(5)%elements(5) = 500 | ||
!$omp end target | ||
end subroutine | ||
|
||
subroutine add() | ||
implicit none | ||
|
||
!$omp target map(tofrom: array_dtype(5)) | ||
array_dtype(5)%elements(5) = array_dtype(5)%elements(5) + 500 | ||
!$omp end target | ||
end subroutine | ||
end module test_0 | ||
|
||
program main | ||
use test_0 | ||
|
||
call assign() | ||
call add() | ||
|
||
print *, array_dtype(5)%elements(5) | ||
end program | ||
|
||
! CHECK: 1000 |