[LLVMdev] Removing function params.
John Criswell
criswell at illinois.edu
Tue Oct 22 08:27:57 PDT 2013
On 10/22/13 10:17 AM, James Courtier-Dutton wrote:
> Hi,
>
> I am writing my own passes in LLVM.
> I start with a function with various uses of a LLVM IR function
> parameter: e.g. paramB.
>
> After running one of my passes, all the uses of the paramB vanish.
> How do I do the last step, and remove the paramB from the function
> parameters in the LLVM IR?
In order to add or remove parameters from a function, you will need to
create a new function and clone the contents of the old function into
the new function. You will then need to replace uses of the old
function with the new function.
There's a utility function called (I think) cloneFunctionInto which
makes this whole process much simpler. Look for a source file with the
word "Clone" in it in llvm/lib/Transforms; the function will be located
there.
As an FYI, if you want to remove an argument because it is unused, LLVM
already has a transform pass that does that. I think it's
DeadArgumentElimination.
-- John T.
>
> I want to go from:
> function test( int paramA, int paramB)
> { ... }
>
> to:
> function test( int paramA)
> { ... }
>
> Is there an LLVM IR API method that does this, or do I have to create
> a whole new function and add all the basic blocks and instructions
> from the old one to it?
>
> Also, how do I do the opposite:
> I want to go from:
> function test( int paramA)
> { ... }
>
> to:
> function test( int paramA, int paramB)
> { ... }
>
>
> Kind Regards
>
> James.
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
More information about the llvm-dev
mailing list