From 282358fac9e6da68162d13966249ef3f17f2c10c Mon Sep 17 00:00:00 2001 From: Steve Scalpone Date: Fri, 27 Mar 2020 09:23:32 -0700 Subject: [PATCH] [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 Original-commit: flang-compiler/f18@116f64315f6218a7f74a8ccdc25f94d322ac6344 Reviewed-on: https://github.com/flang-compiler/f18/pull/1090 --- flang/.drone.star | 4 +-- flang/CMakeLists.txt | 4 +++ flang/README.md | 34 ++++++++++++------- .../flang/Optimizer/Dialect/FIRDialect.h | 6 ++-- 4 files changed, 30 insertions(+), 18 deletions(-) diff --git a/flang/.drone.star b/flang/.drone.star index 27ff72e911cf..b03169c5014a 100644 --- a/flang/.drone.star +++ b/flang/.drone.star @@ -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", @@ -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", diff --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt index 54c5d52c45f6..dceeeb16f25a 100644 --- a/flang/CMakeLists.txt +++ b/flang/CMakeLists.txt @@ -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) diff --git a/flang/README.md b/flang/README.md index 926abc0ecf5d..a64bab0cb912 100644 --- a/flang/README.md +++ b/flang/README.md @@ -1,9 +1,9 @@ - # F18 @@ -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=/lib/cmake/llvm cmake -DLLVM_DIR=$LLVM ... +LLVM=/lib/cmake/llvm \ +MLIR=/lib/cmake/mlir \ +cmake -DLLVM_DIR=$LLVM -DMLIR_DIR=$MLIR ... ``` where `LLVM_BUILD_DIR` is the top-level directory where LLVM was built. @@ -121,7 +125,11 @@ make install ``` Then, `-DLLVM_DIR` would have to be set to - `/install/lib/cmake/llvm` in f18 cmake command. + `/install/lib/cmake/llvm` +and, `-DMLIR_DIR` would have to be set to + `/install/lib/cmake/mlir` + +in f18 cmake command. To run lit tests, `-DLLVM_EXTERNAL_LIT=/build/bin/llvm-lit` must be @@ -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 @@ -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 ``` @@ -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 ``` diff --git a/flang/include/flang/Optimizer/Dialect/FIRDialect.h b/flang/include/flang/Optimizer/Dialect/FIRDialect.h index 4818a7100b9c..7a8fc18937fc 100644 --- a/flang/include/flang/Optimizer/Dialect/FIRDialect.h +++ b/flang/include/flang/Optimizer/Dialect/FIRDialect.h @@ -50,11 +50,11 @@ public: inline void registerFIR() { // we want to register exactly once [[maybe_unused]] static bool init_once = [] { - mlir::registerDialect(); + mlir::registerDialect(); mlir::registerDialect(); mlir::registerDialect(); mlir::registerDialect(); - mlir::registerDialect(); + mlir::registerDialect(); mlir::registerDialect(); return true; }(); @@ -65,7 +65,7 @@ inline void registerFIR() { inline void registerGeneralPasses() { mlir::createCanonicalizerPass(); mlir::createCSEPass(); - mlir::createVectorizePass({}); + mlir::createSuperVectorizePass({}); mlir::createLoopUnrollPass(); mlir::createLoopUnrollAndJamPass(); mlir::createSimplifyAffineStructuresPass();