[LLVMdev] ModulePasses requiring FunctionPasses

Robert L. Bocchino Jr. bocchino at uiuc.edu
Mon May 1 13:32:20 PDT 2006

> 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.


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>

More information about the llvm-dev mailing list