Stream: cranelift

Topic: Peepmatic and rewriting DSLs in Cranelift


view this post on Zulip l1mey (Jan 02 2026 at 23:50):

Hello everyone! I'm new to Cranelift at the moment but have been looking to possibly use the DSLs for compiler peepholes in Cranelift in my project for formalising peepholes in Lean, particularly for encoding the actual rules in the theorem statement.

For example below are two theorems (not rewrites yet!) for associativity and UB refinement using the ~> relation (this is a LLVM style poison model of UB).

image.png

image.png

The peepmatic DSL seems like a perfect fit, and I'll have to adjust it to support polymorphism ∀bitwidths. I've looked around at the resources and I've seen for Peepmatic:

My question is, what happened to Peepmatic? I can't find much mention of it inside the Cranelift codebase. Was it subsumed into a more general rewriting system under ISLE? (I thought peepmatic was for the middle end generic peepholes, that are separate to instruction selection/lowering)

I'm looking for a good DSL base to represent rewrites in a compiler, from what I've seen I can choose between the existing DSL in Cranelift (might not be peepmatic anymore) or the Go compiler's .rules DSL. Cranelift seems like it would be the better choice, given the existing literature and resources around it.

Could the community also point me towards where to get started with understanding how the existing DSL is implemented in Cranelift? I appreciate it!

A DSL and compiler for generating peephole optimizers for Cranelift - fitzgen/peepmatic
This PR introduces peepmatic, a peephole optimizations DSL and peephole optimizer compiler. Developers write a set of optimizations in the DSL, and then peepmatic compiles the set of optimizations ...
peepmatic A peephole optimizations DSL and peephole optimizer compiler for Cranelift Nick Fitzgerald • 2020-05-04

view this post on Zulip Chris Fallin (Jan 03 2026 at 00:25):

Hi @l1mey -- thanks for the question!

You're correct that ISLE has subsumed Peepmatic, and we subsequently removed Peepmatic from the tree -- for all the reasoning, see @fitzgen (he/him) 's PR here: https://github.com/bytecodealliance/wasmtime/pull/3543

ISLE was originally designed for the instruction-selection/lowering use-case, but its (not well-kept) secret is that it is a general matching language, and so in our new rewrite-based mid-end (https://github.com/bytecodealliance/rfcs/blob/main/accepted/cranelift-egraph.md) we re-used ISLE as well. In essence we have two different ISLE environments with two separate preludes that bind it to either the mid-end or back-end context.

For more on ISLE, you can read the ISLE langref, the docs on the backend integration here, the RFC on the ISLE design here, the RFC on the mid-end here, and my blog post on ISLE here.

Peepmatic was an early attempt at a DSL for peephole optimizations, with the idea that maybe sometime in the future we could user it for instruction selection as well. It didn't really pan out,...
RFC process for Bytecode Alliance projects. Contribute to bytecodealliance/rfcs development by creating an account on GitHub.
A lightweight WebAssembly runtime that is fast, secure, and standards-compliant - bytecodealliance/wasmtime
A lightweight WebAssembly runtime that is fast, secure, and standards-compliant - bytecodealliance/wasmtime
Rendered This RFC proposes a new DSL for the instruction selectors in Cranelift, automating the generation of the backends based on a list of term-rewriting rules provided by the backend author. Th...

view this post on Zulip Chris Fallin (Jan 03 2026 at 00:25):

You can see examples of our use of ISLE to define mid-end rewrites here, as well.

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant - bytecodealliance/wasmtime

view this post on Zulip l1mey (Jan 03 2026 at 02:13):

I appreciate it! Thanks for the quick response. I'll take a look over these and let you know if I have any further questions.


Last updated: Jan 09 2026 at 13:15 UTC