[LLVMdev] How to slice the source code?

Mingliang LIU liuml07 at gmail.com
Sun Mar 17 11:25:42 PDT 2013

Hi all,

I'm doing the program slicing [1] in LLVM. Now I implemented the Weiser's
algorithm [2] in a simple way by writing a plugin to analyze the IR. My
final goal is to slice the source code, thus I recorded all the lines of
source code to be sliced. The last step is to delete the lines which are
not in the program slice. However, I met a problem when deleting the source
code directly:

To make it clear, I gave an example following, in which the following lines
(underline decoration) can be deleted. We can see that the line 4 should
also be deleted, but it's not.

> 1   *for (int i = 0; i < BUFSIZE; i++) {*
> 2      *for (int j = 0; j < np; j++)
> *3         *buf[i] = ((rank + j) % np);
> *4  }

I got the LoC info from meta-data of the IR which can be deleted. However,
there is no according IR in the first place, which represents the line 4
(whose functionality is to end a block). I'm not familiar with clang and
its AST. A friend told me to parse the code using python to find the
matching "}" (or END in Fortran) and delete them. I'd like to know if there
is an LLVM way to do this.

Any idea?

Thank you!

[1] http://en.wikipedia.org/wiki/Program_slicing
[2] http://dl.acm.org/citation.cfm?id=802557
Mingliang LIU (刘明亮 in Chinese)

PACMAN Group,  Dept. of Computer Science & Technology
Tsinghua University, Beijing 100084, China
Email: liuml07 at mails.tsinghua.edu.cn
Homepage: http://pacman.cs.tsinghua.edu.cn/~liuml07/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130318/ba0f2a42/attachment.html>

More information about the llvm-dev mailing list