PATCH: removes expand_constant language hook

Ollie Wild aaw@google.com
Wed Mar 28 07:00:00 GMT 2007


> Looks like I've got some more work to do.

Here's an updated patch which handles recursion in the initializer.
The assembly generated with this patch is nearly identical to that
generated without it.  However, 0 offsets are now initialized in the
bss section rather than the data section.  Hopefully, no one has a
problem with that.

Ollie

:ADDPATCH c++:

2007-03-26  Ollie Wild  <aaw@google.com>

     * varasm.c (compare_constant): Removed call to
     lang_hooks.expand_constant.
     (copy_constants): Removed call to lang_hooks.expand_constant.
     (compute_reloc_for_constant): Removed call to
     lang_hooks.expand_constant.
     (output_addressed_constants): Removed call to
     lang_hooks.expand_constant.
     (constructor_static_from_elts_p): Removed call to
     lang_hooks.expand_constant.
     (output_constant): Removed calls to lang_hooks.expand_constant.
     * langhooks.h (struct lang_hooks): Removed field expand_constant.
     * langhooks-def.h (lhd_return_tree): Removed.
     (LANG_HOOKS_EXPAND_CONSTANT): Removed.
     (LANG_HOOKS_INITIALIZER): Removed LANG_HOOKS_EXPAND_CONSTANT.
     * langhooks.c (lhd_return_tree): Removed.

2007-03-26  Ollie Wild  <aaw@google.com>

     * typeck2.c (digest_init): Call cplus_expand_constant after
     convert_for_initialization.
     * cp-objcp-common.h (LANG_HOOKS_EXPAND_CONSTANT): Removed.
     * expr.c (cplus_expand_constant): Updated function description.
-------------- next part --------------
Index: gcc/cp/cp-objcp-common.h
===================================================================
--- gcc/cp/cp-objcp-common.h	(revision 123066)
+++ gcc/cp/cp-objcp-common.h	(working copy)
@@ -51,8 +51,6 @@ extern tree objcp_tsubst_copy_and_build 
 #define LANG_HOOKS_POST_OPTIONS c_common_post_options
 #undef LANG_HOOKS_GET_ALIAS_SET
 #define LANG_HOOKS_GET_ALIAS_SET cxx_get_alias_set
-#undef LANG_HOOKS_EXPAND_CONSTANT
-#define LANG_HOOKS_EXPAND_CONSTANT cplus_expand_constant
 #undef LANG_HOOKS_EXPAND_EXPR
 #define LANG_HOOKS_EXPAND_EXPR cxx_expand_expr
 #undef LANG_HOOKS_EXPAND_DECL
Index: gcc/cp/expr.c
===================================================================
--- gcc/cp/expr.c	(revision 123066)
+++ gcc/cp/expr.c	(working copy)
@@ -34,8 +34,7 @@ Boston, MA 02110-1301, USA.  */
 #include "except.h"
 #include "tm_p.h"
 
-/* Hook used by output_constant to expand language-specific
-   constants.  */
+/* Expand C++-specific constants.  Currently, this means PTRMEM_CST.  */
 
 tree
 cplus_expand_constant (tree cst)
Index: gcc/cp/typeck2.c
===================================================================
--- gcc/cp/typeck2.c	(revision 123066)
+++ gcc/cp/typeck2.c	(working copy)
@@ -703,8 +703,23 @@ digest_init (tree type, tree init)
 
   /* Handle scalar types (including conversions) and references.  */
   if (SCALAR_TYPE_P (type) || code == REFERENCE_TYPE)
-    return convert_for_initialization (0, type, init, LOOKUP_NORMAL,
-				       "initialization", NULL_TREE, 0);
+    {
+      tree *exp;
+
+      init = convert_for_initialization (0, type, init, LOOKUP_NORMAL,
+					 "initialization", NULL_TREE, 0);
+      exp = &init;
+
+      /* Skip any conversions since we'll be outputting the underlying
+	 constant.  */
+      while (TREE_CODE (*exp) == NOP_EXPR || TREE_CODE (*exp) == CONVERT_EXPR
+	     || TREE_CODE (*exp) == NON_LVALUE_EXPR)
+	exp = &TREE_OPERAND (*exp, 0);
+
+      *exp = cplus_expand_constant (*exp);
+
+      return init;
+    }
 
   /* Come here only for aggregates: records, arrays, unions, complex numbers
      and vectors.  */
Index: gcc/langhooks.c
===================================================================
--- gcc/langhooks.c	(revision 123066)
+++ gcc/langhooks.c	(working copy)
@@ -76,14 +76,6 @@ lhd_do_nothing_f (struct function * ARG_
 {
 }
 
-/* Do nothing (return the tree node passed).  */
-
-tree
-lhd_return_tree (tree t)
-{
-  return t;
-}
-
 /* Do nothing (return NULL_TREE).  */
 
 tree
Index: gcc/langhooks.h
===================================================================
--- gcc/langhooks.h	(revision 123066)
+++ gcc/langhooks.h	(working copy)
@@ -302,11 +302,6 @@ struct lang_hooks
      Returns -1 if the language does nothing special for it.  */
   HOST_WIDE_INT (*get_alias_set) (tree);
 
-  /* Called with an expression that is to be processed as a constant.
-     Returns either the same expression or a language-independent
-     constant equivalent to its input.  */
-  tree (*expand_constant) (tree);
-
   /* Called by expand_expr for language-specific tree codes.
      Fourth argument is actually an enum expand_modifier.  */
   rtx (*expand_expr) (tree, rtx, enum machine_mode, int, rtx *);
Index: gcc/varasm.c
===================================================================
--- gcc/varasm.c	(revision 123066)
+++ gcc/varasm.c	(working copy)
@@ -2960,15 +2960,7 @@ compare_constant (const tree t1, const t
       return compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
 
     default:
-      {
-	tree nt1, nt2;
-	nt1 = lang_hooks.expand_constant (t1);
-	nt2 = lang_hooks.expand_constant (t2);
-	if (nt1 != t1 || nt2 != t2)
-	  return compare_constant (nt1, nt2);
-	else
-	  return 0;
-      }
+      return 0;
     }
 
   gcc_unreachable ();
@@ -3034,12 +3026,7 @@ copy_constant (tree exp)
       }
 
     default:
-      {
-	tree t = lang_hooks.expand_constant (exp);
-
-	gcc_assert (t != exp);
-	return copy_constant (t);
-      }
+      gcc_unreachable ();
     }
 }
 

@@ -3871,10 +3858,6 @@ compute_reloc_for_constant (tree exp)
   int reloc = 0, reloc2;
   tree tem;
 
-  /* Give the front-end a chance to convert VALUE to something that
-     looks more like a constant to the back-end.  */
-  exp = lang_hooks.expand_constant (exp);
-
   switch (TREE_CODE (exp))
     {
     case ADDR_EXPR:
@@ -3938,10 +3921,6 @@ output_addressed_constants (tree exp)
 {
   tree tem;
 
-  /* Give the front-end a chance to convert VALUE to something that
-     looks more like a constant to the back-end.  */
-  exp = lang_hooks.expand_constant (exp);
-
   switch (TREE_CODE (exp))
     {
     case ADDR_EXPR:
@@ -4014,10 +3993,6 @@ constructor_static_from_elts_p (tree cto
 tree
 initializer_constant_valid_p (tree value, tree endtype)
 {
-  /* Give the front-end a chance to convert VALUE to something that
-     looks more like a constant to the back-end.  */
-  value = lang_hooks.expand_constant (value);
-
   switch (TREE_CODE (value))
     {
     case CONSTRUCTOR:
@@ -4275,11 +4250,6 @@ output_constant (tree exp, unsigned HOST
   enum tree_code code;
   unsigned HOST_WIDE_INT thissize;
 
-  /* Some front-ends use constants other than the standard language-independent
-     varieties, but which may still be output directly.  Give the front-end a
-     chance to convert EXP to a language-independent representation.  */
-  exp = lang_hooks.expand_constant (exp);
-
   if (size == 0 || flag_syntax_only)
     return;
 
@@ -4336,9 +4306,6 @@ output_constant (tree exp, unsigned HOST
   code = TREE_CODE (TREE_TYPE (exp));
   thissize = int_size_in_bytes (TREE_TYPE (exp));
 
-  /* Give the front end another chance to expand constants.  */
-  exp = lang_hooks.expand_constant (exp);
-
   /* Allow a constructor with no elements for any data type.
      This means to fill the space with zeros.  */
   if (TREE_CODE (exp) == CONSTRUCTOR
Index: gcc/langhooks-def.h
===================================================================
--- gcc/langhooks-def.h	(revision 123066)
+++ gcc/langhooks-def.h	(working copy)
@@ -45,7 +45,6 @@ extern void lhd_do_nothing_i (int);
 extern void lhd_do_nothing_f (struct function *);
 extern bool lhd_post_options (const char **);
 extern HOST_WIDE_INT lhd_get_alias_set (tree);
-extern tree lhd_return_tree (tree);
 extern tree lhd_return_null_tree_v (void);
 extern tree lhd_return_null_tree (tree);
 extern tree lhd_do_nothing_iii_return_null_tree (int, int, int);
@@ -107,7 +106,6 @@ extern void lhd_omp_firstprivatize_type_
 #define LANG_HOOKS_MISSING_ARGUMENT	hook_bool_constcharptr_size_t_false
 #define LANG_HOOKS_POST_OPTIONS		lhd_post_options
 #define LANG_HOOKS_GET_ALIAS_SET	lhd_get_alias_set
-#define LANG_HOOKS_EXPAND_CONSTANT	lhd_return_tree
 #define LANG_HOOKS_EXPAND_EXPR		lhd_expand_expr
 #define LANG_HOOKS_EXPAND_DECL		lhd_expand_decl
 #define LANG_HOOKS_SAFE_FROM_P		lhd_safe_from_p
@@ -292,7 +290,6 @@ extern tree lhd_make_node (enum tree_cod
   LANG_HOOKS_PARSE_FILE, \
   LANG_HOOKS_CLEAR_BINDING_STACK, \
   LANG_HOOKS_GET_ALIAS_SET, \
-  LANG_HOOKS_EXPAND_CONSTANT, \
   LANG_HOOKS_EXPAND_EXPR, \
   LANG_HOOKS_EXPAND_DECL, \
   LANG_HOOKS_SAFE_FROM_P, \


More information about the Gcc-patches mailing list