C compile time

Chris Lattner sabre@nondot.org
Wed Jun 18 19:28:00 GMT 2003


On Wed, 18 Jun 2003, Wolfgang Bangerth wrote:
> Yes, yes, I understand that :-) It's just an observation that not a whole lot
> of code is being placed into anonymous namespaces, whether it being functions
> are whole classes.

Here is an idiom widely used in the LLVM code base, for example:
http://llvm.cs.uiuc.edu/doxygen/GCSE_8cpp-source.html

Most passes in the compiler are implemented as a subclass of a "Pass"
class, which basically exposes a "run" virtual method.  Subclasses (often
living in anonymous namespaces) override this virtual function, then have
a number of private non-virtual methods (like EliminateCSE) in the example
above.  No code outside of the class should ever be able to call
EliminateCSE, yet GCC makes the symbol is made public, which is bad for
the optimizer, and probably slows down the linker as well.

Alternatively, we could implement our passes as basically empty classes,
with a bunch of static methods.  This works, but means that state has to
be passed around through arguments, which isn't as nice.  :)  An example:
http://llvm.cs.uiuc.edu/doxygen/DeadArgumentElimination_8cpp-source.html

Besides the fact that my project would benefit a lot from this, if there
is no reason to not mark the methods static, we should.  I would not be
suprised if this also comes up for important free software applications
like KDE and other large C++ apps.  The boost library also probably uses
them...

-Chris

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



More information about the Gcc mailing list