Skip to content

Commit 98e118c

Browse files
authored
[Flang] Don't use FortranDecimal for runtime (#121997)
Avoid using the same library for runtime and compiler. `FortranDecimal` was used in two ways: 1. As an auxiliary library needed for `libFortranRuntime.a`. This patch adds the two source files of FortranDecimal directly into FortranRuntime, so `FortranRuntime` is not used anymore.   2. As a library used by the Flang compiler. As the only remaining use of the library, extra CMake code to make it compatible with the runtime can be removed. Before this PR, `enable_cuda_compilation` is applied to `FortranDecimal` which causes everything that links to it, including flang (the compiler), to depend on libcudart when CUDA support is enabled. Having two runtime library just makes everything more complicated while the user ideally should not be concerned with how the runtime is structured internally. Some logic was copied for FortranDecimal because of this, such as the ability to be compiled out-of tree (b75a3c9) which is undocumented, the logic to link against the various versions of Microsofts runtime library (#70833), and avoiding dependency on the C++ runtime (7783bba).
1 parent 612df14 commit 98e118c

File tree

11 files changed

+11
-117
lines changed

11 files changed

+11
-117
lines changed

clang/lib/Driver/ToolChains/CommonArgs.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -1321,7 +1321,7 @@ void tools::addOpenMPHostOffloadingArgs(const Compilation &C,
13211321
/// Add Fortran runtime libs
13221322
void tools::addFortranRuntimeLibs(const ToolChain &TC, const ArgList &Args,
13231323
llvm::opt::ArgStringList &CmdArgs) {
1324-
// Link FortranRuntime and FortranDecimal
1324+
// Link FortranRuntime
13251325
// These are handled earlier on Windows by telling the frontend driver to
13261326
// add the correct libraries to link against as dependents in the object
13271327
// file.
@@ -1338,7 +1338,6 @@ void tools::addFortranRuntimeLibs(const ToolChain &TC, const ArgList &Args,
13381338
addAsNeededOption(TC, Args, CmdArgs, /*as_needed=*/false);
13391339
}
13401340
CmdArgs.push_back("-lFortranRuntime");
1341-
CmdArgs.push_back("-lFortranDecimal");
13421341
addArchSpecificRPath(TC, Args, CmdArgs);
13431342

13441343
// needs libexecinfo for backtrace functions

clang/lib/Driver/ToolChains/Flang.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -365,29 +365,25 @@ static void processVSRuntimeLibrary(const ToolChain &TC, const ArgList &Args,
365365
CmdArgs.push_back("-D_MT");
366366
CmdArgs.push_back("--dependent-lib=libcmt");
367367
CmdArgs.push_back("--dependent-lib=FortranRuntime.static.lib");
368-
CmdArgs.push_back("--dependent-lib=FortranDecimal.static.lib");
369368
break;
370369
case options::OPT__SLASH_MTd:
371370
CmdArgs.push_back("-D_MT");
372371
CmdArgs.push_back("-D_DEBUG");
373372
CmdArgs.push_back("--dependent-lib=libcmtd");
374373
CmdArgs.push_back("--dependent-lib=FortranRuntime.static_dbg.lib");
375-
CmdArgs.push_back("--dependent-lib=FortranDecimal.static_dbg.lib");
376374
break;
377375
case options::OPT__SLASH_MD:
378376
CmdArgs.push_back("-D_MT");
379377
CmdArgs.push_back("-D_DLL");
380378
CmdArgs.push_back("--dependent-lib=msvcrt");
381379
CmdArgs.push_back("--dependent-lib=FortranRuntime.dynamic.lib");
382-
CmdArgs.push_back("--dependent-lib=FortranDecimal.dynamic.lib");
383380
break;
384381
case options::OPT__SLASH_MDd:
385382
CmdArgs.push_back("-D_MT");
386383
CmdArgs.push_back("-D_DEBUG");
387384
CmdArgs.push_back("-D_DLL");
388385
CmdArgs.push_back("--dependent-lib=msvcrtd");
389386
CmdArgs.push_back("--dependent-lib=FortranRuntime.dynamic_dbg.lib");
390-
CmdArgs.push_back("--dependent-lib=FortranDecimal.dynamic_dbg.lib");
391387
break;
392388
}
393389
}

flang/docs/FlangDriver.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -175,19 +175,18 @@ like this:
175175

176176
```
177177
$ flang -v -o example example.o
178-
"/usr/bin/ld" [...] example.o [...] "-lFortranRuntime" "-lFortranDecimal" [...]
178+
"/usr/bin/ld" [...] example.o [...] "-lFortranRuntime" [...]
179179
```
180180

181181
The automatically added libraries are:
182182

183183
* `FortranRuntime`: Provides most of the Flang runtime library.
184-
* `FortranDecimal`: Provides operations for decimal numbers.
185184

186185
If the code is C/C++ based and invokes Fortran routines, one can either use Clang
187186
or Flang as the linker driver. If Clang is used, it will automatically all
188187
required runtime libraries needed by C++ (e.g., for STL) to the linker invocation.
189-
In this case, one has to explicitly provide the Fortran runtime libraries
190-
`FortranRuntime` and/or `FortranDecimal`. An alternative is to use Flang to link.
188+
In this case, one has to explicitly provide the Fortran runtime library
189+
`FortranRuntime`. An alternative is to use Flang to link.
191190
In this case, it may be required to explicitly supply C++ runtime libraries.
192191

193192
On Darwin, the logical root where the system libraries are located (sysroot)

flang/lib/Decimal/CMakeLists.txt

+1-83
Original file line numberDiff line numberDiff line change
@@ -6,89 +6,7 @@
66
#
77
#===------------------------------------------------------------------------===#
88

9-
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
10-
cmake_minimum_required(VERSION 3.20.0)
11-
12-
project(FortranDecimal C CXX)
13-
14-
set(CMAKE_CXX_STANDARD 17)
15-
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
16-
set(CMAKE_CXX_EXTENSIONS OFF)
17-
18-
set(FLANG_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../..")
19-
20-
set(LLVM_COMMON_CMAKE_UTILS "${FLANG_SOURCE_DIR}/../cmake")
21-
set(LLVM_CMAKE_UTILS "${FLANG_SOURCE_DIR}/../llvm/cmake")
22-
set(CLANG_CMAKE_UTILS "${FLANG_SOURCE_DIR}/../clang/cmake")
23-
24-
# Add path for custom modules
25-
list(INSERT CMAKE_MODULE_PATH 0
26-
"${FLANG_SOURCE_DIR}/cmake"
27-
"${FLANG_SOURCE_DIR}/cmake/modules"
28-
"${LLVM_COMMON_CMAKE_UTILS}"
29-
"${LLVM_COMMON_CMAKE_UTILS}/Modules"
30-
"${LLVM_CMAKE_UTILS}"
31-
"${LLVM_CMAKE_UTILS}/modules"
32-
"${CLANG_CMAKE_UTILS}/modules"
33-
)
34-
35-
include(AddClang)
36-
include(AddLLVM)
37-
include(AddFlang)
38-
include(HandleLLVMOptions)
39-
40-
include(TestBigEndian)
41-
test_big_endian(IS_BIGENDIAN)
42-
if (IS_BIGENDIAN)
43-
add_compile_definitions(FLANG_BIG_ENDIAN=1)
44-
else ()
45-
add_compile_definitions(FLANG_LITTLE_ENDIAN=1)
46-
endif ()
47-
include_directories(BEFORE
48-
${FLANG_SOURCE_DIR}/include)
49-
endif()
50-
51-
check_cxx_compiler_flag(-fno-lto FLANG_RUNTIME_HAS_FNO_LTO_FLAG)
52-
if (FLANG_RUNTIME_HAS_FNO_LTO_FLAG)
53-
append("-fno-lto" CMAKE_CXX_FLAGS)
54-
endif()
55-
56-
# Disable libstdc++ assertions, even in an LLVM_ENABLE_ASSERTIONS build, to
57-
# avoid an unwanted dependency on libstdc++.so.
58-
add_definitions(-U_GLIBCXX_ASSERTIONS)
59-
60-
set(sources
9+
add_flang_library(FortranDecimal
6110
binary-to-decimal.cpp
6211
decimal-to-binary.cpp
6312
)
64-
65-
include(AddFlangOffloadRuntime)
66-
enable_cuda_compilation(FortranDecimal "${sources}")
67-
enable_omp_offload_compilation("${sources}")
68-
69-
add_flang_library(FortranDecimal INSTALL_WITH_TOOLCHAIN ${sources})
70-
71-
if (DEFINED MSVC)
72-
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded)
73-
add_flang_library(FortranDecimal.static INSTALL_WITH_TOOLCHAIN
74-
binary-to-decimal.cpp
75-
decimal-to-binary.cpp
76-
)
77-
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDLL)
78-
add_flang_library(FortranDecimal.dynamic INSTALL_WITH_TOOLCHAIN
79-
binary-to-decimal.cpp
80-
decimal-to-binary.cpp
81-
)
82-
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDebug)
83-
add_flang_library(FortranDecimal.static_dbg INSTALL_WITH_TOOLCHAIN
84-
binary-to-decimal.cpp
85-
decimal-to-binary.cpp
86-
)
87-
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDebugDLL)
88-
add_flang_library(FortranDecimal.dynamic_dbg INSTALL_WITH_TOOLCHAIN
89-
binary-to-decimal.cpp
90-
decimal-to-binary.cpp
91-
)
92-
add_dependencies(FortranDecimal FortranDecimal.static FortranDecimal.dynamic
93-
FortranDecimal.static_dbg FortranDecimal.dynamic_dbg)
94-
endif()

flang/runtime/CMakeLists.txt

+3-9
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
5959
)
6060
endif()
6161

62-
set(linked_libraries FortranDecimal)
62+
set(linked_libraries "")
6363

6464
# function checks
6565
find_package(Backtrace)
@@ -116,6 +116,8 @@ add_definitions(-U_LIBCPP_ENABLE_ASSERTIONS)
116116
add_subdirectory(Float128Math)
117117

118118
set(sources
119+
${FLANG_SOURCE_DIR}/lib/Decimal/binary-to-decimal.cpp
120+
${FLANG_SOURCE_DIR}/lib/Decimal/decimal-to-binary.cpp
119121
ISO_Fortran_binding.cpp
120122
allocator-registry.cpp
121123
allocatable.cpp
@@ -288,26 +290,18 @@ else()
288290
)
289291
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded)
290292
add_flang_library(FortranRuntime.static ${sources}
291-
LINK_LIBS
292-
FortranDecimal.static
293293
INSTALL_WITH_TOOLCHAIN)
294294
set_target_properties(FortranRuntime.static PROPERTIES FOLDER "Flang/Runtime Libraries")
295295
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDLL)
296296
add_flang_library(FortranRuntime.dynamic ${sources}
297-
LINK_LIBS
298-
FortranDecimal.dynamic
299297
INSTALL_WITH_TOOLCHAIN)
300298
set_target_properties(FortranRuntime.dynamic PROPERTIES FOLDER "Flang/Runtime Libraries")
301299
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDebug)
302300
add_flang_library(FortranRuntime.static_dbg ${sources}
303-
LINK_LIBS
304-
FortranDecimal.static_dbg
305301
INSTALL_WITH_TOOLCHAIN)
306302
set_target_properties(FortranRuntime.static_dbg PROPERTIES FOLDER "Flang/Runtime Libraries")
307303
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDebugDLL)
308304
add_flang_library(FortranRuntime.dynamic_dbg ${sources}
309-
LINK_LIBS
310-
FortranDecimal.dynamic_dbg
311305
INSTALL_WITH_TOOLCHAIN)
312306
set_target_properties(FortranRuntime.dynamic_dbg PROPERTIES FOLDER "Flang/Runtime Libraries")
313307
add_dependencies(FortranRuntime FortranRuntime.static FortranRuntime.dynamic

flang/test/Driver/linker-flags.f90

+2-5
Original file line numberDiff line numberDiff line change
@@ -33,36 +33,33 @@
3333
! SOLARIS-F128NONE-NOT: FortranFloat128Math
3434
! UNIX-F128LIBQUADMATH-SAME: "-lFortranFloat128Math" "--as-needed" "-lquadmath" "--no-as-needed"
3535
! SOLARIS-F128LIBQUADMATH-SAME: "-lFortranFloat128Math" "-z" "ignore" "-lquadmath" "-z" "record"
36-
! UNIX-SAME: "-lFortranRuntime" "-lFortranDecimal" "-lm"
36+
! UNIX-SAME: "-lFortranRuntime" "-lm"
3737
! COMPILER-RT: "{{.*}}{{\\|/}}libclang_rt.builtins.a"
3838

3939
! BSD-LABEL: "{{.*}}ld{{(\.exe)?}}"
4040
! BSD-SAME: "[[object_file]]"
4141
! BSD-F128NONE-NOT: FortranFloat128Math
4242
! BSD-F128LIBQUADMATH-SAME: "-lFortranFloat128Math" "--as-needed" "-lquadmath" "--no-as-needed"
4343
! BSD-SAME: -lFortranRuntime
44-
! BSD-SAME: -lFortranDecimal
4544
! BSD-SAME: -lexecinfo
4645

4746
! DARWIN-LABEL: "{{.*}}ld{{(\.exe)?}}"
4847
! DARWIN-SAME: "[[object_file]]"
4948
! DARWIN-F128NONE-NOT: FortranFloat128Math
5049
! DARWIN-F128LIBQUADMATH-SAME: "-lFortranFloat128Math" "--as-needed" "-lquadmath" "--no-as-needed"
5150
! DARWIN-SAME: -lFortranRuntime
52-
! DARWIN-SAME: -lFortranDecimal
5351

5452
! HAIKU-LABEL: "{{.*}}ld{{(\.exe)?}}"
5553
! HAIKU-SAME: "[[object_file]]"
5654
! HAIKU-F128NONE-NOT: FortranFloat128Math
5755
! HAIKU-F128LIBQUADMATH-SAME: "-lFortranFloat128Math" "--as-needed" "-lquadmath" "--no-as-needed"
58-
! HAIKU-SAME: "-lFortranRuntime" "-lFortranDecimal"
56+
! HAIKU-SAME: "-lFortranRuntime"
5957

6058
! MINGW-LABEL: "{{.*}}ld{{(\.exe)?}}"
6159
! MINGW-SAME: "[[object_file]]"
6260
! MINGW-F128NONE-NOT: FortranFloat128Math
6361
! MINGW-F128LIBQUADMATH-SAME: "-lFortranFloat128Math" "--as-needed" "-lquadmath" "--no-as-needed"
6462
! MINGW-SAME: -lFortranRuntime
65-
! MINGW-SAME: -lFortranDecimal
6663

6764
! NOTE: This also matches lld-link (when CLANG_DEFAULT_LINKER=lld) and
6865
! any .exe suffix that is added when resolving to the full path of

flang/test/Driver/msvc-dependent-lib-flags.f90

-4
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,20 @@
88
! MSVC-SAME: -D_MT
99
! MSVC-SAME: --dependent-lib=libcmt
1010
! MSVC-SAME: --dependent-lib=FortranRuntime.static.lib
11-
! MSVC-SAME: --dependent-lib=FortranDecimal.static.lib
1211

1312
! MSVC-DEBUG: -fc1
1413
! MSVC-DEBUG-SAME: --dependent-lib=clang_rt.builtins.lib
1514
! MSVC-DEBUG-SAME: -D_MT
1615
! MSVC-DEBUG-SAME: -D_DEBUG
1716
! MSVC-DEBUG-SAME: --dependent-lib=libcmtd
1817
! MSVC-DEBUG-SAME: --dependent-lib=FortranRuntime.static_dbg.lib
19-
! MSVC-DEBUG-SAME: --dependent-lib=FortranDecimal.static_dbg.lib
2018

2119
! MSVC-DLL: -fc1
2220
! MSVC-DLL-SAME: --dependent-lib=clang_rt.builtins.lib
2321
! MSVC-DLL-SAME: -D_MT
2422
! MSVC-DLL-SAME: -D_DLL
2523
! MSVC-DLL-SAME: --dependent-lib=msvcrt
2624
! MSVC-DLL-SAME: --dependent-lib=FortranRuntime.dynamic.lib
27-
! MSVC-DLL-SAME: --dependent-lib=FortranDecimal.dynamic.lib
2825

2926
! MSVC-DLL-DEBUG: -fc1
3027
! MSVC-DLL-DEBUG-SAME: --dependent-lib=clang_rt.builtins.lib
@@ -33,4 +30,3 @@
3330
! MSVC-DLL-DEBUG-SAME: -D_DLL
3431
! MSVC-DLL-DEBUG-SAME: --dependent-lib=msvcrtd
3532
! MSVC-DLL-DEBUG-SAME: --dependent-lib=FortranRuntime.dynamic_dbg.lib
36-
! MSVC-DLL-DEBUG-SAME: --dependent-lib=FortranDecimal.dynamic_dbg.lib

flang/test/Driver/nostdlib.f90

-1
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,4 @@
2525
! platform individually.
2626

2727
! CHECK-NOT: "-lFortranRuntime"
28-
! CHECK-NOT: "-lFortranDecimal"
2928
! CHECK-NOT: "-lgcc"

flang/test/Runtime/no-cpp-dep.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ a C compiler.
66
REQUIRES: c-compiler
77
88
RUN: %if system-aix %{ export OBJECT_MODE=64 %}
9-
RUN: %cc -std=c99 %s -I%include %libruntime %libdecimal -lm \
9+
RUN: %cc -std=c99 %s -I%include %libruntime -lm \
1010
RUN: %if system-aix %{-lpthread %}
1111
RUN: rm a.out
1212
*/

flang/test/lit.cfg.py

-3
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,10 @@
168168
# we don't have one, we can just disable the test.
169169
if config.cc:
170170
libruntime = os.path.join(config.flang_lib_dir, "libFortranRuntime.a")
171-
libdecimal = os.path.join(config.flang_lib_dir, "libFortranDecimal.a")
172171
include = os.path.join(config.flang_src_dir, "include")
173172

174173
if (
175174
os.path.isfile(libruntime)
176-
and os.path.isfile(libdecimal)
177175
and os.path.isdir(include)
178176
):
179177
config.available_features.add("c-compiler")
@@ -183,7 +181,6 @@
183181
)
184182
)
185183
tools.append(ToolSubst("%libruntime", command=libruntime, unresolved="fatal"))
186-
tools.append(ToolSubst("%libdecimal", command=libdecimal, unresolved="fatal"))
187184
tools.append(ToolSubst("%include", command=include, unresolved="fatal"))
188185

189186
# Add all the tools and their substitutions (if applicable). Use the search paths provided for

lld/COFF/MinGW.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ AutoExporter::AutoExporter(
5050
"libc++",
5151
"libc++abi",
5252
"libFortranRuntime",
53-
"libFortranDecimal",
5453
"libunwind",
5554
"libmsvcrt",
5655
"libucrtbase",

0 commit comments

Comments
 (0)