Skip to content

Commit 7b73ca3

Browse files
committed
[flang][driver] Delete f18 (i.e. the old Flang driver)
This patch removes `f18`, a.k.a. the old driver. It is being replaced with the new driver, `flang-new`, which has reached feature parity with `f18` a while ago. This was discussed in [1] and also in [2]. With this change, `FLANG_BUILD_NEW_DRIVER` is no longer needed and is also deleted. This means that we are making the dependency on Clang permanent (i.e. it cannot be disabled with a CMake flag). LIT set-up is updated accordingly. All references to `f18` or `f18.cpp` are either updated or removed. The `F18_FC` variable from the `flang` bash script is replaced with `FLANG_FC`. The former is still supported for backwards compatibility. [1] https://lists.llvm.org/pipermail/flang-dev/2021-June/000742.html [2] https://reviews.llvm.org/D103177 Differential Revision: https://reviews.llvm.org/D105811
1 parent 7217b01 commit 7b73ca3

File tree

17 files changed

+78
-991
lines changed

17 files changed

+78
-991
lines changed

flang/CMakeLists.txt

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
2626
project(Flang)
2727
set(FLANG_STANDALONE_BUILD ON)
2828

29-
# For in-tree builds, this variable is inherited from
30-
# llvm-project/llvm/CMakeLists.txt. For out-of-tree builds, we need a
31-
# separate definition.
32-
option(FLANG_BUILD_NEW_DRIVER "Build the flang compiler driver" ON)
33-
3429
set(FLANG_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
3530
if (NOT MSVC_IDE)
3631
set(LLVM_ENABLE_ASSERTIONS ${ENABLE_ASSERTIONS}
@@ -46,24 +41,22 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
4641
get_filename_component(LLVM_DIR_ABSOLUTE ${LLVM_DIR} REALPATH)
4742
list(APPEND CMAKE_MODULE_PATH ${LLVM_DIR_ABSOLUTE})
4843

49-
if(FLANG_BUILD_NEW_DRIVER)
50-
# Users might specify a path to CLANG_DIR that's:
51-
# * a full path, or
52-
# * a path relative to the path of this script.
53-
# Append the absolute path to CLANG_DIR so that find_package works in both
54-
# cases.
55-
get_filename_component(
56-
CLANG_DIR_ABSOLUTE
57-
${CLANG_DIR}
58-
REALPATH
59-
${CMAKE_CURRENT_SOURCE_DIR})
60-
list(APPEND CMAKE_MODULE_PATH ${CLANG_DIR_ABSOLUTE})
61-
62-
# TODO: Remove when libclangDriver is lifted out of Clang
63-
find_package(Clang REQUIRED PATHS "${CLANG_DIR_ABSOLUTE}" NO_DEFAULT_PATH)
64-
if (NOT Clang_FOUND)
65-
message(FATAL_ERROR "Failed to find Clang")
66-
endif()
44+
# Users might specify a path to CLANG_DIR that's:
45+
# * a full path, or
46+
# * a path relative to the path of this script.
47+
# Append the absolute path to CLANG_DIR so that find_package works in both
48+
# cases.
49+
get_filename_component(
50+
CLANG_DIR_ABSOLUTE
51+
${CLANG_DIR}
52+
REALPATH
53+
${CMAKE_CURRENT_SOURCE_DIR})
54+
list(APPEND CMAKE_MODULE_PATH ${CLANG_DIR_ABSOLUTE})
55+
56+
# TODO: Remove when libclangDriver is lifted out of Clang
57+
find_package(Clang REQUIRED PATHS "${CLANG_DIR_ABSOLUTE}" NO_DEFAULT_PATH)
58+
if (NOT Clang_FOUND)
59+
message(FATAL_ERROR "Failed to find Clang")
6760
endif()
6861

6962
# If LLVM links to zlib we need the imported targets so we can too.
@@ -80,9 +73,7 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
8073
include(HandleLLVMOptions)
8174
include(VersionFromVCS)
8275

83-
if(FLANG_BUILD_NEW_DRIVER)
84-
include(AddClang)
85-
endif()
76+
include(AddClang)
8677

8778
include(TableGen)
8879
find_package(MLIR REQUIRED CONFIG)
@@ -206,20 +197,18 @@ endif()
206197
set(FLANG_INTRINSIC_MODULES_DIR ${CMAKE_BINARY_DIR}/include/flang)
207198
set(FLANG_INCLUDE_DIR ${FLANG_BINARY_DIR}/include)
208199

209-
if(FLANG_BUILD_NEW_DRIVER)
210-
# TODO: Remove when libclangDriver is lifted out of Clang
211-
if(FLANG_STANDALONE_BUILD)
212-
set(CLANG_INCLUDE_DIR ${CLANG_INCLUDE_DIRS} )
213-
# No need to specify TableGen output dir as that's embedded in CLANG_DIR
214-
else()
215-
set(CLANG_INCLUDE_DIR ${LLVM_MAIN_SRC_DIR}/../clang/include )
216-
# Specify TableGen output dir for things like DiagnosticCommonKinds.inc,
217-
# DiagnosticDriverKinds.inc (required for reporting diagnostics)
218-
set(CLANG_TABLEGEN_OUTPUT_DIR ${CMAKE_BINARY_DIR}/tools/clang/include)
219-
include_directories(SYSTEM ${CLANG_TABLEGEN_OUTPUT_DIR})
220-
endif()
221-
include_directories(SYSTEM ${CLANG_INCLUDE_DIR})
200+
# TODO: Remove when libclangDriver is lifted out of Clang
201+
if(FLANG_STANDALONE_BUILD)
202+
set(CLANG_INCLUDE_DIR ${CLANG_INCLUDE_DIRS} )
203+
# No need to specify TableGen output dir as that's embedded in CLANG_DIR
204+
else()
205+
set(CLANG_INCLUDE_DIR ${LLVM_MAIN_SRC_DIR}/../clang/include )
206+
# Specify TableGen output dir for things like DiagnosticCommonKinds.inc,
207+
# DiagnosticDriverKinds.inc (required for reporting diagnostics)
208+
set(CLANG_TABLEGEN_OUTPUT_DIR ${CMAKE_BINARY_DIR}/tools/clang/include)
209+
include_directories(SYSTEM ${CLANG_TABLEGEN_OUTPUT_DIR})
222210
endif()
211+
include_directories(SYSTEM ${CLANG_INCLUDE_DIR})
223212

224213
# tco tool and FIR lib output directories
225214
if(FLANG_STANDALONE_BUILD)

flang/docs/ImplementingASemanticCheck.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
:local:
1313
```
1414

15-
I recently added a semantic check to the f18 compiler front end. This document
15+
I recently added a semantic check to the Flang compiler front end. This document
1616
describes my thought process and the resulting implementation.
1717

1818
For more information about the compiler, start with the
@@ -67,7 +67,7 @@ of the call to `intentOutFunc()`:
6767

6868
I also used this program to produce a parse tree for the program using the command:
6969
```bash
70-
f18 -fdebug-dump-parse-tree -fsyntax-only testfun.f90
70+
flang-new -fc1 -fdebug-dump-parse-tree testfun.f90
7171
```
7272

7373
Here's the relevant fragment of the parse tree produced by the compiler:
@@ -295,7 +295,7 @@ In `lib/Semantics/check-do.cpp`, I added an (almost empty) implementation:
295295
I then built the compiler with these changes and ran it on my test program.
296296
This time, I made sure to invoke semantic checking. Here's the command I used:
297297
```bash
298-
f18 -fdebug-resolve-names -fdebug-dump-parse-tree -funparse-with-symbols testfun.f90
298+
flang-new -fc1 -fdebug-unparse-with-symbols testfun.f90
299299
```
300300

301301
This produced the output:
@@ -361,7 +361,7 @@ I noted that a `SymbolSet` did not actually contain an
361361
full `semantics::Symbol` objects into the set. Ideally, we would be able to create an
362362
`std::set<Symbol &>` (a set of C++ references to symbols). But C++ doesn't
363363
support sets that contain references. This limitation is part of the rationale
364-
for the f18 implementation of type `common::Reference`, which is defined in
364+
for the Flang implementation of type `common::Reference`, which is defined in
365365
`include/flang/Common/reference.h`.
366366
367367
`SymbolRef`, the specialization of the template `common::Reference` for

flang/docs/Overview.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
77
-->
88

9+
# Intro
10+
This document goes briefly over compiler phases in Flang. It focuses on the
11+
internal implementation and as such, it is intended for Flang developers rather
12+
than end-users.
13+
914
# Overview of Compiler Phases
1015

1116
```eval_rst
@@ -33,7 +38,7 @@ See: [Preprocessing.md](Preprocessing.md).
3338

3439
**Entry point:** `parser::Parsing::Prescan`
3540

36-
**Command:** `f18 -E src.f90` dumps the cooked character stream
41+
**Command:** `flang-new -fc1 -E src.f90` dumps the cooked character stream
3742

3843
## Parse
3944

@@ -46,8 +51,8 @@ See: [Preprocessing.md](Preprocessing.md).
4651
**Entry point:** `parser::Parsing::Parse`
4752

4853
**Command:**
49-
- `f18 -fdebug-dump-parse-tree -fsyntax-only src.f90` dumps the parse tree
50-
- `f18 -funparse src.f90` converts the parse tree to normalized Fortran
54+
- `flang-new -fc1 -fdebug-dump-parse-tree src.f90` dumps the parse tree
55+
- `flang-new -fc1 -fdebug-unparse src.f90` converts the parse tree to normalized Fortran
5156

5257
## Validate Labels and Canonicalize Do Statements
5358

@@ -74,7 +79,7 @@ See: [Preprocessing.md](Preprocessing.md).
7479

7580
**Entry points:** `semantics::ResolveNames`, `semantics::RewriteParseTree`
7681

77-
**Command:** `f18 -fdebug-dump-symbols -fsyntax-only src.f90` dumps the
82+
**Command:** `flang-new -fc1 -fdebug-dump-symbols src.f90` dumps the
7883
tree of scopes and symbols in each scope
7984

8085
## Check DO CONCURRENT Constraints

flang/include/flang/Frontend/CompilerInvocation.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,7 @@ class CompilerInvocation : public CompilerInvocationBase {
184184
useAnalyzedObjectsForUnparse_ = flag;
185185
}
186186

187-
/// Set the Fortran options to predifined defaults. These defaults are
188-
/// consistend with f18/f18.cpp.
187+
/// Set the Fortran options to predefined defaults.
189188
// TODO: We should map frontendOpts_ to parserOpts_ instead. For that, we
190189
// need to extend frontendOpts_ first. Next, we need to add the corresponding
191190
// compiler driver options in libclangDriver.

flang/include/flang/Frontend/FrontendOptions.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,6 @@ enum ActionKind {
8787
/// \return True if the file extension should be processed as fixed form
8888
bool isFixedFormSuffix(llvm::StringRef suffix);
8989

90-
// TODO: Find a more suitable location for this. Added for compability with
91-
// f18.cpp (this is equivalent to `asFortran` defined there).
92-
Fortran::parser::AnalyzedObjectsAsFortran getBasicAsFortran();
93-
9490
/// \param suffix The file extension
9591
/// \return True if the file extension should be processed as free form
9692
bool isFreeFormSuffix(llvm::StringRef suffix);

flang/lib/CMakeLists.txt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ add_subdirectory(Decimal)
44
add_subdirectory(Lower)
55
add_subdirectory(Parser)
66
add_subdirectory(Semantics)
7-
8-
if(FLANG_BUILD_NEW_DRIVER)
9-
add_subdirectory(Frontend)
10-
add_subdirectory(FrontendTool)
11-
endif()
7+
add_subdirectory(Frontend)
8+
add_subdirectory(FrontendTool)
129

1310
add_subdirectory(Optimizer)

flang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,6 @@ void CompilerInvocation::collectMacroDefinitions() {
571571
void CompilerInvocation::SetDefaultFortranOpts() {
572572
auto &fortranOptions = fortranOpts();
573573

574-
// These defaults are based on the defaults in f18/f18.cpp.
575574
std::vector<std::string> searchDirectories{"."s};
576575
fortranOptions.searchDirectories = searchDirectories;
577576
fortranOptions.isFixedForm = false;

flang/test/CMakeLists.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,9 @@ set(FLANG_TEST_PARAMS
3232
flang_site_config=${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py)
3333

3434
set(FLANG_TEST_DEPENDS
35-
f18 FileCheck count not module_files fir-opt tco
35+
flang-new FileCheck count not module_files fir-opt tco
3636
)
3737

38-
if (FLANG_BUILD_NEW_DRIVER)
39-
list(APPEND FLANG_TEST_DEPENDS flang-new)
40-
endif()
41-
4238
if (FLANG_INCLUDE_TESTS)
4339
if (FLANG_GTEST_AVAIL)
4440
list(APPEND FLANG_TEST_DEPENDS FlangUnitTests)

flang/test/Driver/help-f18.f90

Lines changed: 0 additions & 12 deletions
This file was deleted.

flang/test/lit.cfg.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@
4040

4141
# If the new Flang driver is enabled, add the corresponding feature to
4242
# config.
43-
if config.include_flang_new_driver_test:
44-
config.available_features.add('new-flang-driver')
45-
else:
46-
config.available_features.add('old-flang-driver')
43+
config.available_features.add('new-flang-driver')
4744

4845
# test_source_root: The root path where tests are located.
4946
config.test_source_root = os.path.dirname(__file__)
@@ -64,16 +61,10 @@
6461

6562
# For each occurrence of a flang tool name, replace it with the full path to
6663
# the build directory holding that tool.
67-
tools = []
68-
if config.include_flang_new_driver_test:
69-
tools.append(ToolSubst('%flang', command=FindTool('flang-new'), unresolved='fatal'))
70-
tools.append(ToolSubst('%flang_fc1', command=FindTool('flang-new'),
71-
extra_args=['-fc1'], unresolved='fatal'))
72-
else:
73-
tools.append(ToolSubst('%flang', command=FindTool('f18'),
74-
unresolved='fatal'))
75-
tools.append(ToolSubst('%flang_fc1', command=FindTool('f18'),
76-
unresolved='fatal'))
64+
tools = [
65+
ToolSubst('%flang', command=FindTool('flang-new'), unresolved='fatal'),
66+
ToolSubst('%flang_fc1', command=FindTool('flang-new'), extra_args=['-fc1'],
67+
unresolved='fatal')]
7768

7869
# Define some variables to help us test that the flang runtime doesn't depend on
7970
# the C++ runtime libraries. For this we need a C compiler. If for some reason

flang/test/lit.site.cfg.py.in

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ config.python_executable = "@PYTHON_EXECUTABLE@"
1414
config.flang_standalone_build = @FLANG_STANDALONE_BUILD@
1515
config.cc = "@CMAKE_C_COMPILER@"
1616

17-
# Control the regression test for flang-new driver
18-
import lit.util
19-
config.include_flang_new_driver_test = \
20-
lit.util.pythonize_bool("@FLANG_BUILD_NEW_DRIVER@")
21-
2217
# Support substitution of the tools_dir with user parameters. This is
2318
# used when we can't determine the tool dir at configuration time.
2419
try:

flang/tools/CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
#===------------------------------------------------------------------------===#
88

99
add_subdirectory(f18)
10-
if(FLANG_BUILD_NEW_DRIVER)
11-
add_subdirectory(flang-driver)
12-
endif()
10+
add_subdirectory(flang-driver)
1311
add_subdirectory(tco)
1412
add_subdirectory(f18-parse-demo)
1513
add_subdirectory(fir-opt)

flang/tools/f18/CMakeLists.txt

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,6 @@ set(LLVM_LINK_COMPONENTS
33
FrontendOpenMP
44
Support
55
)
6-
add_flang_tool(f18
7-
dump.cpp
8-
f18.cpp
9-
)
10-
11-
target_link_libraries(f18
12-
PRIVATE
13-
FortranCommon
14-
FortranParser
15-
FortranEvaluate
16-
FortranSemantics
17-
FortranLower
18-
)
196

207
set(MODULES
218
"__fortran_builtins"
@@ -30,11 +17,6 @@ set(MODULES
3017
"__fortran_type_info"
3118
)
3219

33-
target_include_directories(f18
34-
PRIVATE
35-
${CMAKE_CURRENT_BINARY_DIR}
36-
)
37-
3820
# Create module files directly from the top-level module source directory
3921
foreach(filename ${MODULES})
4022
set(base ${FLANG_INTRINSIC_MODULES_DIR}/${filename})
@@ -47,9 +29,9 @@ foreach(filename ${MODULES})
4729
endif()
4830
add_custom_command(OUTPUT ${base}.mod
4931
COMMAND ${CMAKE_COMMAND} -E make_directory ${FLANG_INTRINSIC_MODULES_DIR}
50-
COMMAND f18 -fsyntax-only -module-dir ${FLANG_INTRINSIC_MODULES_DIR}
32+
COMMAND flang-new -fc1 -fsyntax-only -module-dir ${FLANG_INTRINSIC_MODULES_DIR}
5133
${FLANG_SOURCE_DIR}/module/${filename}.f90
52-
DEPENDS f18 ${FLANG_SOURCE_DIR}/module/${filename}.f90 ${depends}
34+
DEPENDS flang-new ${FLANG_SOURCE_DIR}/module/${filename}.f90 ${depends}
5335
)
5436
add_custom_command(OUTPUT ${base}.f18.mod
5537
DEPENDS ${base}.mod
@@ -60,15 +42,10 @@ endforeach()
6042

6143
add_custom_target(module_files ALL DEPENDS ${MODULE_FILES})
6244

63-
install(TARGETS f18 DESTINATION bin)
64-
65-
set(FLANG_DEFAULT_DRIVER "flang-new")
66-
if (NOT FLANG_BUILD_NEW_DRIVER)
67-
set(FLANG_DEFAULT_DRIVER "f18")
68-
endif()
69-
7045
# This flang shell script will only work in a POSIX shell.
7146
if (NOT WIN32)
72-
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/flang.in ${CMAKE_BINARY_DIR}/bin/flang @ONLY)
47+
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/flang
48+
DESTINATION ${CMAKE_BINARY_DIR}/bin
49+
FILE_PERMISSIONS OWNER_EXECUTE OWNER_READ OWNER_WRITE)
7350
install(PROGRAMS ${CMAKE_BINARY_DIR}/bin/flang DESTINATION bin)
7451
endif()

0 commit comments

Comments
 (0)