[llvm-dev] Cloning MachineFunctions

32 views
Skip to first unread message

Owen Rodley via llvm-dev

unread,
Aug 6, 2019, 2:50:33 AM8/6/19
to LLVM Developers
Hi,

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:
1) Is there some utility I've overlooked which can clone MachineFunctions?
2) 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?

Thanks


* 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.

Lorenzo Casalino via llvm-dev

unread,
Aug 6, 2019, 10:27:57 AM8/6/19
to via llvm-dev, owen....@gmail.com
Hi Owen,

Looking to the API, I think MachineFunction cloning is something not
taken into consideration (e.g.,
copy-construction is forbidden).

Maybe, you could achieve your goal by building a new MachineFunction
with the provided constructor,
extracting the parameters from the copied MachineFunction, and using the
MachineFunction::getProperties
and MachineFunctionProperties::set() to copy the properties.

Does it work for you? Or did I miss some particular?

Concerning the utility of the cloning function, I do not see it, except
for specific applications. But this
is my personal opinion; someone else with more experience may properly
address your question.


-- Lorenzo


_______________________________________________
LLVM Developers mailing list
llvm...@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

Owen Rodley via llvm-dev

unread,
Aug 8, 2019, 2:45:07 AM8/8/19
to Lorenzo Casalino, via llvm-dev
Right, this would work, but I think it would just be the first step. We'd still need to copy all of the blocks, instructions, etc.
Reply all
Reply to author
Forward
0 new messages