The following pair of patches is aimed at eliminating global variables from gcc's internals, as per my Cauldron talk on state-removal [1]
Patch 1 introduces a gcc::context class, along with a singleton instance. The name of the instance is chosen so as to be easy to type in the debugger: gcc::context *g; [FWIW you can see an example of a debugging session in: http://gcc.gnu.org/ml/gcc-patches/2013-07/msg01028.html ] My aim is that this pointer will eventually be the only global variable in GCC - so you can think of "g" as standing for either "the global", "gcc" or "gnu" as you prefer :) If we want to support embedding gcc as a shared library, in that configuration "g" would become a thread-local variable. In patch 1, the context class is merely an empty stub. Patch 2 introduces a gcc::pipeline class and moves various non-GTY globals relating to pass management into it. The gcc::context gains its first field: a pointer to the gcc::pipeline instance, and init_optimization_passes becomes the ctor for gcc::pipeline, so that as much as possible can be private. I've successfully bootstrapped the *combination* of patches on x86_64-unknown-linux-gnu: all testcases show the same results as an unpatched build (relative to r201148); I've split them up conceptually in the hope of making review easier. OK for trunk? [I have a series of followup patches which move the passes themselves into this system, integrating it all with ggc and pch, so that pass instances can own GC references, at which point *lots* of modularization of globals becomes possible. However I'm still tracking down the last few testsuite failures with that part - I'll post those patches when I've got it fully working] Thanks Dave [1] http://gcc.gnu.org/wiki/cauldron2013?action=AttachFile&do=view&target=removing-global-state-from-gcc.txt (the class was named "universe" in my Cauldron talk, but I now prefer "gcc::context"). David Malcolm (2): Introduce context class Introduce beginnings of a pipeline class. gcc/Makefile.in | 19 +++++++--- gcc/cgraphunit.c | 22 +++++++----- gcc/context.c | 33 ++++++++++++++++++ gcc/context.h | 51 +++++++++++++++++++++++++++ gcc/lto-cgraph.c | 7 ++-- gcc/lto/Make-lang.in | 3 +- gcc/lto/lto.c | 4 ++- gcc/passes.c | 97 +++++++++++++++++++++++++++++++++++----------------- gcc/pipeline.h | 89 +++++++++++++++++++++++++++++++++++++++++++++++ gcc/statistics.c | 7 ++-- gcc/toplev.c | 7 +++- gcc/tree-pass.h | 29 ---------------- 12 files changed, 288 insertions(+), 80 deletions(-) create mode 100644 gcc/context.c create mode 100644 gcc/context.h create mode 100644 gcc/pipeline.h -- 1.7.11.7