[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 <jperier@nvidia.com>

Original-commit: flang-compiler/f18@116f64315f
Reviewed-on: https://github.com/flang-compiler/f18/pull/1090
This commit is contained in:
Steve Scalpone 2020-03-27 09:23:32 -07:00 committed by GitHub
parent 643edd57fe
commit 282358fac9
4 changed files with 30 additions and 18 deletions

View File

@ -14,7 +14,7 @@ def clang(arch):
"ninja install", "ninja install",
"cd ../..", "cd ../..",
"mkdir build && cd build", "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", "ninja -j8",
"ctest --output-on-failure -j24", "ctest --output-on-failure -j24",
"ninja check-all", "ninja check-all",
@ -40,7 +40,7 @@ def gcc(arch):
"ninja install", "ninja install",
"cd ../..", "cd ../..",
"mkdir build && cd build", "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", "ninja -j8",
"ctest --output-on-failure -j24", "ctest --output-on-failure -j24",
"ninja check-all", "ninja check-all",

View File

@ -67,6 +67,10 @@ project(Flang)
if(LINK_WITH_FIR) if(LINK_WITH_FIR)
include(TableGen) 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) include(AddMLIR)
find_program(MLIR_TABLEGEN_EXE "mlir-tblgen" ${LLVM_TOOLS_BINARY_DIR} find_program(MLIR_TABLEGEN_EXE "mlir-tblgen" ${LLVM_TOOLS_BINARY_DIR}
NO_DEFAULT_PATH) NO_DEFAULT_PATH)

View File

@ -72,12 +72,16 @@ https://llvm.org/docs/GettingStarted.html.
We highly recommend using the same compiler to compile both llvm and f18. We highly recommend using the same compiler to compile both llvm and f18.
The f18 CMakeList.txt file uses 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, To get the correct LLVM and MLIR libraries included in your f18 build,
define LLVM_DIR on the cmake command line. 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 where `LLVM_BUILD_DIR` is
the top-level directory where LLVM was built. the top-level directory where LLVM was built.
@ -121,7 +125,11 @@ make install
``` ```
Then, `-DLLVM_DIR` would have to be set to 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, To run lit tests,
`-DLLVM_EXTERNAL_LIT=<where/you/want/to/build/llvm>/build/bin/llvm-lit` must be `-DLLVM_EXTERNAL_LIT=<where/you/want/to/build/llvm>/build/bin/llvm-lit` must be
@ -142,13 +150,13 @@ Or,
cmake will use the variable CXX to find the C++ compiler. cmake will use the variable CXX to find the C++ compiler.
CXX should include the full path to the compiler CXX should include the full path to the compiler
or a name that will be found on your PATH, 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 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 ### Building f18 with clang
@ -189,7 +197,7 @@ Release builds execute quickly.
### Build F18 ### Build F18
``` ```
cd ~/f18/build cd ~/f18/build
cmake -DLLVM_DIR=$LLVM ~/f18/src cmake -DLLVM_DIR=$LLVM -DMLIR_DIR=$MLIR ~/f18/src
make make
``` ```
@ -198,7 +206,7 @@ make
To run all tests: To run all tests:
``` ```
cd ~/f18/build cd ~/f18/build
cmake -DLLVM_DIR=$LLVM ~/f18/src cmake -DLLVM_DIR=$LLVM -DMLIR_DIR=$MLIR ~/f18/src
make test check-all make test check-all
``` ```

View File

@ -50,11 +50,11 @@ public:
inline void registerFIR() { inline void registerFIR() {
// we want to register exactly once // we want to register exactly once
[[maybe_unused]] static bool init_once = [] { [[maybe_unused]] static bool init_once = [] {
mlir::registerDialect<mlir::AffineOpsDialect>(); mlir::registerDialect<mlir::AffineDialect>();
mlir::registerDialect<mlir::LLVM::LLVMDialect>(); mlir::registerDialect<mlir::LLVM::LLVMDialect>();
mlir::registerDialect<mlir::loop::LoopOpsDialect>(); mlir::registerDialect<mlir::loop::LoopOpsDialect>();
mlir::registerDialect<mlir::StandardOpsDialect>(); mlir::registerDialect<mlir::StandardOpsDialect>();
mlir::registerDialect<mlir::vector::VectorOpsDialect>(); mlir::registerDialect<mlir::vector::VectorDialect>();
mlir::registerDialect<FIROpsDialect>(); mlir::registerDialect<FIROpsDialect>();
return true; return true;
}(); }();
@ -65,7 +65,7 @@ inline void registerFIR() {
inline void registerGeneralPasses() { inline void registerGeneralPasses() {
mlir::createCanonicalizerPass(); mlir::createCanonicalizerPass();
mlir::createCSEPass(); mlir::createCSEPass();
mlir::createVectorizePass({}); mlir::createSuperVectorizePass({});
mlir::createLoopUnrollPass(); mlir::createLoopUnrollPass();
mlir::createLoopUnrollAndJamPass(); mlir::createLoopUnrollAndJamPass();
mlir::createSimplifyAffineStructuresPass(); mlir::createSimplifyAffineStructuresPass();