Skip to content

Commit

Permalink
[flang] [mlir rebase] Add MLIR config and react to MLIR name changes (f…
Browse files Browse the repository at this point in the history
…lang-compiler/f18#1090)

[mlir rebase] Add MLIR config and react to MLIR name changes

Similar to flang-compiler/f18#1085.  Now use the MLIR package to set up paths for include files and libraries.  Three MLIR names changed:
 * VectorOpsDialect to VectorDialect
 * AffineOpsDialect to AffineDialect
 * createVectorizePass to createSuperVectorizePass

Update README.md to explain how to link with MLIR. Update the example gcc to version 8.3.

Update drone.io config to define -DMLIR_DIR

Co-authored-by: Jean Perier <jperier@nvidia.com>

Original-commit: flang-compiler/f18@116f643
Reviewed-on: flang-compiler/f18#1090
  • Loading branch information
sscalpone authored Mar 27, 2020
1 parent 643edd5 commit 282358f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 18 deletions.
4 changes: 2 additions & 2 deletions flang/.drone.star
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def clang(arch):
"ninja install",
"cd ../..",
"mkdir build && cd build",
'env CC=clang-8 CXX=clang++-8 CXXFLAGS="-UNDEBUG -stdlib=libc++" LDFLAGS="-fuse-ld=lld" cmake -GNinja -DCMAKE_BUILD_TYPE=Release .. -DLLVM_DIR=/drone/src/llvm-project/install/lib/cmake/llvm -DLLVM_EXTERNAL_LIT=/drone/src/llvm-project/build/bin/llvm-lit',
'env CC=clang-8 CXX=clang++-8 CXXFLAGS="-UNDEBUG -stdlib=libc++" LDFLAGS="-fuse-ld=lld" cmake -GNinja -DCMAKE_BUILD_TYPE=Release .. -DLLVM_DIR=/drone/src/llvm-project/install/lib/cmake/llvm -DMLIR_DIR=/drone/src/llvm-project/install/lib/cmake/mlir -DLLVM_EXTERNAL_LIT=/drone/src/llvm-project/build/bin/llvm-lit',
"ninja -j8",
"ctest --output-on-failure -j24",
"ninja check-all",
Expand All @@ -40,7 +40,7 @@ def gcc(arch):
"ninja install",
"cd ../..",
"mkdir build && cd build",
'env CC=gcc CXX=g++ CXXFLAGS="-UNDEBUG" LDFLAGS="-fuse-ld=gold" cmake -GNinja -DCMAKE_BUILD_TYPE=Release .. -DLLVM_DIR=/drone/src/llvm-project/install/lib/cmake/llvm -DLLVM_EXTERNAL_LIT=/drone/src/llvm-project/build/bin/llvm-lit',
'env CC=gcc CXX=g++ CXXFLAGS="-UNDEBUG" LDFLAGS="-fuse-ld=gold" cmake -GNinja -DCMAKE_BUILD_TYPE=Release .. -DLLVM_DIR=/drone/src/llvm-project/install/lib/cmake/llvm -DMLIR_DIR=/drone/src/llvm-project/install/lib/cmake/mlir -DLLVM_EXTERNAL_LIT=/drone/src/llvm-project/build/bin/llvm-lit',
"ninja -j8",
"ctest --output-on-failure -j24",
"ninja check-all",
Expand Down
4 changes: 4 additions & 0 deletions flang/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ project(Flang)

if(LINK_WITH_FIR)
include(TableGen)
find_package(MLIR REQUIRED CONFIG)
# Use SYSTEM for the same reasons as for LLVM includes
include_directories(SYSTEM ${MLIR_INCLUDE_DIRS})
list(APPEND CMAKE_MODULE_PATH ${MLIR_DIR})
include(AddMLIR)
find_program(MLIR_TABLEGEN_EXE "mlir-tblgen" ${LLVM_TOOLS_BINARY_DIR}
NO_DEFAULT_PATH)
Expand Down
34 changes: 21 additions & 13 deletions flang/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<!--===- README.md
<!--===- README.md
Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
See https://llvm.org/LICENSE.txt for license information.
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-->

# F18
Expand Down Expand Up @@ -72,12 +72,16 @@ https://llvm.org/docs/GettingStarted.html.
We highly recommend using the same compiler to compile both llvm and f18.

The f18 CMakeList.txt file uses
the variable `LLVM_DIR` to find the installed components.
the variable `LLVM_DIR` to find the installed LLVM components
and
the variable `MLIR_DIR` to find the installed MLIR components.

To get the correct LLVM libraries included in your f18 build,
define LLVM_DIR on the cmake command line.
To get the correct LLVM and MLIR libraries included in your f18 build,
define LLVM_DIR and MLIR_DIR on the cmake command line.
```
LLVM=<LLVM_BUILD_DIR>/lib/cmake/llvm cmake -DLLVM_DIR=$LLVM ...
LLVM=<LLVM_BUILD_DIR>/lib/cmake/llvm \
MLIR=<LLVM_BUILD_DIR>/lib/cmake/mlir \
cmake -DLLVM_DIR=$LLVM -DMLIR_DIR=$MLIR ...
```
where `LLVM_BUILD_DIR` is
the top-level directory where LLVM was built.
Expand Down Expand Up @@ -121,7 +125,11 @@ make install
```

Then, `-DLLVM_DIR` would have to be set to
`<where/you/want/to/build/llvm>/install/lib/cmake/llvm` in f18 cmake command.
`<where/you/want/to/build/llvm>/install/lib/cmake/llvm`
and, `-DMLIR_DIR` would have to be set to
`<where/you/want/to/build/llvm>/install/lib/cmake/mlir`

in f18 cmake command.

To run lit tests,
`-DLLVM_EXTERNAL_LIT=<where/you/want/to/build/llvm>/build/bin/llvm-lit` must be
Expand All @@ -142,13 +150,13 @@ Or,
cmake will use the variable CXX to find the C++ compiler.
CXX should include the full path to the compiler
or a name that will be found on your PATH,
e.g. g++-7.2, assuming g++-7.2 is on your PATH.
e.g. g++-8.3, assuming g++-8.3 is on your PATH.
```
export CXX=g++-7.2
export CXX=g++-8.3
```
or
```
CXX=/opt/gcc-7.2/bin/g++-7.2 cmake ...
CXX=/opt/gcc-8.3/bin/g++-8.3 cmake ...
```

### Building f18 with clang
Expand Down Expand Up @@ -189,7 +197,7 @@ Release builds execute quickly.
### Build F18
```
cd ~/f18/build
cmake -DLLVM_DIR=$LLVM ~/f18/src
cmake -DLLVM_DIR=$LLVM -DMLIR_DIR=$MLIR ~/f18/src
make
```

Expand All @@ -198,7 +206,7 @@ make
To run all tests:
```
cd ~/f18/build
cmake -DLLVM_DIR=$LLVM ~/f18/src
cmake -DLLVM_DIR=$LLVM -DMLIR_DIR=$MLIR ~/f18/src
make test check-all
```

Expand Down
6 changes: 3 additions & 3 deletions flang/include/flang/Optimizer/Dialect/FIRDialect.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ class FIROpsDialect final : public mlir::Dialect {
inline void registerFIR() {
// we want to register exactly once
[[maybe_unused]] static bool init_once = [] {
mlir::registerDialect<mlir::AffineOpsDialect>();
mlir::registerDialect<mlir::AffineDialect>();
mlir::registerDialect<mlir::LLVM::LLVMDialect>();
mlir::registerDialect<mlir::loop::LoopOpsDialect>();
mlir::registerDialect<mlir::StandardOpsDialect>();
mlir::registerDialect<mlir::vector::VectorOpsDialect>();
mlir::registerDialect<mlir::vector::VectorDialect>();
mlir::registerDialect<FIROpsDialect>();
return true;
}();
Expand All @@ -65,7 +65,7 @@ inline void registerFIR() {
inline void registerGeneralPasses() {
mlir::createCanonicalizerPass();
mlir::createCSEPass();
mlir::createVectorizePass({});
mlir::createSuperVectorizePass({});
mlir::createLoopUnrollPass();
mlir::createLoopUnrollAndJamPass();
mlir::createSimplifyAffineStructuresPass();
Expand Down

0 comments on commit 282358f

Please sign in to comment.