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.
(2) another question
I am using the gold-plugin to compile large applications, it works very
well, then, I want to add a pass into
include/llvm/Support/StandardPasses.h: createStandardLTOPasses,
Since I want to add a new phase and disable some existing phase, is there
any way to pass some flag to do that, now my complication model is:
export PREFIX=/home/tianwei/llvm/llvm-gcc-bin/
export CC="$PREFIX/bin/llvm-gcc -use-gold-plugin"
export CXX="$PREFIX/bin/llvm-g++ -use-gold-plugin"
export AR="$PREFIX/bin/ar --plugin
/home/tianwei/llvm/llvm-gcc-bin/libexec/gcc/x86_64-unknown-linux-gnu/4.2.1/libLLVMgold.so"
export NM="$PREFIX/bin/nm --plugin
/home/tianwei/llvm/llvm-gcc-bin/libexec/gcc/x86_64-unknown-linux-gnu/4.2.1/libLLVMgold.so"
export RANLIB=/bin/true #ranlib is not needed, and doesn't support .bc files
in .a
export CFLAGS="-O2 --emit-llvm"
export
LD_LIBRARY_PATH=/usr/local/lib:/home/tianwei/llvm/llvm-gcc-bin/lib/:$LD_LIBRARY_PATH
export
PATH=/home/tianwei/llvm/llvm-gcc-bin/bin/:/home/tianwei/llvm/bin/bin/:$PATH
alias ar="$PREFIX/bin/ar --plugin
/home/tianwei/llvm/llvm-gcc-bin/libexec/gcc/x86_64-unknown-linux-gnu/4.2.1/libLLVMgold.so"
alias nm="$PREFIX/bin/nm --plugin
/home/tianwei/llvm/llvm-gcc-bin/libexec/gcc/x86_64-unknown-linux-gnu/4.2.1/libLLVMgold.so"
alias ranlib=/bin/true
the new ld which enable gold-plugin is installed in the PATH. Using these
configuration, I can build apache/httpd successfully with its default make
system. The trick here is that add "--emit-llvm" into CFLAGS, the
"-c" will
only produce llvm bytecode files. Also add "-use-gold-plugin" into CC,
this
is necessary since the make system usually use llvm-gcc as the link,
llvm-gcc will pass "-use-gold-plugin" into final ld. ("-c"
with
-use-gold-plugin has no bad effect, also ld with --emit-llvm also has no bad
effect, so this works).
But I want to how can I pass additional flag into libLTO as opt in this
compilation model.
Thanks very much.
Tianwei
--
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/20091205/5148c023/attachment.html>
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). -Chris
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>