Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

MLIR For Beginners tutorial

NotificationsYou must be signed in to change notification settings

j2kun/mlir-tutorial

Repository files navigation

This is the code repository for a series of articles on theMLIR framework for building compilers.

Articles

  1. Build System (Getting Started)
  2. Running and Testing a Lowering
  3. Writing Our First Pass
  4. Using Tablegen for Passes
  5. Defining a New Dialect
  6. Using Traits
  7. Folders and Constant Propagation
  8. Verifiers
  9. Canonicalizers and Declarative Rewrite Patterns
  10. Dialect Conversion
  11. Lowering through LLVM
  12. A Global Optimization and Dataflow Analysis
  13. Defining Patterns with PDLL

Bazel build

Bazel is one of two supported build systems for this tutorial. The other isCMake. If you're unfamiliar with Bazel, you can read the tutorials athttps://bazel.build/start. Familiarity with Bazelis not required to build or test, but it is required to follow the articles inthe tutorial series and explained in the first article,Build System (Getting Started).The CMake build is maintained, but was added at article 10 (Dialect Conversion)and will not be explained in the articles.

Note: This project has been upgraded to Bazel 8.3.1 and migrated to useBzlmod for dependency management, replacing the traditional WORKSPACE fileapproach. Dependencies are now managed throughMODULE.bazel using theBazel Central Registry (BCR) where possible.

Prerequisites

Install Bazelisk via instructions athttps://github.com/bazelbuild/bazelisk#installation.This should create thebazel command on your system.

You should also have a modern C++ compiler on your system, eithergcc orclang, which Bazel will detect.

Bazel Version: This project requires Bazel 8.3.1 or newer. The specificversion is pinned in.bazelversion.

Build and test

Run

bazel build ...:allbazeltest ...:all

Dependency Management

The project uses Bzlmod (MODULE.bazel) for dependency management:

  • Core dependencies: Managed through Bazel Central Registry (BCR)
    • rules_python, rules_java, protobuf, abseil-cpp, or-tools, etc.
  • LLVM dependencies: Managed through custom module extension
    • LLVM/MLIR source code via git repository
  • Development tools: hedron_compile_commands via git_override

This approach provides better dependency resolution, versioning, andcompatibility compared to the legacy WORKSPACE approach.

CMake build

CMake is one of two supported build systems for this tutorial. The other isBazel. If you're unfamiliar with CMake, you can read the tutorials athttps://cmake.org/getting-started/. TheCMake build is maintained, but was added at article 10 (Dialect Conversion) andwill not be explained in the articles.

Prerequisites

Checking out the code

Checkout the tutorial including the LLVM dependency (submodules):

git clone --recurse-submodules https://github.com/j2kun/mlir-tutorial.gitcd mlir-tutorial

Building dependencies

Note: The following steps are suitable for macOs and use ninja as buildingsystem, they should not be hard to adapt for your environment.

Build LLVM/MLIR

#!/bin/shBUILD_SYSTEM=NinjaBUILD_TAG=ninjaTHIRDPARTY_LLVM_DIR=$PWD/externals/llvm-projectBUILD_DIR=$THIRDPARTY_LLVM_DIR/buildINSTALL_DIR=$THIRDPARTY_LLVM_DIR/installmkdir -p$BUILD_DIRmkdir -p$INSTALL_DIRpushd$BUILD_DIRcmake ../llvm -G$BUILD_SYSTEM \      -DCMAKE_CXX_COMPILER="$(xcrun --find clang++)" \      -DCMAKE_C_COMPILER="$(xcrun --find clang)" \      -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR \      -DLLVM_LOCAL_RPATH=$INSTALL_DIR/lib \      -DLLVM_PARALLEL_COMPILE_JOBS=7 \      -DLLVM_PARALLEL_LINK_JOBS=1 \      -DLLVM_BUILD_EXAMPLES=OFF \      -DLLVM_INSTALL_UTILS=ON \      -DCMAKE_OSX_ARCHITECTURES="$(uname -m)" \      -DCMAKE_BUILD_TYPE=Release \      -DLLVM_ENABLE_ASSERTIONS=ON \      -DLLVM_CCACHE_BUILD=ON \      -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \      -DLLVM_ENABLE_PROJECTS='mlir' \      -DDEFAULT_SYSROOT="$(xcrun --show-sdk-path)" \      -DCMAKE_OSX_SYSROOT="$(xcrun --show-sdk-path)"cmake --build. --target check-mlirpopd

Build and test

#!/bin/shBUILD_SYSTEM="Ninja"BUILD_DIR=./build-`echo${BUILD_SYSTEM}| tr'[:upper:]''[:lower:]'`rm -rf$BUILD_DIRmkdir$BUILD_DIRpushd$BUILD_DIRLLVM_BUILD_DIR=externals/llvm-project/buildcmake -G$BUILD_SYSTEM .. \    -DLLVM_DIR="$LLVM_BUILD_DIR/lib/cmake/llvm" \    -DMLIR_DIR="$LLVM_BUILD_DIR/lib/cmake/mlir" \    -DBUILD_DEPS="ON" \    -DBUILD_SHARED_LIBS="OFF" \    -DCMAKE_BUILD_TYPE=Debugpopdcmake --build$BUILD_DIR --target MLIRAffineFullUnrollPassescmake --build$BUILD_DIR --target MLIRMulToAddPassescmake --build$BUILD_DIR --target MLIRNoisyPassescmake --build$BUILD_DIR --target mlir-headerscmake --build$BUILD_DIR --target mlir-doccmake --build$BUILD_DIR --target tutorial-optcmake --build$BUILD_DIR --target check-mlir-tutorial

About

MLIR For Beginners tutorial

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors7


[8]ページ先頭

©2009-2025 Movatter.jp