Type unmatched after replacing functions

Hi all,
I am trying to merge functions with the same debug location by
using replaceAllUsesWith().
However, this leads to type unmatched problems because the
functions with the same debug location can have different parameters.

An example is foo(struct A) can be compiled to foo.1(struct A.1) and
foo.2(struct A.2).

I have inserted CastInst to solve the problems of arguments and return
values type unmatched. But I find the problem of unmatched type of uses
of function pointers is harder to solve.
The function pointers are often put in the initializers of global variables, and
they can not be simply replaced by a bitcast ConstantExpr since setOperand()
cannot be used for Constant.

So, is there any solution to this problem?
Thanks!

Hi Will,

Hi Will,

> The function pointers are often put in the initializers of global variables, and
> they can not be simply replaced by a bitcast ConstantExpr since setOperand()
> cannot be used for Constant.

Are you trying to be more selective than Value::replaceAllUsesWith
would allow for some reason?

I'm very glad to select another way if there is a better one. :slight_smile:

OK, then it sounds like that might be exactly what you need:
replaceAllUses of the function you're discarding with an appropriately
casted version of the new function. It automatically rebuilds any
Constant users it finds.

Cheers.

Tim.

> > Are you trying to be more selective than Value::replaceAllUsesWith
> > would allow for some reason?
>
> I'm very glad to select another way if there is a better one. :slight_smile:

OK, then it sounds like that might be exactly what you need:
replaceAllUses of the function you're discarding with an appropriately
casted version of the new function. It automatically rebuilds any
Constant users it finds.

Thank you, this simple method solves the problem perfectly!

Furthermore, I feel excited to receive your reply since last year your
advice also helped me a lot.
It is fortunate to be helped by you again :slight_smile:

Regards,
Will