问题
This is a follow up question from this one.
I am using llvm::CloneFunctionInto
defined in llvm/Transforms/Utils/Cloning.h
in order to create a new function after code generation with the right signature inferred from the type of the return values. This works nicely but it is slow
I am trying to optimize this a little bit by some way to move or transfer the function body from the old function to the new one, is there a utility for that?
I am trying to hack a way to do the transfer by looking at the code in CloneFunctionInto, but wanted to see if an existing function exists
回答1:
Shamelessly stolen from the Arg Promotion pass (search for splice):
// Since we have now created the new function, splice the body of the old
// function right into the new function, leaving the old rotting hulk of the
// function empty.
NF->getBasicBlockList().splice(NF->begin(), F->getBasicBlockList());
Where NF
is the new function you're cloning into and F
is the old function that you have just cloned.
来源:https://stackoverflow.com/questions/12864106/move-function-body-avoiding-full-cloning