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][alias-improvements] Add counters to the oracle


This adds counters to the lowlevel disambiguators, counted per CU
and output with -fmem-report.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to the
branch.

Richard.

2009-02-06  Richard Guenther  <rguenther@suse.de>

	* Makefile.in (toplev.o): Add tree-ssa-alias.h dependency.
	* toplev.c (dump_memory_report): Dump alias and pta stats.
	* tree-ssa-alias.c (alias_stats): New global variable.
	(dump_alias_stats): New function.
	(may_point_to_decl): Make static.
	(may_point_to_same_object): Likewise.
	(refs_may_alias_p): Make a wrapper for statistics, move body ...
	(refs_may_alias_p_1): ... here.
	(ref_maybe_used_by_call_p, ref_maybe_used_by_call_p_1): Likewise.
	(call_may_clobber_ref_p, call_may_clobber_ref_p_1): Likewise.
	* tree-ssa-alias.h (may_point_to_decl, may_point_to_same_object):
	Remove.
	(dump_alias_stats): Declare.
	(dump_pta_stats): Likewise.
	* tree-ssa-structalias.c (pta_stats): New global variable.
	(dump_pta_stats): New function.
	(pt_solution_includes): Make a wrapper for statistics, move body ...
	(pt_solution_includes_1): ... here.
	(pt_solutions_intersect, pt_solutions_intersect_1): Likewise.

Index: alias-improvements/gcc/Makefile.in
===================================================================
*** alias-improvements.orig/gcc/Makefile.in	2009-02-01 12:27:29.000000000 +0100
--- alias-improvements/gcc/Makefile.in	2009-02-06 17:14:52.000000000 +0100
*************** toplev.o : toplev.c $(CONFIG_H) $(SYSTEM
*** 2446,2452 ****
     value-prof.h $(PARAMS_H) $(TM_P_H) reload.h ira.h dwarf2asm.h $(TARGET_H) \
     langhooks.h insn-flags.h $(CFGLAYOUT_H) $(CFGLOOP_H) hosthooks.h \
     $(CGRAPH_H) $(COVERAGE_H) alloc-pool.h $(GGC_H) $(INTEGRATE_H) \
!    opts.h params.def tree-mudflap.h $(REAL_H) tree-pass.h $(GIMPLE_H)
  	$(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) \
  	  -DTARGET_NAME=\"$(target_noncanonical)\" \
  	  -c $(srcdir)/toplev.c $(OUTPUT_OPTION)
--- 2446,2453 ----
     value-prof.h $(PARAMS_H) $(TM_P_H) reload.h ira.h dwarf2asm.h $(TARGET_H) \
     langhooks.h insn-flags.h $(CFGLAYOUT_H) $(CFGLOOP_H) hosthooks.h \
     $(CGRAPH_H) $(COVERAGE_H) alloc-pool.h $(GGC_H) $(INTEGRATE_H) \
!    opts.h params.def tree-mudflap.h $(REAL_H) tree-pass.h $(GIMPLE_H) \
!    tree-ssa-alias.h
  	$(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) \
  	  -DTARGET_NAME=\"$(target_noncanonical)\" \
  	  -c $(srcdir)/toplev.c $(OUTPUT_OPTION)
Index: alias-improvements/gcc/toplev.c
===================================================================
*** alias-improvements.orig/gcc/toplev.c	2009-01-07 11:57:02.000000000 +0100
--- alias-improvements/gcc/toplev.c	2009-02-06 17:14:22.000000000 +0100
*************** along with GCC; see the file COPYING3.
*** 84,89 ****
--- 84,90 ----
  #include "tree-mudflap.h"
  #include "tree-pass.h"
  #include "gimple.h"
+ #include "tree-ssa-alias.h"
  
  #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
  #include "dwarf2out.h"
*************** dump_memory_report (bool final)
*** 2125,2130 ****
--- 2126,2133 ----
    dump_bitmap_statistics ();
    dump_vec_loc_statistics ();
    dump_ggc_loc_statistics (final);
+   dump_alias_stats (stderr);
+   dump_pta_stats (stderr);
  }
  
  /* Clean up: close opened files, etc.  */
Index: alias-improvements/gcc/tree-ssa-alias.c
===================================================================
*** alias-improvements.orig/gcc/tree-ssa-alias.c	2009-02-06 16:13:12.000000000 +0100
--- alias-improvements/gcc/tree-ssa-alias.c	2009-02-06 17:47:06.000000000 +0100
*************** along with GCC; see the file COPYING3.
*** 70,75 ****
--- 70,112 ----
     and tools for walking of the gimple IL.  */
  
  
+ /* Query statistics for the different low-level disambiguators.
+    A high-level query may trigger multiple of them.  */
+ 
+ static struct {
+   unsigned HOST_WIDE_INT refs_may_alias_p_may_alias;
+   unsigned HOST_WIDE_INT refs_may_alias_p_no_alias;
+   unsigned HOST_WIDE_INT ref_maybe_used_by_call_p_may_alias;
+   unsigned HOST_WIDE_INT ref_maybe_used_by_call_p_no_alias;
+   unsigned HOST_WIDE_INT call_may_clobber_ref_p_may_alias;
+   unsigned HOST_WIDE_INT call_may_clobber_ref_p_no_alias;
+ } alias_stats;
+ 
+ void
+ dump_alias_stats (FILE *s)
+ {
+   fprintf (s, "\nAlias oracle query stats:\n");
+   fprintf (s, "  refs_may_alias_p: "
+ 	   HOST_WIDE_INT_PRINT_DEC" disambiguations, "
+ 	   HOST_WIDE_INT_PRINT_DEC" queries\n",
+ 	   alias_stats.refs_may_alias_p_no_alias,
+ 	   alias_stats.refs_may_alias_p_no_alias
+ 	   + alias_stats.refs_may_alias_p_may_alias);
+   fprintf (s, "  ref_maybe_used_by_call_p: "
+ 	   HOST_WIDE_INT_PRINT_DEC" disambiguations, "
+ 	   HOST_WIDE_INT_PRINT_DEC" queries\n",
+ 	   alias_stats.ref_maybe_used_by_call_p_no_alias,
+ 	   alias_stats.refs_may_alias_p_no_alias
+ 	   + alias_stats.ref_maybe_used_by_call_p_may_alias);
+   fprintf (s, "  call_may_clobber_ref_p: "
+ 	   HOST_WIDE_INT_PRINT_DEC" disambiguations, "
+ 	   HOST_WIDE_INT_PRINT_DEC" queries\n",
+ 	   alias_stats.call_may_clobber_ref_p_no_alias,
+ 	   alias_stats.call_may_clobber_ref_p_no_alias
+ 	   + alias_stats.call_may_clobber_ref_p_may_alias);
+ }
+ 
+ 
  /* Return true, if PTR may point to a global variable.  */
  
  bool
*************** may_point_to_global_var (tree ptr)
*** 94,100 ****
  
  /* Return true if PTR may point to DECL.  */
  
! bool
  may_point_to_decl (tree ptr, tree decl)
  {
    struct ptr_info_def *pi;
--- 131,137 ----
  
  /* Return true if PTR may point to DECL.  */
  
! static bool
  may_point_to_decl (tree ptr, tree decl)
  {
    struct ptr_info_def *pi;
*************** may_point_to_decl (tree ptr, tree decl)
*** 126,132 ****
  
  /* Return true if PTR1 and PTR2 may point to the same memory object.  */
  
! bool
  may_point_to_same_object (tree ptr1, tree ptr2)
  {
    struct ptr_info_def *pi1, *pi2;
--- 163,169 ----
  
  /* Return true if PTR1 and PTR2 may point to the same memory object.  */
  
! static bool
  may_point_to_same_object (tree ptr1, tree ptr2)
  {
    struct ptr_info_def *pi1, *pi2;
*************** same_type_for_tbaa (tree type1, tree typ
*** 386,393 ****
  
  /* Return true, if the two memory references REF1 and REF2 may alias.  */
  
! bool
! refs_may_alias_p (tree ref1, tree ref2)
  {
    tree base1, base2;
    HOST_WIDE_INT offset1 = 0, offset2 = 0;
--- 423,430 ----
  
  /* Return true, if the two memory references REF1 and REF2 may alias.  */
  
! static bool
! refs_may_alias_p_1 (tree ref1, tree ref2)
  {
    tree base1, base2;
    HOST_WIDE_INT offset1 = 0, offset2 = 0;
*************** refs_may_alias_p (tree ref1, tree ref2)
*** 570,581 ****
    return true;
  }
  
  
  /* If the call CALL may use the memory reference REF return true,
     otherwise return false.  */
  
  static bool
! ref_maybe_used_by_call_p (gimple call, tree ref)
  {
    tree base = get_base_address (ref);
    unsigned i;
--- 607,629 ----
    return true;
  }
  
+ bool
+ refs_may_alias_p (tree ref1, tree ref2)
+ {
+   bool res = refs_may_alias_p_1 (ref1, ref2);
+   if (res)
+     ++alias_stats.refs_may_alias_p_may_alias;
+   else
+     ++alias_stats.refs_may_alias_p_no_alias;
+   return res;
+ }
+ 
  
  /* If the call CALL may use the memory reference REF return true,
     otherwise return false.  */
  
  static bool
! ref_maybe_used_by_call_p_1 (gimple call, tree ref)
  {
    tree base = get_base_address (ref);
    unsigned i;
*************** ref_maybe_used_by_call_p (gimple call, t
*** 628,633 ****
--- 676,693 ----
    return false;
  }
  
+ static bool
+ ref_maybe_used_by_call_p (gimple call, tree ref)
+ {
+   bool res = ref_maybe_used_by_call_p_1 (call, ref);
+   if (res)
+     ++alias_stats.ref_maybe_used_by_call_p_may_alias;
+   else
+     ++alias_stats.ref_maybe_used_by_call_p_no_alias;
+   return res;
+ }
+ 
+ 
  /* If the statement STMT may use the memory reference REF return
     true, otherwise return false.  */
  
*************** ref_maybe_used_by_stmt_p (gimple stmt, t
*** 660,666 ****
     return true, otherwise return false.  */
  
  static bool
! call_may_clobber_ref_p (gimple call, tree ref)
  {
    tree base;
  
--- 720,726 ----
     return true, otherwise return false.  */
  
  static bool
! call_may_clobber_ref_p_1 (gimple call, tree ref)
  {
    tree base;
  
*************** call_may_clobber_ref_p (gimple call, tre
*** 699,704 ****
--- 759,776 ----
    return true;
  }
  
+ static bool
+ call_may_clobber_ref_p (gimple call, tree ref)
+ {
+   bool res = call_may_clobber_ref_p_1 (call, ref);
+   if (res)
+     ++alias_stats.call_may_clobber_ref_p_may_alias;
+   else
+     ++alias_stats.call_may_clobber_ref_p_no_alias;
+   return res;
+ }
+ 
+ 
  /* If the statement STMT may clobber the memory reference REF return true,
     otherwise return false.  */
  
Index: alias-improvements/gcc/tree-ssa-alias.h
===================================================================
*** alias-improvements.orig/gcc/tree-ssa-alias.h	2009-02-06 16:03:03.000000000 +0100
--- alias-improvements/gcc/tree-ssa-alias.h	2009-02-06 17:06:25.000000000 +0100
*************** struct pt_solution GTY(())
*** 77,84 ****
  /* In tree-ssa-alias.c  */
  extern enum escape_type is_escape_site (gimple);
  extern bool may_point_to_global_var (tree);
- extern bool may_point_to_decl (tree, tree);
- extern bool may_point_to_same_object (tree, tree);
  extern bool refs_may_alias_p (tree, tree);
  extern bool ref_maybe_used_by_stmt_p (gimple, tree);
  extern bool stmt_may_clobber_ref_p (gimple, tree);
--- 77,82 ----
*************** extern void dump_alias_info (FILE *);
*** 89,94 ****
--- 87,93 ----
  extern void debug_alias_info (void);
  extern void dump_points_to_info_for (FILE *, tree);
  extern void debug_points_to_info_for (tree);
+ extern void dump_alias_stats (FILE *);
  
  
  /* In tree-ssa-structalias.c  */
*************** extern void delete_alias_heapvars (void)
*** 97,102 ****
--- 96,102 ----
  extern bool pt_solution_includes (struct pt_solution *, const_tree);
  extern bool pt_solutions_intersect (struct pt_solution *, struct pt_solution *);
  extern void pt_solution_reset (struct pt_solution *);
+ extern void dump_pta_stats (FILE *);
  
  
  #endif /* TREE_SSA_ALIAS_H  */
Index: alias-improvements/gcc/tree-ssa-structalias.c
===================================================================
*** alias-improvements.orig/gcc/tree-ssa-structalias.c	2009-02-06 14:58:03.000000000 +0100
--- alias-improvements/gcc/tree-ssa-structalias.c	2009-02-06 17:46:57.000000000 +0100
*************** find_what_p_points_to (tree p)
*** 5139,5144 ****
--- 5139,5173 ----
      }
  }
  
+ 
+ /* Query statistics for points-to solutions.  */
+ 
+ static struct {
+   unsigned HOST_WIDE_INT pt_solution_includes_may_alias;
+   unsigned HOST_WIDE_INT pt_solution_includes_no_alias;
+   unsigned HOST_WIDE_INT pt_solutions_intersect_may_alias;
+   unsigned HOST_WIDE_INT pt_solutions_intersect_no_alias;
+ } pta_stats;
+ 
+ void
+ dump_pta_stats (FILE *s)
+ {
+   fprintf (s, "\nPTA query stats:\n");
+   fprintf (s, "  pt_solution_includes: "
+ 	   HOST_WIDE_INT_PRINT_DEC" disambiguations, "
+ 	   HOST_WIDE_INT_PRINT_DEC" queries\n",
+ 	   pta_stats.pt_solution_includes_no_alias,
+ 	   pta_stats.pt_solution_includes_no_alias
+ 	   + pta_stats.pt_solution_includes_may_alias);
+   fprintf (s, "  pt_solutions_intersect: "
+ 	   HOST_WIDE_INT_PRINT_DEC" disambiguations, "
+ 	   HOST_WIDE_INT_PRINT_DEC" queries\n",
+ 	   pta_stats.pt_solutions_intersect_no_alias,
+ 	   pta_stats.pt_solutions_intersect_no_alias
+ 	   + pta_stats.pt_solutions_intersect_may_alias);
+ }
+ 
+ 
  /* Reset the points-to solution *PT to a conservative default
     (point to anything).  */
  
*************** pt_solution_empty_p (struct pt_solution
*** 5174,5181 ****
  /* Return true if the points-to solution *PT includes the variable
     declaration DECL.  */
  
! bool
! pt_solution_includes (struct pt_solution *pt, const_tree decl)
  {
    if (pt->anything)
      return true;
--- 5203,5210 ----
  /* Return true if the points-to solution *PT includes the variable
     declaration DECL.  */
  
! static bool
! pt_solution_includes_1 (struct pt_solution *pt, const_tree decl)
  {
    if (pt->anything)
      return true;
*************** pt_solution_includes (struct pt_solution
*** 5190,5206 ****
    /* If this isn't already the escaped solution, union it with that.  */
    if (pt->escaped
        && &cfun->gimple_df->escaped != pt
!       && pt_solution_includes (&cfun->gimple_df->escaped, decl))
      return true;
  
    return false;
  }
  
  /* Return true if both points-to solutions PT1 and PT2 have a non-empty
     intersection.  */
  
! bool
! pt_solutions_intersect (struct pt_solution *pt1, struct pt_solution *pt2)
  {
    if (pt1->anything || pt2->anything)
      return true;
--- 5219,5246 ----
    /* If this isn't already the escaped solution, union it with that.  */
    if (pt->escaped
        && &cfun->gimple_df->escaped != pt
!       && pt_solution_includes_1 (&cfun->gimple_df->escaped, decl))
      return true;
  
    return false;
  }
  
+ bool
+ pt_solution_includes (struct pt_solution *pt, const_tree decl)
+ {
+   bool res = pt_solution_includes_1 (pt, decl);
+   if (res)
+     ++pta_stats.pt_solution_includes_may_alias;
+   else
+     ++pta_stats.pt_solution_includes_no_alias;
+   return res;
+ }
+ 
  /* Return true if both points-to solutions PT1 and PT2 have a non-empty
     intersection.  */
  
! static bool
! pt_solutions_intersect_1 (struct pt_solution *pt1, struct pt_solution *pt2)
  {
    if (pt1->anything || pt2->anything)
      return true;
*************** pt_solutions_intersect (struct pt_soluti
*** 5228,5236 ****
        /* If either points to escaped memory see if the escaped solution
  	 intersects.  */
        if (((pt1->escaped || pt1 == &cfun->gimple_df->escaped)
! 	   && pt_solutions_intersect (&cfun->gimple_df->escaped, pt1))
  	  || ((pt2->escaped || pt2 == &cfun->gimple_df->escaped)
! 	      && pt_solutions_intersect (&cfun->gimple_df->escaped, pt2)))
  	return true;
      }
  
--- 5268,5276 ----
        /* If either points to escaped memory see if the escaped solution
  	 intersects.  */
        if (((pt1->escaped || pt1 == &cfun->gimple_df->escaped)
! 	   && pt_solutions_intersect_1 (&cfun->gimple_df->escaped, pt1))
  	  || ((pt2->escaped || pt2 == &cfun->gimple_df->escaped)
! 	      && pt_solutions_intersect_1 (&cfun->gimple_df->escaped, pt2)))
  	return true;
      }
  
*************** pt_solutions_intersect (struct pt_soluti
*** 5240,5245 ****
--- 5280,5296 ----
  	  && bitmap_intersect_p (pt1->vars, pt2->vars));
  }
  
+ bool
+ pt_solutions_intersect (struct pt_solution *pt1, struct pt_solution *pt2)
+ {
+   bool res = pt_solutions_intersect_1 (pt1, pt2);
+   if (res)
+     ++pta_stats.pt_solutions_intersect_may_alias;
+   else
+     ++pta_stats.pt_solutions_intersect_no_alias;
+   return res;
+ }
+ 
  
  /* Dump points-to information to OUTFILE.  */
  


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