This patch breaks apart the creation of the pass manager from gcc::context's ctor. This will allow us to register additional dumps between the dumpfile manager creation and the pass manager. As I described in https://gcc.gnu.org/ml/gcc-patches/2017-05/msg01164.html when I tried to do this for the language-specific dumps, the existing LANG_HOOKS_INIT_OPTIONS ran too late, and I had to create a new hook and call it from gcc::context's constructor to get it done before the passes were created. That's ugly. Calling the hook from toplev seems better.

Also, I noticed that we were passing a pointer to the not-yet-fully-constructed context to the pass manager, which smells funny.

ok?

nathan
--
Nathan Sidwell
2017-05-16  Nathan Sidwell  <nat...@acm.org>

	* context.h (context::set_passes): New.
	* context.c (context::context): Do not create pass manager.
	* toplev.c (general_init): Create pass manager here.

Index: context.c
===================================================================
--- context.c	(revision 248110)
+++ context.c	(working copy)
@@ -29,14 +29,9 @@ along with GCC; see the file COPYING3.
 gcc::context *g;
 
 gcc::context::context ()
+  : m_passes (NULL), m_dumps (new gcc::dump_manager ())
 {
   have_offload = false;
-
-  /* The pass manager's constructor uses the dump manager (to set up
-     dumps for the various passes), so the dump manager must be set up
-     before the pass manager.  */
-  m_dumps = new gcc::dump_manager ();
-  m_passes = new gcc::pass_manager (this);
 }
 
 gcc::context::~context ()
Index: context.h
===================================================================
--- context.h	(revision 248110)
+++ context.h	(working copy)
@@ -39,6 +39,12 @@ public:
 
   /* Pass-management.  */
 
+  void set_passes (pass_manager *m)
+  {
+    gcc_assert (!m_passes);
+    m_passes = m;
+  }
+
   pass_manager *get_passes () { gcc_assert (m_passes); return m_passes; }
 
   /* Handling dump files.  */
Index: toplev.c
===================================================================
--- toplev.c	(revision 248110)
+++ toplev.c	(working copy)
@@ -1154,9 +1154,13 @@ general_init (const char *argv0, bool in
      processing.  */
   init_ggc_heuristics ();
 
-  /* Create the singleton holder for global state.
-     Doing so also creates the pass manager and with it the passes.  */
+  /* Create the singleton holder for global state.  This creates the
+     dump manager.  */
   g = new gcc::context ();
+
+  /* Create the passes.  */
+  g->set_passes (new gcc::pass_manager (g));
+
   symtab = new (ggc_cleared_alloc <symbol_table> ()) symbol_table ();
 
   statistics_early_init ();

Reply via email to