Skip to content

Commit

Permalink
[flang][cmake] Enable the new driver by default
Browse files Browse the repository at this point in the history
With this patch, `FLANG_BUILD_NEW_DRIVER` is set to `On` by default
(i.e. the new driver is enabled). Note that the new driver depends on
Clang and hence with this change you will need to add `clang` to
`LLVM_ENABLE_PROJECTS`.

If you don't want to build the new driver, set `FLANG_BUILD_NEW_DRIVER`
to `Off`. This way you won't be required to include `clang` in
`LLVM_ENABLE_PROJECTS`.

Differential Revision: https://reviews.llvm.org/D101842
  • Loading branch information
banach-space committed May 11, 2021
1 parent 05d1ae4 commit 04adfb6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 25 deletions.
2 changes: 0 additions & 2 deletions flang/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ cmake_minimum_required(VERSION 3.13.4)

set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON)

option(FLANG_BUILD_NEW_DRIVER "Build the flang compiler driver" OFF)

# Flang requires C++17.
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
Expand Down
35 changes: 15 additions & 20 deletions flang/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,17 @@ of LLVM, follow those instructions and add flang to `LLVM_ENABLE_PROJECTS`.
We highly recommend using the same compiler to compile both llvm and flang.

The flang CMakeList.txt file uses
the variable `LLVM_DIR` to find the installed LLVM components
and
the variable `MLIR_DIR` to find the installed MLIR components.
* `LLVM_DIR` to find the installed LLVM components
* `MLIR_DIR` to find the installed MLIR components
* `CLANG_DIR` to find the installed Clang components

To get the correct LLVM and MLIR libraries included in your flang build,
define LLVM_DIR and MLIR_DIR on the cmake command line.
To get the correct LLVM, MLIR and Clang libraries included in your flang build,
define `LLVM_DIR`, `MLIR_DIR` and `CLANG_DIR` on the cmake command line.
```
LLVM=<LLVM_BUILD_DIR>/lib/cmake/llvm \
MLIR=<LLVM_BUILD_DIR>/lib/cmake/mlir \
cmake -DLLVM_DIR=$LLVM -DMLIR_DIR=$MLIR ...
CLANG=<LLVM_BUILD_DIR>/lib/cmake/clang \
cmake -DLLVM_DIR=$LLVM -DMLIR_DIR=$MLIR -DCLANG_DIR=$CLANG ...
```
where `LLVM_BUILD_DIR` is
the top-level directory where LLVM was built.
Expand Down Expand Up @@ -140,23 +141,17 @@ Release builds execute quickly.
### Build Flang out of tree
```
cd ~/flang/build
cmake -DLLVM_DIR=$LLVM -DMLIR_DIR=$MLIR ~/flang/src
cmake -DLLVM_DIR=$LLVM -DMLIR_DIR=$MLIR -DCLANG_DIR=$CLANG ~/flang/src
make
```

### Build The New Flang Driver
The new Flang driver, `flang-new`, is currently under active development and
should be considered as an experimental feature. For this reason it is disabled
by default. This will change once the new driver replaces the _throwaway_
driver, `flang`.

In order to build the new driver, add `-DFLANG_BUILD_NEW_DRIVER=ON` to your
CMake invocation line. Additionally, when building out-of-tree, use `CLANG_DIR`
(similarly to `LLVM_DIR` and `MLIR_DIR`) to find the installed Clang
components.

**Note:** `CLANG_DIR` is only required when building the new Flang driver,
which currently depends on Clang.
### Disable The New Flang Driver
The new Flang compiler driver, `flang-new`, is implemented in terms of
`clangDriver` and hence it introduces a dependency on Clang. This dependency is
otherwise not required. If you do not require the new driver, you can disable
it by adding `-DFLANG_BUILD_NEW_DRIVER=OFF` to your CMake invocation. With the
new driver disabled, you no longer need to add `clang` to
`LLVM_ENABLE_PROJECTS` (or to specify `CLANG_DIR` when building out-of-tree).

# How to Run Tests

Expand Down
14 changes: 11 additions & 3 deletions llvm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,17 @@ set(LLVM_ENABLE_PROJECTS "" CACHE STRING
if( LLVM_ENABLE_PROJECTS STREQUAL "all" )
set( LLVM_ENABLE_PROJECTS ${LLVM_ALL_PROJECTS})
endif()
if ("flang" IN_LIST LLVM_ENABLE_PROJECTS AND NOT "mlir" IN_LIST LLVM_ENABLE_PROJECTS)
message(STATUS "Enabling MLIR as a dependency to flang")
list(APPEND LLVM_ENABLE_PROJECTS "mlir")

if ("flang" IN_LIST LLVM_ENABLE_PROJECTS)
if (NOT "mlir" IN_LIST LLVM_ENABLE_PROJECTS)
message(STATUS "Enabling MLIR as a dependency to flang")
list(APPEND LLVM_ENABLE_PROJECTS "mlir")
endif()

option(FLANG_BUILD_NEW_DRIVER "Build the flang compiler driver" ON)
if (FLANG_BUILD_NEW_DRIVER AND NOT "clang" IN_LIST LLVM_ENABLE_PROJECTS)
message(FATAL_ERROR "Clang is not enabled, but it's required by the new Flang driver")
endif()
endif()

# LLVM_ENABLE_PROJECTS_USED is `ON` if the user has ever used the
Expand Down

0 comments on commit 04adfb6

Please sign in to comment.