[LLVMdev] use-def chain questions

Tianwei tianwei.sheng at gmail.com
Sat Dec 5 04:02:17 PST 2009

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

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
export NM="$PREFIX/bin/nm --plugin
export RANLIB=/bin/true #ranlib is not needed, and doesn't support .bc files
in .a
export CFLAGS="-O2 --emit-llvm"
alias ar="$PREFIX/bin/ar --plugin
alias nm="$PREFIX/bin/nm --plugin
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.


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>

More information about the llvm-dev mailing list