I’ve recently had the need to clone MachineFunctions for an experimental pass I’m working on*. While there exists code for cloning at the IR level (in Transforms/Utils/Cloning.h), I haven’t been able to find anything for cloning MachineFunctions. I had a brief stab at implementing it but quickly got into the weeds trying to handle all the details.
So, my question is twofold:
- Is there some utility I’ve overlooked which can clone MachineFunctions?
- If I were to implement it, would it be considered a generally useful utility, and accepted into the tree? In other words, is it worth taking the time to do it properly and getting it reviewed?
- To answer the inevitable XY problem question: my pass does combinatorial optimisation at the MachineFunction level: modifying the function, evaluating the result and then backtracking. Some of the changes it makes are hard to undo when backtracking (such as spilling), so I’m trying the approach of cloning the MachineFunction, modifying the new one and then throwing it away.