LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 36 - PassManager enhancements
Summary: PassManager enhancements
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Core LLVM classes (show other bugs)
Version: trunk
Hardware: PC Linux
: P enhancement
Assignee: Devang Patel
URL:
Keywords: new-feature
: 252 (view as bug list)
Depends on:
Blocks: 51
  Show dependency tree
 
Reported: 2003-10-13 12:11 PDT by Chris Lattner
Modified: 2010-02-22 12:52 PST (History)
4 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Lattner 2003-10-13 12:11:46 PDT
The following are my notes on PassManager V2.  Note that the sum effect of these
improvements is basically a complete rewrite of the pass manager.

1. There should be an explicit ModulePass class.  The "Pass" class should
   be abstract.

2. The pass manager should be extended to support callgraph SCC passes
   and Loop passes.  The structural hierarchy of passes should be:

  ModulePass
    CallGraphSCCPass
      FunctionPass
        LoopPass
          BasicBlockPass

3. Instead of the structural hierarchy being reflected directly in
   the C++ class hierarchy, the various Pass subclasses should be
   derived like this:

  Pass
    ModulePass
    CallGraphSCCPass
    FunctionPass
    LoopPass
    BasicBlockPass

4. The current implementation of the PassManager in PassManagerT.h is really
   ugly and should be rewritten.

5. There needs to be a way to indicate that a pass needs to extend the
   lifetime of a pass it uses.  For example, the alias analyses all chain to
   simpler implementation of alias analysis.  For this reason, the simpler
   alias analyses should not be destroyed until the more complex ones are.

6. Implement support for ModulePasses that require FunctionPasses.
Comment 1 Chris Lattner 2003-10-20 14:36:20 PDT
With the above in place, we should also be able to have a "MTModulePass" class,
used for implementing thread-aware module passes.  It should have the following
interface:

1. MTModulePass derives from ModulePass 
2. The "run" method should (on a thread enabled platform) spawn some number
   of threads (probably equal to the number of processors), each of which
   invoke the "runThread" abstract method.
3. Thread aware classes thus implement the runThread method, and use
   synchronization primitives to avoid having the threads step on each other's
   toes.  This is what makes the pass "thread aware".

Note that function passes are already implicitly threaded, multiple function
passes can be run in parallel on different functions at the same time.

Comment 2 Chris Lattner 2003-10-20 14:38:59 PDT
Note that for any of the multithreading improvements to happen, the LLVM VMCore
needs to have locks put into certain places.  For example, updating use_list's
must be atomic, because multiple functions can add/remove uses to global
objects.  There needs to be a clear separation between what a thread (and
implicitly a function pass) is allowed to do to global objects, and what they
are not.

In order to be useful, these rules must be extremely simple.
Comment 3 Chris Lattner 2004-02-25 23:09:43 PST
*** Bug 252 has been marked as a duplicate of this bug. ***
Comment 4 Chris Lattner 2004-02-26 15:29:51 PST
Changing all of these bugs who do not have people looking at them to be assigned
to "unassignedbugs", indicating that if someone is feeling ambitious, they can
take ownership of the bug.

If I stole your bug, and you still want it, feel free to take ownership back.

-Chris
Comment 5 Chris Lattner 2004-07-20 23:43:40 PDT
Another serious problem with the current pass manager: it implicitly assumes
that all FunctionPass's preserve all "ModulePass"'s.  This is a big problem if
your module pass is something like an alias analysis, which is very easy to
invalidate. 
Consider three passes A, B, C, where A is a analysis ModulePass and B/C are
FunctionPass's.  Currently the pass manager batches these up like this
(pipelining B and C together to be run on each function):

A
  B
  C

Causing it to run ABCBCBCBC. Instead it should batch them like this:

A
  B
.
  C

Causing it to run ABBBBCCCC.

-Chris
Comment 6 Chris Lattner 2004-09-19 23:50:21 PDT
> 1. There should be an explicit ModulePass class.  The "Pass" class should
>    be abstract.

This has now been implemented.

-Chris
Comment 7 Chris Lattner 2006-01-09 13:53:57 PST
Comment #5 doesn't make sense.  This is what I was trying to get at:


Another serious problem with the current pass manager: it implicitly assumes
that all FunctionPass's preserve all "ModulePass"'s.  This is a big problem if
your module pass is something like an alias analysis, which is very easy to
invalidate. 

Consider three passes A, B, C, where A is an analysis ModulePass and B/C are
FunctionPass's.  Currently the pass manager batches these up like this
(pipelining B and C together to be run on each function):

A
  B
  C

Causing it to run ABCBCBCBC.  If B invalidates A, the pass manager doesn't know this (it assumes that 
functionpasses always preserve module passes), C will use the invalidated version of A.

Instead it should batch them like this:

.
  B
A
  C

Causing it to run BBBBACCCC.

Note that the pass manager currently generates the ordering above regardless of whether the passes 
are added as "ABC" "BAC" or "BC" where C requires A.

-Chris
Comment 8 Reid Spencer 2006-01-09 14:01:16 PST
Would it be too complex to have each pass declare what kinds of things they
invalidate and have the PassManager find the optimal execution order based on
that information? That way the PassManager doesn't have to make assumptions. It
just looks at each pass and orders them according to the kinds of things they
invalidate.  I haven't thought much about this, just asking a question. Seems it
could lead to conflicting or cyclical dependencies.
Comment 9 Chris Lattner 2006-01-09 14:07:19 PST
The pass manager has that info.  It 'making assumptions' is a bug.

-Chris
Comment 10 Chris Lattner 2006-01-10 02:02:30 PST
some thoughts:
http://lists.cs.uiuc.edu/pipermail/llvmdev/2006-January/005137.html
Comment 11 Devang Patel 2007-01-25 18:46:07 PST
>> 4. The current implementation of the PassManager in PassManagerT.h is really
>>   ugly and should be rewritten.

Done!
Comment 12 Devang Patel 2007-01-25 18:49:46 PST
>>. Instead of the structural hierarchy being reflected directly in
>>   the C++ class hierarchy, the various Pass subclasses should be
>>  derived like this:
>>
>>  Pass
>>    ModulePass
>>    CallGraphSCCPass
>>    FunctionPass
>>    LoopPass
>>   BasicBlockPass

Done! 

Comment 13 Reid Spencer 2007-04-13 23:36:08 PDT
Is this done? If not, can someone summarize what is left to do? It is hard to
reconstruct the remaining work from all the comment entries. Thanks.
Comment 14 Devang Patel 2007-04-15 14:26:34 PDT
Item #6 is not yet done. 
Comment 16 Chris Lattner 2007-04-16 16:16:44 PDT
Anything left? :)
Comment 17 Devang Patel 2007-04-16 16:23:40 PDT
item #5 ?
Comment 18 Chris Lattner 2007-04-16 16:27:26 PDT
Isn't #5 "transitively requiring passes"?
Comment 19 Devang Patel 2007-04-16 16:33:06 PDT
it is.