[LLVMdev] Controlling the order of a FunctionPass

Nick Lewycky nicholas at mxc.ca
Fri Jul 23 21:26:53 PDT 2010


John Criswell wrote:
> Trevor Harmon wrote:
>> On Jul 22, 2010, at 2:05 PM, John Criswell wrote:
>>
>>
>>> If you write your pass as a ModulePass, then you can iterate over the
>>> functions in any order that you want.
>>>
>>
>> I had considered that, but my FunctionPass depends on other passes
>> processing the functions first:
>>
>
> Two things to consider:
>
> 1) The PassManager isn't currently designed to schedule prerequisite
> *transform* passes (like UnifyFunctionExitNodes).  If your pass requires
> that another transform pass be executed first, then the PassManager must
> be explicitly told (via the PassManager.add() method) to run that pass
> first.  If you're running your pass via the opt tool, then it means that
> the user must manually specify the prerequisite passes in the correct
> order (e.g., opt -load<your pass filename>  -mergereturn -<your pass
> name>).  If you're building a separate program that schedules the
> passes, then it needs to run the prerequisite passes first.

What?? Sure it does. See all the passes which require BreakCritEdges or 
LCSSA for examples.

>
> See the sc tool in the SAFECode source code for an example.
>
> 2) For prerequisite *analysis* passes (like LoopInfo), your ModulePass
> can declare them as prerequisites and get access to them using the
> getAnalysis<PassName>(Function *) method.  This is documented in the
> "Writing an LLVM Pass" manual
> (http://llvm.org/docs/WritingAnLLVMPass.html#getAnalysis).
>
> -- John T.
>
>> void MyPass::getAnalysisUsage(AnalysisUsage&AU) const {
>>       AU.addRequired<UnifyFunctionExitNodes>();
>>       AU.addRequired<LoopInfo>();
>>       AU.addPreserved<LoopInfo>();
>> }
>>
>> bool MyPass::runOnFunction(Function&function) {
>>       LoopInfo&loopInfo = getAnalysis<LoopInfo>();
>>       ...
>> }
>>
>> I don't know how to convert the above code into its equivalent form
>> for a ModulePass.
>>
>> Trevor
>>
>>
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>




More information about the llvm-dev mailing list