[LLVMdev] Replacing uses within a function
Carlos Sánchez de La Lama
carlos.delalama at urjc.es
Fri Oct 21 09:15:34 PDT 2011
Hi all,
I am trying to replace all uses of a value1 *inside of a given function*
to use value2. My strategy was to iterate all the basic blocks, again
iterating all the instructions in each basic block, and using
replaceUsesOfWith(value1, value2) for every instruction.
This used to work all right, but now I am finding some problems. There
are instructions like this:
store i32 0, i32* getelementptr inbounds ([3 x i32]* @value1, i32 0, i32
0)
So the store itself is not a user of value1, and the usage does not get
replaced.
I had a similar problem with PHI nodes recently
(http://lists.cs.uiuc.edu/pipermail/llvmdev/2011-October/043954.html)
and I was suggested using value1->replaceAllUsesWith. But again I cannot
cause I want only to replace uses within a given function.
I could iterate value1->use_iterator and replace those which are inside
of the desired function, but with cases as the mentioned one it is not
so easy to find whether a given value is within a function (the GEP in
to store is not inside the function, but used by an instruction that
is).
Is there an easy way to achieve this? I find it would be better to force
all instructions (like the GEP above) to be directly place on the
function, and not as operands of other instructions, unless there is a
good & known reason not to.
BR
Carlos
More information about the llvm-dev
mailing list