Stream: cranelift

Topic: Custom CLIF pass?


view this post on Zulip Kristian H. Kristensen (Jun 12 2023 at 18:53):

Is it possible to plug in a custom CLIF pass? I'm coming into cranelift from an assembly like language and don't have a nice SSA representation, but there are a few domain specific lowerings and transforms that I'd like to do. Ideally, there'd be a way to run a pass after initial conversion to SSA, copy prop and dead code elimination...?

view this post on Zulip Chris Fallin (Jun 12 2023 at 18:59):

@Kristian H. Kristensen we don't have a "pass manager" a la LLVM, but there's nothing stopping you from mutating the function body before invoking final code generation. The Context exposes func publicly and so you could write a pass that traverses and transforms that prior to calling compile_and_emit

view this post on Zulip Kristian H. Kristensen (Jun 12 2023 at 19:04):

@Chris Fallin nice, I'll take a look. I like the more manual approach better anyway, I'm always fighting the LLVM pass manager to find the right place to plug in.

view this post on Zulip Jamey Sharp (Jun 12 2023 at 19:05):

You can't modify the function in between existing passes though, so if you want some of our existing passes to fix up your input for you that's a bit of a pain. But you could call Context::optimize yourself, although the documentation says it's "Public only for testing purposes." If you want that, you'd call optimize, then do your modifications, then let compile_and_emit run optimizations again.

view this post on Zulip Kristian H. Kristensen (Jun 12 2023 at 19:08):

Hi Jamey! Ok, noted.

view this post on Zulip Jamey Sharp (Jun 12 2023 at 19:19):

@Kristian H. Kristensen Oh hey, I didn't recognize your last name, hi! I don't suppose you're starting from some IR in Mesa, are you? I would certainly enjoy seeing Cranelift used there :grinning_face_with_smiling_eyes:

view this post on Zulip Kristian H. Kristensen (Jun 12 2023 at 19:29):

No, this isn't mesa related, but I think there's also a lot of overlap between the mesa internal IR (nir) and what cranelift does... and nir is a very nice IR, although it's not written in rust!

view this post on Zulip Chris Clark (Jun 17 2023 at 21:53):

Kristian H. Kristensen said:

Is it possible to plug in a custom CLIF pass? I'm coming into cranelift from an assembly like language and don't have a nice SSA representation, but there are a few domain specific lowerings and transforms that I'd like to do. Ideally, there'd be a way to run a pass after initial conversion to SSA, copy prop and dead code elimination...?

If there is some optimizations you think could be added, is this something cranelift could benefit from if included in their project?


Last updated: Dec 23 2024 at 12:05 UTC