[LLVMdev] PassManager and dependencies

Chris Lattner sabre at nondot.org
Sun Oct 20 20:51:00 PDT 2002


Sorry in advance for taking so long to respond to this issue...

> I can't seem to figure out how to tell the PassManager that one Pass
> requires the results of two other Passes, in such a way that it will not
> crash itself.  Attached file is the simplest possible example of Passes

> I don't grok this error message. Of course, -opt-a and -opt-b both work
> fine in isolation.

You're right, this error message is terrible.  As it turns out, all of
your passes invalidate all of the other passes, so C doesn't get A (which
is invalidated by B).  The problem turns out to be a really trivial bug:

  virtual void getAnalysisUsage(AnalysisUsage& AU) const {
    AU.preservesAll();   // This is the accessor, not the setter
  }

which should call:
    AU.setPreservesAll();

On a different subject, I noticed that you tried to optimize out the
string overhead for the name() methods:

  virtual const string& name() const
  { static string a("B"); return a; }

instead of a simple:
  virtual const string& name() const { return "B"; }

Because you're trying to be as efficient as possible, here are a few
pointers:
  1. Static variables defined in a function or method impose quite a bit
     of overhead.  These static variables are initialized the first time
     the function is executed... which implies that every time the
     function is executed, the check must be performed.
  2. Don't optimize things that don't have to be optimized.  In general
     these methods aren't called enough, or only during debugging, so it
     is better to be clear than it is to save a few cycles.  As a general
     rule, optimize for clarity, not performance.  Often performance comes
     for free with clarity.
  3. If you REALLY want to be efficient, think about other short-cuts.  In
     this case, a constant string is always returned.  You could change
     the virtual method to always return a const char*, therefore avoiding
     a copy constructor call that may be unneccesary:

  virtual const char *name() const { return "B"; }

     ... but this obviously only works if all of the implementations ONLY
     return static strings.

Anyway, good luck with LLVM.  It's good to know that you're digging into
the pass infrastructure stuff.  I'll look into renaming the preservesAll
interface to something more obvious in the future.  :)

-Chris

http://llvm.cs.uiuc.edu/
http://www.nondot.org/~sabre/Projects/




More information about the llvm-dev mailing list