234 changes: 234 additions & 0 deletions flang-rt/LICENSE.TXT
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.
198 changes: 198 additions & 0 deletions flang-rt/README.md
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.
19 changes: 19 additions & 0 deletions flang-rt/cmake/config.h.cmake.in
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
166 changes: 166 additions & 0 deletions flang-rt/cmake/modules/AddFlangRT.cmake
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
@@ -1,21 +1,13 @@
option(FLANG_EXPERIMENTAL_CUDA_RUNTIME
"Compile Fortran runtime as CUDA sources (experimental)" OFF
)

option(FLANG_CUDA_RUNTIME_PTX_WITHOUT_GLOBAL_VARS
"Do not compile global variables' definitions when producing PTX library" OFF
)

set(FLANG_LIBCUDACXX_PATH "" CACHE PATH "Path to libcu++ package installation")

set(FLANG_EXPERIMENTAL_OMP_OFFLOAD_BUILD "off" CACHE STRING
"Compile Fortran runtime as OpenMP target offload sources (experimental). Valid options are 'off', 'host_device', 'nohost'")

set(FLANG_OMP_DEVICE_ARCHITECTURES "all" CACHE STRING
"List of OpenMP device architectures to be used to compile the Fortran runtime (e.g. 'gfx1103;sm_90')")
#===-- cmake/modules/AddFortranRTOffload.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
#
#===------------------------------------------------------------------------===#

macro(enable_cuda_compilation name files)
if (FLANG_EXPERIMENTAL_CUDA_RUNTIME)
if (FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT STREQUAL "CUDA")
if (BUILD_SHARED_LIBS)
message(FATAL_ERROR
"BUILD_SHARED_LIBS is not supported for CUDA build of Fortran runtime"
Expand Down Expand Up @@ -50,43 +42,34 @@ macro(enable_cuda_compilation name files)
"${CUDA_COMPILE_OPTIONS}"
)

if (EXISTS "${FLANG_LIBCUDACXX_PATH}/include")
# When using libcudacxx headers files, we have to use them
# for all files of F18 runtime.
include_directories(AFTER ${FLANG_LIBCUDACXX_PATH}/include)
add_compile_definitions(RT_USE_LIBCUDACXX=1)
endif()

# Add an OBJECT library consisting of CUDA PTX.
llvm_add_library(${name}PTX OBJECT PARTIAL_SOURCES_INTENDED ${files})
# Create a .a library consisting of CUDA PTX.
# This is different from a regular static library. The CUDA_PTX_COMPILATION
# property can only be applied to object libraries and create *.ptx files
# instead of *.o files. The .a will consist of those *.ptx files only.
add_flangrt_library(obj.${name}PTX OBJECT ${files})
set_property(TARGET obj.${name}PTX PROPERTY CUDA_PTX_COMPILATION ON)
if (FLANG_CUDA_RUNTIME_PTX_WITHOUT_GLOBAL_VARS)
add_flangrt_library(${name}PTX STATIC "$<TARGET_OBJECTS:obj.${name}PTX>")

# Apply configuration options
if (FLANG_RT_CUDA_RUNTIME_PTX_WITHOUT_GLOBAL_VARS)
target_compile_definitions(obj.${name}PTX
PRIVATE FLANG_RUNTIME_NO_GLOBAL_VAR_DEFS
PRIVATE FLANG_RT_NO_GLOBAL_VAR_DEFS
)
endif()

# When using libcudacxx headers files, we have to use them
# for all files of Flang-RT.
if (EXISTS "${FLANG_RT_LIBCUDACXX_PATH}/include")
target_include_directories(obj.${name}PTX AFTER PRIVATE "${FLANG_RT_LIBCUDACXX_PATH}/include")
target_compile_definitions(obj.${name}PTX PRIVATE RT_USE_LIBCUDACXX=1)
endif ()
endif()
endmacro()

macro(enable_omp_offload_compilation files)
if (NOT FLANG_EXPERIMENTAL_OMP_OFFLOAD_BUILD STREQUAL "off")
# 'host_device' build only works with Clang compiler currently.
# The build is done with the CMAKE_C/CXX_COMPILER, i.e. it does not use
# the in-tree built Clang. We may have a mode that would use the in-tree
# built Clang.
#
# 'nohost' is supposed to produce an LLVM Bitcode library,
# and it has to be done with a C/C++ compiler producing LLVM Bitcode
# compatible with the LLVM toolchain version distributed with the Flang
# compiler.
# In general, the in-tree built Clang should be used for 'nohost' build.
# Note that 'nohost' build does not produce the host version of Flang
# runtime library, so there will be two separate distributable objects.
# 'nohost' build is a TODO.
macro(enable_omp_offload_compilation name files)
if (FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT STREQUAL "OpenMP")
# OpenMP offload build only works with Clang compiler currently.

if (NOT FLANG_EXPERIMENTAL_OMP_OFFLOAD_BUILD STREQUAL "host_device")
message(FATAL_ERROR "Unsupported OpenMP offload build of Flang runtime")
endif()
if (BUILD_SHARED_LIBS)
message(FATAL_ERROR
"BUILD_SHARED_LIBS is not supported for OpenMP offload build of Fortran runtime"
Expand All @@ -111,13 +94,13 @@ macro(enable_omp_offload_compilation files)
"${all_amdgpu_architectures};${all_nvptx_architectures}"
)
# TODO: support auto detection on the build system.
if (FLANG_OMP_DEVICE_ARCHITECTURES STREQUAL "all")
set(FLANG_OMP_DEVICE_ARCHITECTURES ${all_gpu_architectures})
if (FLANG_RT_DEVICE_ARCHITECTURES STREQUAL "all")
set(FLANG_RT_DEVICE_ARCHITECTURES ${all_gpu_architectures})
endif()
list(REMOVE_DUPLICATES FLANG_OMP_DEVICE_ARCHITECTURES)
list(REMOVE_DUPLICATES FLANG_RT_DEVICE_ARCHITECTURES)

string(REPLACE ";" "," compile_for_architectures
"${FLANG_OMP_DEVICE_ARCHITECTURES}"
"${FLANG_RT_DEVICE_ARCHITECTURES}"
)

set(OMP_COMPILE_OPTIONS
Expand All @@ -131,14 +114,15 @@ macro(enable_omp_offload_compilation files)
set_source_files_properties(${files} PROPERTIES COMPILE_OPTIONS
"${OMP_COMPILE_OPTIONS}"
)
target_link_options(${name} PUBLIC ${OMP_COMPILE_OPTIONS})

# Enable "declare target" in the source code.
set_source_files_properties(${files}
PROPERTIES COMPILE_DEFINITIONS OMP_OFFLOAD_BUILD
)
else()
message(FATAL_ERROR
"Flang runtime build is not supported for these compilers:\n"
"Flang-rt build with OpenMP offload is not supported for these compilers:\n"
"CMAKE_CXX_COMPILER_ID: ${CMAKE_CXX_COMPILER_ID}\n"
"CMAKE_C_COMPILER_ID: ${CMAKE_C_COMPILER_ID}")
endif()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
//===-- include/flang/Runtime/CUDA/allocator.h ------------------*- C++ -*-===//
//===-- include/flang-rt/CUDA/allocator.h -----------------------*- 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_CUDA_ALLOCATOR_H_
#define FORTRAN_RUNTIME_CUDA_ALLOCATOR_H_
#ifndef FLANG_RT_CUDA_ALLOCATOR_H_
#define FLANG_RT_CUDA_ALLOCATOR_H_

#include "common.h"
#include "flang/Runtime/CUDA/common.h"
#include "flang/Runtime/descriptor-consts.h"
#include "flang/Runtime/entry-names.h"

Expand All @@ -33,4 +33,4 @@ void *CUFAllocUnified(std::size_t);
void CUFFreeUnified(void *);

} // namespace Fortran::runtime::cuda
#endif // FORTRAN_RUNTIME_CUDA_ALLOCATOR_H_
#endif /* FLANG_RT_CUDA_ALLOCATOR_H_ */
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//===-- runtime/allocator-registry.h ----------------------------*- C++ -*-===//
//===-- include/flang-rt/allocator-registry.h -------------------*- 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_ALLOCATOR_REGISTRY_H_
#define FORTRAN_RUNTIME_ALLOCATOR_REGISTRY_H_
#ifndef FLANG_RT_ALLOCATOR_REGISTRY_H_
#define FLANG_RT_ALLOCATOR_REGISTRY_H_

#include "flang/Common/api-attrs.h"
#include "flang/Runtime/allocator-registry-consts.h"
Expand Down Expand Up @@ -55,4 +55,4 @@ RT_OFFLOAD_VAR_GROUP_END

} // namespace Fortran::runtime

#endif // FORTRAN_RUNTIME_ALLOCATOR_REGISTRY_H_
#endif /* FLANG_RT_ALLOCATOR_REGISTRY_H_ */
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- include/flang/Runtime/array-constructor.h ---------------*- C++ -*-===//
//===-- include/flang-rt/array-constructor.h --------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand All @@ -9,11 +9,11 @@
// External APIs to create temporary storage for array constructors when their
// final extents or length parameters cannot be pre-computed.

#ifndef FORTRAN_RUNTIME_ARRAYCONSTRUCTOR_H_
#define FORTRAN_RUNTIME_ARRAYCONSTRUCTOR_H_
#ifndef FLANG_RT_ARRAY_CONSTRUCTOR_H_
#define FLANG_RT_ARRAY_CONSTRUCTOR_H_

#include "flang-rt/descriptor.h"
#include "flang/Runtime/array-constructor-consts.h"
#include "flang/Runtime/descriptor.h"
#include "flang/Runtime/entry-names.h"
#include <cstdint>

Expand Down Expand Up @@ -44,14 +44,6 @@ struct ArrayConstructorVector {
unsigned char useValueLengthParameters_ : 1;
};

static_assert(sizeof(Fortran::runtime::ArrayConstructorVector) <=
MaxArrayConstructorVectorSizeInBytes,
"ABI requires sizeof(ArrayConstructorVector) to be smaller than "
"MaxArrayConstructorVectorSizeInBytes");
static_assert(alignof(Fortran::runtime::ArrayConstructorVector) <=
MaxArrayConstructorVectorAlignInBytes,
"ABI requires alignof(ArrayConstructorVector) to be smaller than "
"MaxArrayConstructorVectorAlignInBytes");

} // namespace Fortran::runtime
#endif // FORTRAN_RUNTIME_ARRAYCONSTRUCTOR_H_
#endif /* FLANG_RT_ARRAY_CONSTRUCTOR_H_ */
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//===-- include/flang/Runtime/descriptor.h ----------------------*- C++ -*-===//
//===-- include/flang-rt/descriptor.h ---------------------------*- 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_DESCRIPTOR_H_
#define FORTRAN_RUNTIME_DESCRIPTOR_H_
#ifndef FLANG_RT_DESCRIPTOR_H_
#define FLANG_RT_DESCRIPTOR_H_

// Defines data structures used during execution of a Fortran program
// to implement nontrivial dummy arguments, pointers, allocatables,
Expand All @@ -18,10 +18,10 @@
// User C code is welcome to depend on that ISO_Fortran_binding.h file,
// but should never reference this internal header.

#include "flang/ISO_Fortran_binding_wrapper.h"
#include "flang-rt/memory.h"
#include "flang-rt/type-code.h"
#include "flang/Common/ISO_Fortran_binding_wrapper.h"
#include "flang/Runtime/descriptor-consts.h"
#include "flang/Runtime/memory.h"
#include "flang/Runtime/type-code.h"
#include <algorithm>
#include <cassert>
#include <cinttypes>
Expand Down Expand Up @@ -482,4 +482,4 @@ class alignas(Descriptor) StaticDescriptor {
};

} // namespace Fortran::runtime
#endif // FORTRAN_RUNTIME_DESCRIPTOR_H_
#endif /* FLANG_RT_DESCRIPTOR_H_ */
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- include/flang/Runtime/memory.h --------------------------*- C++ -*-===//
//===-- include/flang-rt/memory.h -------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand All @@ -9,8 +9,8 @@
// Thin wrapper around malloc()/free() to isolate the dependency,
// ease porting, and provide an owning pointer.

#ifndef FORTRAN_RUNTIME_MEMORY_H_
#define FORTRAN_RUNTIME_MEMORY_H_
#ifndef FLANG_RT_MEMORY_H_
#define FLANG_RT_MEMORY_H_

#include "flang/Common/api-attrs.h"
#include <cassert>
Expand Down Expand Up @@ -170,4 +170,4 @@ template <typename A> struct Allocator {
};
} // namespace Fortran::runtime

#endif // FORTRAN_RUNTIME_MEMORY_H_
#endif /* FLANG_RT_MEMORY_H_ */
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
//===-- include/flang/Runtime/type-code.h -----------------------*- C++ -*-===//
//===-- include/flang-rt/type-code.h ----------------------------*- 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_TYPE_CODE_H_
#define FORTRAN_RUNTIME_TYPE_CODE_H_
#ifndef FLANG_RT_TYPE_CODE_H_
#define FLANG_RT_TYPE_CODE_H_

#include "flang/Common/Fortran-consts.h"
#include "flang/Common/ISO_Fortran_binding_wrapper.h"
#include "flang/Common/optional.h"
#include "flang/ISO_Fortran_binding_wrapper.h"
#include <utility>

namespace Fortran::runtime {
Expand Down Expand Up @@ -75,4 +75,4 @@ class TypeCode {
ISO::CFI_type_t raw_{CFI_type_other};
};
} // namespace Fortran::runtime
#endif // FORTRAN_RUNTIME_TYPE_CODE_H_
#endif /* FLANG_RT_TYPE_CODE_H_ */
18 changes: 18 additions & 0 deletions flang-rt/lib/CMakeLists.txt
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
@@ -1,27 +1,25 @@
#===-- runtime/CUDA/CMakeLists.txt -----------------------------------------===#
#===-- lib/CufRuntime/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_directories(${CUDAToolkit_INCLUDE_DIRS})

# libCufRuntime depends on a certain version of CUDA. To be able to have
# multiple build of this library with different CUDA version, the version is
# added to the library name.
set(CUFRT_LIBNAME CufRuntime_cuda_${CUDAToolkit_VERSION_MAJOR})

add_flang_library(${CUFRT_LIBNAME}
allocator.cpp
add_flangrt_library(${CUFRT_LIBNAME}
allocatable.cpp
allocator.cpp
descriptor.cpp
kernel.cpp
memmove-function.cpp
memory.cpp
registration.cpp
)
target_include_directories(${CUFRT_LIBNAME} PRIVATE ${CUDAToolkit_INCLUDE_DIRS})

if (BUILD_SHARED_LIBS)
set(CUDA_RT_TARGET CUDA::cudart)
Expand All @@ -31,6 +29,11 @@ endif()

target_link_libraries(${CUFRT_LIBNAME}
PRIVATE
FortranRuntime
flang_rt
${CUDA_RT_TARGET}
)

# Phony build target that does not include the CUDA version.
add_custom_target(CufRuntime)
add_dependencies(CufRuntime ${CUFRT_LIBNAME})

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/CUDA/allocatable.cpp --------------------------------------===//
//===-- lib/CufRuntime/allocatable.cpp --------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand All @@ -7,9 +7,10 @@
//===----------------------------------------------------------------------===//

#include "flang/Runtime/CUDA/allocatable.h"
#include "../assign-impl.h"
#include "../stat.h"
#include "../terminator.h"
#include "flang-rt/descriptor.h"
#include "../flang_rt/assign-impl.h"
#include "../flang_rt/stat.h"
#include "../flang_rt/terminator.h"
#include "flang/Runtime/CUDA/common.h"
#include "flang/Runtime/CUDA/descriptor.h"
#include "flang/Runtime/CUDA/memmove-function.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
//===-- runtime/CUDA/allocator.cpp ----------------------------------------===//
//===-- lib/CufRuntime/allocator.cpp ----------------------------*- 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
//
//===----------------------------------------------------------------------===//

#include "flang/Runtime/CUDA/allocator.h"
#include "../derived.h"
#include "../stat.h"
#include "../terminator.h"
#include "../type-info.h"
#include "flang/Common/Fortran.h"
#include "flang/ISO_Fortran_binding_wrapper.h"
#include "flang-rt/CUDA/allocator.h"
#include "flang-rt/allocator-registry.h"
#include "../flang_rt/derived.h"
#include "../flang_rt/stat.h"
#include "../flang_rt/terminator.h"
#include "../flang_rt/type-info.h"
#include "flang/Common/ISO_Fortran_binding_wrapper.h"
#include "flang/Runtime/CUDA/common.h"
#include "flang/Runtime/allocator-registry.h"
#include "flang/Support/Fortran.h"

#include "cuda_runtime.h"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/CUDA/descriptor.cpp ---------------------------------------===//
//===-- lib/CufRuntime/descriptor.cpp ---------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand All @@ -7,10 +7,10 @@
//===----------------------------------------------------------------------===//

#include "flang/Runtime/CUDA/descriptor.h"
#include "../terminator.h"
#include "flang/Runtime/CUDA/allocator.h"
#include "flang-rt/CUDA/allocator.h"
#include "flang-rt/descriptor.h"
#include "../flang_rt/terminator.h"
#include "flang/Runtime/CUDA/common.h"
#include "flang/Runtime/descriptor.h"

#include "cuda_runtime.h"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/CUDA/kernel.cpp -------------------------------------------===//
//===-- lib/CufRuntime/kernel.cpp -------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand All @@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//

#include "flang/Runtime/CUDA/kernel.h"
#include "../terminator.h"
#include "../flang_rt/terminator.h"
#include "flang/Runtime/CUDA/common.h"

#include "cuda_runtime.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/CUDA/memory.cpp -------------------------------------------===//
//===-- lib/CufRuntime/memory.cpp -------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand All @@ -7,8 +7,8 @@
//===----------------------------------------------------------------------===//

#include "flang/Runtime/CUDA/memory.h"
#include "../assign-impl.h"
#include "../terminator.h"
#include "../flang_rt/assign-impl.h"
#include "../flang_rt/terminator.h"
#include "flang/Runtime/CUDA/common.h"
#include "flang/Runtime/CUDA/descriptor.h"
#include "flang/Runtime/CUDA/memmove-function.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/CUDA/registration.cpp -------------------------------------===//
//===-- lib/CufRuntime/registration.cpp -------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand All @@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//

#include "flang/Runtime/CUDA/registration.h"
#include "../terminator.h"
#include "../flang_rt/terminator.h"
#include "flang/Runtime/CUDA/common.h"

#include "cuda_runtime.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#===-- runtime/Float128Math/CMakeLists.txt ---------------------------------===#
#===-- lib/FortranFloat128Math/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.
Expand All @@ -15,6 +15,7 @@
# used for building this FortranFloat128Math library.

include(CheckLibraryExists)
include(CheckIncludeFile)

set(sources
acos.cpp
Expand Down Expand Up @@ -93,32 +94,31 @@ if (FLANG_RUNTIME_F128_MATH_LIB)
)
endif()

add_flang_library(FortranFloat128Math STATIC INSTALL_WITH_TOOLCHAIN
${sources})

if (DEFINED MSVC)
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded)
add_flang_library(FortranFloat128Math.static STATIC INSTALL_WITH_TOOLCHAIN
${sources}
)
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDebug)
add_flang_library(FortranFloat128Math.static_dbg STATIC INSTALL_WITH_TOOLCHAIN
${sources}
)
add_dependencies(FortranFloat128Math FortranFloat128Math.static
FortranFloat128Math.static_dbg
)
endif()
if (WIN32)
# Do not create a FortranFloat128Math library under Windows, the Flang
# driver never links it. Instead, add the sources to the flang_rt itself.
target_sources(FortranFloat128MathILib INTERFACE ${sources})
target_compile_definitions(FortranFloat128MathILib INTERFACE HAS_QUADMATHLIB)
else ()
add_flangrt_library(FortranFloat128Math STATIC INSTALL_WITH_TOOLCHAIN
${sources})
endif ()
target_include_directories(FortranFloat128Math PRIVATE
"${FLANG_RT_SOURCE_DIR}/lib/flang_rt"
)
elseif (HAVE_LDBL_MANT_DIG_113)
# We can use 'long double' versions from libc.
check_library_exists(m sinl "" FOUND_LIBM)
if (FOUND_LIBM)
target_compile_definitions(FortranFloat128MathILib INTERFACE
HAS_LIBM
)
target_include_directories(FortranFloat128MathILib INTERFACE
"${FLANG_RT_SOURCE_DIR}/lib/flang_rt"
)
target_sources(FortranFloat128MathILib INTERFACE ${sources})
else()
message(FATAL_ERROR "FortranRuntime cannot build without libm")
message(FATAL_ERROR "Flang-RT cannot build without libm")
endif()
else()
# We can use '__float128' version from libc, if it has them.
Expand All @@ -127,6 +127,9 @@ else()
target_compile_definitions(FortranFloat128MathILib INTERFACE
HAS_LIBMF128
)
target_include_directories(FortranFloat128MathILib INTERFACE
"${FLANG_RT_SOURCE_DIR}/lib/flang_rt"
)
# Enable this, when math-entries.h and complex-math.h is ready.
# target_sources(FortranFloat128MathILib INTERFACE ${sources})
endif()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/acos.cpp -------------------------------------===//
//===-- lib/FortranFloat128Math/acos.cpp ------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/acosh.cpp ------------------------------------===//
//===-- lib/FortranFloat128Math/acosh.cpp -----------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/asin.cpp -------------------------------------===//
//===-- lib/FortranFloat128Math/asin.cpp ------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/asinh.cpp ------------------------------------===//
//===-- lib/FortranFloat128Math/asinh.cpp -----------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/atan.cpp -------------------------------------===//
//===-- lib/FortranFloat128Math/atan.cpp ------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/atan2.cpp ------------------------------------===//
//===-- lib/FortranFloat128Math/atan2.cpp -----------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/atanh.cpp ------------------------------------===//
//===-- lib/FortranFloat128Math/atanh.cpp -----------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/ceil.cpp -------------------------------------===//
//===-- lib/FortranFloat128Math/ceil.cpp ------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
/*===-- runtime/Float128Math/complex-math.c -------------------------*- C -*-===
/*===-- lib/FortranFloat128Math/complex-math.c ----------------------*- 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
*
* ===-----------------------------------------------------------------------===
*/
*===----------------------------------------------------------------------===*/

#include "complex-math.h"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*===-- runtime/Float128Math/complex-math.h -------------------------*- C -*-===
/*===-- lib/FortranFloat128Math/complex-math.h ----------------------*- 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_FLOAT128MATH_COMPLEX_MATH_H_
#define FORTRAN_RUNTIME_FLOAT128MATH_COMPLEX_MATH_H_
#ifndef FLANG_RT_FORTRANFLOAT128MATH_COMPLEX_MATH_H_
#define FLANG_RT_FORTRANFLOAT128MATH_COMPLEX_MATH_H_

#include "flang/Common/float128.h"
#include "flang/Runtime/entry-names.h"
Expand Down Expand Up @@ -59,4 +59,4 @@
#error "Float128Math build with glibc>=2.26 is unsupported yet"
#endif

#endif /* FORTRAN_RUNTIME_FLOAT128MATH_COMPLEX_MATH_H_ */
#endif /* FLANG_RT_FORTRANFLOAT128MATH_COMPLEX_MATH_H_ */
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/cos.cpp --------------------------------------===//
//===-- lib/FortranFloat128Math/cos.cpp -------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/cosh.cpp -------------------------------------===//
//===-- lib/FortranFloat128Math/cosh.cpp ------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/erf.cpp --------------------------------------===//
//===-- lib/FortranFloat128Math/erf.cpp -------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/erfc.cpp -------------------------------------===//
//===-- lib/FortranFloat128Math/erfc.cpp ------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/exp.cpp --------------------------------------===//
//===-- lib/FortranFloat128Math/exp.cpp -------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/exponent.cpp ---------------------------------===//
//===-- lib/FortranFloat128Math/exponent.cpp --------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/floor.cpp ------------------------------------===//
//===-- lib/FortranFloat128Math/floor.cpp -----------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/fma.cpp --------------------------------------===//
//===-- lib/FortranFloat128Math/fma.cpp -------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/fraction.cpp ---------------------------------===//
//===-- lib/FortranFloat128Math/fraction.cpp --------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/hypot.cpp ------------------------------------===//
//===-- lib/FortranFloat128Math/hypot.cpp -----------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/j0.cpp ---------------------------------------===//
//===-- lib/FortranFloat128Math/j0.cpp --------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/j1.cpp ---------------------------------------===//
//===-- lib/FortranFloat128Math/j1.cpp --------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/jn.cpp ---------------------------------------===//
//===-- lib/FortranFloat128Math/jn.cpp --------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/lgamma.cpp -----------------------------------===//
//===-- lib/FortranFloat128Math/lgamma.cpp ----------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/llround.cpp ----------------------------------===//
//===-- lib/FortranFloat128Math/llround.cpp ---------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/log.cpp --------------------------------------===//
//===-- lib/FortranFloat128Math/log.cpp -------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/log10.cpp ------------------------------------===//
//===-- lib/FortranFloat128Math/log10.cpp -----------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/lround.cpp -----------------------------------===//
//===-- lib/FortranFloat128Math/lround.cpp ----------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//===-- runtime/Float128Math/math-entries.h ---------------------*- C++ -*-===//
//===-- lib/FortranFloat128Math/math-entries.h ------------------*- 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_FLOAT128MATH_MATH_ENTRIES_H_
#define FORTRAN_RUNTIME_FLOAT128MATH_MATH_ENTRIES_H_
#ifndef FLANG_RT_FORTRANFLOAT128MATH_MATH_ENTRIES_H_
#define FLANG_RT_FORTRANFLOAT128MATH_MATH_ENTRIES_H_
#include "terminator.h"
#include "tools.h"
#include "flang/Common/float128.h"
Expand Down Expand Up @@ -231,4 +231,4 @@ DEFINE_SIMPLE_ALIAS(Yn, ynl)

} // namespace Fortran::runtime

#endif // FORTRAN_RUNTIME_FLOAT128MATH_MATH_ENTRIES_H_
#endif /* FLANG_RT_FORTRANFLOAT128MATH_MATH_ENTRIES_H_ */
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/mod-real.cpp ---------------------------------===//
//===-- lib/FortranFloat128Math/mod-real.cpp --------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/modulo-real.cpp ------------------------------===//
//===-- lib/FortranFloat128Math/modulo-real.cpp -----------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/nearbyint.cpp --------------------------------===//
//===-- lib/FortranFloat128Math/nearbyint.cpp -------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/nearest.cpp ----------------------------------===//
//===-- lib/FortranFloat128Math/nearest.cpp ---------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/norm2.cpp ------------------------------------===//
//===-- lib/FortranFloat128Math/norm2.cpp -----------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//===-- runtime/Float128Math/numeric-template-specs.h -----------*- C++ -*-===//
//===-- lib/FortranFloat128Math/numeric-template-specs.h --------*- 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_FLOAT128MATH_NUMERIC_TEMPLATE_SPECS_H_
#define FORTRAN_RUNTIME_FLOAT128MATH_NUMERIC_TEMPLATE_SPECS_H_
#ifndef FLANG_RT_FORTRANFLOAT128MATH_NUMERIC_TEMPLATE_SPECS_H_
#define FLANG_RT_FORTRANFLOAT128MATH_NUMERIC_TEMPLATE_SPECS_H_

#include "math-entries.h"
#include "numeric-templates.h"
Expand Down Expand Up @@ -52,4 +52,4 @@ template <> struct SQRTTy<F128Type> {
};

} // namespace Fortran::runtime
#endif // FORTRAN_RUNTIME_FLOAT128MATH_NUMERIC_TEMPLATE_SPECS_H_
#endif /* FLANG_RT_FORTRANFLOAT128MATH_NUMERIC_TEMPLATE_SPECS_H_ */
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/pow.cpp --------------------------------------===//
//===-- lib/FortranFloat128Math/pow.cpp -------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/random.cpp -----------------------------------===//
//===-- lib/FortranFloat128Math/random.cpp ----------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/remainder.cpp --------------------------------===//
//===-- lib/FortranFloat128Math/remainder.cpp -------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/round.cpp ------------------------------------===//
//===-- lib/FortranFloat128Math/round.cpp -----------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/rrspacing.cpp --------------------------------===//
//===-- lib/FortranFloat128Math/rrspacing.cpp -------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/scale.cpp ------------------------------------===//
//===-- lib/FortranFloat128Math/scale.cpp -----------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/set-exponent.cpp -----------------------------===//
//===-- lib/FortranFloat128Math/set-exponent.cpp ----------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/sin.cpp --------------------------------------===//
//===-- lib/FortranFloat128Math/sin.cpp -------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/sinh.cpp -------------------------------------===//
//===-- lib/FortranFloat128Math/sinh.cpp ------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/spacing.cpp ----------------------------------===//
//===-- lib/FortranFloat128Math/spacing.cpp ---------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/sqrt.cpp -------------------------------------===//
//===-- lib/FortranFloat128Math/sqrt.cpp ------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/tan.cpp --------------------------------------===//
//===-- lib/FortranFloat128Math/tan.cpp -------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/tanh.cpp -------------------------------------===//
//===-- lib/FortranFloat128Math/tanh.cpp ------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/tgamma.cpp -----------------------------------===//
//===-- lib/FortranFloat128Math/tgamma.cpp ----------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/trunc.cpp ------------------------------------===//
//===-- lib/FortranFloat128Math/trunc.cpp -----------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/y0.cpp ---------------------------------------===//
//===-- lib/FortranFloat128Math/y0.cpp --------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/y1.cpp ---------------------------------------===//
//===-- lib/FortranFloat128Math/y1.cpp --------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/Float128Math/yn.cpp ---------------------------------------===//
//===-- lib/FortranFloat128Math/yn.cpp --------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
19 changes: 19 additions & 0 deletions flang-rt/lib/Testing/CMakeLists.txt
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}
)
192 changes: 192 additions & 0 deletions flang-rt/lib/flang_rt/CMakeLists.txt
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()
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/ISO_Fortran_binding.cpp -----------------------------------===//
//===-- lib/flang_rt/ISO_Fortran_binding.cpp --------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand All @@ -10,11 +10,11 @@
// as specified in section 18.5.5 of Fortran 2018.

#include "ISO_Fortran_util.h"
#include "flang-rt/descriptor.h"
#include "flang-rt/type-code.h"
#include "terminator.h"
#include "flang/ISO_Fortran_binding_wrapper.h"
#include "flang/Runtime/descriptor.h"
#include "flang/Common/ISO_Fortran_binding_wrapper.h"
#include "flang/Runtime/pointer.h"
#include "flang/Runtime/type-code.h"
#include <cstdlib>

namespace Fortran::ISO {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
//===-- runtime/ISO_Fortran_util.h ------------------------------*- C++ -*-===//
//===-- lib/flang_rt/ISO_Fortran_util.h -------------------------*- 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_ISO_FORTRAN_UTIL_H_
#define FORTRAN_RUNTIME_ISO_FORTRAN_UTIL_H_
#ifndef FLANG_RT_ISO_FORTRAN_UTIL_H_
#define FLANG_RT_ISO_FORTRAN_UTIL_H_

// Internal utils for establishing CFI_cdesc_t descriptors.

#include "flang-rt/descriptor.h"
#include "flang-rt/type-code.h"
#include "terminator.h"
#include "flang/ISO_Fortran_binding_wrapper.h"
#include "flang/Runtime/descriptor.h"
#include "flang/Runtime/type-code.h"
#include "flang/Common/ISO_Fortran_binding_wrapper.h"
#include <cstdlib>

namespace Fortran::ISO {
Expand Down Expand Up @@ -99,4 +99,4 @@ static inline RT_API_ATTRS void EstablishDescriptor(CFI_cdesc_t *descriptor,
}
}
} // namespace Fortran::ISO
#endif // FORTRAN_RUNTIME_ISO_FORTRAN_UTIL_H_
#endif /* FLANG_RT_ISO_FORTRAN_UTIL_H_ */
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/allocatable.cpp -------------------------------------------===//
//===-- lib/flang_rt/allocatable.cpp ----------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand All @@ -9,12 +9,16 @@
#include "flang/Runtime/allocatable.h"
#include "assign-impl.h"
#include "derived.h"
#include "flang-rt/descriptor.h"
#include "stat.h"
#include "terminator.h"
#include "type-info.h"
#include "flang/ISO_Fortran_binding_wrapper.h"
#include "flang/Common/ISO_Fortran_binding_wrapper.h"
#include "flang/Runtime/assign.h"
#include "flang/Runtime/descriptor.h"

using Fortran::common::TypeCategory;



namespace Fortran::runtime {
extern "C" {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
//===-- runtime/allocator-registry.cpp ------------------------------------===//
//===-- lib/flang_rt/allocator-registry.cpp ---------------------*- 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
//
//===----------------------------------------------------------------------===//

#include "flang/Runtime/allocator-registry.h"
#include "flang-rt/allocator-registry.h"
#include "terminator.h"

namespace Fortran::runtime {

#ifndef FLANG_RUNTIME_NO_GLOBAL_VAR_DEFS
#ifndef FLANG_RT_NO_GLOBAL_VAR_DEFS
RT_OFFLOAD_VAR_GROUP_BEGIN
RT_VAR_ATTRS AllocatorRegistry allocatorRegistry;
RT_OFFLOAD_VAR_GROUP_END
#endif // FLANG_RUNTIME_NO_GLOBAL_VAR_DEFS
#endif // FLANG_RT_NO_GLOBAL_VAR_DEFS

RT_OFFLOAD_API_GROUP_BEGIN
RT_API_ATTRS void AllocatorRegistry::Register(int pos, Allocator_t allocator) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
//===-- runtime/array-constructor.cpp -------------------------------------===//
//===-- lib/flang_rt/array-constructor.cpp ----------------------*- 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
//
//===----------------------------------------------------------------------===//

#include "flang/Runtime/array-constructor.h"
#include "flang-rt/array-constructor.h"
#include "derived.h"
#include "flang-rt/descriptor.h"
#include "terminator.h"
#include "tools.h"
#include "type-info.h"
#include "flang/Runtime/allocatable.h"
#include "flang/Runtime/assign.h"
#include "flang/Runtime/descriptor.h"

namespace Fortran::runtime {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//===-- runtime/assign-impl.h -----------------------------------*- C++ -*-===//
//===-- lib/flang_rt/assign-impl.h ------------------------------*- 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_ASSIGN_IMPL_H_
#define FORTRAN_RUNTIME_ASSIGN_IMPL_H_
#ifndef FLANG_RT_ASSIGN_IMPL_H_
#define FLANG_RT_ASSIGN_IMPL_H_

#include "flang/Runtime/freestanding-tools.h"

Expand All @@ -28,4 +28,4 @@ RT_API_ATTRS void DoFromSourceAssign(Descriptor &, const Descriptor &,
#endif

} // namespace Fortran::runtime
#endif // FORTRAN_RUNTIME_ASSIGN_IMPL_H_
#endif /* FLANG_RT_ASSIGN_IMPL_H_ */
4 changes: 2 additions & 2 deletions flang/runtime/assign.cpp → flang-rt/lib/flang_rt/assign.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/assign.cpp ------------------------------------------------===//
//===-- lib/flang_rt/assign.cpp ---------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand All @@ -9,11 +9,11 @@
#include "flang/Runtime/assign.h"
#include "assign-impl.h"
#include "derived.h"
#include "flang-rt/descriptor.h"
#include "stat.h"
#include "terminator.h"
#include "tools.h"
#include "type-info.h"
#include "flang/Runtime/descriptor.h"

namespace Fortran::runtime {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/buffer.cpp ------------------------------------------------===//
//===-- lib/flang_rt/buffer.cpp ---------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
10 changes: 5 additions & 5 deletions flang/runtime/buffer.h → flang-rt/lib/flang_rt/buffer.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/buffer.h ----------------------------------------*- C++ -*-===//
//===-- lib/flang_rt/buffer.h -----------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand All @@ -8,12 +8,12 @@

// External file buffering

#ifndef FORTRAN_RUNTIME_BUFFER_H_
#define FORTRAN_RUNTIME_BUFFER_H_
#ifndef FLANG_RT_BUFFER_H_
#define FLANG_RT_BUFFER_H_

#include "flang-rt/memory.h"
#include "io-error.h"
#include "flang/Runtime/freestanding-tools.h"
#include "flang/Runtime/memory.h"
#include <algorithm>
#include <cinttypes>
#include <cstring>
Expand Down Expand Up @@ -221,4 +221,4 @@ template <typename STORE, std::size_t minBuffer = 65536> class FileFrame {
bool dirty_{false};
};
} // namespace Fortran::runtime::io
#endif // FORTRAN_RUNTIME_BUFFER_H_
#endif /* FLANG_RT_BUFFER_H_ */
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/character.cpp ---------------------------------------------===//
//===-- lib/flang_rt/character.cpp ------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand All @@ -7,13 +7,13 @@
//===----------------------------------------------------------------------===//

#include "flang/Runtime/character.h"
#include "flang-rt/descriptor.h"
#include "terminator.h"
#include "tools.h"
#include "flang/Common/bit-population-count.h"
#include "flang/Common/uint128.h"
#include "flang/Runtime/character.h"
#include "flang/Runtime/cpp-type.h"
#include "flang/Runtime/descriptor.h"
#include <algorithm>
#include <cstring>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/command.cpp -----------------------------------------------===//
//===-- lib/flang_rt/command.cpp --------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand All @@ -8,10 +8,10 @@

#include "flang/Runtime/command.h"
#include "environment.h"
#include "flang-rt/descriptor.h"
#include "stat.h"
#include "terminator.h"
#include "tools.h"
#include "flang/Runtime/descriptor.h"
#include <cstdlib>
#include <limits>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
/*===-- flang/runtime/complex-powi.cpp ----------------------------*- 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
*
* ===-----------------------------------------------------------------------===
*/
//===-- lib/flang_rt/complex-powi.cpp ---------------------------*- 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
//
//===----------------------------------------------------------------------===//
#include "flang/Common/float128.h"
#include "flang/Runtime/cpp-type.h"
#include "flang/Runtime/entry-names.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
/*===-- flang/runtime/complex-reduction.c ---------------------------*- C -*-===
/*===-- lib/flang_rt/complex-reduction.c ----------------------------*- 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
*
* ===-----------------------------------------------------------------------===
*/
*===----------------------------------------------------------------------===*/

#include "complex-reduction.h"
#include <float.h>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
/*===-- flang/runtime/complex-reduction.h ---------------------------*- C -*-===
/*===-- lib/flang_rt/complex-reduction.h ----------------------------*- 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
*
* ===-----------------------------------------------------------------------===
*/
*===----------------------------------------------------------------------===*/

/* Wraps the C++-coded complex-valued SUM and PRODUCT reductions with
* C-coded wrapper functions returning _Complex values, to avoid problems
* with C++ build compilers that don't support C's _Complex.
*/

#ifndef FORTRAN_RUNTIME_COMPLEX_REDUCTION_H_
#define FORTRAN_RUNTIME_COMPLEX_REDUCTION_H_
#ifndef FLANG_RT_COMPLEX_REDUCTION_H_
#define FLANG_RT_COMPLEX_REDUCTION_H_

#include "flang/Common/float128.h"
#include "flang/Runtime/entry-names.h"
Expand Down Expand Up @@ -156,4 +155,4 @@ void RTNAME(ReduceComplex16DimValue)(
REDUCE_DIM_ARGS(CFloat128ComplexType, CFloat128ComplexType_value_op));
#endif

#endif // FORTRAN_RUNTIME_COMPLEX_REDUCTION_H_
#endif /* FLANG_RT_COMPLEX_REDUCTION_H_ */
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/connection.cpp --------------------------------------------===//
//===-- lib/flang_rt/connection.cpp -----------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/connection.h ------------------------------------*- C++ -*-===//
//===-- lib/flang_rt/connection.h -------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand All @@ -8,8 +8,8 @@

// Fortran I/O connection state (abstracted over internal & external units)

#ifndef FORTRAN_RUNTIME_IO_CONNECTION_H_
#define FORTRAN_RUNTIME_IO_CONNECTION_H_
#ifndef FLANG_RT_CONNECTION_H_
#define FLANG_RT_CONNECTION_H_

#include "format.h"
#include "flang/Common/optional.h"
Expand Down Expand Up @@ -124,4 +124,4 @@ class SavedPosition {
};

} // namespace Fortran::runtime::io
#endif // FORTRAN_RUNTIME_IO_CONNECTION_H_
#endif /* FLANG_RT_CONNECTION_H_ */
4 changes: 2 additions & 2 deletions flang/runtime/copy.cpp → flang-rt/lib/flang_rt/copy.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/copy.cpp -------------------------------------------------===//
//===-- lib/flang_rt/copy.cpp -----------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand All @@ -7,11 +7,11 @@
//===----------------------------------------------------------------------===//

#include "copy.h"
#include "flang-rt/descriptor.h"
#include "stack.h"
#include "terminator.h"
#include "type-info.h"
#include "flang/Runtime/allocatable.h"
#include "flang/Runtime/descriptor.h"
#include <cstring>

namespace Fortran::runtime {
Expand Down
10 changes: 5 additions & 5 deletions flang/runtime/copy.h → flang-rt/lib/flang_rt/copy.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/copy.h ------------------------------------------*- C++ -*-===//
//===-- lib/flang_rt/copy.h -------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand All @@ -9,10 +9,10 @@
// Utilities that copy data in a type-aware fashion, allocating & duplicating
// allocatable/automatic components of derived types along the way.

#ifndef FORTRAN_RUNTIME_COPY_H_
#define FORTRAN_RUNTIME_COPY_H_
#ifndef FLANG_RT_COPY_H_
#define FLANG_RT_COPY_H_

#include "flang/Runtime/descriptor.h"
#include "flang-rt/descriptor.h"

namespace Fortran::runtime {

Expand All @@ -22,4 +22,4 @@ RT_API_ATTRS void CopyElement(const Descriptor &to, const SubscriptValue toAt[],
const Descriptor &from, const SubscriptValue fromAt[], Terminator &);

} // namespace Fortran::runtime
#endif // FORTRAN_RUNTIME_COPY_H_
#endif /* FLANG_RT_COPY_H_ */
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//===-- runtime/derived-api.cpp
//-----------------------------------------------===//
//===-- lib/flang_rt/derived-api.cpp ----------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand All @@ -9,10 +8,10 @@

#include "flang/Runtime/derived-api.h"
#include "derived.h"
#include "flang-rt/descriptor.h"
#include "terminator.h"
#include "tools.h"
#include "type-info.h"
#include "flang/Runtime/descriptor.h"

namespace Fortran::runtime {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/derived.cpp -----------------------------------------------===//
//===-- lib/flang_rt/derived.cpp --------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand All @@ -7,11 +7,11 @@
//===----------------------------------------------------------------------===//

#include "derived.h"
#include "flang-rt/descriptor.h"
#include "stat.h"
#include "terminator.h"
#include "tools.h"
#include "type-info.h"
#include "flang/Runtime/descriptor.h"

namespace Fortran::runtime {

Expand Down
8 changes: 4 additions & 4 deletions flang/runtime/derived.h → flang-rt/lib/flang_rt/derived.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/derived.h -------------------------------------------------===//
//===-- lib/flang_rt/derived.h ----------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand All @@ -8,8 +8,8 @@

// Internal runtime utilities for derived type operations.

#ifndef FORTRAN_RUNTIME_DERIVED_H_
#define FORTRAN_RUNTIME_DERIVED_H_
#ifndef FLANG_RT_DERIVED_H_
#define FLANG_RT_DERIVED_H_

#include "flang/Common/api-attrs.h"

Expand Down Expand Up @@ -40,4 +40,4 @@ RT_API_ATTRS void Destroy(const Descriptor &, bool finalize,
RT_API_ATTRS bool HasDynamicComponent(const Descriptor &);

} // namespace Fortran::runtime
#endif // FORTRAN_RUNTIME_DERIVED_H_
#endif /* FLANG_RT_DERIVED_H_ */
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/descriptor-io.cpp -----------------------------------------===//
//===-- lib/flang_rt/descriptor-io.cpp --------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//===-- runtime/descriptor-io.h ---------------------------------*- C++ -*-===//
//===-- lib/flang_rt/descriptor-io.h ----------------------------*- 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_DESCRIPTOR_IO_H_
#define FORTRAN_RUNTIME_DESCRIPTOR_IO_H_
#ifndef FLANG_RT_DESCRIPTOR_IO_H_
#define FLANG_RT_DESCRIPTOR_IO_H_

// Implementation of I/O data list item transfers based on descriptors.
// (All I/O items come through here so that the code is exercised for test;
Expand All @@ -16,6 +16,7 @@

#include "edit-input.h"
#include "edit-output.h"
#include "flang-rt/descriptor.h"
#include "io-stmt.h"
#include "namelist.h"
#include "terminator.h"
Expand All @@ -24,7 +25,6 @@
#include "flang/Common/optional.h"
#include "flang/Common/uint128.h"
#include "flang/Runtime/cpp-type.h"
#include "flang/Runtime/descriptor.h"

namespace Fortran::runtime::io::descr {
template <typename A>
Expand Down Expand Up @@ -608,4 +608,4 @@ static RT_API_ATTRS bool DescriptorIO(IoStatementState &io,
return false;
}
} // namespace Fortran::runtime::io::descr
#endif // FORTRAN_RUNTIME_DESCRIPTOR_IO_H_
#endif /* FLANG_RT_DESCRIPTOR_IO_H_ */
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
//===-- runtime/descriptor.cpp --------------------------------------------===//
//===-- lib/flang_rt/descriptor.cpp -----------------------------*- 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
//
//===----------------------------------------------------------------------===//

#include "flang/Runtime/descriptor.h"
#include "flang-rt/descriptor.h"
#include "ISO_Fortran_util.h"
#include "derived.h"
#include "flang-rt/allocator-registry.h"
#include "memory.h"
#include "stat.h"
#include "terminator.h"
#include "tools.h"
#include "type-info.h"
#include "flang/Runtime/allocator-registry.h"
#include <cassert>
#include <cstdlib>
#include <cstring>
Expand Down Expand Up @@ -141,8 +141,10 @@ RT_API_ATTRS OwningPtr<Descriptor> Descriptor::Create(

RT_API_ATTRS std::size_t Descriptor::SizeInBytes() const {
const DescriptorAddendum *addendum{Addendum()};
return sizeof *this - sizeof(Dimension) + raw_.rank * sizeof(Dimension) +
(addendum ? addendum->SizeInBytes() : 0);
std::size_t bytes{ sizeof *this - sizeof(Dimension) + raw_.rank * sizeof(Dimension) +
(addendum ? addendum->SizeInBytes() : 0)};
assert (bytes <= MaxDescriptorSizeInBytes(raw_.rank,addendum) && "Descriptor must fit compiler-allocated space");
return bytes;
}

RT_API_ATTRS std::size_t Descriptor::Elements() const {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
//===-- runtime/dot-product.cpp -------------------------------------------===//
//===-- lib/flang_rt/dot-product.cpp ----------------------------*- 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
//
//===----------------------------------------------------------------------===//

#include "flang-rt/descriptor.h"
#include "float.h"
#include "terminator.h"
#include "tools.h"
#include "flang/Common/float128.h"
#include "flang/Runtime/cpp-type.h"
#include "flang/Runtime/descriptor.h"
#include "flang/Runtime/reduction.h"
#include <cfloat>
#include <cinttypes>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/edit-input.cpp --------------------------------------------===//
//===-- lib/flang_rt/edit-input.cpp -----------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
//===-- runtime/edit-input.h ------------------------------------*- C++ -*-===//
//===-- lib/flang_rt/edit-input.h -------------------------------*- 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_EDIT_INPUT_H_
#define FORTRAN_RUNTIME_EDIT_INPUT_H_
#ifndef FLANG_RT_EDIT_INPUT_H_
#define FLANG_RT_EDIT_INPUT_H_

#include "format.h"
#include "io-stmt.h"
#include "flang/Decimal/decimal.h"
#include "flang/Common/decimal.h"

namespace Fortran::runtime::io {

Expand Down Expand Up @@ -50,4 +50,4 @@ extern template RT_API_ATTRS bool EditCharacterInput(
IoStatementState &, const DataEdit &, char32_t *, std::size_t);

} // namespace Fortran::runtime::io
#endif // FORTRAN_RUNTIME_EDIT_INPUT_H_
#endif /* FLANG_RT_EDIT_INPUT_H_ */
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/edit-output.cpp -------------------------------------------===//
//===-- lib/flang_rt/edit-output.cpp ----------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//===-- runtime/edit-output.h -----------------------------------*- C++ -*-===//
//===-- lib/flang_rt/edit-output.h ------------------------------*- 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_EDIT_OUTPUT_H_
#define FORTRAN_RUNTIME_EDIT_OUTPUT_H_
#ifndef FLANG_RT_EDIT_OUTPUT_H_
#define FLANG_RT_EDIT_OUTPUT_H_

// Output data editing templates implementing the FORMAT data editing
// descriptors E, EN, ES, EX, D, F, and G for REAL data (and COMPLEX
Expand All @@ -20,8 +20,8 @@

#include "format.h"
#include "io-stmt.h"
#include "flang/Common/decimal.h"
#include "flang/Common/uint128.h"
#include "flang/Decimal/decimal.h"

namespace Fortran::runtime::io {

Expand Down Expand Up @@ -138,4 +138,4 @@ extern template class RealOutputEditing<10>;
extern template class RealOutputEditing<16>;

} // namespace Fortran::runtime::io
#endif // FORTRAN_RUNTIME_EDIT_OUTPUT_H_
#endif /* FLANG_RT_EDIT_OUTPUT_H_ */
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- runtime/emit-encoded.h ----------------------------------*- C++ -*-===//
//===-- lib/flang_rt/emit-encoded.h -----------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand All @@ -8,8 +8,8 @@

// Templates for emitting CHARACTER values with conversion

#ifndef FORTRAN_RUNTIME_EMIT_ENCODED_H_
#define FORTRAN_RUNTIME_EMIT_ENCODED_H_
#ifndef FLANG_RT_EMIT_ENCODED_H_
#define FLANG_RT_EMIT_ENCODED_H_

#include "connection.h"
#include "environment.h"
Expand Down Expand Up @@ -114,4 +114,4 @@ RT_API_ATTRS bool EmitRepeated(CONTEXT &to, char ch, std::size_t n) {
}

} // namespace Fortran::runtime::io
#endif // FORTRAN_RUNTIME_EMIT_ENCODED_H_
#endif /* FLANG_RT_EMIT_ENCODED_H_ */
Loading