I am very new to LLVM. I illustrate what I want to achieve visually below.
Initially, Inst A is used by other Inst (B, C, D, etc). Now, I want to create a new Inst (A’), which uses A still. However, all other Inst now will use Inst A’ instead. After going through documentations, I find replaceUsesWithIf() function, but I can hardly find any example about how to use it, especially on how to insert the conditional as function_ref.
A
/|\
/ | \
B C D ... // Before
A
|
|
A'
/|\
/ | \
B C D ... // After
(Inst A).replaceUsesWithIf((Inst A'), ...);
Also, be careful not to modify uses or instruction lists while iterating over those lists as it might invalidate the iterator. And there are no asserts that would tell you about it… I collect instructions I need to modify in some kind of a container and apply modifications afterwards.