extract out shared isl_basic_map_div_expr_involves_vars
authorSven Verdoolaege <skimo@kotnet.org>
Tue, 12 Jul 2016 15:23:20 +0000 (12 17:23 +0200)
committerSven Verdoolaege <sven@cerebras.net>
Sun, 25 Feb 2024 14:48:37 +0000 (25 15:48 +0100)
This removes some code duplication.

Note that the same pattern also occurs in other places,
but they will be covered by an isl_basic_map_any_div_involves_vars
that will be extracted in an upcoming commit and
that will also call isl_basic_map_div_expr_involves_vars.

Signed-off-by: Sven Verdoolaege <sven.verdoolaege@gmail.com>
isl_map.c
isl_map_private.h
isl_map_simplify.c

index 6d1aaa9..62b1a9f 100644 (file)
--- a/isl_map.c
+++ b/isl_map.c
@@ -2671,15 +2671,13 @@ __isl_give isl_basic_map *isl_basic_map_remove_dims(
        return bmap;
 }
 
-/* Return true if the definition of the given div (recursively) involves
- * any of the given variables.
+/* Does the local variable "div" of "bmap" have a known expression
+ * that involves the "n" variables starting at "first"?
  */
-static isl_bool div_involves_vars(__isl_keep isl_basic_map *bmap, int div,
-       unsigned first, unsigned n)
+isl_bool isl_basic_map_div_expr_involves_vars(__isl_keep isl_basic_map *bmap,
+       int div, unsigned first, unsigned n)
 {
-       int i;
        isl_bool unknown;
-       isl_size n_div, v_div;
 
        unknown = isl_basic_map_div_is_marked_unknown(bmap, div);
        if (unknown < 0 || unknown)
@@ -2687,6 +2685,23 @@ static isl_bool div_involves_vars(__isl_keep isl_basic_map *bmap, int div,
        if (isl_seq_first_non_zero(bmap->div[div] + 1 + 1 + first, n) >= 0)
                return isl_bool_true;
 
+       return isl_bool_false;
+}
+
+/* Return true if the definition of the given div (recursively) involves
+ * any of the given variables.
+ */
+static isl_bool div_involves_vars(__isl_keep isl_basic_map *bmap, int div,
+       unsigned first, unsigned n)
+{
+       int i;
+       isl_bool involves;
+       isl_size n_div, v_div;
+
+       involves = isl_basic_map_div_expr_involves_vars(bmap, div, first, n);
+       if (involves < 0 || involves)
+               return involves;
+
        n_div = isl_basic_map_dim(bmap, isl_dim_div);
        v_div = isl_basic_map_var_offset(bmap, isl_dim_div);
        if (n_div < 0 || v_div < 0)
index e6f6786..76e443b 100644 (file)
@@ -588,6 +588,9 @@ isl_bool isl_basic_map_applies_range(__isl_keep isl_basic_map *bmap1,
 __isl_give isl_vec *isl_basic_map_inequality_extract_output_upper_bound(
        __isl_keep isl_basic_map *bmap, int ineq, int pos);
 
+isl_bool isl_basic_map_div_expr_involves_vars(__isl_keep isl_basic_map *bmap,
+       int div, unsigned first, unsigned n);
+
 isl_size isl_basic_map_find_output_upper_div_constraint(
        __isl_keep isl_basic_map *bmap, int pos);
 
index cffb37f..380b9e6 100644 (file)
@@ -5092,15 +5092,12 @@ static isl_bool any_div_involves_div(__isl_keep isl_basic_map *bmap, int div)
                return isl_bool_error;
 
        for (i = div + 1; i < n_div; ++i) {
-               isl_bool unknown;
+               isl_bool involves;
 
-               unknown = isl_basic_map_div_is_marked_unknown(bmap, i);
-               if (unknown < 0)
-                       return isl_bool_error;
-               if (unknown)
-                       continue;
-               if (!isl_int_is_zero(bmap->div[i][1 + 1 + v_div + div]))
-                       return isl_bool_true;
+               involves = isl_basic_map_div_expr_involves_vars(bmap, i,
+                                                               v_div + div, 1);
+               if (involves < 0 || involves)
+                       return involves;
        }
 
        return isl_bool_false;