This fixes a minor issue in the previous patch (forgot to add
the equiv class into the hash) and merges lookup and add to
avoid multiple bitmap_hash calls and hashtable lookups for another
minor speedup.

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

Richard.

2013-02-04  Richard Biener  <rguent...@suse.de>

        PR tree-optimization/56113
        * tree-ssa-structalias.c (equiv_class_lookup, equiv_class_add):
        Merge into ...
        (equiv_class_lookup_or_add): ... this.
        (label_visit): Adjust and fix error in previous patch.
        (perform_var_substitution): Adjust.

Index: gcc/tree-ssa-structalias.c
===================================================================
*** gcc/tree-ssa-structalias.c  (revision 195646)
--- gcc/tree-ssa-structalias.c  (working copy)
*************** equiv_class_label_eq (const void *p1, co
*** 1908,1961 ****
          && bitmap_equal_p (eql1->labels, eql2->labels));
  }
  
! /* Lookup a equivalence class in TABLE by the bitmap of LABELS it
!    contains.  Sets *REF_LABELS to the bitmap LABELS is equivalent to.  */
  
! static unsigned int
! equiv_class_lookup (htab_t table, bitmap labels, bitmap *ref_labels)
  {
!   void **slot;
!   struct equiv_class_label ecl;
  
    ecl.labels = labels;
    ecl.hashcode = bitmap_hash (labels);
! 
!   slot = htab_find_slot_with_hash (table, &ecl,
!                                  ecl.hashcode, NO_INSERT);
!   if (!slot)
!     {
!       if (ref_labels)
!       *ref_labels = NULL;
!       return 0;
!     }
!   else
      {
!       equiv_class_label_t ec = (equiv_class_label_t) *slot;
!       if (ref_labels)
!       *ref_labels = ec->labels;
!       return ec->equivalence_class;
      }
- }
- 
- 
- /* Add an equivalence class named EQUIVALENCE_CLASS with labels LABELS
-    to TABLE.  */
  
! static void
! equiv_class_add (htab_t table, unsigned int equivalence_class,
!                bitmap labels)
! {
!   void **slot;
!   equiv_class_label_t ecl = XNEW (struct equiv_class_label);
! 
!   ecl->labels = labels;
!   ecl->equivalence_class = equivalence_class;
!   ecl->hashcode = bitmap_hash (labels);
! 
!   slot = htab_find_slot_with_hash (table, ecl,
!                                  ecl->hashcode, INSERT);
!   gcc_assert (!*slot);
!   *slot = (void *) ecl;
  }
  
  /* Perform offline variable substitution.
--- 1908,1936 ----
          && bitmap_equal_p (eql1->labels, eql2->labels));
  }
  
! /* Lookup a equivalence class in TABLE by the bitmap of LABELS with
!    hash HAS it contains.  Sets *REF_LABELS to the bitmap LABELS
!    is equivalent to.  */
  
! static equiv_class_label *
! equiv_class_lookup_or_add (htab_t table, bitmap labels)
  {
!   equiv_class_label **slot;
!   equiv_class_label ecl;
  
    ecl.labels = labels;
    ecl.hashcode = bitmap_hash (labels);
!   slot = (equiv_class_label **) htab_find_slot_with_hash (table, &ecl,
!                                                         ecl.hashcode, INSERT);
!   if (!*slot)
      {
!       *slot = XNEW (struct equiv_class_label);
!       (*slot)->labels = labels;
!       (*slot)->hashcode = ecl.hashcode;
!       (*slot)->equivalence_class = 0;
      }
  
!   return *slot;
  }
  
  /* Perform offline variable substitution.
*************** label_visit (constraint_graph_t graph, s
*** 2150,2155 ****
--- 2125,2134 ----
        }
        bitmap_set_bit (graph->points_to[n], FIRST_REF_NODE + n);
        graph->pointer_label[n] = pointer_equiv_class++;
+       equiv_class_label_t ecl;
+       ecl = equiv_class_lookup_or_add (pointer_equiv_class_table,
+                                      graph->points_to[n]);
+       ecl->equivalence_class = graph->pointer_label[n];
        return;
      }
  
*************** label_visit (constraint_graph_t graph, s
*** 2167,2188 ****
  
    if (!bitmap_empty_p (graph->points_to[n]))
      {
!       bitmap ref_points_to;
!       unsigned int label = equiv_class_lookup (pointer_equiv_class_table,
!                                              graph->points_to[n],
!                                              &ref_points_to);
!       if (!label)
!       {
!         label = pointer_equiv_class++;
!         equiv_class_add (pointer_equiv_class_table,
!                          label, graph->points_to[n]);
!       }
        else
        {
          BITMAP_FREE (graph->points_to[n]);
!         graph->points_to[n] = ref_points_to;
        }
!       graph->pointer_label[n] = label;
      }
  }
  
--- 2146,2162 ----
  
    if (!bitmap_empty_p (graph->points_to[n]))
      {
!       equiv_class_label_t ecl;
!       ecl = equiv_class_lookup_or_add (pointer_equiv_class_table,
!                                      graph->points_to[n]);
!       if (ecl->equivalence_class == 0)
!       ecl->equivalence_class = pointer_equiv_class++;
        else
        {
          BITMAP_FREE (graph->points_to[n]);
!         graph->points_to[n] = ecl->labels;
        }
!       graph->pointer_label[n] = ecl->equivalence_class;
      }
  }
  
*************** perform_var_substitution (constraint_gra
*** 2222,2228 ****
        bitmap pointed_by;
        bitmap_iterator bi;
        unsigned int j;
-       unsigned int label;
  
        if (!graph->pointed_by[i])
        continue;
--- 2196,2201 ----
*************** perform_var_substitution (constraint_gra
*** 2240,2253 ****
  
        /* Look up the location equivalence label if one exists, or make
         one otherwise.  */
!       label = equiv_class_lookup (location_equiv_class_table,
!                                 pointed_by, NULL);
!       if (label == 0)
!       {
!         label = location_equiv_class++;
!         equiv_class_add (location_equiv_class_table,
!                          label, pointed_by);
!       }
        else
        {
          if (dump_file && (dump_flags & TDF_DETAILS))
--- 2213,2222 ----
  
        /* Look up the location equivalence label if one exists, or make
         one otherwise.  */
!       equiv_class_label_t ecl;
!       ecl = equiv_class_lookup_or_add (location_equiv_class_table, 
pointed_by);
!       if (ecl->equivalence_class == 0)
!       ecl->equivalence_class = location_equiv_class++;
        else
        {
          if (dump_file && (dump_flags & TDF_DETAILS))
*************** perform_var_substitution (constraint_gra
*** 2255,2261 ****
                     get_varinfo (i)->name);
          BITMAP_FREE (pointed_by);
        }
!       graph->loc_label[i] = label;
  
      }
  
--- 2224,2230 ----
                     get_varinfo (i)->name);
          BITMAP_FREE (pointed_by);
        }
!       graph->loc_label[i] = ecl->equivalence_class;
  
      }
  

Reply via email to