Skip to content

Commit 1ad1eb4

Browse files
committed
WIP
1 parent d1bcda3 commit 1ad1eb4

File tree

17 files changed

+246
-146
lines changed

17 files changed

+246
-146
lines changed

flang-rt/CMakeLists.txt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,6 @@ include(ExtendPath)
7373
# Build Mode Introspection #
7474
############################
7575

76-
# Determine whether we are in the runtimes/runtimes-bins directory of a
77-
# bootstrap build.
78-
set(LLVM_TREE_AVAILABLE OFF)
79-
if (LLVM_LIBRARY_OUTPUT_INTDIR AND LLVM_RUNTIME_OUTPUT_INTDIR AND PACKAGE_VERSION)
80-
set(LLVM_TREE_AVAILABLE ON)
81-
endif()
82-
8376
# Path to LLVM development tools (FileCheck, llvm-lit, not, ...)
8477
set(LLVM_TOOLS_DIR "${LLVM_BINARY_DIR}/bin")
8578

flang-rt/cmake/modules/AddFlangRT.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,16 @@
3030
# May specify header files for IDE generators.
3131
# INCLUDE_DIRECTORIES
3232
# Additional target_include_directories for all added targets
33+
# COMPILE_OPTIONS
34+
# Set target compile options of all added targets
3335
# LINK_LIBRARIES
3436
# Additional target_link_libraries for all added targets
3537
# TARGET_PROPERTIES
3638
# Set target properties of all added targets
3739
# )
3840
function (add_flangrt_library name)
3941
set(options STATIC SHARED OBJECT INSTALL_WITH_TOOLCHAIN EXCLUDE_FROM_ALL LINK_TO_LLVM)
40-
set(multiValueArgs ADDITIONAL_HEADERS INCLUDE_DIRECTORIES LINK_LIBRARIES TARGET_PROPERTIES)
42+
set(multiValueArgs ADDITIONAL_HEADERS INCLUDE_DIRECTORIES COMPILE_OPTIONS LINK_LIBRARIES TARGET_PROPERTIES)
4143
cmake_parse_arguments(ARG
4244
"${options}"
4345
""
@@ -332,6 +334,8 @@ function (add_flangrt_library name)
332334
PROPERTIES
333335
Fortran_MODULE_DIRECTORY "${FLANG_RT_OUTPUT_RESOURCE_MOD_DIR}"
334336
)
337+
338+
target_compile_options(${tgtname} PRIVATE ${ARG_COMPILE_OPTIONS})
335339
endforeach ()
336340

337341

flang-rt/lib/runtime/CMakeLists.txt

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ find_package(Backtrace)
1414
set(HAVE_BACKTRACE ${Backtrace_FOUND})
1515
set(BACKTRACE_HEADER ${Backtrace_HEADER})
1616

17+
flang_module_fortran_enable()
18+
1719
include(CheckFortranSourceCompiles)
1820
include(CMakePushCheckState)
1921

@@ -159,9 +161,12 @@ endif ()
159161
list(APPEND supported_sources
160162
__cuda_builtins.f90
161163
__cuda_device.f90
162-
cooperative_groups.f90
164+
cooperative_groups.f90 # Implicitly depends on cudadevice.f90
163165
cudadevice.f90
164166
)
167+
#list(APPEND intrinsics_sources
168+
# cudadevice.f90 # Doesn't it itself require __fortran_builtins.f90 ?
169+
#)
165170

166171
# FIXME: Has CMake support for CUDA-Fortran?
167172
# FIXME: __cuda_builtins.f90 does not need -xcuda?
@@ -304,6 +309,8 @@ set(Fortran_BUILDING_INSTRINSIC_MODULES TRUE)
304309
#add_compile_options($<$<COMPILE_LANGUAGE:Fortran>:SHELL:-module-dir> $<$<COMPILE_LANGUAGE:Fortran>:"${FLANG_RT_OUTPUT_RESOURCE_MOD_DIR}">)
305310
add_compile_options($<$<COMPILE_LANGUAGE:Fortran>:SHELL:"-fintrinsic-modules-path"> $<$<COMPILE_LANGUAGE:Fortran>:"${FLANG_RT_OUTPUT_RESOURCE_MOD_DIR}">)
306311

312+
# Phony target for intrinsics
313+
#add_custom_target(flangrt-mod)
307314

308315

309316

@@ -320,14 +327,18 @@ if (NOT WIN32)
320327
INSTALL_WITH_TOOLCHAIN
321328
ADDITIONAL_HEADERS ${public_headers} ${private_headers}
322329
LINK_LIBRARIES flang_rt.intrinsics
330+
COMPILE_OPTIONS
331+
"$<$<COMPILE_LANGUAGE:Fortran>:SHELL:-fintrinsic-modules-path>"
332+
"$<$<COMPILE_LANGUAGE:Fortran>:${FLANG_RT_OUTPUT_RESOURCE_MOD_DIR}>"
323333
TARGET_PROPERTIES
324334
# Two spellings for the same thing: https://cmake.org/cmake/help/latest/prop_tgt/Fortran_BUILDING_INSTRINSIC_MODULES.html
325335
# Supported only since CMake 3.22
326336
Fortran_BUILDING_INTRINSIC_MODULES TRUE
327337
Fortran_BUILDING_INSTRINSIC_MODULES TRUE
328338
)
339+
329340
# TODO: shared (or global)
330-
target_compile_options(flang_rt.runtime.static PRIVATE "$<$<COMPILE_LANGUAGE:Fortran>:SHELL:-fintrinsic-modules-path>" "$<$<COMPILE_LANGUAGE:Fortran>:${FLANG_RT_OUTPUT_RESOURCE_MOD_DIR}>")
341+
#target_compile_options(flang_rt.runtime.static PRIVATE "$<$<COMPILE_LANGUAGE:Fortran>:SHELL:-fintrinsic-modules-path>" "$<$<COMPILE_LANGUAGE:Fortran>:${FLANG_RT_OUTPUT_RESOURCE_MOD_DIR}>")
331342

332343
enable_cuda_compilation(flang_rt.runtime "${supported_sources}")
333344
enable_omp_offload_compilation(flang_rt.runtime "${supported_sources}")
@@ -360,6 +371,9 @@ else()
360371
${ARGN}
361372
LINK_LIBRARIES ${name}.intrinsics ${Backtrace_LIBRARY}
362373
ADDITIONAL_HEADERS ${public_headers} ${private_headers}
374+
COMPILE_OPTIONS
375+
"$<$<COMPILE_LANGUAGE:Fortran>:SHELL:-fintrinsic-modules-path>"
376+
"$<$<COMPILE_LANGUAGE:Fortran>:${FLANG_RT_OUTPUT_RESOURCE_MOD_DIR}>"
363377
TARGET_PROPERTIES
364378
Fortran_BUILDING_INTRINSIC_MODULES TRUE
365379
Fortran_BUILDING_INSTRINSIC_MODULES TRUE
@@ -414,8 +428,8 @@ else()
414428
# C++ symbols and still requires global data symbols to be annotated
415429
# manually.
416430
add_win_flangrt_runtime(STATIC static MultiThreaded INSTALL_WITH_TOOLCHAIN)
417-
add_win_flangrt_runtime(STATIC dynamic MultiThreadedDLL INSTALL_WITH_TOOLCHAIN)
418431
add_win_flangrt_runtime(STATIC static_dbg MultiThreadedDebug INSTALL_WITH_TOOLCHAIN)
432+
add_win_flangrt_runtime(STATIC dynamic MultiThreadedDLL INSTALL_WITH_TOOLCHAIN)
419433
add_win_flangrt_runtime(STATIC dynamic_dbg MultiThreadedDebugDLL INSTALL_WITH_TOOLCHAIN)
420434

421435
# Unittests link against LLVMSupport which is using CMake's default runtime

flang-rt/lib/runtime/cooperative_groups.f90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
module cooperative_groups
1212

1313
use, intrinsic :: __fortran_builtins, only: c_devptr => __builtin_c_devptr
14+
use :: cudadevice ! implicit dependency, make explicit for CMake
1415

1516
implicit none
1617

flang/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,13 @@ else()
264264
endif()
265265

266266
if (FLANG_STANDALONE_BUILD)
267-
message(STATUS "Not building Flang-RT. For a usable Fortran toolchain, compile a standalone Flang-RT.")
267+
option(FLANG_ENABLE_FLANG_RT "Build flang-rt and modules" ON)
268+
if (FLANG_ENABLE_FLANG_RT)
269+
# TODO: Add runtimes external_project
270+
list(APPEND LLVM_ENABLE_RUNTIMES flang-rt)
271+
else ()
272+
message(STATUS "Not building Flang-RT. For a usable Fortran toolchain, compile a standalone Flang-RT.")
273+
endif ()
268274
elseif (NOT "flang-rt" IN_LIST LLVM_ENABLE_RUNTIMES)
269275
message(STATUS "Not building Flang-RT. For a usable Fortran toolchain, either set FLANG_ENABLE_FLANG_RT=ON, add LLVM_ENABLE_RUNTIMES=flang-rt, or compile a standalone Flang-RT.")
270276
endif ()

flang/lib/Optimizer/CodeGen/CodeGen.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1363,11 +1363,12 @@ getTypeDescriptor(ModOpTy mod, mlir::ConversionPatternRewriter &rewriter,
13631363
name, Fortran::semantics::typeInfoBuiltinModule))
13641364
return rewriter.create<mlir::LLVM::ZeroOp>(loc, llvmPtrTy);
13651365

1366-
if (!options.skipExternalRttiDefinition)
1366+
if (!options.skipExternalRttiDefinition) { llvm::errs() << "type dewxriptor name: '" << name << "'\n";
13671367
fir::emitFatalError(loc,
13681368
"runtime derived type info descriptor was not "
13691369
"generated and skipExternalRttiDefinition and "
13701370
"ignoreMissingTypeDescriptors options are not set");
1371+
}
13711372

13721373
// Rtti for a derived type defined in another compilation unit and for which
13731374
// rtti was not defined in lowering because of the skipExternalRttiDefinition

flang/lib/Parser/prescan.cpp

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,9 +1691,7 @@ Prescanner::IsCompilerDirectiveSentinel(const char *p) const {
16911691
char sentinel[8];
16921692
for (std::size_t j{0}; j + 1 < sizeof sentinel; ++p, ++j) {
16931693
if (int n{IsSpaceOrTab(p)};
1694-
n || !(IsLetter(*p) || *p == '$' || *p == '@'
1695-
//|| *p == '!'
1696-
)) {
1694+
n || !(IsLetter(*p) || *p == '$' || *p == '@')) {
16971695
if (j > 0) {
16981696
if (j == 1 && sentinel[0] == '$' && n == 0 && *p != '&' && *p != '\n') {
16991697
// Free form OpenMP conditional compilation line sentinels have to
@@ -1727,18 +1725,6 @@ constexpr bool IsDirective(const char *match, const char *dir) {
17271725

17281726
Prescanner::LineClassification Prescanner::ClassifyLine(
17291727
const char *start) const {
1730-
if (llvm::StringRef(start).take_front(120).contains('!')) {
1731-
int c = 9;
1732-
}
1733-
if (llvm::StringRef(start).starts_with("real")) {
1734-
int c = 9;
1735-
}
1736-
if (llvm::StringRef(start).starts_with("elemental logical function ieee_is_finite_a")) {
1737-
int c = 9;
1738-
}
1739-
if (llvm::StringRef(start).starts_with("interface ieee_is_finite")) {
1740-
int c = 9;
1741-
}
17421728
if (inFixedForm_) {
17431729
if (std::optional<LineClassification> lc{
17441730
IsFixedFormCompilerDirectiveLine(start)}) {

flang/lib/Semantics/CMakeLists.txt

Lines changed: 26 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,34 @@
1-
add_flang_library(FortranSemantics PARTIAL_SOURCES_INTENDED
1+
add_flang_library(FortranSemantics
22
assignment.cpp
33
attr.cpp
44
canonicalize-acc.cpp
55
canonicalize-directives.cpp
66
canonicalize-do.cpp
77
canonicalize-omp.cpp
8+
check-acc-structure.cpp
9+
check-allocate.cpp
10+
check-arithmeticif.cpp
11+
check-call.cpp
12+
check-case.cpp
13+
check-coarray.cpp
14+
check-cuda.cpp
15+
check-data.cpp
16+
check-deallocate.cpp
17+
check-declarations.cpp
18+
check-do-forall.cpp
19+
check-if-stmt.cpp
20+
check-io.cpp
21+
check-namelist.cpp
22+
check-nullify.cpp
23+
check-omp-atomic.cpp
24+
check-omp-loop.cpp
25+
check-omp-metadirective.cpp
26+
check-omp-structure.cpp
27+
check-purity.cpp
28+
check-return.cpp
29+
check-select-rank.cpp
30+
check-select-type.cpp
31+
check-stop.cpp
832
compute-offsets.cpp
933
data-to-inits.cpp
1034
definable.cpp
@@ -34,6 +58,7 @@ add_flang_library(FortranSemantics PARTIAL_SOURCES_INTENDED
3458
omp_gen
3559

3660
LINK_LIBS
61+
FortranSupport
3762
FortranParser
3863
FortranEvaluate
3964

@@ -52,47 +77,3 @@ target_precompile_headers(FortranSemantics PRIVATE
5277
[["flang/Semantics/tools.h"]]
5378
[["flang/Semantics/symbol.h"]]
5479
)
55-
56-
add_flang_library(FortranSemanticsCheck PARTIAL_SOURCES_INTENDED
57-
check-acc-structure.cpp
58-
check-allocate.cpp
59-
check-arithmeticif.cpp
60-
check-call.cpp
61-
check-case.cpp
62-
check-coarray.cpp
63-
check-cuda.cpp
64-
check-data.cpp
65-
check-deallocate.cpp
66-
check-declarations.cpp
67-
check-do-forall.cpp
68-
check-if-stmt.cpp
69-
check-io.cpp
70-
check-namelist.cpp
71-
check-nullify.cpp
72-
check-omp-atomic.cpp
73-
check-omp-loop.cpp
74-
check-omp-metadirective.cpp
75-
check-omp-structure.cpp
76-
check-purity.cpp
77-
check-return.cpp
78-
check-select-rank.cpp
79-
check-select-type.cpp
80-
check-stop.cpp
81-
82-
DEPENDS
83-
acc_gen
84-
omp_gen
85-
86-
LINK_LIBS
87-
FortranParser
88-
FortranEvaluate
89-
FortranSemantics
90-
91-
LINK_COMPONENTS
92-
Support
93-
FrontendOpenMP
94-
FrontendOpenACC
95-
TargetParser
96-
)
97-
98-
target_link_libraries(FortranSemantics PUBLIC FortranSemanticsCheck)

flang/test/CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,20 +96,26 @@ if (LLVM_BUILD_EXAMPLES)
9696
)
9797
endif ()
9898

99+
if ("flang-rt" IN_LIST LLVM_ENABLE_RUNTIMES AND NOT FLANG_STANDALONE_BUILD)
100+
list(APPEND FLANG_TEST_DEPENDS "flang-rt-mod") # For intrinsic module files (in flang-rt)
101+
endif ()
102+
99103
if ("openmp" IN_LIST LLVM_ENABLE_RUNTIMES AND NOT FLANG_STANDALONE_BUILD)
100-
list(APPEND FLANG_TEST_DEPENDS "libomp-mod")
104+
list(APPEND FLANG_TEST_DEPENDS "libomp-mod") # For omplib.mod and omplib_kinds.mod (in openmp)
101105
endif ()
102106

103107
add_custom_target(flang-test-depends DEPENDS ${FLANG_TEST_DEPENDS})
104108
set_target_properties(flang-test-depends PROPERTIES FOLDER "Flang/Meta")
105109

110+
106111
add_lit_testsuite(check-flang "Running the Flang regression tests"
107112
${CMAKE_CURRENT_BINARY_DIR}
108113
PARAMS ${FLANG_TEST_PARAMS}
109114
DEPENDS ${FLANG_TEST_DEPENDS}
110115
)
111116
set_target_properties(check-flang PROPERTIES FOLDER "Flang/Meta")
112117

118+
#if ("flang-rt" IN_LIST LLVM_ENABLE_RUNTIMES AND NOT FLANG_STANDALONE_BUILD)
113119
# In case of standalone builds.
114120
if (FLANG_STANDALONE_BUILD)
115121
add_lit_testsuites(FLANG ${CMAKE_CURRENT_BINARY_DIR}
@@ -120,6 +126,7 @@ else()
120126
PARAMS ${FLANG_TEST_PARAMS}
121127
DEPENDS ${FLANG_TEST_DEPENDS})
122128
endif()
129+
#endif ()
123130

124131
# To modify the default target triple for flang tests.
125132
if (DEFINED FLANG_TEST_TARGET_TRIPLE)

flang/test/lit.cfg.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,14 @@
177177
if result:
178178
config.environment["LIBPGMATH"] = True
179179

180+
print(f"config.have_flangrt_mod: { config.have_flangrt_mod}")
181+
config.available_features.add("module-independent")
182+
if config.have_flangrt_mod:
183+
config.available_features.add("flangrt-modules")
184+
else:
185+
config.limit_to_features.add("module-independent")
186+
187+
180188
# Determine if OpenMP runtime was built (enable OpenMP tests via REQUIRES in test file)
181189
openmp_flags_substitution = "-fopenmp"
182190
if config.have_openmp_rtl:

0 commit comments

Comments
 (0)