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]

[PATCH] Make mem_sym_stat sorting stable, dump the scores


Bootstrapped & tested on x86_64-unknown-linux-gnu, I'll apply this 
shortly after re-bootstrap after cosmetic changes finished.

Richard.


2007-10-25  Richard Guenther  <rguenther@suse.de>

	* tree-flow.h (mem_sym_stats): Remove.
	(dump_mem_sym_stats_for_var): Declare.
	* tree-dfa.c (dump_variable): Call dump_mem_sym_stats_for_var.
	(mem_sym_stats): Move ...
	* tree-ssa-alias.c (mem_sym_stats): ... here and make it static.
	(mem_sym_score): Rename from ...
	(pscore): ... this.  Remove.
	(dump_mem_sym_stats_for_var): New function.  Dump the score, but
	not the frequencies.
	(compare_mp_info_entries): Make sort stable by disambiguating
	on DECL_UID.

Index: tree-ssa-alias.c
===================================================================
*** tree-ssa-alias.c	(revision 129624)
--- tree-ssa-alias.c	(working copy)
*************** get_mem_sym_stats_for (tree var)
*** 242,247 ****
--- 242,270 ----
  }
  
  
+ /* Return memory reference statistics for variable VAR in function FN.
+    This is computed by alias analysis, but it is not kept
+    incrementally up-to-date.  So, these stats are only accurate if
+    pass_may_alias has been run recently.  If no alias information
+    exists, this function returns NULL.  */
+ 
+ static mem_sym_stats_t
+ mem_sym_stats (struct function *fn, tree var)
+ {
+   void **slot;
+   struct pointer_map_t *stats_map = gimple_mem_ref_stats (fn)->mem_sym_stats;
+ 
+   if (stats_map == NULL)
+     return NULL;
+ 
+   slot = pointer_map_contains (stats_map, var);
+   if (slot == NULL)
+     return NULL;
+ 
+   return (mem_sym_stats_t) *slot;
+ }
+ 
+ 
  /* Set MPT to be the memory partition associated with symbol SYM.  */
  
  static inline void
*************** count_mem_refs (long *num_vuses_p, long 
*** 774,779 ****
--- 797,836 ----
  }
  
  
+ /* The list is sorted by increasing partitioning score (PSCORE).
+    This score is computed such that symbols with high scores are
+    those that are least likely to be partitioned.  Given a symbol
+    MP->VAR, PSCORE(S) is the result of the following weighted sum
+ 
+    PSCORE(S) =   FW * 64 + FR * 32
+    	       + DW * 16 + DR *  8 
+    	       + IW *  4 + IR *  2
+                + NO_ALIAS
+ 
+    where
+ 
+    FW		Execution frequency of writes to S
+    FR		Execution frequency of reads from S
+    DW		Number of direct writes to S
+    DR		Number of direct reads from S
+    IW		Number of indirect writes to S
+    IR		Number of indirect reads from S
+    NO_ALIAS	State of the NO_ALIAS* flags
+ 
+    The basic idea here is that symbols that are frequently
+    written-to in hot paths of the code are the last to be considered
+    for partitioning.  */
+ 
+ static inline long
+ mem_sym_score (mem_sym_stats_t mp)
+ {
+   return mp->frequency_writes * 64 + mp->frequency_reads * 32
+          + mp->num_direct_writes * 16 + mp->num_direct_reads * 8
+ 	 + mp->num_indirect_writes * 4 + mp->num_indirect_reads * 2
+ 	 + var_ann (mp->var)->noalias_state;
+ }
+ 
+ 
  /* Dump memory reference stats for function CFUN to FILE.  */
  
  void
*************** debug_mem_sym_stats (tree var)
*** 874,879 ****
--- 931,953 ----
    dump_mem_sym_stats (stderr, var);
  }
  
+ /* Dump memory reference stats for variable VAR to FILE.  For use
+    of tree-dfa.c:dump_variable.  */
+ 
+ void
+ dump_mem_sym_stats_for_var (FILE *file, tree var)
+ {
+   mem_sym_stats_t stats = mem_sym_stats (cfun, var);
+ 
+   if (stats == NULL)
+     return;
+ 
+   fprintf (file, ", score: %ld", mem_sym_score (stats));
+   fprintf (file, ", direct reads: %ld", stats->num_direct_reads);
+   fprintf (file, ", direct writes: %ld", stats->num_direct_writes);
+   fprintf (file, ", indirect reads: %ld", stats->num_indirect_reads);
+   fprintf (file, ", indirect writes: %ld", stats->num_indirect_writes);
+ }
  
  /* Dump memory reference stats for all memory symbols to FILE.  */
  
*************** update_mem_sym_stats_from_stmt (tree var
*** 950,989 ****
  }
  
  
- /* The list is sorted by increasing partitioning score (PSCORE).
-    This score is computed such that symbols with high scores are
-    those that are least likely to be partitioned.  Given a symbol
-    MP->VAR, PSCORE(S) is the result of the following weighted sum
- 
-    PSCORE(S) =   FW * 64 + FR * 32
-    	       + DW * 16 + DR *  8 
-    	       + IW *  4 + IR *  2
-                + NO_ALIAS
- 
-    where
- 
-    FW		Execution frequency of writes to S
-    FR		Execution frequency of reads from S
-    DW		Number of direct writes to S
-    DR		Number of direct reads from S
-    IW		Number of indirect writes to S
-    IR		Number of indirect reads from S
-    NO_ALIAS	State of the NO_ALIAS* flags
- 
-    The basic idea here is that symbols that are frequently
-    written-to in hot paths of the code are the last to be considered
-    for partitioning.  */
- 
- static inline long
- pscore (mem_sym_stats_t mp)
- {
-   return mp->frequency_writes * 64 + mp->frequency_reads * 32
-          + mp->num_direct_writes * 16 + mp->num_direct_reads * 8
- 	 + mp->num_indirect_writes * 4 + mp->num_indirect_reads * 2
- 	 + var_ann (mp->var)->noalias_state;
- }
- 
- 
  /* Given two MP_INFO entries MP1 and MP2, return -1 if MP1->VAR should
     be partitioned before MP2->VAR, 0 if they are the same or 1 if
     MP1->VAR should be partitioned after MP2->VAR.  */
--- 1024,1029 ----
*************** pscore (mem_sym_stats_t mp)
*** 991,1005 ****
  static inline int
  compare_mp_info_entries (mem_sym_stats_t mp1, mem_sym_stats_t mp2)
  {
!   long pscore1 = pscore (mp1);
!   long pscore2 = pscore (mp2);
  
    if (pscore1 < pscore2)
      return -1;
    else if (pscore1 > pscore2)
      return 1;
    else
!     return 0;
  }
  
  
--- 1031,1045 ----
  static inline int
  compare_mp_info_entries (mem_sym_stats_t mp1, mem_sym_stats_t mp2)
  {
!   long pscore1 = mem_sym_score (mp1);
!   long pscore2 = mem_sym_score (mp2);
  
    if (pscore1 < pscore2)
      return -1;
    else if (pscore1 > pscore2)
      return 1;
    else
!     return DECL_UID (mp1->var) - DECL_UID (mp2->var);
  }
  
  
Index: tree-dfa.c
===================================================================
*** tree-dfa.c	(revision 129624)
--- tree-dfa.c	(working copy)
*************** dump_variable (FILE *file, tree var)
*** 345,360 ****
    if (TREE_THIS_VOLATILE (var))
      fprintf (file, ", is volatile");
  
!   if (mem_sym_stats (cfun, var))
!     {
!       mem_sym_stats_t stats = mem_sym_stats (cfun, var);
!       fprintf (file, ", direct reads: %ld", stats->num_direct_reads);
!       fprintf (file, ", direct writes: %ld", stats->num_direct_writes);
!       fprintf (file, ", indirect reads: %ld", stats->num_indirect_reads);
!       fprintf (file, ", indirect writes: %ld", stats->num_indirect_writes);
!       fprintf (file, ", read frequency: %ld", stats->frequency_reads);
!       fprintf (file, ", write frequency: %ld", stats->frequency_writes);
!     }
  
    if (is_call_clobbered (var))
      {
--- 345,351 ----
    if (TREE_THIS_VOLATILE (var))
      fprintf (file, ", is volatile");
  
!   dump_mem_sym_stats_for_var (file, var);
  
    if (is_call_clobbered (var))
      {
*************** get_ref_base_and_extent (tree exp, HOST_
*** 1010,1034 ****
    return exp;
  }
  
- 
- /* Return memory reference statistics for variable VAR in function FN.
-    This is computed by alias analysis, but it is not kept
-    incrementally up-to-date.  So, these stats are only accurate if
-    pass_may_alias has been run recently.  If no alias information
-    exists, this function returns NULL.  */
- 
- mem_sym_stats_t
- mem_sym_stats (struct function *fn, tree var)
- {
-   void **slot;
-   struct pointer_map_t *stats_map = gimple_mem_ref_stats (fn)->mem_sym_stats;
- 
-   if (stats_map == NULL)
-     return NULL;
- 
-   slot = pointer_map_contains (stats_map, var);
-   if (slot == NULL)
-     return NULL;
- 
-   return (mem_sym_stats_t) *slot;
- }
--- 1001,1003 ----
Index: tree-flow.h
===================================================================
*** tree-flow.h	(revision 129624)
--- tree-flow.h	(working copy)
*************** extern void find_new_referenced_vars (tr
*** 810,816 ****
  extern tree make_rename_temp (tree, const char *);
  extern void set_default_def (tree, tree);
  extern tree gimple_default_def (struct function *, tree);
- extern struct mem_sym_stats_d *mem_sym_stats (struct function *, tree);
  
  /* In tree-phinodes.c  */
  extern void reserve_phi_args_for_new_edge (basic_block);
--- 810,815 ----
*************** extern void dump_mem_ref_stats (FILE *);
*** 856,861 ****
--- 855,861 ----
  extern void debug_mem_ref_stats (void);
  extern void debug_memory_partitions (void);
  extern void debug_mem_sym_stats (tree var);
+ extern void dump_mem_sym_stats_for_var (FILE *, tree);
  extern void debug_all_mem_sym_stats (void);
  
  /* Call-back function for walk_use_def_chains().  At each reaching


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