Skip to content

Commit 282358f

Browse files
authored
[flang] [mlir rebase] Add MLIR config and react to MLIR name changes (flang-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 <[email protected]> Original-commit: flang-compiler/f18@116f643 Reviewed-on: flang-compiler/f18#1090
1 parent 643edd5 commit 282358f

File tree

4 files changed

+30
-18
lines changed

4 files changed

+30
-18
lines changed

flang/.drone.star

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def clang(arch):
1414
"ninja install",
1515
"cd ../..",
1616
"mkdir build && cd build",
17-
'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',
17+
'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',
1818
"ninja -j8",
1919
"ctest --output-on-failure -j24",
2020
"ninja check-all",
@@ -40,7 +40,7 @@ def gcc(arch):
4040
"ninja install",
4141
"cd ../..",
4242
"mkdir build && cd build",
43-
'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',
43+
'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',
4444
"ninja -j8",
4545
"ctest --output-on-failure -j24",
4646
"ninja check-all",

flang/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ project(Flang)
6767

6868
if(LINK_WITH_FIR)
6969
include(TableGen)
70+
find_package(MLIR REQUIRED CONFIG)
71+
# Use SYSTEM for the same reasons as for LLVM includes
72+
include_directories(SYSTEM ${MLIR_INCLUDE_DIRS})
73+
list(APPEND CMAKE_MODULE_PATH ${MLIR_DIR})
7074
include(AddMLIR)
7175
find_program(MLIR_TABLEGEN_EXE "mlir-tblgen" ${LLVM_TOOLS_BINARY_DIR}
7276
NO_DEFAULT_PATH)

flang/README.md

+21-13
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
<!--===- README.md
2-
1+
<!--===- README.md
2+
33
Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
See https://llvm.org/LICENSE.txt for license information.
55
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6-
6+
77
-->
88

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

7474
The f18 CMakeList.txt file uses
75-
the variable `LLVM_DIR` to find the installed components.
75+
the variable `LLVM_DIR` to find the installed LLVM components
76+
and
77+
the variable `MLIR_DIR` to find the installed MLIR components.
7678

77-
To get the correct LLVM libraries included in your f18 build,
78-
define LLVM_DIR on the cmake command line.
79+
To get the correct LLVM and MLIR libraries included in your f18 build,
80+
define LLVM_DIR and MLIR_DIR on the cmake command line.
7981
```
80-
LLVM=<LLVM_BUILD_DIR>/lib/cmake/llvm cmake -DLLVM_DIR=$LLVM ...
82+
LLVM=<LLVM_BUILD_DIR>/lib/cmake/llvm \
83+
MLIR=<LLVM_BUILD_DIR>/lib/cmake/mlir \
84+
cmake -DLLVM_DIR=$LLVM -DMLIR_DIR=$MLIR ...
8185
```
8286
where `LLVM_BUILD_DIR` is
8387
the top-level directory where LLVM was built.
@@ -121,7 +125,11 @@ make install
121125
```
122126

123127
Then, `-DLLVM_DIR` would have to be set to
124-
`<where/you/want/to/build/llvm>/install/lib/cmake/llvm` in f18 cmake command.
128+
`<where/you/want/to/build/llvm>/install/lib/cmake/llvm`
129+
and, `-DMLIR_DIR` would have to be set to
130+
`<where/you/want/to/build/llvm>/install/lib/cmake/mlir`
131+
132+
in f18 cmake command.
125133

126134
To run lit tests,
127135
`-DLLVM_EXTERNAL_LIT=<where/you/want/to/build/llvm>/build/bin/llvm-lit` must be
@@ -142,13 +150,13 @@ Or,
142150
cmake will use the variable CXX to find the C++ compiler.
143151
CXX should include the full path to the compiler
144152
or a name that will be found on your PATH,
145-
e.g. g++-7.2, assuming g++-7.2 is on your PATH.
153+
e.g. g++-8.3, assuming g++-8.3 is on your PATH.
146154
```
147-
export CXX=g++-7.2
155+
export CXX=g++-8.3
148156
```
149157
or
150158
```
151-
CXX=/opt/gcc-7.2/bin/g++-7.2 cmake ...
159+
CXX=/opt/gcc-8.3/bin/g++-8.3 cmake ...
152160
```
153161

154162
### Building f18 with clang
@@ -189,7 +197,7 @@ Release builds execute quickly.
189197
### Build F18
190198
```
191199
cd ~/f18/build
192-
cmake -DLLVM_DIR=$LLVM ~/f18/src
200+
cmake -DLLVM_DIR=$LLVM -DMLIR_DIR=$MLIR ~/f18/src
193201
make
194202
```
195203

@@ -198,7 +206,7 @@ make
198206
To run all tests:
199207
```
200208
cd ~/f18/build
201-
cmake -DLLVM_DIR=$LLVM ~/f18/src
209+
cmake -DLLVM_DIR=$LLVM -DMLIR_DIR=$MLIR ~/f18/src
202210
make test check-all
203211
```
204212

flang/include/flang/Optimizer/Dialect/FIRDialect.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ class FIROpsDialect final : public mlir::Dialect {
5050
inline void registerFIR() {
5151
// we want to register exactly once
5252
[[maybe_unused]] static bool init_once = [] {
53-
mlir::registerDialect<mlir::AffineOpsDialect>();
53+
mlir::registerDialect<mlir::AffineDialect>();
5454
mlir::registerDialect<mlir::LLVM::LLVMDialect>();
5555
mlir::registerDialect<mlir::loop::LoopOpsDialect>();
5656
mlir::registerDialect<mlir::StandardOpsDialect>();
57-
mlir::registerDialect<mlir::vector::VectorOpsDialect>();
57+
mlir::registerDialect<mlir::vector::VectorDialect>();
5858
mlir::registerDialect<FIROpsDialect>();
5959
return true;
6060
}();
@@ -65,7 +65,7 @@ inline void registerFIR() {
6565
inline void registerGeneralPasses() {
6666
mlir::createCanonicalizerPass();
6767
mlir::createCSEPass();
68-
mlir::createVectorizePass({});
68+
mlir::createSuperVectorizePass({});
6969
mlir::createLoopUnrollPass();
7070
mlir::createLoopUnrollAndJamPass();
7171
mlir::createSimplifyAffineStructuresPass();

0 commit comments

Comments
 (0)