Skip to content

Commit 5e5ec22

Browse files
committed
Post-merge fixes
1 parent ed062e4 commit 5e5ec22

File tree

7 files changed

+578
-3
lines changed

7 files changed

+578
-3
lines changed

flang-rt/lib/flang_rt/CMakeLists.txt

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
#===-- lib/flang_rt/CMakeLists.txt -----------------------------------------===#
2+
#
3+
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
# See https://llvm.org/LICENSE.txt for license information.
5+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
#
7+
#===------------------------------------------------------------------------===#
8+
9+
include(AddFlangRTOffload)
10+
# function checks
11+
find_package(Backtrace)
12+
set(HAVE_BACKTRACE ${Backtrace_FOUND})
13+
set(BACKTRACE_HEADER ${Backtrace_HEADER})
14+
15+
16+
# List of files that are buildable for all devices.
17+
set(supported_sources
18+
${FLANG_SOURCE_DIR}/lib/Decimal/binary-to-decimal.cpp
19+
${FLANG_SOURCE_DIR}/lib/Decimal/decimal-to-binary.cpp
20+
ISO_Fortran_binding.cpp
21+
allocator-registry.cpp
22+
allocatable.cpp
23+
array-constructor.cpp
24+
assign.cpp
25+
buffer.cpp
26+
character.cpp
27+
connection.cpp
28+
copy.cpp
29+
derived-api.cpp
30+
derived.cpp
31+
descriptor-io.cpp
32+
descriptor.cpp
33+
dot-product.cpp
34+
edit-input.cpp
35+
edit-output.cpp
36+
environment.cpp
37+
external-unit.cpp
38+
extrema.cpp
39+
file.cpp
40+
findloc.cpp
41+
format.cpp
42+
inquiry.cpp
43+
internal-unit.cpp
44+
io-api.cpp
45+
io-api-minimal.cpp
46+
io-error.cpp
47+
io-stmt.cpp
48+
iostat.cpp
49+
matmul-transpose.cpp
50+
matmul.cpp
51+
memory.cpp
52+
misc-intrinsic.cpp
53+
namelist.cpp
54+
non-tbp-dio.cpp
55+
numeric.cpp
56+
pointer.cpp
57+
product.cpp
58+
pseudo-unit.cpp
59+
ragged.cpp
60+
stat.cpp
61+
sum.cpp
62+
support.cpp
63+
terminator.cpp
64+
tools.cpp
65+
transformational.cpp
66+
type-code.cpp
67+
type-info.cpp
68+
unit.cpp
69+
unit-map.cpp
70+
utf.cpp
71+
)
72+
73+
# List of source not used for GPU offloading.
74+
set(host_sources
75+
${FLANG_SOURCE_DIR}/module/iso_fortran_env_impl.f90
76+
command.cpp
77+
complex-powi.cpp
78+
complex-reduction.c
79+
exceptions.cpp
80+
execute.cpp
81+
extensions.cpp
82+
main.cpp
83+
random.cpp
84+
reduce.cpp
85+
reduction.cpp
86+
stop.cpp
87+
temporary-stack.cpp
88+
time-intrinsic.cpp
89+
)
90+
91+
file(GLOB_RECURSE public_headers
92+
"${FLANG_RT_SOURCE_DIR}/include/flang_rt/*.h"
93+
"${FLANG_SOURCE_DIR}/include/flang/Common/*.h"
94+
)
95+
96+
file(GLOB_RECURSE private_headers
97+
"${FLANG_RT_SOURCE_DIR}/lib/flang_rt/*.h"
98+
"${FLANG_SOURCE_DIR}/lib/Common/*.h"
99+
)
100+
101+
102+
# Import changes from sibling FortranFloat128Math
103+
get_target_property(f128_sources
104+
FortranFloat128MathILib INTERFACE_SOURCES
105+
)
106+
if (f128_sources)
107+
# The interface may define special macros for Float128Math files,
108+
# so we need to propagate them.
109+
get_target_property(f128_defs
110+
FortranFloat128MathILib INTERFACE_COMPILE_DEFINITIONS
111+
)
112+
set_property(SOURCE ${f128_sources}
113+
APPEND PROPERTY COMPILE_DEFINITIONS
114+
${f128_defs}
115+
)
116+
get_target_property(f128_include_dirs
117+
FortranFloat128MathILib INTERFACE_INCLUDE_DIRECTORIES
118+
)
119+
set_property(SOURCE ${f128_sources}
120+
APPEND PROPERTY INCLUDE_DIRECTORIES
121+
${f128_include_dirs}
122+
)
123+
else ()
124+
set(f128_sources "")
125+
endif ()
126+
127+
128+
set(sources ${supported_sources} ${host_sources} ${f128_sources})
129+
130+
if (NOT WIN32)
131+
add_flangrt_library(flang_rt STATIC
132+
${sources}
133+
INSTALL_WITH_TOOLCHAIN
134+
ADDITIONAL_HEADERS ${public_headers} ${private_headers}
135+
)
136+
137+
enable_cuda_compilation(flang_rt.static "${supported_sources}")
138+
enable_omp_offload_compilation(flang_rt.static "${supported_sources}")
139+
140+
# For unittests that depend on flang_rt. Should link to the static version
141+
# of the library.
142+
add_library(flang_rt.static ALIAS flang_rt)
143+
add_library(flang_rt.unittest ALIAS flang_rt)
144+
else()
145+
# Target for building all versions of the runtime
146+
add_custom_target(flang_rt)
147+
set_target_properties(flang_rt PROPERTIES FOLDER "Flang-RT/Meta")
148+
149+
function (add_win_flangrt_library libtype suffix msvc_lib)
150+
set(name "flang_rt.${suffix}")
151+
add_flangrt_library(${name} ${libtype}
152+
${sources}
153+
${ARGN}
154+
ADDITIONAL_HEADERS ${public_headers} ${private_headers}
155+
)
156+
157+
if (msvc_lib)
158+
set_target_properties(${name}
159+
PROPERTIES
160+
MSVC_RUNTIME_LIBRARY "${msvc_lib}"
161+
)
162+
endif ()
163+
164+
# Setting an unique Fortran_MODULE_DIRECTORY is required for each variant to
165+
# write a different .mod file.
166+
set_target_properties(${name}
167+
PROPERTIES
168+
Fortran_MODULE_DIRECTORY "module.${suffix}"
169+
)
170+
171+
enable_cuda_compilation(${name} "${supported_sources}")
172+
enable_omp_offload_compilation(${name} "${supported_sources}")
173+
add_dependencies(flang_rt ${name})
174+
endfunction ()
175+
176+
# Variants of the static flang_rt for different versions of the msvc runtime.
177+
#
178+
# The dynamic/dynamic_dbg variants are not DLLs themselves, only require
179+
# linking to msvcrt(d).dll.
180+
# FIXME: Generating actual runtime DLLs is currently not possible. There are
181+
# two roadblocks:
182+
#
183+
# * Flang emits /DEFAULTLIB:flang_rt.dynamic.lib into
184+
# iso_fortran_env_impl.f90.obj. Because that file is itself part of
185+
# flang_rt.dynamic, this results in a recursive dependency when invoking
186+
# the linker.
187+
#
188+
# * The externally-visible functions must either be annotated with
189+
# __declspec(dllexport), or listed in an exports file. A possible workaround
190+
# is CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS which would also export the internal
191+
# C++ symbols and still requires global data symbols to be annotated
192+
# manually.
193+
add_win_flangrt_library(STATIC static MultiThreaded INSTALL_WITH_TOOLCHAIN)
194+
add_win_flangrt_library(STATIC static_dbg MultiThreadedDebug INSTALL_WITH_TOOLCHAIN)
195+
add_win_flangrt_library(STATIC dynamic MultiThreadedDLL INSTALL_WITH_TOOLCHAIN)
196+
add_win_flangrt_library(STATIC dynamic_dbg MultiThreadedDebugDLL INSTALL_WITH_TOOLCHAIN)
197+
198+
# Unittests link against LLVMSupport which is using CMake's default runtime
199+
# library selection, which is either MultiThreadedDLL or MultiThreadedDebugDLL
200+
# depending on the configuration. They have to match or linking will fail.
201+
if (GENERATOR_IS_MULTI_CONFIG)
202+
# We cannot select an ALIAS library because it may be different
203+
# per configuration. Fallback to CMake's default.
204+
add_win_flangrt_library(STATIC unittest "" EXCLUDE_FROM_ALL)
205+
else ()
206+
string(TOLOWER ${CMAKE_BUILD_TYPE} build_type)
207+
if (build_type STREQUAL "debug")
208+
add_library(flang_rt.unittest ALIAS flang_rt.dynamic_dbg)
209+
else ()
210+
add_library(flang_rt.unittest ALIAS flang_rt.dynamic)
211+
endif ()
212+
endif ()
213+
endif()

flang/CMakeLists.txt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,25 @@ else()
223223
include_directories(SYSTEM ${MLIR_TABLEGEN_OUTPUT_DIR})
224224
endif()
225225

226-
option(FLANG_INCLUDE_RUNTIME "Build the runtime in-tree (deprecated; to be replaced with LLVM_ENABLE_RUNTIMES=flang-rt)" ON)
226+
set(FLANG_INCLUDE_RUNTIME_default ON)
227+
if ("flang-rt" IN_LIST LLVM_ENABLE_RUNTIMES)
228+
set(FLANG_INCLUDE_RUNTIME_default OFF)
229+
endif ()
230+
option(FLANG_INCLUDE_RUNTIME "Build the runtime in-tree (deprecated; to be replaced with LLVM_ENABLE_RUNTIMES=flang-rt)" FLANG_INCLUDE_RUNTIME_default)
231+
if (FLANG_INCLUDE_RUNTIME)
232+
if ("flang-rt" IN_LIST LLVM_ENABLE_RUNTIMES)
233+
message(WARNING "Building Flang-RT using LLVM_ENABLE_RUNTIMES. FLANG_INCLUDE_RUNTIME=${FLANG_INCLUDE_RUNTIME} ignored.")
234+
set(FLANG_INCLUDE_RUNTIME OFF)
235+
else ()
236+
message(STATUS "Building flang_rt in-tree")
237+
endif ()
238+
else ()
239+
if ("flang-rt" IN_LIST LLVM_ENABLE_RUNTIMES)
240+
message(STATUS "Building Flang-RT using LLVM_ENABLE_RUNTIMES.")
241+
else ()
242+
message(STATUS "Not building Flang-RT. For a usable Fortran toolchain, compile a standalone Flang-RT")
243+
endif ()
244+
endif ()
227245
pythonize_bool(FLANG_INCLUDE_RUNTIME)
228246

229247
set(FLANG_TOOLS_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH

flang/test/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,5 +126,7 @@ if (DEFINED FLANG_TEST_TARGET_TRIPLE)
126126
endif()
127127

128128
# Compatibility targets.
129-
add_custom_target(check-flang-rt)
130-
add_dependencies(check-flang-rt check-flang)
129+
if (FLANG_INCLUDE_RUNTIME)
130+
add_custom_target(check-flang-rt)
131+
add_dependencies(check-flang-rt check-flang)
132+
endif ()

flang/unittests/Common/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
add_flang_unittest(FlangCommonTests
2+
FastIntSetTest.cpp
3+
)
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
//===-- flang/unittests/Common/FastIntSetTest.cpp ---------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "gtest/gtest.h"
10+
#include "flang/Common/fast-int-set.h"
11+
#include <optional>
12+
13+
TEST(FastIntSetTests, Sanity) {
14+
static constexpr int N{100};
15+
Fortran::common::FastIntSet<N> set;
16+
17+
ASSERT_FALSE(set.IsValidValue(-1));
18+
ASSERT_TRUE(set.IsValidValue(0));
19+
ASSERT_TRUE(set.IsValidValue(N - 1));
20+
ASSERT_FALSE(set.IsValidValue(N));
21+
ASSERT_TRUE(set.IsEmpty());
22+
ASSERT_EQ(set.size(), 0);
23+
ASSERT_FALSE(set.Contains(0));
24+
ASSERT_FALSE(set.Contains(N - 1));
25+
26+
ASSERT_TRUE(set.Add(0));
27+
ASSERT_FALSE(set.IsEmpty());
28+
ASSERT_EQ(set.size(), 1);
29+
ASSERT_TRUE(set.Contains(0));
30+
31+
ASSERT_TRUE(set.Add(0)); // duplicate
32+
ASSERT_EQ(set.size(), 1);
33+
ASSERT_TRUE(set.Contains(0));
34+
35+
ASSERT_TRUE(set.Remove(0));
36+
ASSERT_TRUE(set.IsEmpty());
37+
ASSERT_EQ(set.size(), 0);
38+
ASSERT_FALSE(set.Contains(0));
39+
40+
ASSERT_FALSE(set.Add(N));
41+
ASSERT_TRUE(set.IsEmpty());
42+
ASSERT_EQ(set.size(), 0);
43+
ASSERT_FALSE(set.Contains(N));
44+
45+
ASSERT_TRUE(set.Add(N - 1));
46+
ASSERT_FALSE(set.IsEmpty());
47+
ASSERT_EQ(set.size(), 1);
48+
ASSERT_TRUE(set.Contains(N - 1));
49+
50+
std::optional<int> x;
51+
x = set.PopValue();
52+
ASSERT_TRUE(x.has_value());
53+
ASSERT_EQ(*x, N - 1);
54+
ASSERT_TRUE(set.IsEmpty());
55+
ASSERT_EQ(set.size(), 0);
56+
57+
x = set.PopValue();
58+
ASSERT_FALSE(x.has_value());
59+
60+
for (int j{0}; j < N; ++j) {
61+
ASSERT_TRUE(set.Add(j)) << j;
62+
}
63+
ASSERT_FALSE(set.IsEmpty());
64+
ASSERT_EQ(set.size(), N);
65+
for (int j{0}; j < N; ++j) {
66+
ASSERT_TRUE(set.Contains(j)) << j;
67+
}
68+
69+
for (int j{0}; j < N; ++j) {
70+
ASSERT_TRUE(set.Remove(j)) << j;
71+
ASSERT_EQ(set.size(), N - j - 1) << j;
72+
ASSERT_FALSE(set.Contains(j)) << j;
73+
}
74+
75+
ASSERT_TRUE(set.IsEmpty());
76+
ASSERT_EQ(set.size(), 0);
77+
78+
for (int j{N - 1}; j >= 0; --j) {
79+
ASSERT_TRUE(set.Add(j)) << j;
80+
}
81+
for (int j{0}; j < N; j++) {
82+
x = set.PopValue();
83+
ASSERT_TRUE(x.has_value());
84+
ASSERT_EQ(*x, j) << j;
85+
}
86+
ASSERT_TRUE(set.IsEmpty());
87+
ASSERT_EQ(set.size(), 0);
88+
89+
for (int j{0}; j < N; j++) {
90+
ASSERT_TRUE(set.Add(j)) << j;
91+
}
92+
ASSERT_FALSE(set.IsEmpty());
93+
ASSERT_EQ(set.size(), N);
94+
for (int j{0}; j < N; j += 2) {
95+
ASSERT_TRUE(set.Remove(j)) << j;
96+
}
97+
ASSERT_FALSE(set.IsEmpty());
98+
ASSERT_EQ(set.size(), N / 2);
99+
for (int j{0}; j < N; j++) {
100+
ASSERT_EQ(set.Contains(j), (j & 1) == 1);
101+
}
102+
103+
set.Clear();
104+
ASSERT_TRUE(set.IsEmpty());
105+
}

0 commit comments

Comments
 (0)