[LLVMdev] use-def chain questions

Tianwei tianwei.sheng at gmail.com
Sat Dec 5 22:39:37 PST 2009


On Sun, Dec 6, 2009 at 2:42 AM, Chris Lattner <clattner at apple.com> wrote:

>
> On Dec 5, 2009, at 4:02 AM, Tianwei wrote:
>
> > Hi, all,
> >    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
> > 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
> >
> > int foo(int *q, int *p) {
> >   int x;
> >   *p = 1;
> >   x = *q;
> >   return x;
> > }
> >
> > the IR after front-end is:
> >
> > s1:  store i32* %q, i32** %q_addr
> > s2: store i32* %p, i32** %p_addr
> >
> > s3:  %1 = load i32** %p_addr, align 8                ; <i32*> [#uses=1]
> > s4: store i32 1, i32* %1, align 4
> >
> > s5:  %2 = load i32** %q_addr, align 8                ; <i32*> [#uses=1]
> > s6:  %3 = load i32* %2, align 4                      ; <i32> [#uses=1]
> > s7: store i32 %3, i32* %x, align 4
> >
> > 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
> >
> > 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?
> > 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.
>
> 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).
>
> Hi,Chris,
    Thanks very much. I will look into the MemoryDependenceAnalysis phase to
see how it works.
BTW, does anyone know my second question about passing flag to gold-plugin?

Thanks.

Tianwei

> -Chris




-- 
Sheng, Tianwei
Inst. of High Performance Computing
Dept. of Computer Sci. & Tech.
Tsinghua Univ.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20091206/a5bec2b8/attachment.html>


More information about the llvm-dev mailing list