Package: xdsl
xDSL: A Python-native SSA Compiler FrameworkxDSLis a Python-native compiler framework built around
SSA-based intermediate representations (IRs). Users of xDSL build a compiler by
assembling predefined domain-specific IRs and, optionally, defining their own custom IRs. xDSL uses multi-level IRs, meaning
that during the compilation process, a program will be lowered through several
of these IRs. This allows the implementation of abstraction-specific
optimization passes, similar to the structure of common DSL compilers (such as
Devito, Psyclone, and Firedrake). To simplify the writing of these passes, xDSL
uses a uniform data structure based on SSA, basic blocks, and regions, which
additionally enables the writing of generic passes.The design of xDSL is influenced byMLIR, a compiler
framework developed in C++, that is part of the LLVM project. An inherent
advantage of a close design is the easy interaction between the two frameworks,
making it possible to translate abstractions and programs back and forth. This
results in one big SSA-based abstraction ecosystem that can be worked with
through Python, making analysis through simple scripting languages possible.
Additionally, xDSL can leverage MLIR's code generation and low-level
optimization capabilities.InstallationGetting StartedxDSL Developer SetupDeveloper InstallationTestingFormattingInstallationTo use xDSL as part of a larger project for developing your own compiler,
just installxDSL via pip:pipinstallxdslNote:This version of xDSL is validated against a specific MLIR version,
interoperability with other versions may result in problems. The supported
MLIR version is commit98e674c9f16d677d95c67bc130e267fae331e43c.Getting StartedTo get familiar with xDSL, we recommend starting with our Jupyter notebooks. The
notebooks consist of examples and documentation concerning the core xDSL data
structures and the xDSL's Python-embedded abstraction definition language, as
well as examples of implementing custom compilers, like a database compiler.
There also exists a small documentation showing how to connect xDSL with MLIR
for users interested in that use case.A Database exampleA simple introductionA DSL for defining new IRsConnecting xDSL with MLIRWe provide a Makefile containing a lot of common tasks, which might provide
an overview of common actions.xDSL Developer SetupTo contribute to the development of xDSL follow the subsequent steps.Developer Installationgitclonehttps://github.com/xdslproject/xdsl.gitcdxdsl# set up the venv and install everythingmakevenv# activate the venvsourcevenv/bin/activateTestingThe xDSL project uses pytest unit tests and LLVM-style filecheck tests. They can
be executed from the root directory:# Executes pytests which are located in tests/pytest# Executes filecheck testslittests/filecheck# run all tests using makefilemaketestsFormatting and TypecheckingAll python code used in xDSL usesblackto
format the code in a uniform manner.To automate the formatting, we use pre-commit hooks from thepre-commitpackage.# Install the pre-commit on your `.git` foldermakeprecommit-install# to run the hooks:makeprecommit# alternatively, running black on all staged files:makeblack# or simply black $(git diff --staged --name-only)Furthermore, all python code must run throughpyrightwithout errors. Pyright can be run on all staged files through the
makefile usingmake pyright.DiscussionYou can also join the discussion at ourZulip chat room, kindly supported by community hosting fromZulip.