GitPedia

Heir

A compiler for homomorphic encryption

From google·Updated June 19, 2026·View on GitHub·

An MLIR-based toolchain for [homomorphic encryption](https://en.wikipedia.org/wiki/Homomorphic_encryption) compilers. Read the docs at [the HEIR website](https://heir.dev). The project is written primarily in C++, distributed under the Apache License 2.0 license, first published in 2023. Key topics include: homomorphic-encryption, mlir.

Latest release: nightly-2026.06.20Nightly 2026.06.20
June 20, 2026View Changelog →

HEIR: Homomorphic Encryption Intermediate Representation

GitHub Workflow Status (with event)
GitHub Contributors
GitHub Discussions
GitHub License
OpenSSF Scorecard

An MLIR-based toolchain for
homomorphic encryption
compilers. Read the docs at the HEIR website.

For more information on MLIR, see the MLIR homepage.

Quickstart (Python)

Pip install the heir_py package

bash
pip install heir_py

Then run an example:

python
from heir import compile from heir.mlir import I64, Secret @compile() # defaults to scheme="bgv", OpenFHE backend, and debug=False def func(x: Secret[I64], y: Secret[I64]): sum = x + y diff = x - y mul = x * y expression = sum * diff + mul deadcode = expression * mul return expression func.setup() enc_x = func.encrypt_x(7) enc_y = func.encrypt_y(8) result_enc = func.eval(enc_x, enc_y) result = func.decrypt_result(result_enc) print( f"Expected result for `func`: {func.original(7,8)}, FHE result:" f" {result}" )

This will compile the function above using the BGV scheme to machine code via
the OpenFHE backend.
Then calling the function will encrypt the inputs, run the function, and return
the decrypted result. The function call foo(7, 8) runs the entire
encrypt-run-decrypt flow for ease of testing.

Building from source

HEIR requires a recent C compiler (see
clang_matrix
for version-specific support, recent GCCs also tend to work), and some backends
like OpenFHE require libomp-dev.

HEIR depends on LLVM (from source) so a clean build may take 15-30 minutes
depending on your machine.

This project uses bazel for its build system. Install
bazelisk to manage the bazel version
automatically. Then, with bazel on your path (pointing to bazelisk), run the
following to build the main pass-running tool.

bash
bazel build //tools:heir-opt

Or run an end-to-end test like

bash
bazel test //tests/Examples/openfhe/ckks/halevi_shoup_matvec:all

See the bazel tips page for more
example commands and tips on using bazel.

Supported backends and schemes

Backend LibraryBGVBFVCKKSCGGI
OpenFHE
Lattigo
tfhe-rs
Jaxite

Note some backends do not support all schemes.

Contributing

There are many ways to contribute to HEIR:

Citations

The HEIR project can be cited in in academic work through following entry:

text
@misc{ali2025heir, title={HEIR: A Universal Compiler for Homomorphic Encryption}, author={Asra Ali and Jaeho Choi and Bryant Gipson and Shruthi Gorantala and Jeremy Kun and Wouter Legiest and Lawrence Lim and Alexander Viand and Meron Zerihun Demissie and Hongren Zheng}, year={2025}, eprint={2508.11095}, archivePrefix={arXiv}, primaryClass={cs.CR}, url={https://arxiv.org/abs/2508.11095}, }

Support disclaimer

This is not an officially supported Google product.

<!-- mdformat global-off -->

Contributors

Showing top 12 contributors by commit count.

View all contributors on GitHub →

This article is auto-generated from google/heir via the GitHub API.Last fetched: 6/20/2026