Rekha R
2013-Oct-06 12:23 UTC
[LLVMdev] Suggestion on simple optimization pass for a beginner?
Hello, I am a beginner in LLVM development with the aim of writing a new optimization pass. But then before I could do that, I thought of writing simple passes. I could successfully implement the Hello pass as given in the doc. Then I wrote a simple Constant Folding pass - evaluate instructions of the form c=10+20 and replace all uses of c with 30. Only later did I realize that Clang does this optimization while building the IR. Hence I couldn't check whether my constant folding pass is "working". I have two questions: 1. Is there a way to disable constant folding during IR development by clang? 2. If not, can someone suggest a simple optimization (simple in complexity on the lines of constant folding) to get started? My intention is to get used to the APIs in LLVM and not get cluttered by the optimization itself. (Hence I chose constant folding in the first place.) Any opinion will be appreciated :) Regards, Rekha -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20131006/c31e4feb/attachment.html>
John Criswell
2013-Oct-06 16:33 UTC
[LLVMdev] Suggestion on simple optimization pass for a beginner?
On 10/6/13 7:23 AM, Rekha R wrote:> Hello, > > I am a beginner in LLVM development with the aim of writing a new > optimization pass. But then before I could do that, I thought of > writing simple passes. I could successfully implement the Hello pass > as given in the doc. Then I wrote a simple Constant Folding pass - > evaluate instructions of the form c=10+20 and replace all uses of c > with 30. Only later did I realize that Clang does this optimization > while building the IR. Hence I couldn't check whether my constant > folding pass is "working". I have two questions: > > 1. Is there a way to disable constant folding during IR development by > clang?There are probably multiple ways to do this. One quick way would be to try different optimization levels (-O1 or -O3, for example). Another way would be to generate an LLVM assembly file (-S -emit-llvm) and to assemble that using llvm-as.> 2. If not, can someone suggest a simple optimization (simple in > complexity on the lines of constant folding) to get started?Constant propagation is one good candidate, as is dead code elimination, sparse conditional constant propagation, aggressive dead code elimination, strength reduction, etc. Instrumentation passes can also be good for practice. For example, instrumenting every load or store with a call to a run-time function to print the accessed address is pretty simple. -- John T. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20131006/f90feb67/attachment.html>
Rekha R
2013-Oct-07 11:46 UTC
[LLVMdev] Suggestion on simple optimization pass for a beginner?
On Sun, Oct 6, 2013 at 10:03 PM, John Criswell <criswell at illinois.edu>wrote:> On 10/6/13 7:23 AM, Rekha R wrote: > > Hello, > > I am a beginner in LLVM development with the aim of writing a new > optimization pass. But then before I could do that, I thought of writing > simple passes. I could successfully implement the Hello pass as given in > the doc. Then I wrote a simple Constant Folding pass - evaluate > instructions of the form c=10+20 and replace all uses of c with 30. Only > later did I realize that Clang does this optimization while building the > IR. Hence I couldn't check whether my constant folding pass is "working". I > have two questions: > > 1. Is there a way to disable constant folding during IR development by > clang? > > > There are probably multiple ways to do this. One quick way would be to > try different optimization levels (-O1 or -O3, for example). Another way > would be to generate an LLVM assembly file (-S -emit-llvm) and to assemble > that using llvm-as. > >> Yes. I tried both ways. It didn't work. The IR generated by clang has > constant expressions folded. Seems clang does this opt during IR > generations. Couldn't get the motivation why. > > 2. If not, can someone suggest a simple optimization (simple in > complexity on the lines of constant folding) to get started? > > > Constant propagation is one good candidate, as is dead code elimination, > sparse conditional constant propagation, aggressive dead code elimination, > strength reduction, etc. > > Instrumentation passes can also be good for practice. For example, > instrumenting every load or store with a call to a run-time function to > print the accessed address is pretty simple. > > Thanks.> -- John T. > >-- Rekha -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20131007/e8eac370/attachment.html>
David Tweed
2013-Oct-08 08:03 UTC
[LLVMdev] Suggestion on simple optimization pass for a beginner?
Hi, If you're looking for something incredibly simple to get started with it might be fruitful to implement replacement of particular function calls of constant arguments with the appropriate result. (That might also then lead to opportunities for a constant propagation pass.) This would involve quite a bit of API usage without being actually that involved, and if you're doing it just for the learning experience you probably neededn't bother too much about the corner cases that make this tricky in general. Cheers, Dave From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] On Behalf Of Rekha R Sent: 06 October 2013 13:24 To: LLVM Developers Mailing List Subject: [LLVMdev] Suggestion on simple optimization pass for a beginner? Hello, I am a beginner in LLVM development with the aim of writing a new optimization pass. But then before I could do that, I thought of writing simple passes. I could successfully implement the Hello pass as given in the doc. Then I wrote a simple Constant Folding pass - evaluate instructions of the form c=10+20 and replace all uses of c with 30. Only later did I realize that Clang does this optimization while building the IR. Hence I couldn't check whether my constant folding pass is "working". I have two questions: 1. Is there a way to disable constant folding during IR development by clang? 2. If not, can someone suggest a simple optimization (simple in complexity on the lines of constant folding) to get started? My intention is to get used to the APIs in LLVM and not get cluttered by the optimization itself. (Hence I chose constant folding in the first place.) Any opinion will be appreciated :) Regards, Rekha -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20131008/3cda9836/attachment.html>
Possibly Parallel Threads
- [LLVMdev] Suggestion on simple optimization pass for a beginner?
- [LLVMdev] Suggestion on simple optimization pass for a beginner?
- [LLVMdev] A way to write new pass by keeping source and build directories separate
- linkedin gem
- [LLVMdev] Appropriate DS for implementing worklist