Skip to content
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] Put ISO_Fortran_binding.h where it can be easily used #68756

Closed
wants to merge 4 commits into from

Conversation

psteinfeld
Copy link
Contributor

The update stems from the discussion in
https://discourse.llvm.org/t/adding-flang-specific-header-files-to-clang/72442

I decided to put ISO_Fortran_binding.h in a place where it would be accessible with the include: "#include<ISO_Fortran_binding.h>" rather than "#include<fortran/ISO_Fortran_binding.h>" because this is what gfortran does.

The changes to put the header file into the build and install areas are in .../flang/CMakeLists.txt. This code calls "get_clang_resource_dir", which requires "PACKAGE_VERSION" to be defined, so I added code to define it.

Note that the file is also installed into ".../include/flang", so if a user wanted to access the file from a compiler other than clang, it would be available.

I added a test in ".../flang/test/Examples". Since the flang project depends on clang, clang will always be available in a flang build. To make the test work, I also needed to put ISO_Fortran_binding.h into the build area.

The update stems from the discussion in
https://discourse.llvm.org/t/adding-flang-specific-header-files-to-clang/72442

I decided to put ISO_Fortran_binding.h in a place where it would be
accessible with the include: "#include<ISO_Fortran_binding.h>" rather
than "#include<fortran/ISO_Fortran_binding.h>" because this is what
gfortran does.

The changes to put the header file into the build and install areas are
in .../flang/CMakeLists.txt.  This code  calls "get_clang_resource_dir",
which requires "PACKAGE_VERSION" to be defined, so I added code to
define it.

Note that the file is also installed into ".../include/flang", so if a
user wanted to access the file from a compiler other than clang, it
would be available.

I added a test in ".../flang/test/Examples".  Since the flang project
depends on clang, clang will always be available in a flang build.  To
make the test work, I also needed to put ISO_Fortran_binding.h into the
build area.
@llvmbot llvmbot added the flang Flang issues not falling into any other category label Oct 10, 2023
! UNSUPPORTED: system-windows
! RUN: split-file %s %t
! RUN: %clang -c %t/cfile.c
! RUN: %flang -flang-experimental-hlfir cfile.o %t/src.f90
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
! RUN: %flang -flang-experimental-hlfir cfile.o %t/src.f90
! RUN: %flang -flang-experimental-hlfir cfile.o %t/src.f90 -o %t/ctofortran

! RUN: split-file %s %t
! RUN: %clang -c %t/cfile.c
! RUN: %flang -flang-experimental-hlfir cfile.o %t/src.f90
! RUN: a.out | FileCheck %s
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
! RUN: a.out | FileCheck %s
! RUN: %t/ctofortran | FileCheck %s

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it may fail because of the missing "./", but I would suggest a named executable file to make it more explicit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Slava. You're a prince!

@@ -64,6 +64,7 @@ set(FLANG_TEST_DEPENDS
FortranRuntime
Fortran_main
FortranDecimal
clang
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this pulling in all of clang? Do we really need that? If this is only for testing, can we use REQUIRES: clang in the test to make sure clang is available?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I'll remove it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REQUIRES: clang only affects whether the LIT test is run or not. The clang keyword, in this case, has to be present in config.available_features for the test to run. Since we do not add clang into the available features list, the test will just not run. Even if we did enabled clang as a LIT feature, we still have to guarantee that the clang target (that builds the actual clang executable) is built before the test runs - this can only be done by setting proper dependency in CMake files.

If building the whole clang under check-flang is not acceptable, we need another solution.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I generally use check-flang to build flang. Also, was not sure whether to add a dependency with the whole of clang for just one test.

Yes, we have to add clang to config.available_features for REQUIRES to work.

For the dependency with clang, Do we really want to check with the clang just built or is it sufficient to check with the clang installed on the system? Also, is it OK to check with the system compiler?

The OpenMP runtime library checks for the presence of flang for running an offload test. Would that be a possible way?
https://reviews.llvm.org/D158546

Another reference might include the way the runtime no dependency on C++ libs is checked.
https://reviews.llvm.org/D104290

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option would be to add this to the llvm-test-suite (https://github.com/llvm/llvm-test-suite/tree/main/Fortran/UnitTests) and ensure that one of the buildbots run it.

Also, I would like to clarify that this is not a blocker issue. If the dependency has to be there and that is what is preferred, we can go ahead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the dependency with clang, Do we really want to check with the clang just built or is it sufficient to check with the clang installed on the system? Also, is it OK to check with the system compiler?

Yes, we need to check with the clang that has just been built. The test is checking that clang is able to find the header file, so clang used for the test is the one which has the header file in its "installation" structure.

If we change the LIT test from clang compilation +flang compilation + execution into just clang compilation, then we can move this functionality into clang/lib/Headers completely.

We can have an end-to-end test with clang/flang/executable in llvm-test-suite as you suggested.

I think adding clang dependency is too much overhead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving the functionality into clang would make clang dependent on flang, which we don't want. I do think we want to keep the file ISO_Fortran_binding.h in the flang project.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think the "dependency" I am talking about is a problem. If we move the LIT tests into clang source tree, and do not use flang-new in the test, then the only dependency is the ability for clang CMake code to access ISO_Fortran_binding.h, which is already a part of the LLVM source tree. So it should not be a problem.

Anyway, I am okay with keeping it as-is, but without having the clang dependency for check-flang. Moving the LIT test out of the tree should "resolve" this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to make this test configurable based on a cmake variable? That way, we could keep in in the flang tree and keep it so that it created and executes a program.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After talking to Slava. This doesn't seem like a viable alternative.

@@ -0,0 +1,59 @@
! UNSUPPORTED: system-windows
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also add something like REQUIRES: clang

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Kiran. Will do.

@psteinfeld
Copy link
Contributor Author

By the way, I timed doing a full build of clang, flang, and check-flang. On my system, this took 8:30. I then did a build of just check-flang. This took 5:50.

@psteinfeld
Copy link
Contributor Author

After all of this discussion, I'm convinced that the right place to put this test is in the llvm cross project tests (//github.com/llvm/llvm-project/tree/main/cross-project-tests as was suggested earlier by @tschuett.

I'll abandon this change.

@psteinfeld
Copy link
Contributor Author

New pull request for this in #69121

psteinfeld added a commit that referenced this pull request Oct 19, 2023
The update stems from the discussion in

https://discourse.llvm.org/t/adding-flang-specific-header-files-to-clang/72442

This is my second attempt at this. My first attempt was in pull request
#68756.

I decided to put ISO_Fortran_binding.h in a place where it would be
accessible with the include: "#include<ISO_Fortran_binding.h>" rather
than "#include<fortran/ISO_Fortran_binding.h>" because this is what
gfortran implements.

Note that the file is also installed into ".../include/flang", so if a
user wanted to access the file from a compiler other than clang, it
would be available.

I added a test in ".../flang/test/Examples". To make the test work, I
also needed to put ISO_Fortran_binding.h into the build area.

Although the flang project depends on clang, clang may not always be
available in a flang build. For example, when building just the
"check-flang" target, the "clang" executable may not be available at the
time the new test gets run. To account for this, I made the test's
script check for the existence of the "clang" executable. If "clang" is
not available, it simply prints "PASS". If it is available, it fully
builds and executes the test. On success, this will also print "PASS"
psteinfeld added a commit that referenced this pull request Oct 30, 2023
The update stems from the discussion in

https://discourse.llvm.org/t/adding-flang-specific-header-files-to-clang/72442

This is my third attempt at this. My second attempt was in pull request
#69121.

This is my second attempt at this. My first attempt was in pull request
#68756.

This pull request has three changes from the second one:
- I put the test into the Driver directory rather than Examples so that
it would get run without require the define LLVM_BUILD_EXAMPLES.
- When installing ISO_Fortran_binding.h, I changed the location where it
was installed from.
- I changed the test so that it would work when flang was built with
shared libraries.

Here's the information from my previous attempts:

I decided to put ISO_Fortran_binding.h in a place where it would be
accessible with the include: "#include<ISO_Fortran_binding.h>" rather
than "#include<fortran/ISO_Fortran_binding.h>" because this is what
gfortran implements.

Note that the file is also installed into ".../include/flang", so if a
user wanted to access the file from a compiler other than clang, it
would be available.

I added a test in ".../flang/test/Driver". To make the test work, I also
needed to put ISO_Fortran_binding.h into the build area.

Although the flang project depends on clang, clang may not always be
available in a flang build. For example, when building just the
"check-flang" target, the "clang" executable may not be available at the
time the new test gets run. To account for this, I made the test's
script check for the existence of the "clang" executable. If "clang" is
not available, it simply prints "PASS". If it is available, it fully
builds and executes the test. On success, this will also print "PASS"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants