This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

One more langhook


This makes lang_unsave a langhook, and removes the unused hook
lang_unsave_expr_now, making the code a little clearer IMO.

Bootstrapped all except Ada without regressions.  OK to commit?

Neil.

	* expr.c (expand_expr): Use unsave lang hook.
	* langhooks-def.h (LANG_HOOKS_UNSAVE): New.
	(LANG_HOOKS_INITIALIZER): Update.
	* langhooks.h (struct lang_hooks): New hook unsave.
	* tree.c (lang_unsave, lang_unsave_expr_now): Remove.
	(unsave_expr_1): Remove unused lang_unsave_expr_now.
	(unsave_expr_now_r): Rename lhd_unsave.  Update. Return input.
	(unsave_expr_now): Remove.
	* tree.h (unsave_expr_now, lang_unsave,
	lang_unsave_expr_now): Remove.
	(lhd_unsave): New.
cp:
	* cp-lang.c (LANG_HOOKS_UNSAVE): Redefine.
	* cp-tree.h (cxx_unsave): New.
	* tree.c (cp_unsave): Rename cxx_unsave, update prototype.
	(init_tree): Update.

============================================================
Index: gcc/expr.c
--- gcc/expr.c	2002/03/01 01:19:48	1.425
+++ gcc/expr.c	2002/03/03 13:32:24
@@ -6441,7 +6441,7 @@ expand_expr (exp, target, tmode, modifie
       {
 	rtx temp;
 	temp = expand_expr (TREE_OPERAND (exp, 0), target, tmode, modifier);
-	TREE_OPERAND (exp, 0) = unsave_expr_now (TREE_OPERAND (exp, 0));
+	TREE_OPERAND (exp, 0) = (*lang_hooks.unsave) (TREE_OPERAND (exp, 0));
 	return temp;
       }
 
============================================================
Index: gcc/langhooks-def.h
--- gcc/langhooks-def.h	2002/02/28 07:39:24	1.9
+++ gcc/langhooks-def.h	2002/03/03 13:32:24
@@ -77,6 +77,7 @@ void lhd_tree_inlining_end_inlining		PAR
 #define LANG_HOOKS_SAFE_FROM_P		lhd_safe_from_p
 #define LANG_HOOKS_STATICP		lhd_staticp
 #define LANG_HOOKS_DUP_LANG_SPECIFIC_DECL lhd_do_nothing_t
+#define LANG_HOOKS_UNSAVE		lhd_unsave
 #define LANG_HOOKS_HONOR_READONLY	false
 #define LANG_HOOKS_PRINT_STATISTICS	lhd_do_nothing
 #define LANG_HOOKS_PRINT_XNODE		lhd_print_tree_nothing
@@ -146,6 +147,7 @@ int lhd_tree_dump_type_quals			PARAMS ((
   LANG_HOOKS_SAFE_FROM_P, \
   LANG_HOOKS_STATICP, \
   LANG_HOOKS_DUP_LANG_SPECIFIC_DECL, \
+  LANG_HOOKS_UNSAVE, \
   LANG_HOOKS_HONOR_READONLY, \
   LANG_HOOKS_PRINT_STATISTICS, \
   LANG_HOOKS_PRINT_XNODE, \
============================================================
Index: gcc/langhooks.h
--- gcc/langhooks.h	2002/02/28 07:39:24	1.16
+++ gcc/langhooks.h	2002/03/03 13:32:24
@@ -132,6 +132,11 @@ struct lang_hooks
      DECL_NODE with a newly GC-allocated copy.  */
   void (*dup_lang_specific_decl) PARAMS ((tree));
 
+  /* UNSAVE is called before its argument, an UNSAVE_EXPR, is to be
+     unsaved.  Modify it in-place so that all the evaluate only once
+     things are cleared out.  */
+  tree (*unsave) PARAMS ((tree));
+
   /* Nonzero if TYPE_READONLY and TREE_READONLY should always be honored.  */
   bool honor_readonly;
 
============================================================
Index: gcc/tree.c
--- gcc/tree.c	2002/03/02 03:52:16	1.242
+++ gcc/tree.c	2002/03/03 13:32:34
@@ -52,8 +52,6 @@ Software Foundation, 59 Temple Place - S
 /* obstack.[ch] explicitly declined to prototype this.  */
 extern int _obstack_allocated_p PARAMS ((struct obstack *h, PTR obj));
 
-static void unsave_expr_now_r PARAMS ((tree));
-
 /* Objects allocated on this obstack last forever.  */
 
 struct obstack permanent_obstack;
@@ -168,14 +166,6 @@ static void type_hash_mark PARAMS ((cons
 static int mark_tree_hashtable_entry PARAMS((void **, void *));
 
 /* If non-null, these are language-specific helper functions for
-   unsave_expr_now.  If present, LANG_UNSAVE is called before its
-   argument (an UNSAVE_EXPR) is to be unsaved, and all other
-   processing in unsave_expr_now is aborted.  LANG_UNSAVE_EXPR_NOW is
-   called from unsave_expr_1 for language-specific tree codes.  */
-void (*lang_unsave) PARAMS ((tree *));
-void (*lang_unsave_expr_now) PARAMS ((tree));
-
-/* If non-null, these are language-specific helper functions for
    unsafe_for_reeval.  Return negative to not handle some tree.  */
 int (*lang_unsafe_for_reeval) PARAMS ((tree));
 
@@ -1708,23 +1698,21 @@ unsave_expr_1 (expr)
       break;
 
     default:
-      if (lang_unsave_expr_now != 0)
-	(*lang_unsave_expr_now) (expr);
       break;
     }
 }
 
-/* Helper function for unsave_expr_now.  */
+/* Default lang hook for "unsave".  */
 
-static void
-unsave_expr_now_r (expr)
+tree
+lhd_unsave (expr)
      tree expr;
 {
   enum tree_code code;
 
   /* There's nothing to do for NULL_TREE.  */
   if (expr == 0)
-    return;
+    return expr;
 
   unsave_expr_1 (expr);
 
@@ -1740,8 +1728,8 @@ unsave_expr_now_r (expr)
     case 'x':  /* miscellaneous: e.g., identifier, TREE_LIST or ERROR_MARK.  */
       if (code == TREE_LIST)
 	{
-	  unsave_expr_now_r (TREE_VALUE (expr));
-	  unsave_expr_now_r (TREE_CHAIN (expr));
+	  lhd_unsave (TREE_VALUE (expr));
+	  lhd_unsave (TREE_CHAIN (expr));
 	}
       break;
 
@@ -1755,26 +1743,13 @@ unsave_expr_now_r (expr)
 	int i;
 
 	for (i = first_rtl_op (code) - 1; i >= 0; i--)
-	  unsave_expr_now_r (TREE_OPERAND (expr, i));
+	  lhd_unsave (TREE_OPERAND (expr, i));
       }
       break;
 
     default:
       abort ();
     }
-}
-
-/* Modify a tree in place so that all the evaluate only once things
-   are cleared out.  Return the EXPR given.  */
-
-tree
-unsave_expr_now (expr)
-     tree expr;
-{
-  if (lang_unsave!= 0)
-    (*lang_unsave) (&expr);
-  else
-    unsave_expr_now_r (expr);
 
   return expr;
 }
============================================================
Index: gcc/tree.h
--- gcc/tree.h	2002/03/02 03:52:16	1.312
+++ gcc/tree.h	2002/03/03 13:32:44
@@ -2550,18 +2550,6 @@ extern tree unsave_expr			PARAMS ((tree)
 
 extern void unsave_expr_1               PARAMS ((tree));
 
-/* Like unsave_expr_1, but recurses into all subtrees.  */
-
-extern tree unsave_expr_now		PARAMS ((tree));
-
-/* If non-null, these are language-specific helper functions for
-   unsave_expr_now.  If present, LANG_UNSAVE is called before its
-   argument (an UNSAVE_EXPR) is to be unsaved, and all other
-   processing in unsave_expr_now is aborted.  LANG_UNSAVE_EXPR_NOW is
-   called from unsave_expr_1 for language-specific tree codes.  */
-extern void (*lang_unsave)              PARAMS ((tree *));
-extern void (*lang_unsave_expr_now)     PARAMS ((tree));
-
 /* Return 0 if it is safe to evaluate EXPR multiple times,
    return 1 if it is safe if EXPR is unsaved afterward, or
    return 2 if it is completely unsafe.  */
@@ -2756,6 +2744,8 @@ extern tree get_set_constructor_bytes		P
 extern tree get_callee_fndecl                   PARAMS ((tree));
 extern void set_decl_assembler_name             PARAMS ((tree));
 extern int type_num_arguments                   PARAMS ((tree));
+extern tree lhd_unsave				PARAMS ((tree));
+
 
 /* In stmt.c */
 
============================================================
Index: gcc/cp/cp-lang.c
--- gcc/cp/cp-lang.c	2002/02/28 07:39:37	1.10
+++ gcc/cp/cp-lang.c	2002/03/03 13:32:44
@@ -52,6 +52,8 @@ static HOST_WIDE_INT cxx_get_alias_set P
 #define LANG_HOOKS_SAFE_FROM_P c_safe_from_p
 #undef LANG_HOOKS_DUP_LANG_SPECIFIC_DECL
 #define LANG_HOOKS_DUP_LANG_SPECIFIC_DECL cxx_dup_lang_specific_decl
+#undef LANG_HOOKS_UNSAVE
+#define LANG_HOOKS_UNSAVE cxx_unsave
 #undef LANG_HOOKS_PRINT_STATISTICS
 #define LANG_HOOKS_PRINT_STATISTICS cxx_print_statistics
 #undef LANG_HOOKS_PRINT_XNODE
============================================================
Index: gcc/cp/cp-tree.h
--- gcc/cp/cp-tree.h	2002/03/01 07:19:29	1.683
+++ gcc/cp/cp-tree.h	2002/03/03 13:32:57
@@ -4222,6 +4222,7 @@ extern void replace_defarg			PARAMS ((tr
 extern void end_input				PARAMS ((void));
 
 /* in tree.c */
+extern tree cxx_unsave				PARAMS ((tree));
 extern void init_tree			        PARAMS ((void));
 extern int pod_type_p				PARAMS ((tree));
 extern tree canonical_type_variant              PARAMS ((tree));
============================================================
Index: gcc/cp/tree.c
--- gcc/cp/tree.c	2002/03/01 01:48:58	1.269
+++ gcc/cp/tree.c	2002/03/03 13:33:01
@@ -44,7 +44,6 @@ static tree no_linkage_helper PARAMS ((t
 static tree build_srcloc PARAMS ((const char *, int));
 static tree mark_local_for_remap_r PARAMS ((tree *, int *, void *));
 static tree cp_unsave_r PARAMS ((tree *, int *, void *));
-static void cp_unsave PARAMS ((tree *));
 static tree build_target_expr PARAMS ((tree, tree));
 static tree count_trees_r PARAMS ((tree *, int *, void *));
 static tree verify_stmt_tree_r PARAMS ((tree *, int *, void *));
@@ -2297,7 +2296,6 @@ void
 init_tree ()
 {
   make_lang_type_fn = cp_make_lang_type;
-  lang_unsave = cp_unsave;
   lang_statement_code_p = cp_statement_code_p;
   lang_set_decl_assembler_name = mangle_decl;
   list_hash_table = htab_create (31, list_hash, list_hash_eq, NULL);
@@ -2389,12 +2387,11 @@ cp_unsave_r (tp, walk_subtrees, data)
   return NULL_TREE;
 }
 
-/* Called by unsave_expr_now whenever an expression (*TP) needs to be
-   unsaved.  */
+/* Called whenever an expression needs to be unsaved.  */
 
-static void
-cp_unsave (tp)
-     tree *tp;
+tree
+cxx_unsave (tp)
+     tree tp;
 {
   splay_tree st;
 
@@ -2403,13 +2400,15 @@ cp_unsave (tp)
   st = splay_tree_new (splay_tree_compare_pointers, NULL, NULL);
 
   /* Walk the tree once figuring out what needs to be remapped.  */
-  walk_tree (tp, mark_local_for_remap_r, st, NULL);
+  walk_tree (&tp, mark_local_for_remap_r, st, NULL);
 
   /* Walk the tree again, copying, remapping, and unsaving.  */
-  walk_tree (tp, cp_unsave_r, st, NULL);
+  walk_tree (&tp, cp_unsave_r, st, NULL);
 
   /* Clean up.  */
   splay_tree_delete (st);
+
+  return tp;
 }
 
 /* Returns the kind of special function that DECL (a FUNCTION_DECL)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]