parameters sent by llvm::ExtractCodeRegion


I use llvm::ExtractCodeRegion to extract a region of code into a new
function and everything seems to be OK. But I need to write the new function
into a separate file for further processing. Therefore, I copy in the new
file the new function together with all globals and declarations of the
module, to make them visible for my function.

The problem appears when I have some global static structures declared in
the module, which are modified in the original code, before the blocks I
want to extract. Being declared outside of the original function, they will
not be given as input parameters to the new function. So, when I extract the
new function in a separate file, it doesn't see the modifications that have
been done on the static structures.

If I include the globals of the module in the new file, these structures are
redefined, so my function gets them all as being reinitialised.

I need to process the new file with llvm-as and llc, and as far as I know
these tools do not accept more than one file as parameters.

The only solution that comes to my mind is to modify the
llvm::ExtractCodeRegion to send as parameters also the globals used inside
the code to be extracted. But I am open to better solutions.