diff --git a/.github/workflows/build_and_test_cmake.yml b/.github/workflows/build_and_test_cmake.yml index a257c48..78d51db 100644 --- a/.github/workflows/build_and_test_cmake.yml +++ b/.github/workflows/build_and_test_cmake.yml @@ -29,6 +29,14 @@ jobs: ./externals/llvm-project key: ${{ runner.os }}-cmake-${{ hashFiles('bazel/import_llvm.bzl') }}-${{ hashFiles('**/CMakeLists.txt') }} + - name: Cache mlir-tutorial build + id: cache-mlir-tutorial + uses: actions/cache@v3 + with: + path: | + ./build + key: ${{ runner.os }}-cmake-${{ hashFiles('bazel/import_llvm.bzl') }}-${{ hashFiles('**/CMakeLists.txt') }} + - name: Git config run: | git config --global --add safe.directory ${GITHUB_WORKSPACE} @@ -47,9 +55,10 @@ jobs: - name: Build and test mlir-tutorial run: | mkdir build && cd build - cmake -DLLVM_DIR=${GITHUB_WORKSPACE}/externals/llvm-project/build/lib/cmake/llvm -DMLIR_DIR=${GITHUB_WORKSPACE}/externals/llvm-project/build/lib/cmake/mlir .. + cmake -DLLVM_DIR=${GITHUB_WORKSPACE}/externals/llvm-project/build/lib/cmake/llvm -DMLIR_DIR=${GITHUB_WORKSPACE}/externals/llvm-project/build/lib/cmake/mlir -DBUILD_DEPS="ON" .. cmake --build . --target MLIRAffineFullUnrollPasses cmake --build . --target MLIRMulToAddPasses + cmake --build . --target MLIRNoisyPasses cmake --build . --target mlir-headers cmake --build . --target tutorial-opt cmake --build . --target check-mlir-tutorial diff --git a/.gitignore b/.gitignore index 36802d6..258a6a8 100644 --- a/.gitignore +++ b/.gitignore @@ -4,9 +4,6 @@ bazel-mlir-tutorial bazel-out bazel-testlogs -# git submodule -externals - # cmake related files # ignore the user specified CMake presets in subproject directories. /*/CMakeUserPresets.json diff --git a/CMakeLists.txt b/CMakeLists.txt index 56aab9f..46b2d9b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,16 @@ include_directories(${PROJECT_SOURCE_DIR}) include_directories(${PROJECT_SOURCE_DIR}/externals/llvm-project) include_directories(${PROJECT_BINARY_DIR}) +message(STATUS "Fetching or-tools...") +include(FetchContent) +FetchContent_Declare( + or-tools + GIT_REPOSITORY https://github.com/google/or-tools.git + GIT_TAG main +) +FetchContent_MakeAvailable(or-tools) +message(STATUS "Done fetching or-tools") + add_subdirectory(tests) add_subdirectory(tools) -add_subdirectory(lib) \ No newline at end of file +add_subdirectory(lib) diff --git a/README.md b/README.md index a894731..bd82a31 100644 --- a/README.md +++ b/README.md @@ -1,33 +1,32 @@ # MLIR For Beginners -This is the code repository for a series of articles -on the [MLIR framework](https://mlir.llvm.org/) for building compilers. +This is the code repository for a series of articles on the +[MLIR framework](https://mlir.llvm.org/) for building compilers. ## Articles -1. [Build System (Getting Started)](https://jeremykun.com/2023/08/10/mlir-getting-started/) -2. [Running and Testing a Lowering](https://jeremykun.com/2023/08/10/mlir-running-and-testing-a-lowering/) -3. [Writing Our First Pass](https://jeremykun.com/2023/08/10/mlir-writing-our-first-pass/) -4. [Using Tablegen for Passes](https://jeremykun.com/2023/08/10/mlir-using-tablegen-for-passes/) -5. [Defining a New Dialect](https://jeremykun.com/2023/08/21/mlir-defining-a-new-dialect/) -6. [Using Traits](https://jeremykun.com/2023/09/07/mlir-using-traits/) -7. [Folders and Constant Propagation](https://jeremykun.com/2023/09/11/mlir-folders/) -8. [Verifiers](https://jeremykun.com/2023/09/13/mlir-verifiers/) -9. [Canonicalizers and Declarative Rewrite Patterns](https://jeremykun.com/2023/09/20/mlir-canonicalizers-and-declarative-rewrite-patterns/) +1. [Build System (Getting Started)](https://jeremykun.com/2023/08/10/mlir-getting-started/) +2. [Running and Testing a Lowering](https://jeremykun.com/2023/08/10/mlir-running-and-testing-a-lowering/) +3. [Writing Our First Pass](https://jeremykun.com/2023/08/10/mlir-writing-our-first-pass/) +4. [Using Tablegen for Passes](https://jeremykun.com/2023/08/10/mlir-using-tablegen-for-passes/) +5. [Defining a New Dialect](https://jeremykun.com/2023/08/21/mlir-defining-a-new-dialect/) +6. [Using Traits](https://jeremykun.com/2023/09/07/mlir-using-traits/) +7. [Folders and Constant Propagation](https://jeremykun.com/2023/09/11/mlir-folders/) +8. [Verifiers](https://jeremykun.com/2023/09/13/mlir-verifiers/) +9. [Canonicalizers and Declarative Rewrite Patterns](https://jeremykun.com/2023/09/20/mlir-canonicalizers-and-declarative-rewrite-patterns/) 10. [Dialect Conversion](https://jeremykun.com/2023/10/23/mlir-dialect-conversion/) 11. [Lowering through LLVM](https://jeremykun.com/2023/11/01/mlir-lowering-through-llvm/) - ## Bazel build Bazel is one of two supported build systems for this tutorial. The other is CMake. If you're unfamiliar with Bazel, you can read the tutorials at [https://bazel.build/start](https://bazel.build/start). Familiarity with Bazel is not required to build or test, but it is required to follow the articles in -the tutorial series and explained in the first article, [Build System (Getting -Started)](https://jeremykun.com/2023/08/10/mlir-getting-started/). The CMake -build is maintained, but was added at article 10 (Dialect Conversion) and will -not be explained in the articles. +the tutorial series and explained in the first article, +[Build System (Getting Started)](https://jeremykun.com/2023/08/10/mlir-getting-started/). +The CMake build is maintained, but was added at article 10 (Dialect Conversion) +and will not be explained in the articles. ### Prerequisites @@ -51,16 +50,16 @@ bazel test ...:all CMake is one of two supported build systems for this tutorial. The other is Bazel. If you're unfamiliar with CMake, you can read the tutorials at -[https://cmake.org/getting-started/](https://cmake.org/getting-started/). -The CMake build is maintained, but was added at article 10 (Dialect Conversion) -and will not be explained in the articles. +[https://cmake.org/getting-started/](https://cmake.org/getting-started/). The +CMake build is maintained, but was added at article 10 (Dialect Conversion) and +will not be explained in the articles. ### Prerequisites -* Make sure you have installed everything needed to build LLVM -https://llvm.org/docs/GettingStarted.html#software -* For this recipe Ninja is used so be sure to have it as well installed -https://github.com/ninja-build/ninja/wiki/Pre-built-Ninja-packages +* Make sure you have installed everything needed to build LLVM + https://llvm.org/docs/GettingStarted.html#software +* For this recipe Ninja is used so be sure to have it as well installed + https://github.com/ninja-build/ninja/wiki/Pre-built-Ninja-packages ### Checking out the code @@ -128,15 +127,18 @@ mkdir $BUILD_DIR pushd $BUILD_DIR LLVM_BUILD_DIR=externals/llvm-project/build +ORTOOLS_BUILD_DIR=externals/llvm-project/build cmake -G $BUILD_SYSTEM .. \ -DLLVM_DIR="$LLVM_BUILD_DIR/lib/cmake/llvm" \ -DMLIR_DIR="$LLVM_BUILD_DIR/lib/cmake/mlir" \ + -DBUILD_DEPS="ON" \ -DCMAKE_BUILD_TYPE=Debug popd cmake --build $BUILD_DIR --target MLIRAffineFullUnrollPasses cmake --build $BUILD_DIR --target MLIRMulToAddPasses +cmake --build $BUILD_DIR --target MLIRNoisyPasses cmake --build $BUILD_DIR --target mlir-headers cmake --build $BUILD_DIR --target mlir-doc cmake --build $BUILD_DIR --target tutorial-opt diff --git a/externals/llvm-project b/externals/llvm-project index 896749a..f778eaf 160000 --- a/externals/llvm-project +++ b/externals/llvm-project @@ -1 +1 @@ -Subproject commit 896749aa0d420ae573255a64a349bc2a76cfed37 +Subproject commit f778eafdd878e8b11ad76f9e0a312ce7791a7481 diff --git a/lib/Analysis/CMakeLists.txt b/lib/Analysis/CMakeLists.txt new file mode 100644 index 0000000..a52d48b --- /dev/null +++ b/lib/Analysis/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(ReduceNoiseAnalysis) diff --git a/lib/Analysis/ReduceNoiseAnalysis/CMakeLists.txt b/lib/Analysis/ReduceNoiseAnalysis/CMakeLists.txt new file mode 100644 index 0000000..99cb75f --- /dev/null +++ b/lib/Analysis/ReduceNoiseAnalysis/CMakeLists.txt @@ -0,0 +1,7 @@ +add_mlir_library(ReduceNoiseAnalysis + ReduceNoiseAnalysis.cpp + + ${PROJECT_SOURCE_DIR}/lib/Analysis/ReduceNoiseAnalysis/ + ADDITIONAL_HEADER_DIRS + LINK_LIBS PUBLIC +) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 714031d..c1572fe 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -1,3 +1,4 @@ -add_subdirectory(Dialect) +add_subdirectory(Analysis) add_subdirectory(Conversion) +add_subdirectory(Dialect) add_subdirectory(Transform) diff --git a/lib/Dialect/CMakeLists.txt b/lib/Dialect/CMakeLists.txt index aff4d19..1f27a0f 100644 --- a/lib/Dialect/CMakeLists.txt +++ b/lib/Dialect/CMakeLists.txt @@ -1 +1,2 @@ -add_subdirectory(Poly) \ No newline at end of file +add_subdirectory(Noisy) +add_subdirectory(Poly) diff --git a/lib/Dialect/Noisy/CMakeLists.txt b/lib/Dialect/Noisy/CMakeLists.txt index 5e38757..41fe14e 100644 --- a/lib/Dialect/Noisy/CMakeLists.txt +++ b/lib/Dialect/Noisy/CMakeLists.txt @@ -12,10 +12,6 @@ add_dependencies(mlir-headers MLIRNoisyOpsIncGen) add_mlir_doc(NoisyDialect NoisyDialect Noisy/ -gen-dialect-doc) -set(LLVM_TARGET_DEFINITIONS NoisyPatterns.td) -mlir_tablegen(NoisyCanonicalize.cpp.inc -gen-rewriters) -add_public_tablegen_target(MLIRNoisyCanonicalizationIncGen) - add_mlir_dialect_library(MLIRNoisy NoisyDialect.cpp NoisyOps.cpp diff --git a/lib/Transform/CMakeLists.txt b/lib/Transform/CMakeLists.txt index 9caa085..5534bc3 100644 --- a/lib/Transform/CMakeLists.txt +++ b/lib/Transform/CMakeLists.txt @@ -1,2 +1,3 @@ add_subdirectory(Affine) -add_subdirectory(Arith) \ No newline at end of file +add_subdirectory(Arith) +add_subdirectory(Noisy) diff --git a/lib/Transform/Noisy/CMakeLists.txt b/lib/Transform/Noisy/CMakeLists.txt new file mode 100644 index 0000000..df76aa6 --- /dev/null +++ b/lib/Transform/Noisy/CMakeLists.txt @@ -0,0 +1,14 @@ +add_mlir_library(NoisyPasses + ReduceNoiseOptimizer.cpp + + ${PROJECT_SOURCE_DIR}/lib/Transform/Noisy/ + ADDITIONAL_HEADER_DIRS + + LINK_LIBS PUBLIC + ReduceNoiseAnalysis +) + +set(LLVM_TARGET_DEFINITIONS Passes.td) +mlir_tablegen(Passes.h.inc -gen-pass-decls -name Noisy) +add_public_tablegen_target(MLIRNoisyPasses) +add_mlir_doc(Passes NoisyPasses ./ -gen-pass-doc) diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 59f33b1..8cd5559 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -4,12 +4,15 @@ get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS) set (LIBS ${dialect_libs} ${conversion_libs} - MLIRPoly AffineFullUnroll - MulToAdd + MLIRNoisy MLIROptLib MLIRPass + MLIRPoly + MulToAdd + NoisyPasses PolyToStandard + ortools::ortools ) add_llvm_executable(tutorial-opt tutorial-opt.cpp)