[PATCH 18/40] Move compute_alias_check_pairs to tree-data-ref.c

Frederik Harwath frederik@codesourcery.com
Wed Dec 15 15:54:25 GMT 2021


Move this function from tree-loop-distribution.c to tree-data-ref.c
and make it non-static to enable its use from other parts of GCC.

gcc/ChangeLog:
        * tree-loop-distribution.c (data_ref_segment_size): Remove function.
        (latch_dominated_by_data_ref): Likewise.
        (compute_alias_check_pairs): Likewise.

        * tree-data-ref.c (data_ref_segment_size): New function,
        copied from tree-loop-distribution.c
        (compute_alias_check_pairs): Likewise.
        (latch_dominated_by_data_ref): Likewise.

        * tree-data-ref.h (compute_alias_check_pairs): New declaration.
---
 gcc/tree-data-ref.c          | 87 ++++++++++++++++++++++++++++++++++++
 gcc/tree-data-ref.h          |  3 ++
 gcc/tree-loop-distribution.c | 87 ------------------------------------
 3 files changed, 90 insertions(+), 87 deletions(-)

diff --git a/gcc/tree-data-ref.c b/gcc/tree-data-ref.c
index 46f4ffedb483..6a3659dc490c 100644
--- a/gcc/tree-data-ref.c
+++ b/gcc/tree-data-ref.c
@@ -2636,6 +2636,93 @@ create_intersect_range_checks (class loop *loop, tree *cond_expr,
     dump_printf (MSG_NOTE, "using an address-based overlap test\n");
 }

+/* Compute and return an expression whose value is the segment length which
+   will be accessed by DR in NITERS iterations.  */
+
+static tree
+data_ref_segment_size (struct data_reference *dr, tree niters)
+{
+  niters = size_binop (MINUS_EXPR,
+                      fold_convert (sizetype, niters),
+                      size_one_node);
+  return size_binop (MULT_EXPR,
+                    fold_convert (sizetype, DR_STEP (dr)),
+                    fold_convert (sizetype, niters));
+}
+
+/* Return true if LOOP's latch is dominated by statement for data reference
+   DR.  */
+
+static inline bool
+latch_dominated_by_data_ref (class loop *loop, data_reference *dr)
+{
+  return dominated_by_p (CDI_DOMINATORS, single_exit (loop)->src,
+                        gimple_bb (DR_STMT (dr)));
+}
+
+/* Compute alias check pairs and store them in COMP_ALIAS_PAIRS for LOOP's
+   data dependence relations ALIAS_DDRS.  */
+
+void
+compute_alias_check_pairs (class loop *loop, vec<ddr_p> *alias_ddrs,
+                          vec<dr_with_seg_len_pair_t> *comp_alias_pairs)
+{
+  unsigned int i;
+  unsigned HOST_WIDE_INT factor = 1;
+  tree niters_plus_one, niters = number_of_latch_executions (loop);
+
+  gcc_assert (niters != NULL_TREE && niters != chrec_dont_know);
+  niters = fold_convert (sizetype, niters);
+  niters_plus_one = size_binop (PLUS_EXPR, niters, size_one_node);
+
+  if (dump_file && (dump_flags & TDF_DETAILS))
+    fprintf (dump_file, "Creating alias check pairs:\n");
+
+  /* Iterate all data dependence relations and compute alias check pairs.  */
+  for (i = 0; i < alias_ddrs->length (); i++)
+    {
+      ddr_p ddr = (*alias_ddrs)[i];
+      struct data_reference *dr_a = DDR_A (ddr);
+      struct data_reference *dr_b = DDR_B (ddr);
+      tree seg_length_a, seg_length_b;
+
+      if (latch_dominated_by_data_ref (loop, dr_a))
+       seg_length_a = data_ref_segment_size (dr_a, niters_plus_one);
+      else
+       seg_length_a = data_ref_segment_size (dr_a, niters);
+
+      if (latch_dominated_by_data_ref (loop, dr_b))
+       seg_length_b = data_ref_segment_size (dr_b, niters_plus_one);
+      else
+       seg_length_b = data_ref_segment_size (dr_b, niters);
+
+      unsigned HOST_WIDE_INT access_size_a
+       = tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (DR_REF (dr_a))));
+      unsigned HOST_WIDE_INT access_size_b
+       = tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (DR_REF (dr_b))));
+      unsigned int align_a = TYPE_ALIGN_UNIT (TREE_TYPE (DR_REF (dr_a)));
+      unsigned int align_b = TYPE_ALIGN_UNIT (TREE_TYPE (DR_REF (dr_b)));
+
+      dr_with_seg_len_pair_t dr_with_seg_len_pair
+       (dr_with_seg_len (dr_a, seg_length_a, access_size_a, align_a),
+        dr_with_seg_len (dr_b, seg_length_b, access_size_b, align_b),
+        /* ??? Would WELL_ORDERED be safe?  */
+        dr_with_seg_len_pair_t::REORDERED);
+
+      comp_alias_pairs->safe_push (dr_with_seg_len_pair);
+    }
+
+  if (tree_fits_uhwi_p (niters))
+    factor = tree_to_uhwi (niters);
+
+  /* Prune alias check pairs.  */
+  prune_runtime_alias_test_list (comp_alias_pairs, factor);
+  if (dump_file && (dump_flags & TDF_DETAILS))
+    fprintf (dump_file,
+            "Improved number of alias checks from %d to %d\n",
+            alias_ddrs->length (), comp_alias_pairs->length ());
+}
+
 /* Create a conditional expression that represents the run-time checks for
    overlapping of address ranges represented by a list of data references
    pairs passed in ALIAS_PAIRS.  Data references are in LOOP.  The returned
diff --git a/gcc/tree-data-ref.h b/gcc/tree-data-ref.h
index 74f579c9f3f2..4929b059ddea 100644
--- a/gcc/tree-data-ref.h
+++ b/gcc/tree-data-ref.h
@@ -582,6 +582,9 @@ extern opt_result runtime_alias_check_p (ddr_p, class loop *, bool);
 extern int data_ref_compare_tree (tree, tree);
 extern void prune_runtime_alias_test_list (vec<dr_with_seg_len_pair_t> *,
                                           poly_uint64);
+
+extern void compute_alias_check_pairs (class loop *, vec<ddr_p> *,
+                                      vec<dr_with_seg_len_pair_t> *);
 extern void create_runtime_alias_checks (class loop *,
                                         const vec<dr_with_seg_len_pair_t> *,
                                         tree*);
diff --git a/gcc/tree-loop-distribution.c b/gcc/tree-loop-distribution.c
index 583c01a42d86..ed6f2c2974f1 100644
--- a/gcc/tree-loop-distribution.c
+++ b/gcc/tree-loop-distribution.c
@@ -2582,93 +2582,6 @@ loop_distribution::break_alias_scc_partitions (struct graph *rdg,
     }
 }

-/* Compute and return an expression whose value is the segment length which
-   will be accessed by DR in NITERS iterations.  */
-
-static tree
-data_ref_segment_size (struct data_reference *dr, tree niters)
-{
-  niters = size_binop (MINUS_EXPR,
-                      fold_convert (sizetype, niters),
-                      size_one_node);
-  return size_binop (MULT_EXPR,
-                    fold_convert (sizetype, DR_STEP (dr)),
-                    fold_convert (sizetype, niters));
-}
-
-/* Return true if LOOP's latch is dominated by statement for data reference
-   DR.  */
-
-static inline bool
-latch_dominated_by_data_ref (class loop *loop, data_reference *dr)
-{
-  return dominated_by_p (CDI_DOMINATORS, single_exit (loop)->src,
-                        gimple_bb (DR_STMT (dr)));
-}
-
-/* Compute alias check pairs and store them in COMP_ALIAS_PAIRS for LOOP's
-   data dependence relations ALIAS_DDRS.  */
-
-static void
-compute_alias_check_pairs (class loop *loop, vec<ddr_p> *alias_ddrs,
-                          vec<dr_with_seg_len_pair_t> *comp_alias_pairs)
-{
-  unsigned int i;
-  unsigned HOST_WIDE_INT factor = 1;
-  tree niters_plus_one, niters = number_of_latch_executions (loop);
-
-  gcc_assert (niters != NULL_TREE && niters != chrec_dont_know);
-  niters = fold_convert (sizetype, niters);
-  niters_plus_one = size_binop (PLUS_EXPR, niters, size_one_node);
-
-  if (dump_file && (dump_flags & TDF_DETAILS))
-    fprintf (dump_file, "Creating alias check pairs:\n");
-
-  /* Iterate all data dependence relations and compute alias check pairs.  */
-  for (i = 0; i < alias_ddrs->length (); i++)
-    {
-      ddr_p ddr = (*alias_ddrs)[i];
-      struct data_reference *dr_a = DDR_A (ddr);
-      struct data_reference *dr_b = DDR_B (ddr);
-      tree seg_length_a, seg_length_b;
-
-      if (latch_dominated_by_data_ref (loop, dr_a))
-       seg_length_a = data_ref_segment_size (dr_a, niters_plus_one);
-      else
-       seg_length_a = data_ref_segment_size (dr_a, niters);
-
-      if (latch_dominated_by_data_ref (loop, dr_b))
-       seg_length_b = data_ref_segment_size (dr_b, niters_plus_one);
-      else
-       seg_length_b = data_ref_segment_size (dr_b, niters);
-
-      unsigned HOST_WIDE_INT access_size_a
-       = tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (DR_REF (dr_a))));
-      unsigned HOST_WIDE_INT access_size_b
-       = tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (DR_REF (dr_b))));
-      unsigned int align_a = TYPE_ALIGN_UNIT (TREE_TYPE (DR_REF (dr_a)));
-      unsigned int align_b = TYPE_ALIGN_UNIT (TREE_TYPE (DR_REF (dr_b)));
-
-      dr_with_seg_len_pair_t dr_with_seg_len_pair
-       (dr_with_seg_len (dr_a, seg_length_a, access_size_a, align_a),
-        dr_with_seg_len (dr_b, seg_length_b, access_size_b, align_b),
-        /* ??? Would WELL_ORDERED be safe?  */
-        dr_with_seg_len_pair_t::REORDERED);
-
-      comp_alias_pairs->safe_push (dr_with_seg_len_pair);
-    }
-
-  if (tree_fits_uhwi_p (niters))
-    factor = tree_to_uhwi (niters);
-
-  /* Prune alias check pairs.  */
-  prune_runtime_alias_test_list (comp_alias_pairs, factor);
-  if (dump_file && (dump_flags & TDF_DETAILS))
-    fprintf (dump_file,
-            "Improved number of alias checks from %d to %d\n",
-            alias_ddrs->length (), comp_alias_pairs->length ());
-}
-
 /* Given data dependence relations in ALIAS_DDRS, generate runtime alias
    checks and version LOOP under condition of these runtime alias checks.  */

--
2.33.0

-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955


More information about the Gcc-patches mailing list