[LLVMdev] Question about use-def chain
Bill Wendling
isanbard at gmail.com
Wed Mar 12 01:59:26 PDT 2008
Hi 신건철,
On Mar 12, 2008, at 12:22 AM, 신건철 wrote:
> Programmers’ manual says we can iterate over a use-def chain by
> op_iterator.
>
> It works fine except for load and store instruction of stack
> variables.
>
>
>
> For example, a simple bitcode is like the below.
>
> i = alloca i32
>
> store i32 0, i32* %i, align 4
>
> %tmp1 = load i32* %i, align 4
>
>
>
> If I apply a use-def chain to load instruction, I get alloca
> instruction.
>
> I think store instruction is a correct use-def chain.
>
> Am I right?
>
> Is there any other method to iterate over a use-def chain in this
> case?
>
The op_iterator will tell you what definitions the instruction uses.
So in this case, the "alloca" instruction is the correct one because
the store instruction isn't defining %i. If you were to iterate over
the uses of the alloca instruction, then you would get the "store"
and "load" instructions.
If you're trying to determine that %i is the same value for both the
"store" and "load" instructions, then you'll probably want to compare
the op_iterator values for both the "store" and "load" and see if
they match. For example, %i in this case matches, because %i isn't
redefined between the store and the load.
-bw
More information about the llvm-dev
mailing list