Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link against CIRCT and use it for codegen #234

Merged
merged 52 commits into from
Jan 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
bd1e194
mlir: Add a basic circt-sys crate
fabianschuiki Jul 22, 2021
7621f92
mlir: Add higher-level circt crate
fabianschuiki Aug 18, 2021
a80e56e
mlir: Add LLHD and standard dialect, restructure
fabianschuiki Sep 2, 2021
caca0d1
mlir: Add first codegen support
fabianschuiki Sep 2, 2021
8765141
mlir: Move circt crates into src directory
fabianschuiki Nov 13, 2021
65d8b0a
mlir: Add CIRCT submodule and build script
fabianschuiki Nov 14, 2021
a84e8c8
mlir: Compile order fixes
fabianschuiki Nov 15, 2021
f2633e5
mlir: Implement operation printing to a `Write`
fabianschuiki Nov 15, 2021
c0d27ec
mlir: Add LLVM lit-based tests
fabianschuiki Nov 15, 2021
1ff86d4
mlir: Add helper to go from MlirStringRef to &str
fabianschuiki Nov 15, 2021
bbe43a8
mlir: Move ModuleOp into a new `builtin` module
fabianschuiki Nov 15, 2021
ca620d5
mlir: Add support for debug info and location translation
fabianschuiki Nov 15, 2021
983e027
mlir: Add MLIR type emission
fabianschuiki Nov 15, 2021
ee28b3c
mlir: Add LLHD dialect type support
fabianschuiki Nov 15, 2021
639e56d
mlir: Emit proper entity type signatures
fabianschuiki Nov 15, 2021
dda21c6
mlir: First expression emissions
fabianschuiki Nov 15, 2021
f509127
mlir: Add first declaration support
fabianschuiki Nov 15, 2021
bc806e6
mlir: Add port default value driving
fabianschuiki Nov 15, 2021
ff32e20
mlir: Basic process emission
fabianschuiki Nov 16, 2021
864a88f
mlir: Add process prolog/epilog
fabianschuiki Nov 16, 2021
32bb626
mlir: Impl rvalue codegen
fabianschuiki Nov 17, 2021
e93cf19
mlir: Update CI to include CIRCT/LLVM and lit tests
fabianschuiki Nov 17, 2021
0390669
mlir: Add missing struct/array const emission
fabianschuiki Nov 18, 2021
da9ffec
mlir: Get new codegen to not crash for all tests
fabianschuiki Nov 18, 2021
730af9d
mlir: Stop using llhd.not and llhd.neg ops
fabianschuiki Nov 18, 2021
4385ed6
mlir: Add module and process instantiation
fabianschuiki Nov 18, 2021
c4c62c8
mlir: Impl if stmt codegen
fabianschuiki Nov 20, 2021
ec8c5cd
mlir: Impl loop codegen
fabianschuiki Nov 21, 2021
cda34a0
mlir: Impl procedural assignment codegen
fabianschuiki Nov 21, 2021
15d2982
mlir: Impl timed wait codegen
fabianschuiki Nov 21, 2021
abd95a5
mlir: Impl implicit event codegen
fabianschuiki Nov 21, 2021
71c0c76
mlir: Wait emission cleanup
fabianschuiki Nov 21, 2021
87b41e1
mlir: Impl case stmt codegen
fabianschuiki Nov 21, 2021
a0a3f8e
mlir: Impl explicit event trigger codegen
fabianschuiki Nov 21, 2021
825aaf6
mlir: Rearrange test cases
fabianschuiki Nov 21, 2021
7c99782
mlir: Remove obsolete codegen functions
fabianschuiki Nov 21, 2021
4b53323
mlir: Update circt submodule
fabianschuiki Nov 24, 2021
68651cb
mlir: Update README with CIRCT/LLVM/MLIR instructions
fabianschuiki Nov 24, 2021
5a35b81
mlir: Point CI build to install directories instead of build
fabianschuiki Nov 24, 2021
57f9f32
mlir: Drop xml2 from CIRCT system library list
fabianschuiki Nov 24, 2021
7d32f19
mlir: Report MLIR diagnostics through Moore's diagnostic engine
fabianschuiki Nov 24, 2021
eb13fdb
mlir: Remove unused ops, fix cond_br, fix typos
fabianschuiki Nov 24, 2021
591acfa
mlir: Pick a dummy name for process instances
fabianschuiki Nov 24, 2021
33a5b1f
mlir: Revert CI back to using build dir, don't install
fabianschuiki Nov 25, 2021
540e431
mlir: Fix ICmpOp return type and ExtractOp attr type
fabianschuiki Nov 25, 2021
bab3cf7
mlir: Uniquify signal and instance names
fabianschuiki Nov 25, 2021
09cf0e0
mlir: Improve MLIR location tracking
fabianschuiki Nov 25, 2021
874a108
mlir: Improve circt-sys rebuild on CIRCT recompilation
fabianschuiki Nov 25, 2021
1a88094
mlir: Properly truncate indices/offsets to clog2 of array/integer size
fabianschuiki Nov 25, 2021
1730612
mlir: Fix minor emission issues
fabianschuiki Nov 25, 2021
5416d84
mlir: Speed up location translations
fabianschuiki Jan 15, 2022
de5abbb
rustfmt: Fix vhdl/score/lower_hir.rs
fabianschuiki Jan 16, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/build-circt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
set -e

mkdir -p circt/build
cd circt/build
cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DMLIR_DIR=$PWD/../llvm/build/lib/cmake/mlir \
-DLLVM_DIR=$PWD/../llvm/build/lib/cmake/llvm \
fabianschuiki marked this conversation as resolved.
Show resolved Hide resolved
-DLLVM_ENABLE_ASSERTIONS=ON

cmake --build . -- -j$(nproc)
17 changes: 17 additions & 0 deletions .github/build-llvm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
set -e

mkdir -p circt/llvm/build
cd circt/llvm/build
cmake ../llvm \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_BUILD_EXAMPLES=OFF \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DLLVM_ENABLE_BINDINGS=OFF \
-DLLVM_ENABLE_OCAMLDOC=OFF \
-DLLVM_ENABLE_PROJECTS=mlir \
-DLLVM_INSTALL_UTILS=ON \
-DLLVM_OPTIMIZED_TABLEGEN=ON \
-DLLVM_TARGETS_TO_BUILD=""

cmake --build . -- -j$(nproc)
124 changes: 88 additions & 36 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,67 +3,119 @@ on: [push, pull_request]
name: CI

jobs:
check:
name: Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
name: "source checkout"
- uses: actions-rs/toolchain@v1
name: "toolchain installation"
with:
profile: minimal
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
name: "cargo check"
with:
command: check

lints:
name: Lints
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
name: "source checkout"
- uses: actions-rs/toolchain@v1
name: "toolchain installation"
- name: Checkout sources
uses: actions/checkout@v2

- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
components: rustfmt, clippy

- uses: actions-rs/cargo@v1
name: "cargo fmt"
- name: Run rustfmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check

- uses: actions-rs/cargo@v1
name: "cargo clippy"
continue-on-error: true # TODO: Remove once we have fixed the mall
- name: Run clippy
uses: actions-rs/cargo@v1
continue-on-error: true # TODO: Remove once we have fixed them all
with:
command: clippy

test:
name: Tests
check:
name: Checks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
name: "source checkout"
- name: Checkout sources
uses: actions/checkout@v2
with:
submodules: recursive
- uses: actions-rs/toolchain@v1
name: "toolchain installation"

- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
name: "cargo test"
components: rustfmt, clippy

- name: Configure Environment
id: env
run: |
echo "CIRCT_SYS_CIRCT_DIR=$GITHUB_WORKSPACE/circt" >> $GITHUB_ENV
echo "::set-output name=circt-hash::$(git rev-parse @:./circt)"
echo "::set-output name=llvm-hash::$(cd circt && git rev-parse @:./llvm)"

# Fetch LLVM from the cache if possible, otherwise rebuild it.
- name: Fetch LLVM from cache
id: cache-llvm
uses: martijnhols/actions-cache/restore@v3
with:
path: circt/llvm/build
fabianschuiki marked this conversation as resolved.
Show resolved Hide resolved
key: ${{ runner.os }}-llvm-${{ hashFiles('.github/build-llvm.sh') }}-${{ steps.env.outputs.llvm-hash }}

- name: Rebuild LLVM
if: steps.cache-llvm.outputs.cache-hit != 'true'
run: .github/build-llvm.sh

- name: Upload LLVM to cache
if: steps.cache-llvm.outputs.cache-hit != 'true'
uses: martijnhols/actions-cache/save@v3
with:
path: circt/llvm/build
key: ${{ steps.cache-llvm.outputs.primary-key }}

# Fetch CIRCT from the cache if possible, otherwise rebuild it.
- name: Fetch CIRCT from cache
id: cache-circt
uses: martijnhols/actions-cache/restore@v3
with:
path: circt/build
key: ${{ runner.os }}-circt-${{ hashFiles('.github/build-circt.sh') }}-${{ steps.env.outputs.circt-hash }}

- name: Rebuild CIRCT
if: steps.cache-circt.outputs.cache-hit != 'true'
run: .github/build-circt.sh

- name: Upload CIRCT to cache
if: steps.cache-circt.outputs.cache-hit != 'true'
uses: martijnhols/actions-cache/save@v3
with:
path: circt/build
key: ${{ steps.cache-circt.outputs.primary-key }}

# Run the quick check build.
- name: Run "cargo check"
uses: actions-rs/cargo@v1
with:
command: check
args: --all

# Run the regular build.
- name: Run "cargo build"
uses: actions-rs/cargo@v1
with:
command: build

# Run the unit tests.
- name: Run "cargo test"
uses: actions-rs/cargo@v1
with:
command: test
args: --all
- run: python3 scripts/test.py --debug --verbose
name: "regression tests"

# Run the tests.
- name: Run lit tests
run: circt/llvm/build/bin/llvm-lit test -v
- name: Run regression tests (old)
run: env TERM=xterm-color test/run.sh
- name: Run regression tests (new)
run: python3 scripts/test.py --debug --verbose
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "test/third-party/common_cells"]
path = test/third-party/common_cells
url = https://github.com/pulp-platform/common_cells.git
[submodule "circt"]
path = circt
url = https://github.com/fabianschuiki/circt.git
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ moore-common = { path = "src/common", version = "0.13.2" }
moore-derive = { path = "src/derive", version = "0.13.2" }
moore-svlog = { path = "src/svlog", version = "0.13.2" }
moore-vhdl = { path = "src/vhdl", version = "0.13.2" }
circt = { path = "src/circt" }
clap = "2"
llhd = "0.16"
# llhd = { git = "https://github.com/fabianschuiki/llhd" }
Expand Down
54 changes: 53 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,62 @@ Moore is a compiler for hardware description languages that outputs [llhd] assem

### Installation

You need a working [Rust installation](https://rustup.rs/). Use cargo to install moore:
You need a working [Rust installation](https://rustup.rs/) to build Moore. The project also depends on the [CIRCT project](https://github.com/llvm/circt) and transitively on MLIR and LLVM. To get a working binary, you generally want to ensure you have the `circt` and `circt/llvm` submodules checked out:

git submodule update --init --recursive

And then follow these steps:

#### Build LLVM and MLIR

mkdir -p circt/llvm/build
pushd circt/llvm/build
cmake ../llvm \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=../install \
-DLLVM_BUILD_EXAMPLES=OFF \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DLLVM_ENABLE_BINDINGS=OFF \
-DLLVM_ENABLE_OCAMLDOC=OFF \
-DLLVM_ENABLE_PROJECTS=mlir \
-DLLVM_INSTALL_UTILS=ON \
-DLLVM_OPTIMIZED_TABLEGEN=ON \
-DLLVM_TARGETS_TO_BUILD=""
cmake --build . --target install
popd

#### Build CIRCT

mkdir -p circt/build
pushd circt/build
cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=../install \
-DMLIR_DIR=$PWD/../llvm/install/lib/cmake/mlir \
-DLLVM_DIR=$PWD/../llvm/install/lib/cmake/llvm \
-DLLVM_ENABLE_ASSERTIONS=ON
cmake --build . --target install
popd

#### Build Moore

Set the following environment variables to indicate where your LLVM and CIRCT build is:

export CIRCT_SYS_CIRCT_DIR=$PWD/circt
export CIRCT_SYS_CIRCT_BUILD_DIR=$PWD/circt/install
export CIRCT_SYS_LLVM_DIR=$PWD/circt/llvm
export CIRCT_SYS_LLVM_BUILD_DIR=$PWD/circt/llvm/install

Use cargo to install Moore:

cargo install moore

#### Development

For active development, you'll want to use the usual `check`, `build`, `run`, and `test` subcommands.

You may also find it useful to point the `*_BUILD_DIR` environment variables at the actual build directories (usually `circt/llvm/build` and `circt/build`), such that you don't need to re-install on every change to CIRCT or LLVM.

### Example

Assume the following input file:
Expand Down
1 change: 1 addition & 0 deletions circt
Submodule circt added at ba755a
3 changes: 2 additions & 1 deletion scripts/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@ def finish(self):
else:
suffices = ["sv", "v", "vhd"]
third_party = test_dir/"third-party"
globs = [[p for p in test_dir.glob("**/*."+suffix) if third_party not in p.parents] for suffix in suffices]
mlir = test_dir/"mlir"
globs = [[p for p in test_dir.glob("**/*."+suffix) if third_party not in p.parents and mlir not in p.parents] for suffix in suffices]
tests = [TestCase(p.relative_to(test_dir), p) for p in sorted(itertools.chain(*globs))]
sys.stdout.write("running {} tests\n".format(len(tests)))

Expand Down
Loading