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]

Re: [tree-ssa PATCH] Pick memory consumption low hanging fruit


On Tuesday 18 November 2003 19:01, Andrew MacLeod wrote:
> On Tue, 2003-11-18 at 11:32, law@redhat.com wrote:
> > In message <200311181219.41900.s.bosscher@student.tudelft.nl>, Steven
> > Bosscher writes:
> > A few things stick out like a sore thumb:
>
> Hmm, yeah. I just turned on GATHER_STATISTICS so I can look too :-)


Here are the patches I used to make it produce per-node statistics.  Perhaps 
they're useful for others as well (not hacking this in yourself saves you at 
least a few minutes ;-)

Gr.
Steven

Index: tree.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.c,v
retrieving revision 1.263.2.69
diff -c -3 -p -r1.263.2.69 tree.c
*** tree.c	17 Nov 2003 23:39:20 -0000	1.263.2.69
--- tree.c	18 Nov 2003 21:13:08 -0000
*************** extern int _obstack_allocated_p (struct 
*** 55,62 ****
  #ifdef GATHER_STATISTICS
  /* Statistics-gathering stuff.  */
  
! int tree_node_counts[(int) all_kinds];
! int tree_node_sizes[(int) all_kinds];
  
  /* Keep in sync with tree.h:enum tree_node_kind.  */
  static const char * const tree_node_kind_names[] = {
--- 55,62 ----
  #ifdef GATHER_STATISTICS
  /* Statistics-gathering stuff.  */
  
! int tree_node_kind_counts[(int) all_kinds];
! int tree_node_kind_sizes[(int) all_kinds];
  
  /* Keep in sync with tree.h:enum tree_node_kind.  */
  static const char * const tree_node_kind_names[] = {
*************** static const char * const tree_node_kind
*** 77,82 ****
--- 77,86 ----
    "lang_decl kinds",
    "lang_type kinds"
  };
+ 
+ int tree_node_code_counts[MAX_TREE_CODES];
+ int tree_node_code_sizes[MAX_TREE_CODES];
+ 
  #endif /* GATHER_STATISTICS */
  
  /* Unique id for next decl created.  */
*************** make_node (enum tree_code code)
*** 291,298 ****
        abort ();
      }
  
!   tree_node_counts[(int) kind]++;
!   tree_node_sizes[(int) kind] += length;
  #endif
  
    t = ggc_alloc_tree (length);
--- 295,305 ----
        abort ();
      }
  
!   tree_node_kind_counts[(int) kind]++;
!   tree_node_kind_sizes[(int) kind] += length;
! 
!   tree_node_code_counts[(int) code]++;
!   tree_node_code_sizes[(int) code] += length;
  #endif
  
    t = ggc_alloc_tree (length);
*************** make_tree_vec (int len)
*** 593,600 ****
    int length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec);
  
  #ifdef GATHER_STATISTICS
!   tree_node_counts[(int) vec_kind]++;
!   tree_node_sizes[(int) vec_kind] += length;
  #endif
  
    t = ggc_alloc_tree (length);
--- 600,610 ----
    int length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec);
  
  #ifdef GATHER_STATISTICS
!   tree_node_kind_counts[(int) vec_kind]++;
!   tree_node_kind_sizes[(int) vec_kind] += length;
! 
!   tree_node_code_counts[(int) TREE_VEC]++;
!   tree_node_code_sizes[(int) TREE_VEC] += length;
  #endif
  
    t = ggc_alloc_tree (length);
*************** tree_cons (tree purpose, tree value, tre
*** 1079,1086 ****
    memset (node, 0, sizeof (struct tree_common));
  
  #ifdef GATHER_STATISTICS
!   tree_node_counts[(int) x_kind]++;
!   tree_node_sizes[(int) x_kind] += sizeof (struct tree_list);
  #endif
  
    TREE_SET_CODE (node, TREE_LIST);
--- 1089,1099 ----
    memset (node, 0, sizeof (struct tree_common));
  
  #ifdef GATHER_STATISTICS
!   tree_node_kind_counts[(int) x_kind]++;
!   tree_node_kind_sizes[(int) x_kind] += sizeof (struct tree_list);
! 
!   tree_node_code_counts[(int) TREE_LIST]++;
!   tree_node_code_sizes[(int) TREE_LIST] += sizeof (struct tree_list);
  #endif
  
    TREE_SET_CODE (node, TREE_LIST);
*************** build1 (enum tree_code code, tree type, 
*** 2404,2411 ****
        break;
      }
  
!   tree_node_counts[(int) kind]++;
!   tree_node_sizes[(int) kind] += length;
  #endif
  
  #ifdef ENABLE_CHECKING
--- 2417,2427 ----
        break;
      }
  
!   tree_node_kind_counts[(int) kind]++;
!   tree_node_kind_sizes[(int) kind] += length;
! 
!   tree_node_code_counts[(int) code]++;
!   tree_node_code_sizes[(int) code] += length;
  #endif
  
  #ifdef ENABLE_CHECKING
*************** type_hash_canon (unsigned int hashcode, 
*** 3084,3091 ****
    if (t1 != 0)
      {
  #ifdef GATHER_STATISTICS
!       tree_node_counts[(int) t_kind]--;
!       tree_node_sizes[(int) t_kind] -= sizeof (struct tree_type);
  #endif
        return t1;
      }
--- 3100,3110 ----
    if (t1 != 0)
      {
  #ifdef GATHER_STATISTICS
!       tree_node_kind_counts[(int) t_kind]--;
!       tree_node_kind_sizes[(int) t_kind] -= sizeof (struct tree_type);
! 
!       tree_node_code_counts[(int) TREE_CODE (type)]--;
!       tree_node_code_sizes[(int) TREE_CODE (type)] -= sizeof (struct tree_type);
  #endif
        return t1;
      }
*************** dump_tree_statistics (void)
*** 4589,4598 ****
    for (i = 0; i < (int) all_kinds; i++)
      {
        fprintf (stderr, "%-20s %7d %10d\n", tree_node_kind_names[i],
! 	       tree_node_counts[i], tree_node_sizes[i]);
!       total_nodes += tree_node_counts[i];
!       total_bytes += tree_node_sizes[i];
      }
    fprintf (stderr, "---------------------------------------\n");
    fprintf (stderr, "%-20s %7d %10d\n", "Total", total_nodes, total_bytes);
    fprintf (stderr, "---------------------------------------\n");
--- 4608,4631 ----
    for (i = 0; i < (int) all_kinds; i++)
      {
        fprintf (stderr, "%-20s %7d %10d\n", tree_node_kind_names[i],
! 	       tree_node_kind_counts[i], tree_node_kind_sizes[i]);
!       total_nodes += tree_node_kind_counts[i];
!       total_bytes += tree_node_kind_sizes[i];
      }
+   fprintf (stderr, "---------------------------------------\n\n");
+ 
+   fprintf (stderr, "Code                   Nodes      Bytes\n");
+   fprintf (stderr, "---------------------------------------\n");
+   for (i = 0; i < MAX_TREE_CODES; i++)
+     {
+       if (tree_node_code_counts[i] == 0)
+ 	continue;
+ 
+       fprintf (stderr, "%-20s %7d %10d\n", tree_code_name[i],
+ 	       tree_node_code_counts[i], tree_node_code_sizes[i]);
+     }
+   fprintf (stderr, "---------------------------------------\n\n");
+ 
    fprintf (stderr, "---------------------------------------\n");
    fprintf (stderr, "%-20s %7d %10d\n", "Total", total_nodes, total_bytes);
    fprintf (stderr, "---------------------------------------\n");
*************** make_phi_node (tree var, int len)
*** 5158,5165 ****
    size = sizeof (struct tree_phi_node) + (len - 1) * sizeof (struct phi_arg_d);
  
  #ifdef GATHER_STATISTICS
!   tree_node_counts[(int) phi_kind]++;
!   tree_node_sizes[(int) phi_kind] += size;
  #endif
  
    phi = ggc_alloc_tree (size);
--- 5191,5201 ----
    size = sizeof (struct tree_phi_node) + (len - 1) * sizeof (struct phi_arg_d);
  
  #ifdef GATHER_STATISTICS
!   tree_node_kind_counts[(int) phi_kind]++;
!   tree_node_kind_sizes[(int) phi_kind] += size;
! 
!   tree_node_code_counts[(int) PHI_NODE]++;
!   tree_node_code_sizes[(int) PHI_NODE] += size;
  #endif
  
    phi = ggc_alloc_tree (size);
Index: tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.h,v
retrieving revision 1.342.2.130
diff -c -3 -p -r1.342.2.130 tree.h
*** tree.h	18 Nov 2003 15:04:32 -0000	1.342.2.130
--- tree.h	18 Nov 2003 21:13:10 -0000
*************** typedef enum
*** 3631,3637 ****
    all_kinds
  } tree_node_kind;
  
! extern int tree_node_counts[];
! extern int tree_node_sizes[];
!     
  #endif  /* GCC_TREE_H  */
--- 3631,3639 ----
    all_kinds
  } tree_node_kind;
  
! extern int tree_node_kind_counts[];
! extern int tree_node_kind_sizes[];
! 
! extern int tree_node_code_counts[];
! extern int tree_node_code_sizes[];    
  #endif  /* GCC_TREE_H  */
Index: cp/lex.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/lex.c,v
retrieving revision 1.284.2.19
diff -c -3 -p -r1.284.2.19 lex.c
*** cp/lex.c	28 Sep 2003 06:07:27 -0000	1.284.2.19
--- cp/lex.c	18 Nov 2003 21:13:12 -0000
*************** retrofit_lang_decl (tree t)
*** 756,763 ****
    else abort ();
  
  #ifdef GATHER_STATISTICS
!   tree_node_counts[(int)lang_decl] += 1;
!   tree_node_sizes[(int)lang_decl] += size;
  #endif
  }
  
--- 756,763 ----
    else abort ();
  
  #ifdef GATHER_STATISTICS
!   tree_node_kind_counts[(int)lang_decl] += 1;
!   tree_node_kind_sizes[(int)lang_decl] += size;
  #endif
  }
  
*************** cxx_dup_lang_specific_decl (tree node)
*** 779,786 ****
    DECL_LANG_SPECIFIC (node) = ld;
  
  #ifdef GATHER_STATISTICS
!   tree_node_counts[(int)lang_decl] += 1;
!   tree_node_sizes[(int)lang_decl] += size;
  #endif
  }
  
--- 779,786 ----
    DECL_LANG_SPECIFIC (node) = ld;
  
  #ifdef GATHER_STATISTICS
!   tree_node_kind_counts[(int)lang_decl] += 1;
!   tree_node_kind_sizes[(int)lang_decl] += size;
  #endif
  }
  
*************** copy_lang_type (tree node)
*** 816,823 ****
    TYPE_LANG_SPECIFIC (node) = lt;
  
  #ifdef GATHER_STATISTICS
!   tree_node_counts[(int)lang_type] += 1;
!   tree_node_sizes[(int)lang_type] += size;
  #endif
  }
  
--- 816,823 ----
    TYPE_LANG_SPECIFIC (node) = lt;
  
  #ifdef GATHER_STATISTICS
!   tree_node_kind_counts[(int)lang_type] += 1;
!   tree_node_kind_sizes[(int)lang_type] += size;
  #endif
  }
  
*************** cxx_make_type (enum tree_code code)
*** 850,857 ****
        pi->u.c.h.is_lang_type_class = 1;
  
  #ifdef GATHER_STATISTICS
!       tree_node_counts[(int)lang_type] += 1;
!       tree_node_sizes[(int)lang_type] += sizeof (struct lang_type);
  #endif
      }
  
--- 850,857 ----
        pi->u.c.h.is_lang_type_class = 1;
  
  #ifdef GATHER_STATISTICS
!       tree_node_kind_counts[(int)lang_type] += 1;
!       tree_node_kind_sizes[(int)lang_type] += sizeof (struct lang_type);
  #endif
      }
  
? ChangeLog.entry
Index: tree.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.c,v
retrieving revision 1.338
diff -c -3 -p -r1.338 tree.c
*** tree.c	14 Nov 2003 08:19:59 -0000	1.338
--- tree.c	18 Nov 2003 21:07:28 -0000
*************** extern int _obstack_allocated_p (struct 
*** 52,59 ****
  #ifdef GATHER_STATISTICS
  /* Statistics-gathering stuff.  */
  
! int tree_node_counts[(int) all_kinds];
! int tree_node_sizes[(int) all_kinds];
  
  /* Keep in sync with tree.h:enum tree_node_kind.  */
  static const char * const tree_node_kind_names[] = {
--- 52,59 ----
  #ifdef GATHER_STATISTICS
  /* Statistics-gathering stuff.  */
  
! int tree_node_kind_counts[(int) all_kinds];
! int tree_node_kind_sizes[(int) all_kinds];
  
  /* Keep in sync with tree.h:enum tree_node_kind.  */
  static const char * const tree_node_kind_names[] = {
*************** static const char * const tree_node_kind
*** 72,77 ****
--- 72,81 ----
    "lang_decl kinds",
    "lang_type kinds"
  };
+ 
+ int tree_node_code_counts[MAX_TREE_CODES];
+ int tree_node_code_sizes[MAX_TREE_CODES];
+ 
  #endif /* GATHER_STATISTICS */
  
  /* Unique id for next decl created.  */
*************** make_node (enum tree_code code)
*** 266,273 ****
        abort ();
      }
  
!   tree_node_counts[(int) kind]++;
!   tree_node_sizes[(int) kind] += length;
  #endif
  
    t = ggc_alloc_tree (length);
--- 270,280 ----
        abort ();
      }
  
!   tree_node_kind_counts[(int) kind]++;
!   tree_node_kind_sizes[(int) kind] += length;
! 
!   tree_node_code_counts[(int) code]++;
!   tree_node_code_sizes[(int) code] += length;
  #endif
  
    t = ggc_alloc_tree (length);
*************** make_tree_vec (int len)
*** 561,568 ****
    int length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec);
  
  #ifdef GATHER_STATISTICS
!   tree_node_counts[(int) vec_kind]++;
!   tree_node_sizes[(int) vec_kind] += length;
  #endif
  
    t = ggc_alloc_tree (length);
--- 568,578 ----
    int length = (len - 1) * sizeof (tree) + sizeof (struct tree_vec);
  
  #ifdef GATHER_STATISTICS
!   tree_node_kind_counts[(int) vec_kind]++;
!   tree_node_kind_sizes[(int) vec_kind] += length;
! 
!   tree_node_code_counts[(int) TREE_VEC]++;
!   tree_node_code_sizes[(int) TREE_VEC] += length;
  #endif
  
    t = ggc_alloc_tree (length);
*************** tree_cons (tree purpose, tree value, tre
*** 1047,1054 ****
    memset (node, 0, sizeof (struct tree_common));
  
  #ifdef GATHER_STATISTICS
!   tree_node_counts[(int) x_kind]++;
!   tree_node_sizes[(int) x_kind] += sizeof (struct tree_list);
  #endif
  
    TREE_SET_CODE (node, TREE_LIST);
--- 1057,1067 ----
    memset (node, 0, sizeof (struct tree_common));
  
  #ifdef GATHER_STATISTICS
!   tree_node_kind_counts[(int) x_kind]++;
!   tree_node_kind_sizes[(int) x_kind] += sizeof (struct tree_list);
! 
!   tree_node_code_counts[(int) TREE_LIST]++;
!   tree_node_code_sizes[(int) TREE_LIST] += sizeof (struct tree_list);
  #endif
  
    TREE_SET_CODE (node, TREE_LIST);
*************** build1 (enum tree_code code, tree type, 
*** 2424,2431 ****
        break;
      }
  
!   tree_node_counts[(int) kind]++;
!   tree_node_sizes[(int) kind] += length;
  #endif
  
  #ifdef ENABLE_CHECKING
--- 2437,2447 ----
        break;
      }
  
!   tree_node_kind_counts[(int) kind]++;
!   tree_node_kind_sizes[(int) kind] += length;
! 
!   tree_node_code_counts[(int) code]++;
!   tree_node_code_sizes[(int) code] += length;
  #endif
  
  #ifdef ENABLE_CHECKING
*************** type_hash_canon (unsigned int hashcode, 
*** 3060,3067 ****
    if (t1 != 0)
      {
  #ifdef GATHER_STATISTICS
!       tree_node_counts[(int) t_kind]--;
!       tree_node_sizes[(int) t_kind] -= sizeof (struct tree_type);
  #endif
        return t1;
      }
--- 3076,3086 ----
    if (t1 != 0)
      {
  #ifdef GATHER_STATISTICS
!       tree_node_kind_counts[(int) t_kind]--;
!       tree_node_kind_sizes[(int) t_kind] -= sizeof (struct tree_type);
! 
!       tree_node_code_counts[(int) TREE_CODE (type)]--;
!       tree_node_code_sizes[(int) TREE_CODE (type)] -= sizeof (struct tree_type);
  #endif
        return t1;
      }
*************** dump_tree_statistics (void)
*** 4507,4516 ****
    for (i = 0; i < (int) all_kinds; i++)
      {
        fprintf (stderr, "%-20s %7d %10d\n", tree_node_kind_names[i],
! 	       tree_node_counts[i], tree_node_sizes[i]);
!       total_nodes += tree_node_counts[i];
!       total_bytes += tree_node_sizes[i];
      }
    fprintf (stderr, "---------------------------------------\n");
    fprintf (stderr, "%-20s %7d %10d\n", "Total", total_nodes, total_bytes);
    fprintf (stderr, "---------------------------------------\n");
--- 4526,4549 ----
    for (i = 0; i < (int) all_kinds; i++)
      {
        fprintf (stderr, "%-20s %7d %10d\n", tree_node_kind_names[i],
! 	       tree_node_kind_counts[i], tree_node_kind_sizes[i]);
!       total_nodes += tree_node_kind_counts[i];
!       total_bytes += tree_node_kind_sizes[i];
      }
+   fprintf (stderr, "---------------------------------------\n\n");
+ 
+   fprintf (stderr, "Code                   Nodes      Bytes\n");
+   fprintf (stderr, "---------------------------------------\n");
+   for (i = 0; i < MAX_TREE_CODES; i++)
+     {
+       if (tree_node_code_counts[i] == 0)
+ 	continue;
+ 
+       fprintf (stderr, "%-20s %7d %10d\n", tree_code_name[i],
+ 	       tree_node_code_counts[i], tree_node_code_sizes[i]);
+     }
+   fprintf (stderr, "---------------------------------------\n\n");
+ 
    fprintf (stderr, "---------------------------------------\n");
    fprintf (stderr, "%-20s %7d %10d\n", "Total", total_nodes, total_bytes);
    fprintf (stderr, "---------------------------------------\n");
Index: tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.h,v
retrieving revision 1.453
diff -c -3 -p -r1.453 tree.h
*** tree.h	14 Nov 2003 08:19:59 -0000	1.453
--- tree.h	18 Nov 2003 21:07:30 -0000
*************** typedef enum
*** 3107,3113 ****
    all_kinds
  } tree_node_kind;
  
! extern int tree_node_counts[];
! extern int tree_node_sizes[];
!     
  #endif  /* GCC_TREE_H  */
--- 3107,3115 ----
    all_kinds
  } tree_node_kind;
  
! extern int tree_node_kind_counts[];
! extern int tree_node_kind_sizes[];
! 
! extern int tree_node_code_counts[];
! extern int tree_node_code_sizes[];    
  #endif  /* GCC_TREE_H  */
Index: cp/lex.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/lex.c,v
retrieving revision 1.317
diff -c -3 -p -r1.317 lex.c
*** cp/lex.c	18 Sep 2003 15:05:57 -0000	1.317
--- cp/lex.c	18 Nov 2003 21:07:34 -0000
*************** retrofit_lang_decl (tree t)
*** 756,763 ****
    else abort ();
  
  #ifdef GATHER_STATISTICS
!   tree_node_counts[(int)lang_decl] += 1;
!   tree_node_sizes[(int)lang_decl] += size;
  #endif
  }
  
--- 756,763 ----
    else abort ();
  
  #ifdef GATHER_STATISTICS
!   tree_node_kind_counts[(int)lang_decl] += 1;
!   tree_node_kind_sizes[(int)lang_decl] += size;
  #endif
  }
  
*************** cxx_dup_lang_specific_decl (tree node)
*** 779,786 ****
    DECL_LANG_SPECIFIC (node) = ld;
  
  #ifdef GATHER_STATISTICS
!   tree_node_counts[(int)lang_decl] += 1;
!   tree_node_sizes[(int)lang_decl] += size;
  #endif
  }
  
--- 779,786 ----
    DECL_LANG_SPECIFIC (node) = ld;
  
  #ifdef GATHER_STATISTICS
!   tree_node_kind_counts[(int)lang_decl] += 1;
!   tree_node_kind_sizes[(int)lang_decl] += size;
  #endif
  }
  
*************** copy_lang_type (tree node)
*** 816,823 ****
    TYPE_LANG_SPECIFIC (node) = lt;
  
  #ifdef GATHER_STATISTICS
!   tree_node_counts[(int)lang_type] += 1;
!   tree_node_sizes[(int)lang_type] += size;
  #endif
  }
  
--- 816,823 ----
    TYPE_LANG_SPECIFIC (node) = lt;
  
  #ifdef GATHER_STATISTICS
!   tree_node_kind_counts[(int)lang_type] += 1;
!   tree_node_kind_sizes[(int)lang_type] += size;
  #endif
  }
  
*************** cxx_make_type (enum tree_code code)
*** 850,857 ****
        pi->u.c.h.is_lang_type_class = 1;
  
  #ifdef GATHER_STATISTICS
!       tree_node_counts[(int)lang_type] += 1;
!       tree_node_sizes[(int)lang_type] += sizeof (struct lang_type);
  #endif
      }
  
--- 850,857 ----
        pi->u.c.h.is_lang_type_class = 1;
  
  #ifdef GATHER_STATISTICS
!       tree_node_kind_counts[(int)lang_type] += 1;
!       tree_node_kind_sizes[(int)lang_type] += sizeof (struct lang_type);
  #endif
      }
  

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