add exported isl_multi_id
authorSven Verdoolaege <sven.verdoolaege@gmail.com>
Thu, 12 Apr 2018 07:38:02 +0000 (12 09:38 +0200)
committerSven Verdoolaege <sven@cerebras.net>
Thu, 2 May 2019 16:19:13 +0000 (2 18:19 +0200)
This type of objects keeps track of a space along with
identifiers for the set dimensions.  This will be useful
for transforming parameters into set dimensions with
the identifiers specifying the parameters that need
to be transformed into the set dimensions at the corresponding
positions and vice versa.

While a space itself can also have names for set dimensions,
these are transient and only meant for pretty printing.
They are not guaranteed to survive any operation
(on the space itself or indeed on any other object somehow
related to the space).

Signed-off-by: Sven Verdoolaege <sven.verdoolaege@gmail.com>
doc/user.pod
include/isl/id.h
include/isl/id_type.h
isl_id.c
isl_id_private.h
isl_output.c
print.c

index 8cee127..c9592f1 100644 (file)
@@ -559,6 +559,8 @@ in which the object was created.
 
        #include <isl/id.h>
        isl_ctx *isl_id_get_ctx(__isl_keep isl_id *id);
+       isl_ctx *isl_multi_id_get_ctx(
+               __isl_keep isl_multi_id *mi);
 
        #include <isl/local_space.h>
        isl_ctx *isl_local_space_get_ctx(
@@ -1120,6 +1122,10 @@ of the original object.
        __isl_give isl_space *isl_union_pw_qpolynomial_fold_get_space(
                __isl_keep isl_union_pw_qpolynomial_fold *upwf);
 
+       #include <isl/id.h>
+       __isl_give isl_space *isl_multi_id_get_space(
+               __isl_keep isl_multi_id *mi);
+
        #include <isl/val.h>
        __isl_give isl_space *isl_multi_val_get_space(
                __isl_keep isl_multi_val *mv);
@@ -1265,6 +1271,9 @@ These functions are mostly useful to obtain the identifiers, positions
 or names of the parameters.  Identifiers of individual dimensions are
 essentially only useful for printing.  They are ignored by all other
 operations and may not be preserved across those operations.
+To keep track of a space along with names/identifiers of
+the set dimensions, use an C<isl_multi_id> as described in
+L</"Functions">.
 
        #include <isl/space.h>
        __isl_give isl_space *isl_space_set_dim_id(
@@ -1782,6 +1791,10 @@ of all the corresponding identifiers, use the following function.
        __isl_give isl_union_map *isl_union_map_reset_user(
                __isl_take isl_union_map *umap);
 
+       #include <isl/id.h>
+       __isl_give isl_multi_id *isl_multi_id_reset_user(
+               __isl_take isl_multi_id *mi);
+
        #include <isl/val.h>
        __isl_give isl_multi_val *isl_multi_val_reset_user(
                __isl_take isl_multi_val *mv);
@@ -2583,6 +2596,9 @@ Besides sets and relation, C<isl> also supports various types of functions.
 Each of these types is derived from the value type (see L</"Values">)
 or from one of two primitive function types
 through the application of zero or more type constructors.
+As a special case, a multiple expression can also be derived
+from an identifier (see L</"Identifiers">) although the result
+is not really a function.
 We first describe the primitive type and then we describe
 the types derived from these primitive types.
 
@@ -2851,8 +2867,9 @@ as that of the base expressions, but the range space
 can be any space.  In case the base expressions have
 a set space, the corresponding multiple expression
 also has a set space.
-Objects of the value type do not have an associated space.
-The space of a multiple value is therefore always a set space.
+Objects of the value or identifier type do not have an associated space.
+The space of a multiple value or
+multiple identifier is therefore always a set space.
 Similarly, the space of a multiple union piecewise
 affine expression is always a set space.
 If the base expressions are not total, then
@@ -2861,7 +2878,7 @@ have an explicit domain that keeps track of the domain
 outside of any base expressions.
 
 The multiple expression types defined by C<isl>
-are C<isl_multi_val>, C<isl_multi_aff>, C<isl_multi_pw_aff>,
+are C<isl_multi_val>, C<isl_multi_id>, C<isl_multi_aff>, C<isl_multi_pw_aff>,
 C<isl_multi_union_pw_aff>.
 
 A multiple expression with the value zero for
@@ -2934,6 +2951,11 @@ as the domains of the base expressions in the list.
 If the base expressions have a set space (or no associated space),
 then this space also needs to be a set space.
 
+       #include <isl/id.h>
+       __isl_give isl_multi_id *isl_multi_id_from_id_list(
+               __isl_take isl_space *space,
+               __isl_take isl_id_list *list);
+
        #include <isl/val.h>
        __isl_give isl_multi_val *isl_multi_val_from_val_list(
                __isl_take isl_space *space,
@@ -3006,6 +3028,12 @@ using the following functions.
 Multiple expressions can be copied and freed using
 the following functions.
 
+       #include <isl/id.h>
+       __isl_give isl_multi_id *isl_multi_id_copy(
+               __isl_keep isl_multi_id *mi);
+       __isl_null isl_multi_id *isl_multi_id_free(
+               __isl_take isl_multi_id *mi);
+
        #include <isl/val.h>
        __isl_give isl_multi_val *isl_multi_val_copy(
                __isl_keep isl_multi_val *mv);
@@ -3031,6 +3059,9 @@ the following functions.
 The number of base expressions in a multiple
 expression can be obtained using the following functions.
 
+       #include <isl/id.h>
+       int isl_multi_id_size(__isl_keep isl_multi_id *mi);
+
        #include <isl/val.h>
        isl_size isl_multi_val_size(__isl_keep isl_multi_val *mv);
 
@@ -3045,6 +3076,10 @@ expression can be obtained using the following functions.
 The base expression at a given position of a multiple
 expression can be extracted using the following functions.
 
+       #include <isl/id.h>
+       __isl_give isl_id *isl_multi_id_get_id(
+               __isl_keep isl_multi_id *mi, int pos);
+
        #include <isl/val.h>
        __isl_give isl_val *isl_multi_val_get_val(
                __isl_keep isl_multi_val *mv, int pos);
@@ -3060,6 +3095,11 @@ expression can be extracted using the following functions.
 
 It can be replaced using the following functions.
 
+       #include <isl/id.h>
+       __isl_give isl_multi_id *isl_multi_id_set_id(
+               __isl_take isl_multi_id *mi, int pos,
+               __isl_take isl_id *id);
+
        #include <isl/val.h>
        __isl_give isl_multi_val *isl_multi_val_set_val(
                __isl_take isl_multi_val *mv, int pos,
@@ -3804,6 +3844,11 @@ To actually print something, use
                __isl_take isl_printer *p,
                __isl_keep isl_multi_val *mv);
 
+       #include <isl/id.h>
+       __isl_give isl_printer *isl_printer_print_multi_id(
+               __isl_take isl_printer *p,
+               __isl_keep isl_multi_id *mi);
+
        #include <isl/aff.h>
        __isl_give isl_printer *isl_printer_print_aff(
                __isl_take isl_printer *p, __isl_keep isl_aff *aff);
@@ -3921,6 +3966,8 @@ in isl format.
        #include <isl/id.h>
        __isl_give char *isl_id_to_str(
                __isl_keep isl_id *id);
+       __isl_give char *isl_multi_id_to_str(
+               __isl_keep isl_multi_id *mi);
 
        #include <isl/space.h>
        __isl_give char *isl_space_to_str(
@@ -4281,6 +4328,10 @@ The following functions check whether the space of the given
                __isl_keep isl_map *map);
        isl_bool isl_map_is_product(__isl_keep isl_map *map);
 
+       #include <isl/id.h>
+       isl_bool isl_multi_id_range_is_wrapping(
+               __isl_keep isl_multi_id *mi);
+
        #include <isl/val.h>
        isl_bool isl_multi_val_range_is_wrapping(
                __isl_keep isl_multi_val *mv);
@@ -4448,6 +4499,11 @@ return true if the objects are not the same.
                __isl_keep isl_union_map *umap1,
                __isl_keep isl_union_map *umap2);
 
+       #include <isl/id.h>
+       isl_bool isl_multi_id_plain_is_equal(
+               __isl_keep isl_multi_id *mi1,
+               __isl_keep isl_multi_id *mi2);
+
        #include <isl/val.h>
        isl_bool isl_multi_val_plain_is_equal(
                __isl_keep isl_multi_val *mv1,
@@ -4903,6 +4959,10 @@ flat anonymous space.
                __isl_take isl_union_set *domain,
                __isl_take isl_union_set *range);
 
+       #include <isl/id.h>
+       __isl_give isl_multi_id *isl_multi_id_from_range(
+               __isl_take isl_multi_id *mi);
+
        #include <isl/val.h>
        __isl_give isl_multi_val *isl_multi_val_from_range(
                __isl_take isl_multi_val *mv);
@@ -5751,6 +5811,10 @@ then the name of the space is also removed.
        __isl_give isl_map *isl_map_flatten(
                __isl_take isl_map *map);
 
+       #include <isl/id.h>
+       __isl_give isl_multi_id *isl_multi_id_flatten_range(
+               __isl_take isl_multi_id *mi);
+
        #include <isl/val.h>
        __isl_give isl_multi_val *isl_multi_val_flatten_range(
                __isl_take isl_multi_val *mv);
@@ -5902,6 +5966,11 @@ All parameters need to be named.
                __isl_take isl_map *map,
                __isl_take isl_space *model);
 
+       #include <isl/id.h>
+       __isl_give isl_multi_id *isl_multi_id_align_params(
+               __isl_take isl_multi_id *mi,
+               __isl_take isl_space *model);
+
        #include <isl/val.h>
        __isl_give isl_multi_val *isl_multi_val_align_params(
                __isl_take isl_multi_val *mv,
@@ -6998,6 +7067,11 @@ two input spaces.
                __isl_take isl_union_map *umap1,
                __isl_take isl_union_map *umap2);
 
+       #include <isl/id.h>
+       __isl_give isl_multi_id *isl_multi_id_range_product(
+               __isl_take isl_multi_id *mi1,
+               __isl_take isl_multi_id *mi2);
+
        #include <isl/val.h>
        __isl_give isl_multi_val *isl_multi_val_range_product(
                __isl_take isl_multi_val *mv1,
@@ -7073,6 +7147,12 @@ instead.
                __isl_take isl_union_map *umap1,
                __isl_take isl_union_map *umap2);
 
+       #include <isl/id.h>
+       __isl_give isl_multi_id *
+       isl_multi_id_flat_range_product(
+               __isl_take isl_multi_id *mi1,
+               __isl_take isl_multi_id *mi2);
+
        #include <isl/val.h>
        __isl_give isl_multi_val *isl_multi_val_flat_range_product(
                __isl_take isl_multi_val *mv1,
@@ -7152,6 +7232,16 @@ from the result using the following functions.
        isl_union_map_range_factor_range(
                __isl_take isl_union_map *umap);
 
+       #include <isl/id.h>
+       __isl_give isl_multi_id *isl_multi_id_factor_range(
+               __isl_take isl_multi_id *mi);
+       __isl_give isl_multi_id *
+       isl_multi_id_range_factor_domain(
+               __isl_take isl_multi_id *mi);
+       __isl_give isl_multi_id *
+       isl_multi_id_range_factor_range(
+               __isl_take isl_multi_id *mi);
+
        #include <isl/val.h>
        __isl_give isl_multi_val *isl_multi_val_factor_range(
                __isl_take isl_multi_val *mv);
@@ -7199,6 +7289,11 @@ C<isl_multi_pw_aff_factor_range> and
 C<isl_multi_union_pw_aff_factor_range>
 take functions that live in a set space.
 
+       #include <isl/id.h>
+       __isl_give isl_multi_id *isl_multi_id_range_splice(
+               __isl_take isl_multi_id *mi1, unsigned pos,
+               __isl_take isl_multi_id *mi2);
+
        #include <isl/val.h>
        __isl_give isl_multi_val *isl_multi_val_range_splice(
                __isl_take isl_multi_val *mv1, unsigned pos,
index 90020f1..cc3e145 100644 (file)
@@ -4,6 +4,7 @@
 #include <isl/ctx.h>
 #include <isl/id_type.h>
 #include <isl/list.h>
+#include <isl/multi.h>
 #include <isl/printer_type.h>
 #include <isl/stdint.h>
 
@@ -13,6 +14,8 @@ extern "C" {
 
 ISL_DECLARE_EXPORTED_LIST_FN(id)
 
+ISL_DECLARE_MULTI(id)
+
 isl_ctx *isl_id_get_ctx(__isl_keep isl_id *id);
 uint32_t isl_id_get_hash(__isl_keep isl_id *id);
 
@@ -35,6 +38,11 @@ __isl_give isl_printer *isl_printer_print_id(__isl_take isl_printer *p,
        __isl_keep isl_id *id);
 void isl_id_dump(__isl_keep isl_id *id);
 
+__isl_give isl_printer *isl_printer_print_multi_id(__isl_take isl_printer *p,
+       __isl_keep isl_multi_id *mi);
+void isl_multi_id_dump(__isl_keep isl_multi_id *mi);
+__isl_give char *isl_multi_id_to_str(__isl_keep isl_multi_id *mi);
+
 #if defined(__cplusplus)
 }
 #endif
index eb13c16..0cb3c1c 100644 (file)
@@ -12,6 +12,9 @@ typedef struct isl_id isl_id;
 
 ISL_DECLARE_EXPORTED_LIST_TYPE(id)
 
+struct __isl_export isl_multi_id;
+typedef struct isl_multi_id isl_multi_id;
+
 #if defined(__cplusplus)
 }
 #endif
index 6fc44e0..9edc522 100644 (file)
--- a/isl_id.c
+++ b/isl_id.c
@@ -282,3 +282,23 @@ __isl_give isl_id *isl_id_read_from_str(isl_ctx *ctx, const char *str)
        isl_stream_free(s);
        return id;
 }
+
+/* Is "id1" (obviously) equal to "id2"?
+ *
+ * isl_id objects can be compared by pointer value, but
+ * isl_multi_*_plain_is_equal needs an isl_*_plain_is_equal.
+ */
+static isl_bool isl_id_plain_is_equal(__isl_keep isl_id *id1,
+       __isl_keep isl_id *id2)
+{
+       if (!id1 || !id2)
+               return isl_bool_error;
+       return id1 == id2;
+}
+
+#undef BASE
+#define BASE id
+
+#include <isl_multi_no_domain_templ.c>
+#include <isl_multi_no_explicit_domain.c>
+#include <isl_multi_templ.c>
index 940db04..3b053e8 100644 (file)
@@ -40,4 +40,9 @@ __isl_give isl_id *isl_stream_read_id(__isl_keep isl_stream *s);
 
 extern isl_id isl_id_none;
 
+#undef BASE
+#define BASE id
+
+#include <isl_multi_templ.h>
+
 #endif
index 0ef3aa9..127eae4 100644 (file)
@@ -29,6 +29,7 @@
 #include <isl_local.h>
 #include <isl_local_space_private.h>
 #include <isl_aff_private.h>
+#include <isl_id_private.h>
 #include <isl_val_private.h>
 #include <isl_constraint_private.h>
 #include <isl/ast_build.h>
@@ -3324,6 +3325,58 @@ __isl_give isl_printer *isl_printer_print_multi_val(
 
 /* Print dimension "pos" of data->space to "p".
  *
+ * data->user is assumed to be an isl_multi_id.
+ *
+ * If the current dimension is an output dimension, then print
+ * the corresponding identifier.  Otherwise, print the name of the dimension.
+ */
+static __isl_give isl_printer *print_dim_mi(__isl_take isl_printer *p,
+       struct isl_print_space_data *data, unsigned pos)
+{
+       isl_multi_id *mi = data->user;
+
+       if (data->type == isl_dim_out)
+               return isl_printer_print_id(p, mi->u.p[pos]);
+       else
+               return print_name(data->space, p, data->type, pos, data->latex);
+}
+
+/* Print the isl_multi_id "mi" to "p" in isl format.
+ */
+static __isl_give isl_printer *print_multi_id_isl(__isl_take isl_printer *p,
+       __isl_keep isl_multi_id *mi)
+{
+       isl_space *space;
+       struct isl_print_space_data data = { 0 };
+
+       space = isl_multi_id_peek_space(mi);
+       p = print_param_tuple(p, space, &data);
+       p = isl_printer_print_str(p, "{ ");
+       data.print_dim = &print_dim_mi;
+       data.user = mi;
+       p = isl_print_space(space, p, 0, &data);
+       p = isl_printer_print_str(p, " }");
+       return p;
+}
+
+/* Print the isl_multi_id "mi" to "p".
+ *
+ * Currently only supported in isl format.
+ */
+__isl_give isl_printer *isl_printer_print_multi_id(
+       __isl_take isl_printer *p, __isl_keep isl_multi_id *mi)
+{
+       if (!p || !mi)
+               return isl_printer_free(p);
+
+       if (p->output_format == ISL_FORMAT_ISL)
+               return print_multi_id_isl(p, mi);
+       isl_die(isl_printer_get_ctx(p), isl_error_unsupported,
+               "unsupported output format", return isl_printer_free(p));
+}
+
+/* Print dimension "pos" of data->space to "p".
+ *
  * data->user is assumed to be an isl_multi_union_pw_aff.
  *
  * The current dimension is necessarily a set dimension, so
diff --git a/print.c b/print.c
index 44855a2..a87f922 100644 (file)
--- a/print.c
+++ b/print.c
@@ -17,6 +17,9 @@
 #define BASE id
 #include <print_templ.c>
 #undef BASE
+#define BASE multi_id
+#include <print_templ.c>
+#undef BASE
 #define BASE val
 #include <print_templ.c>
 #undef BASE