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...?
@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
@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.
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.
Hi Jamey! Ok, noted.
@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:
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!
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: Nov 22 2024 at 16:03 UTC