| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,234 @@ | ||
| ============================================================================== | ||
| The LLVM Project is under the Apache License v2.0 with LLVM Exceptions: | ||
| ============================================================================== | ||
|
|
||
| Apache License | ||
| Version 2.0, January 2004 | ||
| http://www.apache.org/licenses/ | ||
|
|
||
| TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION | ||
|
|
||
| 1. Definitions. | ||
|
|
||
| "License" shall mean the terms and conditions for use, reproduction, | ||
| and distribution as defined by Sections 1 through 9 of this document. | ||
|
|
||
| "Licensor" shall mean the copyright owner or entity authorized by | ||
| the copyright owner that is granting the License. | ||
|
|
||
| "Legal Entity" shall mean the union of the acting entity and all | ||
| other entities that control, are controlled by, or are under common | ||
| control with that entity. For the purposes of this definition, | ||
| "control" means (i) the power, direct or indirect, to cause the | ||
| direction or management of such entity, whether by contract or | ||
| otherwise, or (ii) ownership of fifty percent (50%) or more of the | ||
| outstanding shares, or (iii) beneficial ownership of such entity. | ||
|
|
||
| "You" (or "Your") shall mean an individual or Legal Entity | ||
| exercising permissions granted by this License. | ||
|
|
||
| "Source" form shall mean the preferred form for making modifications, | ||
| including but not limited to software source code, documentation | ||
| source, and configuration files. | ||
|
|
||
| "Object" form shall mean any form resulting from mechanical | ||
| transformation or translation of a Source form, including but | ||
| not limited to compiled object code, generated documentation, | ||
| and conversions to other media types. | ||
|
|
||
| "Work" shall mean the work of authorship, whether in Source or | ||
| Object form, made available under the License, as indicated by a | ||
| copyright notice that is included in or attached to the work | ||
| (an example is provided in the Appendix below). | ||
|
|
||
| "Derivative Works" shall mean any work, whether in Source or Object | ||
| form, that is based on (or derived from) the Work and for which the | ||
| editorial revisions, annotations, elaborations, or other modifications | ||
| represent, as a whole, an original work of authorship. For the purposes | ||
| of this License, Derivative Works shall not include works that remain | ||
| separable from, or merely link (or bind by name) to the interfaces of, | ||
| the Work and Derivative Works thereof. | ||
|
|
||
| "Contribution" shall mean any work of authorship, including | ||
| the original version of the Work and any modifications or additions | ||
| to that Work or Derivative Works thereof, that is intentionally | ||
| submitted to Licensor for inclusion in the Work by the copyright owner | ||
| or by an individual or Legal Entity authorized to submit on behalf of | ||
| the copyright owner. For the purposes of this definition, "submitted" | ||
| means any form of electronic, verbal, or written communication sent | ||
| to the Licensor or its representatives, including but not limited to | ||
| communication on electronic mailing lists, source code control systems, | ||
| and issue tracking systems that are managed by, or on behalf of, the | ||
| Licensor for the purpose of discussing and improving the Work, but | ||
| excluding communication that is conspicuously marked or otherwise | ||
| designated in writing by the copyright owner as "Not a Contribution." | ||
|
|
||
| "Contributor" shall mean Licensor and any individual or Legal Entity | ||
| on behalf of whom a Contribution has been received by Licensor and | ||
| subsequently incorporated within the Work. | ||
|
|
||
| 2. Grant of Copyright License. Subject to the terms and conditions of | ||
| this License, each Contributor hereby grants to You a perpetual, | ||
| worldwide, non-exclusive, no-charge, royalty-free, irrevocable | ||
| copyright license to reproduce, prepare Derivative Works of, | ||
| publicly display, publicly perform, sublicense, and distribute the | ||
| Work and such Derivative Works in Source or Object form. | ||
|
|
||
| 3. Grant of Patent License. Subject to the terms and conditions of | ||
| this License, each Contributor hereby grants to You a perpetual, | ||
| worldwide, non-exclusive, no-charge, royalty-free, irrevocable | ||
| (except as stated in this section) patent license to make, have made, | ||
| use, offer to sell, sell, import, and otherwise transfer the Work, | ||
| where such license applies only to those patent claims licensable | ||
| by such Contributor that are necessarily infringed by their | ||
| Contribution(s) alone or by combination of their Contribution(s) | ||
| with the Work to which such Contribution(s) was submitted. If You | ||
| institute patent litigation against any entity (including a | ||
| cross-claim or counterclaim in a lawsuit) alleging that the Work | ||
| or a Contribution incorporated within the Work constitutes direct | ||
| or contributory patent infringement, then any patent licenses | ||
| granted to You under this License for that Work shall terminate | ||
| as of the date such litigation is filed. | ||
|
|
||
| 4. Redistribution. You may reproduce and distribute copies of the | ||
| Work or Derivative Works thereof in any medium, with or without | ||
| modifications, and in Source or Object form, provided that You | ||
| meet the following conditions: | ||
|
|
||
| (a) You must give any other recipients of the Work or | ||
| Derivative Works a copy of this License; and | ||
|
|
||
| (b) You must cause any modified files to carry prominent notices | ||
| stating that You changed the files; and | ||
|
|
||
| (c) You must retain, in the Source form of any Derivative Works | ||
| that You distribute, all copyright, patent, trademark, and | ||
| attribution notices from the Source form of the Work, | ||
| excluding those notices that do not pertain to any part of | ||
| the Derivative Works; and | ||
|
|
||
| (d) If the Work includes a "NOTICE" text file as part of its | ||
| distribution, then any Derivative Works that You distribute must | ||
| include a readable copy of the attribution notices contained | ||
| within such NOTICE file, excluding those notices that do not | ||
| pertain to any part of the Derivative Works, in at least one | ||
| of the following places: within a NOTICE text file distributed | ||
| as part of the Derivative Works; within the Source form or | ||
| documentation, if provided along with the Derivative Works; or, | ||
| within a display generated by the Derivative Works, if and | ||
| wherever such third-party notices normally appear. The contents | ||
| of the NOTICE file are for informational purposes only and | ||
| do not modify the License. You may add Your own attribution | ||
| notices within Derivative Works that You distribute, alongside | ||
| or as an addendum to the NOTICE text from the Work, provided | ||
| that such additional attribution notices cannot be construed | ||
| as modifying the License. | ||
|
|
||
| You may add Your own copyright statement to Your modifications and | ||
| may provide additional or different license terms and conditions | ||
| for use, reproduction, or distribution of Your modifications, or | ||
| for any such Derivative Works as a whole, provided Your use, | ||
| reproduction, and distribution of the Work otherwise complies with | ||
| the conditions stated in this License. | ||
|
|
||
| 5. Submission of Contributions. Unless You explicitly state otherwise, | ||
| any Contribution intentionally submitted for inclusion in the Work | ||
| by You to the Licensor shall be under the terms and conditions of | ||
| this License, without any additional terms or conditions. | ||
| Notwithstanding the above, nothing herein shall supersede or modify | ||
| the terms of any separate license agreement you may have executed | ||
| with Licensor regarding such Contributions. | ||
|
|
||
| 6. Trademarks. This License does not grant permission to use the trade | ||
| names, trademarks, service marks, or product names of the Licensor, | ||
| except as required for reasonable and customary use in describing the | ||
| origin of the Work and reproducing the content of the NOTICE file. | ||
|
|
||
| 7. Disclaimer of Warranty. Unless required by applicable law or | ||
| agreed to in writing, Licensor provides the Work (and each | ||
| Contributor provides its Contributions) on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
| implied, including, without limitation, any warranties or conditions | ||
| of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A | ||
| PARTICULAR PURPOSE. You are solely responsible for determining the | ||
| appropriateness of using or redistributing the Work and assume any | ||
| risks associated with Your exercise of permissions under this License. | ||
|
|
||
| 8. Limitation of Liability. In no event and under no legal theory, | ||
| whether in tort (including negligence), contract, or otherwise, | ||
| unless required by applicable law (such as deliberate and grossly | ||
| negligent acts) or agreed to in writing, shall any Contributor be | ||
| liable to You for damages, including any direct, indirect, special, | ||
| incidental, or consequential damages of any character arising as a | ||
| result of this License or out of the use or inability to use the | ||
| Work (including but not limited to damages for loss of goodwill, | ||
| work stoppage, computer failure or malfunction, or any and all | ||
| other commercial damages or losses), even if such Contributor | ||
| has been advised of the possibility of such damages. | ||
|
|
||
| 9. Accepting Warranty or Additional Liability. While redistributing | ||
| the Work or Derivative Works thereof, You may choose to offer, | ||
| and charge a fee for, acceptance of support, warranty, indemnity, | ||
| or other liability obligations and/or rights consistent with this | ||
| License. However, in accepting such obligations, You may act only | ||
| on Your own behalf and on Your sole responsibility, not on behalf | ||
| of any other Contributor, and only if You agree to indemnify, | ||
| defend, and hold each Contributor harmless for any liability | ||
| incurred by, or claims asserted against, such Contributor by reason | ||
| of your accepting any such warranty or additional liability. | ||
|
|
||
| END OF TERMS AND CONDITIONS | ||
|
|
||
| APPENDIX: How to apply the Apache License to your work. | ||
|
|
||
| To apply the Apache License to your work, attach the following | ||
| boilerplate notice, with the fields enclosed by brackets "[]" | ||
| replaced with your own identifying information. (Don't include | ||
| the brackets!) The text should be enclosed in the appropriate | ||
| comment syntax for the file format. We also recommend that a | ||
| file or class name and description of purpose be included on the | ||
| same "printed page" as the copyright notice for easier | ||
| identification within third-party archives. | ||
|
|
||
| Copyright [yyyy] [name of copyright owner] | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
|
|
||
|
|
||
| ---- LLVM Exceptions to the Apache 2.0 License ---- | ||
|
|
||
| As an exception, if, as a result of your compiling your source code, portions | ||
| of this Software are embedded into an Object form of such source code, you | ||
| may redistribute such embedded portions in such Object form without complying | ||
| with the conditions of Sections 4(a), 4(b) and 4(d) of the License. | ||
|
|
||
| In addition, if you combine or link compiled forms of this Software with | ||
| software that is licensed under the GPLv2 ("Combined Software") and if a | ||
| court of competent jurisdiction determines that the patent provision (Section | ||
| 3), the indemnity provision (Section 9) or other Section of the License | ||
| conflicts with the conditions of the GPLv2, you may retroactively and | ||
| prospectively choose to deem waived or otherwise exclude such Section(s) of | ||
| the License, but only in their entirety and only with respect to the Combined | ||
| Software. | ||
|
|
||
| ============================================================================== | ||
| Software from third parties included in the LLVM Project: | ||
| ============================================================================== | ||
| The LLVM Project contains third party software which is under different license | ||
| terms. All such code will be identified clearly using at least one of two | ||
| mechanisms: | ||
| 1) It will be in a separate directory tree with its own `LICENSE.txt` or | ||
| `LICENSE` file at the top containing the specific license and restrictions | ||
| which apply to that software, or | ||
| 2) It will contain specific license and restriction terms at the top of every | ||
| file. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,198 @@ | ||
| <!--===- README.md | ||
| 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 | ||
| --> | ||
|
|
||
| # Fortran Runtime (Flang-RT) | ||
|
|
||
| Flang-RT is the runtime library for code emitted by the Flang compiler | ||
| (https://flang.llvm.org). | ||
|
|
||
|
|
||
| ## Getting Started | ||
|
|
||
| There are two build modes for the Flang-RT. The bootstrap build, also | ||
| called the in-tree build, and the runtime-only build, also called the | ||
| out-of-tree build. | ||
| Not to be confused with the terms | ||
| [in-source and out-of-source](https://cmake.org/cmake/help/latest/manual/cmake.1.html#introduction-to-cmake-buildsystems) | ||
| builds as defined by CMake. In an in-source build, the source directory and the | ||
| build directory are identical, whereas with an out-of-source build the | ||
| build artifacts are stored somewhere else, possibly in a subdirectory of the | ||
| source directory. LLVM does not support in-source builds. | ||
|
|
||
|
|
||
| ### Requirements | ||
|
|
||
| Requirements: | ||
| * [Same as LLVM](https://llvm.org/docs/GettingStarted.html#requirements). | ||
|
|
||
|
|
||
| ### Bootstrap/In-Tree Build | ||
|
|
||
| The bootstrap build will first build Clang and Flang, then use these compilers | ||
| to compile Flang-RT. CMake will create a secondary build tree | ||
| configured to use these just-built compilers. The secondary build will reuse | ||
| the same build options (Flags, Debug/Release, ...) as the primary build. | ||
| It will also ensure that once built, Flang-RT is found by Flang from either | ||
| the build- or install-prefix. To enable, add `flang-rt` to | ||
| `LLVM_ENABLE_RUNTIMES`: | ||
|
|
||
| ```bash | ||
| cmake -S <path-to-llvm-project-source>/llvm \ | ||
| -GNinja \ | ||
| -DLLVM_ENABLE_PROJECTS="clang;flang" \ | ||
| -DLLVM_ENABLE_RUNTIMES=flang-rt \ | ||
| ... | ||
| ``` | ||
|
|
||
| It is recommended to enable building OpenMP alongside Flang and Flang-RT | ||
| as well. This will build `omp_lib.mod` required to use OpenMP from Fortran. | ||
| Building Compiler-RT may also be required, particularly on platforms that do | ||
| not provide all C-ABI functionality (such as Windows). | ||
|
|
||
| ```bash | ||
| cmake -S <path-to-llvm-project-source>/llvm \ | ||
| -GNinja \ | ||
| -DCMAKE_BUILD_TYPE=Release \ | ||
| -DLLVM_ENABLE_PROJECTS="clang;flang;openmp" \ | ||
| -DLLVM_ENABLE_RUNTIMES="compiler-rt;flang-rt" \ | ||
| ... | ||
| ``` | ||
|
|
||
| By default, the enabled runtimes will only be built for the host platform | ||
| (`-DLLVM_RUNTIME_TARGETS=default`). To add additional targets to support | ||
| cross-compilation via `flang --target=<target-triple>`, add more triples to | ||
| `LLVM_RUNTIME_TARGETS`, such as | ||
| `-DLLVM_RUNTIME_TARGETS="default;aarch64-linux-gnu"`. | ||
|
|
||
| After configuration, build, test, and install the runtime(s) via | ||
|
|
||
| ```shell | ||
| $ ninja flang-rt | ||
| $ ninja check-flang-rt | ||
| $ ninja install | ||
| ``` | ||
|
|
||
|
|
||
| ### Runtime-only/Out-of-Tree Build | ||
|
|
||
| Instead of building Clang and Flang from scratch, the Runtime-only build uses | ||
| CMake's environment introspection to find a C, C++, and Fortran compiler. The | ||
| compiler to be used can be controlled using CMake's standard mechanisms such as | ||
| `CMAKE_CXX_COMPILER`, `CMAKE_CXX_COMPILER`, and `CMAKE_Fortran_COMPILER`. | ||
| `CMAKE_Fortran_COMPILER` must be `flang` built from the same Git commit as | ||
| Flang-RT to ensure they are using the same ABI. The C and C++ compiler | ||
| can be any compiler supporting the same ABI. | ||
|
|
||
| In addition to the compiler, the build be able to find LLVM development tools | ||
| such as `lit` and `FileCheck` that are not found in an LLVM's install | ||
| directory. Use `CMAKE_BINARY_DIR` to point to directory where LLVM has | ||
| been built. A simple build configuration might look like the following: | ||
|
|
||
| ```bash | ||
| cmake -S <path-to-llvm-project-source>/runtimes \ | ||
| -GNinja \ | ||
| -DLLVM_BINARY_DIR=<path-to-llvm-builddir> \ | ||
| -DCMAKE_Fortran_COMPILER=<path-to-llvm-builddir>/bin/flang \ | ||
| -DCMAKE_Fortran_COMPILER_WORKS=yes \ | ||
| -DLLVM_ENABLE_RUNTIMES=flang-rt \ | ||
| ... | ||
| ``` | ||
|
|
||
| The `CMAKE_Fortran_COMPILER_WORKS` parameter must be set because otherwise CMake | ||
| will test whether the Fortran compiler can compile and link programs which will | ||
| obviously fail without a runtime library available yet. | ||
|
|
||
| Building Flang-RT for cross-compilation triple, the target triple can | ||
| be selected using `LLVM_DEFAULT_TARGET_TRIPLE` AND `LLVM_RUNTIMES_TARGET`. | ||
| Of course, Flang-RT can be built multiple times with different build | ||
| configurations, but have to be located manually when using with the Flang | ||
| driver using the `-L` option. | ||
|
|
||
| A more complete build configuration could be the following: | ||
|
|
||
| ```bash | ||
| cmake -S <path-to-llvm-project-source>/runtimes \ | ||
| -GNinja \ | ||
| -DCMAKE_BUILD_TYPE=Release \ | ||
| -DCMAKE_INSTALL_PREFIX="${HOME}/local" \ | ||
| -DLLVM_ENABLE_RUNTIMES="compiler-rt;flang-rt" \ | ||
| -DCMAKE_C_COMPILER=gcc \ | ||
| -DCMAKE_CXX_COMPILER=g++ \ | ||
| -DLLVM_BINARY_DIR=<path-to-llvm-builddir> \ | ||
| -DLLVM_DIR=<path-to-llvm-builddir>/lib/cmake/llvm \ | ||
| -DClang_DIR=<path-to-llvm-builddir>/lib/cmake/clang \ | ||
| -DCMAKE_Fortran_COMPILER=<path-to-llvm-builddir-or-installprefix>/bin/flang \ | ||
| -DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-linux-gnu \ | ||
| -DLLVM_RUNTIMES_TARGET=x86_64-linux-gnu \ | ||
| ... | ||
| ``` | ||
|
|
||
| ## Configuration Option Reference | ||
|
|
||
| Flang-RT has the followign configuration options. This is in | ||
| addition to the build options the LLVM_ENABLE_RUNTIMES mechanism and | ||
| CMake itself provide. | ||
|
|
||
| * `FLANG_RT_INCLUDE_TESTS` (boolean; default: `ON`) | ||
|
|
||
| When `OFF`, does not add any tests and unittests. The `check-flang-rt` | ||
| build target will do nothing. | ||
|
|
||
| * `FLANG_RUNTIME_F128_MATH_LIB` (default: `""`) | ||
|
|
||
| Determines the implementation of `REAL(16)` math functions. If set to | ||
| `libquadmath`, uses `quadmath.h` and `-lquadmath` typically distributed with | ||
| gcc. If empty, disables `REAL(16)` support. For any other value, introspects | ||
| the compiler for `__float128` or 128-bit `long double` support. | ||
| [More details](docs/Real16MathSupport.md). | ||
|
|
||
| * `FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT` (values: `"CUDA"`,`"OpenMP"`, `""` default: `""`) | ||
|
|
||
| When set to `CUDA`, builds Flang-RT with experimental support for GPU | ||
| accelerators using CUDA. `CMAKE_CUDA_COMPILER` must be set if not | ||
| automatically detected by CMake. `nvcc` as well as `clang` are supported. | ||
|
|
||
| When set to `OpenMP`, builds Flang-RT with experimental support for | ||
| GPU accelerators using OpenMP offloading. Only Clang is supported for | ||
| `CMAKE_C_COMPILER` and `CMAKE_CXX_COMPILER`. | ||
|
|
||
| * `FLANG_RT_ENABLE_CUF` (bool, default: `OFF`) | ||
|
|
||
| Compiles the `libCufRuntime_cuda_<CUDA-version>.a/.so` library. This is | ||
| independent of `FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT=CUDA` and only | ||
| requires a | ||
| [CUDA Toolkit installation](https://cmake.org/cmake/help/latest/module/FindCUDAToolkit.html) | ||
| (no `CMAKE_CUDA_COMPILER`). | ||
|
|
||
|
|
||
| ### Exprimental CUDA Support | ||
|
|
||
| With `-DFLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT=CUDA`, the following | ||
| additional configuration options become available. | ||
|
|
||
| * `FLANG_RT_LIBCUDACXX_PATH` (path, default: `""`) | ||
|
|
||
| Path to libcu++ package installation. | ||
|
|
||
| * `FLANG_RT_CUDA_RUNTIME_PTX_WITHOUT_GLOBAL_VARS` (boolean, default: `OFF`) | ||
|
|
||
| Do not compile global variables' definitions when producing PTX library. | ||
| Default is `OFF`, meaning global variable definitions are compiled by | ||
| default. | ||
|
|
||
|
|
||
| ### Exprimental OpenMP Offload Support | ||
|
|
||
| With `-DFLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT=OpenMP`, the following | ||
| additional configuration options become available. | ||
|
|
||
| * `FLANG_RT_DEVICE_ARCHITECTURES` (default: `"all"`) | ||
|
|
||
| A list of device architectures that Flang-RT is going to support. | ||
| If `"all"` uses a pre-defined list of architectures. Same purpose as | ||
| `LIBOMPTARGET_DEVICE_ARCHITECTURES` from liboffload. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| /*===-- cmake/config.cmake.in ---------------------------------------*- C -*-=== | ||
| * | ||
| * 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 | ||
| * | ||
| *===----------------------------------------------------------------------===*/ | ||
|
|
||
| #ifndef FORTRAN_RUNTIME_CONFIG_H | ||
| #define FORTRAN_RUNTIME_CONFIG_H | ||
|
|
||
| /* Define to 1 if you have the `strerror_r' function. */ | ||
| #cmakedefine01 HAVE_STRERROR_R | ||
|
|
||
| /* Define to 1 if you have the declaration of `strerror_s', and to 0 if you | ||
| don't. */ | ||
| #cmakedefine01 HAVE_DECL_STRERROR_S | ||
|
|
||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,166 @@ | ||
| #===-- cmake/modules/AddFlangRT.cmake --------------------------------------===# | ||
| # | ||
| # 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 | ||
| # | ||
| #===------------------------------------------------------------------------===# | ||
|
|
||
| # Builds a library with common options for flang-rt. | ||
| # | ||
| # Usage: | ||
| # | ||
| # add_flangrt_library(name sources ... | ||
| # SHARED | ||
| # Build a dynamic (.so/.dll) library | ||
| # STATIC | ||
| # Build a static (.a/.lib) library | ||
| # OBJECT | ||
| # Create only object files without static/dynamic library | ||
| # INSTALL_WITH_TOOLCHAIN | ||
| # Install library into Clang's resource directory so it can be found by the | ||
| # Flang driver during compilation, including tests | ||
| # EXCLUDE_FROM_ALL | ||
| # Do not build library by default; typically used for libraries needed for | ||
| # testing only, no install | ||
| # LINK_TO_LLVM | ||
| # Library requires include path and linking to LLVM's Support component | ||
| # ADDITIONAL_HEADERS | ||
| # May specify header files for IDE generators. | ||
| # ) | ||
| function (add_flangrt_library name) | ||
| set(options STATIC SHARED OBJECT INSTALL_WITH_TOOLCHAIN EXCLUDE_FROM_ALL LINK_TO_LLVM) | ||
| set(multiValueArgs ADDITIONAL_HEADERS) | ||
| cmake_parse_arguments(ARG | ||
| "${options}" | ||
| "" | ||
| "${multiValueArgs}" | ||
| ${ARGN}) | ||
|
|
||
| if (ARG_INSTALL_WITH_TOOLCHAIN AND ARG_EXCLUDE_FROM_ALL) | ||
| message(SEND_ERROR "add_flangrt_library(${name} ...): | ||
| INSTALL_WITH_TOOLCHAIN and EXCLUDE_FROM_ALL are in conflict. When | ||
| installing an artifact it must have been built first in the 'all' target. | ||
| ") | ||
| endif () | ||
|
|
||
| # Also add header files to IDEs to list as part of the library | ||
| set_source_files_properties(${ARG_ADDITIONAL_HEADERS} PROPERTIES HEADER_FILE_ONLY ON) | ||
|
|
||
| # Forward libtype to add_library | ||
| set(extra_args "") | ||
| if (ARG_SHARED) | ||
| list(APPEND extra_args SHARED) | ||
| endif () | ||
| if (ARG_STATIC) | ||
| list(APPEND extra_args STATIC) | ||
| endif () | ||
| if (ARG_OBJECT) | ||
| list(APPEND extra_args OBJECT) | ||
| endif () | ||
| if (ARG_EXCLUDE_FROM_ALL) | ||
| list(APPEND extra_args EXCLUDE_FROM_ALL) | ||
| endif () | ||
|
|
||
| add_library(${name} ${extra_args} ${ARG_ADDITIONAL_HEADERS} ${ARG_UNPARSED_ARGUMENTS}) | ||
|
|
||
| if (ARG_INSTALL_WITH_TOOLCHAIN) | ||
| set_target_properties(${name} PROPERTIES FOLDER "Flang-RT/Toolchain Libraries") | ||
| elseif (ARG_OBJECT) | ||
| set_target_properties(${name} PROPERTIES FOLDER "Flang-RT/Object Libraries") | ||
| else () | ||
| set_target_properties(${name} PROPERTIES FOLDER "Flang-RT/Libraries") | ||
| endif () | ||
|
|
||
| # Minimum required C++ version for Flang-RT, even if CMAKE_CXX_STANDARD is defined to something else. | ||
| target_compile_features(${name} PRIVATE cxx_std_17) | ||
|
|
||
| # Use compiler-specific options to disable exceptions and RTTI. | ||
| if (LLVM_COMPILER_IS_GCC_COMPATIBLE) | ||
| target_compile_options(${name} PRIVATE | ||
| $<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions -fno-rtti -fno-unwind-tables -fno-asynchronous-unwind-tables> | ||
| ) | ||
| elseif (MSVC) | ||
| target_compile_options(${name} PRIVATE | ||
| $<$<COMPILE_LANGUAGE:CXX>:/EHs-c- /GR-> | ||
| ) | ||
| elseif (CMAKE_CXX_COMPILER_ID MATCHES "XL") | ||
| target_compile_options(${name} PRIVATE | ||
| $<$<COMPILE_LANGUAGE:CXX>:-qnoeh -qnortti> | ||
| ) | ||
| endif () | ||
|
|
||
| # Also for CUDA source when compiling with FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT=CUDA | ||
| if (CMAKE_CUDA_COMPILER_ID MATCHES "NVIDIA") | ||
| # Assuming gcc as host compiler. | ||
| target_compile_options(${name} PRIVATE | ||
| $<$<COMPILE_LANGUAGE:CUDA>:--no-exceptions -Xcompiler -fno-rtti -Xcompiler -fno-unwind-tables -Xcompiler -fno-asynchronous-unwind-tables> | ||
| ) | ||
| else () | ||
| # Assuming a clang-compatible CUDA compiler. | ||
| target_compile_options(${name} PRIVATE | ||
| $<$<COMPILE_LANGUAGE:CUDA>:-fno-exceptions -fno-rtti -fno-unwind-tables -fno-asynchronous-unwind-tables> | ||
| ) | ||
| endif () | ||
|
|
||
| # Flang-rt's public headers | ||
| target_include_directories(${name} PRIVATE "${FLANG_RT_SOURCE_DIR}/include") | ||
|
|
||
| # For ISO_Fortran_binding.h to be found by the runtime itself (Accessed as #include "flang/ISO_Fortran_binding.h") | ||
| # User applications can use #include <ISO_Fortran_binding.h> | ||
| target_include_directories(${name} PRIVATE "${FLANG_SOURCE_DIR}/include") | ||
|
|
||
| # For flang-rt's configured config.h to be found | ||
| target_include_directories(${name} PRIVATE "${FLANG_RT_BINARY_DIR}") | ||
|
|
||
| # Disable libstdc++/libc++ assertions, even in an LLVM_ENABLE_ASSERTIONS | ||
| # build, to avoid an unwanted dependency on libstdc++/libc++.so. | ||
| if (FLANG_RT_SUPPORTS_UNDEFINE_FLAG) | ||
| target_compile_options(${name} PUBLIC -U_GLIBCXX_ASSERTIONS) | ||
| target_compile_options(${name} PUBLIC -U_LIBCPP_ENABLE_ASSERTIONS) | ||
| endif () | ||
|
|
||
| # Flang/Clang (including clang-cl) -compiled programs targeting the MSVC ABI | ||
| # should only depend on msv(u)crt. LLVM still emits libgcc/compiler-rt | ||
| # functions in some cases like 128-bit integer math (__udivti3, __modti3, | ||
| # __fixsfti, __floattidf, ...) that msvc does not support. We are injecting a | ||
| # dependency to Compiler-RT's builtin library where these are implemented. | ||
| if (MSVC AND (CMAKE_CXX_COMPILER_ID MATCHES ".*Clang") AND FLANG_RT_BUILTINS_LIBRARY) | ||
| target_compile_options(${name} PRIVATE "$<$<COMPILE_LANGUAGE:CXX,C>:-Xclang>$<$<COMPILE_LANGUAGE:Fortran>:-Xflang>" "--dependent-lib=${FLANG_RT_BUILTINS_LIBRARY}") | ||
| endif () | ||
|
|
||
| # Non-GTest unittests depend on LLVMSupport | ||
| if (ARG_LINK_TO_LLVM) | ||
| if (LLVM_LINK_LLVM_DYLIB) | ||
| set(llvm_libs LLVM) | ||
| else() | ||
| llvm_map_components_to_libnames(llvm_libs Support) | ||
| endif() | ||
| target_link_libraries(${name} PUBLIC ${llvm_libs}) | ||
| target_include_directories(${name} PUBLIC ${LLVM_INCLUDE_DIRS}) | ||
| endif () | ||
|
|
||
| # If this is part of the toolchain, put it into the compiler's resource | ||
| # directory. Otherwise it is part of testing and is not installed at all. | ||
| # TODO: Consider multi-configuration builds (MSVC_IDE, "Ninja Multi-Config") | ||
| if (ARG_INSTALL_WITH_TOOLCHAIN) | ||
| set_target_properties(${name} | ||
| PROPERTIES | ||
| LIBRARY_OUTPUT_DIRECTORY "${FLANG_RT_BUILD_LIB_DIR}" | ||
| ARCHIVE_OUTPUT_DIRECTORY "${FLANG_RT_BUILD_LIB_DIR}" | ||
| RUNTIME_OUTPUT_DIRECTORY "${FLANG_RT_BUILD_LIB_DIR}" | ||
| ) | ||
|
|
||
| install(TARGETS ${name} | ||
| LIBRARY DESTINATION "${FLANG_RT_INSTALL_LIB_DIR}" | ||
| ARCHIVE DESTINATION "${FLANG_RT_INSTALL_LIB_DIR}" | ||
| RUNTIME DESTINATION "${FLANG_RT_INSTALL_LIB_DIR}" | ||
| ) | ||
| endif () | ||
|
|
||
| # flang-rt should build all the flang-rt targets that are built in an | ||
| # 'all' build. | ||
| if (NOT ARG_EXCLUDE_FROM_ALL) | ||
| add_dependencies(flang-rt ${name}) | ||
| endif () | ||
| endfunction (add_flangrt_library) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| #===-- lib/CMakeLists.txt --------------------------------------------------===# | ||
| # | ||
| # 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 | ||
| # | ||
| #===------------------------------------------------------------------------===# | ||
|
|
||
| add_subdirectory(FortranFloat128Math) | ||
| add_subdirectory(flang_rt) | ||
|
|
||
| if (FLANG_RT_ENABLE_CUF) | ||
| add_subdirectory(CufRuntime) | ||
| endif() | ||
|
|
||
| if (FLANG_RT_INCLUDE_TESTS) | ||
| add_subdirectory(Testing) | ||
| endif () |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| #===-- lib/Testing/CMakeLists.txt ------------------------------------------===# | ||
| # | ||
| # 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 | ||
| # | ||
| #===------------------------------------------------------------------------===# | ||
|
|
||
| set(public_headers "") | ||
| file(GLOB_RECURSE public_headers | ||
| "${FLANG_SOURCE_DIR}/lib/Testing/*.h" | ||
| ) | ||
|
|
||
| add_flangrt_library(NonGTestTesting EXCLUDE_FROM_ALL LINK_TO_LLVM | ||
| ${FLANG_SOURCE_DIR}/lib/Testing/testing.cpp | ||
| ${FLANG_SOURCE_DIR}/lib/Testing/fp-testing.cpp | ||
| ADDITIONAL_HEADERS | ||
| ${public_headers} | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,192 @@ | ||
| #===-- lib/flang_rt/CMakeLists.txt -----------------------------------------===# | ||
| # | ||
| # 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 | ||
| # | ||
| #===------------------------------------------------------------------------===# | ||
|
|
||
| include(AddFlangRTOffload) | ||
| # function checks | ||
| find_package(Backtrace) | ||
| set(HAVE_BACKTRACE ${Backtrace_FOUND}) | ||
| set(BACKTRACE_HEADER ${Backtrace_HEADER}) | ||
|
|
||
|
|
||
| # List of files that are buildable for all devices. | ||
| set(supported_sources | ||
| ISO_Fortran_binding.cpp | ||
| allocator-registry.cpp | ||
| allocatable.cpp | ||
| array-constructor.cpp | ||
| assign.cpp | ||
| buffer.cpp | ||
| character.cpp | ||
| connection.cpp | ||
| copy.cpp | ||
| derived-api.cpp | ||
| derived.cpp | ||
| descriptor-io.cpp | ||
| descriptor.cpp | ||
| dot-product.cpp | ||
| edit-input.cpp | ||
| edit-output.cpp | ||
| environment.cpp | ||
| external-unit.cpp | ||
| extrema.cpp | ||
| file.cpp | ||
| findloc.cpp | ||
| format.cpp | ||
| inquiry.cpp | ||
| internal-unit.cpp | ||
| io-api.cpp | ||
| io-api-minimal.cpp | ||
| io-error.cpp | ||
| io-stmt.cpp | ||
| iostat.cpp | ||
| matmul-transpose.cpp | ||
| matmul.cpp | ||
| memory.cpp | ||
| misc-intrinsic.cpp | ||
| namelist.cpp | ||
| non-tbp-dio.cpp | ||
| numeric.cpp | ||
| pointer.cpp | ||
| product.cpp | ||
| pseudo-unit.cpp | ||
| ragged.cpp | ||
| stat.cpp | ||
| sum.cpp | ||
| support.cpp | ||
| terminator.cpp | ||
| tools.cpp | ||
| transformational.cpp | ||
| type-code.cpp | ||
| type-info.cpp | ||
| unit.cpp | ||
| unit-map.cpp | ||
| utf.cpp | ||
| ) | ||
|
|
||
| # List of source not used for GPU offloading. | ||
| set(host_sources | ||
| ${FLANG_SOURCE_DIR}/lib/Common/binary-to-decimal.cpp | ||
| ${FLANG_SOURCE_DIR}/lib/Common/decimal-to-binary.cpp | ||
| command.cpp | ||
| complex-powi.cpp | ||
| complex-reduction.c | ||
| exceptions.cpp | ||
| execute.cpp | ||
| extensions.cpp | ||
| ${FLANG_SOURCE_DIR}/module/iso_fortran_env_impl.f90 | ||
| main.cpp | ||
| random.cpp | ||
| reduce.cpp | ||
| reduction.cpp | ||
| stop.cpp | ||
| temporary-stack.cpp | ||
| time-intrinsic.cpp | ||
| ) | ||
|
|
||
| file(GLOB_RECURSE public_headers | ||
| "${FLANG_RT_SOURCE_DIR}/include/flang_rt/*.h" | ||
| "${FLANG_SOURCE_DIR}/include/flang/Common/*.h" | ||
| ) | ||
|
|
||
| file(GLOB_RECURSE private_headers | ||
| "${FLANG_RT_SOURCE_DIR}/lib/flang_rt/*.h" | ||
| "${FLANG_SOURCE_DIR}/lib/Common/*.h" | ||
| ) | ||
|
|
||
|
|
||
| # Import changes from sibling FortranFloat128Math | ||
| get_target_property(f128_sources | ||
| FortranFloat128MathILib INTERFACE_SOURCES | ||
| ) | ||
| if (f128_sources) | ||
| # The interface may define special macros for Float128Math files, | ||
| # so we need to propagate them. | ||
| get_target_property(f128_defs | ||
| FortranFloat128MathILib INTERFACE_COMPILE_DEFINITIONS | ||
| ) | ||
| set_property(SOURCE ${f128_sources} | ||
| APPEND PROPERTY COMPILE_DEFINITIONS | ||
| ${f128_defs} | ||
| ) | ||
| get_target_property(f128_include_dirs | ||
| FortranFloat128MathILib INTERFACE_INCLUDE_DIRECTORIES | ||
| ) | ||
| set_property(SOURCE ${f128_sources} | ||
| APPEND PROPERTY INCLUDE_DIRECTORIES | ||
| ${f128_include_dirs} | ||
| ) | ||
| else () | ||
| set(f128_sources "") | ||
| endif () | ||
|
|
||
|
|
||
| set(sources ${supported_sources} ${host_sources} ${f128_sources}) | ||
|
|
||
| if (NOT WIN32) | ||
| add_flangrt_library(flang_rt STATIC | ||
| ${sources} | ||
| INSTALL_WITH_TOOLCHAIN | ||
| ADDITIONAL_HEADERS ${public_headers} ${private_headers} | ||
| ) | ||
|
|
||
| enable_cuda_compilation(flang_rt "${supported_sources}") | ||
| enable_omp_offload_compilation(flang_rt "${supported_sources}") | ||
|
|
||
| # For unittests that depend on flang_rt. Should link to the static version | ||
| # of the library. | ||
| add_library(flang_rt.static ALIAS flang_rt) | ||
| add_library(flang_rt.unittest ALIAS flang_rt) | ||
| else() | ||
| # Target for building all versions of the runtime | ||
| add_custom_target(flang_rt) | ||
| set_target_properties(flang_rt PROPERTIES FOLDER "Flang-RT/Meta") | ||
|
|
||
| function (add_win_flangrt_library libtype suffix msvc_lib) | ||
| set(name "flang_rt.${suffix}") | ||
| add_flangrt_library(${name} ${libtype} | ||
| ${sources} | ||
| ${ARGN} | ||
| ADDITIONAL_HEADERS ${public_headers} ${private_headers} | ||
| ) | ||
|
|
||
| # Setting an unique Fortran_MODULE_DIRECTORY is required for each variant to | ||
| # write a different .mod file. | ||
| set_target_properties(${name} | ||
| PROPERTIES | ||
| MSVC_RUNTIME_LIBRARY ${msvc_lib} | ||
| Fortran_MODULE_DIRECTORY "module.${suffix}" | ||
| ) | ||
|
|
||
| enable_cuda_compilation(${name} "${supported_sources}") | ||
| enable_omp_offload_compilation(${name} "${supported_sources}") | ||
| add_dependencies(flang_rt ${name}) | ||
| endfunction () | ||
|
|
||
| add_win_flangrt_library(STATIC static MultiThreaded INSTALL_WITH_TOOLCHAIN) | ||
| add_win_flangrt_library(STATIC static_dbg MultiThreadedDebug INSTALL_WITH_TOOLCHAIN) | ||
|
|
||
| # unittests link against LLVMSupport which is compiled with /MD | ||
| add_win_flangrt_library(STATIC unittest MultiThreadedDLL EXCLUDE_FROM_ALL) | ||
|
|
||
| # FIXME: Generating runtime DLLs is currently not possible. There are two | ||
| # roadblocks: | ||
| # | ||
| # * Flang emits /DEFAULTLIB:flang_rt.dynamic.lib into | ||
| # iso_fortran_env_impl.f90.obj. Because that file is itself part of | ||
| # flang_rt.dynamic, this results in a recursive dependency when invoking | ||
| # the linker. | ||
| # | ||
| # * The externally-visible functions must either be annotated with | ||
| # __declspec(dllexport), or listed in an exports file. A possible workaround | ||
| # is CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS which would also export the internal | ||
| # C++ symbols and still requires global data symbols to be annotated | ||
| # manually. | ||
| # | ||
| #add_win_flangrt_library(SHARED dynamic MultiThreadedDLL) | ||
| #add_win_flangrt_library(SHARED dynamic_dbg MultiThreadedDebugDLL) | ||
| endif() |