Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add getting started docs on running heir-opt manually
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 590339874
j2kun authored and copybara-github committed Dec 12, 2023
1 parent cfd9009 commit 664874e
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions docs/content/en/docs/getting_started.md
Original file line number Diff line number Diff line change
@@ -20,7 +20,9 @@ git clone git@github.com:google/heir.git && cd heir
bazel build @heir//tools:heir-opt
```

Some passes in this repository require Yosys as a dependency (`--yosys-optimizer`). If you would like to skip Yosys and ABC compilation to speed up builds, use the following build setting:
Some passes in this repository require Yosys as a dependency
(`--yosys-optimizer`). If you would like to skip Yosys and ABC compilation to
speed up builds, use the following build setting:

```bash
bazel build --define=HEIR_NO_YOSYS=1 @heir//tools:heir-opt
@@ -39,6 +41,29 @@ Like above, run the following to skip tests that depend on Yosys:
bazel test --define=HEIR_NO_YOSYS=1 --test_tag_filters=-yosys @heir//...
```

## Optional: Run heir-opt on an mlir file

HEIR comes with two central binaries, `heir-opt` for running optimization passes
and dialect conversions, and `heir-translate` for backend code generation. To
see the list of available passes in each one, run the binary with `--help`:

```bash
bazel run //tools:heir-opt -- --help
bazel run //tools:heir-translate -- --help
```

Once you've chosen a pass or `--pass-pipeline` to run, execute it on the desired
file. For example, you can run a test file through `heir-opt` to see its output.
Note that when the binary is run via `bazel`, you must pass absolute paths to
input files. You can also access the underlying binary at
`bazel-bin/tools/heir-opt`, provided it has already been built.

```bash
bazel run //tools:heir-opt -- \
--comb-to-cggi -cse \
$PWD/tests/comb_to_cggi/add_one.mlir
```

## Developing in HEIR

We use [pre-commit](https://pre-commit.com/) to manage a series of git
@@ -67,7 +92,8 @@ pre-commit run --all-files

## Creating a New Pass

The `templates` folder contains Python scripts to create boilerplate for new conversion or (dialect-specific) transform passes.
The `templates` folder contains Python scripts to create boilerplate for new
conversion or (dialect-specific) transform passes.

### Conversion Pass

@@ -83,11 +109,13 @@ python templates/templates.py new_conversion_pass \
--target_dialect_mnemonic=tfhe_rust
```

In order to build the resulting code, you must fix the labeled `FIXME`s in the type converter and the op conversion patterns.
In order to build the resulting code, you must fix the labeled `FIXME`s in the
type converter and the op conversion patterns.

### Transform Passes

To create a transform or rewrite pass that operates on a dialect, run a command similar to the following:
To create a transform or rewrite pass that operates on a dialect, run a command
similar to the following:

```
python templates/templates.py new_dialect_transform \

0 comments on commit 664874e

Please sign in to comment.