Using CodeGen information to modify IR

Hi, I’m working on the backend for a custom compiler that I’m building for a student project. I make several transformations to the code at the IR level, but the correctness of these transformations is affected by spilled registers under certain conditions.

I can identify these registers using a MachineIR pass but undoing the transformations at the MachineIR level seems cumbersome and impractical. Ideally, I would want to be able to locate the IR basic blocks which include the offending register spills so I can undo the transformations to these blocks.

What would be the best way to do this? I noticed that the API offers a getBasicBlock() function on the MachineIR block, although I am not sure how much it would help my situation since I need a lot of other information that I gather in analysis passes at the IR level to undo the changes.

I would be happy to share any more details about my problem that would help you to point me in the right direction.

There is no way of doing this. When the MIR is created, the corresponding IR module is no longer mutable.

Making potentially incorrect transformation is the problem here. You can put your transformed code under a conditional branch and have the original code in the other side of it. Then, in codegen, you could simply pick one depending on whether your conditions were met.

That sounds reasonable, thank you!