2020-01-15 00:20:49 +08:00
|
|
|
# Test runner infrastructure for Flang. This configures the Flang test trees
|
|
|
|
# for use by Lit, and delegates to LLVM's lit test handlers.
|
|
|
|
|
2020-08-02 03:53:27 +08:00
|
|
|
llvm_canonicalize_cmake_booleans(
|
2021-08-12 18:42:08 +08:00
|
|
|
FLANG_BUILD_EXAMPLES
|
2020-08-02 03:53:27 +08:00
|
|
|
FLANG_STANDALONE_BUILD
|
2021-08-12 18:42:08 +08:00
|
|
|
LLVM_ENABLE_PLUGINS
|
2020-08-02 03:53:27 +08:00
|
|
|
)
|
|
|
|
|
2020-02-26 07:22:14 +08:00
|
|
|
set(FLANG_TOOLS_DIR ${FLANG_BINARY_DIR}/bin)
|
2020-01-28 20:58:30 +08:00
|
|
|
|
2021-08-13 00:11:54 +08:00
|
|
|
# FIXME In out-of-tree builds, "SHLIBDIR" is undefined and passing it to
|
|
|
|
# `configure_lit_site_cfg` leads to a configuration error. This is currently
|
|
|
|
# only required by plugins/examples, which are not supported in out-of-tree
|
|
|
|
# builds.
|
|
|
|
if (FLANG_STANDALONE_BUILD)
|
|
|
|
set(PATHS_FOR_PLUGINS "")
|
|
|
|
else ()
|
|
|
|
set(PATHS_FOR_PLUGINS "SHLIBDIR")
|
|
|
|
endif ()
|
|
|
|
|
2020-01-15 00:20:49 +08:00
|
|
|
configure_lit_site_cfg(
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py
|
|
|
|
MAIN_CONFIG
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py
|
2021-08-12 18:42:08 +08:00
|
|
|
PATHS
|
2021-08-13 00:11:54 +08:00
|
|
|
${PATHS_FOR_PLUGINS}
|
2020-01-15 00:20:49 +08:00
|
|
|
)
|
|
|
|
|
2020-06-03 01:15:44 +08:00
|
|
|
configure_lit_site_cfg(
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg.py
|
|
|
|
MAIN_CONFIG
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.cfg.py
|
|
|
|
)
|
|
|
|
|
2020-07-16 21:15:07 +08:00
|
|
|
configure_lit_site_cfg(
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/NonGtestUnit/lit.site.cfg.py.in
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/NonGtestUnit/lit.site.cfg.py
|
|
|
|
MAIN_CONFIG
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/NonGtestUnit/lit.cfg.py
|
|
|
|
)
|
|
|
|
|
2020-01-15 00:20:49 +08:00
|
|
|
set(FLANG_TEST_PARAMS
|
|
|
|
flang_site_config=${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py)
|
|
|
|
|
|
|
|
set(FLANG_TEST_DEPENDS
|
2022-03-24 00:49:40 +08:00
|
|
|
flang-new
|
|
|
|
llvm-config
|
|
|
|
FileCheck
|
|
|
|
count
|
|
|
|
not
|
|
|
|
module_files
|
|
|
|
fir-opt
|
|
|
|
tco
|
|
|
|
bbc
|
2022-04-06 19:59:28 +08:00
|
|
|
llvm-dis
|
2022-03-24 00:49:40 +08:00
|
|
|
llvm-objdump
|
|
|
|
split-file
|
[flang][driver] Add support for generating executables
This patch adds 2 missing items required for `flang-new` to be able to
generate executables:
1. The Fortran_main runtime library, which implements the main entry
point into Fortran's `PROGRAM` in Flang,
2. Extra linker flags to include Fortran runtime libraries (e.g.
Fortran_main).
Fortran_main is the bridge between object files generated by Flang and
the C runtime that takes care of program set-up at system-level. For
every Fortran `PROGRAM`, Flang generates the `_QQmain` function.
Fortran_main implements the C `main` function that simply calls
`_QQmain`.
Additionally, "<driver-path>/../lib" directory is added to the list of
search directories for libraries. This is where the required runtime
libraries are currently located. Note that this the case for the build
directory. We haven't considered installation directories/targets yet.
With this change, you can generate an executable that will print `hello,
world!` as follows:
```bash
$ cat hello.f95
PROGRAM HELLO
write(*, *) "hello, world!"
END PROGRAM HELLO
$ flang-new -flang-experimental-exec hello.f95
./a.out
hello, world!
```
NOTE 1: Fortran_main has to be a static library at all times. It invokes
`_QQmain`, which is the main entry point generated by Flang for the
given input file (you can check this with `flang-new -S hello.f95 -o - |
grep "Qmain"`). This means that Fortran_main has an unresolved
dependency at build time. The linker will allow this for a static
library. However, if Fortran_main was a shared object, then the linker
will produce an error: `undefined symbol: `_QQmain`.
NOTE 2: When Fortran runtime libraries are generated as shared libraries
(excluding Fortran_main, which is always static), you will need to
tell the dynamic linker (by e.g. tweaking LD_LIBRARY_PATH) where to look
for them when invoking the executables. For example:
```bash
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:<flang-build-dir>/lib/ ./a.out
```
NOTE 3: This feature is considered experimental and currently guarded
with a flag: `-flang-experimental-exec`.
Differential Revision: https://reviews.llvm.org/D122008
[1] https://github.com/flang-compiler/f18-llvm-project
CREDITS: Fortran_main was originally written by Eric Schweitz, Jean
Perier, Peter Klausler and Steve Scalpone in the fir-dev` branch in [1].
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Peter Klausler <pklausler@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Steve Scalpone <sscalpone@nvidia.com
2022-03-18 00:24:54 +08:00
|
|
|
FortranRuntime
|
|
|
|
Fortran_main
|
|
|
|
FortranDecimal
|
2020-01-15 00:20:49 +08:00
|
|
|
)
|
2020-03-12 12:47:22 +08:00
|
|
|
|
2020-06-03 01:15:44 +08:00
|
|
|
if (FLANG_INCLUDE_TESTS)
|
|
|
|
if (FLANG_GTEST_AVAIL)
|
|
|
|
list(APPEND FLANG_TEST_DEPENDS FlangUnitTests)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2021-08-12 18:42:08 +08:00
|
|
|
if (FLANG_BUILD_EXAMPLES)
|
2021-08-19 16:07:45 +08:00
|
|
|
list(APPEND FLANG_TEST_DEPENDS
|
|
|
|
flangPrintFunctionNames
|
2021-09-29 15:28:40 +08:00
|
|
|
flangOmpReport
|
2021-08-19 16:07:45 +08:00
|
|
|
)
|
2021-08-12 18:42:08 +08:00
|
|
|
endif ()
|
|
|
|
|
2020-02-26 07:22:14 +08:00
|
|
|
add_custom_target(flang-test-depends DEPENDS ${FLANG_TEST_DEPENDS})
|
|
|
|
|
|
|
|
add_lit_testsuite(check-flang "Running the Flang regression tests"
|
2020-01-15 00:20:49 +08:00
|
|
|
${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
PARAMS ${FLANG_TEST_PARAMS}
|
2020-03-05 23:12:06 +08:00
|
|
|
DEPENDS ${FLANG_TEST_DEPENDS}
|
2020-05-12 02:38:53 +08:00
|
|
|
)
|
2020-02-26 07:22:14 +08:00
|
|
|
set_target_properties(check-flang PROPERTIES FOLDER "Tests")
|
|
|
|
|
2020-06-22 12:54:28 +08:00
|
|
|
# In case of standalone builds.
|
|
|
|
if (FLANG_STANDALONE_BUILD)
|
|
|
|
add_lit_testsuites(FLANG ${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
PARAMS ${FLANG_TEST_PARAMS}
|
|
|
|
DEPENDS ${FLANG_TEST_DEPENDS})
|
|
|
|
else()
|
|
|
|
add_lit_testsuites(FLANG ${CMAKE_CURRENT_SOURCE_DIR}
|
|
|
|
PARAMS ${FLANG_TEST_PARAMS}
|
|
|
|
DEPENDS ${FLANG_TEST_DEPENDS})
|
|
|
|
endif()
|