Hi, I am a new user of LLVM. I am using it as the IR for a compiler for a subset of LUA. I have the .ll file ready and it executes fine when passed to the llvm interpreter. Now, I wish to perform a few optimizations to the code starting with dead code elimination. For this I would need the CFG. I am very new to all of this stuff. Please help me out guys. The way I want to proceed is to start at the top of the CFG and then find out the blocks reachable from here. At the end, if any basic block remains unreachable, then I would classify it as dead code. I read a few things about llvm passes and felt this could be made a pass. Please let me know what's the right and fastest way to do this. Regards, Hersh -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20091114/4b7ca78f/attachment.html>
> Now, I wish to perform a few optimizations to the code starting with dead > code elimination.LLVM already provides huge variety of optimization passes. Is there any specific reason why do you need to do a DCE by yourself? -- With best regards, Anton Korobeynikov Faculty of Mathematics and Mechanics, Saint Petersburg State University
On Nov 14, 2009, at 7:02 AM, Hersh.S. Iyer wrote:> Hi, > > I am a new user of LLVM. I am using it as the IR for a compiler for a subset of LUA. > I have the .ll file ready and it executes fine when passed to the llvm interpreter. > > Now, I wish to perform a few optimizations to the code starting with dead code elimination. > For this I would need the CFG. I am very new to all of this stuff. Please help me out guys.Take a look at llvm/include/llvm/Support/CFG.h. Grep lib/Transforms/*/*.cpp for uses of pred_ for example. -Chris
On Sat, Nov 14, 2009 at 7:02 AM, Hersh.S. Iyer <coolhersh at gmail.com> wrote:> Now, I wish to perform a few optimizations to the code starting with dead > code elimination. > For this I would need the CFG. I am very new to all of this stuff. Please > help me out guys. > The way I want to proceed is to start at the top of the CFG and then find > out the blocks > reachable from here. At the end, if any basic block remains unreachable, > then I would > classify it as dead code.I think the function RemoveUnreachableBlocksFromFn in lib/Transforms/Scalar/SimplifyCFGPass.cpp does the transformation you're describing. -Eli
Hersh.S. Iyer wrote:> Hi, > > I am a new user of LLVM. I am using it as the IR for a compiler for a > subset of LUA. > I have the .ll file ready and it executes fine when passed to the llvm > interpreter. > > Now, I wish to perform a few optimizations to the code starting with > dead code elimination. > For this I would need the CFG. I am very new to all of this stuff. > Please help me out guys. > The way I want to proceed is to start at the top of the CFG and then > find out the blocks > reachable from here. At the end, if any basic block remains unreachable, > then I would > classify it as dead code. > > I read a few things about llvm passes and felt this could be made a > pass. Please let me > know what's the right and fastest way to do this.If what's you've got is a .ll file on disk and you're just wondering how to optimize it, use the 'opt' tool. The list of passes available in LLVM is here: http://llvm.org/docs/Passes.html . A good default selection is available through 'opt -std-compile-opts', and if your .ll file represents a whole program (ie., it includes main()) then you can run 'opt -std-link-opts' too. Nick