I wish to write an LLVM pass that two arguments of type i32 to select functions. My first try (sketched below) failed:
bool MyFunctionPass::runOnFunction(Function &f)
{
Type *int32 = Type::getInt32Ty(f.getParent()->getContext());
Argument *xC = new Argument(int32, "__xC", &f);
...
The module verifier crashes if I try the above. The newly added argument type is junk 0xCDCDCDCD (uninitialized heap memory). The function type remains:
void (i32 addrspace(1)*, i32 addrspace(1)*, i32)
instead of being extended by the new i32.
Also, adding the parameter directly to the parameter list Function::getArgumentList() failed as the Argument constructor links itself to the function, and this is detected as a double link.
- Do I need a ModulePass to do this, or will a FunctionPass suffice?
- Is there an elegant way of doing this?
Thanks!