<br><br><div class="gmail_quote">On Sun, Dec 6, 2009 at 2:42 AM, Chris Lattner <span dir="ltr"><<a href="mailto:clattner@apple.com">clattner@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im"><br>
On Dec 5, 2009, at 4:02 AM, Tianwei wrote:<br>
<br>
> Hi, all,<br>
>    We are working on a static analysis phase on LLVM's IR, we want to do a backforward phase through the use-def chain, I knew that LLVM<br>
> had a built-in SSA form which provide the use-def chain for virtual register variables, however, I want to know if you also provide some kinds of use-def chain for memory operations? for example, I have the following source code<br>

><br>
> int foo(int *q, int *p) {<br>
>   int x;<br>
>   *p = 1;<br>
>   x = *q;<br>
>   return x;<br>
> }<br>
><br>
> the IR after front-end is:<br>
><br>
> s1:  store i32* %q, i32** %q_addr<br>
> s2: store i32* %p, i32** %p_addr<br>
><br>
> s3:  %1 = load i32** %p_addr, align 8                ; <i32*> [#uses=1]<br>
> s4: store i32 1, i32* %1, align 4<br>
><br>
> s5:  %2 = load i32** %q_addr, align 8                ; <i32*> [#uses=1]<br>
> s6:  %3 = load i32* %2, align 4                      ; <i32> [#uses=1]<br>
> s7: store i32 %3, i32* %x, align 4<br>
><br>
> in the source code, I want to find the definition statement of "*q", here since we do not know if p and q are aliased or not, we assume they are may-aliased, So I want to find the statement "*p = 1" as the define statement<br>

><br>
> in the IR code, s6 is the load instruction for "*p", s4 is the store instruction for "*q", is there existing infrastructure for us to use and find s4 directly?<br>
> I understand that I can traverse back every instruction, and compare the alias result to see if any instruction prior to it is define statement, but I am not sure if there is already better way to do that.<br>
<br>
</div>This is what the MemoryDependenceAnalysis pass is used for.  Given a load (for example) it searches "up" the cfg to find a defining store or a clobbering value (e.g. a store which may alias the loaded pointer).<br>

<font color="#888888"><br></font></blockquote><div>Hi,Chris,</div><div>    Thanks very much. I will look into the MemoryDependenceAnalysis phase to see how it works.</div><div>BTW, does anyone know my second question about passing flag to gold-plugin? </div>
<div><br></div><div>Thanks.</div><div><br></div><div>Tianwei</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><font color="#888888">
-Chris</font></blockquote></div><br><br clear="all"><br>-- <br>Sheng, Tianwei<br>Inst. of High Performance Computing<br>Dept. of Computer Sci. & Tech.<br>Tsinghua Univ.<br>