I am trying to write a ModulePass which requires PostDominator sets for every function in the module. Now finding post dominators is a function pass. The link on the llvm.org website says that : "Currently it is illegal for a ModulePass<http://llvm.org/docs/WritingAnLLVMPass.html#ModulePass>to require a FunctionPass <http://llvm.org/docs/WritingAnLLVMPass.html#FunctionPass>. This is because there is only one instance of the FunctionPass<http://llvm.org/docs/WritingAnLLVMPass.html#FunctionPass>object ever created, thus nowhere to store information for all of the functions in the program at the same time. Although this has come up a couple of times before, this has always been worked around by factoring one big complicated pass into a global and an interprocedural part, both of which are distinct. In the future, it would be nice to have this though." This says that we can work around by factoring the code into a global and interprocedural part. If so, is our global pass a Module pass ? And then, how do the global and inter-procedural passes interact ? Is there a specific example where this has been done before ? Thanks, -Balpreet -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20060501/ca8cb622/attachment.html>
On May 1, 2006, at 1:00 PM, Balpreet Pankaj wrote:> I am trying to write a ModulePass which requires PostDominator sets > for every function in the module. Now finding post dominators is a > function pass. The link on the llvm.org website says that : > > "Currently it is illegal for a ModulePass to require a > FunctionPass. This is because there is only one instance of the > FunctionPass object ever created, thus nowhere to store information > for all of the functions in the program at the same time. Although > this has come up a couple of times before, this has always been > worked around by factoring one big complicated pass into a global > and an interprocedural part, both of which are distinct. In the > future, it would be nice to have this though." > > This says that we can work around by factoring the code into a > global and interprocedural part. If so, is our global pass a Module > pass ? And then, how do the global and inter-procedural passes > interact ? Is there a specific example where this has been done > before ? >Ahhh, you must remember the terribly confusing terminology. Global means function level. This is sort of like doing an iterative data flow where you have a part that computes local basic block analyses, and then the global part merges those analyses at exits and entries to blocks. Now you are going to do something on a function level, store it to data structures of some sort and use a ModulePass to merge at calls. The only problem I see is this is still an issue of a Module Pass Requiring a FunctionPass, so you are going to have to declare some sort of structure like a std::vector of whatever analysis structure you need, and "push a new one on" in the beginning of run on Function. A hash_map from Function* to analysis information might be better however. Actually, if you want to get this working really fast it might be better to just edit PostDominator set to have a map of PostDominatorSets, and make it a ModulePass.> Thanks, > -Balpreet > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20060501/509fbf0f/attachment.html>
Robert L. Bocchino Jr.
2006-May-01 20:32 UTC
[LLVMdev] ModulePasses requiring FunctionPasses
> I am trying to write a ModulePass which requires PostDominator sets > for every function in the module. Now finding post dominators is a > function pass.In the past, I have done this by making the requiring pass a FunctionPass instead of a ModulePass. If you look in include/llvm/ Pass.h, you'll see that a FunctionPass is just a ModulePass in which (1) a "doInitialization" method is called; (2) a "runOnFunction" method is called for each function in the module; and (3) a "doFinalization" method is called. The doInitialization and doFinalization methods both take a Module as an argument, so any interprocedural code can go there. If you create a data structure to store the results of the runOnFunction methods as they are called and put your interprocedural code in the "doFinalization" method, you can write a FunctionPass that requires another FunctionPass and does interprocedural analysis. This is a little ugly, but it works. If there's a better way, I'd certainly like to know about it. :^)> This says that we can work around by factoring the code into a > global and interprocedural part. If so, is our global pass a Module > pass ? And then, how do the global and inter-procedural passes > interact ? Is there a specific example where this has been done > before ?I have an example that I can give you offline. Rob Robert L. Bocchino Jr. Ph.D. Student University of Illinois, Urbana-Champaign -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20060501/853fd0f5/attachment.html>
On Mon, 1 May 2006, Balpreet Pankaj wrote:> I am trying to write a ModulePass which requires PostDominator sets for > every function in the module. Now finding post dominators is a function > pass. The link on the llvm.org website says that : > "Currently it is illegal for a > ModulePass<http://llvm.org/docs/WritingAnLLVMPass.html#ModulePass>to > require a > FunctionPass <http://llvm.org/docs/WritingAnLLVMPass.html#FunctionPass>.Yup :(> This says that we can work around by factoring the code into a global and > interprocedural part. If so, is our global pass a Module pass ? And then, > how do the global and inter-procedural passes interact ? Is there a specific > example where this has been done before ?I don't know of any specific examples in the source code. :( -Chris -- http://nondot.org/sabre/ http://llvm.org/
Seemingly Similar Threads
- [LLVMdev] FunctionPass Analysis is not saved after ModulePasses run?
- [LLVMdev] modulepass requiring a functionpass
- [LLVMdev] Requiring a ModulePass to be run from a FunctionPass
- [LLVMdev] ModulePass that requires FunctionPass
- [LLVMdev] about writing a functionpass requiring a modulepass