[incremental] Patch: FYI: more late gimplification clean up

Tom Tromey tromey@redhat.com
Tue Dec 4 21:10:00 GMT 2007


I'm checking this in on the incremental-compiler branch.

This is a follow-on to my last patch.  This one cleans up a couple
places where we were running passes in the front end which required
gimple input.

The first is diagnose_omp_structured_block_errors.  I just turned this
into an ordinary pass, which is run near the start of
all_lowering_passes.  I don't really understand why this couldn't be
done this way on the trunk.  But, since a lot of the test suite is not
working on my branch, perhaps the answer is waiting to be found.

The second is c_gimple_diagnostics_recursively.  Here I took a
potentially controversial route: I added a new langhook for a
post-gimplification pass.

I don't know if this is the best choice.  Please comment.
Note that this won't affect LTO, which AIUI is the primary driver
behind the "no new langhooks" direction.

The other possible choice here was to make this into a generic pass,
in its own file.  The approach I took has less code churn.  The "new
file" approach should work just as well; AFAICT the code here is
actually language-independent.

The only remaining late-gimplification problem I know of is some code
in the C++ FE.  I'm deferring that a little.

Tom

ChangeLog:
2007-12-04  Tom Tromey  <tromey@redhat.com>

	* c-decl.c (c_gimple_diagnostics_recursively): Remove.
	(finish_function): Remove comment.
	* c-common.h (c_warn_unused_result_pass): Declare.
	(c_warn_unused_result): Delete declaration.
	* c-common.c (c_warn_unused_result): Now static.
	(run_warn_unused_result): New function.
	(c_warn_unused_result_pass): New global.
	Include tree-pass.h.
	* c-objc-common.h (LANG_HOOKS_POST_GIMPLIFY_PASS): New macro.
	* langhooks-def.h (LANG_HOOKS_POST_GIMPLIFY_PASS): New macro.
	(LANG_HOOKS_INITIALIZER): Use it.
	* langhooks.h (struct lang_hooks) <post_gimplify_pass>: New
	field.
	* tree-gimple.h (diagnose_omp_structured_block_errors): Remove
	declaration.
	* omp-low.c (diagnose_omp_structured_block_errors): Change return
	type.  Make static.  Don't set current_function_decl.
	(pass_diagnose_omp_blocks): New global.
	* tree-pass.h (pass_diagnose_omp_blocks): Declare.
	* passes.c (init_optimization_passes) <all_lowering_passes>: Run
	pass_diagnose_omp_blocks, lang_hooks.post_gimplify_pass.

cp/ChangeLog:
2007-12-04  Tom Tromey  <tromey@redhat.com>

	* cp-objcp-common.h (LANG_HOOKS_POST_GIMPLIFY_PASS): New macro.
	* decl.c (finish_function): Remove comment.

fortran/ChangeLog:
2007-12-04  Tom Tromey  <tromey@redhat.com>

	* trans-decl.c (gfc_gimplify_function): Remove.
	(build_entry_thunks): Update.
	(gfc_generate_function_code): Update.

Index: tree-pass.h
===================================================================
--- tree-pass.h	(revision 130053)
+++ tree-pass.h	(working copy)
@@ -288,6 +288,7 @@
 extern struct tree_opt_pass pass_lower_vector;
 extern struct tree_opt_pass pass_lower_vector_ssa;
 extern struct tree_opt_pass pass_lower_omp;
+extern struct tree_opt_pass pass_diagnose_omp_blocks;
 extern struct tree_opt_pass pass_expand_omp;
 extern struct tree_opt_pass pass_object_sizes;
 extern struct tree_opt_pass pass_fold_builtins;
Index: omp-low.c
===================================================================
--- omp-low.c	(revision 130053)
+++ omp-low.c	(working copy)
@@ -4571,30 +4571,44 @@
   return NULL_TREE;
 }
 
-void
-diagnose_omp_structured_block_errors (tree fndecl)
+static unsigned int
+diagnose_omp_structured_block_errors (void)
 {
-  tree save_current = current_function_decl;
   struct walk_stmt_info wi;
 
-  current_function_decl = fndecl;
-
   all_labels = splay_tree_new (splay_tree_compare_pointers, 0, 0);
 
   memset (&wi, 0, sizeof (wi));
   wi.callback = diagnose_sb_1;
-  walk_stmts (&wi, &DECL_SAVED_TREE (fndecl));
+  walk_stmts (&wi, &DECL_SAVED_TREE (current_function_decl));
 
   memset (&wi, 0, sizeof (wi));
   wi.callback = diagnose_sb_2;
   wi.want_locations = true;
   wi.want_return_expr = true;
-  walk_stmts (&wi, &DECL_SAVED_TREE (fndecl));
+  walk_stmts (&wi, &DECL_SAVED_TREE (current_function_decl));
 
   splay_tree_delete (all_labels);
   all_labels = NULL;
 
-  current_function_decl = save_current;
+  return 0;
 }
 
+struct tree_opt_pass pass_diagnose_omp_blocks = 
+{
+  "diagnoseompblocks",			/* name */
+  gate_lower_omp,			/* gate */
+  diagnose_omp_structured_block_errors,	/* execute */
+  NULL,					/* sub */
+  NULL,					/* next */
+  0,					/* static_pass_number */
+  0,					/* tv_id */
+  PROP_gimple_any,			/* properties_required */
+  0,					/* properties_provided */
+  0,					/* properties_destroyed */
+  0,					/* todo_flags_start */
+  TODO_dump_func,			/* todo_flags_finish */
+  0					/* letter */
+};
+
 #include "gt-omp-low.h"
Index: tree-gimple.h
===================================================================
--- tree-gimple.h	(revision 130053)
+++ tree-gimple.h	(working copy)
@@ -135,7 +135,6 @@
 extern tree gimple_boolify (tree);
 
 /* In omp-low.c.  */
-extern void diagnose_omp_structured_block_errors (tree);
 extern tree omp_reduction_init (tree, tree);
 
 /* In tree-nested.c.  */
Index: cp/decl.c
===================================================================
--- cp/decl.c	(revision 130603)
+++ cp/decl.c	(working copy)
@@ -11627,10 +11627,6 @@
       f->x_return_value = NULL;
       f->bindings = NULL;
       f->extern_decl_map = NULL;
-
-      /* Handle attribute((warn_unused_result)).  Relies on gimple input.  */
-      /* FIXME: do this elsewhere.  */
-/*       c_warn_unused_result (&DECL_SAVED_TREE (fndecl)); */
     }
   /* Clear out the bits we don't need.  */
   local_names = NULL;
Index: cp/cp-objcp-common.h
===================================================================
--- cp/cp-objcp-common.h	(revision 130053)
+++ cp/cp-objcp-common.h	(working copy)
@@ -137,6 +137,8 @@
 #define LANG_HOOKS_TO_TARGET_CHARSET c_common_to_target_charset
 #undef LANG_HOOKS_GIMPLIFY_EXPR
 #define LANG_HOOKS_GIMPLIFY_EXPR cp_gimplify_expr
+#undef LANG_HOOKS_POST_GIMPLIFY_PASS
+#define LANG_HOOKS_POST_GIMPLIFY_PASS &c_warn_unused_result_pass
 #undef LANG_HOOKS_OMP_PREDETERMINED_SHARING
 #define LANG_HOOKS_OMP_PREDETERMINED_SHARING cxx_omp_predetermined_sharing
 #undef LANG_HOOKS_OMP_CLAUSE_DEFAULT_CTOR
Index: c-objc-common.h
===================================================================
--- c-objc-common.h	(revision 130454)
+++ c-objc-common.h	(working copy)
@@ -121,6 +121,8 @@
 /* Hooks for tree gimplification.  */
 #undef LANG_HOOKS_GIMPLIFY_EXPR
 #define LANG_HOOKS_GIMPLIFY_EXPR c_gimplify_expr
+#undef LANG_HOOKS_POST_GIMPLIFY_PASS
+#define LANG_HOOKS_POST_GIMPLIFY_PASS &c_warn_unused_result_pass
 
 #undef LANG_HOOKS_OMP_PREDETERMINED_SHARING
 #define LANG_HOOKS_OMP_PREDETERMINED_SHARING c_omp_predetermined_sharing
Index: c-decl.c
===================================================================
--- c-decl.c	(revision 130518)
+++ c-decl.c	(working copy)
@@ -6956,29 +6956,6 @@
   cfun->x_dont_save_pending_sizes_p = 1;
 }
 
-/* Emit diagnostics that require gimple input for detection.  Operate on
-   FNDECL and all its nested functions.  */
-
-#if 0
-static void
-c_gimple_diagnostics_recursively (tree fndecl)
-{
-  struct cgraph_node *cgn;
-
-  /* Handle attribute((warn_unused_result)).  Relies on gimple input.  */
-  c_warn_unused_result (&DECL_SAVED_TREE (fndecl));
-
-  /* Notice when OpenMP structured block constraints are violated.  */
-  if (flag_openmp)
-    diagnose_omp_structured_block_errors (fndecl);
-
-  /* Finalize all nested functions now.  */
-  cgn = cgraph_node (fndecl);
-  for (cgn = cgn->nested; cgn ; cgn = cgn->next_nested)
-    c_gimple_diagnostics_recursively (cgn->decl);
-}
-#endif
-
 /* Finish up a function declaration and compile that function
    all the way to assembler language output.  The free the storage
    for the function definition.
@@ -7088,8 +7065,6 @@
       if (!decl_function_context (fndecl))
 	{
 	  c_genericize (fndecl);
-	  /* FIXME: this should be a generic pass.  */
-/* 	  c_gimple_diagnostics_recursively (fndecl); */
 
 	  /* ??? Objc emits functions after finalizing the compilation unit.
 	     This should be cleaned up later and this conditional removed.  */
Index: fortran/trans-decl.c
===================================================================
--- fortran/trans-decl.c	(revision 130603)
+++ fortran/trans-decl.c	(working copy)
@@ -1536,32 +1536,6 @@
   DECL_ARGUMENTS (fndecl) = arglist;
 }
 
-/* Convert FNDECL's code to GIMPLE and handle any nested functions.  */
-
-static void
-gfc_gimplify_function (tree fndecl)
-{
-  struct cgraph_node *cgn;
-
-#if 0
-  gimplify_function_tree (fndecl);
-  dump_function (TDI_generic, fndecl);
-
-  /* Generate errors for structured block violations.  */
-  /* ??? Could be done as part of resolve_labels.  */
-  if (flag_openmp)
-    diagnose_omp_structured_block_errors (fndecl);
-#endif
-
-  /* Convert all nested functions to GIMPLE now.  We do things in this order
-     so that items like VLA sizes are expanded properly in the context of the
-     correct function.  */
-  cgn = cgraph_node (fndecl);
-  for (cgn = cgn->nested; cgn; cgn = cgn->next_nested)
-    gfc_gimplify_function (cgn->decl);
-}
-
-
 /* Do the setup necessary before generating the body of a function.  */
 
 static void
@@ -1755,7 +1729,6 @@
 
       current_function_decl = NULL_TREE;
 
-      gfc_gimplify_function (thunk_fndecl);
       cgraph_finalize_function (thunk_fndecl, false);
 
       /* We share the symbols in the formal argument list with other entry
@@ -3404,10 +3377,7 @@
        added to our parent's nested function list.  */
     (void) cgraph_node (fndecl);
   else
-    {
-      gfc_gimplify_function (fndecl);
-      cgraph_finalize_function (fndecl, false);
-    }
+    cgraph_finalize_function (fndecl, false);
 }
 
 void
Index: langhooks.h
===================================================================
--- langhooks.h	(revision 130454)
+++ langhooks.h	(working copy)
@@ -408,6 +408,10 @@
      enum gimplify_status, though we can't see that type here.  */
   int (*gimplify_expr) (tree *, tree *, tree *);
 
+  /* If non-null, a language-specific pass to be run after
+     gimplification.  */
+  struct tree_opt_pass *post_gimplify_pass;
+
   /* Fold an OBJ_TYPE_REF expression to the address of a function.
      KNOWN_TYPE carries the true type of the OBJ_TYPE_REF_OBJECT.  */
   tree (*fold_obj_type_ref) (tree, tree);
Index: c-common.c
===================================================================
--- c-common.c	(revision 130053)
+++ c-common.c	(working copy)
@@ -48,6 +48,7 @@
 #include "real.h"
 #include "cgraph.h"
 #include "target-def.h"
+#include "tree-pass.h"
 
 cpp_reader *parse_in;		/* Declared in c-pragma.h.  */
 
@@ -6433,7 +6434,7 @@
    ignored and attribute((warn_unused_result)) is set.  This is done before
    inlining, so we don't have to worry about that.  */
 
-void
+static void
 c_warn_unused_result (tree *top_p)
 {
   tree t = *top_p;
@@ -6502,6 +6503,30 @@
     }
 }
 
+static unsigned int
+run_warn_unused_result (void)
+{
+  c_warn_unused_result (&DECL_SAVED_TREE (current_function_decl));
+  return 0;
+}
+
+struct tree_opt_pass c_warn_unused_result_pass =
+{
+  "cunusedresult",			/* name */
+  NULL,					/* gate */
+  run_warn_unused_result,		/* execute */
+  NULL,					/* sub */
+  NULL,					/* next */
+  0,					/* static_pass_number */
+  0,					/* tv_id */
+  PROP_gimple_any,			/* properties_required */
+  0,					/* properties_provided */
+  0,					/* properties_destroyed */
+  0,					/* todo_flags_start */
+  TODO_dump_func,			/* todo_flags_finish */
+  0					/* letter */
+};
+
 /* Convert a character from the host to the target execution character
    set.  cpplib handles this, mostly.  */
 
Index: c-common.h
===================================================================
--- c-common.h	(revision 130454)
+++ c-common.h	(working copy)
@@ -884,8 +884,6 @@
 
 extern bool c_dump_tree (void *, tree);
 
-extern void c_warn_unused_result (tree *);
-
 extern void verify_sequence_points (tree);
 
 extern tree fold_offsetof (tree, tree);
@@ -1030,4 +1028,6 @@
 #define GCC_DIAG_STYLE __gcc_cdiag__
 #endif
 
+extern struct tree_opt_pass c_warn_unused_result_pass;
+
 #endif /* ! GCC_C_COMMON_H */
Index: passes.c
===================================================================
--- passes.c	(revision 130053)
+++ passes.c	(working copy)
@@ -477,6 +477,9 @@
     backend might produce already lowered functions that are not processed
     by these passes.  */
   p = &all_lowering_passes;
+  if (lang_hooks.post_gimplify_pass)
+    NEXT_PASS (*lang_hooks.post_gimplify_pass);
+  NEXT_PASS (pass_diagnose_omp_blocks);
   NEXT_PASS (pass_remove_useless_stmts);
   NEXT_PASS (pass_mudflap_1);
   NEXT_PASS (pass_lower_omp);
Index: langhooks-def.h
===================================================================
--- langhooks-def.h	(revision 130454)
+++ langhooks-def.h	(working copy)
@@ -160,6 +160,7 @@
 
 /* Hooks for tree gimplification.  */
 #define LANG_HOOKS_GIMPLIFY_EXPR lhd_gimplify_expr
+#define LANG_HOOKS_POST_GIMPLIFY_PASS NULL
 #define LANG_HOOKS_FOLD_OBJ_TYPE_REF NULL
 
 /* Tree dump hooks.  */
@@ -285,6 +286,7 @@
   LANG_HOOKS_DECLS, \
   LANG_HOOKS_FOR_TYPES_INITIALIZER, \
   LANG_HOOKS_GIMPLIFY_EXPR, \
+  LANG_HOOKS_POST_GIMPLIFY_PASS, \
   LANG_HOOKS_FOLD_OBJ_TYPE_REF, \
   LANG_HOOKS_BUILTIN_FUNCTION, \
   LANG_HOOKS_INIT_TS,          \



More information about the Gcc-patches mailing list