[LLVMdev] Convert a function to "main"

Tim Northover t.p.northover at gmail.com
Thu Oct 3 08:48:55 PDT 2013


Hi Pablo,

> * Create a new function "main" without arguments and copy all basic-block's
> from the original function to the new one. I've had problems with this
> approach because of cloning not updating operators of the basic-block
> instructions. Thanks to

This is the approach I'd take. It sounds like you may have discovered
it already, but there's a function "CloneFunctionInto" which should be
able to do everything for you.

What I'd do is create a new skeleton function "main". Populate it with
your new register definitions that will take over from the arguments.
So main would then look like:

define i32 @main() {
   %arg1 = alloca float
   ...
   %argN = alloca i8
}

Then call CloneFunctionInto, telling it about these %argX registers
and how they map to the original function's arguments. With luck
everything should be copied and updated properly for you.

Cheers.

Tim.



More information about the llvm-dev mailing list