[LLVMdev] Do all user-written passes have to be run through a PassManager object (called from outside the LLVM infrastructure)?

John Criswell criswell at illinois.edu
Thu Jan 16 18:59:12 PST 2014

On 1/16/14 6:21 PM, Gai, Jiading wrote:
> Thanks John. Out of curiosity,  I wonder if it's possible to summarize the LLVMpass-specific design patterns. I.e., the software engineering techniques that were used to design/implement the LLVM Pass Infrastructure. Equivalently, this may also answer the question "Why is the code this way". This visibility can improve understanding and that is likely to improve quality as more developers are better informed.

I'm probably not the best person to answer this, but at a high level, 
the Pass Infrastructure does two things:

1) It helps people follow the "Separation of Concerns" principle of 
compiler writing by making it easy to plug in new transforms into the 
LLVM copiler.

2) It helps optimize the running of analysis passes.

Separation of Concerns means that instead of writing one big piece of 
code to optimize a program, we write small transforms, run one after 
another, that perform simple transforms.  For example, we have one pass 
that does constant propagation and another pass that removes dead code.  
Adding a new optimization simply requires that one write a new pass and 
plug it into the chain of optimizations passes being run by a PassManager.

The LLVM PassManager is designed to avoid re-running analysis passes 
that simply gather information about the program for other passes. For 
example, multiple optimizations use dominance information which can be 
expensive to compute.  Some passes transform the code in a way that 
requires that any existing dominance analysis be redone; other passes 
transform the code in a way that allows existing dominance analysis to 
be reused by later optimization passes.  By knowing which passes use 
dominance information and which passes do not modify dominance 
information, the PassManager can avoid running the dominance analysis 
pass more times than necessary.

Hope that helps a little.

-- John T.

> ________________________________________
> From: Criswell, John T
> Sent: Thursday, January 16, 2014 1:29 PM
> To: Gai, Jiading; llvmdev at cs.uiuc.edu
> Subject: Re: [LLVMdev] Do all user-written passes have to be run through a PassManager object (called from outside the LLVM infrastructure)?
> On 1/16/14 11:44 AM, Gai, Jiading wrote:
>> I have written several passes that have no pre-requisites for any
>> previous LLVM native passes prior to my own. For those passes, I have verified that at
>> least the following two approaches are equivalent in terms of executing
>> those self-written passes and getting the correct results:
> I don't know if you *must* run all passes via a PassManager, but I think
> you should.  That's how passes are designed to work, and running them
> through a PassManager provides some future-proofing benefits (e.g., if
> you add a prerequisite analysis pass to one of your passes, it will
> "just work").
> -- John T.

More information about the llvm-dev mailing list