Jorge Navas
2012-Aug-06 13:04 UTC
[LLVMdev] How to call some transformation passes (LoopRotate and LoopUnroll) from my own pass
Hello, I wrote my own pass which needs to do some loop unrolling. I can perform loop unrolling via opt: opt -mem2reg -loops -loop-simplify -loop-rotate -lcssa -loop-unroll -unroll-count=50 mytest.bc -o mytest.bc This command works perfectly. However, what I really want is to produce the **same behavior** but from my own pass (i.e., I don't want to use opt). I wrote a Module pass which already calls other analysis and transformation passes in its getAnalysisUsage method: void MyPass::getAnalysisUsage(AnalysisUsage& AU) const { AU.addRequired<LoopInfo>(); AU.addPreserved<LoopInfo>(); AU.addRequiredID(LoopSimplifyID); AU.addPreservedID(LoopSimplifyID); AU.addRequiredID(LCSSAID); AU.addPreservedID(LCSSAID); } However, I couldn't figure out how to call the LoopRotate and LoopUnroll passes since I cannot use addRequiredID or addRequired for these two transformations. In Scalar.h, I found:> Pass *createLoopUnrollPass(int Threshold = -1, int Count = -1, int AllowPartial = -1); > Pass *createLoopRotatePass();Is to call these methods the way to go? How?, can somebody show me an excerpt? P.S. I tried hard on Google but I couldn't find anything related. Thanks! Jorge
Raphael Ernani Rodrigues
2012-Aug-06 13:27 UTC
[LLVMdev] How to call some transformation passes (LoopRotate and LoopUnroll) from my own pass
Hi, Jorge. When you put these "AU.addRequired<OtherPass>();", you are telling to the pass manager that your pass will use the other passes. You can actually call the other passes with get analysis, like this: LoopInfo &li = getAnalysis<LoopInfo>(); I hope it helps. Regards, Raphael Ernani 2012/8/6 Jorge Navas <navas at comp.nus.edu.sg>:> > Hello, > > I wrote my own pass which needs to do some loop unrolling. > > I can perform loop unrolling via opt: > > opt -mem2reg -loops -loop-simplify -loop-rotate -lcssa -loop-unroll > -unroll-count=50 mytest.bc -o mytest.bc > > This command works perfectly. > > However, what I really want is to produce the **same behavior** but > from my own pass (i.e., I don't want to use opt). I wrote a Module > pass which already calls other analysis and transformation passes in > its getAnalysisUsage method: > > > void MyPass::getAnalysisUsage(AnalysisUsage& AU) const { > AU.addRequired<LoopInfo>(); > AU.addPreserved<LoopInfo>(); > AU.addRequiredID(LoopSimplifyID); > AU.addPreservedID(LoopSimplifyID); > AU.addRequiredID(LCSSAID); > AU.addPreservedID(LCSSAID); > } > > However, I couldn't figure out how to call the LoopRotate and > LoopUnroll passes since I cannot use addRequiredID or addRequired for > these two transformations. > > In Scalar.h, I found: > >> Pass *createLoopUnrollPass(int Threshold = -1, int Count = -1, int AllowPartial = -1); >> Pass *createLoopRotatePass(); > > > Is to call these methods the way to go? How?, can somebody show me an > excerpt? > > P.S. I tried hard on Google but I couldn't find anything related. > > Thanks! > > Jorge > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Andrew Trick
2012-Aug-06 17:25 UTC
[LLVMdev] How to call some transformation passes (LoopRotate and LoopUnroll) from my own pass
On Aug 6, 2012, at 6:04 AM, Jorge Navas <navas at comp.nus.edu.sg> wrote:> > Hello, > > I wrote my own pass which needs to do some loop unrolling. > > I can perform loop unrolling via opt: > > opt -mem2reg -loops -loop-simplify -loop-rotate -lcssa -loop-unroll > -unroll-count=50 mytest.bc -o mytest.bc > > This command works perfectly. > > However, what I really want is to produce the **same behavior** but > from my own pass (i.e., I don't want to use opt). I wrote a Module > pass which already calls other analysis and transformation passes in > its getAnalysisUsage method: > > > void MyPass::getAnalysisUsage(AnalysisUsage& AU) const { > AU.addRequired<LoopInfo>(); > AU.addPreserved<LoopInfo>(); > AU.addRequiredID(LoopSimplifyID); > AU.addPreservedID(LoopSimplifyID); > AU.addRequiredID(LCSSAID); > AU.addPreservedID(LCSSAID); > } > > However, I couldn't figure out how to call the LoopRotate and > LoopUnroll passes since I cannot use addRequiredID or addRequired for > these two transformations. > > In Scalar.h, I found: > >> Pass *createLoopUnrollPass(int Threshold = -1, int Count = -1, int AllowPartial = -1); >> Pass *createLoopRotatePass(); > > > Is to call these methods the way to go? How?, can somebody show me an > excerpt?The create*Pass methods give you a Pass instance that you can add to a pass manager. If you're replacing "opt", you should look at the opt driver, opt.cpp to see how to do this. You can call addRequired<X> from your pass to force the PassManager to run X before your pass. If you want to do these transformations within a single pass, then the transformations need to be exposed as a utility. llvm::UnrollLoop() currently is, but LoopRotation is not. LoopRotation could be exposed as a utility (or you could copy the relevant code), but you should try not to do that. The llvm strategy is that loop rotation should do the right thing when it runs before your pass. If loop rotation needs more information to what you want it to do, then you can create a some new analysis that loop rotation requires. You may want to try browsing the online docs, such as... http://llvm.org/docs/WritingAnLLVMPass.html Hope that helps. -Andy
Jorge Navas
2012-Aug-08 04:11 UTC
[LLVMdev] How to call some transformation passes (LoopRotate and LoopUnroll) from my own pass
Thanks! I understand now much better. Jorge On Monday, August 6, 2012 at 10:25:24 (-0700), Andrew Trick wrote:>> >> On Aug 6, 2012, at 6:04 AM, Jorge Navas <navas at comp.nus.edu.sg> wrote: >> >> > >> > Hello, >> > >> > I wrote my own pass which needs to do some loop unrolling. >> > >> > I can perform loop unrolling via opt: >> > >> > opt -mem2reg -loops -loop-simplify -loop-rotate -lcssa -loop-unroll >> > -unroll-count=50 mytest.bc -o mytest.bc >> > >> > This command works perfectly. >> > >> > However, what I really want is to produce the **same behavior** but >> > from my own pass (i.e., I don't want to use opt). I wrote a Module >> > pass which already calls other analysis and transformation passes in >> > its getAnalysisUsage method: >> > >> > >> > void MyPass::getAnalysisUsage(AnalysisUsage& AU) const { >> > AU.addRequired<LoopInfo>(); >> > AU.addPreserved<LoopInfo>(); >> > AU.addRequiredID(LoopSimplifyID); >> > AU.addPreservedID(LoopSimplifyID); >> > AU.addRequiredID(LCSSAID); >> > AU.addPreservedID(LCSSAID); >> > } >> > >> > However, I couldn't figure out how to call the LoopRotate and >> > LoopUnroll passes since I cannot use addRequiredID or addRequired for >> > these two transformations. >> > >> > In Scalar.h, I found: >> > >> >> Pass *createLoopUnrollPass(int Threshold = -1, int Count = -1, int AllowPartial = -1); >> >> Pass *createLoopRotatePass(); >> > >> > >> > Is to call these methods the way to go? How?, can somebody show me an >> > excerpt? >> >> The create*Pass methods give you a Pass instance that you can add to a pass manager. If you're replacing "opt", you should look at the opt driver, opt.cpp to see how to do this. You can call addRequired<X> from your pass to force the PassManager to run X before your pass. >> >> If you want to do these transformations within a single pass, then the transformations need to be exposed as a utility. llvm::UnrollLoop() currently is, but LoopRotation is not. LoopRotation could be exposed as a utility (or you could copy the relevant code), but you should try not to do that. The llvm strategy is that loop rotation should do the right thing when it runs before your pass. If loop rotation needs more information to what you want it to do, then you can create a some new analysis that loop rotation requires. >> >> You may want to try browsing the online docs, such as... >> http://llvm.org/docs/WritingAnLLVMPass.html >> >> Hope that helps. >> >> -Andy