Stream: git-cranelift

Topic: cranelift / Issue #513 Infix operators in the text format?


view this post on Zulip GitHub (Feb 28 2020 at 23:24):

alexcrichton transferred Issue #513:

Currently, cranelift IR is always printed with one instruction per line, eg.:

function %foo(i32, i32, i32) -> i32 {
ebb0(v0: i32, v1: i32, v2:i32):
    v3 = imul v0, v1
    v4 = iadd v3, v2
    return v4
}

What if we introduced some simple syntax sugar for instructions with only one use? It'd be in addition to the existing syntax. We could then (optionally) print that same code like this:

function %foo(i32, i32, i32) -> i32 {
ebb0(v0: i32, v1: i32, v2:i32):
    return v0 * v1 + v2
}

That would be much easier to read in many cases, which is of potential interest to cranelift developers, but also to cranelift users looking to understand how cranelift is compiling their code.

This also might make it even more interesting to switch to // comments (#471).

There's some ambiguity with syntax like v0 + 1, but I think we can resolve it by saying that we always use the _imm instruction when possible rather than emitting an iconst

And there's the question if value numbers for the intermediate values. My rough idea is that they'd just always use the next available value number.

There are other issues to consider too, such as printing srclocs and instruction encodings. But I think we could find reasonable ways to make these work. The main question is, is this idea worth pursuing?


Last updated: Dec 23 2024 at 14:03 UTC