-
Notifications
You must be signed in to change notification settings - Fork 12.3k
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
[flang][runtime] Build ISO_FORTRAN_ENV to export kind arrays as linkable symbols #95388
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
48b29b4
Fixes #89403
mjklemm 933135e
Remove obsolete comment
mjklemm 3a80ca5
Compile and link ISO_FORTRAN_ENV
mjklemm 01179b1
Set the CACHE variable only once
mjklemm 6f02773
Update iso_fortran_env_impl.f90
mjklemm 95beb28
Update flang/tools/f18/CMakeLists.txt
mjklemm bcaf836
Update flang/tools/f18/CMakeLists.txt
mjklemm 9d30f41
Add newline
mjklemm 268aca4
Fix typo that came in from suggestion
mjklemm 04f52d6
Add test
mjklemm 077568a
Revert "Add test"
mjklemm 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
!===-- module/iso_fortran_env_impl.f90 --=--------------------------------===! | ||
! | ||
! Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
! See https://llvm.org/LICENSE.txt for license information. | ||
! SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
! | ||
!===------------------------------------------------------------------------===! | ||
|
||
! This MODULE implements part of the ISO_FORTRAN_ENV module file, which | ||
! partially requires linkable symbols for some entities defined | ||
! (e.g., real_kinds). | ||
|
||
module iso_fortran_env_impl | ||
implicit none | ||
private | ||
|
||
! INTEGER types | ||
integer, parameter, public :: & | ||
selectedInt8 = selected_int_kind(2), & | ||
selectedInt16 = selected_int_kind(4), & | ||
selectedInt32 = selected_int_kind(9), & | ||
selectedInt64 = selected_int_kind(18),& | ||
selectedInt128 = selected_int_kind(38), & | ||
safeInt8 = merge(selectedInt8, selected_int_kind(0), & | ||
selectedInt8 >= 0), & | ||
safeInt16 = merge(selectedInt16, selected_int_kind(0), & | ||
selectedInt16 >= 0), & | ||
safeInt32 = merge(selectedInt32, selected_int_kind(0), & | ||
selectedInt32 >= 0), & | ||
safeInt64 = merge(selectedInt64, selected_int_kind(0), & | ||
selectedInt64 >= 0), & | ||
safeInt128 = merge(selectedInt128, selected_int_kind(0), & | ||
selectedInt128 >= 0) | ||
|
||
integer, parameter, public :: & | ||
int8 = merge(selectedInt8, merge(-2, -1, selectedInt8 >= 0), & | ||
digits(int(0,kind=safeInt8)) == 7), & | ||
int16 = merge(selectedInt16, merge(-2, -1, selectedInt16 >= 0), & | ||
digits(int(0,kind=safeInt16)) == 15), & | ||
int32 = merge(selectedInt32, merge(-2, -1, selectedInt32 >= 0), & | ||
digits(int(0,kind=safeInt32)) == 31), & | ||
int64 = merge(selectedInt64, merge(-2, -1, selectedInt64 >= 0), & | ||
digits(int(0,kind=safeInt64)) == 63), & | ||
int128 = merge(selectedInt128, merge(-2, -1, selectedInt128 >= 0), & | ||
digits(int(0,kind=safeInt128)) == 127) | ||
|
||
integer, parameter, dimension(*), public :: __builtin_integer_kinds = [ & | ||
selected_int_kind(0), & | ||
[(pack([selected_int_kind(k)], & | ||
selected_int_kind(k) >= 0 .and. & | ||
selected_int_kind(k) /= selected_int_kind(k-1)), & | ||
integer :: k=1, 39)]] | ||
|
||
! LOGICAL TYPES | ||
integer, parameter, public :: & | ||
logical8 = int8, logical16 = int16, logical32 = int32, logical64 = int64 | ||
|
||
integer, parameter, dimension(*), public :: __builtin_logical_kinds = [ & | ||
pack([logical8], logical8 >= 0), & | ||
pack([logical16], logical16 >= 0), & | ||
pack([logical32], logical32 >= 0), & | ||
pack([logical64], logical64 >= 0) & | ||
] | ||
|
||
! REAL types | ||
integer, parameter, public :: & | ||
selectedReal16 = selected_real_kind(3, 4), & ! IEEE half | ||
selectedBfloat16 = selected_real_kind(2, 37), & ! truncated IEEE single | ||
selectedReal32 = selected_real_kind(6, 37), & ! IEEE single | ||
selectedReal64 = selected_real_kind(15, 307), & ! IEEE double | ||
selectedReal80 = selected_real_kind(18, 4931), & ! 80x87 extended | ||
selectedReal64x2 = selected_real_kind(31, 307), & ! "double-double" | ||
selectedReal128 = selected_real_kind(33, 4931), & ! IEEE quad | ||
safeReal16 = merge(selectedReal16, selected_real_kind(0,0), & | ||
selectedReal16 >= 0), & | ||
safeBfloat16 = merge(selectedBfloat16, selected_real_kind(0,0), & | ||
selectedBfloat16 >= 0), & | ||
safeReal32 = merge(selectedReal32, selected_real_kind(0,0), & | ||
selectedReal32 >= 0), & | ||
safeReal64 = merge(selectedReal64, selected_real_kind(0,0), & | ||
selectedReal64 >= 0), & | ||
safeReal80 = merge(selectedReal80, selected_real_kind(0,0), & | ||
selectedReal80 >= 0), & | ||
safeReal64x2 = merge(selectedReal64x2, selected_real_kind(0,0), & | ||
selectedReal64x2 >= 0), & | ||
safeReal128 = merge(selectedReal128, selected_real_kind(0,0), & | ||
selectedReal128 >= 0) | ||
|
||
integer, parameter, public :: & | ||
real16 = merge(selectedReal16, merge(-2, -1, selectedReal16 >= 0), & | ||
digits(real(0,kind=safeReal16)) == 11), & | ||
bfloat16 = merge(selectedBfloat16, merge(-2, -1, selectedBfloat16 >= 0), & | ||
digits(real(0,kind=safeBfloat16)) == 8), & | ||
real32 = merge(selectedReal32, merge(-2, -1, selectedReal32 >= 0), & | ||
digits(real(0,kind=safeReal32)) == 24), & | ||
real64 = merge(selectedReal64, merge(-2, -1, selectedReal64 >= 0), & | ||
digits(real(0,kind=safeReal64)) == 53), & | ||
real80 = merge(selectedReal80, merge(-2, -1, selectedReal80 >= 0), & | ||
digits(real(0,kind=safeReal80)) == 64), & | ||
real64x2 = merge(selectedReal64x2, merge(-2, -1, selectedReal64x2 >= 0), & | ||
digits(real(0,kind=safeReal64x2)) == 106), & | ||
real128 = merge(selectedReal128, merge(-2, -1, selectedReal128 >= 0), & | ||
digits(real(0,kind=safeReal128)) == 113) | ||
|
||
integer, parameter, dimension(*), public :: __builtin_real_kinds = [ & | ||
pack([real16], real16 >= 0), & | ||
pack([bfloat16], bfloat16 >= 0), & | ||
pack([real32], real32 >= 0), & | ||
pack([real64], real64 >= 0), & | ||
pack([real80], real80 >= 0), & | ||
pack([real64x2], real64x2 >= 0), & | ||
pack([real128], real128 >= 0) & | ||
] | ||
end module iso_fortran_env_impl |
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
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.
This breaks some of my builds. I believe this won't work in general unless you make sure that the object file is built before
FortranRuntime
target tries to build, i.e. there has to be a target dependency in this CMake file.I think you can try to reproduce it by deleting the module object file and running
make FortranRuntime
- it will fail with something like: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.
On it. Seems like Ninja understands the dependency, as it has a single build file that see the generated object file in one place and defers the target in the runtime libraries until that object file has been built. This does not seem to be the case for Makefile builds, because they are split across different Makefiles.
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.
Created #99737 to hopefully resolve this. Can you please see if the PR resolves the issue?
And sorry for breaking your builds!
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.
Thank you, Michael. No problem, it should fix my builds, and building
module_files
target before the complete build was a workaround for me.