[gfortran] Make all labels DECL_ARTIFICIAL

Steven Bosscher stevenb@suse.de
Mon Dec 20 21:22:00 GMT 2004


Hi,

There is absolutely nothing we gain from making Fortran's numeric
labels user labels (gdb can't put break points on them), and they
for some reason hurt performance.  So the attached patch just all
marks them as compiler-generated.  Thoughts?

Gr.
Steven

	* trans-decl.c (gfc_build_label_decl): Set DECL_ARTIFICAL and
	TREE_USED for all labels.
	(gfc_trans_entry_master_switch): Use it instead of building a
	label by hand.
	* trans-io.c (add_case): Likewise.
	* trans-stmt.c (gfc_trans_integer_select): Likewise.

Index: trans-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/trans-decl.c,v
retrieving revision 1.49
diff -u -3 -p -r1.49 trans-decl.c
--- trans-decl.c	25 Nov 2004 11:13:35 -0000	1.49
+++ trans-decl.c	20 Dec 2004 07:09:29 -0000
@@ -148,9 +148,9 @@ gfc_add_decl_to_function (tree decl)
 }
 
 
-/* Build a  backend label declaration.
-   Set TREE_USED for named lables.  For artificial labels it's up to the
-   caller to mark the label as used.  */
+/* Build a  backend label declaration.  Set TREE_USED for named lables.
+   The context of the label is always the current_function_decl.  All
+   labels are marked artificial.  */
 
 tree
 gfc_build_label_decl (tree label_id)
@@ -174,19 +174,13 @@ gfc_build_label_decl (tree label_id)
   DECL_CONTEXT (label_decl) = current_function_decl;
   DECL_MODE (label_decl) = VOIDmode;
 
-  if (label_name)
-    {
-      DECL_ARTIFICIAL (label_decl) = 1;
-    }
-  else
-    {
-      /* We always define the label as used, even if the original source
-         file never references the label.  We don't want all kinds of
-         spurious warnings for old-style Fortran code with too many
-         labels.  */
-      TREE_USED (label_decl) = 1;
-    }
+  /* We always define the label as used, even if the original source
+     file never references the label.  We don't want all kinds of
+     spurious warnings for old-style Fortran code with too many
+     labels.  */
+  TREE_USED (label_decl) = 1;
 
+  DECL_ARTIFICIAL (label_decl) = 1;
   return label_decl;
 }
 
@@ -2122,16 +2116,13 @@ gfc_trans_entry_master_switch (gfc_entry
   for (; el; el = el->next)
     {
       /* Add the case label.  */
-      label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
-      DECL_CONTEXT (label) = current_function_decl;
+      label = gfc_build_label_decl (NULL_TREE);
       val = build_int_cst (gfc_array_index_type, el->id);
       tmp = build3_v (CASE_LABEL_EXPR, val, NULL_TREE, label);
       gfc_add_expr_to_block (&block, tmp);
       
       /* And jump to the actual entry point.  */
       label = gfc_build_label_decl (NULL_TREE);
-      TREE_USED (label) = 1;
-      DECL_CONTEXT (label) = current_function_decl;
       tmp = build1_v (GOTO_EXPR, label);
       gfc_add_expr_to_block (&block, tmp);
 
Index: trans-io.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/trans-io.c,v
retrieving revision 1.24
diff -u -3 -p -r1.24 trans-io.c
--- trans-io.c	10 Nov 2004 20:03:21 -0000	1.24
+++ trans-io.c	20 Dec 2004 07:09:30 -0000
@@ -454,8 +454,7 @@ add_case (int label_value, gfc_st_label 
   value = build_int_cst (NULL_TREE, label_value);
 
   /* Make a backend label for this case.  */
-  tmp = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
-  DECL_CONTEXT (tmp) = current_function_decl;
+  tmp = gfc_build_label_decl (NULL_TREE);
 
   /* And the case itself.  */
   tmp = build3_v (CASE_LABEL_EXPR, value, NULL_TREE, tmp);
Index: trans-stmt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/trans-stmt.c,v
retrieving revision 1.19
diff -u -3 -p -r1.19 trans-stmt.c
--- trans-stmt.c	12 Dec 2004 20:27:00 -0000	1.19
+++ trans-stmt.c	20 Dec 2004 07:09:31 -0000
@@ -947,8 +947,7 @@ gfc_trans_integer_select (gfc_code * cod
 	    }
 
           /* Build a label.  */
-          label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
-          DECL_CONTEXT (label) = current_function_decl;
+          label = gfc_build_label_decl (NULL_TREE);
 
 	  /* Add this case label.
              Add parameter 'label', make it match GCC backend.  */



More information about the Gcc-patches mailing list